//-------------------------------------------------------------------------------------------------
//filename: javascript.js
//purpose : Keep the javascripts out of the main .ASP page because spiders like it better
//
//revised : 09/10/07 dwl - Modified SubmitHome_onclick() & SubmitIt_onlick() because on se1.asp click on header to get home page not working because JS functions can't use ASP variable substitution like "<%sec%>" and "<%unsec%>"
//revised : 01/20/06 cjc - change scripts to use <%=sec%> and <%=unsec%> variables.
//revised : 12/29/05 cjc - fix navigation if existing user saves basket and then tries "continue shopping"
//revised : 12/29/05 cjc - alter DelItem to get rid of hopshop
//revised : 12/29/05 cjc - alter back_to_shop to get rid of hopshop
//revised : 12/29/05 cjc - alter basketwork to get rid of hopshop
//revised : 12/07/05 cjc - AddtoCartClick now accepts fpartselected (index of part added from asgrid list)  as a parameter
//revised : 11/22/05 cjc - revise back_to_shop to default to asgridyearmodel! makes more sense
//revised : 11/22/05 cjc - AddtoCartClick changed to deal with products that MUST go to product for attributes.
//revised : 11/09/05 cjc - AddtoCartClick now also sets HShopperID
//revised : 11/09/05 cjc - AddToCartClick func now points directly to xt_orderform_additem avoiding 1 more hop!
//revised : 11/01/05 cjc - AddToCartClick function now points to shop.asp NOT hopshop.asp.
//revised : 08/29/05 cjc - fixed open_window_800 to be right window size  
//revised : 02/28/05 dwl - Modifying home page
//revised : 12/07/04 tfb - separated from shop.asp 
//-------------------------------------------------------------------------------------------------

/////////////////////////////////////////////////
//--- scripts for the dept trees
///////////////////////////////////////////////

function show_dept(dept,depttarget) {
  window.document.thisForm.Hdept_id.value = dept;
  window.document.thisForm.HTarget.value = depttarget;
  window.document.thisForm.settree.value = '1';
  window.document.thisForm.action = "shop.asp";
  window.document.thisForm.submit()
}

function SubmitMenuBar_onclick(fMenuLevel,fMenuTarget,fCatid) { 
  document.thisForm.Hdept_id.value = '';
  document.thisForm.HTarget.value=fMenuTarget;
  document.thisForm.HFwdTar.value = document.thisForm.HTarget.value;
  document.thisForm.HCat_id.value = fCatid ;
  document.thisForm.HReqYM.value="";
  
  if (fMenuLevel <=5) {
    document.thisForm.HC6.value= 0;document.thisForm.HCD6.value= "";document.thisForm.HTar6.value= "";
    document.thisForm.HCatid6.value = 0
  }
  if (fMenuLevel <=4) {
    document.thisForm.HC5.value=0;document.thisForm.HCD5.value="";document.thisForm.HTar5.value="";
    document.thisForm.HCatid5.value = 0
  }
  if (fMenuLevel <=3) {
    document.thisForm.HC4.value=0;document.thisForm.HCD4.value="";document.thisForm.HTar4.value="";
    document.thisForm.HCatid4.value = 0
  }
  if (fMenuLevel <=2) {
    document.thisForm.HC3.value=0;document.thisForm.HCD3.value="";document.thisForm.HTar3.value="";
    document.thisForm.HCatid3.value = 0
  }
  if (fMenuLevel <=1){
    document.thisForm.HC2.value=0;document.thisForm.HCD2.value="";document.thisForm.HTar2.value="";
    document.thisForm.HCatid2.value = 0
  }
  if (fMenuLevel == 0) {
    document.thisForm.HC1.value=0;document.thisForm.HCD1.value="";document.thisForm.HTar1.value="";
    document.thisForm.HCatid1.value = 0
  }
  document.thisForm.action = "shop.asp"
  document.thisForm.submit()
}

//--- user clicks change year model/set year model -- we want to set the hidden fwd target
//    to the page they are looking at now so we can send them back to the same page after they set a year model>
//
function GetYearModel(fTarget) { ;
  document.thisForm.HCat_id.value = "" ;
  document.thisForm.HTarget.value = "vehyear.asp"
  document.thisForm.HFwdTar.value = fTarget ;
  document.thisForm.action= "shop.asp";
  document.thisForm.submit();
}

