﻿var isie = (navigator.userAgent.toLowerCase().indexOf('msie') != -1) ? true : false;
var _httpsUrl = 'https://www.yes24.vn';
var _httpUrl = 'http://www.yes24.vn';

function onUpdating(imageUrl, width, height, padding) {
    document.body.style.cursor = "wait";
    var loading = document.createElement("img");
    loading.id = "loading";
    loading.style.position = "absolute";
    loading.style.zIndex = "0";
    loading.src = imageUrl;
    loading.border = 0;
    if (width != null)
        loading.style.width = width;

    if (height != null)
        loading.style.height = height;

    if (padding == null)
        padding = 0;

    document.body.appendChild(loading);
    loading.style.posLeft = ((document.documentElement.clientWidth - padding) / 2) + document.documentElement.scrollLeft;
    loading.style.posTop = ((document.documentElement.clientHeight - 50) / 2) + document.documentElement.scrollTop;
    setTimeout("onUpdated()", 5000);
}

function onUpdated() {
    document.body.style.cursor = "default";
    var loading = document.getElementById("loading");
    if (loading != null)
        document.body.removeChild(loading);
}

function swf(src, w, h, n, flashvar) {
    if (flashvar == null)
        flashvar = "";

    html = '';
    if (isie) {
        html = '<object id = "' + n + '"  type="application/x-shockwave-flash"  width="' + w + '" height="' + h + '">';
        html += '<param name="movie" value="' + src + '">';
        html += '<param name="quality" value="high">';
        html += '<param name = "allowScriptAccess" value = "always" />';
        html += '<param name = "wmode" value = "transparent" />';
        html += '<param name="flashvars" value="wsPath=' + _flashWS + '&linkDomain=' + _httpUrl + flashvar + '" /> ';
        html += '</object>';
    } else {
        html = '<embed id = "' + n + '" name="' + n + '" ';
        html += 'type="application/x-shockwave-flash" ';
        html += 'pluginspage = "http://www.macromedia.com/go/getflashplayer" ';
        html += 'width = "' + w + '" height = "' + h + '" ';
        html += 'src = "' + src + '" ';
        html += 'quality = "high" ';
        html += 'allowScriptAccess = "always" ';
        html += 'wmode = "transparent" ';
        html += 'flashvars = "wsPath=' + _flashWS + '&linkDomain=' + _httpUrl + flashvar + '">';
        html += '</embed>';
    }
    
    document.write(html);
}

function swf2(src, w, h, n, flashvar, d) {
    if (flashvar == null)
        flashvar = "";

    var obj = document.getElementById(d);

    html = '';
    if (isie) {
        html += '<object id = "' + n + '"  type="application/x-shockwave-flash"  width="' + w + '" height="' + h + '">';
        html += '<param name="movie" value="' + src + '">';
        html += '<param name="quality" value="high">';
        html += '<param name = "allowScriptAccess" value = "always" />';
        html += '<param name = "wmode" value = "transparent" />';
        html += '<param name="flashvars" value="wsPath=' + _flashWS + '&linkDomain=' + _httpUrl + flashvar + '" /> ';
        html += '</object>';
    } else {
        html = '<embed id = "' + n + '" name="' + n + '" ';
        html += 'type="application/x-shockwave-flash" ';
        html += 'pluginspage = "http://www.macromedia.com/go/getflashplayer" ';
        html += 'width = "' + w + '" height = "' + h + '" ';
        html += 'src = "' + src + '" ';
        html += 'quality = "high" ';
        html += 'allowScriptAccess = "always" ';
        html += 'wmode = "transparent" ';
        html += 'flashvars = "wsPath=' + _flashWS + '&linkDomain=' + _httpUrl + flashvar + '">';
        html += '</embed>';
    }

    obj.innerHTML = html;
}

function insertGnb() {
    swf2('/5TFlash/gnbnavi.swf', '740px', '460px', "gnbnavi", "&textBanner1=316850&textBanner2=TB1&multiBanner1=316850&multiBanner2=MB1&multiBanner3=316850&multiBanner4=MB2", "dvAllCategory")
}

