/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject()
{
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		request_type = new XMLHttpRequest();
	}
	return request_type;
}

var http = createObject();

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
var httpzip = createObject();
function validatezip(make,model,zip,siteurl)
{
    model = model.replace(/&amp;/,'%26');
    model = model.replace(/&/,'%26');
	nocache = Math.random();
	httpzip.open('get','http://www.autotropolis.com/article.manager/modules/mod_getquote/modeldropdown.php?make='+make+'&model='+model+'&zip='+zip+'&nocache='+nocache);
	httpzip.onreadystatechange = validatezipreply;
	httpzip.send(null);	
	
}
function validatezipreply()
{
	
	if(httpzip.readyState == 4)
	{
		var response = httpzip.responseText;

		if(response == 0)
		{
			//alert("There was some error calling validate zip method");
			
		}
		else
		{
			var arr=response.split('http://');
			if(arr.length==2)
			{
				location.href=response;
			}
			else
			{
				document.getElementById('message').innerHTML="<font color='red' size='1'>"+response+"</font>";
			}
		}
	}
}


var http_verfiy = createObject();
function getqoutemodels(makeid)
{
	nocache = Math.random();
	http_verfiy.open('get','http://www.autotropolis.com/article.manager/modules/mod_getquote/modeldropdown.php?makeid='+makeid+'&nocache='+nocache);
	http_verfiy.onreadystatechange = getqoutemodelsreply;
	http_verfiy.send(null);
	
}
function getqoutemodelsreply()
{
	if(http_verfiy.readyState == 4)
	{
		var response = http_verfiy.responseText;
		if(response == 0)
		{
			//alert("There was some error filling model drop down");
			
		}
		else
		{
			var optionarray=response.split('#');
			var options;
			document.getElementById('quotemodels').options.length=1;
			var selectedvalue=document.getElementById('modelvalue').value;
	         for(var i=0; i<optionarray.length-1; i++)
			{				
				options=optionarray[i];
				var optionsValue = optionarray[i].replace(/&amp;/,"&");
				document.getElementById('quotemodels').options[document.getElementById('quotemodels').options.length] = new Option(optionsValue,options);
				if(selectedvalue==options)
				{
					//document.getElementById('quotemodels').options[i+1].selected=true;

				}
			}

		}
	}
}
function onKeyChange(e)
{
if(!e)
e = window.event || event;

if(e.keyCode == 13)
{
  call_validatezip();
}
}

 function call_validatezip()
             	 {
             	 	if(document.getElementById('quotemake').selectedIndex==0)
             	 	{
             	 		alert('Please select a make');
             	 		return false;
             	 	}
             	 	if(document.getElementById('quotemodels').selectedIndex==0)
             	 	{
             	 		alert('Please select a model');
             	 		return false;
             	 	}
             	 	if(document.getElementById('zip').value=="")
             	 	{
             	 		alert('Zip Required');
             	 		return false;
             	 	}
             	 	validatezip(document.getElementById('quotemake').options[document.getElementById('quotemake').selectedIndex].text,document.getElementById('quotemodels').options[document.getElementById('quotemodels').selectedIndex].text,document.getElementById('zip').value,'http://www.autotropolis.com/');
             	 }