﻿ 
 function InquiryBtnClick()
 {
    var listID = getCookie("listProductID");
    var adminEmail = getCookie("AdminEmail");
    if(listID !="")
    {
        window.location= "mailto:" + adminEmail + "&subject=Inquiry&body=List product code: " + listID;
        delCookie("listProductID");
        uncheckAllProduct();
    }
 }
 
 function checkProduct(node)
 {
        var listPID = getCookie("listProductID");
        listPID = trim(listPID, ' ');
        if(node.checked)
        {
            if(listPID.indexOf(node.value) < 0)
            {
                if(listPID =="")
                {
                    listPID += node.value;
                }
                else
                {
                    listPID += ", " + node.value;
                }
            }
                
        }
        else
        {
            if(listPID.indexOf(node.value) > 0)
            {
                var temp =  ", "  + node.value;
                listPID = listPID.replace(temp, "");
            }
            if(listPID.indexOf(node.value) == 0)
            {
                var tem1 = node.value +  ", ";
                listPID = listPID.replace(tem1,"");
            }
                
        }
        setCookie("listProductID", listPID,1);
 }
   
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 "";
}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function delCookie(c_name)
{
     var exp = new Date();
     exp.setTime (exp.getTime() - 1);
     var s = this.getCookie(c_name);
     document.cookie = c_name +"="+ s +";expires="+  exp.toGMTString();
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function uncheckAllProduct()
{
    var items = document.getElementsByTagName('input');
    for (var i = 0; i < items.length; i++) {
        if(items[i].type == 'checkbox')
            items[i].checked = '';
    }
    
}

 