var phone_num;
var thevars;
var kickout;
var infoObj 		= new Array();		 //holds values from the url string.


function buildlink(url) {
	//pageTracker._trackEvent('Key Interactions', 'BTN - Get a Quote', window.location.href);
	
	
	if(thenum == null) { thenum = 0; } //default
	if(the_se == null || the_se == "NA" || the_se == "") { the_se = "NA";}//default
	
	location.href = url + "?num=" + thenum + "&se=" + the_se;		
}

window.onload=function(){
	getQueryVariables();
	setPhone(phone_num);
}


function getQueryVariables() {
	
	var searchString = document.location.search;
	
	// strip off the leading '?'
	searchString = searchString.substring(1);
	var nvPairs = searchString.split("&");
	
	for (i = 0; i < nvPairs.length; i++)
	{
		var nvPair 	= nvPairs[i].split("=");
		var name	= nvPair[0];
		var value	= nvPair[1];
		infoObj[i] 	= value; 
	}
	init(infoObj);
}

function init(infoob) {
	thevars			= infoob; //grabs the url variables into an array
	thenum			= thevars[0];
	the_se			= thevars[1];
	phone_num	= phoneNums[thenum];
	return;
}

function setPhone(thenumber) {
	
	if(thenumber == null) {
		phone_num = phoneNums[0];
	}
	if(document.getElementById('phone')) {
		document.getElementById('phone').innerHTML = phone_num;
	}
	if(document.getElementById('phone_small')) {
		document.getElementById('phone_small').innerHTML = phone_num;
	}
}

//Start: Zip processing--------------

function zipInputClear(field) {
	if (field.defaultValue==field.value) {field.value = '';}
	else if (field.value == '') {field.value = field.defaultValue;}
}

function validateZIP(field) 
{
    var valid = "0123456789";
	var hyphencount = 0;
	
			
	if (field.length!=5) {
		alert("Please enter a five digit ZIP code.");
		
		return false;
	
	}
	
	for (var i=0; i < field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
		{
			alert("Invalid characters in your zip code.  Please try again.");
			return false;
		}
	}
	
	//pageTracker._trackEvent('Key Interactions', 'BTN - Get a Quote', window.location.href);
	//get query string
	var qs = window.location.search.substring(1);
	if (qs != "" && qs != null)
		window.location = homedir + "quoting/landing/startquote.aspx?" + qs + "&zipcode=" + field;
	else
		window.location = homedir + "quoting/landing/startquote.aspx?zipcode=" + field;
		
	return false;
}

function submitDetails(e) {
	var characterCode; 					//literal character code will be stored in this variable
	
	if(e && e.which){ 					//if which property of event object is supported (NN4)
		e = e	
		characterCode = e.which		//character code is contained in NN4's (and Firefox's) which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	if(characterCode == 13) { 		//if generated character code is equal to ascii 13 (if enter key)
		validate();
	}
	return true;
}

function gotoNewPlace() {
	if(the_se == null || the_se == "NA" || the_se == "") { the_se = "NA";} 
	
	window.location = homedir + "quoting/landing/pca-landing.aspx?num=" + thenum + "&se=" + the_se;
	return true;
}


	
function validate()
{
    validateZIP(document.getElementById('zip').value);
    document.getElementById('zip').focus();
}

//End: Zip processing--------------

function ttmPopUp(popurl){
	var winpops=window.open(popurl,"","width=432,height=365,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,top=250,left=250")
}