function SubmitIt_onclick(fC1,fC2,fC3,fC4,fC5,fC6,fCY,fCM,fdept_id,fReqYM,fTargetURL,fCD1,fCD2,fCD3,fCD4,fCD5,fCD6,fTar1,fTar2,fTar3,fTar4,fTar5,fTar6,fCatid1,fCatid2,fCatid3,fCatid4,fCatid5,fCatid6,fCat_id){;
  document.thisForm.HC1.value=fC1;
  document.thisForm.HC2.value=fC2;
  document.thisForm.HC3.value=fC3;
  document.thisForm.HC4.value=fC4;
  document.thisForm.HC5.value=fC5;
  document.thisForm.HC6.value=fC6;
  document.thisForm.HCY.value=fCY;
  document.thisForm.HCM.value=fCM;
  document.thisForm.Hdept_id.value=fdept_id;
  document.thisForm.HReqYM.value=fReqYM;
  document.thisForm.HTarget.value=fTargetURL;
  document.thisForm.HCD1.value=fCD1;
  document.thisForm.HCD2.value=fCD2;
  document.thisForm.HCD3.value=fCD3;
  document.thisForm.HCD4.value=fCD4;
  document.thisForm.HCD5.value=fCD5;
  document.thisForm.HCD6.value=fCD6
  document.thisForm.HTar1.value=fTar1;
  document.thisForm.HTar2.value=fTar2;
  document.thisForm.HTar3.value=fTar3;
  document.thisForm.HTar4.value=fTar4;
  document.thisForm.HTar5.value=fTar5;
  document.thisForm.HTar6.value=fTar6;
  document.thisForm.HCat_id.value=fCat_id
  document.thisForm.HCatid1.value=fCatid1;
  document.thisForm.HCatid2.value=fCatid2;
  document.thisForm.HCatid3.value=fCatid3;
  document.thisForm.HCatid4.value=fCatid4;
  document.thisForm.HCatid5.value=fCatid5;
  document.thisForm.HCatid6.value=fCatid6;
         
  document.thisForm.action = "http://www.bavauto.com/shop.asp"
  document.thisForm.submit();
}

/////////////////////////////////////////////////
//--- misc page functions
//////////////////////////////////////////////

function search(){
  window.document.thisForm.HCat_id.value = "0";
  window.document.thisForm.Hsrchstr.value = window.document.thisForm.SearchStr.value;
  window.document.thisForm.HFwdTar.value = "search.asp";
  window.document.thisForm.HTarget.value = "search.asp";
  window.document.thisForm.action = "shop.asp"
  window.document.thisForm.submit();
}

//--- this function forces updating quanities before continuing shopping if they've been edited by the user
//    the var "dirty" is outside any function and isn't declared. There for it is global?  02/05/05 dwl
//
dirty = false
//
function back_to_shop(reftar) {
  //--- at the moment dirty is only set true by changing a quanity on basket.asp
  //
  //cjc default reftar to asgridyearmodel
  if (reftar == "" || reftar=="basket.asp"){
	reftar = "asgridyearmodel.asp"
  }
  if (dirty == true){
    //--- alert("updating quanities and prices before continuing");
    window.document.thisForm.HReftarget.value = reftar;
    //cjc    window.document.thisForm.HTarget.value = "xt_orderform_editquantities.asp";
    //cjc    window.document.thisForm.action = "hopshop.asp"
    window.document.thisForm.action = "xt_orderform_editquantities.asp"
  }
  else {
    window.document.thisForm.HTarget.value = reftar;
    window.document.thisForm.action = "shop.asp";
  }
  window.document.thisForm.submit()
}
  
function tellus_onclick(url) {
  tellus_window = window.open(url,"smallwindow",'toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=0,resizable=yes,width=500,height=400');
  //alert("here are the formvars being passed to the tellus URL - " + url)
  tellus_window.focus();
}

