// Customising Variables
var awCustomDefaultLeft=20; // Default Left Position
var awCustomDefaultTop=20;  // Default Top Position


var pcsPV,awCustomP,awCustomText,awCustomA,awCustomC,awCustomOKFun,awCustomCFun,awCustomt,awCustomc,awCustomx,awCustomy,awCustomobj,awCustomobjLeft,awCustomobjTop,awCustomObjLeft,awCustomObjTop;
var awCustomSelAry=new Array();

function awCustomPrompt(txt,iv,v,x,y){
 awCustomPV=v;
 awCustomP=document.getElementById('awCustomPromptPanel');
 awCustomP.style.left=awCustomDefaultLeft+'px';
 awCustomP.style.top=awCustomDefaultTop+'px';
 if (x){
  awCustomP.style.left=x+'px';
  awCustomP.style.top=y+'px';
 }
 awCustomText=document.getElementById('awCustomPromptIP');
 awCustomHideSelects(awCustomP);
 awCustomText.value=iv;
 awCustomP.style.visibility='visible';
 document.getElementById('awCustomPromptTxt').innerHTML=txt;
 awCustomText.select();
}

function awCustomPromptOK(dealerNbr){
	ShowSelectAdvancedSearch(true);
	document.getElementById("address").value = awCustomText.value;
	
	//get the directions link that was clicked by the user
	document.getElementById("showMapPopup").value = "true";
	
	//need to submit the form so that the directions links will be populated with the correct source lat/lng
	document.formWTBResults.submit();
}

function awCustomPromptCancel(){
 awCustomP.style.visibility='hidden';
 awCustomShowSelects(awCustomP);
}

function awCustomPromptFocus(){
 setTimeout('awCustomPromptFocus2();',500);
}

function awCustomPromptFocus2(){
 if (awCustomP.style.visibility=='visible'){
  awCustomText.select();
 }
}

function awCustomAlert(txt,x,y){
 awCustomA=document.getElementById('awCustomAlertPanel');
 awCustomA.style.left=awCustomDefaultLeft+'px';
 awCustomA.style.top=awCustomDefaultTop+'px';
 if (x){
  awCustomA.style.left=x+'px';
  awCustomA.style.top=y+'px';
 }
 awCustomHideSelects(awCustomA);
 awCustomA.style.visibility='visible';
 document.getElementById('awCustomAlertTxt').innerHTML=txt;
}

function awCustomAlertOK(){
 awCustomA.style.visibility='hidden';
 awCustomShowSelects(awCustomA);
}

function awCustomConfirm(txt,okf,cf,x,y){
 awCustomOKFun=okf;
 awCustomCFun=cf;
 awCustomC=document.getElementById('awCustomConfirmPanel');
 awCustomC.style.left=awCustomDefaultLeft+'px';
 awCustomC.style.top=awCustomDefaultTop+'px';
 if (x){
  awCustomC.style.left=x+'px';
  awCustomC.style.top=y+'px';
 }
 awCustomHideSelects(awCustomC);
 awCustomC.style.visibility='visible';
 document.getElementById('awCustomConfirmTxt').innerHTML=txt;
}

function awCustomConfirmOK(){
 awCustomC.style.visibility='hidden';
 if (awCustomTypeof(window[awCustomOKFun.split('(')[0]])=='function'){
  eval(awCustomOKFun);
 }
 awCustomShowSelects(awCustomC);
}

function awCustomConfirmCancel(){
 awCustomC.style.visibility='hidden';
 if (awCustomTypeof(window[awCustomOKFun.split('(')[0]])=='function'){
  eval(awCustomCFun);
 }
 awCustomShowSelects(awCustomC);
}

function awCustomTypeof(x) {
 var awCustomt=typeof x;
 if (awCustomt!="object") return awCustomt;
 var awCustomc=Object.prototype.toString.apply(x);
 awCustomc=awCustomc.substring(8,awCustomc.length-1);
 return awCustomc;
}

function awCustomHideSelects(obj){
 if (!document.all){ return; }
 awCustomSelAry=new Array();
 var awCustomx=awCustomPos(obj)[0];
 var awCustomy=awCustomPos(obj)[1];
 for (awCustomi=0;awCustomi<document.all.tags('select').length;awCustomi++) {
  awCustomobj=document.all.tags('select')[awCustomi];
  if (!awCustomobj||!awCustomobj.offsetParent)
   continue;
   awCustomobjLeft=awCustomPos(awCustomobj)[0];
   awCustomobjTop=awCustomPos(awCustomobj)[1];
   if (awCustomx>(awCustomobjLeft+awCustomobj.offsetWidth)||awCustomobjLeft>(awCustomx+obj.offsetWidth));
   else if (awCustomy>awCustomobjTop+awCustomobj.offsetHeight);
   else if ((awCustomy+obj.offsetHeight)<awCustomobjTop);
   else {
    if (awCustomobj.style.visibility!='hidden'){
     awCustomSelAry[awCustomSelAry.length]=awCustomobj;
    }
    awCustomobj.style.visibility='hidden';
   }
 }
}

function awCustomPos(awCustom){
 awCustomObjLeft=awCustom.offsetLeft;
 awCustomObjTop=awCustom.offsetTop;
 while(awCustom.offsetParent!=null){
  awCustomObjParent=awCustom.offsetParent;
  awCustomObjLeft+=awCustomObjParent.offsetLeft;
  awCustomObjTop+=awCustomObjParent.offsetTop;
  awCustom=awCustomObjParent;
 }
 return [awCustomObjLeft,awCustomObjTop];
}

function awCustomShowSelects(){
 for (awCustom0=0;awCustom0<awCustomSelAry.length;awCustom0++){
  awCustomSelAry[awCustom0].style.visibility='visible';
 }
}


