var xmlhttp;

function showCond(screen)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="service.php";
url=url+"?q="+screen;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function showResult(cond,screen)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="result.php";
url=url+"?q="+screen+'-'+cond;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged1;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtCond").innerHTML=xmlhttp.responseText;
}
}

function stateChanged1()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtResult").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function updateDrop(sel)
{
	
	
	
alert(document.getElementById('secondDrop').innerHTML);
//document.myform.ninetysix[sel.value].checked==true;
document.getElementById('secondDrop').innerHTML=sel.value;
}



function getCityList(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	//document.getElementById('dhtmlgoodies_city').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		ajax.requestFile = 'getCities.php?countryCode='+countryCode;	// Specifying which file to get
		ajax.onCompletion = createCities;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}

function createCities()
{
	var obj = document.getElementById('dhtmlgoodies_city');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code
}
var hotspot = document.getElementsByName('hotspot');
var hotspot_content = document.getElementsByName('hotspot_content');
 
function hotspot_load()
{
	for (var i = 0; i < hotspot.length; i++)
  	{
		hotspot[i].someProperty = i;
		hotspot[i].onclick = function() {hotspot_toggle(this.someProperty)};
	}
	for (var i = 0; i < hotspot_content.length; i++)
	{
		hotspot_content[i].style.display = 'none';
	}
}
 
function hotspot_toggle(i)
{
	if(typeof ClickTaleExec=='function') ClickTaleExec('hotspot_toggle(' + i + ')');
	if (hotspot_content[i].style.display == 'none')
	{
		hotspot_content[i].style.display = ''
	}
	else
		hotspot_content[i].style.display = 'none'
}
 
function hotspot_show_all()
{
	for (var i = 0; i < hotspot_content.length; i++)
	{
		hotspot_content[i].style.display = '';
	}
}
 
function hotspot_hide_all()
{
	for (var i = 0; i < hotspot_content.length; i++)
	{
		hotspot_content[i].style.display = 'none';
	}
}

 
function show_value_type()
{
	if(typeof ClickTaleExec=='function') ClickTaleExec('show_value_type()');
	var set;
	set = document.cart_quantity.elements['value_type'];
	var value_type;
	for(var i = 0; i < set.length; i++)
	{
		if (set[i].checked)
		{
			value_type = set[i].value;
		}
	}
	if ( value_type == '0' )
	{
		
		document.getElementById('value_amount').style.display = '';
		document.getElementById('value_service').style.display = 'none';
		document.getElementById('value_spa').style.display = 'none';

	}
	else if ( value_type == '1' )
	{
		document.getElementById('value_spa').style.display = 'none';
		document.getElementById('value_amount').style.display = 'none';
		document.getElementById('value_service').style.display = '';
		
	}else if ( value_type == '2' )
	{
		document.getElementById('value_amount').style.display = 'none';
		document.getElementById('value_service').style.display = 'none';
		document.getElementById('value_spa').style.display = '';
		
		
	}
	else
	{
		document.getElementById('value_amount').style.display = 'none';
		document.getElementById('value_service').style.display = 'none';
		document.getElementById('value_spa').style.display = 'none';

	}
}
 
 
 
function show_client_type()
{
	set = document.cart_quantity.elements['client_type'];
	var client_type;
	for(var i = 0; i < set.length; i++)
	{
		if (set[i].checked)
		{
			client_type = set[i].value;
		}
	}
	if ( client_type == 'first_time' )
	{
		document.getElementById('client_email_password').style.display = 'none';
	}
	else if ( client_type == 'existing' )
	{
		document.getElementById('client_email_password').style.display = 'block';
	}
	else
	{
		document.getElementById('client_email_password').style.display = 'none';
	}
}
 
