function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popup(url, width, height) {
  window.open(url,"_blank","width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=0,menubar=0,scrollbars=0");
}

function popup2(url, width, height, scrollbars) {
  window.open(url,"_blank","width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=0,menubar=0,scrollbars=" + scrollbars);
}

function popupLarge(url, target) {
  window.open(url,target);
}


function openwin(url,w_title,width,height)
{
	var maxw = window.screen.availWidth;
	var maxh = window.screen.availHeight;
	var win = window.open(url,w_title,'screenX=0,screenY=0,left='+((maxw-width)/2)+',top=0,width=' + width + ',height=' + height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
		win.focus();
}

function body_img_onload()
{
	MM_preloadImages('', 
					 ''
					 );
	//alert("hello");
}


/**********************************************************/
function find_PosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function find_PosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function xstooltip_show(id, description, tooltip_id)
{
	//alert(description);
	//alert(tooltip_id);
	var obj_tooltip = document.getElementById(tooltip_id);
	var obj = document.getElementById(id);
	//alert(obj.width);
	//alert(obj.height);
	var obj_width = obj.width;
	var obj_height = obj.height;
	
	if(description)
	{
		obj_tooltip.innerHTML = description;
		obj_tooltip.style.top=find_PosY(obj) + 'px';
		obj_tooltip.style.left=find_PosX(obj) + obj_width + 6 + 'px';
		obj_tooltip.style.visibility = 'visible';
	}
}

function xstooltip_hide(id)
{
    var obj = document.getElementById(id); 
    obj.style.visibility = 'hidden'; 
}

function getBrowserHeight()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	 //Non-IE
	  myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	  //IE 6+ in 'standards compliant mode'
	  myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  //IE 4 compatible
	  myHeight = document.body.clientHeight;
	}
	return myHeight;
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}
/**********************************************************/

/**********************************************************/
/* Functions for site */
/**********************************************************/
function getCustomerState(value)
{
	//alert(value);
	var url = "get_customer_state_combo.php?country_code="+value;
	var myAjax = new Ajax.Request(
        url,
        {
			method: 'post', 
			parameters: value, 
			onComplete: getCustomerStateResponse
		}
    );
}
function getCustomerStateResponse(originalRequest)
{
	//alert(originalRequest.responseText);
	var obj = $("customer_state");
	obj.innerHTML = originalRequest.responseText;
}

function getDeliveryState(value, url)
{
	//alert('tset'+url);
	//var url = "{relativeslash}get_delivery_state_combo.php?country_code="+value;
	url += value;
	//alert(url);
	var myAjax = new Ajax.Request(
        url,
        {
			method: 'post', 
			parameters: value, 
			onComplete: getDeliveryStateResponse
		}
    );
}
function getDeliveryStateResponse(originalRequest)
{
	//alert(originalRequest.responseText);
	var obj = $("delivery_state");
	obj.innerHTML = originalRequest.responseText;
}
function deleteAddress(id, isDefault)
{
	var myForm = document.form1;
	if (isDefault == 1)
	{
		alert('You can not delete the default address.')
		return false;
	}
	if(confirm('Do you want to delete this address record?'))
	{
		myForm.delete_id.value = id;
		myForm.set_default.value = '';
		myForm.submit();
	}
	else
		return false;
}
function setDefault()
{
	var myForm = document.form1;
	myForm.delete_id.value = '';
	myForm.set_default.value = '1';
	//alert('aaa');
	myForm.submit();
}
function addNew(url)
{
	location.href = url;
}
function clear_cart(url)
{
	if(confirm("Are you sure to clear your cart?"))
	{
		document.location.href=url;
	}
}
function showCreditCard()
{
	var obj = $("creditcard_block");
	if(obj)
	{
		obj.style.display = "inline";
	}
}
function hideCreditCard()
{
	var obj = $("creditcard_block");
	if(obj)
	{
		obj.style.display = "none";
	}
}

