﻿// JScript File

  function HideDIV()
    {
        document.getElementById("DIVCompareError").style.display='none';
    }
    function HideDIVPRoduct(id)
    {
          document.getElementById("DIVCompareError"+id).style.display='none';
    }
     // This function will set Cookies 
     function setCookie(obj,val,imagename)
      {
          var expires="";
          var name='chkval';
          var CookieImages='Compare';
          var pos=-1;
          
          var cValue=readCookie(name); 
          var CookieImagesValue=readCookie(CookieImages);
                    
          if(obj.src.indexOf("images/unchecked_box.gif")>=0)
          {
          if(cValue.split(",").length<=5 )
          {
                    
            obj.src="images/checked_box.gif";
            if(cValue!="")
            {
                pos =cValue.indexOf(val);
                if(pos<0)
                {
                 cValue+=val+",";    
                 CookieImagesValue+=imagename+",";                              
                }
            }
            else
            {
                cValue=val+",";
                CookieImagesValue=imagename+",";
            }
            
            document.getElementById("DIVTextCompare"+val).innerHTML="Added to comparison tool";
            document.getElementById("DIVTextCompare"+val).className="smallRedText";
            document.getElementById("DIV" + val).className="blacktext divBorderRed";
            document.getElementById("DIVCompareList").style.display="block";
            document.getElementById("DIVCompareMain").className="comparebg";
            document.getElementById("DIVCompareBottom").style.display="block";
            var fomselement=document.getElementsByTagName("img");
            iCount=0
            for (i=0;i<fomselement.length;i++)
             {
               if( fomselement[i].id.indexOf("imgCompare")>=0)
               { 
                    iCount++;   
                    if(fomselement[i].src.indexOf("watch_icon.gif")>=0)
                    {                      
                        fomselement[i].src="images/products/"+imagename;
                        document.getElementById("DIVClear"+iCount).style.display="block";
                        break;
                    }
                }
             }
            }
              else
              {
               document.getElementById("DIVCompareError"+val).style.display="block";
              }
          }
          else
          {
          obj.src="images/unchecked_box.gif";
          
          var fomselement=document.getElementsByTagName("img");
          var associative_array=cValue.split(",");
          var associative_image_array=CookieImagesValue.split(",");
          
          if(associative_array.length <=2)
          {
            document.getElementById("DIVCompareList").style.display="none";
            document.getElementById("DIVCompareMain").className="comparebg_unselect";
            document.getElementById("DIVCompareBottom").style.display="none";
          }
         
          
          for (j=0;j<=associative_array.length;j++) 
          {
            if(associative_array[j]== val)
            {
                cValue=cValue.replace((val+","),"");
                break;
            }
          }
          
      
           for (j=0;j<=associative_image_array.length;j++) 
            {
            if(associative_image_array[j]== imagename)
            {
                CookieImagesValue=CookieImagesValue.replace((imagename+","),""); 
                break;
            }
          }
          iCount=0
          for (i=0;i<fomselement.length;i++)
             {
               if( fomselement[i].id.indexOf("imgCompare")>=0)
               {   
                    iCount++ ;
                    if(fomselement[i].src.indexOf(imagename)>=0)
                    {  
                        fomselement[i].src="images/watch_icon.gif";
                        document.getElementById("DIVClear"+iCount).style.display="none";
                        break;
                    }
                }
             }
             
            document.getElementById("DIVTextCompare"+val).innerHTML="Compare this watch";
            document.getElementById("DIVTextCompare"+val).className="blackTextBold";
            document.getElementById("DIV" + val).className="blackText divWithoutBorder";            
          }
          
          document.cookie = name+"="+cValue+expires+"; path=/";
          document.cookie = CookieImages+"="+CookieImagesValue+expires+"; path=/";
        ShiftImages(CookieImagesValue);
       }
       
       // this function will read  cookie value 
       function readCookie(name)
       {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	   }
	return "";
    }
    
    // this function will be erase cookie
    function eraseCookie(name)
    {
        document.cookie = name+"="+""+"; path=/";
	}
    //this function will be checked checkboxes if 
 
    function RemoveDiv(id,pos)
    {   
      var fomselement=document.getElementsByTagName("img");
      var imagename=document.getElementById(id).src;
      var productid=imagename.id;
      var CookieImages='Compare';
      var cValue=readCookie('chkval');
      var CookieImagesValue=readCookie('Compare');
      var associative_array=cValue.split(",");
      var associative_image_array=CookieImagesValue.split(",");

      document.getElementById(id).src="images/watch_icon.gif";
      document.getElementById("DIVClear"+pos).style.display="none";
      var id=0;
         for (j=0;j<=associative_image_array.length-2;j++) 
          {
           
            if(imagename.indexOf(associative_image_array[j])>=0)
            {
                imagename=associative_image_array[j];
                id=j
                CookieImagesValue=CookieImagesValue.replace((associative_image_array[j]+","),""); 
                break;
            }
          }
            document.cookie = CookieImages+"="+CookieImagesValue+"; path=/";
           ShiftImages(CookieImagesValue);
      //+++++++++++++++++++++++++++++++++++++++++++   
             cValue=cValue.replace((associative_array[id]+","),"");
             document.cookie = 'chkval'+"="+cValue+"; path=/";
             var productid=associative_array[id]
            document.getElementById("DIV"+productid).className="blackText divWithoutBorder";
            document.getElementById("DIVTextCompare"+productid).innerHTML="Compare this watch";
            document.getElementById("DIVTextCompare"+productid).className="blackTextBold";
            document.getElementById(productid).src="images/unchecked_box.gif";   
        //++++++++++++++++++++++++++++++++++++++++++++++++++
                  
//       for (i=0;i<fomselement.length;i++)  
//        {
//        if(fomselement[i].src.indexOf(imagename)>=0)
//         {
//           
//            productid=fomselement[i].id.split("productImage")[1];
//            document.getElementById("DIV"+productid).className="blackText divWithoutBorder";
//            document.getElementById("DIVTextCompare"+productid).innerHTML="Compare this watch";
//            document.getElementById("DIVTextCompare"+productid).className="blackTextBold";
//            document.getElementById(productid).src="images/unchecked_box.gif";
//            
//              for (j=0;j<=associative_array.length;j++) 
//              {
//                if(associative_array[j]== productid)
//                {
//                    cValue=cValue.replace((productid+","),"");
//                     document.cookie = 'chkval'+"="+cValue+"; path=/";
//                    break;
//                }
//              }
//            break;
//         }
//       }
     
     
       if(associative_image_array.length<=2)
       {
         document.getElementById("DIVCompareList").style.display="none";
         document.getElementById("DIVCompareMain").className="comparebg_unselect";
         document.getElementById("DIVCompareBottom").style.display="none";
         
       }
    }
    
    function CompareWathes()
    {
      var CookieImages='Compare';
      var cValue=readCookie('chkval');
      var CookieImagesValue=readCookie('Compare');
      var associative_image_array=CookieImagesValue.split(",");

      if(associative_image_array.length<3)
       document.getElementById("DIVCompareError").style.display="block";
      else
      {
       document.getElementById("DIVCompareError").style.display="none";
       window.location="compare_watches.aspx";
      }
      
    }
   
   function ShiftImages(CookieImagesValue)
   {
            var  associative_image_array=CookieImagesValue.split(",");
             for (j=0;j<=4;j++) 
              {
                if(j<=associative_image_array.length-2)
                {
         document.getElementById("imgCompare"+(j+1)).src= "GiplComponent.aspx?path=\\images\\products\\" +  associative_image_array[j] + "&width=46&height=83";
                    document.getElementById("DIVClear"+(j+1)).style.display="block";
                }
                else
                {
                   document.getElementById("imgCompare"+(j+1)).src="images/watch_icon.gif";
                    document.getElementById("DIVClear"+(j+1)).style.display="none";  
                }
              }     
   }
   
   function checkinnerkpage()
   {
        var cValue=readCookie('chkval');
      var CookieImagesValue=readCookie('Compare');
      var associative_array=cValue.split(",");
      var associative_image_array=CookieImagesValue.split(",");
     var fomselement=document.getElementsByTagName("img");
          
            for (i=0;i<fomselement.length;i++)
            {
              val=fomselement[i].id;
              isvalid=false;        
              for (j=0;j<=associative_array.length;j++) 
              {
                if(associative_array[j]==val)
                {
                    isvalid=true;
                    break;
                }
                
              }
          
           
          if (fomselement[i].alt=="checkbox" && isvalid)
          {
             
             fomselement[i].src="images/checked_box.gif";
             document.getElementById("DIVTextCompare"+fomselement[i].id).innerHTML="Added to comparison tool";
             document.getElementById("DIVTextCompare"+fomselement[i].id).className="smallRedText";
             document.getElementById("DIV" + fomselement[i].id).className="blackText divBorderRed";
          }
          else if(fomselement[i].alt=="checkbox" && (! isvalid))
          {
             fomselement[i].src="images/unchecked_box.gif";
             document.getElementById("DIVTextCompare"+fomselement[i].id).innerHTML="Compare this watch";
             document.getElementById("DIVTextCompare"+fomselement[i].id).className="blackTextBold";
             document.getElementById("DIV" + fomselement[i].id).className="blackText divWithoutBorder";
          }
                  
        }
        
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
         if(associative_image_array.length>1)
         {
            document.getElementById("DIVCompareList").style.display="block";
            document.getElementById("DIVCompareMain").className="comparebg";
            document.getElementById("DIVCompareBottom").style.display="block";
         }
         for (j=0;j<=associative_image_array.length-2;j++) 
          {
            
                document.getElementById("imgCompare"+(j+1)).src="GiplComponent.aspx?path=\\images\\products\\" +  associative_image_array[j] + "&width=46&height=83";;
                document.getElementById("DIVClear"+(j+1)).style.display="block";
          }
        
   }