function show_delivery()
{
	if(typeof ClickTaleExec=='function') ClickTaleExec('show_delivery()');
	set = document.cart_quantity.elements['delivery'];
	var delivery;
	for(var i = 0; i < set.length; i++)
	{
		if (set[i].checked)
		{
			delivery = set[i].value;
		}
	}
	
	if ( delivery == '1' )
	{
		document.getElementById('to').style.display = 'block';
		document.getElementById('to_email_when').style.display = 'block';
			document.getElementById('to_email_whennn').style.display = 'block';
			document.getElementById('to_email_whenn').style.display = 'none';
						document.getElementById('title').style.display = 'none';
					document.getElementById('sender').style.display = 'block';
							document.getElementById('senderr').style.display = 'none';
									document.getElementById('recipient').style.display = 'block';
											document.getElementById('recipientt').style.display = 'none';
			
		//document.getElementById('gift_design_section').style.display = 'block';
	//	document.getElementById('preview_section').style.display = 'block';
	document.getElementById('recc').style.display ='none'; 
	document.getElementById('reccc').style.display ='block'; 
						document.getElementById('rec').style.display = 'block';
	}
	else if ( delivery == '2' )
	{
		document.getElementById('to').style.display = 'block';
		document.getElementById('title').style.display = 'none';
document.getElementById('to_email_when').style.display = 'block';
document.getElementById('to_email_whennn').style.display = 'block';
			document.getElementById('to_email_whenn').style.display = 'none';
						document.getElementById('recc').style.display = 'block';
						document.getElementById('rec').style.display = 'none';
						document.getElementById('reccc').style.display = 'none';
						
						document.getElementById('sender').style.display = 'block';
							document.getElementById('senderr').style.display = 'none';
									document.getElementById('recipient').style.display = 'block';
											document.getElementById('recipientt').style.display = 'none';
	//	document.getElementById('gift_design_section').style.display = 'block';
	//	document.getElementById('preview_section').style.display = 'block';
	}
	else if ( delivery == '3' )
	{
		document.getElementById('to').style.display = 'block';
		document.getElementById('title').style.display = 'block';
		document.getElementById('to_email_when').style.display = 'block';
		document.getElementById('to_email_whennn').style.display = 'none';
		document.getElementById('to_email_whenn').style.display = 'block';
		document.getElementById('sender').style.display = 'none';
							document.getElementById('senderr').style.display = 'block';
									document.getElementById('recipient').style.display = 'none';
											document.getElementById('recipientt').style.display = 'block';
		//document.getElementById('gift_design_section').style.display = 'none';
		//document.getElementById('preview_section').style.display = 'none';
		document.getElementById('reccc').style.display = 'none';
						document.getElementById('recc').style.display = 'none';
						document.getElementById('rec').style.display = 'none';
	}
	else
	{
		document.getElementById('to').style.display = 'none';
	document.getElementById('title').style.display = 'none';
	document.getElementById('to_email_when').style.display = 'none';
		document.getElementById('to_email_whennn').style.display = 'none';
			document.getElementById('to_email_whenn').style.display = 'none';
			document.getElementById('recc').style.display = 'none';
			document.getElementById('reccc').style.display = 'none';
						document.getElementById('rec').style.display = 'none';
						document.getElementById('sender').style.display = 'none';
							document.getElementById('senderr').style.display = 'none';
									document.getElementById('recipient').style.display = 'none';
											document.getElementById('recipientt').style.display = 'none';
		//document.getElementById('gift_design_section').style.display = 'block';
	//	document.getElementById('preview_section').style.display = 'block';
	}
	// don't show designs if we only have one...
	//row = document.getElementById('gift_design_cat').value;
	//set = document.form.elements['org_gift_design' + document.getElementById('gift_design_cat').value];
//	if (document.getElementById('gift_design_cat').length == 1 && set.value)
	//	document.getElementById('gift_design_section').style.display = 'none';
}
 

 

function preview(org_gift_design, email_when, value_type, value, apply_tax, gratuity)
{
	org = 2329;
	// detect IE 5.0, which doesn't support encodeURI()
	if (navigator.appVersion.indexOf("MSIE 5.0")!=-1)
		url = 'http://fuse.boomtime.com/gift_preview.php?1=' + org + '&2=' + org_gift_design + '&3=' + escape(document.getElementById('to').value) + '&4=' + escape(document.getElementById('from').value) + '&5=' + email_when + '&6=' + value_type + '&7=' + escape(value) + '&8=' + escape(document.getElementById('message').value) + '&10=' + escape(apply_tax) + '&12=' + escape(gratuity);
	else
		url = 'http://fuse.boomtime.com/gift_preview.php?1=' + org + '&2=' + org_gift_design + '&3=' + encodeURIComponent(document.getElementById('to').value) + '&4=' + encodeURIComponent(document.getElementById('from').value) + '&5=' + email_when + '&6=' + value_type + '&7=' + encodeURIComponent(value) + '&8=' + encodeURIComponent(document.getElementById('message').value) + '&10=' + escape(apply_tax)+ '&12=' + escape(gratuity);
	popped = window.open(url,'_blank','height=635,width=740,scrollbars=Yes,toolbar=No,menubar=No,resizable=Yes,statusbar=No');
	if (! popped)
		alert("Unfortunately, the Preview window didn't come up, probably because of a pop-up blocker. Please turn the pop-up blocker off, and try again.");
}
	
var submitted = false;
 
