﻿/**********************************
    KawasakiLive.com
    Copywrite 2008
   
***********************************/   
   
   var DEBUG_MODE = false;
          
   function isvalidUrl(){ 
   }


   var currentSearhFocus = "";
   var rootKaw = "http://www.kawasaki.com";
    
  function downloadContent(filename) {
  
      var newwin = window.open('../fuseDownload/DownloadImage.aspx?fString='+filename);
      //PageMethods.DownloadFile(filename, onSuccess, onFailed, ctx);
  
  }
  
  function viewImage(path, width, height) {
    var rgx = new RegExp(/img=(.*)/);
    var image = rgx.exec(path)[1];
    window.open("ViewImage.html?image=" + image, "imageWindow", "scollbar=yes,toolbar=no,resize=no,address=no,width=" + width + ",height=" + height);
    delete rgx;
  }
    
   function dealerSearch_Click() {
       var q = document.getElementById("inputSearchDealer");
       if (currentSearhFocus=="d2") q = document.getElementById("inputSearchDealerSub");
       if ((q.value != "") && (q.value != " zip code") && (q.value != "      zip code")) {
           var frUrl = "strContentURL=/SITE/DLDEALERLOCATOR/DLDEALERLOCATOR.ASP?zip%3D" + q.value + "%26DISP%3DN%26amp%3BProdType%3DV%26amp%3BProdLine%3DALL";
           //document.location.href = rootKaw + "/DefaultFrame.aspx?" + frUrl;
           window.open(rootKaw + "/DefaultFrame.aspx?" + frUrl);
       }
   }
   
   function dealerSearch_Focus() {
       var q = document.getElementById("inputSearchDealer");
       if (q.value == " zip code")
           q.value = "";
        currentSearhFocus = "d";
   }
   
   function dealerSearch_Blur() {
       var q = document.getElementById("inputSearchDealer");
       if (q.value == "")
           q.value = " zip code";
        currentSearhFocus = "";
   }

   function dealerSearchSub_Focus() {
       var q = document.getElementById("inputSearchDealerSub");
       if (q.value == " zip code")
           q.value = "";
       currentSearhFocus = "d2";
   }

   function dealerSearchSub_Blur() {
       var q = document.getElementById("inputSearchDealerSub");
       if (q.value == "")
           q.value = " zip code";
       currentSearhFocus = "";
   }


   /* 
   
   */
   function trapKeypress(t, e, theKey) {
       var iKeyCode = 0;
       if (window.event) iKeyCode = window.event.keyCode
       else if (e) iKeyCode = e.which;
       if ((t == 1) && (iKeyCode == theKey)) {
           siteSearch_Click();
           return false;
       }
       else if ((t == 2) && (iKeyCode == theKey)) {
           dealerSearch_Click();
           return false;
       }
   }
   
   
   
   
   
   
   /// 
   var lzcinit="      zip code"; 
   function zipCodeSelect_in(ob){
    if(ob.value==lzcinit)
       ob.value="";
        
   }
   
   
   /// Zip Codes 
   function zipCodeSelect_out(ob){
       if(ob.value=='')       
       ob.value=lzcinit;   
   }
   
   
   /// Downloads and Extras
   function clickDNE(ob,t){
       var identifier = "5_2_0";
       if (parseInt(t) == 2) identifier = "5_3_0";
       selectEvent(ob,identifier);
   }
   
   
   /// Send to friend - Event
   function STF_Event(){
   }
   
   function scrollTop(){
       //$('html, body').animate({ scrollTop: 0 }, 'slow');
       $('html').animate({ scrollTop: 0 }, 'slow'); 
   }
   
   /// Select a racer
    function selectRacer(ob,eid,tid){
        if(DEBUG_MODE)
            alert("selectRacingEvent :eid:" + eid + ":tid:" + tid);
        
    
        var identifier="4_"+tid+"_"+eid;
        selectEvent(ob,identifier);
    }


    function selectRacerFromId(ob, val) {
        var sp = val.split("_");
        var identifier = "4_" + sp[1] + "_" + sp[0];
        selectEvent(ob, identifier); 
    }
   
   
     
   function selectRacingEvent(ob,eid,sid){
        if(DEBUG_MODE)
        alert("selectRacingEvent"+eid);

        var identifier="3_"+sid+"_"+eid;
        selectEvent(ob,identifier);
   }
       
   function selectProductEvent(ob,eid,sid){
        if(DEBUG_MODE)
        alert("selectProductEvent"+eid);

    if (typeof (sid) == "undefined") {sid = 0; }

    var identifier = "1_" + sid + "_" + eid;
        selectEvent(ob,identifier);
   }
   
   
   
   function callLifestyleEvent(ob,eid){
        if(DEBUG_MODE)
        alert("callLifestyleEvent" + eid);
        
        var identifier="2_"+eid+"_0";
        selectEvent(null, identifier);   
   }


    ///Holds the current event identifier
    /// Default is 1_0_0, products section
    var currentEventItentifier = "1_0_0";    
   
   
   
   /// Navigate to new section of site
   /// sender: object 
   function selectEvent(sender,e){
        if(DEBUG_MODE)
            alert(e);

       
        window.location = "sections.aspx?#/" + e;

        scrollTop();

        currSelTab = "secTab_1";
   }
   
       
   function callFlash(s,ss,sss){
        alert("callFlash");
        //document.getElementById("flashContent").navigateSection(s,ss,sss);
   }
       
       ///  Function: navigateMenu_click
       ///  Flash calls this function when navigating to a specific function
       ///  sectionId:          int:    (required) Section identifier (included in navigation.xml feed id atribute ie: <section id="1" title="PRODUCTS"> )
       ///  subsectionId:       int:    (optional, required if passing subSubSectionId) Subsection identifier (included in navigation.xml feed id atribute ie: <subsection id="1" title="PRODUCTS 1"> )
       ///  subSubSectionId:    int:    (optional) Sub-Sub section identifier (included in navigation.xml feed id atribute ie: <subsection id="1" title="EVENT 2"> )
       function navigateMenu_click(sectionId, subsectionId, subSubSectionId)
       {
           
             if(DEBUG_MODE)
             alert("DEBUG MODE: " + sectionId+" :: "+subsectionId+" :: "+subSubSectionId);
       
       
            /*  Note:
                sectionId       should always be passed
                subSectionId    should be passed if the navigating to a sub-sub-section (actual event or rider page)
                                We never actual link to a "Sub Section" of the site, only a section landing page or an event
                subSubSectionId should be passed when navigating top an actual event detail otherwise pass void. 
                                NOTE: both sectionId and subSectionId are required when linking to an event.
                
            */
            
            /* 
                Steps in this function 
                change deep link in querystring
                call ajax for lower section of webpage... subpage only
             */
                //document.getElementById
                
                /// Note
                // Section 1 is products    
                // Section 4 is riders...   there will only be a section and a subsection
                //                          Call rider detail info page.
                // Section 2 is lifestytle. there will only be a sectrion and an event id

         
         
                currentEventItentifier = sectionId + "_" + subsectionId + "_" + subSubSectionId;
         
                
                if(typeof sectionId == "undefined") {
                    alert("Error on navigation, sectionId required");
                    //return;
                }
                if(typeof subsectionId == "undefined") {
                    subsectionId = 0;
                }
                if(typeof subSubSectionId == "undefined") {
                    subSubSectionId = 0;
                }
                
                if(sectionId==0){
                    return;
                }
                
                
                //NOTE!!!
                //Move the sub section to the last parameter if thats all there is\
                //This ensures that the third variable is always the event id
                //Mainly applies to the lifestyle section of the site which does not use a tertiary navigation elements
                if((parseInt(subSubSectionId)==0)&&(parseInt(subsectionId)!=0)){
                    subSubSectionId=subsectionId;
                    subsectionId=0;
                }
                
               
                if(DEBUG_MODE)
                alert("new values: " + sectionId+" :: "+subsectionId+" :: "+subSubSectionId);

               

                document.getElementById("hfiS1").value=sectionId;
                document.getElementById("hfiS2").value=subsectionId;
                document.getElementById("hfiS3").value=subSubSectionId;  
                //document.getElementById(hiddenVar).value="Yello";
                
                //reset any state holders
                //currSelTab="";
                
                __doPostBack('btnUpdate',''); 
           
       }
       
       
      
     
     