function getCustomerState(value,url)
{
	//alert(value);
	//var url = "get_customer_state_combo.php?country_code="+value;
	if(url)
	{
		url += value;
	}
	else
	{
		url = "get_customer_state_combo.php?country_code="+value;
	}
	var myAjax = new Ajax.Request(
        url,
        {
			method: 'post', 
			parameters: value, 
			onComplete: getCustomerStateResponse
		}
    );
}
function getCustomerStateResponse(originalRequest)
{
	//alert(originalRequest.responseText);
	var obj = $("customer_state");
	obj.innerHTML = originalRequest.responseText;
}
function selectAddressBook(url)
{
	popup2(url, 800, 300, 1);
}
function getDeliveryAddress(id)
{
	//alert(id);
	var f = document.frmShipping;
	f.submit_value.value = "";
	f.get_delivery.value = "1";
	f.delivery_id.value = id;
	//alert(f.get_delivery.value);
	f.submit();
}
function getshippingAddress(id)
{
	//alert(id);
	var f = document.frmShipping;
	f.submit_value.value = "";
	f.get_shipping.value = "1";
	f.shipping_id.value = id;
	f.submit();
}
function cancelOrder()
{
	var f = document.frmCancel;
	f.submit_value.value = "1";
	f.submit();
}
function acceptCancelOrder()
{
	var f = document.frmCancel;
	f.accept_cancel.value = "1";
	f.submit();
}
function check_submit(e)
{
	var f = document.frmSearch;
	var text = f.keyword.value;
	
	if(e)
	{
		e = e;
	}
	else
	{
		e = window.event;
	} 
	
	if(e.which)
	{ 
		var keycode = e.which;
	}
	else
	{
		var keycode = e.keyCode;
	}
	
	if(keycode==13)
	{
		//alert(text);
		if(text == '')
		{
			alert('Please input keyword to search !');
			f.keyword.focus();
			return false;
		}
		else
		{
			f.submit();
		}
	}
}
function search_keyword()
{
	var f = document.frmSearch;
	var text = f.keyword.value;
	if(text == '')
	{
		alert('Please input keyword to search !');
		f.keyword.focus();
	}
	else
	{
		f.submit();
	}
}
function showForm(id)
{
	//alert(id);
	var obj = document.getElementById(id);
	if(obj)
	{
		if(obj.style.display=="none")
		{
			obj.style.display="inline";
		}
		else
		{
			obj.style.display="none";
		}
	}
}
function doCopy(url)
{
	var myForm = document.frmUpdate;
	if (myForm.chk_copy.checked==true)
	{
		myForm.delivery_name.value = myForm.customer_billing_name.value;
		myForm.delivery_street_address.value = myForm.customer_address.value;
		myForm.delivery_city.value = myForm.customer_city.value;
		myForm.delivery_zipcode.value = myForm.customer_zipcode.value;
		myForm.delivery_country.selectedIndex = myForm.customer_country.selectedIndex;
		
		url += "state_code=" + myForm.customer_state.value + "&country_code=";
		getDeliveryState(myForm.delivery_country.value, url);
		
		myForm.delivery_phone.value = myForm.customer_phone.value;
	}
	else
	{
		myForm.delivery_name.value = '';
		myForm.delivery_street_address.value = '';
		myForm.delivery_city.value = '';
		myForm.delivery_zipcode.value = '';
		myForm.delivery_country.selectedIndex = 0;
		getDeliveryState(myForm.delivery_country.value, url);
		myForm.delivery_phone.value = '';
	}
}


