var absPath="http://www.souq4cars.com/"; 
//var absPath="http://192.168.2.3/souq4cars.com/"; 
 var xmlHttp;
 
   try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
   catch (e)
     {
     // Internet Explorer
		 try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
     catch (e)
    {
		try
		  {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      }
    }
 }
function getModels(m)
{
	var make=m;
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open("GET", absPath+"ajax/models.php?make="+make,true);
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	else
		// if the connection is busy, try again after one second
		setTimeout('getModels()', 1000);
}
function handleServerResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
		txtResponse=xmlHttp.responseText;
		document.getElementById('model_div').innerHTML ='';
		var newdiv = document.createElement("div");
		newdiv.innerHTML = txtResponse;
		var container = document.getElementById("model_div");
		container.appendChild(newdiv);
		}
		else
		{
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function getSearchModels(m)
{
	
	var make=m;

	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
	
		xmlHttp.open("GET", absPath+"ajax/models.php?make_search="+make,true);
		xmlHttp.onreadystatechange = handleSearchModelResponse;
		xmlHttp.send(null);
	}
	else
		// if the connection is busy, try again after one second
		setTimeout('getModels()', 1000);
}
function  handleSearchModelResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			txtResponse=xmlHttp.responseText;
			document.getElementById('model_div').innerHTML ='';
		var newdiv = document.createElement("div");
		newdiv.innerHTML = txtResponse;
		var container = document.getElementById("model_div");
		container.appendChild(newdiv);

		document.getElementById('model_div1').innerHTML ='';
		var newdiv = document.createElement("div");
		newdiv.innerHTML = txtResponse;
		var container = document.getElementById("model_div1");
		container.appendChild(newdiv);
		}
		else
		{
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}



function toggleCheckboxes(fmobj) 
{
 if(document.getElementById('chkCheckAll').checked==true)
 {
  for (var i=0;i<document.getElementById(fmobj).elements.length;i++) {
    var e = document.getElementById(fmobj).elements[i];
    if ((e.name != 'chkCheckAll') && (e.type=='checkbox') ) {
      e.checked=true;
	  }
      
  	}
  }
   if(document.getElementById('chkCheckAll').checked==false)
 {
  for (var i=0;i<document.getElementById(fmobj).elements.length;i++) {
    var e = document.getElementById(fmobj).elements[i];
    if ((e.name != 'chkCheckAll') && (e.type=='checkbox') ) {
      e.checked=false;
	  }
      
  	}
  }
}

function park_single(id,vehicle)
{
	
	var now=new Date();
	var timems=now.getTime();
	now.setTime(timems);
	var park_date=now.toLocaleString();
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open("GET", absPath+"ajax/carpark.php?park_id="+id+"&v="+vehicle+"&park_date="+park_date,true);
		xmlHttp.onreadystatechange = carParkResponse;
		xmlHttp.send(null);
	}
	else
	setTimeout('park_single(id,vehicle)', 1000);


}
function carParkResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			txtResponse=xmlHttp.responseText;
			document.location=absPath+'carpark.php?msg='+txtResponse;
		}
		else
		alert("There was a problem accessing the server: " + xmlHttp.statusText);
	}
}

function park_selected(vehicle)
{
	var ids="";
	for (var i=0;i<document.vehicles.elements.length;i++) 
	{
		var e = document.vehicles.elements[i];
	
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.checked==true)) 
		{
			ids+=e.value+",";
		}
	  
		
	}
	if(ids=="")
	{
		alert("You have not selected any vehicle, You must select atleast one to delete.");
		return false;
	}
	else
	{
		var now=new Date();
		var timems=now.getTime();
		now.setTime(timems);
		alert(ids);
		alert(vehicle);
		var park_date=now.toLocaleString();
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
		{
			xmlHttp.open("GET", absPath+"ajax/carpark.php?park_ids="+ids+"&v="+vehicle+"&park_date="+park_date,true);
			alert( absPath+"ajax/carpark.php?park_ids="+ids+"&v="+vehicle+"&park_date="+park_date);
			xmlHttp.onreadystatechange =selectedCarParkResponse;
			xmlHttp.send(null);
		}
		else
		setTimeout('park_selected(vehicle)', 1000);
	
	}

}
function selectedCarParkResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			txtResponse=xmlHttp.responseText;
			//document.location=absPath+'carpark.php?msg='+txtResponse;
		}
		else
		alert("There was a problem accessing the server: " + xmlHttp.statusText);
	}
	
}
function car_park_options()
{
if(document.car_park.option.value=='delete')
deleteCarPark();
else if(document.car_park.option.value=='send_mail')
recommendVehicle();  //from car park .....means ,there can be multiple vehicles

}
function deleteCarPark()
{
	
	var cookieIds="";
	
	for (var i=0;i<document.car_park.elements.length;i++) 
	{
		var e = document.car_park.elements[i];
	
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.checked==true)) 
		{
			cookieIds+=e.value+",";
		}
	  
		
	}
	if(cookieIds=="")
	{
		alert("You have not selected any vehicle, You must select atleast one to delete.");
		return false;
	}
	
	else
	{
		var conf=confirm("Are you sure to delete the vehicle(s) ?")
		if(!(conf))
		return false;
		else
		{
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
			{
				xmlHttp.open("GET", absPath+"ajax/carpark.php?car_ids="+cookieIds,true);
				xmlHttp.onreadystatechange = deleteCarResponse;
				xmlHttp.send(null);
			}
			else
			setTimeout('deleteCarPark()', 1000);
		}
		
	}
	
	
}

function deleteCarResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			txtResponse=xmlHttp.responseText;
			document.getElementById('msg_div').innerHTML =txtResponse;
			document.location='carpark.php?msg=3';
		}
		else
		alert("There was a problem accessing the server: " + xmlHttp.statusText);
	}
}

function recommendVehicle()
{
		var cookieIds="";
		var v;
	for (var i=0;i<document.car_park.elements.length;i++) 
	{
		var e = document.car_park.elements[i];
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.checked==true)) 
		{
			v=(e.value).substr(4);
			cookieIds+=e.value+",";
		}
	  
		
	}
	if(cookieIds=="")
	{
		alert("You have not selected any vehicle, You must select atleast one to Send.");
		return false;
	}
document.car_park_recommend.ids.value=cookieIds;
openbox_carpark('Recommend Vehicle on Souq4Cars',1);

}
function save_memo(memoId)
{
	var note;
	if(document.getElementById(memoId).value!='')
	{
		note=document.getElementById(memoId).value;
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
			{
				xmlHttp.open("GET",absPath+"ajax/carpark.php?memo_id="+memoId+"&note="+note,true);
				xmlHttp.onreadystatechange = saveMemoResponse;
				xmlHttp.send(null);
			}
	else
		setTimeout('deleteCarPark()', 1000);
	}
}

function saveMemoResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			txtResponse=xmlHttp.responseText;
			document.getElementById('msg_div').innerHTML =txtResponse;
			document.location='carpark.php?msg=4';
		}
		else
		alert("There was a problem accessing the server: " + xmlHttp.statusText);
	}
}

function show()
{
	
	document.getElementById('diff1').style.display = 'block'; 
	document.getElementById('diff_zip_code').setAttribute("class", "required zip_optional");
	document.getElementById('diff_city').setAttribute("class", "required name");
	document.getElementById('diff_country').setAttribute("class", "required listbox");
	document.getElementById('diff_cc_phone').setAttribute("class", "required listbox");
	document.getElementById('diff_cc_fax').setAttribute("class", "required listbox");
	document.getElementById('diff_prefix_phone').setAttribute("class", "required number min 10 max 10000000");
	document.getElementById('diff_phone').setAttribute("class", "required number min 1000 max 1000000000");
	document.getElementById('diff_prefix_fax').setAttribute("class", "required number min 10 max 10000000");
	document.getElementById('diff_fax').setAttribute("class", "required number min 1000 max 1000000000");
	document.getElementById('diff_street').setAttribute("class", "required");
}

function hide()
{
	document.getElementById('diff1').style.display = 'none'; 
	document.getElementById('diff_zip_code').setAttribute("class", "");
	document.getElementById('diff_city').setAttribute("class", "");
	document.getElementById('diff_country').setAttribute("class", "");
	document.getElementById('diff_cc_phone').setAttribute("class", "");
	document.getElementById('diff_cc_fax').setAttribute("class", "");
	document.getElementById('diff_prefix_phone').setAttribute("class", "");
	document.getElementById('diff_phone').setAttribute("class", "");
	document.getElementById('diff_prefix_fax').setAttribute("class", "");
	document.getElementById('diff_fax').setAttribute("class", "");
	document.getElementById('diff_street').setAttribute("class", "");
}
function search_active()
{
	document.getElementById('search1').style.display = 'block';
	document.getElementById('search2').style.display = 'block'; 
	document.getElementById('offer1').style.display = 'none';
	document.getElementById('offer2').style.display = 'none'; 
}

function offer_active()
{
	document.getElementById('offer1').style.display = 'block';
	document.getElementById('offer2').style.display = 'block'; 
	document.getElementById('search1').style.display = 'none';
	document.getElementById('search2').style.display = 'none'; 
}



function hide_beta()
{
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open("GET", absPath+"ajax/beta_popup.php",true);
		xmlHttp.onreadystatechange = hide_betaResponse;
		xmlHttp.send(null);
	}
	else
	setTimeout('hide_beta()', 1000);


}
function hide_betaResponse()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			closebox();
			
		}
		else
		alert("There was a problem accessing the server: " + xmlHttp.statusText);
	}
}


