﻿        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");
            //window.open("http://www.pasteli.co.il", "_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;
            }
            
            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 AddtoOrderV3(arr)
//        {
//            if(!privateAddtoOrder2(arr))
//            { 
//                return;
//            }
//            
//            document.getElementById(arr[0][1] + "PrMsg").style.visibility = 'visible';
//            t=setTimeout("document.getElementById('" + arr[0][1] + "PrMsg').style.visibility = 'hidden'", 1200);
//        }
        
        function privateAddtoOrder(PrId, startID)
        {
            PQtxb = document.getElementById(startID+"txbProductQuantity");
            q = parseInt(PQtxb.value);
            
            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 = getCookie('PasteliCookies1');
            paId = s.substring((s.indexOf('PasteliId=') + 10), s.indexOf('&'));
            s = s.substr(s.indexOf('PasteliOrder=') + 13);
            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('PasteliId='+paId+'&PasteliOrder='+s);
            setCookie('PasteliCookies1', 'PasteliId='+paId+'&PasteliOrder='+s, 365);
            
            return true;
        }
        
        
        
//        function privateAddtoOrder2(arr)//arr[PrId, startID,text]
//        {
//            PQtxb=new Array();
//            for(i=0;i<arr.length;i++)
//            {
//            PQtxb[i] = document.getElementById(arr[i][1]+"txbProductQuantity");
//            alert(PQtxb[i][0]);
//            q = parseInt(PQtxb[i].value);
//            
//            if(isNaN(PQtxb[i].value) || q < 0 || isNaN(q))
//            {
//                PQtxb[i].value = '';
//                document.getElementById(arr[i][1]+"invalid").style.visibility = 'visible';;
//                return false;
//            }
//            
//            PQtxb[i].value = q.toString();
//            
//            hf = document.getElementById("ctl00_hfOrder");
//             
//            s1 = PQtxb[i][0]+",";
//            s2 = q+"."
//            
//            s = getCookie('PasteliCookies');
//            paId = s.substring((s.indexOf('PasteliId=') + 10), s.indexOf('&'));
//            s = s.substr(s.indexOf('PasteliOrder=') + 13);
//            
//            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('PasteliId='+paId+'&PasteliOrder='+s);
//            setCookie('PasteliCookies', 'PasteliId='+paId+'&PasteliOrder='+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 setCookie(c_name,value,expiredays)
        {
            var exdate=new Date();
            exdate.setDate(exdate.getDate()+expiredays);
            //document.cookie=c_name+ "=" +escape(value)+
            document.cookie=c_name+ "=" +value+
            ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
        }
       
        //window.onload=montre;
        function montre(id) 
        {
            /*
            var d = document.getElementById(id);
            
            for (var i = 1; i<=document.getElementById('ctl00_dvMenuSide').childNodes[0].childNodes.length; i++) 
            {
	            if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
            }
            if (d) {d.style.display='block';}
            */
        }
        
        function sideMenuMouseOver(imageID)
        {
            /*
            alert(document.images);
            if(document.images) 
            {
                document.getElementById(imageID).src = "Design/OrangeArrowMouseOver.jpg";
            }
            */
        }
        
        function sideMenuMouseOut(imageID)
        {
            /*
             if(document.images) 
            {
                document.getElementById(imageID).src = "Design/OrangeArrow.jpg";
            }
            */
        }

        function ClearAll()
        {
            /*
             var arrInput = document.getElementById("ctl00_cphText_dvOrderMainDiv").getElementsByTagName("input")
             
             for(var i=0; i< arrInput.length; i++)
             {
                arrInput[i].value = "";
            }
            */
        }
       
        function CheckAllCheckBox(idname)
        {
            /*
            mybool=document.getElementById(idname).checked;

            for (i = 0; i < document.aspnetForm.length; i++)
            {
                myidname=document.aspnetForm[i].id
                if(myidname.indexOf("chkToBuy")>-1)
                {
    	            document.aspnetForm[i].checked=mybool;
    	        }
            }
            */
        }
        function CheckMainCheckBox(idname)
        {
            /*
            mybool=document.getElementById(idname).checked;
            if(mybool)
            {
                for (i = 0; i < document.aspnetForm.length; i++)
                {
                    myidname=document.aspnetForm[i].id
                    if(myidname != "ctl00_cphText_chkAll" && myidname.indexOf("chkToBuy")>-1)
                    {
	                    if(!document.aspnetForm[i].checked)
	                    {
    	                    mybool=document.aspnetForm[i].checked
    	                    break;
	                    }
                    }
                }
            }
            document.getElementById('ctl00_cphText_chkAll').checked=mybool;
            */
        }
       
       function ReloadMonths()
       {
            /*
            var maxMonth = 12;
            var d=new Date();
            var maxYear =d.getFullYear + 10;
            var month;
            var i;
            
            if(document.getElementById('ctl00_cphText_ddlValidYear').options[document.getElementById('ctl00_cphText_ddlValidYear').selectedIndex].text != d.getFullYear())
                month = 1;
            else
                month = d.getMonth() + 1;
            
            document.getElementById('ctl00_cphText_ddlValidMonth').options.length = 0;
            for(i=month; i<=maxMonth;i++)
            {
                var newOption = window.document.createElement('OPTION');
                newOption.text = i;
                newOption.value = i;
                document.getElementById('ctl00_cphText_ddlValidMonth').options.add(newOption);
            }
            */
       } 
