﻿var sysWording;
var sysWordingRead = false;
var intSysWordingCheckSpeed = 100;
XML_Reader("websites/" + getWebsite() + "/XML/Localization.xml", "Localization");
function Localization(xml) {
    sysWording = $("content", xml);
    sysWordingRead = true;
}


function querySt(strName) {
    hu = window.location.search.substring(1);
    var rtn = "";
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0].toUpperCase() == strName.toUpperCase()) {
            rtn = ft[1];
        }
    }
    return rtn;
}

function getURLId() {
    hu = window.location.href.substring(0);
    gy = hu.split("#");
    if (gy[1] != null) {
        return gy[1];
    }
    else {
        return "";
    }
}

function getWebsite() {
    var rtnVal;
    var testdefault = "global";
    switch (window.location.hostname.toLowerCase()) {
        case "localhost":
            rtnVal = testdefault;
            break;
        case "athena.asus.com":
        case "192.168.88.165":
        case "localtest":
            hu = window.location.pathname;
            gy = hu.split("/");
            rtnVal = gy[1];
            break;
        case "www.asus.com":
        case "hu.asus.com":
        case "www.asus.hu":
        case "asus.cl":
            rtnVal = "global";
            break;
        case "tw.asus.com":
        case "www.asus.com.tw":
        case "taiwan.asus.com":
            rtnVal = "tw";
            break;
        case "uk.asus.com":
            rtnVal = "gb";
            break;
        case "www.asus.fr":
        case "fr.asus.com":
            rtnVal = "fr";
            break;
        case "usa.asus.com":
            rtnVal = "us";
            break;
        case "ae.asus.com":
            rtnVal = "ae";
            break;
        case "www.asus.com.au":
        case "au.asus.com":
        case "asus.com.au":
            rtnVal = "au";
            break;
        case "asus.com.pl":
            rtnVal = "pl";
            break;
        case "www.asus.cz":
            rtnVal = "cz";
            break;
        case "www.asus.dk":
            rtnVal = "dk";
            break;
        case "www.asus.fi":
            rtnVal = "fi";
            break;
        case "www.asus.no":
            rtnVal = "no";
            break;
        case "www.asus.it":
            rtnVal = "it";
            break;
        case "my.asus.com":
            rtnVal = "my";
            break;
        case "sg.asus.com":
            rtnVal = "sg";
            break;
        case "www.asus.ua":
            rtnVal = "ua";
            break;
        case "za.asus.com":
            rtnVal = "za";
            break;
        case "ph.asus.com":
            rtnVal = "ph";
            break;
        case "bd.asus.com":
            rtnVal = "bd";
            break;
        case "in.asus.com":
            rtnVal = "in";
            break;
        case "lk.asus.com":
            rtnVal = "lk";
            break;
        case "pk.asus.com":
            rtnVal = "pk";
            break;
        case "www.asus.com.tr":
            rtnVal = "tr";
            break;
        case "www.asus.co.nz":
            rtnVal = "nz";
            break;
        case "www.asus.de":
            rtnVal = "de";
            break;
        case "ca.asus.com":
            if (getcookiedata('Lang') == '') {
                rtnVal = "caen";
            }
            else {
                rtnVal = getcookiedata('Lang');
            }
            break;
        case "ru.asus.com":
            rtnVal = "ru";
            break;
        case "www.asus.com.cn":
            rtnVal = "cn";
            break;
        case "www.asus.nl":
            rtnVal = "nl";
            break;
        case "br.asus.com":
            rtnVal = "br";
            break;
        case "www.asus.se":
            rtnVal = "se";
            break;
        case "www.asus.es":
            rtnVal = "es";
            break;
        case "latin.asus.com":
            rtnVal = "ar";
            break;
        case "id.asus.com":
            rtnVal = "id";
            break;
        case "vn.asus.com":
            rtnVal = "vn";
            break;
        case "www.asus.co.th":
            rtnVal = "th";
            break;
        case "hk.asus.com":
            rtnVal = "hk";
            break;
        case "mx.asus.com":
            rtnVal = "mx";
            break;
        case "pt.asus.com":
            rtnVal = "pt";
            break;            
        case "ch.asus.com":
            if (getcookiedata('Lang') == '') {
                rtnVal = "chde";
            }
            else {
                rtnVal = getcookiedata('Lang');
            }
            break;
        case "www.asus.gr":
            rtnVal = "gr";
            break;
        case "be.asus.com":
            if (getcookiedata('Lang') == '') {
                rtnVal = "befr";
            }
            else {
                rtnVal = getcookiedata('Lang');
            }
            break;
        case "ro.asus.com":
            rtnVal = "ro";
            break;
        case "www.asus.rs":
            rtnVal = "rs";
            break;
        default:
            rtnVal = testdefault;
            break;
    }
    return rtnVal;
}

function isMultipleLanguageWebsite() {
    switch (window.location.hostname.toLowerCase()) {
        case "ca.asus.com":
        case "ch.asus.com":
        case "be.asus.com":
            return true;
        default:
            return false;
    }
}

function getGoogleTrackerCode() {

}

function getcookiedata(cookieName) {
    theData = "";
    theCookie = document.cookie + ";";
    start = theCookie.indexOf(cookieName+"=");
    if (start != -1) {
        end = theCookie.indexOf(";", start);
        theData = unescape(theCookie.substring(start + cookieName.length + 1, end));
    }
    return theData.replace(";","");
}

function add_compare_model(cookieName, product_id, model_name) {
    theData = getcookiedata(cookieName);
    if (theData.indexOf(product_id + ".") != -1) {
    }
    else {
        document.cookie = cookieName + "=" + escape(theData + product_id + "." + model_name + ",");
    }
}