function withVase(url, data, id)
{
	//alert(url);
	var myAjax = new Ajax.Request(
        url,
        {
			method: 'post', 
			parameters: data, 
			onComplete: withVaseResponse
		}
    );
	//alert(url);
	var obj = document.getElementById("subtotal");
	var f = document.frmItem;
	var obj_selectShipping = f.selectShipping;
	var subTotal = parseFloat(data);
	if(obj_selectShipping)
	{
		if(obj_selectShipping.length)
		{
			//alert(obj_selectShipping.length);
			for(i=0;i<obj_selectShipping.length;i++)
			{
				if(obj_selectShipping[i].selected==true)
				{
					//alert(obj_selectShipping.value);
					var shipping_id_tring = obj_selectShipping.value + "_shipping_id";
					var obj_shipping_id = document.getElementById(shipping_id_tring);
					if(obj_shipping_id)
					{
						if(obj_shipping_id.value)
						{
							//alert(obj_shipping_id.value);
							subTotal = subTotal + parseFloat(obj_shipping_id.value);
						}
					}
				}
			}
		}
	}
	obj.innerHTML = "Sub Total : USD"+subTotal.toFixed(2);
	//alert(id);
	setOptionID(id);
}
function withVaseResponse(originalRequest)
{
	//alert(originalRequest.responseText);
	var obj = $("optionvase_block");
	obj.innerHTML = originalRequest.responseText;
}
function addPrice(value, vase_id_value)
{
	//alert(vase_id_value);
	
	var obj = document.getElementById("subtotal");
	var f = document.frmItem;
	var obj_option_id = f.option_id;
	var obj_selectShipping = f.selectShipping;
	var subTotal = parseFloat(value);
	if(obj_option_id)
	{
		if(obj_option_id.length)
		{
			//alert(obj_option_id.length);
			for(i=0;i<obj_option_id.length;i++)
			{
				if(obj_option_id[i].checked==true)
				{
					//alert(obj_option_id[i].value);
					subTotal = subTotal + parseFloat(obj_option_id[i].value);
				}
			}
		}
		else
		{
			subTotal = subTotal + parseFloat(obj_option_id.value);
		}
	}
	if(obj_selectShipping)
	{
		if(obj_selectShipping.length)
		{
			//alert(obj_selectShipping.length);
			for(i=0;i<obj_selectShipping.length;i++)
			{
				if(obj_selectShipping[i].selected==true)
				{
					//alert(obj_selectShipping.value);
					var shipping_id_tring = obj_selectShipping.value + "_shipping_id";
					var obj_shipping_id = document.getElementById(shipping_id_tring);
					if(obj_shipping_id)
					{
						if(obj_shipping_id.value)
						{
							//alert(obj_shipping_id.value);
							subTotal = subTotal + parseFloat(obj_shipping_id.value);
						}
					}
				}
			}
		}
	}
	//alert(subTotal);
	
	f.option_vase_id.value = vase_id_value;
	obj.innerHTML = "Sub Total : USD"+subTotal.toFixed(2);
}
function selectAddSubTotal(value)
{
	//alert(value);
	var obj = document.getElementById("subtotal");
	var f = document.frmItem;
	var obj_option_id = f.option_id;
	var obj_vase_id = f.vase_id;
	var subTotal = 0;
	if(obj_option_id)
	{
		if(obj_option_id.length)
		{
			//alert(obj_option_id.length);
			for(i=0;i<obj_option_id.length;i++)
			{
				if(obj_option_id[i].checked==true)
				{
					//alert(obj_option_id[i].value);
					subTotal = subTotal + parseFloat(obj_option_id[i].value);
				}
			}
		}
		else
		{
			subTotal = subTotal + parseFloat(obj_option_id.value);
		}
	}
	//alert(subTotal);
	if(obj_vase_id)
	{
		//alert("choose vase");
		if(obj_vase_id.length)
		{
			for(i=0;i<obj_vase_id.length;i++)
			{
				if(obj_vase_id[i].checked == true)
				{
					subTotal = subTotal + parseFloat(obj_vase_id[i].value);
				}
			}
		}
		else
		{
			subTotal = subTotal + parseFloat(obj_vase_id.value);
		}
	}
	//alert(subTotal);
	var shipping_id_tring = value + "_shipping_id";
	var obj_shipping_id = document.getElementById(shipping_id_tring);
	if(obj_shipping_id)
	{
		if(obj_shipping_id.value)
		{
			//alert(obj_shipping_id.value);
			subTotal = subTotal + parseFloat(obj_shipping_id.value);
		}
	}
	if(obj)
	{
		obj.innerHTML = "Sub Total : USD"+subTotal.toFixed(2);
	}
}
function setOptionID(id)
{
	var f = document.frmItem;
	var obj_option_id = f.option_id;
	if(id)

	{
		f.item_option_id.value = id;
	}
}
function orderGift()
{
	var f = document.frmItem;
	f.submit();
}
function focusVase(vase_id_value)
{
	alert(vase_id_value);
	var f = document.frmItem;
	var obj = f.vase_id;
	if(obj)
	{
		if(obj.length)
		{
			alert(obj.length);
		}
		else
		{
		}
	}
	
}

function checkFrom()
{
	var f = document.frm_comment;
	if(f.review_content.value=='')
	{
		alert('Please enter a comment.');
		f.review_content.focus();
		return;
	}
	f.submit();
}

