  var sUserID;
  var sOrderID;
  var iFavCount;
  var sCardType;
  var bHasQuote;
  var bFavorite;
  var bOrdered;
  var bFontChange = false;
  
  var  PrefillID;       
  var  FontID;  
  var  ColorID;
  var  QuoteID;
     
	
		function toggle(sector , state  )
		{
	 	   switch (sector)
		  {
		       case "divCard"                :  {netdevCard.className = state ? "div_on" :  "div_off"      ; break }
		       case "divCustomEnlarge"  :  {netdevCustomEnlarge.className = state ? "div_on" :  "div_off"      ; break }
		       case "divVerse"               :  {netdevVerse.className = state ? "div_on" :  "div_off"      ; break }
		       case "divQuote"              :  {netdevQuote.className = state ? "div_on" :  "div_off"      ; break }
		       case "divWeddingInfo"     :  {netdevWeddingInfo.className = state ? "div_on" :  "div_off"      ; break }
		  }
		}
		
		function turnOnArea(area)
		 {
		    switch(area)
		    {
		       case "Card" :
		        {
		              toggle("divVerse", false);
				      toggle("divQuote", false);
				      toggle("divCard", true);
				      toggle("divWeddingInfo",false)
				      break;
		         }
		    
		       case "WeddingInfo" :
		        {
		              toggle("divVerse", false)
				      toggle("divQuote", false)
				      toggle("divCard", false)
				      toggle("divWeddingInfo",true)
				      break;
		         }
		    
		     case "Verse" :
		        {
		              toggle("divVerse", true)
				      toggle("divQuote", false)
				      toggle("divCard", false)
				      toggle("divWeddingInfo",false)
				      break;
		         }
		    
		    case "Quote" :
		        {
		              toggle("divVerse", false)
				      toggle("divQuote", true)
				      toggle("divCard", false)
				      toggle("divWeddingInfo",false)
				      break;
		         }
		    
		    case "CustomEnlarge" :
		        {
		              toggle("divCard", false)
				      toggle("divCustomEnlarge",true)
				      break;
		         }
		    default:
		    alert (area + " Not Found! "  )
		    
		    }
		 }
  
  
  function openCalendar(sUrl, sCalHeight, sCalWidth)
  {
    var pLeft = (screen.width / 2) - (sCalWidth / 2);
    var pTop = (screen.height / 2) - (sCalHeight / 2);
    
    window.open(sUrl, null, 'height=' + sCalHeight + ',width=' + sCalWidth + ',top=' + pTop + ',left=' + pLeft + ',status=yes,toolbar=no,menubar=no,location=no');
  }
  
  function OptionReminder()
  {
    if (sType == 'I')
    {
        if (confirm('Invitations have several customizing options to choose from:\r\n\r\n1) Enlarge Bride & Groom Names is a very popular option.\r\n2) Printed Outer Envelopes are a great way to ensure proper return to you in case of postal problems.\r\n3) Lined Inner Envelopes are a beautiful compliment to your invitation.\r\n\r\nHave you selected all of the options you would like?\r\n\r\nClick "OK" to continue, "Cancel" to add options.'))
        {
            return true;
        }
        else
            return false;
    }
    else if (sType == 'F' || sType == 'T')
    {
         if (confirm('This piece has the option of having your return address printed on the envelopes back flap.\r\n\r\nThis feature is important to ensure proper return to you in case of postal problems.\r\n\r\nIf you would like to add this option click "Cancel", if you are satisfied with your selections click "OK".'))
        {
            return true;
        }
        else
            return false;       
    }
    else
        return true;
  }
  
  function EnlargeNames(obj)
  {
		
  	if (obj.checked)
  	{
  		if (Custom)
  		{

            turnOnArea('CustomEnlarge') ;
			obj = GetObject("spNameEnlargeHelp");
			obj.innerHTML = "<span style='color: #00A000; cursor: pointer;'  onclick='turnOnArea(\'CustomEnlarge\');' ><b>edit</b></span>";
			obj.title = "Click to change Enlarged Names selections.";
  		}
  			
  		document.images.area1.src = 'card.aspx?piece=' + sPieceID + '&type=I&area=1&prefill=' + PrefillID + '&font=' + FontID + '&color=' + ColorID + '&enlarge=1&size=area';				
	}
	else
	{
  		if (Custom)
		{
           turnOnArea('Card') ;
			obj = GetObject("spNameEnlargeHelp");
			obj.innerHTML = "<a href=\"#\" onclick=\"alert('This option will slightly enlarge the Bride and Groom names.'); return false;\" title=\"Tell me more about this option...\" style=\"color: #00A000;\"><b>?</b></a>";
		}
		
  		document.images.area1.src = '/card.aspx?piece=' + sPieceID + '&type=I&area=1&prefill=' + PrefillID + '&font=' + FontID + '&color=' + ColorID + '&enlarge=0&size=area';					
	}
  }
  
  function CancelCustomEnlarge()
  {
	//var obj = GetObject("spNameEnlargeHelp");
	//obj.innerHTML = "<a href=\"#\" onclick=\"alert('This option will slightly enlarge the Bride and Groom names.'); return false;\" title=\"Tell me more about this option...\" style=\"color: #00A000;\"><b>?</b></a>";
 	
	turnOnArea('Card') ;
	 
	//document.getElementById('divCustomEnlarge').className='div_off'; 
	//document.getElementById('divCard').className='div_on'; 
	//document.getElementById('chkLrgNm').checked=false;  
 }
  
  function PopulateModifyVerse()
  {
	var verse = verse_text.replace(/!n/gi,"\r\n");
	textarea = GetObject("txtVerse");
	textarea.value = verse;
  }
			
  function UpdatePrices()
  {
	
	 
	var qtyobj;
	var prt_env_obj;
	var left_copy_obj;
	var right_copy_obj;
	var corner_copy_obj;
	var prt_env_obj;
	var lin_env_obj;
	var msg_ins_obj;
	var clr_ink_obj;
	
	var item_price=0;
	var prt_env_price=0;
	var corner_copy_price=0;
	var lin_env_price=0;
	var msg_ins_price=0;
	var clr_ink_price=0;
	var total_price=0;
	
	var item_price_calcd=0;
	var prt_env_price_calcd=0;
	var corner_copy_price_calcd=0;
	var lin_env_price_calcd=0;
	var msg_ins_price_calcd=0;
	var clr_ink_price_calcd=0;
	var total_price_calcd=0;
	
	var item_price_show;
	var prt_env_price_show;
	var corner_copy_show;
	var lin_env_price_show;
	var msg_ins_price_show;
	var clr_ink_price_show;
	var total_price_show;
	
	var quantity;
	var overage;
		
	qtyobj = GetObject('txtQuantity');
	prt_env_obj = GetObject('chkPrintedEnv');
	lin_env_obj = GetObject('chkLinedEnv');
	msg_ins_obj = GetObject('chkMsgInside');
	clr_ink_obj = document.getElementById(    aspcontrol  +   'cmbColor')  //GetObject('cmbColor');
	left_copy_obj = GetObject('chkCornerCopyLeft');
	right_copy_obj = GetObject('chkCornerCopyRight');

	//Default printed envelopes to true if response card
	if (sCardType == "E")
	{
		prt_env_obj.checked = true;
		prt_env_obj.disabled = true;
	}
	
	//Default to 100 items
	if (qtyobj.value == "")
		qtyobj.value = "100";
	
	//Set quantity to int value of form object
	quantity = parseInt(qtyobj.value);

	if (left_copy_obj != null || right_copy_obj != null)
	{	
		if ((left_copy_obj != null && left_copy_obj.checked) && (right_copy_obj != null && right_copy_obj.checked))
		{
			corner_copy_price = formatCurrency(cTwoSideCopy);
			corner_copy_show = '$' + corner_copy_price;
			corner_copy_obj = GetObject('spCornerCopy');
			corner_copy_obj.innerHTML = corner_copy_show;
			corner_copy_obj = GetObject('divCornerCopy');
			corner_copy_obj.className = "div_on";
		}
		else if ((left_copy_obj != null && left_copy_obj.checked) || (right_copy_obj != null && right_copy_obj.checked))
		{
			corner_copy_price = formatCurrency(cOneSideCopy);
			corner_copy_show = '$' + corner_copy_price;
			corner_copy_obj = GetObject('spCornerCopy');
			corner_copy_obj.innerHTML = corner_copy_show;
			corner_copy_obj = GetObject('divCornerCopy');
			corner_copy_obj.className = "div_on";
		}
		else
		{
			corner_copy_obj = GetObject('divCornerCopy');
			corner_copy_obj.className = "div_off";
		}		
	}

	if (msg_ins_obj != null)
	{	
		if (msg_ins_obj.checked)
		{
			msg_ins_price = formatCurrency(cMsgIns);
			msg_ins_show = '$' + msg_ins_price;
			msg_ins_obj = GetObject('spMsgInsCost');
			msg_ins_obj.innerHTML = msg_ins_show;
			msg_ins_obj = GetObject('divMsgIns');
			msg_ins_obj.className = "div_on";
		}
		else
		{
			msg_ins_obj = GetObject('divMsgIns');
			msg_ins_obj.className = "div_off";		
		}		
	}
 
	if (clr_ink_obj != null)
	{	
		if (clr_ink_obj.selectedIndex != 0)
		{
			clr_ink_price = formatCurrency(cClrInk);
			clr_ink_show = '$' + clr_ink_price;
			clr_ink_obj = GetObject('spClrInkCost');
			clr_ink_obj.innerHTML = clr_ink_show;
			clr_ink_obj = GetObject('divClrInk');
			clr_ink_obj.className = "div_on";
		}
		else
		{
			clr_ink_obj = GetObject('divClrInk');
			clr_ink_obj.className = "div_off";			
		}
	}	
			
	//Minimum order is 25 pieces
	if (quantity <= 25)
	{
		qtyobj.value = "25";
		quantity = parseInt(qtyobj.value);
		
		if (prt_env_obj != null)
		{	
			if (prt_env_obj.checked && sType != "E")
			{
				prt_env_price = formatCurrency(cPrtEnv25);
				prt_env_show = '$' + prt_env_price;
				prt_env_obj = GetObject('spPrtEnvCost');
				prt_env_obj.innerHTML = prt_env_show;
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_on";
			}
			else
			{
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_off";			
			}
		}		
			
		if (lin_env_obj != null)
		{	
			if (lin_env_obj.checked)
			{
				lin_env_price = formatCurrency(cLinEnv25);
				lin_env_show = '$' + lin_env_price;
				lin_env_obj = GetObject('spLinEnvCost');
				lin_env_obj.innerHTML = lin_env_show;
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_on";
			}
			else
			{
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_off";			
			}
		}		

		item_price_calcd = formatCurrency(c25 / quantity);
		total_price_calcd = formatCurrency(c25 + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price) + parseFloat(corner_copy_price));
		//total_price_calcd = formatCurrency((parseFloat(item_price_calcd) * quantity) + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price));
		
		item_price_show = '$' + item_price_calcd + ' ea. <span style="font-size: 7pt;">(nearest cent)</span>';
		total_price_show = '$' + total_price_calcd;

	}
	
	if ((quantity > 25) && (quantity <= 50))
	{
		qtyobj.value = "50";
		quantity = parseInt(qtyobj.value);

		if (prt_env_obj != null)
		{	
			if (prt_env_obj.checked && sType != "E")
			{
				prt_env_price = formatCurrency(cPrtEnv50);
				prt_env_show = '$' + prt_env_price;
				prt_env_obj = GetObject('spPrtEnvCost');
				prt_env_obj.innerHTML = prt_env_show;
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_on";
			}
			else
			{
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_off";		
			}
		}		
			
		if (lin_env_obj != null)
		{	
			if (lin_env_obj.checked)
			{
				lin_env_price = formatCurrency(cLinEnv50);
				lin_env_show = '$' + lin_env_price;
				lin_env_obj = GetObject('spLinEnvCost');
				lin_env_obj.innerHTML = lin_env_show;
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_on";
			}
			else
			{
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_off";		
			}
		}		

		item_price_calcd = formatCurrency(c50 / quantity);
		total_price_calcd = formatCurrency(c50 + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price) + parseFloat(corner_copy_price));
		//total_price_calcd = formatCurrency((parseFloat(item_price_calcd) * quantity) + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price));

		item_price_show = '$' + item_price_calcd + ' ea. <span style="font-size: 7pt;">(nearest cent)</span>';
		total_price_show = '$' + total_price_calcd;
	}
	
	if ((quantity > 50) && (quantity <= 75))
	{
		qtyobj.value = "75";
		quantity = parseInt(qtyobj.value);

		if (prt_env_obj != null)
		{	
			if (prt_env_obj.checked && sType != "E")
			{
				prt_env_price = formatCurrency(cPrtEnv75);
				prt_env_show = '$' + prt_env_price;
				prt_env_obj = GetObject('spPrtEnvCost');
				prt_env_obj.innerHTML = prt_env_show;
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_on";
			}
			else
			{
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_off";		
			}
		}		
			
		if (lin_env_obj != null)
		{	
			if (lin_env_obj.checked)
			{
				lin_env_price = formatCurrency(cLinEnv75);
				lin_env_show = '$' + lin_env_price;
				lin_env_obj = GetObject('spLinEnvCost');
				lin_env_obj.innerHTML = lin_env_show;
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_on";
			}
			else
			{
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_off";		
			}
		}		

		item_price_calcd = formatCurrency(c75 / quantity);
		total_price_calcd = formatCurrency(c75 + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price) + parseFloat(corner_copy_price));
		//total_price_calcd = formatCurrency((parseFloat(item_price_calcd) * quantity) + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price));

		item_price_show = '$' + item_price_calcd + ' ea. <span style="font-size: 7pt;">(nearest cent)</span>';
		total_price_show = '$' + total_price_calcd;
	}
	
	if ((quantity > 75) && (quantity <= 100))
	{
		qtyobj.value = "100";
		quantity = parseInt(qtyobj.value);

		if (prt_env_obj != null)
		{	
			if (prt_env_obj.checked && sType != "E")
			{
				prt_env_price = formatCurrency(cPrtEnv100);
				prt_env_show = '$' + prt_env_price;
				prt_env_obj = GetObject('spPrtEnvCost');
				prt_env_obj.innerHTML = prt_env_show;
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_on";
			}
			else
			{
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_off";		
			}
		}		
			
		if (lin_env_obj != null)
		{	
			if (lin_env_obj.checked)
			{
				lin_env_price = formatCurrency(cLinEnv100);
				lin_env_show = '$' + lin_env_price;
				lin_env_obj = GetObject('spLinEnvCost');
				lin_env_obj.innerHTML = lin_env_show;
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_on";
			}
			else
			{
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_off";			
			}
		}		

		item_price_calcd = formatCurrency(c100 / quantity);
		total_price_calcd = formatCurrency(c100 + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price) + parseFloat(corner_copy_price));
		//total_price_calcd = formatCurrency((parseFloat(item_price_calcd) * quantity) + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price));

		item_price_show = '$' + item_price_calcd + ' ea. <span style="font-size: 7pt;">(nearest cent)</span>';
		total_price_show = '$' + total_price_calcd;
	}
		
	if (quantity > 100)
	{
		var num_over = ((quantity - 100) / 25);
		var num_over_parse = parseInt(num_over);
		
		if (num_over > num_over_parse)
			overage = num_over_parse + 1;
		else
			overage = num_over_parse;
		
		qtyobj.value = (100 + (overage * 25));
		quantity = parseInt(qtyobj.value);

		if (prt_env_obj != null)
		{	
			if (prt_env_obj.checked && sType != "E")
			{
				prt_env_price = formatCurrency(cPrtEnv100 + (cPrtEnvAdd * overage));
				prt_env_show = '$' + prt_env_price;
				prt_env_obj = GetObject('spPrtEnvCost');
				prt_env_obj.innerHTML = prt_env_show;
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_on";
			}
			else
			{
				prt_env_obj = GetObject('divPrtEnv');
				prt_env_obj.className = "div_off";			
			}
		}		
		
		if (lin_env_obj != null)
		{	
			if (lin_env_obj.checked)
			{
				lin_env_price = formatCurrency(cLinEnv100 + (cLinEnvAdd * overage));
				lin_env_show = '$' + lin_env_price;
				lin_env_obj = GetObject('spLinEnvCost');
				lin_env_obj.innerHTML = lin_env_show;
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_on";
			}
			else
			{
				lin_env_obj = GetObject('divLinEnv');
				lin_env_obj.className = "div_off";		
			}
		}		

		item_price_calcd = formatCurrency((c100 + (cAdd * overage)) / quantity);
		total_price_calcd = formatCurrency((parseFloat(item_price_calcd) * quantity) + parseFloat(prt_env_price) + parseFloat(lin_env_price) + parseFloat(msg_ins_price) + parseFloat(clr_ink_price) + parseFloat(corner_copy_price));

		item_price_show = '$' + item_price_calcd + ' ea. <span style="font-size: 7pt;">(nearest cent)</span>';
		total_price_show = '$' + total_price_calcd;
	}

	item_price = GetObject('itemPrice');
	item_price.innerHTML = "<span>" + item_price_show + "</span>"; 
	
	total_price = GetObject('itemTotal');
	total_price.innerHTML = "<span><b>" + total_price_show + "</b></span>";
  }
  
  function InkColorChanged()
  {
    return TextChanged();
  }
  
  function TextChanged()
  {
	var obj;
	

	 
 	SaveSelections();

   // var iPrefillID = netVerse ;   // GetValue('cmbVerse');
	
	if (sCardType == "I")
	{
		if (PrefillID >= 1000)
		{
			Custom = true;
			obj = GetObject("spNameEnlargeHelp");
			obj.innerHTML = "<span style=\'color: #00A000; cursor: pointer;\' onclick=\'turnOnArea(\"CustomEnlarge\");\'><strong>edit</strong></span>"
			obj.title = "Click to change Enlarged Names selections.";
		}
		else
		{
			Custom = false;
			obj = GetObject("spNameEnlargeHelp");
			obj.innerHTML = "<a href='#' onclick=\"alert('This option will slightly enlarge the Bride and Groom names.'); return false;\" title='Tell me more about this option...\' style='color: #00A000;'><strong>?</strong></a>";
		}
	}

    return DisplayAllAreas();
  }
  
  function AddRemoveFavorite(oBtn)
  {
	bFavorite = "True";

	FavoriteChanged();
  }
  
  function FavoriteChanged()
  {
     
  //  var iPrefillID    =  netVerse;       
  //  var iFontID     =   netFont     ;
 //   var sColorID   =   GetColorFromComboValue( new String(netColor)); 
    var sSelected  = (bFavorite ? "T" : "F");
    var sQuoteID   = (bHasQuote ?  QuoteID : "");
    var iMsgIns	   = 0;
    var obj = GetObject('chkMsgInside');
    
    if (obj != null) { 
		if (obj.checked) 
			iMsgIns = 1;
	}

	location.href = "/favorite.aspx?set=" + sSetID + "&piece=" + sPieceID +
		"&sel=" + sSelected + "&prefill=" + PrefillID + "&qte=" + sQuoteID +
		"&font=" + FontID + "&color=" + ColorID + "&type=" + sCardType + "&msg=" + iMsgIns;
  }
  
    function FavoriteDeleted(oBtn)
  {
	document.getElementById('del_fav').src= "favorite.aspx?set=" + oBtn.setID + "&piece=" + oBtn.pieceID + "&type=" + oBtn.cardType + "&sel=f";   
  }

  function DisplaySelections(iVerse, iQuote, iFont, iColor, qty, sRetAdd, sLined, sMsgIns, sLrgNms, sLeftCornerCopy, sRightCornerCopy)
  {
    //var obj = GetObject('chkFavorite');
    //obj.checked = bFavorite;
    //debugger
	
     obj = document.getElementById(aspcontrol + 'cmbVerse');
  	 obj.selectedIndex = iVerse;
    //cmbVerse.selectedIndex = iVerse;
    
    
    if (bHasQuote)
    {
      obj = document.getElementById(aspcontrol + 'cmbQuote');
      obj.selectedIndex = iQuote;
    }
 
 //   if ( typeof(cmbQuote) != "undefined" )
 //    cmbQuote.selectedIndex = iQuote;
 
    obj = document.getElementById(aspcontrol + 'cmbFont');
    obj.selectedIndex = iFont;
  
   //cmbFont.selectedIndex = iFont;
  
      obj = document.getElementById(aspcontrol + 'cmbColor');
      obj.selectedIndex = iColor;
   // cmbColor.selectedIndex = iColor;
    
    //qty
    if (qty != "")
    {
        obj = GetObject('txtQuantity');
	    obj.value = qty;
    }
    //printed env
    if (sRetAdd != "")
    {
        obj = GetObject('chkPrintedEnv');
	
		if (obj != null)
		    obj.checked = sRetAdd;
    }    
    //lined env
    if (sLined >= 0)
    {
        obj = GetObject('chkLinedEnv');
		    
		if (obj != null)
		{
			obj.checked = true;
			obj = GetObject('cmbLiner');
			obj.disabled = false;
			obj.selectedIndex = sLined;
			var img = obj.options[obj.selectedIndex].image;
			obj = GetObject("imgLinerColor");
			obj.src = "/images/liners/" + img;
		}	
    }    
    //msginside
    if (sMsgIns != "")
    {
        obj = GetObject('chkMsgInside');
	    
	    if (obj != null)
			obj.checked = sMsgIns;
    }    
    
    //enlarge names
    if (sType == "I")
    {
        obj = GetObject('chkLrgNm');
	    
	    if (obj != null)
			obj.checked = sLrgNms;
    }    

    //left corner copy
    if (sLeftCornerCopy != "")
    {
        obj = GetObject('chkCornerCopyLeft');
	    
	    if (obj != null)
			obj.checked = sLeftCornerCopy;
    }    

    //right corner copy
    if (sRightCornerCopy != "")
    {
        obj = GetObject('chkCornerCopyRight');
	    
	    if (obj != null)
			obj.checked = sRightCornerCopy;
    }    

    InkColorChanged();
    return false;
  }
  function OrderChanged(btn, iPieceID, sType, qty, sRetAdd, sLined, sMsgIns)
  {
    // Use the current time to prevent image caching
    var t = TimeString();
    var obj;
  
    if (btn.mode == "add")
    {
      // Get the text options
    
   //    var iPrefillID    =  netVerse;       
   //    var iFontID     =   netFont     ;
  //     var sColorID   =   GetColorFromComboValue( new String(netColor)); 
       var sQuoteID   = (bHasQuote ?  QuoteID : "");
     


      // Get the order options
      var iRetAdd = 0;
      var iMsgIns = 0;
      var iLrgNms = 0;
      var sLinerID = "";
	  var iLeftCornerCopy = 0;
	  var iRightCornerCopy = 0;

      if (sRetAdd != "")
      {
        obj = GetObject(sRetAdd);
        if (obj.checked) iRetAdd = 1;
      }

      if (sMsgIns != "")
      {
        obj = GetObject(sMsgIns);
        if (obj.checked) iMsgIns = 1;
      }
 
      if (sLined != "")
      {
        obj = GetObject(sLined);
        if (obj.checked) sLinerID = GetValue('cmbLiner');
      }
      
      if (sType == "I")
      {
        obj = GetObject("chkLrgNm");
        if (obj.checked) 
			iLrgNms = 1;
      }

	  if (sType == "I" || sType == "E")
	  {
		if (!CheckReturnAddress(document.getElementById('chkPrintedEnv')))
			return false;
			
		if (document.getElementById('chkCornerCopyLeft') != null && document.getElementById('chkCornerCopyLeft').checked == true)
		{
			if (!LeftCornerCopy(document.getElementById('chkCornerCopyLeft')))
				return false;
		}

		if (document.getElementById('chkCornerCopyRight') != null && document.getElementById('chkCornerCopyRight').checked == true)
		{
			if (!RightCornerCopy(document.getElementById('chkCornerCopyRight')))
				return false;
		}
	  }

		obj = GetObject('chkCornerCopyLeft');    
	  	if (obj != null) { 
			if (obj.checked) 
				iLeftCornerCopy = 1;
		}

		obj = GetObject('chkCornerCopyRight');    
		if (obj != null) { 
			if (obj.checked) 
				iRightCornerCopy = 1;
		}

     var sQty = GetValue(qty);

      // Add this item the to cart
      //obj = GetObject('dummy');
   
      location.href =
        "/order.aspx?sel=T&opt=order&id=" + sUserID + "&order=" + sOrderID +
        "&set=" + sSetID + "&piece=" + iPieceID + "&type=" + sType +
        "&qty=" + sQty + "&addr=" + iRetAdd + "&liner=" + sLinerID +
        "&msg=" + iMsgIns + "&prefill=" +iPrefillID + "&qte=" + sQuoteID +
        "&font=" + FontID + "&color=" + ColorID + "&enlarge=" + iLrgNms + "&time=" + t +
        "&lcc=" + iLeftCornerCopy + "&rcc=" + iRightCornerCopy;
   }
    else
    {
      // Remove this item from the cart
      obj = GetObject('dummy');
      obj.src = "..\order.aspx?sel=F&opt=order&id=" + sUserID + "&order=" + sOrderID +
                "&set=" + sSetID + "&piece=" + iPieceID + "&type=" + sType + "&time=" + t;
	  
	  //QuickSummary();
    }    
  }
  
  function AdminOrderChanged(btn, iPieceID, sType, qty, sRetAdd, sLined, sMsgIns)
  {
    // Use the current time to prevent image caching
    var t = TimeString();
   var obj;
  
    // Get the text options
	
	//  var iPrefillID    =  netVerse;       
    //   var iFontID     =   netFont     ;
    //   var sColorID   =   GetColorFromComboValue( new String(netColor)); 
       var sQuoteID   = (bHasQuote ?  QuoteID : "");
     
	
	var iLeftCornerCopy = 0;
	var iRightCornerCopy = 0;

    var AdjustmentDesc = new String(GetValue('txtAdjustmentDesc'));
    
    if (AdjustmentDesc == "")
		AdjustmentDesc = "No reason entered.";
    
    var adminuser = new String(GetValue('adminuser'));
    var ReturnURL = new String(GetValue('adminreturn'));
    var OrderItemID = GetValue('orderitem');

    // Get the order options
    var iRetAdd = 0;
    var iMsgIns = 0;
    var iLrgNms = 0;
    var sLinerID = "";

    if (sRetAdd != "")
    {
    obj = GetObject(sRetAdd);
    if (obj.checked) iRetAdd = 1;
    }

    if (sMsgIns != "")
    {
    obj = GetObject(sMsgIns);
    if (obj.checked) iMsgIns = 1;
    }

    if (sLined != "")
    {
    obj = GetObject(sLined);
    if (obj.checked) sLinerID = GetValue('cmbLiner');
    }
    
    if (sType == "I")
    {
    obj = GetObject("chkLrgNm");
    if (obj.checked) 
		iLrgNms = 1;
    }

		obj = GetObject('chkCornerCopyLeft');    
	  	if (obj != null) { 
			if (obj.checked) 
				iLeftCornerCopy = 1;
		}

		obj = GetObject('chkCornerCopyRight');    
		if (obj != null) { 
			if (obj.checked) 
				iRightCornerCopy = 1;
		}
		
    var sQty = GetValue(qty);

    location.href =
    "/order.aspx?admin=y&sel=T&opt=order&user=" + sUserID + "&order=" + sOrderID +
    "&set=" + sSetID + "&piece=" + iPieceID + "&type=" + sType + "&orderitem=" + OrderItemID +
    "&qty=" + sQty + "&addr=" + iRetAdd + "&liner=" + sLinerID +
    "&msg=" + iMsgIns + "&prefill=" + PrefillID + "&qte=" + sQuoteID +
    "&font=" + FontID + "&color=" + ColorID + "&enlarge=" + iLrgNms + "&time=" + t +
    "&lcc=" + iLeftCornerCopy + "&rcc=" + iRightCornerCopy +
    "&desc=" + AdjustmentDesc + "&adminuser=" + adminuser + "&return=" + ReturnURL;
  }

  function OptionChanged(oOpt, iPieceID, sType, sOpt)
  {
	SaveSelections();

    //if ((sOpt == "addr") && (sSelected == "T") && (!bAddress))
      ////alert("Please click 'Personalize Text' and enter your return address.");
    return true;
  }
  function LinerChanged(sChk, sCmb, iPieceID, sType)
  {
	SaveSelections();
	
	var obj = GetObject(sChk);

	if (obj.checked)
	{
		obj = GetObject("cmbLiner");
		obj.disabled = false;
		var img = obj.options[obj.selectedIndex].attributes["image"].value;
		obj = GetObject("imgLinerColor");
		obj.src = "/images/liners/" + img;
	}
	else
	{
		obj = GetObject("cmbLiner");
		obj.disabled = true;
	}		
    return true;
  }
  function MessageChanged(oChk, iPieceID, sType)
  {
	SaveSelections(iPieceID, sType);
    return DisplayAllAreas();
  }
  function QuickSummary()
  {
	// //alert('get summary');
    // Update the quick summary (use time to prevent image caching)
    obj = GetObject('summary');
    obj.src = "summary.aspx?id=" + sUserID + "&order=" + sOrderID +
              "&set=" + sSetID + "&time=" + TimeString();
  }
  
  function NavigatePiece()
  {
	//var menuIndex = document.getElementById('cmbPieces').selectedIndex;
	//location.href = document.getElementById('cmbPieces').options[menuIndex].value;

	var menuIndex = document.getElementById('cmbPieces');
	location.href = menuIndex.options[menuIndex.selectedIndex].value;
  }
  
  function GetColorFromComboValue ( val )
  {
    var retVal = val.charAt(0); // legacy way
    
    var token = '#';
    var index = val.indexOf( token );
    
    if ( index > -1 )
    {   // found the token, now split it out and get the value
        var tmp = val.split( token );
        
        retVal = tmp[ 0 ];
    }
    //alert( retVal );
    return retVal;  
  }
  
  function SaveSelections()
  {
	//alert("In SaveSelections - UserID = " + sUserID);
    
 //     var iPrefillID    =  netVerse;       
 //      var iFontID     =   netFont     ;
 //      var sColorID   =   GetColorFromComboValue( new String(netColor)); 
      var sQuoteID   = (bHasQuote ?   QuoteID : "");
     



      // Get the order options
      var iMsgIns = 0;
      var iRetAdd = 0;
	  var iLrgNms = 0;
	  var iLeftCornerCopy = 0;
	  var iRightCornerCopy = 0;
      var sLinerID = "";

		var obj = GetObject('chkMsgInside'); 
		if (obj != null) { 
			if (obj.checked) 
				iMsgIns = 1;
		}
		 
		obj = GetObject('chkPrintedEnv');    
		if (obj != null) { 
			if (obj.checked) 
				iRetAdd = 1;
		}
		 
		obj = GetObject('chkLinedEnv');    
		if (obj != null) { 
			if (obj.checked) 
				sLinerID = GetValue('cmbLiner');
		}

		obj = GetObject('chkLrgNm');    
		if (obj != null) { 
			if (obj.checked) 
				iLrgNms = 1;
		}

		obj = GetObject('chkCornerCopyLeft');    
		if (obj != null) { 
			if (obj.checked) 
				iLeftCornerCopy = 1;
		}

		obj = GetObject('chkCornerCopyRight');    
		if (obj != null) { 
			if (obj.checked) 
				iRightCornerCopy = 1;
		}

      obj = GetObject('txtQuantity');
	  var sQty = obj.value; 
 //debugger     
      // Add selected options for this user/item to the saved selections table
      obj = GetObject('dummy');
   
      obj.src =
        "/selections.aspx?user=" + sUserID +
        "&set=" + sSetID + "&piece=" + sPieceID + "&type=" + sType +
        "&qty=" + sQty + "&addr=" + iRetAdd + "&liner=" + sLinerID +
        "&msg=" + iMsgIns + "&prefill=" + PrefillID + "&qte=" + sQuoteID +
        "&font=" + FontID + "&color=" + ColorID + "&enlarge=" + iLrgNms +
        "&lcc=" + iLeftCornerCopy + "&rcc=" + iRightCornerCopy + "&fc=" + bFontChange;
        
        //alert("After selections.aspx");
  }

	function formatCurrency(num) 
	{
//		num = num.toString().replace(/\$|\,/g,'');
//		
//		if(isNaN(num))
//			num = "0";
//		
//		sign = (num == (num = Math.abs(num)));
//		
//		num = Math.floor(num*100+0.50000000001);   
//		
//		cents = num%100;
//		
//		num = Math.floor(num/100).toString();
//		
//		if(cents<10)
//			cents = "0" + cents;
//		
//		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//			num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
//		
//		return (num + '.' + cents);

		return num.toFixed(2);
		//return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	
	function RightCornerCopy(obj)
	{
		var str;
  		var FontID;
  		var ColorID;
		var PrefillID;
		var imgobj;
			
  		str = new String( document.getElementById('optsForm').cmbColor.value);
  		FontID = GetValue('cmbFont');
  		//ColorID = str.charAt(0);
  		ColorID   = GetColorFromComboValue( str ); //str.charAt(0);
		PrefillID = GetValue('cmbVerse');

		if (obj != null && obj != "undefined" && obj.checked)
		{
			if (!bRightCornerCopy)
			{
				var answer = confirm("Please take a moment to enter the text you would like printed on the bottom right corner of this item. It is required before proceeding. Enter your text now?");
			
				if (answer)
				{
					UpdatePrices();
	
					var obj;
					
					obj = GetObject("divVerse");
					obj.className = "div_off";
					obj = GetObject("divQuote");
					obj.className = "div_off";
					obj = GetObject("divCard");
					obj.className = "div_off";
					obj = GetObject("divWeddingInfo");
					obj.className = "div_on";
					
					scroll(0,800);

					document.getElementById('txtRightCorner1').focus();

					return false;						
				}
				else
				{
					UpdatePrices();
					return false;
				}
			}
			else
			{
				imgobj = GetObject("area" + sRightCornerCopyAreaID);		
  				imgobj.src = 'card.aspx?piece=' + sPieceID + '&type=I&rcc=1&area=' + sRightCornerCopyAreaID + '&prefill=' + PrefillID + '&font=' + FontID + '&color=' + ColorID + '&enlarge=1&size=area&cid=' + sUserID;
				UpdatePrices();
				return true;
			}
		}
		
		if (!obj.checked)
		{
			imgobj = GetObject("area" + sRightCornerCopyAreaID);		
			imgobj.src = 'card.aspx?piece=' + sPieceID + '&type=I&rcc=0&area=' + sRightCornerCopyAreaID + '&prefill=' + PrefillID + '&font=' + FontID + '&color=' + ColorID + '&enlarge=1&size=area&cid=' + sUserID;

			UpdatePrices();
			return true;
		}
	}
	
	function LeftCornerCopy(obj)
	{
		var str;
  		var FontID;
  		var ColorID;
		var PrefillID;
		var imgobj;
			
  		str = new String( document.getElementById('optsForm').cmbColor.value);
  		FontID = GetValue('cmbFont');
  		//ColorID = str.charAt(0);
  		ColorID   = GetColorFromComboValue( str ); //str.charAt(0);
		PrefillID = GetValue('cmbVerse');
					
		if (obj != null && obj != "undefined" && obj.checked)
		{
			if (!bLeftCornerCopy)
			{
				var answer = confirm("Please take a moment to enter the text you would like printed on the bottom left corner of this item. It is required before proceeding. Enter your text now?");
			
				if (answer)
				{
					UpdatePrices();
	                turnOnArea ("WeddingInfo");
					scroll(0,800);
					document.getElementById(aspcontrol +  "txtLeftCorner1").focus()
					return false;						
				}
				else
				{
					UpdatePrices();
					return false;
				}
			}
			else
			{
				imgobj = GetObject("area" + sLeftCornerCopyAreaID);		
  				imgobj.src = 'card.aspx?piece=' + sPieceID + '&type=I&lcc=1&area=' + sLeftCornerCopyAreaID + '&prefill=' + PrefillID + '&font=' + FontID + '&color=' + ColorID + '&enlarge=1&size=area&cid=' + sUserID;
				UpdatePrices();
				return true;
			}
		}

		if (!obj.checked)
		{
			imgobj = GetObject("area" + sLeftCornerCopyAreaID);		
			imgobj.src = 'card.aspx?piece=' + sPieceID + '&type=I&lcc=0&area=' + sLeftCornerCopyAreaID + '&prefill=' + PrefillID + '&font=' + FontID + '&color=' + ColorID + '&enlarge=0&size=area&cid=' + sUserID;					
			UpdatePrices();
			return true;
		}				
	}
	
	function CheckReturnAddress(obj)
	{
		if (obj != null && obj != "undefined" && obj.checked)
		{
			if (!bAddress)
			{
				var answer = confirm("We ask that you please take a moment to enter the address you would like printed on the back flap of this item's envelope. It is required before proceeding. Enter your return address now?");
			
				if (answer)
				{
			    	turnOnArea ("WeddingInfo");
					scroll(0,800);

					if (sType == "E")
				    document.getElementById(aspcontrol +  "txtResponseName").focus()
					else if (sType == "T")
			        document.getElementById(aspcontrol +  "txtThankYouName").focus()
					else
					 document.getElementById(aspcontrol +  "txtReturnName").focus()
					
					
					return false;						
				}
				else
				{
					return false;
				}
			}
			else
			{
				return true;
			}
		}
		
		if (!obj.checked)
		{
			return true;
		}
	}
	
	function CheckLargeNameOption(PrefillID)
	{
		var obj = GetObject("divLrgNm");
		var on = false;

		for (i=0; i<aVrsLrgNm.length; i++)
		{
			if (PrefillID == aVrsLrgNm[i] || PrefillID >= 1000)
			{
				obj.className = "div_on";
				on = true;
				break;
			}
		}
		if (!on)
			obj.className = "div_off";	
	}
	
	function BackToShop()
	{
		location.href = "/cardPreview.aspx?cat=" + Category + "&set=" + SetID + "&piece=" + PieceID + "&type=" + CardType;
	}