
function setCookie(name, value)
         {
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
         if(name != '')
            document.cookie = name + '=' + value;
         }

function getCookie(name)
         {
         //Without this, it will return the first value 
         //in document.cookie when name is the empty string.
         if(name == '')
            return('');
         
         name_index = document.cookie.indexOf(name + '=');
         
         if(name_index == -1)
            return('');
         
         cookie_value =  document.cookie.substr(name_index + name.length + 1, 
                                                document.cookie.length);
         
         //All cookie name-value pairs end with a semi-colon, except the last one.
         end_of_cookie = cookie_value.indexOf(';');
         if(end_of_cookie != -1)
            cookie_value = cookie_value.substr(0, end_of_cookie);

         //Restores all the blank spaces.
         space = cookie_value.indexOf('+');
         while(space != -1)
              { 
              cookie_value = cookie_value.substr(0, space) + ' ' + 
              cookie_value.substr(space + 1, cookie_value.length);
							 
              space = cookie_value.indexOf('+');
              }

         return(cookie_value);
         }

function clearCookie(name)
         {                  
         expires = new Date();
         expires.setYear(expires.getYear() - 1);

         document.cookie = name + '=null' + '; expires=' + expires; 		 
         }
         
function clearCookies()
         {
         Cookies = document.cookie;
         Cookie = Cookies;
         expires = new Date();
         expires.setYear(expires.getYear() - 1);

         while(Cookie.length > 0)
              {
              //All cookie name-value pairs end with a semi-colon, except the last one.
              Cookie = Cookies.substr(0, Cookies.indexOf(';'));
              Cookies = Cookies.substr(Cookies.indexOf(';') + 1, Cookies.length);

              if(Cookie != '')
                 document.cookie = Cookie + '; expires=' + expires;
              else
                 document.cookie = Cookies + '; expires=' + expires;			  			  	  
              }		 		 
         }


function addProduct(productId,productName,languageId,showDetails,detailsDiv,detailsContainer,remove)
{
    
    var myHashTable = {};
    var currentProducts = '';
    var prodId = '';
    var prodName = '';
    var cookie = '';
    
    currentProducts = getCookie('DeAceroPrintCart_'+languageId);
    var aProducts = currentProducts.split('_');
    
    if (currentProducts != '')
    {
        for(i = 0; i < aProducts.length; i++)
        {
            prodId = aProducts[i].split('|')[0];
            prodName = aProducts[i].split('|')[1];
            if (prodId)
            {
                myHashTable[prodId] = prodName;
            }
        }
    }
    
    myHashTable[productId] = productName;
    
    for(var n in myHashTable)
    {
        cookie += n + '|' + myHashTable[n] + '_';
    }
    
    setCookie('DeAceroPrintCart_'+languageId,cookie);
    
    if (showDetails) showProducts(languageId,detailsDiv,detailsContainer,remove);
    
}

function showProducts(languageId,detailsDiv,detailsContainer,remove)
{
    var myHashTable = {};
    var currentProducts = '';
    var prodId = '';
    var prodName = '';
    var cookie = '';
    var result = new Array();
    var oDiv;
    var oDetails;
    
    currentProducts = getCookie('DeAceroPrintCart_'+languageId);
    var aProducts = currentProducts.split('_');
    
    if (currentProducts != '')
    {
        for(i = 0; i < aProducts.length; i++)
        {
            prodId = aProducts[i].split('|')[0];
            prodName = aProducts[i].split('|')[1];
            if (prodId)
            {
                result[i] = '<tr><td>' + prodName + '</td><td><a href="#" onclick="removeProduct(\'' + prodId + '\',\'' 
                            + languageId + '\',true,\'' + detailsDiv + '\',\'' 
                            + detailsContainer + '\');">' + remove + '</a>' + '</td></tr>';
            }
        }
        if (oDiv = document.getElementById(detailsDiv))
        {
            oDiv.innerHTML = '<table>' + result.join(' ') + '</table>';
            if (oDetails = document.getElementById(detailsContainer))
            {
             if (oDetails.style.display == 'none')
             {
                oDetails.style.display = '';
             }
             else
             {
                oDetails.style.display = 'none';
             }
            }
        }
    }
}

function hideProducts(detailsContainer)
{
    if (oDetails = document.getElementById(detailsContainer))
    {
     if (oDetails.style.display == 'none')
     {
        oDetails.style.display = '';
     }
     else
     {
        oDetails.style.display = 'none';
     }
    }
}

function removeProduct(productId,languageId,showDetails,detailsDiv,detailsContainer)
{
    
    var myHashTable = {};
    var currentProducts = '';
    var prodId = '';
    var prodName = '';
    var cookie = '';
    
    currentProducts = getCookie('DeAceroPrintCart_'+languageId);
    var aProducts = currentProducts.split('_');
    
    if (currentProducts != '')
    {
        for(i = 0; i < aProducts.length; i++)
        {
            prodId = aProducts[i].split('|')[0];
            prodName = aProducts[i].split('|')[1];
            if (prodId && prodId != productId)
            {
                myHashTable[prodId] = prodName;
            }
        }
    }
       
    for(var n in myHashTable)
    {
        cookie += n + '|' + myHashTable[n] + '_';
    }
    
    setCookie('DeAceroPrintCart_'+languageId,cookie);
    
    if (showDetails) showProducts(languageId,detailsDiv,detailsContainer);
    
}

