var iInId; 
var iAjx = 0;

function Ajax()
{
  this.toString = function() { return "Ajax"; }
  this.http = new HTTP();

  this.makeRequest = function(_method, _url, _callbackMethod)
  {  
	if(_callbackMethod == _callbackMethod )
	{
		if(iAjx > 0)iAjx--;
	}
	iAjx ++; 
	
    this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
    this.request.onreadystatechange = _callbackMethod; 
    this.request.open(_method, _url, true);
    this.request.send(_url);
  }
  
  this.checkReadyState = function(_id, _1, _2, _3)
  {    
    switch(this.request.readyState)
    {       
      case 1:
		if(document.getElementById("dvLoadingImg") != null)
		{
			document.getElementById("dvLoadingImg").style.display= "block";   
		}
		else
		{
			if(_id != '' && _id != null)
			{
				document.getElementById(_id).innerHTML = "<span style='font-family:arial;font-size:11px;' >"+ _1 +" </span><span style='font-family:arial;font-size:11px;'></span>";  
				BeginPageLoad(_id);
			}
		}
		// document.getElementById(_id).innerHTML = _1;
        break;
      case 2:
		// document.getElementById(_id).innerHTML = _2;
        break;
      case 3:
		// document.getElementById(_id).innerHTML = _3;
        break;
      case 4:  
      
		iAjx --;  
	 	if(document.getElementById("dvLoadingImg") != null)
		{				
			window.clearInterval(iInId);  
			iInId = window.setInterval("EndLoadimg();", 600);				  
 		}
 		else
 		{
 	  		EndPageLoad(); 
 		}
 		
		if(this.http.status(this.request.status) == "success")
		{   
	  		if(this.request.responseText.indexOf('~logout~') != -1)
			{
				fnLogOut();
				return;
			}
		}
		
      return this.http.status(this.request.status);
    }
  }
}

var iLoopCounter = 1;
var iMaxLoop = 5;
var iIntervalId;
var oDiv;

function BeginPageLoad(dvName) 
{  
	if(oDiv != dvName)  
	{
		oDiv = dvName; 
		iIntervalId = window.setInterval("iLoopCounter=UpdateProgressMeter(iLoopCounter,iMaxLoop)", 500);
    }
} 
function EndLoadimg() 
{    

	if(typeof(iInId) != "undefined") 
	{  
		if(iAjx <= 0)
		{
			document.getElementById('dvLoadingImg').style.display = 'none'; 
			window.clearInterval(iInId);   
		}
    }
}
function EndPageLoad() 
{
    if(iAjx <= 0)
	{
		window.clearInterval(iIntervalId); 
    }
}

var iLoadId; 
var oDiv =null;
function fnLoadingImg(obj)
{  
	if(obj == null)
	{
		obj = oDiv;
	}
	else
	{
		oDiv = obj;
	}
	if(obj.innerHTML == "")
	{
		document.getElementById("dvLoadingImg").style.display = "block"; 		
		iLoadId = setTimeout('fnLoadingImg()', 600);
	}	
	else
	{
		document.getElementById("dvLoadingImg").style.display = "none"; 
		window.clearInterval(iLoadId);  	
	}
}

function UpdateProgressMeter(iCurrentLoopCounter, iMaximumLoops) 
{
    iCurrentLoopCounter += 1;
    if(oDiv)
    {
		if(document.getElementById(oDiv).childNodes.length > 1)
		{
			if (iCurrentLoopCounter <= iMaximumLoops)
			{
				document.getElementById(oDiv).childNodes[1].innerHTML += ".";
				return iCurrentLoopCounter;
			}
			else
			{
				document.getElementById(oDiv).childNodes[1].innerHTML = "";
				return 1;
			}
		}
		else
		{	oDiv="";
			return 1;
		}
    }
}

 

 

function HTTP()
{
  this.toString = function() { return "HTTP"; }

  this.status = function(_status)
  {
 
    switch(_status)
    {
      case 200:
        return "success";
        break;
      case 404: 
        return "File not found.";
        break;
      default:
        return "HTTP Status: " + _status;
     }
  }
}



// Custom Select Box//

function fnDDclick(obj)
{ 
	obj = document.getElementById(obj);
	if(navigator.userAgent.indexOf("Firefox")!=-1)
	{    
		
		for(var i=0;i<document.getElementsByName("SlectBox").length; i++ )
		{			 
			document.getElementsByName("SlectBox")[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].style.display = "none";
		} 
		
		obj.childNodes[0].childNodes[1].style.display = "block";
		obj.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.width = obj.clientWidth;
 	}
 	else
 	{
  		for(var i=0;i<document.all.item("SlectBox").length; i++ )
		{
			document.all.item("SlectBox")[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].style.display = "none";
		}   
 		obj.childNodes[0].childNodes[1].style.display = "block";
 	} 
}

document.onmousedown = fnHideDD;

