// declare new variables for each new div that you add, and link to the div by ID
// var region_div = document.getElementById("region_div");
var doc = null;
var Chat_all_counter = new Array(); 
var Current_chat_counter=0;
var Current_chat_id=0;
var Session_Id=0;

Update_request_alert();
Update_respons_alert();

function ajax()
{
    if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
}
function Valid_username(login){
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=username&login="+login, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Valid_folder(foldername){
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=folder&foldername="+foldername, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_username(login){
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=edit_username&login="+login, false); 
	       doc.send(null);
		  
	      return  doc.responseText;
	    }
}



function Valid_email(email){
		
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	     doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_email(email){
		
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=edit_email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_email(email){
		
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=edit_email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Select_states(Country)
	{
		
		
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=states&country="+Country, false);   
	       doc.send(null);

		if(Country=="other")
			{
				document.getElementById('div_country').innerHTML='<input type="text" name="Country" value="">';
				document.getElementById('country_heading_div').innerHTML="Country :";
			}
		//else
		//	{
			//	document.getElementById('div_country').innerHTML='';
		    //	document.getElementById('country_heading_div').innerHTML='';
		//	}
		
		if(doc.responseText!=0)
		   	{
				
				document.getElementById('div_states').innerHTML=doc.responseText;
				document.getElementById('state_heading_div').innerHTML='State :';
				document.getElementById('div_city').innerHTML='';
		    	document.getElementById('city_heading_div').innerHTML='';
			}
		else	
			{
				document.getElementById('div_states').innerHTML='<input type="text" name="State" value="">';
				document.getElementById('state_heading_div').innerHTML='State :';
				document.getElementById('div_city').innerHTML='<input type="text" name="city" value="">';
		    	document.getElementById('city_heading_div').innerHTML='City';
			}
		
		if(Country!=78)
			{
			document.getElementById('zipcode_heading_div').innerHTML='';
			document.getElementById('div_zipcode').innerHTML='';
			}
		}
	}
	
function Select_city(Country,State)
	{
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=city&country="+Country+"&state="+State, false);   
	       doc.send(null);
		 
		  document.getElementById('city_heading_div').innerHTML='City :';
		  
		if(doc.responseText!=0)
			{
			$City_str=doc.responseText+" <br/> If your town is not in the list - click on other cities and a text box will appear where you can type in the city you are looking for.";
		   document.getElementById('div_city').innerHTML=$City_str;
			}
		else
			document.getElementById('div_city').innerHTML='<input type="text" name="city" value="">';
				
		if(Country==78)
			{
			  document.getElementById('zipcode_heading_div').innerHTML='Postcode :';
			 document.getElementById('div_zipcode').innerHTML='<input type="text" size=6 name="zipcode" value="" maxlength="4">';
			}
		else
			{
			document.getElementById('zipcode_heading_div').innerHTML='';
			 document.getElementById('div_zipcode').innerHTML='';
			}
		}
	}	
	
function Select_subcity(City)
	{
	  if (City=="other")
	  	{
		   document.getElementById('city_heading_div1').innerHTML='City :';
		   document.getElementById('div_city1').innerHTML='<input type="text" name="city1" value="">';
		}
	else
		{
			document.getElementById('city_heading_div1').innerHTML='';
			document.getElementById('div_city1').value='';
		   document.getElementById('div_city1').innerHTML='';
		}
	}	

function Give_rate(video_id,rate)
	{
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=videorate&video_id="+video_id+"&rate="+rate, false);   
	       doc.send(null);
		  
		   document.getElementById('div_view_rate').innerHTML=doc.responseText;
		   document.getElementById('div_give_rate').innerHTML="";
		   
		}
	}

function Give_club_rate(club_id,rate)
	{
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=clubrate&club_id="+club_id+"&rate="+rate, false);   
	       doc.send(null);
		  
		   document.getElementById('div_view_rate').innerHTML=doc.responseText;
		   document.getElementById('div_give_rate').innerHTML="";
		   
		}
	}
			

function Update_chat(filename)
	{
	
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	      doc.open("GET", "http://www.adultsfunclub.co.uk/location.php?section=updatechat&filename="+filename, false);   
	       doc.send(null);
		 
		   document.getElementById('chat_contents').innerHTML=doc.responseText;
		}
			
	}	

//***********************************************************************************************************
//*********************************************chat function*************************************************
//***********************************************************************************************************
function Run_Chat()
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=update_chat_counter1&chat_id="+Current_chat_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
					var Chat_counter =(parseInt(doc.responseText));

					if(Current_chat_counter!=Chat_counter)
						{
						Current_chat_counter=Chat_counter;	
						Update_chat(Current_chat_id);
						}
					}
				}
			}  
	  };
		
	setTimeout('Run_Chat()', 1000); 
		doc.send(null);
	}
	
