﻿// JScript File
function ShowPopup(hoveritem, imageUrl, partDesc) 
    { 
        //alert(imageUrl);
        hp = document.getElementById("hoverpopup"); 
        sp = document.getElementById("SpanPartName"); 
        //sp.innerText = partDesc;
        //alert(findY(hoveritem));
        // Set popup to visible 
       
        var pan = document.getElementById('ctl00_PlaceHolderMain_pnlProductDetails');
        //alert(pan.scrollTop);
        var x = findX(hoveritem);
     
        //alert(hp.offsetLeft);
        
        var y = findY(hoveritem);
    
        if(((y - pan.scrollTop) + 250) > 575)
        {
            y = y - 250 ; 
            //alert(y);  
        }
      
        hp.style.top =  y  - pan.scrollTop + 'px' ; 
        hp.style.left = x + 40 + 'px'; 
        
//        if(navigator.appName == "Netscape")
//        {
//           alert(hp.style.top);
//        }
        //alert(imageUrl);
        hp.style.visibility = "visible"; 
        hp.style.background = 'url(' + imageUrl + ')'; 
        hp.style.backgroundRepeat  = 'no-repeat';
        hp.style.backgroundPosition = 'center center'; 
        hp.style.backgroundColor = 'white';
        hp.style.textAlign = 'center';
        //hp.filters.alpha.opacity= 100;
        //alert(y);
        
    } 


    function KeepPopup(hoveritem) 
    { 
        hp = document.getElementById("hoverpopup"); 

        // Set popup to visible 
        hp.style.top = hoveritem.offsetTop; 
        hp.style.left = hoveritem.offsetLeft; 

        hp.style.visibility = "visible"; 
       
    } 

    function HidePopup() 
    { 
        hp = document.getElementById("hoverpopup"); 
        hp.style.visibility = "Hidden"; 
    } 
    
    
    
    function findX(obj) { 
        var x = 0; 
        while (obj) { 
        x += obj.offsetLeft 
        obj = obj.offsetParent; 
        } 
        //alert(x); 
        return x;
        } 
    function findY(obj) { 
        var y = 0; 
        while (obj) { 
        y += obj.offsetTop
        //alert(obj.id + "  " + obj.offsetTop); 
        obj = obj.offsetParent; 
        } 
         //alert(y); 
         return y;
        } 
        

    function ShowPopupNoOffset(hoveritem, imageUrl,partDesc) 
    { 
        //alert(imageUrl);
        hp = document.getElementById("hoverpopup"); 
        //findY(hoveritem);
        // Set popup to visible 
        //alert( findX(hoveritem));
        var pan = document.getElementById('ctl00_PlaceHolderMain_pnlProductDetails');
        //alert(pan.scrollTop);
        sp = document.getElementById("SpanPartName"); 
        //sp.innerText = partDesc;
        
        var y = findY(hoveritem);
        var x = findX(hoveritem);
        //alert(y);
        if(((y - pan.scrollTop)) > 350)
        {
            y = (y) - 250 ; 
            //alert(y);  
        }
   
        
        hp.style.top =  y  + 'px'; 
        hp.style.left = x + 40 + 'px'; 
        
        //alert(imageUrl);
        hp.style.visibility = "visible"; 
        hp.style.background = 'url(' + imageUrl + ')'; 
        hp.style.backgroundRepeat  = 'no-repeat';
        hp.style.backgroundPosition = 'center center' 
        hp.style.backgroundColor = 'white';
        hp.style.textAlign = 'center';
        //alert(y);
        
    } 
    
     function TabChanged(sender, args)
    {
        //alert(sender.get_activeTabIndex());
        switch(sender.get_activeTabIndex())
        {
            case 0:
                //document.getElementById('ctl00_PlaceHolderMain_Tabs_Panel1_ddYear').focus();
                document.getElementById('ctl00_PlaceHolderMain_Tabs_Panel1_rcomboYear').focus();
            break;
            case 1: 
                document.getElementById('ctl00_PlaceHolderMain_Tabs_Panel2_txtApplSearch').focus();
            break;
            case 2:
                document.getElementById('ctl00_PlaceHolderMain_Tabs_Panel3_txtVinSearch').focus()
            break;
            
            break;
        }

    }
    
    function bodyOnLoad()
    {
        alert("body load");
    }
    
    function PrintPage(site)
    {
        var bolWebPartFound = true;
      
        if (document.getElementById != null)
         {
          //Create html to print in new window
            var PrintingHTML = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
            PrintingHTML += '<html xmlns="http://www.w3.org/1999/xhtml" >';
            PrintingHTML += '<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="content-language" content="en" /><input name="ctl00$ucHeaderTag$hdnPageId" type="hidden" id="ctl00_ucHeaderTag_hdnPageId" />';
            PrintingHTML += '<title></title><link href="Themes/4s.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="Scripts/AppScript.js"></script></head><body>';
          
            PrintingHTML += '<div><table><tr><td colspan="4"><img src="Images/' + site + '_print.gif" id="Img1" style="border:0px;" /></td></tr>';
            PrintingHTML += '<tr><td colspan="4"><table class="printStyle" style="background-color:Gray;color:White;font-weight:bold;border:solid 1px white;width:100%;"  border="0">';
            PrintingHTML += '<tr style="vertical-align:bottom;height:20px;"><td style="width:35px">Order Qty</td><td style="width:40px">Part#</td><td style="width:50px">Per Car Qty</td><td style="width:50px">Brand</td><td style="width:235px">Product</td><td  style="width:350px">Comments</tr></table>';
            PrintingHTML += '<tr><td colspan="4"><div  id="ctl00_PlaceHolderMain_pnlProductDetails" style="width:100%;">';

            var WebPartData = document.getElementById('ctl00_PlaceHolderMain_pnlProductDetails');
              if (WebPartData != null)
              {
               PrintingHTML += WebPartData.innerHTML;
               bolWebPartFound = true;
              }
              else
              {
               bolWebPartFound = false;
               alert ('Cannot Find Web Part');
              }
             }
            PrintingHTML += '</div></td></tr></table>\n</BODY>\n</HTML>';
            PrintingHTML = PrintingHTML.replace(/Delete.gif/g,"BLANK.GIF");
         //PrintingHTML += '</td></tr></table> </div>   \n</BODY>\n</HTML>';
         //Open new window to print
         if (bolWebPartFound)
         {
              var id;
              //alert(PrintingHTML);
              var PrintingWindow = window.open("", id , "toolbar,width=800,height=600,scrollbars,resizable,menubar");
              PrintingWindow.document.open();
              PrintingWindow.document.write(PrintingHTML);
              // Open Print Window
              
              //window.print(PrintingHTML);
              PrintingWindow.document.close(); 

              PrintingWindow.print();
         }
         
    }
    
    function ShowHelpText(divId, img)
    {
        //alert(divId);
        hp = document.getElementById(divId); 
        //alert(img);
        var x = findX(img);
        var y = findY(img);
        //alert(x);
        //alert(y);
        hp.style.top =  y + 25 + 'px' ; 
        hp.style.left = x + 5 + 'px' ; 
        hp.style.visibility = "visible"; 
    }
    
    function KeepHelpText(helpDiv) 
    { 
        //hp = document.getElementById("hoverpopup"); 

        // Set popup to visible 
        helpDiv.style.top = hoveritem.offsetTop; 
        helpDiv.style.left = hoveritem.offsetLeft; 
        helpDiv.style.visibility = "visible"; 
       
    } 

    function HideHelpText(helpDiv)
    { 
        hp = document.getElementById(helpDiv); 
        hp.style.visibility = "Hidden"; 
    }
    
    function SelectAllParts(flag)
    {
        
        for(i = 0; i < document.getElementsByTagName('*').length; i++)
        {
            elm = document.getElementsByTagName('*')[i]
               
            if (elm.type=='checkbox' &&  elm.id.substring(0,34)=='ctl00_PlaceHolderMain_RepeaterImg_') 
            {
               //alert(elm.id);
               elm.checked = flag; 
            }
        }
        
    }
    
    function ShowAlert(message)
    {
        alert(message);
        return
    }
    
    String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }

    function CartClick(ctrl){
        
        if(document.getElementById(ctrl.id.replace("imgBtnShoppingCart","txtQty")).value.trim() == "")
        {
            alert("Please enter the order quantity before adding to cart!");
            return;
        }
    }
    
   function getBrandUrl(query, partNum){
   
        /*
        switch(brand){
            case "STD":
                url = "http://www.standardbrand.com/web_app/catalog/smp_bgbulk.aspx?strSearch=" + partNum;
            break;
            case "BWD":
                url = "http://www.bwdbrand.com/web_app/catalog/bwd_bgBulk.aspx?strSearch=" + partNum;
            break;
            case "NIE":
                url = "http://www.niehoff.com/catalogs/nie_bgbulk.aspx?strSearch=" + partNum;
            break;
            case "FS":
                url = "http://www.smpcorp.com/Test/4sCat/CatalogSearch.aspx?action=GetPartSrch&Site=FourSeasons&Part=" + partNum;
             break;
             case "FA":
                url = "http://www.smpcorp.com/Test/4sCat/CatalogSearch.aspx?action=GetPartSrch&Site=FactoryAir&Part=" + partNum;
             break;
             case "MU":
                url = "http://www.smpcorp.com/Test/4sCat/CatalogSearch.aspx?action=GetPartSrch&Site=Murray&Part=" + partNum;
             break;
            default : 
            break;
        }
        */
       //alert(query);
       var outQuery = "";
       var isPartFlag = false;
       var isVehicleFlag = false;
       var oldVehicle = "";
       if (query.toString().length > 0) {
           var splitResult = query.substring(1).split("&");
           for (i = 0; i < splitResult.length; i++) {
               if (splitResult[i].startsWith("Part=")) {
                   splitResult[i] = "Part=" + partNum
                   isPartFlag = true;
               }

               if (splitResult[i].startsWith("SType=")) {
                   splitResult[i] = "SType=0"
               }
               
               if (splitResult[i].match("vehicle=")) {
                   isVehicleFlag = true;
                   oldVehicle = splitResult[i].substring(8,splitResult[i].length);
               }
               
               //alert(outQuery);
               outQuery += ((i==0)?"?" : "&") + splitResult[i] ;
           }
       }
       var hdnControl =  document.getElementById("ctl00_PlaceHolderMain_hdnVehicleId");
       if (!isVehicleFlag & hdnControl != null) {
            outQuery += ((outQuery.length > 0) ? "&" : "?") + "vehicle=" + hdnControl.value;
        }
        else if (oldVehicle.length > 0 && outQuery.indexOf(oldVehicle) > 0 ) {
            outQuery = outQuery.replace(oldVehicle, hdnControl.value);
       }
       
       if (!isPartFlag) outQuery += ((outQuery.length > 0)?"&" : "?" ) + "Part=" + partNum;
       window.location.href = "CatalogSearch.aspx" + outQuery; 
    }
    
    function getBrandUrlFromList(query, partNum) {

        //alert(query);
        var partQuery = "";
        var isPartFlag = false;
        if (query.toString().length > 0) {
            var splitResult = query.substring(1).split("&");
            for (i = 0; i < splitResult.length; i++) {
                if (splitResult[i].startsWith("Part=")) {
                    partQuery = splitResult[i];
                    isPartFlag = true;
                }
            }
        }

        if (isPartFlag) {
            query = query.replace(partQuery, "Part=" + partNum);
        }
        else {
            query += ((query.length > 0) ? "&" : "?") + "Part=" + partNum;
        }
        window.location.href = "CatalogSearch.aspx" + query;
    }
        
    function setBrowser()
    {
         //alert(navigator.appName + " hellow " + navigator.appVersion);
        
        if((screen.width < 1024) && (screen.height < 768))
        {
            var div = document.getElementById("divBrowserInfo");
            div.style.visibility = 'visible';
            div.style.display = 'block';
            //document.getElementById("divBrowserInfo").style.visibility = "visible"; 
            
            document.getElementById("spanResText").style.visibility = "visible";  
        }
        ajaxFunction();

        
        
    }
    
    function OPenCloseInfo(flag)
    {
        document.getElementById("divViewingInfo").style.visibility = flag;   
    }
    
    function ajaxFunction()
    {
      var xmlHttp;
      try
      {
          // Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
      }
      catch (e)
      {
          // Internet Explorer
          try
          {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
            try
            {
                 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

            }
            catch (e)
            {
                var div = document.getElementById("divBrowserInfo");
                div.style.visibility = 'visible';
                div.style.display = 'block';
                document.getElementById("spanPageIssueLink").style.visibility = "visible";
                document.getElementById("divViewingInfo").style.visibility = "visible";
                return false;
            }
          }
       }
   }

   function showBgPopupDiv() {
       var hp = document.getElementById("hoverpopup");
       hp.style.visibility = "visible";
       hp.style.background = 'url(' + document.getElementById("ctl00_PlaceHolderMain_hdnImageUrl").value + ')';
       hp.style.backgroundRepeat = 'no-repeat';
       hp.style.backgroundPosition = 'center center';
       hp.style.backgroundColor = 'white';
       hp.style.textAlign = 'center';
   }


   function hideBgPopupDiv() {
       var hp = document.getElementById("hoverpopup");
       hp.style.visibility = "hidden";
   }

   function hideGeneralPopupDiv(ctrl) {
       ctrl.style.visibility = "hidden";
   }
   
   function keepBgPopupDiv(ctrl) {
       //var hp = document.getElementById("hoverpopup");
       ctrl.style.visibility = "visible";
   }

   function clearPartSearchBox() {
       document.getElementById("ctl00_PlaceHolderMain_Tabs_Panel1_txtPartSrch").value = "";
   }


   function showMultiPopupDiv(ctrl) {
       //alert(findX(ctrl));
       var pan = document.getElementById('ctl00_PlaceHolderMain_PanelWatermark');
       //alert(pan.scrollLeft);
       var hp = document.getElementById("hoverpopup");
       hp.style.visibility = "visible";
       hp.style.background = 'url(' + document.getElementById(ctrl.id.replace("imgPart","hdnImageUrl")).value + ')';
       hp.style.backgroundRepeat = 'no-repeat';
       hp.style.backgroundPosition = 'center center';
       hp.style.backgroundColor = 'white';
       hp.style.textAlign = 'center';
       var left = (findX(ctrl) - 100) - pan.scrollLeft;
       hp.style.left = (left > 600)? 600 : left;
       hp.style.top = findY(pan) + 100;
   }

   function validateStringLen() {
       
       var ctrl = document.getElementById("ctl00_PlaceHolderMain_Tabs_Panel1_txtPartSrch")
       if ((document.getElementById("ctl00_PlaceHolderMain_Tabs_Panel1_Srchbtns_1").checked ||
         document.getElementById("ctl00_PlaceHolderMain_Tabs_Panel1_Srchbtns_2").checked)
         && ctrl.value.length < 3) {
           alert("Please enter atleast 3 characters for search!");
           return false; 
       }

       return true;
   }

   var clientX;
   var clientY;

   function CloseExtender() {

       //alert(clientY);
       if (clientX > 80 && clientX < 310 && clientY > 75 && clientY < 425) {
           return false;
       }
       else {
           
           var imgIn = document.getElementById("ctl00_PlaceHolderMain_Tabs_TabPanel5_imgbtnComponBoxIn");
           var imgOut = document.getElementById("ctl00_PlaceHolderMain_Tabs_TabPanel5_imgbtnComponBoxOut");
           imgOut.style.display = "none";
           imgIn.style.display = "block";
           return true;
       }   
   }

   function findTargetControl(ev) {
       //origEl = ev.target || ev.srcElement;
       //targetControl = origEl.id;
       clientX = ev.clientX;
       clientY = ev.clientY;
   }

   //Script for Catagory lookup

   function CategoryGroupClick(ctrl) {

       flag = ctrl.checked
       var count = document.getElementById(ctrl.id.replace("chkItemSelect", "hdn_ItemsCount")).value
       for (i = 0; i < count; i++) {
           elm = document.getElementById(ctrl.id.replace("chkItemSelect", "lvItems_ctrl" + i.toString() + "_chkItemSelect")); if (elm.type == 'checkbox') {
               //alert(elm.id);
               elm.checked = flag;
               AddCategoryToSearchList(elm);
           }
       }
   }

   function AddCategoryToSearchList(ctrl) {

       var txtCategory = document.getElementById('<%=this.txtCategory.ClientID%>');
       var catagories = document.getElementById('<%=this.hdn_txtCategory.ClientID%>');
       var layout = document.getElementById(ctrl.id.replace("chkItemSelect", "hdn_WebLayoutId")).value;
       var code = document.getElementById(ctrl.id.replace("chkItemSelect", "hdn_AttributeCode")).value;
       var value = document.getElementById(ctrl.id.replace("chkItemSelect", "hdn_AttributeValue")).value;
       if (ctrl.checked) {
           if (catagories.value == "") {
               catagories.value = layout + ":" + code + "," + value
           }
           else {
               if (catagories.value.indexOf(layout + ":" + code + "," + value) < 0)
                   catagories.value = catagories.value + ";" + layout + ":" + code + "," + value
           }
       }
       else {
           if (catagories.value.length > 0) {

               var fText = (catagories.value + ";").replace(layout + ":" + code + "," + value + ";", "")
               catagories.value = fText.substring(0, fText.length - 1);

           }
       }
       //alert(catagories.value);
       if (catagories.value.length > 0) txtCategory.value = "<<Selected>>";
       else txtCategory.value = "Click to select Catagories/Attributes";
       //AjaxControlToolkit.TextBoxWrapper.get_Wrapper(txtCategory).set_Watermark("Hellow");
   }

   function ClearCustomSearch() {
        var pan = $get('divCustomSearch');
        for (i = 0; i < pan.getElementsByTagName('INPUT').length; i++) {
            elm = pan.getElementsByTagName('INPUT')[i];
            if (elm.type == 'checkbox' && elm.checked) {
                elm.checked = false;
            }
        }

        document.getElementById('<%=txtCategory.ClientID%>').value = "Click to select Catagories/Attributes";
        document.getElementById('<%=txtPopCode.ClientID%>').value = "Click to select Pop Codes";
   }


   function showGeneralPopupDiv(ctrlId) {
       var hp = document.getElementById(ctrlId);
       //alert(hp);
       hp.style.visibility = "visible";
   }

   function hideGeneralPopupDivWithId(ctrlId) {
       var hp = document.getElementById(ctrlId);
       hp.style.visibility = "hidden";
   }

   
   //End Script