var ie=document.all && !window.opera;
var dom=document.getElementById;
iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
//var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
var docheight=(ie)? iebody.clientHeight: window.innerHeight;
var ChangeLayout = false;
// su dung gsubmit de xac dinh la trang co can check login hay khong
// mac dinh khi form submit thi no se check gsubmit de ve server kiem tra session
var gsubmit = false;
var eventtarget = "";
var httpRequest;
if (window.XMLHttpRequest) {
    httpRequest = new XMLHttpRequest();
}	
else {
    if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
} 

var Calgie = {};
	Calgie.Culture = {Vietnam :"vi-VN", US : "en-US" };
var INNO={};
var portal = {
    language:"vi-VN",
    dateFormat:"dd/MM/yyyy",
    pathroot:"#",
    pagename:"",
    appid:"1",
    iscookies:true,
    ismember:false,
    login:false,
    owner:"",
    sessiontimeout:20,
    siteid:"0",
    username:"",
    CallServer:function(url,data,CallBack) 
    {
       
        var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;    
        httpRequest.open( "POST", url, true );        
        httpRequest.setRequestHeader("Content-type", "text/xml"); 
        httpRequest.onreadystatechange = CallBack;
        httpRequest.send(data); 
    }   
    }
		


var httpRequest;
if (window.XMLHttpRequest) {
    httpRequest = new XMLHttpRequest();
}	
else {
    if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

CallServer=function(url,data,CallBack) 
{
   
    var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
//    document.getElementById("Loading").style.top=scroll_top+"px";
//    document.getElementById("Loading").style.display = "block";
    var pathurl = window.location.search.split('&');
    
    var sitename;
    
    for (var i=0; i<pathurl.length; i++)
    {
        if (pathurl[i].toLowerCase().indexOf('sitename')>=0)
        {
            
            sitename=pathurl[i].split('=')[1];
            break;
        }
    }
    
    httpRequest.open( "POST", url+'?SiteID='+portal.siteid + "&sitename=" + sitename, true );
    httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
    httpRequest.onreadystatechange = CallBack;
    httpRequest.send(data); 
} 

function getResult()
{
       if (httpRequest.readyState == 4 && httpRequest.status == 200) 
        {
            document.getElementById("Loading").style.display = "none";
            var a = httpRequest.responseText; 
        }
}
function CheckSession()
{
    if (!gsubmit) 
    {
        CallServer(portal.pathroot + 'sec/checksession.aspx','',getResultSession); 
        return false;
    } 
    else 
        return true;
}
function getResultSession()
{
       if (httpRequest.readyState == 4 && httpRequest.status == 200) 
        {
            if (httpRequest.responseText=="1")
            {
                //alert(httpRequest.responseText);
                gsubmit = true;
                document.forms[0].submit();
            }
            else
            {
                eventtarget = httpRequest.responseText;
                Show(document.getElementById("dlogin"));
            }
            Hide(document.getElementById("Loading"));
        }
}
function getResultLogin()
{
       if (httpRequest.readyState == 4 && httpRequest.status == 200) 
        {
            if (httpRequest.responseText=="1")
            {
                Hide(document.getElementById("dlogin"));
                gsubmit = true;
            }
            else
            {
                document.getElementById("lb_login_error").innerText = httpRequest.responseText;
            }
            Hide(document.getElementById("Loading"));
        }
}
function UnHighlight(){}

function Highlight(){}

function HasPageValidators()
{
    var hasValidators = false;
  
    try
    {
        if (typeof Page_Validators === 'undefined'?false:Page_Validators.length > 0)
        {
            hasValidators = true;
        }
    }
    catch (error)
    {
    }
  
    return hasValidators;
}
//      
function ValidationGroupEnable()
{
    if (HasPageValidators())
    {
        for(i=0; i < Page_Validators.length; i++)
        ValidatorEnable(Page_Validators[i], false);                             
    }
}
//===============Loi-Loading================

function creatediv(id)
{
   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);      
   newdiv.style.background = "White";
   newdiv.style.position = "absolute";
   newdiv.style.zIndex = 100000;
   newdiv.style.textAlign = "center";
   newdiv.style.opacity = 0.5;
   newdiv.style.filter = "alpha(opacity=50)";
   img = document.createElement('img');
   img.src = "images/Loading.gif";
   newdiv.appendChild(img);
   document.body.appendChild(newdiv);   
} 	
function removediv(id)
{
    var dv=document.getElementById(id);
    if(dv!=null)
    {
    document.body.removeChild(id);   
    }
}
function getLeft(obj)	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft;
				if (obj.style && obj.style.overflowX == 'scroll')
				{
					curleft -= obj.scrollLeft;
				}
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}

function getTop(obj) {
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop;
				if (obj.style && obj.style.overflowY == 'scroll')
				{
					curtop -= obj.scrollTop;
				}
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

var secs_hideUpdatePageNote = 3;                                

function hideUpdatePageNote() {                                 
    secs_hideUpdatePageNote--;                              
    if(secs_hideUpdatePageNote == 0) { 
        $('#spDesign').html('');               
        $('#spDesign').fadeOut();
    }
    else 
    {                     
        setTimeout("hideUpdatePageNote()",1000);
    }
}  

function GoPage(url)
{
   location.href = url;
}
//=====================end Loi Loading===========================

function AddEvent(ele, eventName, func)
{
    if(window.addEventListener){ // Mozilla, Netscape, Firefox
        ele.addEventListener(eventName, func, false);
    } else { // IE
        ele.attachEvent('on' + eventName, func);	            
    }
}  
function isCompleted(e)
{           
} 
function isDeleted(e)
{
}      
function isCanceled(e)
{
}   
function SelectAllCheckboxes(Chk,FullName){
    var xState=Chk.checked;	
	var elm=Chk.form.elements;
	for(i=0;i<elm.length;i++)
	    if(elm[i].type=="checkbox" && elm[i].id.substring(elm[i].id.length-FullName.length)==FullName)
		{
    		if(elm[i].checked!=xState)
	    	    elm[i].click();
		}
}       