function showCompareScreen()
{
    objProdLeft = document.getElementById('ddlCompareProdLeft');
    idSubProdLeft = objProdLeft.options[objProdLeft.selectedIndex].value
    
    objProdRight = document.getElementById('ddlCompareProdRigth');
    idSubProdRight = objProdRight.options[objProdRight.selectedIndex].value
    
    objProdLeftInner = document.getElementById('ddlCompareProdLeftInner');
    objProdRightInner = document.getElementById('ddlCompareProdRigthInner');
    
    objProdLeftInner.selectedIndex = objProdLeft.selectedIndex;
    objProdRightInner.selectedIndex = objProdRight.selectedIndex;
    
    objSubPLeft = document.getElementById('imgSubproduct_' + idSubProdLeft);
    objSubPRight = document.getElementById('imgSubproduct_' + idSubProdRight);
    objImgCompareLeft = document.getElementById('imgCompareLeft');
    objImgCompareRight = document.getElementById('imgCompareRigth');
    
    objHddLeft = document.getElementById('hddSubProdLeftComp');
    objHddRight = document.getElementById('hddSubProdRightComp');
    
    objHddLeft.value = idSubProdLeft;
    objHddRight.value = idSubProdRight;
    if (objSubPLeft != null)
    {
        objImgCompareLeft.src = objSubPLeft.src;
    }
    else
    {
        objImgCompareLeft.src = '/images/blnk_main.gif';
    }
    if (objSubPRight != null)
    {
        objImgCompareRight.src = objSubPRight.src;
    }
    else
    {
        objImgCompareRight.src = '/images/blnk_main.gif';
    }
    
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth;
        var pageHeight = document.body.scrollHeight;
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth;
      var pageHeight = document.body.offsetHeight;
    } else {
      // var pageWidth='100%';
       //var pageHeight='100%';
    }   
    
    
    
    
    objDiv = document.getElementById('divCompare');    
    objDiv.style.display = '';
    objDiv.style.width = '850px';        
    objDiv.style.top = Math.round((document.documentElement.clientHeight/2)-(objDiv.clientHeight/2)+document.documentElement.scrollTop)+'px';    
    objDiv.style.left = Math.round((document.documentElement.clientWidth/2)-(objDiv.clientWidth/2))+"px";
    
    
    grayOut(true);        

    document.body.appendChild(objDiv);
    

    objDiv.style.position = 'absolute';
    objDiv.style.zIndex = 100;               
    
    
}

function closeScreenCompare()
{
    objDiv = document.getElementById('divCompare');
    objDiv.style.display = 'none';
    grayOut(false);
}

function showPropTableLeft()
{
    objHddLeft = document.getElementById('hddSubProdLeftComp');
    objTableComp = document.getElementById('divPropertiesCompare');
    objImgCompareRight = document.getElementById('imgCompareRigth');
    objImgCompareLeft = document.getElementById('imgCompareLeft');
    objImgCompareRight.border = 0;
    objImgCompareLeft.border = 2;
    iSubProdId = objHddLeft.value;
    if (iSubProdId != null)
    {
        objSubPTable = document.getElementById('tblProperties_' + iSubProdId);
        objTableComp.innerHTML = '<table align="center">' +objSubPTable.innerHTML + '</table>'
    }
    else
    {
        objTableComp.innerHTML = '';
    }
}

function showPropTableRight()
{
    objHddRight = document.getElementById('hddSubProdRightComp');
    objTableComp = document.getElementById('divPropertiesCompare');   
    objImgCompareRight = document.getElementById('imgCompareRigth');
    objImgCompareLeft = document.getElementById('imgCompareLeft');
    objImgCompareRight.border = 2;
    objImgCompareLeft.border = 0;
    iSubProdId = objHddRight.value;
    if (iSubProdId != null)
    {
        objSubPTable = document.getElementById('tblProperties_' + iSubProdId);
        objTableComp.innerHTML = '<table align="center">' +objSubPTable.innerHTML + '</table>'
    }
    else
    {
        objTableComp.innerHTML = '';
    }
}

function showCompareInner()
{
    objProdLeft = document.getElementById('ddlCompareProdLeftInner');
    idSubProdLeft = objProdLeft.options[objProdLeft.selectedIndex].value
    
    objProdRight = document.getElementById('ddlCompareProdRigthInner');
    idSubProdRight = objProdRight.options[objProdRight.selectedIndex].value
    
    objSubPLeft = document.getElementById('imgSubproduct_' + idSubProdLeft);
    objSubPRight = document.getElementById('imgSubproduct_' + idSubProdRight);
    objImgCompareLeft = document.getElementById('imgCompareLeft');
    objImgCompareRight = document.getElementById('imgCompareRigth');
    
    objHddLeft = document.getElementById('hddSubProdLeftComp');
    objHddRight = document.getElementById('hddSubProdRightComp');
    
    objHddLeft.value = idSubProdLeft;
    objHddRight.value = idSubProdRight;
    if (objSubPLeft != null)
    {
        objImgCompareLeft.src = objSubPLeft.src;
    }
    else
    {
        objImgCompareLeft.src = '/images/blnk_main.gif';
    }
    if (objSubPRight != null)
    {
        objImgCompareRight.src = objSubPRight.src;
    }
    else
    {
        objImgCompareRight.src = '/images/blnk_main.gif';
    }
            
}