function openwin_withscroll(url,w_title,width,height)
{
	var maxw = window.screen.availWidth;
	var maxh = window.screen.availHeight;
	var win = window.open(url,w_title,'screenX=0,screenY=0,left='+((maxw-width)/2)+',top='+((maxh-height)/2)+',width=' + width + ',height=' + height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
		win.focus();
}

function viewDescription(url)
{
	openwin_withscroll(url,'title',690,550);
}

function ordergift_addPrice(id, price)
{
	//alert(id + " : " + price);
	 var f = document.frmGift;
	 var obj_gift_id = f.gift_id;
	 var total = parseFloat(f.total_gift_price.value);
	 if(!total)
	 {
	 	total = parseFloat("0");
	 }
	 if(obj_gift_id)
	 {
	 	if(obj_gift_id.length)
		{
			for(i=0;i<obj_gift_id.length;i++)
			{
				if(obj_gift_id[i].checked==true)
				{
					if(parseInt(obj_gift_id[i].value)==parseInt(id))
					{
						//alert(i);
						total += parseFloat(price);
						var gift_id_parameter = id + "_gift_id";
						var obj_gift_id = document.getElementById(gift_id_parameter);
						if(obj_gift_id)
						{
							obj_gift_id.checked = true;
						}
					}
				}
				else
				{
					if(parseInt(obj_gift_id[i].value)==parseInt(id))
					{
						//alert(i);
						total -= parseFloat(price);
						var gift_id_parameter = id + "_gift_id";
						var obj_gift_id = document.getElementById(gift_id_parameter);
						if(obj_gift_id)
						{
							obj_gift_id.checked = false;
						}
					}
				}
			}
		}
		else
		{
			if(obj_gift_id.checked==true)
			{
				total += parseFloat(price);
				var gift_id_parameter = id + "_gift_id";
				var obj_gift_id = document.getElementById(gift_id_parameter);
				if(obj_gift_id)
				{
					obj_gift_id.checked = true;
				}
			}
			else
			{
				total -= parseFloat(price);
				var gift_id_parameter = id + "_gift_id";
				var obj_gift_id = document.getElementById(gift_id_parameter);
				if(obj_gift_id)
				{
					obj_gift_id.checked = false;
				}
			}
		}
	 }
	 
	 f.total_gift_price.value = total;
	 
	 var order_sub_total = parseFloat(f.flower_sub_total.value) + total;
	 order_sub_total = "&#36;" + order_sub_total.toFixed(2);
	 var obj_order_sub_total = document.getElementById("order_sub_total");
	 var obj_basket_order_sub_total = document.getElementById("basket_order_sub_total");
	 obj_order_sub_total.innerHTML = order_sub_total;
	 //obj_basket_order_sub_total.innerHTML = order_sub_total;
	 
	 total = "&#36;" + total;
	 
	 var obj_gift_sub_total = document.getElementById("gift_sub_total");
	 if(obj_gift_sub_total)
	 {
	 	obj_gift_sub_total.innerHTML = total;
	 }
	 
	 
	 //alert(total);
}

function postError(url)
{
	var f = document.frmGift;
	f.action = url;
	f.submit();
}

function selectShipping(url)
{
	popup2(url, 800, 300, 1);
}

function selectDeliveryDate(url)
{
	openwin(url,'',300,210);//popup2(url, 300, 210, 0);
}
function getDeliveryDate()
{
	//alert("HELLO");
	location.reload();
}

function navigate(i)
{
	var f = document.frmList;
	//f.action="index.php";
	f.page.value=i;
	f.submit();
}

function press_checkFrom()
{
	var f = document.frm_comment;
	if(f.your_name.value=='')
	{
		alert('Please enter Your name.');
		f.your_name.focus();
		return;
	}
	if(f.your_email.value=='')
	{
		alert('Please enter Email address.');
		f.your_email.focus();
		return;
	}
	if(f.comment.value=='')
	{
		alert('Please enter a comment.');
		f.comment.focus();
		return;
	}
	if(f.security_code.value=='')
	{
		alert('Please enter Security Code.');
		f.security_code.focus();
		return;
	}
	f.submit();
}

function authorize_checkForm()
{
	var f = document.frm_authorize;
	if(f.cc_number.value=='')
	{
		alert("Please enter your credit card number.");
		f.cc_number.focus();
		return;
	}
	if(f.cc_cvv.value=='')
	{
		alert("Please enter secure code.");
		f.cc_cvv.focus();
		return;
	}
	
	if(f.payment_opt.value==1)
	{
		f.submit();
	}
	else
	{
		f.poffline.value = 1;
		f.action = "";
		f.submit();
	}
}

function pay_offline(url)
{
	var f = document.frm_authorize;
	f.action = url;
	f.submit();
}