	
function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch){
 
 if (showItSwitch) {
   elementToSet.style.display = "inline";
   elementToSet.style.visibility = "visible";
 }
 else{
   if (keepPlacementSwitch) {
     elementToSet.style.display = "inline";
     elementToSet.style.visibility = "hidden";
   }
   else{
     elementToSet.style.display = "none";
   }
 }
}
function hideTable(){
 setElementVisibility(document.getElementById("myTable"), false, true);
}

function removeTable(){
 setElementVisibility(document.getElementById("myTable"), false, false);
	document.getElementById("calendar1").value='00-00-0000';
}

function showTable(){
	//alert("Charles");
 setElementVisibility(document.getElementById("myTable"), true);
}
function removeRelics(){
 setElementVisibility(document.getElementById("ret_relics"), false, false);
}

function showRelics(){
	//alert("Charles");
 setElementVisibility(document.getElementById("ret_relics"), true);
}	
	
	
	
	
	
	
	
	
	
	
	
	function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }	
	
	function getState(countryId) {	
		var strURL="findmake.php?country="+countryId;
		var req = getXMLHTTP();
		
		if (req) {			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			
			req.send(null);
		}		
	}
	
	function getCity(countryId,stateId) {
		var strURL="findmodel.php?country="+countryId+"&state="+stateId;
		
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
	function getCitySearch()
	{
		alert("Praveen");
	}
	
	function ajxSelMake(typeName) {
	
		
		var strURL="get_make1.php?type="+typeName;
		var req = getXMLHTTP();
		
		if (req) {			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('div_make').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			
			req.send(null);
		}		
	}
	
	function getModel(typeId,makeName) {
		if(makeName=="others")
		{
			var strURL="get_make_others1.php?type="+typeId+"&make="+makeName;
		
			var req = getXMLHTTP();
		
			if (req) {
			
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {						
							document.getElementById('div_make_others').innerHTML=req.responseText;
							document.getElementById('div_model').innerHTML="<input type='text' id='model_others' name='model_others' >"
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
						//getModelOthers()
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}
		}
		
		else{
			document.getElementById('div_make_others').innerHTML="";
			var strURL="get_model1.php?type="+typeId+"&make="+makeName;
			var req = getXMLHTTP();
		
			if (req) {
			
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {
							
							document.getElementById('div_model').innerHTML=req.responseText;
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}
		}
	}
	
	function ajxSelPackage(listName)
	{
		var strURL="get_package1.php?list="+listName;
		if(listName=="prelist")
		{
			showTable();
			showRelics();
		}
		else if(listName=="forsale")
		{
			removeTable();
			showRelics();
		}
		else if(listName=="relics")
		{
			removeTable();
			removeRelics();
		}
		
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('div_package').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
		/*var e = document.getElementById("package");
		var strUser = e.options[e.selectedIndex].value;
		getBrowseButton(strUser,listName);*/
	}
	 
	 
	 function getModelOthers(modelName)
	 {
		 
		 if(modelName=="others")
		 {
			 var strURL="get_model_others1.php?model="+modelName;
		
			var req = getXMLHTTP();
		
			if (req) {
			
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
					// only if "OK"
						if (req.status == 200) {						
						document.getElementById('div_model_others').innerHTML=req.responseText;						
						} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}
			 
		 }
		 else{
		 	document.getElementById('div_model_others').innerHTML="";	
		 }
	 }
	
	
	function getBrowseButton(packageName,typeName)
	{
		var strURL="get_browse_button1.php?packageName="+packageName+"&typeName="+typeName;;
		
		var req = getXMLHTTP();
		
		if (req) {
			
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('div_browse_button').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
	}
	
	

//Auto populate state and city
	
function populateCity(val,from)
{
	if(from=="new_tractor")
	{
		var strURL="get_city.php?zip="+val;
	}
	else if(from=="tractor")
	{
		var strURL="get_city_tractor.php?zip="+val;
	}
	else if(from=="auction")
	{
		var strURL="get_city_auction.php?zip="+val;
	}
	else if(from=="register")
	{
		var strURL="get_city_register.php?zip="+val;
	}
	var req = getXMLHTTP();
		
		if (req) {
			
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('div_city').innerHTML=req.responseText;	
					if(document.getElementById('City').value=="")
					{
						alert("Invalid Zip Code");
					}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
	
}

function checkPromoCode(name)
{
	var strURL="get_promo.php?name="+name;
		
	var req = getXMLHTTP();
		
	if (req) {
			
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
			// only if "OK"
				if (req.status == 200) {	
					var a=req.responseText;
					
					document.getElementById('div_promo').innerHTML=req.responseText;
					
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}
}