﻿// JScript File

    function is_ie_browser()
    {
    	var browserName=navigator.appName; 

    	if (browserName=="Microsoft Internet Explorer")
    	   return true;   	 
    	else
    	   return false;      	
    }

    function OpenWin_1(id) 
    { //v2.0
        window.open('productinfo.aspx?id='+id,'ProductDetails','width=650,height=500,directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0');
    }
    
    function OpenWin(id) 
    { //v2.0
        window.open('../productinfo.aspx?id='+id,'ProductDetails','width=650,height=500,directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0');
    }
    
    function OpenWinExDemo(id)
    { //v2.0
        window.open('exdemo.aspx?id='+id,'ProductDetails','width=549,height=350,directories=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');
    }
    
    function BuyProductBounce(id)
    {
        window.location='dealer/displayproduct.aspx?pid='+id;
    }
    
    function sayhello()
    {
	alert("hello.");
    }
    
    function RetrieveProductsByCheckBox(evt)
    {   
        var myItemId = "";
        var findDivCat = document.getElementById("divCat");
        if (findDivCat != null)
            myItemId = findDivCat.innerHTML;  //get current cat id
        if (myItemId != "")
        {        
            var myArray = myItemId.split("|");
            var myId = myArray[0];
            var myCategory = myArray[1];
            var myVID = myArray[3];
            var myType = myArray[2];
            
            if (IsNumeric(myId))
            {
                if (is_ie_browser())
                {  //go to page top
                      location.href = "#top";
                }
                
                //empty the area
                var findDiv = document.getElementById("divProductsList");
                findDiv.innerHTML = "";
                     
                //show product category as breadcrum
                var findDivBreadcrum = document.getElementById("divBreadcrumProductCategory");
                findDivBreadcrum.innerHTML = "<strong>" + myCategory + "</strong>";                                 
                
                var findDivspanLoadingBar = document.getElementById("spanLoadingBar");
                findDivspanLoadingBar.innerHTML = "<img src='../images/loading.gif' />Loading....";            
                
                //set the myId with hide ex demo variable
                if (evt.checked == true)                    
                    myId = myId + "|h"; //show
                else
                    myId = myId + "|s"; //hide
                
                if (myType=="cat")
                        myId = myId + "|cat";
                else if (myType=="ven")
                        myId = myId + "|ven|" + myVID;
                
                Anthem_InvokePageMethod('GetProductsByCategoryID', [myId], ProductsCallbackListProducts);
            }
            else
                alert('no record in myArray[0]');
        }
    }
        
    
    function RetrieveProducts(myItemId)
    {
        var findDivCat = document.getElementById("divCat"); //save current CAT ID
        if (findDivCat != null)
            findDivCat.innerHTML = myItemId;
                
        var myArray = myItemId.split("|");
        var myId = myArray[0];
        var myCategory = myArray[1];
        var myVID = myArray[3];
        var myType = myArray[2];

        if (IsNumeric(myId))
        {
            if (is_ie_browser())
            {  //go to page top
                  location.href = "#top";
            }
            else
                window.location.href="#top";
            //empty the area
            var findDiv = document.getElementById("divProductsList");
            findDiv.innerHTML = "";

            var findDivProductNewsContent = document.getElementById("ctl00_ContentPlaceHolderBodyMain_divProductNews");
            if (findDivProductNewsContent != null)
                findDivProductNewsContent.innerHTML="";

            //dealer zone
            var findDivCTBreadcrump = document.getElementById("ctl00_ContentPlaceHolderBodyMain_breadcrump");
            if (findDivCTBreadcrump != null)
                findDivCTBreadcrump.innerHTML="COMPONENTS";
            
            //dealer zone 
            var findDivSpecialAndPromotion = document.getElementById("ctl00_ContentPlaceHolderBodyMain_divSpecialAndPromotion");
            if (findDivSpecialAndPromotion != null)
                findDivSpecialAndPromotion.style.display = "none";
            
                 
            //show product category as breadcrum
            var findDivBreadcrum = document.getElementById("divBreadcrumProductCategory");
            findDivBreadcrum.innerHTML = "<strong>" + myCategory + "</strong>";                                 
            
            var findDivspanLoadingBar = document.getElementById("spanLoadingBar");
            findDivspanLoadingBar.innerHTML = "<img src='../images/loading.gif' />Loading....";                                     
            
            //set the myId with hide ex demo variable
            var findDivHideDemo = document.getElementById("divHideExDemo");
            if (findDivHideDemo != null)
            {
                if (document.aspnetForm.ctl00$ContentPlaceHolderBodyMain$CheckBoxHideExDemo.checked == true)
                    myId = myId + "|h"; //show
                else
                    myId = myId + "|s"; //hide                                   
            }
                if (myType=="cat")
                        myId = myId + "|cat";
                else if (myType=="ven")
                        myId = myId + "|ven|" + myVID;
            Anthem_InvokePageMethod('GetProductsByCategoryID', [myId], ProductsCallbackListProducts);
        }
        else
            alert('no record in myArray[0]');
    }

    //2 funtions to perform Anthem Ajax
    function GetProducts(evt)
    {            
        var src = window.event != window.undefined ? window.event.srcElement : evt.target;
        var nodeClick = src.tagName.toLowerCase() == "a";

        if(nodeClick)
        {
            var nodeText = src.innerText;           
            var nodeValue = GetNodeValue(src);                                    
            
            //if node is the leaves of the tree, then call back. It checks the numbers
            if (IsNumeric(nodeValue))
            {
		        if (is_ie_browser())
                {  //go to page top
                  location.href = "#top";
                }

                //empty the area
                var findDiv = document.getElementById("divProductsList");
                findDiv.innerHTML = "";
                
		            if (is_ie_browser())
		            {       
                	//show product category as breadcrum
                	var findDivBreadcrum = document.getElementById("divBreadcrumProductCategory");
                	findDivBreadcrum.innerHTML = "<strong>" + nodeText + "</strong>";                                 
                    }

                var findDivspanLoadingBar = document.getElementById("spanLoadingBar");
                findDivspanLoadingBar.innerHTML = "<img src='../images/loading.gif' />Loading....";                                   
                
                Anthem_InvokePageMethod('GetProductsByCategoryID', [nodeValue], ProductsCallbackListProducts);
                return false; //stop call dopostback to reload page by dot net javascript
            }
            else
                return true;
            
                                  
        }
        
    }        
    
    function ProductsCallbackListProducts(response)
    {  
       var finddivPageHeaderText = document.getElementById("breadcrump");   
       if (finddivPageHeaderText != null)  
                    finddivPageHeaderText.innerHTML = "COMPONENTS";      
       
       var finddivHideExDemo = document.getElementById("divHideExDemo");   
       if (finddivHideExDemo != null)
       {
                finddivHideExDemo.style.display="block";
       }             
       

       
      var findDivspanLoadingBar = document.getElementById("spanLoadingBar");   
   
      if (is_ie_browser()) //ie browser
	    findDivspanLoadingBar.innerHTML = "";
      else	      //non ie browser
	    findDivspanLoadingBar.innerHTML = " ";

      var findDiv = document.getElementById("divProductsList");
      findDiv.innerHTML = response.value;
      
      if (response.value != "")
      {
        //show product category as breadcrum
        var find_totalRecords = document.getElementById("totalProductRecordsLoaded");
        if (find_totalRecords != null)
        {
            if (find_totalRecords.value != "")
            {
                var findDivBreadcrump = document.getElementById("divBreadcrumProductCategory");
                var divValue = findDivBreadcrump.innerHTML;
                if (is_ie_browser())
                    findDivBreadcrump.innerHTML = divValue + " - " + find_totalRecords.value + " record(s) found";            
                else
		            findDivBreadcrump.innerHTML = find_totalRecords.value + " record(s) found";            
            }
        }
      }
      else
        findDivspanLoadingBar.innerHTML = "No record found";              
        
        
    }

    //add to cart
    function addSingleItemToCart(strCount)
    {       
        var strID = "productIDRow" + strCount;      
        var strQtyID = "txQty" + strCount;
        var strPartNum = "thePartNum" + strCount;
        var strQty = document.getElementById(strQtyID).value;                     
        var varProductID = document.getElementById(strID).value;
        var varPartNum = document.getElementById(strPartNum).innerHTML;
        var loadingbarID = "loadingBarHidden";
        
        if (strQty == "") //QTY text box validation
            alert("Please enter the QTY and try again");
        else if (strQty<1 || strQty>100)
            alert("Qty must be between 1 to 100");
        else if (IsNumeric(strQty)==false)
            alert("Please enter digits in the Qty");
        else
        {
          strItem = varProductID + "|" + strQty + "^" + varPartNum;
          if (varProductID != "")
          {
             var findDivspanLoadingBar = document.getElementById("spanLoadingBar");
             findDivspanLoadingBar.innerHTML = "<img src='../images/loading.gif' />Loading....";
             
             //showLoadingBar(loadingbarID); //show the loading bar at the middle of the page
             
             Anthem_InvokePageMethod('AddOneItemToCart', [strItem], ProductsCallbackAddOneItem);
          }

        }
    }
    
    function ProductsCallbackAddOneItem(response)
    {       
        var loadingbarID = "loadingBarHidden";
        var findDivspanLoadingBar = document.getElementById("spanLoadingBar");

        if (is_ie_browser())
            findDivspanLoadingBar.innerHTML = "";
        else
	    findDivspanLoadingBar.innerHTML = " ";
	    
	    //hideLoadingBar(loadingbarID); //hide the loading bar at the middle of the page

        var s = response.value;
        var myValue = s.split("|");
        var totalItems = myValue[0];
        var totalPrice = reformateCurrency(myValue[1]);
        var PartNum = myValue[2];
        var Qty = myValue[3];                               
        
        var findSpan1 = document.getElementById("ctl00_CartDetailUserControl1_lblTotalItem");
        findSpan1.innerHTML = totalItems;
        var findSpan2= document.getElementById("ctl00_CartDetailUserControl1_lblTotalAmount");
        findSpan2.innerHTML = "$" + totalPrice;
        
	
	findDivspanLoadingBar.style.color = "red";
	findDivspanLoadingBar.innerHTML = PartNum + " x " + Qty + " added to the Cart.";
    }
    
    //get the currency with only two decimal
    function reformateCurrency(dollar)
    {
        var myDollar = Math.round(dollar*100);
        myDollar = myDollar/100;
        return myDollar;
    }
    
    function GetNodeValue(node)
    {
        var nodeValue = "";
        var nodePath = node.href.substring(node.href.indexOf(",")+2,node.href.length-2);
        var nodeValues = nodePath.split("\\");        
        
        if(nodeValues.length > 1)
        nodeValue = nodeValues[nodeValues.length - 1];
        else
        nodeValue = nodeValues[0].substr(1);

        return nodeValue;
    }

    function IsNumeric(sText)
    {
       var ValidChars = "0123456789";
       var IsNumber=true;
       var Char;

     
       for (i = 0; i < sText.length && IsNumber == true; i++) 
          { 
          Char = sText.charAt(i); 
          if (ValidChars.indexOf(Char) == -1) 
             {
             IsNumber = false;
             }
          }
       return IsNumber;
       
    }




