var DB88 = {}
if (typeof(YAHOO) != "undefined") {
    YAHOO.namespace("example.container");
}
var postCatID = "";
var childWin = null;
var isMasterDisabled = 0;
var currentPath = window.location.href.substr(0,window.location.href.lastIndexOf("/")+1); 
var tempPopup = "";
var closeCaption = "Close";
var yesCaption = "Yes";
var noCaption = "No";
var passwordCaption = 'Password';
var loginEmailCaption = 'Login e-mail';
var loginCaption = 'Login';
var forgotPasswordQuestionMarkCaption = 'Forgot password?';
var notA88DBMemberCaption = 'Not a 88DB Member?';
var registerNowCaption = 'Register Now';
var canelCaption = 'Canel';
var enterEmailForPasswordCaption = 'To retrieve your password, please enter the registered e-mail address below.';
var emailAddressCaption = 'E-mail Address';
var submitCaption = 'Submit';
var youCanNowAddFavouriteCaption = 'You can add favourite now.';


function hideObj(objName) {
  var obj = document.getElementById(objName);
  obj.style.visibility='hidden';
  obj.style.display='none';
}







 function MasterChannelChangeToOrange(thisID)
 {
      document.getElementById(thisID).style.zIndex=12;
      if(NavigatorDefaultChannel==thisID)return false;
      if(document.getElementById(thisID) != null)
      {
          document.getElementById(thisID).childNodes[1].style.color="#f27900";
          document.getElementById(thisID).style.backgroundImage="url('')";
          if(thisID=="liAllCategory")document.getElementById("navArrowImg").src="icon_navArrowDown.gif";
      }  
      
 }
  function MasterChannelChangeToGray(thisID)
 {  
    if(NavigatorDefaultChannel==thisID)return false;
    if(document.getElementById(thisID) != null)
    {
        document.getElementById(thisID).childNodes[1].style.color="#444444";
        document.getElementById(thisID).style.backgroundImage="url('bg_nav.gif')";
        if(thisID=="liAllCategory")document.getElementById("navArrowImg").src="icon_navArrowRight.gif";
    }  
 }

function MoveDivToDiv()
{
    /*var toDivId = "Div_MarketingHtmlLeft";
    var fromDivId = "_ctl0_DB88ContentHolder_MarketingHtmlLeft_pnlMarketingHtml";*/
    var objToDiv = document.getElementById("Div_MarketingHtmlLeft");
    var objFromDiv = document.getElementById("_ctl0_DB88ContentHolder_MarketingHtmlLeft_pnlMarketingHtml");
    if(objToDiv != undefined && objToDiv != null)
    {
        if(objFromDiv != undefined && objFromDiv != null)
        {
            objToDiv.innerHTML = objFromDiv.innerHTML;
        }
    }
}
if (window.addEventListener)
    window.addEventListener("load", MoveDivToDiv, false);
else if (window.attachEvent)
    window.attachEvent("onload", MoveDivToDiv);
else
    window.onload = MoveDivToDiv;


//--------------------------stringbuilder class
StringBuilder = function() {
    this._strings = new Array();
    
    this.append = function(str) {
        this._strings.push(str);
    }
        
    this.toString = function() {
        var separator = arguments.length == 0 ? "" : arguments[0];
        return this._strings.join(separator);
    }
};

