
var vs_ie4=document.all
var vs_ns6=document.getElementById
var site = "TGB";

function jump(cid){
	document.jump.cid.value=cid
	document.jump.submit();
}

function jump2tfs(cid){
	document.jump.dealer_id.value=cid
	document.jump.submit();
}


function getAToZList(str) {
var output="";
	output='<table cellpadding="0" cellspacing="0"><tr><td id="dealersListContentFull">'
	if (!str) str = "";
	var charArr = str.split("");
	var charArrLen = charArr.length;
	var numRec = centerlist.length;
	for (var i = 0; i < numRec; i++) {
		for (var j = 0; j < charArrLen; j++) {
			var centreStartChar = centerlist[i].CENTRENAME.toString().charAt(0);
			if (centreStartChar.toUpperCase() == charArr[j]) {
				output+=addRow2Output(centerlist[i].CENTRETYPE, centerlist[i].CENTREID, centerlist[i].CENTRENAME, centerlist[i].TEL, centerlist[i].URL, centerlist[i].ServiceTel);
				break;
			}
		}
		if (charArrLen == 0) 	output+=addRow2Output(centerlist[i].CENTRETYPE, centerlist[i].CENTREID, centerlist[i].CENTRENAME, centerlist[i].TEL, centerlist[i].ServiceTel);
	}
	output+="</td></tr><table>";
	generatetext(output,"dealersListFull");
	output="";
	return false;
}


function addRow2Output(CENTRETYPE,CENTREID,CENTRENAME,TEL, URL, SERVICETEL){
	var output="";
	output+='	<div class="dealerList">';
	output+='		<table cellpadding="0" cellspacing="0">';
	output+='			<tr>';
	output+='				<td class="dListName">';
	output+='				<h5>' + CENTRENAME + '</h5>';
	output+='				<span class="txtCufon">Tel: <span class="bold">' + TEL + '</span></span>';
	if(SERVICETEL != "") output+='				<br><span class="txtCufon">Service Tel: <span class="bold">' + SERVICETEL + '</span></span>';
	output+='				</td>';
	output+='				<td class="dListLink">';
	if(site=="TFS"){
		output+='					<ul>';
		output+='						<li><a href="JavaScript:jump2tfs('+"'"+CENTREID+"'"+')" class="txtCufon">Select This Dealer</a></li>';
		output+='						<li><a target="detailswin" href="/cgi-bin/toyota/bv/FindCenters/ShowDealer.jsp?cid='+CENTREID+'&m=k&postcode=' + document.frm.postcode.value + '&details=sales" class="txtCufon">More details &amp; Directions</a></li>';
		output+='					</ul>';
	}else{
		output+='					<ul>';
		output+='						<li><a href="JavaScript:jump('+"'"+CENTREID+"'"+')" class="txtCufon">More details &amp; Directions</a></li>';
		output+='						<li><a href="' +URL+'" class="txtCufon">Visit the Centre Website</a></li>';
		output+='					</ul>';
	}
	output+='				</td>';
	output+='				<td class="dListImg">';
	if(CENTRETYPE.indexOf("S")>-1){
		output+='					<img src="/googlemaps/images/services/sales.jpg" title="Approved Sales" alt="Approved Sales"/>';
		output+='					<img src="/googlemaps/images/services/aftersales.jpg" title="Approved After Sales" alt="Approved After Sales"/>';
	}
	if(CENTRETYPE=="A")
		output+='					<img src="/googlemaps/images/services/aftersales.jpg" title="Approved After Sales" alt="Approved After Sales"/>';
	
	for(var i = 0, numRec = agreements.length; i < numRec; i++) {
		if(CENTREID==agreements[i].CENTREID){
			if(agreements[i].AGREEMENTTYPEID=="22") output+='					<img src="/googlemaps/images/services/business.jpg" title="Approved Business Centre" alt="Approved Business Centre"/>';
			if(agreements[i].AGREEMENTTYPEID=="3") output+='					<img src="/googlemaps/images/services/commercial.jpg" title="Approved Commercial Vehicle Centre" alt="Approved Commercial Vehicle Centre"/>';
			if(agreements[i].AGREEMENTTYPEID=="8") output+='					<img src="/googlemaps/images/services/motability.jpg" title="Motability Affiliated" alt="Motability Affiliated"/>';
		}
	}
	output+='				</td>';
	output+='			</tr>';
	output+='		</table>';
	output+='	</div>';
	return output;
}

