// JavaScript Document
/*
	Created By		-	kamala Kannan.D
	Created On		-	April,	04,	2008
	@description	-	This JS file is used to include all pages which uses ajax,
						and this page provide functions to create xmlHttpRequest object
*/


/*
	Created By		-	kamala Kannan.D
	Created On		-	March,	31,	2008
	@description	-	This function used to Create and return the XMLDOM
	@return 		-	Object -	XMLDOM
	@param			-	none
*/
function getXMLDom(pmText,xml)
{
	if(xml=='text')
	{
		 try 
			{
			  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			  xmlDoc.async="false";
			  xmlDoc.loadXML(pmText);
			}  
			catch(e)
			{
				try 
				{
					parser=new DOMParser();
					xmlDoc=parser.parseFromString(pmText,"text/xml");
				}
				catch(e)
				{
					alert(e.message);
					return;
				}
			}
			return xmlDoc;
	}
	else
	{
		try 
			{
			  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			  xmlDoc.async="false";
			  xmlDoc.load(pmText);
			}  
			catch(e)
			{
				try 
				{
					xmlDoc=document.implementation.createDocument("","",null);
					xmlDoc.async="false";
					xmlDoc.load(pmText);
				}
				catch(e)
				{
					alert(e.message);
					return;
				}
			}
			return xmlDoc;
	}
	
var xmlDoc;
	   
}

/*
	Created By		-	kamala Kannan.D
	Created On		-	March,	31,	2008
	@description	-	This function used to Create and return the XMLHttpRequest
	@return 		-	Object -	XMLHttpRequest
	@param			-	none
*/
function getXMLHttpRequest()
{
	try
  	{
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		try
      		{
      			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			alert("Your browser does not support AJAX!");
      			return false;
      		}
    	}
  	}
	return xmlHttp;
}

/*
		Created By		-	Kamala Kannan.D
		Created On		-	May 13,2008
		@description	-	To call a server page from the client using the ajax
		@param			-	Object 	XMLHttpRequest object
							String	Servaer page to request and check whether the session exist or not.
							String	Server page to request
							String 	get or post
							String 	QueryString to pass with request
		@return			-	none
*/
function callAjax(pmXmlhttp,pmServerPage,pmGetOrPost,pmParams,pmCallbackMethod)
{
	var oXmlhttp	=	pmXmlhttp;
	var vServerPage	=	pmServerPage;
	var vMethod		=	pmGetOrPost.toLowerCase();
	var vParams		=	pmParams;
	if(oXmlhttp		!= 	null)
	{
		if(vMethod	==	"get")
		{
			url		=	vServerPage+"?"+vParams;
			//Send the proper header information along with the request
			oXmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			oXmlhttp.setRequestHeader("Content-length", params.length);
			oXmlhttp.setRequestHeader("Connection", "close");
			oXmlhttp.open("GET",url,true);
			oXmlhttp.onreadystatechange 	=	pmCallbackMethod; 
		}
		else
		{
			url		=	vServerPage;
			//alert(vServerPage+"?"+vParams);
			oXmlhttp.onreadystatechange = pmCallbackMethod;
		  	oXmlhttp.open('POST', url, true);
		  	oXmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  	oXmlhttp.setRequestHeader("Content-length", vParams.length);
		  	oXmlhttp.setRequestHeader("Connection", "close");
		  	oXmlhttp.send(vParams);
		}
	}
}

/*
		Created By		-		Kamala Kannan.D
		Created On		-		July 03,2008
		@descrption		-		To hit a server page and return whether session exist or not.
		@param			-		String server page		-	This page only used to check whether the session exist or not
		@return 		-		Boolean
*/
function isSessionExist(pmServerPage,pmParams,pmRedirectPath)
{
		var xmlSession		=	null;
		var vResult		=	"";
		var xmlSession;
		var vParams		=	pmParams;
		xmlSession			=	getXMLHttpRequest();
		url				=	pmServerPage;
		xmlSession.onreadystatechange = function() 
									 {		
										if(xmlSession.readyState == 4 && xmlSession.status == 200) 
										{
											vResult			=	xmlSession.responseText;
											if(vResult		==	0)
											{
												alert("Your Session Has Been Expired Please Login");
												window.location = pmRedirectPath;
											}
											
										}
									 }
		xmlSession.open('POST', url, true);
		xmlSession.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlSession.setRequestHeader("Content-length", vParams.length);
		xmlSession.setRequestHeader("Connection", "close");
		xmlSession.send(vParams);
}