function add_cookie(cookieName, cookieContent, windowlife) {
    if (windowlife) {
        document.cookie = cookieName + "=" + cookieContent + ";expires=1990/1/1";
    }
    else {
        document.cookie = cookieName + "=" + cookieContent;
    }
}

function remove_compare_model(cookieName, product_id, model_name) {
    theData = getcookiedata(cookieName);
    theData = theData.replace(product_id + "." + model_name + ",", "");
//    if (theData.length == 1) {
//        document.cookie = cookieName + "=" + escape(theData) + ";expires=1990/1/1";
//    }
//    else {
        document.cookie = cookieName + "=" + escape(theData);
//    }
}

function itemcount(strValue) {
    var items = new Array;
    items = strValue.split(",");
    return items.length;
}

var fileIsExistedreturnvalue;
function fileIsExisted(path) {
    var checkCNT=0;
    var objXHR = createAJAX();
    if (!objXHR) return false;
    try {
        objXHR.open("get", path, false);
        objXHR.send(null);
        while (objXHR.readyState != 4 || checkCNT <= 50) {
            checkCNT = checkCNT + 1;
        }
        return (objXHR.status == 200) ? true : false;
    }
    catch (er) {
        return false;
    }
}

function fileIsExisted_onreadystatechange(obj) {
    if (objXHR.readyState == 4) {
        if (objXHR.status == 200) {
            objXHR.onreadystatechange = null;
            return true;
        }
        else {
            return false;
        }
    }
}


function createAJAX(){
    var HttpRequest = false;
    try {
        HttpRequest = new XMLHttpRequest();
        // for almost all browsers. (Maybe included M$IE7)   
    } catch (tryMSIE) {
        try {
            HttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (tryMSIE2) {
            try {
                HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (NotSupported) {
                HttpRequest = false;
            }
        }
    }
    return HttpRequest;
}

function flash_palyer(strFilename, intHeight, intWidth) {
    var objectflash = "";
    objectflash += "<object codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36' width='" + intWidth + "' height='" + intHeight + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>";
	objectflash += "        <param name='FlashVars' value='' />";
	objectflash += "        <param name='Movie' value='" + strFilename + "' />";
	objectflash += "        <param name='Src' value='" + strFilename + "' />";
	objectflash += "        <param name='WMode' value='Transparent' />";
	objectflash += "        <param name='Play' value='-1' />";
	objectflash += "        <param name='Loop' value='-1' />";
	objectflash += "        <param name='Quality' value='High' />";
	objectflash += "        <param name='SAlign' value='' />";
	objectflash += "        <param name='Menu' value='-1' />";
	objectflash += "        <param name='Base' value='' />";
	objectflash += "        <param name='AllowScriptAccess' value='always' />";
	objectflash += "        <param name='Scale' value='ShowAll' />";
	objectflash += "        <param name='DeviceFont' value='0' />";
	objectflash += "        <param name='EmbedMovie' value='0' />";
	objectflash += "        <param name='BGColor' value='' />";
	objectflash += "        <param name='SWRemote' value='' />";
	objectflash += "        <param name='MovieData' value='' />";
	objectflash += "        <param name='SeamlessTabbing' value='1' />";
	objectflash += "        <param value='false' name='menu' />";
	objectflash += "        <param value='opaque' name='wmode' />";
	objectflash += "        <embed wmode='transparent' flashvars='" + strFilename + "' src='" + strFilename + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + intWidth + "' height='" + intHeight + "'></embed>";
    objectflash += "    </object>";
    return objectflash;
}


//Date Format Functions Begin
Date.prototype.formatDate = function(format) {
    var date = this;
    if (!format)
        format = "yyyy/mm/dd";
    var month = date.getMonth() + 1;
    var year = date.getFullYear();
    format = format.replace("mm", month.toString().padL(2, "0"));

    if (format.indexOf("yyyy") > -1)
        format = format.replace("yyyy", year.toString());
    else if (format.indexOf("yy") > -1)
        format = format.replace("yy", year.toString().substr(2, 2));

    format = format.replace("dd", date.getDate().toString().padL(2, "0"));
    var hours = date.getHours();

    return format;
}

String.prototype.padL = function(width, pad) {
    if (!width || width < 1)
        return this;

    if (!pad) pad = " ";

    var length = width - this.length

    if (length < 1)
        return this.substr(0, width);

    return (String.repeat(pad, length) + this).substr(0, width);
}
String.prototype.padR = function(width, pad) {
    if (!width || width < 1)
        return this;

    if (!pad) pad = " ";

    var length = width - this.length

    if (length < 1) this.substr(0, width);
    return (this + String.repeat(pad, length)).substr(0, width);
}
String.repeat = function(chr, count) {
    var str = "";
    for (var x = 0; x < count; x++) {
        str += chr
    };
    return str;
}

function date_format(da, fo) {

    var date = new Date(da);
    var str = date.formatDate(fo);

    return str;

}

function trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); }
//Date Format Functions End

function youtubePlayer(yHeight, yWidth, URL, obj) {
    var youtubeObj = "<object height='" + yHeight + "' width='" + yWidth + "'><param value='" + URL + "&autoplay=1' name='movie'><param value='true' name='allowFullScreen'><param value='always' name='allowscriptaccess'><embed height='" + yHeight + "' width='" + yWidth + "' allowfullscreen='true' allowscriptaccess='always' type='application/x-shockwave-flash' src='" + URL + "&autoplay=1'></object>";
    $(obj).after(youtubeObj);
    $(obj).hide();
}