/* 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){

	//url = "http://vikas.classicittserver/" + 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;
	loadingMesg=msg;
	//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. */
	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="Please wait... loading";
		else msg=loadingMesg;
	if(http.readyState == 1)
	{
		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 ;		
		
		/* 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>/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];
				}	
		//alert(response);
	    document.getElementById(elementId).innerHTML = response;	
	
		
		//alert(document.getElementById(elementId).innerHTML);
		
		var objTextArea = document.getElementById("txtBody");
				if(objTextArea != null)
				{
					//objTextArea.value = arrMessage[1];// document.body.response;
				}
	  if(arrMessage[1])
		{	
			 generateValJavascript(s);
		}
	}
}




/* 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]);
}

//********** Add _ajx suffix in url 

function CreateAjaxURL(link){		
  var arrPath = link.split('?');
	if(typeof(arrPath[1])!="undefined")
	{
		
		
		//if(!regex.exec(arrPath[1]))
		if(arrPath[1].indexOf('_ajx')==-1)
			link += "&_ajx=1" ;
	}
	else
		link += "?_ajx=1" ;

	
	return link;
}

//********** The function to open popup to invite friends for chat .........


function popitup(url)
{ 
        //alert(url);
        
        objSubWin2=window.open(url,'ChatRequest','left=215,top=140,width=600,height=360,scrollbars=no,resizable=yes');
        if(!objSubWin2)  alert("Please disable Popup Blocker.");
        else objSubWin2.focus();            
}    
