function fnHideDD(e)
{   
	var ev=(e)? e: event;
	var nTarget = (e)? e.target : event.srcElement;
	var nTargetId = (e)? e.target.getAttribute("id") : event.srcElement.id;
	
	
	if(!(nTarget.tagName == "DIV" && nTargetId == "dvScroll"))
	{
	
		if(nTarget.parentNode.tagName != "LI")
		{
			if(navigator.userAgent.indexOf("Firefox")!=-1)
			{    
				if(document.getElementById("SlectBox") != null)
				{
					for(var i=0;i<document.getElementById("SlectBox").length; i++ )
					{ 
						document.getElementById("SlectBox")[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[2].style.display = "none";
					}  			
					if(typeof(document.getElementById("SlectBox").length) == "undefined" )
					{
						document.getElementById("SlectBox").parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[2].style.display = "none";
					}
				} 
				
 			}
 			else
 			{
 			
 				var obj = document.all.item("SlectBox");
 				if(obj != null )
 				{
  					for(var i=0;i<obj.length; i++ )
					{
						obj[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].style.display = "none";
					}    
					if(typeof(obj.length) == "undefined" )
					{	
						obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].style.display = "none";
					}
				} 
 			}
	 		 
 		}  
 			
 			if ( document.getElementById("divMTD") != null && typeof(document.getElementById("divMTD")) != "undefined" )
 			{
 				document.getElementById("divMTD").style.display = "none";
 			}
 			if ( document.getElementById("divEquMTD") != null && typeof(document.getElementById("divEquMTD")) != "undefined" )
 			{
 				document.getElementById("divEquMTD").style.display = "none";
 			}
 			if ( document.getElementById("divCompMTD") != null && typeof(document.getElementById("divCompMTD")) != "undefined" )
 			{
 				document.getElementById("divCompMTD").style.display = "none";
 			}
	}
} 


function getRef(name)
{ 
	return document.getElementById(name);
}

var timerid;
var twidth= "100%";
var theight = 23;
 
function setStatusMsg(message)
{ 
	if(timerid) clearInterval(timerid);  
	getRef("statusbar").innerHTML = "<table cellspacing=0 style='FONT-SIZE: 12px; COLOR: #FF9900; FONT-FAMILY:arial; BACKGROUND-COLOR: #000000;'  cellpadding=3 border=0 width="+twidth+" height="+theight+" align=left><tr><td width=4><table width=4 border=0 cellpadding=0 cellspacing=0><tr><td width=4></td></tr></table></td><td width="+twidth+" align=left valign=middle><B>"+message+"&nbsp;&nbsp;</B></td></tr></table>";
	//<td width=20 align=center><img src='"+imgpath+"/WmAttCan.gif' onclick=\"hideStatus()\"></td>
 	var leftp = 0;//parseInt(screen.width / 2) - 250; 
	getRef("statusbar").style.visibility = 'visible';
	getRef("statusbar").style.display = 'block';
	var topPos = parseInt(document.body.clientHeight) - theight + document.body.scrollTop;;
	getRef("statusbar").style.left = leftp;
	getRef("statusbar").style.top = topPos;
	getRef("statusbar").style.width = twidth; 
	timerid = setInterval(hideStatus, 10000); 
}

function adjustStatusBar()
{
	getRef("statusbar").style.top = parseInt(document.body.clientHeight)-theight+document.body.scrollTop;
}

function hideStatus()
{
	clearInterval(timerid);
	getRef("statusbar").style.visibility = 'hidden';
	getRef("statusbar").style.display = 'none';
	//getRef("statusbar").style.zIndex = -1;
}

//---------Custom Select Box -----//


function fnLogOut()
{  
	if(typeof(top.opener) == 'undefined')
	{
		document.getElementById('aHome').click();
 		return;
	}
	if(typeof(top.opener.document) != 'object')
	{
		document.getElementById('aHome').click();
	}
	else
	{
		top.close(); 		
		top.opener.focus(); 
	}
}

window.document.onkeydown = function(e)
{ 
	var ev=(e)? e: event;
	top.keySarav = ev.keyCode;
}  


function fnsrcElement(e) 
{
	return (window.event) ? window.event.srcElement : e.target;
}
function fnsrcElementId(e) 
{
	return (window.event) ? window.event.srcElement.id : e.target.getAttribute("id");
}


function getObjInnerText(obj)
{ 
 
	var elem = obj;
	if (typeof(elem.text) != "undefined")
	{ 
		return elem.text;
	}
	else if (typeof(elem.textContent) != "undefined")
	{
		return elem.textContent;
	}
	else if (typeof(elem.innerText) != "undefined")
	{
		return elem.innerText;
	} 
}


function fnClick(obj)
{
	if(document.all)
	{
		obj.click();
	}
	else
	{
		clickevent = document.createEvent("MouseEvents")
		clickevent.initEvent("click", true, true) 
		obj.dispatchEvent(clickevent) ; 
	}
}