/*======================================================================*\
|| #################################################################### ||
|| # AT Movie 1.0                                                     # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2008-2009 AnhTrang.Org . All Rights Reserved.         # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ----------- AT MOVIE IS FREE SOFTWARE - OPEN SOURCE ------------ # ||
|| # http://www.anhtrang.org | http://www.anhtrang.org/support.html   # ||
|| #################################################################### ||
\*======================================================================*/

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.stripExtra().trim().stripSpace().stripViet();
    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+'/images/V.gif';
    }
    else {
        setMethod(-1);
        document.getElementById(id).src = site+'/images/E.gif';
    }
    return true;
}