var xmlHttp

function detstate(manf,yer,manaf,man,pid,loc_id,ses_man,ses_mod,ses_yr,pos_val)
{
  xmlHttp=GetXmlHttpObject();
  if(xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

 var url="modle.php";
 url=url+"?pid="+pid+"&st=1"+"&ses_man="+ses_man+"&ses_mod="+ses_mod+"&ses_yr="+ses_yr+"&posval="+pos_val;

 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChanged;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function showCustomer(str,type,loc_id,pid)
{
  xmlHttp=GetXmlHttpObject();
  if(xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  
var url="modle.php";
url=url+"?q="+str+"&t="+type+"&locid="+loc_id+"&pid="+pid;

//alert(url);
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function showCustomer2(str,type,m1,loc_id,pid)
{
  xmlHttp=GetXmlHttpObject();
  if(xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  
var url="modle.php";
url=url+"?q="+str+"&t="+type+"&m="+m1+"&locid="+loc_id+"&pid="+pid;

url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{
	//alert(xmlHttp.responseText);

	var n=xmlHttp.responseText;

	var ty=n.split('~');

	if(ty[3]=="st2")
	{
        var ses_ids=ty[4].split(',');
		var lh_val=ses_ids[1];
		if(lh_val=="1" || lh_val=="3")
			document.f_serch.RH[0].checked=true;
		else
			document.f_serch.RH[1].checked=true;
	}
	if(ty[3]=="st")
	{
				removeOptions(document.f_serch.model2);
				addOption(document.f_serch.model2,'- select model -','');
				removeOptions(document.f_serch.syear);
				addOption(document.f_serch.syear,'- select year -','');
                

				var ses_ids=ty[4].split(',');
                var title=ty[0].split(',');
				var uni=0;
                var flg=1;

				for(var i=0;i<title.length;i++)
				{
				for(var j=i+1;j<title.length;j++)
					{
					   if(title[i]==title[j])
						{
						  uni++; 
						}
					}
				}

				var new_len=title.length-uni;
                 for(var i=0,k=0;i<title.length;i++)
				{
				   for(var j=i+1;j<title.length;j++)
					{
					   if(title[i]==title[j])
						{
						   flg=0;break;
						}
					}
					if(flg==1)
					{
						var j_id=title[i].split('^');

						if(j_id[0]==ses_ids[0] && (new_len==1 || ses_ids[3]=="2"))
						{
							document.f_serch.make.options[k+1].selected=true;
						}
						k++;
					}
				flg=1;
				}
           
            if(ses_ids[3]=="2" || new_len==1)
			{
				removeOptions(document.f_serch.model2);
				addOption(document.f_serch.model2,'- select model -','');
				var title=ty[1].split(',');
				var uni=0;

				for(var i=0;i<title.length;i++)
				{
				for(var j=i+1;j<title.length;j++)
					{
					   if(title[i]==title[j])
						{
						  uni++; 
						}
					}
				}
				var new_len=title.length-uni;
				var flg=1;
				
               for(var i=0,k=0;i<title.length;i++)
				{
				   for(var j=i+1;j<title.length;j++)
					{
					   if(title[i]==title[j])
						{
						   flg=0;break;
						}
					}
					if(flg==1)
					{
					var j_id=title[i].split('^');
                    var j_nid=j_id[0].split('_');           
					var finalvalue=j_id[1].replace(/&quot;/g,'"');
					if(finalvalue!="" && j_nid[1]!="" && j_nid[0]==document.f_serch.make.value)
						{
							addOption(document.f_serch.model2,finalvalue,j_nid[1]);	
							if(j_nid[1]==ses_ids[1] && (new_len==1 || ses_ids[3]=="2"))
							{
								document.f_serch.model2.options[k+1].selected=true;
							}
							k++;
						}
					
					}
					flg=1;
				}
				//alert(ses_ids[2]);
				//alert(ty[2]);
               if(new_len=="1" || ses_ids[3]=="2" )
				{
                removeOptions(document.f_serch.syear);
				addOption(document.f_serch.syear,'- select year -','');
				var title=ty[2].split(',');
				for(var i=0,k=0;i<title.length;i++)
				{
					var j_id=title[i].split('^');
					var j_nid=j_id[0].split('_');
					var finalvalue=j_id[1].replace(/&quot;/g,'"');
					if(finalvalue!=" - " && j_nid[1]!="" && j_nid[0]==document.f_serch.model2.value)
					{
					addOption(document.f_serch.syear,finalvalue,j_nid[1]);

					if(j_nid[1]==ses_ids[2] && (title.length==1 || ses_ids[3]=="2"))
					{
						document.f_serch.syear.options[k+1].selected=true;
					}
					k++;
					}
				}
				}
			}

	}
	else
	if(ty[0]==1)
	{
		if(ty[1]!='')
		{
				var title=ty[1].split('_');
				removeOptions(document.f_serch.model2);
				addOption(document.f_serch.model2,'- select model -','');
				removeOptions(document.f_serch.syear);
				addOption(document.f_serch.syear,'- select year -','');
				if(ty[2]!="candetails")
			    {
                //document.f_serch.smaterial.value='';  
				removeOptions(document.f_serch.Frontrearset);
				addOption(document.f_serch.Frontrearset,'- select type -','');
				}
		for(var i=0;i<title.length;i++)
		{
	
			var j_id=title[i].split(',');
			var finalvalue=j_id[1].replace(/&quot;/g,'"');
			addOption(document.f_serch.model2,finalvalue,j_id[0]);				

		}
		}
		else
		{
				removeOptions(document.f_serch.model2);
				addOption(document.f_serch.model2,'- select model -','');
				removeOptions(document.f_serch.syear);
				addOption(document.f_serch.syear,'- select year -','');
				if(ty[2]!="candetails")
			    {
				//document.f_serch.smaterial.value='';
				removeOptions(document.f_serch.Frontrearset);
				addOption(document.f_serch.Frontrearset,'- select type -','');
				}
		}
	}
	else
	if(ty[0]==2)
	{
		if(ty[1]!='')
		{

				var title=ty[1].split('_');
				removeOptions(document.f_serch.syear);
				addOption(document.f_serch.syear,'- select year -','');
				/*if(ty[2]!="candetails")
				document.f_serch.smaterial.value='';*/
				for(var i=0;i<title.length;i++)
				{
						
					var j_id=title[i].split(',');
					var finalvalue=j_id[1].replace(/&quot;/g,'"');
					addOption(document.f_serch.syear,finalvalue,j_id[0]);				

				}
		}
		else
		{
			    removeOptions(document.f_serch.syear);
				addOption(document.f_serch.syear,'- select year -','');
				/*if(ty[2]!="candetails")
				document.f_serch.smaterial.value='';*/
		}
	}

//document.f_emp.lmname.value=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function removeOptions(selectbox)
{
//alert(selectbox.options.length);
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//alert(i);
if(selectbox.options[i])
selectbox.remove(i);
}
}
//add

function addOption(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
function showCustomer3(str,loc_id,pids)
{
	if(str=='')
	{
	alert("Please Select year");
	return false;
	}
	else if(loc_id!="candetails")
	{
	//document.f_serch.smaterial.value='';
	document.f_serch.submit();
	}
	else if(loc_id=="candetails")
	{
		manf=document.f_serch.make.value;
        mod=document.f_serch.model2.value;
		yer=document.f_serch.syear.value;
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null)
		{
		alert ("Your browser does not support AJAX!");
		return;
		}

		var url="modle.php";
		url=url+"?manf="+manf+"&yer="+yer+"&mod="+mod+"&pid="+pids+"&st=2";

		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function showCustomer6(str)
{
	/*if(str=='')
	{
	alert("Please Select Type of Mat");
	return false;
	}
	else
	{*/
	var ye=document.f_serch.syear.value;
		
	var mod=document.f_serch.model2.value;
	var mc=document.f_serch.make.value;
	
	if(ye=='' || mod=='' || mc=='')
	{
	alert("Please Select Make, Model and  Year");
    if(mc=='')
	document.f_serch.make.focus();
	else if(mod=='')
	document.f_serch.model2.focus();
	else if(ye=='')
	document.f_serch.syear.focus();

	return false;
	}
	else
	{
	document.f_serch.fr_type.value='mats';
	document.f_serch.submit();
	}
	//}
}

function showCustomer4(str)
{
	var ye=document.f_serch.syear.value;
	
	var mod=document.f_serch.model2.value;
	var mc=document.f_serch.make.value;
	//var mat=document.f_serch.smaterial.value;
	if(ye=='' || mod=='' || mc=='')
	{
	alert("Please Select Make, Model and  Year");
	if(mc=='')
	document.f_serch.make.focus();
	else if(mod=='')
	document.f_serch.model2.focus();
	else if(ye=='')
	document.f_serch.syear.focus();
	return false;
	}
	else
	{
	document.f_serch.fr_type2.value='mats';
	document.f_serch.submit();
	}

}
function showCustomer5()
{
	var ye=document.f_serch.syear.value;
		
	var mod=document.f_serch.model2.value;
	var mc=document.f_serch.make.value;
	//var mat=document.f_serch.smaterial.value;

	if(ye=='' || mod=='' || mc=='')
	{
	alert("Please Select Make, Model and  Year");
	if(mc=='')
	document.f_serch.make.focus();
	else if(mod=='')
	document.f_serch.model2.focus();
	else if(ye=='')
	document.f_serch.syear.focus();
	return false;
	}
	else
	{
		/*var ye=document.f_serch.syear.value;
		
		var mod=document.f_serch.model2.value;
		var mc=document.f_serch.make.value;
	window.location="cannonpoduct.php?me="+mc+"&mod="+mod+"&ye="+ye;	*/
	/*if(document.f_serch.RH.checked==true)
		{
	document.f_serch.submit();
		}
		else if(document.f_serch.LH.checked==true)
		{*/
	document.f_serch.submit();
		//}
}

}
//disable right click