function openCategory(act, h) {
    var obj = $("#dvDepth");
    if (act == "open") {
        obj.width(605);
        obj.height(h);
    }
    else {
        obj.width(605);
        obj.height(31);
    }
}

function gnbOpen(act) {
    var obj = $get("dvAllCategory");
    if (act == "open") {
        obj.style.width = "735px";
        obj.style.height = "450px";
        obj.style.overflow = "";
    }
    else {
        obj.style.width = "185px";
        obj.style.height = "31px";
        obj.style.overflow = "hidden";
    }
}

function searchOpen(act) {
    var obj = $get("dvSearch");
    if (act == "open") {
        obj.style.width = "547px";
        obj.style.height = "300px";
        obj.style.overflow = "";
    }
    else {
        obj.style.width = "547px";
        obj.style.height = "31px";
        obj.style.overflow = "hidden";
    }
}

function searchMsg(msg) {
    alert(msg);
}

function closeAll(n) {
    var obj = $get(n);
    if (obj != null)
        obj.closeAll();
}

/*********** Category Main Flash *******************/
function layerWidthLnb(_w, _h) {
    var width = parseInt(_w) + 10;
    var height = parseInt(_h) + 10;

    var dvLnbNav = $("#dvlnbnavi");
    if (dvLnbNav != null) {
        dvLnbNav.width(width);
        dvLnbNav.height(height);
    }
}

function layerHeightLnb(_h) {
    var height = parseInt(_h) + 10 + "px";

    var dvLnbNav = $("#dvlnbnavi");
    var dvLnb = $("#dvCategoryLNB");

    if (dvLnbNav != null) {
        dvLnbNav.height(height);
    }

    if (dvLnb != null)
        dvLnb.height(height);
}


/*********** SkyScraper *********************/
function GetSkyData() {
    var cookie = new Cookie();
    var links = "";
    var imgs = "";
    var linkData = cookie.Read("skyUrl");
    if (linkData != null && linkData != '')
        links = linkData;

    var imgData = cookie.Read("skyImage");
    if (imgData != null && imgData != '')
        imgs = imgData;

    var param = "&loginId=&linkStr=" + links + "&imgStr=" + imgs;
	 
    return param;
}

function SetSkyData(productCode, imageName) {
    var cookie = new Cookie();
    var linkData = cookie.Read("skyUrl");
    var imgData = cookie.Read("skyImage");
    var arrLink = new Array();
    var arrImage = new Array();
    
    if (linkData != null && linkData != '')
        arrLink = linkData.split(',');

    if (imgData != null && imgData != '')
        arrImage = imgData.split(',');

    if (ArrContains(arrLink, productCode)) {
        return;
    }
    
    linkData = productCode;
    imgData = imageName;

    if (arrLink.length > 0) {
        if (arrLink.length >= 10) {
            ArrRemove(arrLink, 10);
            ArrRemove(arrImage, 10);
        }

        for (var i = 0; i < arrLink.length; i++) {
            linkData += "," + arrLink[i];
            imgData += "," + arrImage[i]
        }
    }

    var date = new Date();
    date.setTime(date.getTime()+(7*24*60*60*1000));

    cookie.Save("skyUrl", linkData, "/", date.toGMTString());
    cookie.Save("skyImage", imgData, "/", date.toGMTString());
}

function ArrRemove(array, from, to) {
    var rest = array.slice((to || from) + 1 || array.length);
    array.length = from < 0 ? array.length + from : from;
    return array.push.apply(array, rest);
};

function ArrContains(array, matchToValue) {
    for (var i = 0; i < array.length; i++) {
        if (matchToValue == array[i])
            return true;
    }
    return false;
}

function GoNameLink(name) {
    document.location.href = "#" + name;
}

/************** Web Service *******************/
function GetSuggestionList(prefixText, count, name) {
    var pl = new SOAPClientParameters();
    pl.add("prefixText", prefixText);
    pl.add("count", count);
    var result = SOAPClient.invoke(_flashWS, "GetSuggestionList", pl, false);
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetSuggestionList(result);
}

function GetBanner(categoryNo, areaId, name) {
    var pl = new SOAPClientParameters();
    pl.add("categoryNo", categoryNo);
    pl.add("areaId", areaId);
    SOAPClient.invoke(_flashWS, "GetBanner", pl, true, GetBanner_CallBack, name);
}

