
// stores the reference to the XMLHttpRequest object 
var xmlHttp = createXmlHttpRequestObject();
var xmlHttp1 = createXmlHttpRequestObject();
var userfirstlim=0;
var usersecondlim=1;
var count=10;
var favfirstlim=0;
var favsecondlim=1;
var favcount=10;

// retrieves the XMLHttpRequest object 
function createXmlHttpRequestObject() 
{ 
// will store the reference to the XMLHttpRequest object 
	var xmlHttp; 
// if running Internet Explorer 
			if(window.ActiveXObject) 
			{ 
					try 
					{ 
							xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
					} 
					catch (e) 
					{ 
							xmlHttp = false; 
					} 
			} 
			// if running Mozilla or other browsers 
			else 
			{ 
					try 
					{ 
							xmlHttp = new XMLHttpRequest(); 
							
					} 
					catch (e) 
					{ 
							xmlHttp = false; 
					} 
			} 	
			// return the created object or display an error message 
			if (!xmlHttp) 
					alert("Error creating the XMLHttpRequest object."); 
			else 
					return xmlHttp; 
} 


// make asynchronous HTTP request using the XMLHttpRequest object 
function processfavourites(userid,limitsensor,vidcount) 
{ 

	if(limitsensor == 0)
	{
	//	usersecondlim=userfirstlim;
		favfirstlim=favfirstlim-4;
	}
	if(limitsensor == 1)
	{
		favfirstlim=favfirstlim+4;
	//	usersecondlim=usersecondlim+4;
		
	}
	if(limitsensor == 3)
	{
		favfirstlim=0;
		favsecondlim=4;
	}
	
	
	tempvar1=favfirstlim+4
	favcount=vidcount;	
		/*alert(userfirstlim+ "temp--" +tempvar +"count--" + subcount)*/
	if(favfirstlim==0)
			{
					document.getElementById("img3").disabled= true;
					
			}
			else
			{
					document.getElementById("img3").disabled= false;
			}
			if(favfirstlim>=favcount-1||tempvar1>=favcount)
			{
					document.getElementById("img4").disabled= true;
			
			}
			else
			{
					document.getElementById("img4").disabled= false;
			}
	
// proceed only if the xmlHttp object isn't busy 
			if (xmlHttp1.readyState == 4 || xmlHttp1.readyState == 0) 
			{ 
				
						
				var url="userprofilefavourite_ajx.php?userid="+userid+"&userfirstlim="+favfirstlim+"&usersecondlim="+favsecondlim;
				xmlHttp1.open("GET",url,true)
											
						// define the method to handle server responses 
						xmlHttp1.onreadystatechange = handleServerResponse1; 
						// make the server request 
						xmlHttp1.send(null); 
			} 
			
						// if the connection is busy, try again after one second 
} 

function process(userid,limitsensor,vidcount) 
{ 

	if(limitsensor == 0)
	{
	//	usersecondlim=userfirstlim;
		userfirstlim=userfirstlim-4;
	}
	if(limitsensor == 1)
	{
		userfirstlim=userfirstlim+4;
	//	usersecondlim=usersecondlim+4;
		
	}
	if(limitsensor == 3)
	{
		userfirstlim=0;
		usersecondlim=4;
	}
	
		tempvar=userfirstlim+4
		
	
	count=vidcount;
	/*alert(userfirstlim+ "temp--" +tempvar +"count--" + count)*/
	if( userfirstlim==0)
			{
					document.getElementById("img1").disabled= true;
					
			}
			else
			{
					document.getElementById("img1").disabled= false;
			}
			if(userfirstlim>=count-1||tempvar>=count)
			{
					document.getElementById("img2").disabled= true;
			
			}
			else
			{
					document.getElementById("img2").disabled= false;
			}
	
// proceed only if the xmlHttp object isn't busy 
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) 
			{ 
				
						
				var url="userprofile_ajx.php?userid="+userid+"&userfirstlim="+userfirstlim+"&usersecondlim="+usersecondlim;
				xmlHttp.open("GET",url,true)
											
						// define the method to handle server responses 
						xmlHttp.onreadystatechange = handleServerResponse; 
						// make the server request 
						xmlHttp.send(null); 
			} 
			
						// if the connection is busy, try again after one second 
} 
// executed automatically when a message is received from the server 
function handleServerResponse() 
{ 
			// move forward only if the transaction has completed 
			if (xmlHttp.readyState == 4) 
			{ 
			// status of 200 indicates the transaction completed successfully 
			
					if (xmlHttp.status == 200) 
					{
							// extract the XML retrieved from the server 
							
							xmlResponse =  xmlHttp.responseText;
							//alert(xmlResponse);
							var info=document.getElementById("mem_info");
							info.innerHTML=xmlResponse;
							
							
							
							// obtain the document element (the root element) of the XML structure 
							//xmlDocumentElement = xmlResponse.documentElement; 
							// get the text message, which is in the first child of 
							// the the document element 
							//helloMessage = xmlDocumentElement.firstChild.data; 
							// update the client display using the data received from the server 
							//alert(helloMessage);
							//document.getElementById("company_name").value = 
							//'<i>' + helloMessage + '</i>'; 
							// restart sequence 
							//setTimeout('process()', 1000); 
					} 
					// a HTTP status different than 200 signals an error 
					else 
					{ 
							alert("There was a problem accessing the server: " + xmlHttp.statusText); 
					} 
			} 
} 
function handleServerResponse1() 
{ 
			// move forward only if the transaction has completed 
			if (xmlHttp1.readyState == 4) 
			{ 
			// status of 200 indicates the transaction completed successfully 
			
					if (xmlHttp1.status == 200) 
					{
							// extract the XML retrieved from the server 
							
							xmlResponse =  xmlHttp1.responseText;
							//alert(xmlResponse);
							var info=document.getElementById("fav_info");
							info.innerHTML=xmlResponse;
														
							
					} 
					// a HTTP status different than 200 signals an error 
					else 
					{ 
							alert("There was a problem accessing the server: " + xmlHttp.statusText); 
					} 
			} 
} 

