﻿// JScript File



function showhidediv(val)
{

		for(i=1;i<=25;i++) 
		{
		    
			if( 'div'+i != val)
			{
			    if(document.getElementById("div"+i))
		        {
		        	document.getElementById("div"+i).style.display='none';
		        	
		        }
			}
			
		}
		if(document.getElementById(val))
		{
		    if(document.getElementById(val).style.display=='none')
			{	
			    if(document.getElementById(val).innerHTML.length > 0 )
			    {
                //   alert('inside if page data = '+ val);
				   document.getElementById(val).style.display='';
				   createCookie("pagedata",val);    
				}
				else
				{
				  //  alert('inside elseif page data = '+ val);
				    createCookie("pagedata","");    
				}
				
			}
			else
			{
			  //  alert('inside else page data = '+ val);
			    
				document.getElementById(val).style.display='none';
				createCookie("pagedata","");
		        createCookie("cn","");
		        createCookie("dis","");
			}
			}
}

function hideall()
{
    createCookie("pagedata","");
    for(i=1;i<=25;i++) 
		{
			    if(document.getElementById("div"+i))
		        {
		        	document.getElementById("div"+i).style.display='none';
		        	
		        }
		}
 }
   function SetActive(setact)
    {
 
        createCookie("setcol",setact);
       
        if(document.getElementById(setact))
            document.getElementById(setact).style.color='orange';
        //document.getElementById(setact).setAttribute('className','font-red');
        //alert(document.getElementById(setact).getAttribute('className'));
    }
   function SetActive1(Psetact)
    {
        
      hideall();
     // SetActive(setact);
     createCookie("Psetcol",Psetact);
       
        if(document.getElementById(Psetact))
            document.getElementById(Psetact).style.color='orange';
      
    }
    function SetActive2(setact)
    {
        
      hideall();
      SetActive(setact);
      
    }
    
    
function onloaddata()
{

         var data = GetCookie("pagedata");
         var s = document.location.href;
         
           if( s.indexOf('c-') > -1)
           {
           
           
                temp = s.substring(s.indexOf("c-"),s.length);     
              
                showhidediv("div" + temp.split("-")[1] );
            
            return;
           }
             if( s.indexOf('s-') > -1)
           {
           
                temp = s.substring(s.indexOf("s-"),s.length);     
              
                SetActive("adiv" + temp.split("-")[1] );
            
           
           }
        if(data != null)
        {
            if(data !="")
            {
               // alert('pagedata = '+ data);
                createCookie("divID1",'');
                showhidediv(data);
                
                
            }
        }
         var setact=GetCookie("setcol");
         var Psetact=GetCookie("Psetcol");
    if( setact != null)
    {
                   if(document.getElementById(setact))
                    {
                           document.getElementById(setact).style.color='orange';
                           
                     } 
     } 
         
   if( Psetact != null && setact == null)
    {
    
                   if(document.getElementById(Psetact))
                    {
                    
                           document.getElementById(Psetact).style.color='orange';
                           
                     } 
     }   
        
        var urldata =  document.location.href;
        
     
        
        if(document.getElementById('chk1')!=null)
        {
             document.getElementById('chk1').checked = false;
             document.getElementById('btnCheckOutNowBottom').setAttribute('disabled',true);
             document.getElementById('btnCheckOutNowBottom').setAttribute('src',"skins/Skin_1/images/button_checkout_now_off.gif");
        }
                        
        var disdata = GetCookie('dis');
        if(disdata != null)
        {
            if(disdata !="")
            {
                if(disdata == 'true')
                if(document.getElementById('chk1')!=null)
                    {
                        document.getElementById('chk1').checked = true;
                        document.getElementById('btnCheckOutNowBottom').setAttribute('disabled',false);
                        document.getElementById('btnCheckOutNowBottom').setAttribute("src","skins/Skin_1/images/button_checkout_now.gif");
                    }
                        
            }
        }
}

function bookmarksite(title,url){

    if (window.sidebar) // firefox

          window.sidebar.addPanel(title, url, "");

    else if(window.opera && window.print){ // opera

          var elem = document.createElement('a');

          elem.setAttribute('href',url);

          elem.setAttribute('title',title);

          elem.setAttribute('rel','sidebar');

          elem.click();
    } 

    else if(document.all)// ie

          window.external.AddFavorite(url, title);
    else
        alert("Press Ctl + D To Bookmark this Page.");
}


function Remove_Controls(remId)
{
    var d = document.getElementById('RptPersonalize');
  var olddiv = document.getElementById("divdetail"+remId);
  d.removeChild(olddiv);
   var count= GetCookie("Counter");
  if(count > 1)
  {
    count--;
    createCookie("Counter",count);    
   }
   else
   {
    createCookie("Counter","");    
   }
}