function GetBanner_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetBanner(result);
}

function GetMultiBanner(categoryNo, areaId, name) {
    var pl = new SOAPClientParameters();
    pl.add("categoryNo", categoryNo);
    pl.add("areaId", areaId);
    SOAPClient.invoke(_flashWS, "GetMultiBanner", pl, true, GetMultiBanner_CallBack, name);
}

function GetMultiBanner_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetMultiBanner(result);
}

function GetTextBanner(categoryNo, areaId, name) {
    var pl = new SOAPClientParameters();
    pl.add("categoryNo", categoryNo);
    pl.add("areaId", areaId);
    SOAPClient.invoke(_flashWS, "GetTextBanner", pl, true, GetTextBanner_CallBack, name);
}

function GetTextBanner_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetTextBanner(result);
}

function GetHitKeyword(name) {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(_flashWS, "GetHitKeyword", pl, true, GetHitKeyword_CallBack, name);
}

function GetHitKeyword_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetHitKeyword(result);
}

function GetFirstCategory(name) {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(_flashWS, "GetFirstCategory", pl, true, GetFirstCategory_CallBack, name);
}

function GetFirstCategory_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetFirstCategory(result);
}

function GetItemZone(name) {
    var pl = new SOAPClientParameters();
    var result = SOAPClient.invoke(_flashWS, "GetItemZone", pl, false);
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetItemZone(result);
}

function GetBrandZone(categoryNo, name) {
    var pl = new SOAPClientParameters();
    var result = SOAPClient.invoke(_flashWS, "GetBrandZone", pl, false);
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetBrandZone(result);
}

function GetSubCategory(categoryNo, name) {
    var pl = new SOAPClientParameters();
    pl.add("categoryNo", categoryNo);
    SOAPClient.invoke(_flashWS, "GetSubCategory", pl, true, GetSubCategory_CallBack, name);
}

function GetSubCategory_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetSubCategory(result);
}

var _categoryTreeData = null;
var _name = null;

function GetCategoryTree(name) {
    if (_categoryTreeData != null) {
        var obj = document.getElementById(name);
        if (obj != null)
            obj.GetCategoryTree(_categoryTreeData);

        return;
    }

    var pl = new SOAPClientParameters();
    _categoryTreeData = SOAPClient.invoke(_flashWS, "GetCategoryTree", pl, false);
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetCategoryTree(_categoryTreeData);
}

function GetProductList(categoryNo, areaId, rowCount, name) {
    var pl = new SOAPClientParameters();
    pl.add("categoryNo", categoryNo);
    pl.add("areaId", areaId);
    pl.add("rowCount", rowCount);
    SOAPClient.invoke(_flashWS, "GetProductList", pl, true, GetProductList_CallBack, name);
}

function GetProductList_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetProductList(result);
}

function GetCurrentDateString(name) {
    var pl = new SOAPClientParameters();
    SOAPClient.invoke(_flashWS, "GetCurrentDateString", pl, true, GetCurrentDateString_CallBack, name);
}

function GetCurrentDateString_CallBack(result, req, name) {
    var obj = document.getElementById(name);
    if (obj != null)
        obj.GetCurrentDateString(result);
}

function GetMemberInfo(loginId, name) { 
 
    var pl = new SOAPClientParameters();
    pl.add("loginId", loginId);
    var result = SOAPClient.invoke(_flashWS, "GetMemberInfo", pl, false);
	var obj;   
 	if (navigator.appName.indexOf("Microsoft") != -1) {
             obj= window[name];
         } else {
             obj= document[name];
       } 
    if (obj != null)
        obj.GetMemberInfo(result);
}

function GetUserName() {	
    var pl = new SOAPClientParameters();
    var result = SOAPClient.invoke(_flashWS, "GetUserName", pl, false);
	var obj;	
	if (navigator.appName.indexOf("Microsoft") != -1) {
             obj= window["skyScraper"];
         } else {
             obj= document["skyScraper"];
       } 
    if (obj != null)	
		obj.GetUserName(result)
        
}