/// Global error handler     
function glErr(){
    window.location.href="";
}


/*  Function:    sectionChange
    Parameters:  sec: interger section id
    Description: Used for sections that contain tabs views of content...
                 Content pages must be programmed to call this function             
*/             
function sectionChange(sec){
    
    currSelTab="secTab_"+sec;
    
    resetTabHighlights();
    
    var nT=5;
    for(a=1;a<=nT;a++){
        var t=document.getElementById("content_tab"+a);
        if(t){
        if(a==sec){
            t.style.display='block';
        }
        else{
            t.style.display='none';
        }
        }
    }

    window.focus(); 
    //window.blur();return true;
    
 }
 
 

// function selectRacer(id){
//    if(id=="0"){return}
//    //!!! NEED TO PASS RECER INFO TO FLASH
//    navigateMenu_click(4,id);
// }
 
 
 ///Tab selection
 var currSelTab = "secTab_1";
 
 function rollOnTab(o){
    var src=o.src;
    if(src.indexOf('_over.jpg')>1){   
    }
    else{
        o.src=ReplaceAll(o.src,".jpg","_over.jpg");
    }
 }
 
 function rollOffTab(o){
   
   if(o.id==currSelTab){return}
       
   var src=o.src;
    if(src.indexOf('_over.jpg')>1){
        o.src=ReplaceAll(o.src,"_over.jpg",".jpg");
    }
    else{   
    }
 }
 
 function resetTabHighlights(){
    for(x=1;x<=5;x++){
        var hdl = document.getElementById("secTab_"+x);
        if(hdl){
            rollOffTab(hdl);
        }
    }
 }
 
 ///Image rollover function
 function rollOn(o){
    var src=o.src;
    if(src.indexOf('_over.jpg')>1){   
    }
    else{
        o.src=ReplaceAll(o.src,".jpg","_over.jpg");
    }
 }
 function rollOff(o){
   var src=o.src;
    if(src.indexOf('_over.jpg')>1){
        o.src=ReplaceAll(o.src,"_over.jpg",".jpg");
    }
    else{   
    }
 }
 





 
 
 ///String Replace
function ReplaceAll(sString, sReplaceThis, sWithThis) { 
    if (sReplaceThis != "" && sReplaceThis != sWithThis) { 
    var counter = 0; 
    var start = 0; 
    var before = ""; 
    var after = ""; 
    while (counter<sString.length) { 
    start = sString.indexOf(sReplaceThis, counter); 
    if (start == -1) { 
    break; 
    } else { 
    before = sString.substr(0, start); 
    after = sString.substr(start + sReplaceThis.length, sString.length); 
    sString = before + sWithThis + after; 
    counter = before.length + sWithThis.length; 
    } 
    } 
    } 
    return sString; 
    } 
