﻿
function LoadImage(id, src) {
    if (id.getAttribute("loi") == null) {
        id.setAttribute("loi", "1");
    }
    else {
        id.setAttribute("loi", eval(id.getAttribute("loi")) + 1);
    }
    if (eval(id.getAttribute("loi")) >= 2) {
        var width = src.substr(src.lastIndexOf("=") + 1, src.length - src.lastIndexOf("="));
        id.onerror = null;
        id.src = "/Images/no_image.jpg";
    }
    else {
        id.src = src;
    }
}
function LoadFocus() {
    var divMenu = document.getElementById("nav");
    var listA = divMenu.getElementsByTagName("A");
    for (var i = 0; i < listA.length; i++) {
        if (listA[i].href.indexOf(document.getElementById('menu').value) != -1) {

            listA[i].className = "active";
            break;
        }
    }
}
function SearchKeyPress(event) {
    var textSearch = document.getElementById('txtSearch');
    var strSearch = textSearch.value;
    var url = "";
    var key;
    if (window.event) {
        key = window.event.keyCode;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/tim-kiem.htm?KeySearch=" + strSearch + "&PageIndex=1";
                document.location.href = url;
                event.keyCode = 0;
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }
        }
    }
    else {
        key = event.which;
        if (key == 13) {
            if (textSearch.value != "") {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
                if (strSearch == "") return false;
                else if (strSearch.indexOf("?") != -1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/tim-kiem.htm?KeySearch=" + strSearch + "&PageIndex=1";
                window.location.href = url;
                return false;
            }
            else {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");

                return false;
            }

        }
    }
}
function OnSearchClick() {
    var textSearch = document.getElementById('txtSearch');
    if (textSearch.value != "") {
        var strSearch = textSearch.value;
        strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');
        if (strSearch == "") return false;
        else if (strSearch.indexOf("?") != -1) return false;
        strSearch = encodeURIComponent(strSearch)
        url = "/tim-kiem.htm?KeySearch=" + strSearch + "&PageIndex=1";
        if (document.all) {
            window.location.href = url;
        }
        else {
            document.location.href = url;
        }
        return false;
    }
    else {
        alert("Bạn chưa nhập từ khóa tìm kiếm!");
        return false;
    }
}
function SearchFocus() {
    var textSearch = document.getElementById('txtSearch');
    text = textSearch.value;
    if (text == "...điền từ khoá cần tìm") textSearch.value = "";
}

function SearchBlur() {
    var textSearch = document.getElementById('txtSearch');
    text = textSearch.value;
    if (text == "") textSearch.value = "...điền từ khoá cần tìm";
}
function InputFocus(textdefault,control) {
    text = control.value;
    if (text == textdefault) control.value = "";
}

function InputBlur(textdefault,control) {
    text = control.value;
    if (text == "") control.value = textdefault;
}
function AjaxRequestURLNew(url) 
{
    var xmlHttp;
    try {
        if (!document.all) {
            xmlHttp = new XMLHttpRequest();
        }
        else {
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
    }
    catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
    };
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            alert(xmlHttp.responseText);
        }
    };
    xmlHttp.open("GET", url, true); xmlHttp.send(null);
}
function showpopup(url,width,height) {var left = (screen.width - width)/2;var top = (screen.height - height)/2;var params = 'width='+width+', height='+height;params += ', top='+top+', left='+left;params += ', directories=no';params += ', location=no';params += ', menubar=no';params += ', resizable=no';params += ', scrollbars=no';params += ', status=no';params += ', toolbar=no';newwin=window.open(url,'windowname5', params);if (window.focus) {newwin.focus()}return false;}