function InitText(target, type) {
    if (target.value == target.defaultValue && type == 0) target.value = '';
    if (!target.value && type == 1) target.value = target.defaultValue;
}

function ModalResize(w, h) {
    if (isie) {
        window.dialogWidth = w + "px";
        window.dialogHeight = h + "px";
    }
    else {
        window.resizeTo(w, h +45);
    }
}

function SetMenuSrc(id) {
    var obj = document.getElementById(id);
    if (obj != null) {
        var src = obj.src.replace("_off", "_on");
        obj.src = src;
    }
}

//-----------------------POPUP--------------------------
function windowOpen(URL, Width, Height, scroll, resize) {
    window.open(URL, 'Popup01', 'left=0,top=0,width=' + Width + ', height=' + Height + ',scrollbars=' + scroll + ',toolbars=no,status=0,menubar=0,location=0,titlebar=no,resizable=' + resize);
}


/*
function GetSuggestionList(prefixText, count, name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetSuggestionList(prefixText, count, OnSuggestionListComplete, OnError, name);
    }
}

function OnSuggestionListComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetSuggestionList(result);
}

function GetBanner(categoryNo, areaId, name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetBanner(categoryNo, areaId, OnBannerComplete, OnError, name);
    }
}

function OnBannerComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetBanner(result);
}

function GetMultiBanner(categoryNo, areaId, name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetMultiBanner(categoryNo, areaId, OnMultiBannerComplete, OnError, name);
    }
}

function OnMultiBannerComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetMultiBanner(result);
}

function GetTextBanner(categoryNo, areaId, name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetTextBanner(categoryNo, areaId, OnGetTextBannerComplete, OnError, name);
    }
}

function OnGetTextBannerComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetTextBanner(result);
}

function GetHitKeyword(name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetHitKeyword(OnHitKeywordComplete, OnError, name);
    }
}

function OnHitKeywordComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetHitKeyword(result);
}

function GetFirstCategory(name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetFirstCategory(OnFirstCategoryComplete, OnError, name);
    }
}

function OnFirstCategoryComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetFirstCategory(result);
}

function GetItemZone(name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetItemZone(OnGetItemZoneComplete, OnError, name);
    }
}

function OnGetItemZoneComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetItemZone(result);
}

function GetBrandZone(name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetBrandZone(OnBrandZoneComplete, OnError, name);
    }
}

function OnBrandZoneComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetBrandZone(result);
}

function GetSubCategory(name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetSubCategory(OnSubCategoryComplete, OnError, name);
    }
}

function OnSubCategoryComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetSubCategory(result);
}

var _categoryTreeData = null;
var _name = null;

function GetCategoryTree(name) {
    if (_categoryTreeData != null) {
        var obj = document.getElementById(name);
        if (obj != null)
            obj.GetCategoryTree(_categoryTreeData);

        return;
    }

    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetCategoryTree(OnCategoryTreeComplete, OnError, name);
    }
}

function OnCategoryTreeComplete(result, name) {
    _categoryTreeData = result;
    var obj = document.getElementById(name);
    
    if (obj != null)
        obj.GetCategoryTree(result);
}

function GetProductList(categoryNo, areaId, rowCount, name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetProductList(categoryNo, areaId, rowCount, OnProductListComplete, OnError, name);
    }
}

function OnProductListComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetProductList(result);
}

function GetCurrentDateString(name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetProductList(OnCurrentDateStringComplete, OnError, name);
    }
}

function OnCurrentDateStringComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetCurrentDateString(result);
}

function GetMemberInfo(loginId, name) {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetMemberInfo(loginId, OnMemberInfoComplete, OnError, name);
    }
}

function OnMemberInfoComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetMemberInfo(result);
}

function GetUserName() {
    if (typeof (iStyle24) != 'undefined') {
        iStyle24.V3.Web.WSIF.Flash.GetUserName(OnGetUserNameComplete, OnError, "skyScraper");
    }
}

function OnGetUserNameComplete(result, name) {
    var obj = document.getElementById(name);

    if (obj != null)
        obj.GetUserName(result);
}
*/
function OnError(result) {
    //alert(result.get_message());
}
