﻿        function ClearTextBox(id)
        {
            txb = document.getElementById(id);
            if(txb.value == 'חפש באתר')
            {
                txb.value = '';
            }
        }
        
        function ClearQuantityTextBox(PrId)
        {
            var inps = document.getElementsByTagName("input");
            
            for(i  = 0; i < inps.length; i++)
            {
                inp = inps[i];
                if(inp.type == "text" && inp.title == PrId)
                {
                    inp.value = "0";
                }
            }
        }
        
        function ClearInvalid(id)
        {
            indavidId=id.replace("txbProductQuantity", "invalid");
            document.getElementById(indavidId).style.visibility = 'hidden';
            o = document.getElementById('PrMsg');
            if(o != null)
            {
                o.style.visibility = 'hidden';
            }
        }
        
        function openDefaultPage()
        {
            //window.open("default.aspx", "_self");
            // onmousemove="this.style.cursor = 'pointer'" onmouseout="this.style.cursor = 'default'" onclick="openDefaultPage()"
        }
        
        function AddtoOrder(PrId, startID)
        {
        //
          document.getElementById('PrMsg').style.visibility = 'hidden';
           if(!privateAddtoOrder(PrId, startID))
            { 
                return;
            }
            var IE = document.all?true:false;
            var tempX = 0;
            var tempY = 0;
             if (IE) { // grab the x-y pos.s if browser is IE
                tempX = event.clientX + document.body.parentElement.document.body.scrollLeft+10;
                tempY = event.clientY + document.body.parentElement.scrollTop-10;
              } 
              
              if (tempX < 0){tempX = 0}
              if (tempY < 0){tempY = 0}  
              
               if (IE)
               {
              document.getElementById('PrMsg').style.left = tempX;
              document.getElementById('PrMsg').style.top = tempY;
               document.getElementById('PrMsg').style.visibility = 'visible';
                t=setTimeout("document.getElementById('PrMsg').style.visibility = 'hidden'", 1200);
              }
              else
              {
              document.getElementById('PrMsg').style.visibility = 'visible';
               t=setTimeout("document.getElementById('PrMsg').style.visibility = 'hidden'", 1200);
              }
            
        }

        function AddtoSellOrder(PrId, startID)
        {
            document.getElementById('PrMsg').style.visibility = 'hidden';
            
            if(!privateAddtoSellOrder(PrId, startID))
            { 
                return;
            }
            var IE = document.all?true:false;
            var tempX = 0;
            var tempY = 0;
             if (IE) { // grab the x-y pos.s if browser is IE
                tempX = event.clientX + document.body.parentElement.document.body.scrollLeft+10;
                tempY = event.clientY + document.body.parentElement.scrollTop-10;
              } 
              
              if (tempX < 0){tempX = 0}
              if (tempY < 0){tempY = 0}  
              
               if (IE)
               {
              document.getElementById('PrMsg').style.left = tempX;
              document.getElementById('PrMsg').style.top = tempY;
               document.getElementById('PrMsg').style.visibility = 'visible';
                t=setTimeout("document.getElementById('PrMsg').style.visibility = 'hidden'", 1200);
              }
              else
              {
              document.getElementById('PrMsg').style.visibility = 'visible';
               t=setTimeout("document.getElementById('PrMsg').style.visibility = 'hidden'", 1200);
              }
            //document.getElementById('PrMsg').style.visibility = 'visible';
            //t=setTimeout("document.getElementById('PrMsg').style.visibility = 'hidden'", 1200);
        }
        
        function AddtoOrderV2(PrId, startID)
        {
            //alert(PrId+' ,'+ startID);
            if(!privateAddtoOrder(PrId, startID))
            { 
                return;
            }
            
            document.getElementById(startID + "PrMsg").style.visibility = 'visible';
            t=setTimeout("document.getElementById('" + startID + "PrMsg').style.visibility = 'hidden'", 1200);
        }
        