function do_button_submit(btn, disable, other_btns)
{
	if (btn.id == 'review' || btn.id == 'buy_another')
	{
		if ((document.cart_quantity.rating.value == 0 || document.cart_quantity.review_text.value == '') && document.cart_quantity.review_complete.value == 0 && btn.id == 'review')
		{
			if (document.cart_quantity.rating.value == 0)
			{
  				document.getElementById('err_rating').innerHTML = '&nbsp;&nbsp;&nbsp;Please choose the number of stars.';
				document.getElementById('err_review_text').innerHTML = '&nbsp;';
			}
  			else
  			{
  				document.getElementById('err_rating').innerHTML = '&nbsp;';
				document.getElementById('err_review_text').innerHTML = 'Please enter your review.';
  			}
			return false;
		}
 
		if (btn.id == 'buy_another' && navigator.userAgent.indexOf('Firefox') > 0)
		{
			document.cart_quantity.buy_another.value = "Buy Another";
			document.cart_quantity.submit();
			return;
		}
	}
 
	if (submitted == true) { return; }
	if (document.cart_quantity.button_submit)
	{
		submitted = disable;
		document.cart_quantity.button_submit.value = btn.id;
		btn.disabled = disable;
		if (other_btns)
		{
			for (var i = 0; i < other_btns.length; i++)
			{
				if (document.cart_quantity.elements[other_btns[i]])
				{
					document.cart_quantity.elements[other_btns[i]].disabled = disable;
				}
			}
		}
		document.cart_quantity.submit();
		document.cart_quantity.button_submit.value = '';
	}
	return;
}







function getXMLHTTP() {
		var xmlhttp=false;
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}

		return xmlhttp;
	}

	

function getCurrencyCode(strURL)
{
	var req = getXMLHTTP();
	if (req)
	{
		//function to be called when state is changed
		req.onreadystatechange = function()
		{
			//when state is completed i.e 4
			if (req.readyState == 4)
			{
				// only if http status is "OK"
				if (req.status == 200)
				{

					document.getElementById('divid').innerHTML=req.responseText;
					
				}
				else
				{
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}
		 }
		 req.open("GET", strURL, true);
		 req.send(null);
	}
}
jQuery.fn.truncate = function(len)
{
  this.val(this.val().substring(0,len));
  return false;
}

jQuery.fn.maxLength = function(len)
{
  var maxLengthKeyPress = new Array();
  var maxLengthChange = new Array();
  var appleKeyOn = false;
  
  //the second argument should be true if len should be based on
  //the maxlength attribute instead of the input
  var useAttr = arguments.length>1 ? arguments[1] : false;
  
  var handleKeyUp = function(e)
  {
    //if the apple key (macs) is being pressed, set the indicator
    if(e.keyCode==224||e.keyCode==91)
      appleKeyOn = false;
  }
  
  var handleKeyDown = function(e)
  {
    //if the apple key (macs) is being released, turn off the indicator
    if(e.keyCode==224||e.keyCode==91)
      appleKeyOn = true;
  }
  
  var handleKeyPress = function(e)
  {   
    //if this keyCode does not increase the length of the textarea value,
    //just let it go
    if(appleKeyOn || (e.charCode==0&&e.keyCode!=13) || e.ctrlKey)
      return;

    //get the textarea element
    var textarea = $(this);
    //if the length should be based on the maxlength attribute instead of the
    //input, use that
    len = useAttr ? parseInt(textarea.attr('maxlength')) : len;
    //get the value of the textarea
    var val = textarea.val();
    //get the length of the current text selection
    var selected = Math.abs(textarea.attr('selectionStart') - textarea.attr('selectionEnd'));
    selected = isNaN(selected) ? 0 : selected;
    //if this is the maximum length
    if(val.length==len && selected<1)
      return false;
    else if(val.length>len && selected<(val.length-len))
      return textarea.truncate(len);
  };
  
  var handleChange = function(e)
  {
    //get the textarea element
    var textarea = $(this);
    
    //if the length should be based on the maxlength attribute instead of the
    //input, use that
    len = useAttr ? parseInt(textarea.attr('maxlength')) : len;
    
    //truncate the textarea to its proper length
    textarea.truncate(len);
  };
  
  //get the current keyup and change functions
  var removeKeyPress = maxLengthKeyPress[this.selector];
  var removeChange = maxLengthChange[this.selector];

  //remove the keyup and change functions from any matched elements in case
  //a maxlength was previously set and a new one is being set
  this.die('keypress', removeKeyPress);
  this.die('change', removeChange);
  
  if(len==0 && !useAttr)
    return;
  
  //set the keyup and change functions for this element set and all future
  //elements matching this selector
  this.live('keypress', handleKeyPress);
  this.live('change', handleChange);
  this.live('keydown', handleKeyDown);
  this.live('keyup', handleKeyUp);
  
  //save the current keyup and change functions so that they can be
  //remove later
  maxLengthKeyPress[this.selector] = handleKeyPress;
  maxLengthChange[this.selector] = handleChange;
  
  //trigger a keypress event so that the limit will be enforced
  this.keypress();
};
/*
$(function()
{
  
  $('textarea[maxlength]').maxLength(null, true);
});*/