function Update_chat()
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=update_chat_mess&chat_id="+Current_chat_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
						var arraylist=doc.responseText.split("|*@*|");
					
					document.getElementById('div_mess').innerHTML = arraylist[0];
					
					  el=document.getElementById('div_mess');
					  el.scrollTop = el.scrollHeight - el.offsetHeight;

					if(arraylist[1]=='C' || arraylist[1]=='B')
						setTimeout("Close_redirect();", 2000); 
					}
				}
			}  
	  };
		doc.send(null);
	}	
	
function Close_redirect()
	{
		document.location="index.php?show=chat_close&chat_id="+Current_chat_id;
	}
	//***********************************************************************************
function call_binned(chat_id)
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=update_chat_binned&chat_id="+chat_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
						var arraylist=doc.responseText.split("|*@*|");
					
					if(arraylist[0]=='B')
						document.location="index.php?show=chat_close&Waiterid="+arraylist[1];
						
					}
				}
			}  
	  };
		doc.send(null);
	}	

	//************************************************************************************8

	
function Update_chat_counter(Mess)
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
	
	
	doc.open('GET', "./timer.php?section=update_chat_counter&chat_id="+Current_chat_id+"&Mess="+Mess, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		doc.send(null);
	}	

function Update_waiting_list()
{		
	var doc=null;
	
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
		
	doc.open('GET', "./timer.php?section=update_waiting", true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
					document.getElementById('div_waitng_users').innerHTML = doc.responseText;
				}
			}  
	  };
	  
	  setTimeout('Update_waiting_list();', 5000);  
		doc.send(null); 
	}		

function Update_current_list()
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=update_current", true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
					document.getElementById('div_current_users').innerHTML = doc.responseText;
				}
			}  
	  };
	  
	  setTimeout('Update_current_list();', 5000); 
		doc.send(null);
	}	

function Update_not_responding()
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=not_responding", true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
					document.getElementById('div_not_responding').innerHTML = doc.responseText;
				}
			}  
	  };
	  
	  setTimeout('Update_not_responding();',5000); 
		doc.send(null);
	}	
	
	
function call_history(chat_id,user_id)
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=show_history&chat_id="+chat_id+"&user_id="+user_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
				
					document.getElementById('div_chat_history').innerHTML = doc.responseText;
					}
				}
			}  
	  };
		doc.send(null);
	}
	
function Update_request_alert()
{	
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=request_alert", true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
					if(doc.responseText!=0)
					{
						
						var arraylist=doc.responseText.split("|*@*|");

							if(arraylist[0]!='')
									document.getElementById('div_request').innerHTML = arraylist[0];
							if(arraylist[1]!=0)
									mess_window(arraylist[1]);
					}
				
				}
			}  
	  };
	  
	  setTimeout('Update_request_alert();', 2000); 
		doc.send(null);
	}	
	
function Update_respons_alert()
{	
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=respons_alert", true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
					if(doc.responseText!=0)
					{
						var arraylist=doc.responseText.split("|*@*|");
							
							if(arraylist[0]!='')
								{	
									document.getElementById('div_respons').innerHTML = arraylist[0];
									document.getElementById('div_imchat').innerHTML = "<font color='#FFA100'>IM Chat</font>";
								}
								
							if(arraylist[1]!=0)
									mess_window(arraylist[1]);
					}
				}
			}  
	  };
	  
	  setTimeout('Update_respons_alert();', 5000); 
		doc.send(null);
	}	
	

function Update_current_All_list()
{		
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}

	doc.open('GET', "./timer.php?section=update_current_All&Current_chat_id="+Current_chat_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
						var arraylist=doc.responseText.split("|*@*|");
						for(l=0;l<arraylist.length;l++)
						{	 
							var arraylist1=arraylist[l].split("**");
							var cht_id =(parseInt(arraylist1[0]));
							var counter =(parseInt(arraylist1[1]));
														
							if(Chat_all_counter[cht_id]!=counter)
								{	
									document.getElementById('Chat_status'+cht_id).innerHTML = "New";
									document.getElementById('div_imchat').innerHTML = "<font color='#FFA100'>IM Chat</font>";
								}
						}
					}
				} 
			}
		  };
		doc.send(null);
		
		setTimeout('Update_current_All_list();', 5000); 
	}
	
function Update_im(Value)
	{
		var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer.php?section=update_im&Value="+Value, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	doc.send(null);
	}