﻿// JScript File
var xmlHttp
function SendRequest(FormName,MethodName,arguments,imageid)
	{
	
	if(FormName.length==0)
		{
			alert ("Please specify form name.")
			return false;
		}

	    xmlHttp=GetXmlHttpObject();
	    
	    if(xmlHttp==null)
		{
			alert('Browser does not support ajax.');
			return false;
		}
		else
		{
			var url=FormName;
			document.getElementById(imageid).style.display='block';
    		xmlHttp.onreadystatechange=function() {stateChanged(imageid)}
	    	xmlHttp.open("POST",url,true)
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			arguments=document.getElementById(arguments).value;
			
			xmlHttp.send("Method="+MethodName+"&args="+arguments+"")
			
			return true;
		}
		xmlHttp=null;
}
function stateChanged(id) 
{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var str=xmlHttp.responseText ;
			
			if(str.length!=0)
			{
			    eval("fu = function() {" + str + "}");
			    fu();
			}
			document.getElementById(id).style.display='none';
		} 
		
} 
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function SendRequestWithControl(FormName,FormData,AckFunction)
	{
	
	if(FormName.length==0)
		{
			alert ("Please specify form name.")
			return false;
		}

	    xmlHttp=GetXmlHttpObject();
	    
	    if(xmlHttp==null)
		{
			alert('Browser does not support ajax.');
			return false;
		}
		else
		{
			var url=FormName;
    		xmlHttp.onreadystatechange=function() {AckFunction(xmlHttp)};
	    	xmlHttp.open("POST",url,true)
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			xmlHttp.send(FormData)
			return true;
		}
		xmlHttp=null;
}
// This is for Ajax : End
function FillCombo(id,arr)
{
    hidid=id.replace("_","$");
    hidid=hidid.replace("_","$");

    document.getElementById('_'+hidid).value='';
    
	for(i=0;i<arr.length;i++)
	{
		document.getElementById(id).options[i]=new Option(arr[i][0],arr[i][1]);	
		if(document.getElementById('_'+hidid).value=='')
		{
		    document.getElementById('_'+hidid).value=arr[i][0]+':'+arr[i][1];    
		}
		else
		{
		    document.getElementById('_'+hidid).value=document.getElementById('_'+hidid).value+';'+arr[i][0]+':'+arr[i][1];
		}
	}
}
function FillOnlyCombo(id,arr)
{
    var t=true;
    while(t)
    {
        var lenc=document.getElementById(id).options.length;
        for(i=0;i<lenc;i++)
	    {
	   
		   document.getElementById(id).options[i]=null;	
	    }
	    if(document.getElementById(id).options.length==0)
	        t=false;
	}
	for(i=0;i<arr.length;i++)
	{
	
		document.getElementById(id).options[i]=new Option(arr[i][0],arr[i][1]);	
	}
	
}