
//#######################################
//# SEARCH 1
//#######################################

var str = 'Nhập Tên Bộ Phim Hoặc Diễn Viên Cần Tìm...';

function setValue(obj) {
    if (obj.value == '') {
        obj.value = str;
        obj.style.color = '#5A5A5A';
    }
    else if (obj.value == str) {
        obj.value = '';
        obj.style.color = '#1E1E1E';
    }
}

String.prototype.trim = function() { //Trim ambas direcciones
    return this.replace(/^[ ]+|[ ]+$/g, "");
}

String.prototype.stripSpace = function() { //Trim ambas direcciones
    return this.replace(/(\s\s+)/g, " ");
}

String.prototype.stripExtra = function() { //Trim ambas direcciones
    re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\.|\//g;
    return this.replace(re, "");
}

String.prototype.stripViet = function() {
    var replaceChr = String.prototype.stripViet.arguments[0];
    var stripped_str = this;
    var viet = [];
    i = 0;
    viet[i++] = new Array('a', "/á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/g");
    viet[i++] = new Array('o', "/ó|ò|ỏ|õ|ọ|ơ|ớ|ờ|ở|ỡ|ợ|ô|ố|ồ|ổ|ỗ|ộ/g");
    viet[i++] = new Array('e', "/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/g");
    viet[i++] = new Array('u', "/ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự/g");
    viet[i++] = new Array('i', "/í|ì|ỉ|ĩ|ị/g");
    viet[i++] = new Array('y', "/ý|ỳ|ỷ|ỹ|ỵ/g");
    viet[i++] = new Array('d', "/đ/g");
    for (var i = 0; i < viet.length; i++) {
        stripped_str = stripped_str.replace(eval(viet[i][1]), viet[i][0]);
        stripped_str = stripped_str.replace(eval(viet[i][1].toUpperCase().replace('G', 'g')), viet[i][0].toUpperCase());
    }
    if (replaceChr) {
        return stripped_str.replace(/[\W]|_/g, replaceChr).replace(/\s/g, replaceChr).replace(/^\-+|\-+$/g, replaceChr);
    } else {
        return stripped_str;
    }
};

function CheckSearch(obj) {
    var length = obj.keyword.value.trim().length;
    if (length < 2 || obj.keyword.value == str) {
        alert("Từ khóa phải có chiều dài từ 2 kí tự trở lên!");
        if (length < 1)
            obj.keyword.value = '';
        obj.keyword.focus();
        return false;
    }
    obj.keyword.value = obj.keyword.value.trim().stripSpace();
    return true;
}

function initS() {
    if (document.frmSearch.keyword.value == '') {
        setValue(document.frmSearch.keyword);
    }
}

function btnVietkey_onclick(id) {
    if (document.getElementById(id).src.indexOf('V.gif') == -1) {
        setMethod(0);
        document.getElementById(id).src = site+'/skin/movie/images/V.gif';
    }
    else {
        setMethod(-1);
        document.getElementById(id).src = site+'/skin/movie/images/E.gif';
    }
    return true;
}

//#######################################
//# SEARCH 2
//#######################################

function str_replace(search, replace, str){
	var ra = replace instanceof Array, sa = str instanceof Array, l = (search = [].concat(search)).length, replace = [].concat(replace), i = (str = [].concat(str)).length;
	while(j = 0, i--)
		while(str[i] = str[i].split(search[j]).join(ra ? replace[j] || "" : replace[0]), ++j < l);
	return sa ? str : str[0];
}
function do_search() {
	tab = document.getElementById("t").value;
	kw = document.getElementById("keyword").value;
	kw = str_replace(' ', '_', kw);
	kw = str_replace('%20', '_', kw);
	if (!kw) alert('Bạn chưa nhập từ khóa');
	else {
		kw = encodeURIComponent(kw);
		window.location.href = site+'/?anime=/search/'+kw+'/'+tab;	
	}
  return false;
}
function applyType(obj, value) {
    var arrType = document.getElementsByName('searchType');
    for (var i = 0; i < arrType.length; i++) {
        arrType[i].className = '';
    }
    obj.className = 'curnav';
	document.getElementById("frmsearch").t.value = value;
}
//#######################################
//# END SEARCH
//#######################################

