

/* The following function creates an XMLHttpRequest object... */
var elementId="";
var loadingMesg="";
function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{

		/* Create the object using other browser's method */

		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}


var http = createRequestObject();
function getRequest(url,id,msg){
	
//alert("from ajax:--"+url);
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url...
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the
		index of the selected item.
	*/
	elementId=id;
    var div = document.createElement('div');	
	div.innerHTML = msg ;
    loadingMesg = div.innerHTML;
//	alert(url);
	http.open('get', url);

	/* Define a function to call once a response has been received. This will be our

		handleProductCategories function that we define below. */

	http.onreadystatechange = ManipulateRequest;

	/* Send the data. We use something other than null when we are sending using the POST

		method. */

		//alert(http.readyState);

	http.send(null);

}



function ManipulateRequest(){

	/* Make sure that the transaction has finished. The XMLHttpRequest object

		has a property called readyState with several states:

		0: Uninitialized

		1: Loading

		2: Loaded

		3: Interactive

		4: Finished */

	if(loadingMesg=="") var msg="";//<FONT><B>Loading please wait.........</B></FONT>";

		else msg=loadingMesg;

	if(http.readyState == 1)

		{

		//alert("ok");	

		  if(document.getElementById(elementId))

			document.getElementById(elementId).innerHTML=msg;								

		}

	else if(http.readyState == 4){ //Finished loading the response

		/* We have got the response from the server-side script,

			let's see just what it was. using the responseText property of

			the XMLHttpRequest object. */



		var response = http.responseText;		

      //   alert("reponse is"+response);

		//var m = response ;

		

		// alert("res from ajzx:---"+response);		

		 //return false;



		var testFull = response ; 

		

		/* And now we want to change the product_categories <div> content.

			we do this using an ability to get/change the content of a page element

			that we can find: innerHTML. */



	 // abc = response.ownerDocument

		var arrMessage = response.split("<!--jsvalidationcode-->");



		 if(arrMessage[1])

				{

				   //var strJavascriptCode = arrMessage[1].replace("<script language=\"javascript\">", "");

				   var s = new String(arrMessage[1]);

				   s = s.replace(/<script language=\"javascript\">/gi,""); // Replaces main script tags



				   s = s.replace(/<script language=\"JavaScript\" type=\"text\/javascript\">/gi,"");  // Replaces main script tags

					s = s.replace(/<script type=\"text\/javascript\">/gi,"");  // Replaces main script tags

				   s = s.replace(/<\/script>/gi,"");  // Replaces </script>



				   s = s.replace(/<!--/gi,"");  // Replaces Comments in javascript code

				   s = s.replace(/-->/gi,"");  // Replaces Comments in javascript code



				   //s = s.replace(/\/\//gi,"");  // Replaces Comments in javascript code







				   response = arrMessage[0];

				}



	  if(document.getElementById(elementId))

	  	{			

			//document.getElementById("txtBody").value = m ;

		   // alert(response);

			

			document.getElementById(elementId).innerHTML = "";

			document.getElementById(elementId).innerHTML = response;



	  

		}







		var objTextArea = document.getElementById("txtBody");



				if(objTextArea != null)

				{

				 //if(objTextArea.value=="")



					//objTextArea.value = response;// document.body.response;



					//document.getElementById("txtBodyjs").value = s;



				}



				 if(arrMessage[1])

					{

						  generateValJavascript(s);

					}				

		}



		



		//setTimeout("taketime()",10);

}



function taketime()

	{

		///checkSession();

	}



/* Create an element of <Script> and append this code in the Body element */

function generateValJavascript(code)

	{

	     var scripts = document.createElement('script');



		 document.body.appendChild(scripts);



		 scripts.text = code;

	}



function getXMLHttpObj(){

	if(typeof(XMLHttpRequest)!='undefined')

		return new XMLHttpRequest();



	var axO=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0',

		'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], i;

	for(i=0;i<axO.length;i++)

		try{

			return new ActiveXObject(axO[i]);

		}catch(e){}

	return null;

}



function loadScript(scriptpath, functions){

//	alert('here');

	var oXML = getXMLHttpObj();

	oXML.open('GET', scriptpath, false);

	oXML.send('');

	eval(oXML.responseText);

	for(var i=0; i<functions.length; i++)

		window[functions[i]] = eval(functions[i]);

}





function checkSession(){



	

	url = _JS_WWWROOT+"/common/checkSession.php";

	

	http.open('get', url);

	/* Define a function to call once a response has been received. This will be our

		handleProductCategories function that we define below. */

	http.onreadystatechange = ManipulateSessionRequest ;

	/* Send the data. We use something other than null when we are sending using the POST

		method. */

	http.send(null);

}



function ManipulateSessionRequest(){

	

	/* Make sure that the transaction has finished. The XMLHttpRequest object

		has a property called readyState with several states:

		0: Uninitialized

		1: Loading

		2: Loaded

		3: Interactive

		4: Finished */	

	//alert(http.readyState);

	if(http.readyState == 1)

		{		  	

		}

	else if(http.readyState == 4){ //Finished loading the response

		/* We have got the response from the server-side script,

			let's see just what it was. using the responseText property of

			the XMLHttpRequest object. */



		var response = http.responseText;

		

		//alert(response);

		if( response == "no" )

			{

			  document.location.href = _JS_WWWROOT+"/admin/login/index.php?logout=2" ;

			}		

	}



	return true;

}