function add_Controls()
 {

var count= GetCookie("Counter");

if(count != null)
 {
     if(count !="")
     {             
           count++; 
       
     }
     else
     {
        count = 1;
      }
 } 
else
{
     count=1;
} 

var oldcount=count-1;


createCookie("Counter",count);     
var array0 = new Array();
var array1 = new Array();
var array2 = new Array();
var array3 = new Array();
var array4 = new Array();
var array5 = new Array();
var array6 = new Array();
var array7 = new Array();
var array8 = new Array();

var htmlstr='<div class="detail" id="divdetail' + count + '">' + document.getElementById("divdetail0").innerHTML + '</div> ';   
//for(i=0;i<count;i++)
//{

//    array0[i] = document.getElementById("EngrvFirst" + i).value;
//    array1[i] = document.getElementById("EngrvSecond" + i).value;
// //   array2[i] = document.getElementById("EngrvThird" + i).value;
////    array3[i] = document.getElementById("ddlChooseFlask" + i).value;
//    array4[i] = document.getElementById("ddlFonts" + i).value;
//    array5[i] = document.getElementById("ddlGiftWrapping" + i).selectedIndex;
//    array6[i] = document.getElementById("ddlExpedite" + i).selectedIndex;
//    array7[i] = document.getElementById("txtQty" + i).value;
//    array8[i] = document.getElementById("FontImg" + i).value;
//}

var newhtml=htmlstr.replace("div0","div"+count);
newhtml=newhtml.replace("ddlChooseFlask0","ddlChooseFlask"+count);
newhtml=newhtml.replace("ddlChooseFlask0","ddlChooseFlask"+count);
newhtml=newhtml.replace("EngrvFirst0","EngrvFirst"+count);
newhtml=newhtml.replace("EngrvFirst0","EngrvFirst"+count);
newhtml=newhtml.replace("EngrvSecond0","EngrvSecond"+count);
newhtml=newhtml.replace("EngrvSecond0","EngrvSecond"+count);
newhtml=newhtml.replace("EngrvThird0","EngrvThird"+count);
newhtml=newhtml.replace("EngrvThird0","EngrvThird"+count);
newhtml=newhtml.replace("ddlFonts0","ddlFonts"+count);
newhtml=newhtml.replace("ddlFonts0","ddlFonts"+count);
newhtml=newhtml.replace("ddlFonts0","ddlFonts"+count);
newhtml=newhtml.replace("ddlFonts0","ddlFonts"+count);
newhtml=newhtml.replace("ddlGiftWrapping0","ddlGiftWrapping"+count);
newhtml=newhtml.replace("ddlGiftWrapping0","ddlGiftWrapping"+count);
newhtml=newhtml.replace("ddlExpedite0","ddlExpedite"+count);
newhtml=newhtml.replace("ddlExpedite0","ddlExpedite"+count);
newhtml=newhtml.replace("txtQty0","txtQty"+count);
newhtml=newhtml.replace("txtQty0","txtQty"+count);

newhtml=newhtml.replace("FontImg0","FontImg"+count);
newhtml=newhtml.replace("FontImg0","FontImg"+count);

newhtml=newhtml.replace("add_Controls()","Remove_Controls("+ count +")");
newhtml=newhtml.replace("[ + ] Add Another Personalized Product","[ - ] Remove  This Personalized Product");

var  HtmlString= document.getElementById("RptPersonalize").innerHTML;
document.getElementById("RptPersonalize").innerHTML="";

document.getElementById("RptPersonalize").innerHTML=newhtml+HtmlString;


 
}


function Remove_ControlsOld_17_jan(remId)
{
    var d = document.getElementById('RptPersonalize');
  var olddiv = document.getElementById("div"+remId);
  d.removeChild(olddiv);
 
   
}
function add_Controlsold_17_jan() {

//alert(count);
var count= GetCookie("Counter");
if(count != null)
 {
     if(count !="")
     {             
           count++; 
           
     }
 } 
else
{
  
    count=0;
} 
createCookie("Counter",count);     
  var html='<div class="detail" id="div' + count + '">' +   //<div class="detail" id="div'+count +' >'+
                        	'<div class="pt1">'+
                        	'<p>Personalize This Product</p>'+
                            'Engraving One Line(15 characters) (+$5.95) :<br>' +
							'<input type="text"  id="EngrvFirst' + count + '"  name="EngrvFirst' + count + '"  />' +
							'<br>'+                          
							'Engraving Second Line(15 characters) (+$5.95) :<br>' +
                            '<input type="text"  id="EngrvSecond' + count +'"  name="EngrvSecond' + count +'" /><br>' +                            
                            'Engraving Third Line(15 characters) (+$5.95) :<br>' +
                            '<input type="text"  id="EngrvThird' +count+'"  name="EngrvThird' +count+'" /><br>' +
                            'Choose Engraving Fonts:<br>' +
                            '<div style="margin:8px 0px;">' +
                            '<select ID="ddlFonts'+count+'"  name="ddlFonts'+count+'" ><option>Sample Fonts</option> </select>' +                            
                            '</div>' +
                            '</div>' +
                            '<div class="pt2">' +
                            '<p>Engraving Sample Fonts</p>' +                            
                            'NOTE:Engraving Characters Should Be In Exact Order You Want Engraved. Monogram fonts should have exactly 3 initials.<br>'+
                            '<br>'+
                            '<p class="left">Giftwrapping</p>'+                            
                          	'<p class="right">' +                          	                          	
                          	'<select id="ddlGiftWrapping'+count+'"  name="ddlGiftWrapping'+count+'" ><option>Sample Fonts</option> </select>' +
                            '</p>'+                            
                            '<p class="left" style="height:35px;">Expedite Engraving?</p>'+
                          	'<p class="right" style="height:35px;">'+
                          	'<select id="ddlExpedite'+count+'"  name="ddlExpedite'+count+'" ><option>Sample Fonts</option> </select></p>' +                            
                             '<p class="left">Quantity :</p>' +
							'<p class="right">' +
						   		'<input type="text"  id="txtQty' + count + '"  name="txtQty' + count + '"  /></p>'  +                             
                            '<a href="#" onclick="javascript:Remove_Controls('+ count +')">[ + ] Remove  This Personalized Product</a>' +
                            '</div>' +
                        '</div> ';                     
                        document.getElementById("RptPersonalize").innerHTML += html;
                    
}
function createCookie(name,value,days)
{
       if (days)
       {
           var date = new Date();
           date.setTime(date.getTime()+(days*24*60*60*1000));
           var expires = "; expires="+date.toGMTString();
       }
       else var expires = "";
       document.cookie = name+"="+value+expires+"; path=/";
}
function GetCookie(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 null;
}