//for the tab
function mouseoverTab(i)
{
	obj1 = document.getElementById("spanTab1");
	obj2 = document.getElementById("spanTab2");
	
	if (i == '1')
	{
		obj1.style.color="blue";
		obj2.style.color="#000000";
	}
	else if (i=='2')
	{
		obj1.style.color="#000000";
	    obj2.style.color="blue";
	}
	
	return false;
}

function clickTab(j)
{
	obj1 = document.getElementById("ctl00_ContentPlaceHolderLeftBottom_lbBrowseCategory");
	obj2 = document.getElementById("ctl00_ContentPlaceHolderLeftBottom_lbBrowseVendor");
    var findDiv = document.getElementById("divProductsList");
    if (findDiv!=null)
      findDiv.innerHTML = "";
      
    var findDivBreadcrump = document.getElementById("divBreadcrumProductCategory");
    if (findDivBreadcrump!=null)
        findDivBreadcrump.innerHTML = "";	
	
	//breadcrump
	var findDivCTBreadcrump = document.getElementById("ctl00_ContentPlaceHolderBodyMain_breadcrump");
            if (findDivCTBreadcrump != null)
                findDivCTBreadcrump.innerHTML="SPECIAL AND PROMOTIONS";	
	
	//show special and promotion
	var findDivSpecialAndPromotion = document.getElementById("ctl00_ContentPlaceHolderBodyMain_divSpecialAndPromotion");
	if (findDivSpecialAndPromotion != null)
	    findDivSpecialAndPromotion.style.display = "block";
	
	var finddivHideExDemo = document.getElementById("divHideExDemo");   
    if (finddivHideExDemo != null)
    {
            finddivHideExDemo.style.display="none";
    }
}


function RetrieveCat(strVendorID)
{
    Anthem_InvokePageMethod('load_VendorMenu', [strVendorID], RespondCallbackVendorMenu);
}

function RespondCallbackVendorMenu(response)
{
    var value1 = response.value;
    if (response.value != "")
    {               
        var find_VendorCategory = document.getElementById("ctl00_ContentPlaceHolderLeftBottom_LabelProductMenu");

            find_VendorCategory.innerHTML=response.value;
    }

}