function open_media_window(url) {
  smwin = window.open(url,"smwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=no,width=325,height=295');
  smwin.focus();
  //smwin == open          
}

function open_window(url) {
  smwin = window.open(url,"smwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,width=630,height=500');
  smwin.focus();
  //smwin == open          
}

function open_window_800(url) {
  smwin = window.open(url,"smwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,width=820,height=820');
  smwin.focus();
  //smwin == open          
}

function open_photo_window(url) {
  smwin = window.open(url,"smwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,width=720,height=500');
  smwin.focus();
  //smwin == open          
}

function open_window_mysize(width, url) {
  smwin = window.open(url,"smwin",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,width='+width+',height=500');
  smwin.focus();
  //smwin == open          
}

//////////////////////////////////////////////////
//--- on product.asp
////////////////////////////////////////////////

function open_img_window(img) {
  link = 'lview.asp'
  file = link + '?imgfile=assets/imglib500/' + img;
  lview = window.open(file,"smallwindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=no,width=550,height=560');
  lview.focus();
}

function open_catz_img_window(img) {
  link = 'lview.asp'
  file = link + '?imgfile=assets/zz800/' + img;
  lview = window.open(file,"smallwindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,width=600,height=600');
  lview.focus();
}

function SubmitHome_onclick(tar,anchor) { ;
  document.thisForm.HReftarget.value = document.thisForm.HTarget.value;
  document.thisForm.HFwdTar.value=tar;
  document.thisForm.HTarget.value=tar;
  document.thisForm.HCat_id.value = 0 ;
  document.thisForm.HReqYM.value= "";
  document.thisForm.HC6.value= 0;document.thisForm.HCD6.value= "";document.thisForm.HTar6.value= "";
  document.thisForm.HCatid6.value = 0
  document.thisForm.HC5.value=0;document.thisForm.HCD5.value="";document.thisForm.HTar5.value="";
  document.thisForm.HCatid5.value = 0
  document.thisForm.HC4.value=0;document.thisForm.HCD4.value="";document.thisForm.HTar4.value="";
  document.thisForm.HCatid4.value = 0
  document.thisForm.HC3.value=0;document.thisForm.HCD3.value="";document.thisForm.HTar3.value="";
  document.thisForm.HCatid3.value = 0
  document.thisForm.HC2.value=0;document.thisForm.HCD2.value="";document.thisForm.HTar2.value="";
  document.thisForm.HCatid2.value = 0
  document.thisForm.HC1.value=0;document.thisForm.HCD1.value="";document.thisForm.HTar1.value="";
  document.thisForm.HCatid1.value = 0
  if (! (anchor == 'undefined')){
        document.thisForm.action = document.thisForm.action + "#"+ anchor;  
  }
  document.thisForm.submit()
}

function LogInBut(fTarget) {
  document.thisForm.HReftarget.value = document.thisForm.HTarget.value;
  document.thisForm.HTarget.value = "login.asp"
  document.thisForm.HFwdTar.value = fTarget
  document.thisForm.Hpf_id.value = "" ;
  document.thisForm.HCat_id.value = "" ; 
  document.thisForm.action= "<%=sec%>shop.asp";
  document.thisForm.submit();
}

function GetHeader(fTarget) {
  document.thisForm.HReftarget.value = document.thisForm.HTarget.value;
  document.thisForm.HTarget.value = fTarget
  document.thisForm.action= "shop.asp";
  document.thisForm.submit();
}

//////////////////////////////////////////////////
//scripts for basket.asp  so they're present for all calls prior to basket
///////////////////////////////////////////////

function BuyTime() {
  if (dirty == true){
    alert("Please click the recalculate button to update your cart before continuing.");
    return false;
  }   
  else { 
    return true;
  }
}

function BasketWork(fBasTarget) {
  //--- For debugging:
  //alert("hello from basketwork passed - " + fBasTarget)
  
//cjc  window.document.thisForm.HTarget.value = fBasTarget;
//cjc  window.document.thisForm.action = "hopshop.asp";
  window.document.thisForm.HTarget.value = "basket.asp"
  window.document.thisForm.action = "xt_orderform_editquantities.asp"
  window.document.thisForm.submit();
} 

function DelItem(fBasTarget,fDelIndex) {
  //--- For debugging:
  //alert("Into DelItem")
  
//cjc  window.document.thisForm.HTarget.value = fBasTarget;
  window.document.thisForm.HDelIndex.value = fDelIndex;
//cjc  window.document.thisForm.action = "hopshop.asp";
  window.document.thisForm.action = fBasTarget;
  window.document.thisForm.submit();
} 

function clear_attr(){
  window.document.thisForm.Hattrvalue1.value = "";
  window.document.thisForm.Hattrvalue2.value = "";
  window.document.thisForm.Hattrvalue3.value = "";
  window.document.thisForm.HComments.value = "";  
}
  
/////////////////////////////////////////////////
//DW rollover functions
///////////////////////////////////////////////

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/////////////////////////////////////////////////
//shop.asp scripts
///////////////////////////////////////////////

function popUp(url) {
  sealWin=window.open(url,"win",'toolbar=0,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=650,height=450');
  self.name = "mainWin";
}

function AddToCartClick(fpf_id,fdept_id,fTar,fref,fplus,fpartselected) {
  window.document.thisForm.HReftarget.value = fref;
  window.document.thisForm.Hplus.value= fplus;
  window.document.thisForm.HCat_id.value="";
  window.document.thisForm.Hpf_id.value =fpf_id;
//cjc  window.document.thisForm.HTarget.value = fTar;
  window.document.thisForm.HTarget.value = "basket.asp";
  window.document.thisForm.HFwdTar.value = "basket.asp";
  window.document.thisForm.Hdept_id.value = fdept_id;
  window.document.thisForm.HCounter.value=fpartselected
  if (fTar == "xt_orderform_additem.asp") {
		window.document.thisForm.action = "xt_orderform_additem.asp"
  }		
  else if (fTar == "product.asp") {
    window.document.thisForm.action = "shop.asp";
    window.document.thisForm.HTarget.value = "product.asp"
  }
  else {
	window.document.thisForm.action = "shop.asp"
  }	
  window.document.thisForm.submit()
}

//CJC commented this out as per DAN-O 10/19/05 
function noRightClick() {
//  if (event.button==2) {
//      alert("Copywrite Bavarian Autosport 2001-2004")
//  }
}

//--- Prevent any right click to save images from the web site to disk
//    Shouldn't this function call go in the main document?  02/05/05 dwl
//
document.onmousedown=noRightClick

//--- end of javascript.js
