
//====AJAX GLOBAL SETTING===
     //Banner ad location
     //var adBanner = "/Images/Ad/inviteyahoo.jpg";
     var adBanner = "/Images/Banner/banner1706.jpg";
     //var onclickEvent = "showPopWin('http://ipass.ionline.vn/InviteYMPage.aspx?serviceId=4', 550, 500, null);";
     var onclickEvent = "showPopWin('/HTML/Invite-Upload.htm?v=2.0', 650, 500, null);";
     
	 Ajax.Responders.register(
	    {
		    onCreate: function(){
		        if (AJAXController.ajax_calling != "getalert")
		        {
	                Element.show('divSystemWorking');
	            }
		    },
		    onComplete: function() {
			    if(Ajax.activeRequestCount == 0){
				    Element.hide('divSystemWorking');
				    }
		    }
	    });
	  //=====END AJAX GLOBAL SETTING===
	  var reportError = function(t) {
	  }

	 var divUserUploadWith = 650;
	 
	 function setAlertDivPosion ()
	 {
	 	var theBody;
	 	if (document.documentElement && document.documentElement.scrollTop)
	 	theBody = document.documentElement;
	 	else theBody = document.body;
	 	
	 	var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
	    var div = $('divAlert');
	    div.style.top = parseInt(scTop) + "px";
	    div.style.left = parseInt(fullWidth-250) + "px";
	    
	    //Set UserUpload Div
	    var div2 = $('divUserUpload');
	    div2.style.top = parseInt(scTop) + "px";
	    div2.style.left = parseInt(fullWidth-divUserUploadWith) + "px";
	 }
	 
	 function LoadAlert ()
	 {
		if(Ajax.activeRequestCount == 0){
	    		AJAXController.MakeAjaxRequestWithCallBack("getalert", "", "divAlert", " Element.show ('divAlert'); ");
	    		 setElementOpacity ('divAlert', 0.9);
		}
	 }
	 
	  function LoadUserUpload ()
	 {
	    divUserUploadWith = 650;
	    AJAXController.MakeAjaxRequestWithCallBack("userupload", "", "divUserUpload", " Element.show ('divUserUpload'); ");
	    setElementOpacity ('divUserUpload', 0.9);
	    setAlertDivPosion ();
	 }
	 
	 function KillAlert ()
	 {
	    if (alertTimer)
	        clearInterval (alertTimer);
	    Element.hide ('divAlert');
	 }
	 
	 function setElementOpacity(element, level) {
      $(element).style.opacity = level;
      $(element).style.MozOpacity = level;
      $(element).style.KhtmlOpacity = level;
      $(element).style.filter = "alpha(opacity=" + (level * 100) + ");";
    }
    
    function handleHistoryEvent(newLocation, historyData) {
         if (newLocation)
        {
            var his = String (newLocation); 
            his = Base64.decode (his);
            if (his != "")
            {
                if (his.indexOf(":") >= 0)
                {
                    var funcName =          String (his.split(":")[0]);
                    var funcCall =          String (his.split(":")[1]);
                    var funcPars =          String (his.split(":")[2]);
                    var funcUpdateElement = String (his.split(":")[3]);
                    var funcCallBack =      String (his.split(":")[4]);
                    
                    try{   
                        var torun = "";
                        if (funcCallBack != "")
                            torun = "AJAXController." + funcName + "('" + funcCall + "','" + funcPars + "','" + funcUpdateElement + "','" + funcCallBack + "')" ;
                        else     torun = "AJAXController." + funcName + "('" + funcCall + "','" + funcPars + "','" + funcUpdateElement + "')" ;
                        eval (torun);
                    }catch (e)
                    {
                    }
                }
            }
        }   
    }
    
    function initialize() {
        //initLightbox();
        window.historyStorage.init();
        window.dhtmlHistory.create();
        dhtmlHistory.initialize();
        dhtmlHistory.addListener(handleHistoryEvent);
        //LoadAlert();
        setAlertDivPosion();
    }
    
    //Change BG
    function ChangBGMain ()
    {
          
    	
        var prefixBGPath = "/Images/Banner/";
        var BGNo = Math.floor( 1 + 4 * Math.random() );
        applyCssPath ("CSSBackGround", "/Css/v3_Bg" + BGNo + ".css");
    }
    
    //Init Alert
    function InitAlert ()
    {
        LoadAlert();
     //Refresh every 30s
     var alertTimer = window.setInterval (function () {LoadAlert();}, 30000);
     //Auto Stop Alert after online 6h and do not close browser
     window.setTimeout (function () {KillAlert();}, 6* 60 * 60000);
    }
    
    
    //Init when page home load
    function InitPageLoad()
    {
        if (window.location.href.indexOf("#") >= 0)
        {
            var query = String (window.location.href.split("#")[1]);
            query = Base64.decode (query);
            if (query != "" && query != "Page:home::mainCenter:")
            {
                if (query.indexOf(":") >= 0)
                {
                    var funcName =          String (query.split(":")[0]);
                    var funcCall =          String (query.split(":")[1]);
                    var funcPars =          String (query.split(":")[2]);
                    var funcUpdateElement = String (query.split(":")[3]);
                    var funcCallBack =      String (query.split(":")[4]);
                    try{   
                        var torun = '';
                        if (funcCallBack != '')
                            torun = "AJAXController." + funcName + "('" + funcCall + "','" + funcPars + "','" + funcUpdateElement + "','" + funcCallBack + "')" ;
                        else     torun = "AJAXController." + funcName + "('" + funcCall + "','" + funcPars + "','" + funcUpdateElement + "')" ;
                        eval (torun);
                        
                    }catch (e)
                    {
                    }
                }
             }
        } else window.location.href = "#" + Base64.encode ("Page:home::mainCenter:");
    }
    
    //Add window event
    addEvent(window, "load", initialize);
   // addEvent(window, "resize", setAlertDivPosion);
//addEvent(window, "scroll", setAlertDivPosion);