function addRow2Bubble(CENTRETYPE,CENTREID,CENTRENAME,TEL,URL,SERVICETEL){
	var output="<div class='winDealer'>";
	output+='	<div>';
	output+='		<table cellspacing="0" cellpadding="1">';
	output+='			<tr>';
	output+='				<td>';
	output+='					<h5>' + CENTRENAME + '</h5>';
	output+='				</td>';
	output+='			</tr>';
	output+='			<tr>';
	output+='				<td>';
	output+='					<span class="bubTel txtCufon">Tel: <span class="bold" style="font-size:9pt;">' + TEL + '</span></span>';
	if(SERVICETEL != "") output+='					<br><span class="bubTel txtCufon">Service Tel: <span class="bold" style="font-size:9pt;">' + SERVICETEL + '</span></span>';
	output+='				</td>';
	output+='			</tr>';
	output+='			<tr>';
	output+='				<td>';
	output+='					<ul>';
	output+='						<li><a href="JavaScript:jump('+"'"+CENTREID+"'"+')" class="txtCufon">More details & Directions</a></li>';
	output+='						<li><a href="'+URL+'/cgi-bin/toyota/bv/dealersites/dealer_home.jsp?dealerId=' +CENTREID+'&id=D_homepage&DSredirect=DealerHome_map" class="txtCufon">Visit the Centre Website</a></li>';
	output+='					</ul>';
	output+='				</td>';
	output+='			</tr>';
	output+='			<tr>';
	output+='				<td class="bubImg"> ';
	if(CENTRETYPE.indexOf("S")>-1){
		output+='					<img src="/googlemaps/images/services/sales_b.jpg" title="Approved Sales" alt="Approved Sales"/>';
		output+='					<img src="/googlemaps/images/services/aftersales_b.jpg" title="Approved After Sales" alt="Approved After Sales"/>';
	}
	if(CENTRETYPE=="A")
		output+='					<img src="/googlemaps/images/services/aftersales_b.jpg" title="Approved After Sales" alt="Approved After Sales"/>';
	
	for(var i = 0, numRec = agreements.length; i < numRec; i++) {
		if(CENTREID==agreements[i].CENTREID){
			if(agreements[i].AGREEMENTTYPEID=="22") output+='					<img src="/googlemaps/images/services/business_b.jpg" title="Approved Business Centre" alt="Approved Business Centre"/>';
			if(agreements[i].AGREEMENTTYPEID=="3") output+='					<img src="/googlemaps/images/services/commercial_b.jpg" title="Approved Commercial Vehicle Centre" alt="Approved Commercial Vehicle Centre"/>';
			if(agreements[i].AGREEMENTTYPEID=="8") output+='					<img src="/googlemaps/images/services/motability_b.jpg" title="Motability Affiliated" alt="Motability Affiliated"/>';
		}
	}
	output+='				</td>';
	output+='			</tr>';
	output+='		</table>';
	output+='	</div>';
	output+='</div>';
	return output;
}


function generatetext(stext,obj){
	if (vs_ie4||vs_ns6)
	var contentobj=document.getElementById? document.getElementById(obj): eval("document.all."+obj)

	if (vs_ie4||vs_ns6){
		contentobj.innerHTML=stext
	}
	else if (document.layers){
		var myobj=eval("document."+obj)
		myobj.write(stext)
		myobj.close()
	}
	else
		alert('You need NS 4+ or IE 4+ to view the images!')
}

function addtodrop(odrop,stext,sval) {
	nlen = odrop.length;
	var soption = new Option(stext, sval);
	odrop.options[nlen] = soption; 
}

function dclear(odrop){ 
	nlen=odrop.length;
	for (i=0; i<nlen; i++){
		odrop.options[0]=null ;
	}
 }

function isValidPostcode(PostcodeObject){
	var error="";
	var test = PostcodeObject.value;
	size = test.length;
	test = test.toUpperCase(); //Change to uppercase

	while (test.slice(0,1) == " "){ //Strip leading spaces
		test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " "){ //Strip trailing spaces
		test = test.substr(0,size-1);size = test.length
	}
	//PostcodeObject.value = test; //write back to form field
	if (size < 6 || size > 8){ //Code length rule
		error=(test + " is not complete - please enter your entire postcode");
		return false;
	}
	if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
		error=(test + " is not valid - the postcode cannot start with a number");
		return false;
	}
	if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
		error=(test + " is not valid - the second part of the postcode must start with a number followed by two letters");
		return false;
	}
	if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
		error=(test + " is not valid - the second part of the postcode must start with a number followed by two letters");
		return false;
	}
	if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
		error=(test + " is not valid - the second part of the postcode must start with a number followed by two letters");
		return false;
	}
	if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
		error=(test + " is not valid - please include the space");
		return false;
	}
	count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
	if (count1 != count2){//only one space rule
		error=(test + " is not a valid postcode - only one space allowed");
		return false;
	}
	//PostcodeObject.focus();
	return true;
}


function isValidTown(TownObject){
	var error="";
	var test = TownObject.value;
	var size = test.length
	if (size < 3) { //Code length rule
		error=(test + " is not recognised - please modify your town name or use the directory search");
		return false;
	}
	if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
		error=(test + " is not recognised - town names cannot start with a number");
		return false;
	} 
	//TownObject.focus();
	return true;
}

function imgRollOn(imageObj) { imageObj.src = imageObj.src.replace(/.gif/, "-ro.gif"); }
function imgRollOff(imageObj) { imageObj.src = imageObj.src.replace(/-ro.gif/, ".gif"); }