//ajax post
AjaxPost = function(dataContainerId, url) {

    this.xmlHttp = null;
    this.dataContainerId = dataContainerId;

    this.createXhr = function() {       
        var msXmlIds = [
            'MSXML2.XMLHTTP.3.0',   //3.0 version is best than other MSXML2.XMLHTTP
		    'MSXML2.XMLHTTP',
		    'Microsoft.XMLHTTP'
		    ];
        
        try {
            this.xmlHttp = new XMLHttpRequest();
        } catch (e1) {
            for (var i = 0; i < msXmlIds.length; ++i) {
                try {
                    this.xmlHttp = new ActiveXObject(msXmlIds[i]);
                    break;
                }
                catch (e2) {

                }
            }
        }
    }

    
    function getData(dataContainer) {
        var sbData = new StringBuilder();        
        var fields;
        if (dataContainer.tagName.toLowerCase() == "form") {
            fields = dataContainer.elements;    
        } else {
            fields = getDataElements(dataContainer);            
        }
        for (var i = 0; s = fields.length, i < s; i++) {
            if ((name = fields[i].name) && (value = fields[i].value)) {
                sbData.append(name + "=" + encodeURIComponent(value));
            }
        }
        return sbData.toString("&");
    }
    
    this.onSuccess = function(xmlHttp) {};
    this.onFailure = function(xmlHttp) {};
    
    this.additionalData = "";    //format: "PostId=123456&Name=db88"
        
    this.post = function() {
        if (!this.xmlHttp) this.createXhr();
        var dataContainer = document.getElementById(this.dataContainerId);
        if (!dataContainer) return;

        var postData = getData(dataContainer); //collect data   
             
        ajaxPost = this;    
        ajaxPost.xmlHttp.onreadystatechange = function() {
            if (ajaxPost.xmlHttp.readyState == 4) {
                if (ajaxPost.xmlHttp.status == 200) {
                    if (ajaxPost.onSuccess) {
                        ajaxPost.onSuccess.apply(ajaxPost.onSuccess, [ajaxPost.xmlHttp]);
                    }
                } else {
                    if (ajaxPost.onFailure) {
                        ajaxPost.onFailure.apply(ajaxPost.onFailure, [ajaxPost.xmlHttp]);
                    }
                }
            }
        }

        if (this.xmlHttp.overrideMimeType) {            
            this.xmlHttp.overrideMimeType("text/html");
        }
        
        this.xmlHttp.open("POST", url, true);
        //add this row.sure it is post method
        //this row must open method belowe        
        this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
        this.xmlHttp.setRequestHeader("Content-length", postData.length);
        this.xmlHttp.setRequestHeader("Connection", "close");
        if (this.additionalData == "") {
            this.xmlHttp.send(postData);
        } else {
            this.xmlHttp.send(postData + "&" + this.additionalData);
        }
    }
};

//{success: fucntion, failure: function}
AjaxGet = function(url, handler) {

    this.xmlHttp = null;    

    this.createXhr = function() {       
        var msXmlIds = [
            'MSXML2.XMLHTTP.3.0',   //3.0 version is best than other MSXML2.XMLHTTP
		    'MSXML2.XMLHTTP',
		    'Microsoft.XMLHTTP'
		    ];
        
        try {
            this.xmlHttp = new XMLHttpRequest();
        } catch (e1) {
            for (var i = 0; i < msXmlIds.length; ++i) {
                try {
                    this.xmlHttp = new ActiveXObject(msXmlIds[i]);
                    break;
                }
                catch (e2) {

                }
            }
        }
    };
        
    this.get = function() {
        if (!this.xmlHttp) this.createXhr();
                     
        ajaxGet = this;    
        this.xmlHttp.onreadystatechange = function() {
            if (ajaxGet.xmlHttp.readyState == 4) {
                if (ajaxGet.xmlHttp.status == 200) {
                    if (handler && handler.success) {
                        handler.success.apply(handler.success, [ajaxGet.xmlHttp]);
                    }
                } else {
                    if (handler && handler.failure) {
                        handler.failure.apply(handler.failure, [ajaxGet.xmlHttp]);
                    }
                }
            }
        }
        
        this.xmlHttp.open("GET", url, true);
        this.xmlHttp.send(null);
    };
};


WatermarkText = function(textId, waterText) {
    
    this.initialValue = waterText;    
    this.id = textId;
    
    this.control = document.getElementById(textId);    
    this.control.value = this.initialValue || this.control.value;
    this.control.style.color = "#c0c0c0";
    //add custom attribute
    this.control.watermark = "true";
    
    var watermarkText = this;
    
    var onblur = function() {
        if (watermarkText.control.value == "" || watermarkText.control.value == watermarkText.initialValue) {            
            watermarkText.control.value = watermarkText.initialValue;
            watermarkText.control.style.color = "#c0c0c0";
        } else {
            watermarkText.control.style.color = "#000000";
        }
    };
    
    var onfocus = function() {
        if (watermarkText.control.value == waterText) {            
            watermarkText.control.value = "";
        }
        watermarkText.control.style.color = "#000000";
    };
        
    this.getValue = function() {
        return this.control.value;
    };
    
    this.setValue = function(value) {
        this.control.value = value;
    };
    
    if (window.ActiveXObject) { //IE
        this.control.attachEvent("onblur", onblur);
        this.control.attachEvent("onfocus", onfocus);
    } else {    //Mozilla
        this.control.addEventListener("blur", onblur, false);
        this.control.addEventListener("focus", onfocus, false);
    }   
};