//       
        
        function privateAddtoOrder(PrId, startID)
        {
            PQtxb = document.getElementById(startID+"txbProductQuantity");
    
            q = parseInt(PQtxb.value);
            //alert(q);
            if(isNaN(PQtxb.value) || q < 0 || isNaN(q))
            {
                PQtxb.value = '';
                document.getElementById(startID+"invalid").style.visibility = 'visible';;
                return false;
            }
            
            PQtxb.value = q.toString();
            
            hf = document.getElementById("ctl00_hfOrder");
             
            s1 = PrId+",";
            s2 = q+"."
            
            s = unescape(getCookie('fazarcCookie1'));
	        //alert(s);
            paId = s.substring((s.indexOf('fazarcId=') + 9), s.indexOf('&'));
            s = s.substr(s.indexOf('fazarcOrder=') + 12);
	
            add = false;
            
            if(s.indexOf(s1)==-1)
            {
                add = true;
            }
           
            if(add && s.indexOf(s1+s2)==-1)
            {
                s = s+s1+s2;
            }
            else
            {
                olds = (s.substr(s.indexOf(s1)).split(".")[0])+".";
                s = s.replace(olds, s1+s2);
            }
            //alert(unescape('fazarcId='+paId+'&fazarcOrder='+s));
            setCookie('fazarcCookie1', unescape('fazarcId='+paId+'&fazarcOrder='+s), 365);
            
            return true;
        }
        
         function privateAddtoSellOrder(PrId, startID)
        {
            PQtxb = document.getElementById(startID+"txbProductQuantity");
    
            q = parseInt(PQtxb.value);
            //alert(q);
            if(isNaN(PQtxb.value) || q < 0 || isNaN(q))
            {
                PQtxb.value = '';
                document.getElementById(startID+"invalid").style.visibility = 'visible';;
                return false;
            }
            
            PQtxb.value = q.toString();
            
            hf = document.getElementById("ctl00_hfOrder");
             
            s1 = PrId+",";
            s2 = q+"."
            
            s = unescape(getSellCookie('fazarcSellCookie1'));
	        //alert(s);
            paId = s.substring((s.indexOf('fazarcSellId=') + 13), s.indexOf('&'));
            s = s.substr(s.indexOf('fazarcSellOrder=') + 16);
	
            add = false;
            
            if(s.indexOf(s1)==-1)
            {
                add = true;
            }
           
            if(add && s.indexOf(s1+s2)==-1)
            {
                s = s+s1+s2;
            }
            else
            {
                olds = (s.substr(s.indexOf(s1)).split(".")[0])+".";
                s = s.replace(olds, s1+s2);
            }
            //alert(unescape('fazarcId='+paId+'&fazarcOrder='+s));
            setCookie('fazarcSellCookie1', unescape('fazarcSellId='+paId+'&fazarcSellOrder='+s), 365);
            
            return true;
        }
        
//     
        
        function getCookie(c_name)
        {
        if (document.cookie.length>0)
          {
            c_start=document.cookie.indexOf(c_name + "=");
            if (c_start!=-1)
            { 
                c_start=c_start + c_name.length+1; 
                c_end=document.cookie.indexOf(";",c_start);
                if (c_end==-1) c_end=document.cookie.length;
                //return unescape(document.cookie.substring(c_start,c_end));
                return document.cookie.substring(c_start,c_end);
            } 
          }
        return "";
        }
        
        
         function getSellCookie(c_name)
        {
        if (document.cookie.length>0)
          {
            c_start=document.cookie.indexOf(c_name + "=");
            if (c_start!=-1)
            { 
                c_start=c_start + c_name.length+1; 
                c_end=document.cookie.indexOf(";",c_start);
                if (c_end==-1) c_end=document.cookie.length;
                //return unescape(document.cookie.substring(c_start,c_end));
                //alert(document.cookie.substring(c_start,c_end));
                //alert(unescape(document.cookie.substring(c_start,c_end)));
                return document.cookie.substring(c_start,c_end);
            } 
          }
        return "";
        }
        function setCookie(c_name,value,expiredays)
        {
            var exdate=new Date();
            exdate.setDate(exdate.getDate()+expiredays);
            //alert(c_name+ "=" +escape(value)+ " " + expiredays);
            document.cookie=c_name+ "=" +value+
            ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
        }
       
        
