String.prototype.trim=function()
{return this.replace(/^\s*/,"").replace(/\s*$/,"");}
function ChangePreReg(obj,id)
{var el=document.getElementById(id);if(obj.checked){el.value='Y';}
else{el.value='N';}}
function validateForm()
{if(document.getElementById("at_form"))
{document.getElementById("at_form").onsubmit=function()
{var pc=document.getElementById("postcode");if(pc&&pc.value.trim()==""&&pc.style.visibility!="hidden")
{showError("Please fill in your postcode");return false;}
if(document.getElementById("makes").selectedIndex<1)
{showError("Please select a make");return false;}
if(!checkPostCode(document.getElementById("postcode").value.trim()))
{if(document.getElementById('postcode').style.visibility!="hidden"){showError("Please check your postcode");return false;}else{document.getElementById("postcode").value='';}}}}}
function DisplayExtras(aid,tid,exp)
{var exid=document.getElementById(tid);var exa=document.getElementById(aid);var exp=document.getElementById(exp);if(exid.style.display==''||exid.style.display=='none')
{if(navigator.userAgent.indexOf('MSIE')!=-1)exid.style.display='block';else exid.style.display='table';exa.innerHTML='[-] Advanced search options';exp.value='1';}
else
{exid.style.display='none';exa.innerHTML='[+] Advanced search options';exp.value='0';}}
function popupLinks()
{if(document.getElementById("results"))
{var x=document.getElementById("results").getElementsByTagName('a');for(var i=0;i<x.length;i++)
{if(x[i].getAttribute('target')=='_blank')
{x[i].onclick=function()
{return popitup(this.href);}
x[i].title+=' (Popup)';}}}}
function popitup(url)
{newwindow=window.open(url,'name','menubar=1,resizable=1,height=630,width=714');if(window.focus)
{newwindow.focus()}
return false;}
function showError(theError)
{var x;if(!document.getElementById("errors"))
{x=document.createElement("span");x.id="errors";x.className="red md_clear mb10 fbold";document.getElementById("at_form").insertBefore(x,document.getElementById("at_form").firstChild);}
else
{x=document.getElementById("errors");}
x.innerHTML=theError;}
function monitorPostcode()
{if(document.getElementById("postcode"))
{var inPC=document.getElementById("postcode");if(inPC.value.trim()=='')
{inPC.value='Postcode';}
inPC.onfocus=function()
{if(this.value=='Postcode')
{this.value='';}}}}
function checkPostCode(toCheck)
{var alpha1="[abcdefghijklmnoprstuwyz]";var alpha2="[abcdefghklmnopqrstuvwxy]";var alpha3="[abcdefghjkstuw]";var alpha4="[abehmnprvwxy]";var alpha5="[abdefghjlnpqrstuwxyz]";var pcexp=new Array();pcexp.push(new RegExp("^("+alpha1+"{1}"+alpha2+"?[0-9]{1,2})(\\s*)([0-9]{1}"+alpha5+"{2})$","i"));pcexp.push(new RegExp("^("+alpha1+"{1}[0-9]{1}"+alpha3+"{1})(\\s*)([0-9]{1}"+alpha5+"{2})$","i"));pcexp.push(new RegExp("^("+alpha1+"{1}"+alpha2+"?[0-9]{1}"+alpha4+"{1})(\\s*)([0-9]{1}"+alpha5+"{2})$","i"));pcexp.push(/^(GIR)(\s*)(0AA)$/i);pcexp.push(/^(bfpo)(\s*)([0-9]{1,4})$/i);pcexp.push(/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);var postCode=toCheck;var valid=false;for(var i=0;i<pcexp.length;i++)
{if(pcexp[i].test(postCode))
{pcexp[i].exec(postCode);postCode=RegExp.$1.toUpperCase()+" "+RegExp.$3.toUpperCase();postCode=postCode.replace(/C\/O\s*/,"c/o ");valid=true;break;}}
if(valid){return postCode;}else return false;}
function ChangeTab2(type,id)
{for(var i=1;i<=3;i++)
{var div=document.getElementById('atTab'+i);if(id==i){div.style.backgroundColor='#ffffff';}
else{div.style.backgroundColor='#e6e5ea';}}
var banner=document.getElementById('banner');if(type=='new')
{document.getElementById('used').name='new';document.getElementById('postcode').style.visibility='hidden';document.getElementById('postcode').value='';banner.src='http://m3.ttxm.co.uk/images/gfx/mot/heading-tab-at.jpg';arr_makes=new_makes;arr_models=new_models;}
else if(type=='used')
{document.getElementById('used').name='used';document.getElementById('postcode').style.visibility='visible';document.getElementById('postcode').value='Postcode';banner.src='http://m3.ttxm.co.uk/images/gfx/mot/heading-tab-at.jpg';arr_makes=used_makes;arr_models=used_models;}
else if(type=='bikes')
{document.getElementById('used').name='bikes';document.getElementById('postcode').style.visibility='visible';document.getElementById('postcode').value='Postcode';banner.src='http://m0.ttxm.co.uk/images/gfx/mot/heading-tab-at-bike.jpg';arr_makes=bikes_makes;arr_models=bikes_models;}
DrawMakes('makes');DrawModels('makes','models',true);}
function ChangeTab(type)
{if(type=='new')
{document.getElementById('used').name='new';document.getElementById('atTab1').className='artTab';document.getElementById('atTab2').className='artTabSelected';document.getElementById('at-image').src='http://www.tiscali.co.uk/media/images/gfx/mot/at-top-bar-new.gif';document.getElementById('postcode').style.visibility='hidden';document.getElementById('postcode').value='';arr_makes=new_makes;arr_models=new_models;}
else if(type=='used')
{document.getElementById('used').name='used';document.getElementById('atTab1').className='artTabSelected';document.getElementById('atTab2').className='artTab';document.getElementById('at-image').src='http://www.tiscali.co.uk/media/images/gfx/mot/at-top-bar.gif';document.getElementById('postcode').style.visibility='visible';document.getElementById('postcode').value='Postcode';arr_makes=used_makes;arr_models=used_models;}
DrawMakes('makes');DrawModels('makes','models',true);}
function DrawMakes(makeid)
{var makeid=document.getElementById(makeid);var sel_make=makeid.options[makeid.selectedIndex].value;makeid.length=0;for(i=0;i<arr_makes.length;i++)
{makeid.options[i]=new Option(arr_makes[i]);makeid.options[i].value=arr_makes[i];if(arr_makes[i]==sel_make)
{makeid.options[i].selected=true;}}}
function DrawModels(makeid,modelid,init)
{var makeid=document.getElementById(makeid);var modelid=document.getElementById(modelid);var sel_make=makeid.options[makeid.selectedIndex].value;var sel_modl=modelid.selectedIndex;if(arr_makes.length==0||arr_models.length==0){return false;}
for(i=0;i<arr_makes.length;i++)
{if(arr_makes[i]==sel_make)
{var res=arr_models[i];if(res.length)
{modelid.length=0;for(j=0;j<res.length;j++)
{modelid.options[j]=new Option(res[j]);if(res[j]=='MODEL'){res[j]='ANY';}
modelid.options[j].value=res[j];}
break;}}}}
