// JavaScript Document



function doFocus (ElementName) {
	var Obj= ElementName;
	Obj.focus();
}



function doFocusSetStyle (ElementName) {
	doFocus(ElementName);
	var Obj = ElementName;
	Obj.style.borderColor="#8a0000";
}



function doLabelStyle (ElementName) {
	var Obj = document.getElementById(ElementName);
	Obj.style.color="#8a0000";
}



function doResetLabelStyle (Arrstr) {

	var lblArr =doResetLabelStyle.arguments;

	for (i=0; i<lblArr.length; i++) {
		document.getElementById(lblArr[i]).style.color="";	
	}

}



function doResetInput (frmID) {	
	var frmObj=document.getElementById(frmID);

	for (var i = 0; i < frmObj.elements.length; i++) {
		if (frmObj.elements[i].type == "text" || frmObj.elements[i].type == "select-one") {
			frmObj.elements[i].style.borderColor = "";
		}
	}
}



function resetErrMsg () {

	for (i=1; i<=20; i++) {
		if (document.getElementById("msg"+i)) {
			var curMsg = document.getElementById("msg"+i);
			curMsg.innerHTML="&nbsp;";
		}
	}
}



/*================================================================================================*/

function Browser() {



  var ua, s, i;



  this.isIE    = false;  // Internet Explorer

  this.isOP    = false;  // Opera

  this.isNS    = false;  // Netscape

  this.version = null;



  ua = navigator.userAgent;



  s = "Opera";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isOP = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }



  s = "Netscape6/";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isNS = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }



  // Treat any other "Gecko" browser as Netscape 6.1.



  s = "Gecko";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isNS = true;

    this.version = 6.1;

    return;

  }



  s = "MSIE";

  if ((i = ua.indexOf(s))) {

    this.isIE = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }

}



var browser = new Browser();



function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;

  if (el.offsetParent != null)

    x += getPageOffsetLeft(el.offsetParent);

  return x;

}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;

  if (el.offsetParent != null)

    y += getPageOffsetTop(el.offsetParent);

  return y;

}



function showError(formobj,err_str,err_div,input) {

	var x = getPageOffsetLeft(input);

	var y = getPageOffsetTop(input);

	var objCon = MM_findObj(err_div+"Content");

	var divObj = MM_findObj(err_div);

	if (objCon != null) {

		objCon.innerHTML="<p>"+err_str+"</p>";

	}

	if (divObj != null) {

		divObj.style.left = (x+70)+"px";

		divObj.style.top = y+16+"px";

		divObj.style.visibility = "visible";

	}



	if (browser.isIE) {

		var iframeObj = MM_findObj(err_div+"Iframe");

		if (iframeObj != null && divObj!=null) {

			iframeObj.style.width = divObj.offsetWidth+"px";

			iframeObj.style.height = divObj.offsetHeight+"px";

			iframeObj.style.left = divObj.style.left;

			iframeObj.style.top = divObj.style.top;

			iframeObj.style.visibility = "visible";

		}

	}

	//resetFrmFeedBack(formobj);

	input.focus();

	input.style.backgroundColor="#F1F2F2";

	return false;

}



function closeError(err_div) {

	var divObj=MM_findObj(err_div);

	if (divObj!=null) {

		divObj.style.visibility="hidden";

	}

	if (browser.isIE) {

		var iframeObj = MM_findObj(err_div+"Iframe");

		if (iframeObj!=null) {

			iframeObj.style.visibility="hidden";

		}

	}

}

/*================================================================================================*/

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_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}



function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}



function MM_showHideLayers() { //v6.0

  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }

    obj.visibility=v; }

}





function showhideFile(id) {

	var mobj=document.getElementById(id);

	if (mobj.style.display=="none" || mobj.style.display=="") {

		mobj.style.display="block";

	}else{

		mobj.style.display="none";	

	}

	

}



function getElementsByBaseTagClass(base, tag, className) { 

    var classPat = new RegExp('\\b'+className+'\\b'); 

    var nodes = base.getElementsByTagName(tag); 

    var matching = []; 

    for (var i = 0; i < nodes.length; i++) { 

        if (classPat.test(nodes[i].className)) { 

            matching.push(nodes[i]); 

        } 

    } 

	return matching; 

}

/*================================================================================================*/



function isEmail(s){

	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/) != -1)

		return true ;

	return false ;

}



function isPhone(s) {

	if (s.search(/^[ .0-9-]{3,}$/) != -1)

		return true ;

	return false ;

}



function isNumber(val)

{

	if (isNaN(val) || val<=0)

		return false;

	else

		return true;

}



function isDate(s) {

	if (s.search(/^([0]?[1-9]|[1|2][0-9]|[3][0|1])[.\/-]([0]?[1-9]|[1][0-2])[.\/-]([0-9]{4}|[0-9]{2})$/) != -1)

		return true ;

	return false ;

}

function isDateEn(s) {

	if (s.search(/^([0]?[1-9]|[1][0-2])[.\/-]([0]?[1-9]|[1|2][0-9]|[3][0|1])[.\/-]([0-9]{4}|[0-9]{2})$/) != -1)

		return true ;

	return false ;

}



function isPostCode(s,type) {

	if (type == 'CA')
	{
		if (s.search(/^([A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9])$/) != -1)
			return true ;
		return false ;
	}
	else if (type == 'US')
	{
		if (s.search(/^([0-9][0-9][0-9][0-9][0-9])$/) != -1)
			return true ;
		return false ;
	}
	else
	{
		if (trim(s) != "")
			return true;
		return false;
	}
}



function chkyob (s) {

	year=s.substr(s.lastIndexOf("/")+1, s.length);

	var date = new Date();

	var myear= date.getFullYear();

	if (year<myear) {

		return true;

	}

	return false;

}





function filterKey2(e, DOBID, sepSym) {

	var keynum

	var keychar

	var numcheck

	

	if(window.event) {

		keynum = e.keyCode

	} else if(e.which) {

		keynum = e.which

	}

	keychar = String.fromCharCode(keynum);

	numcheck = /[0-9]/;

	if(!numcheck.test(keychar)) {

		if (keynum!=8&&typeof(keynum)!="undefined") {

			//alert("Please enter only numeric characters");

			return false;

		}

	}

	var iDOB=document.getElementById(DOBID);

	var numLen=iDOB.value.length+1;	

	if ((numLen==3 || numLen==6)&& numcheck.test(keychar)) {

		iDOB.value+=sepSym;

	}

	return true;

}





function filterKey3(e, DOBID, sepSym) {

	var keynum

	var keychar

	var numcheck

	

	if(window.event) {

		keynum = e.keyCode

	} else if(e.which) {

		keynum = e.which

	}

	keychar = String.fromCharCode(keynum);



	numcheck = /[0-9]/;

	if(!numcheck.test(keychar)) {

		if (keynum!=8&&typeof(keynum)!="undefined") {

			//alert("Please enter only numeric characters");

			return false;

		}

	}

	var iDOB=document.getElementById(DOBID);

	var numLen=iDOB.value.length+1;

	if ((numLen==6)&& numcheck.test(keychar)) {

		iDOB.value+=sepSym;

	}

	return true;

}





function isBlank(str) {

	if(trim(str) == "" ) 

		return true ;

	return false ;

}



function trim(str) {

	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');

}



function emptyValue(obj)

{

	obj.value = '';

}



function checkContact(frm)

{

	if (trim(frm.contactName.value)=="")

	{

		showError(frm,"Please input your name.","error",frm.contactName);

		frm.contactName.focus();

		return;

	}



	if (!isEmail(trim(frm.contactEmail.value)))

	{

		showError(frm,"Email is invalid.","error",frm.contactEmail);

		frm.contactEmail.focus();

		return;

	}

	

	if (!isPhone(frm.phoneNumber.value))

	{

		showError(frm,"Please input your phone number.","error",frm.phoneNumber);

		frm.phoneNumber.focus();

		return;

	}



	if (frm.contactInquire.options[frm.contactInquire.selectedIndex].value == 0)

	{

		showError(frm,"Please select your inquiring.","error",frm.contactInquire);

		frm.contactInquire.focus();

		return;

	}

	

	if (trim(frm.contactConcern.value) == "")

	{

		showError(frm,"Please input your question.","error",frm.contactConcern);

		frm.contactConcern.focus();

		return;

	}

	

	frm.submit();

}



function checkQuoteDesign(frm)

{

	if (trim(frm.contactName.value)=="")

	{

		showError(frm,"Please input your name.","error",frm.contactName);

		frm.contactName.focus();

		return;

	}



	if (!isEmail(trim(frm.contactEmail.value)))

	{

		showError(frm,"Email is invalid.","error",frm.contactEmail);

		frm.contactEmail.focus();

		return;

	}



	/*if (frm.contactInquire.options[frm.contactInquire.selectedIndex].value == 0)

	{

		showError(frm,"Please select the product in which you are interested.","error",frm.contactInquire);

		frm.contactInquire.focus();

		return;

	}*/

	

	if (trim(frm.quoteColor.value)=="")

	{

		showError(frm,"Please input color.","error",frm.quoteColor);

		frm.quoteColor.focus();

		return;

	}

	

	if (trim(frm.quoteSize1.value)=="" && trim(frm.quoteSize2.value)=="" && trim(frm.quoteSize3.value)=="")

	{

		showError(frm,"Please input size.","error",frm.quoteSize1);

		frm.quoteSize1.focus();

		return;

	}

	

	frm.submit();

}



function checkQuoteProduct(frm)

{

	if (trim(frm.contactName.value)=="")

	{

		showError(frm,"Please input your name.","error",frm.contactName);

		frm.contactName.focus();

		return;

	}



	if (!isEmail(trim(frm.contactEmail.value)))

	{

		showError(frm,"Email is invalid.","error",frm.contactEmail);

		frm.contactEmail.focus();

		return;

	}



	if (trim(frm.contactInquire.value) == "")

	{

		showError(frm,"Please input a product in which you are interested.","error",frm.contactInquire);

		frm.contactInquire.focus();

		return;

	}

	

	if (trim(frm.quoteColor1.value)=="" && trim(frm.quoteColor2.value)=="" && trim(frm.quoteColor3.value)=="")

	{

		showError(frm,"Please input color.","error",frm.quoteColor1);

		frm.quoteColor1.focus();

		return;

	}

	

	if (trim(frm.quoteSize1.value)=="" && trim(frm.quoteSize2.value)=="")

	{

		showError(frm,"Please input size.","error",frm.quoteSize1);

		frm.quoteSize1.focus();

		return;

	}

	

	frm.submit();

}



function goCheckout()
{		
	if ($('my_total_amount').value <=0)
	{
		alert('Please pick more products into cart to checkout');
		return;
	}

	window.location = web_path+"checkout/step1/";
}



function checkStep1(frm)
{		

	if (trim($('ordName').value) == "")
	{
		showError(frm,"Please input first name.","error",frm.ordName);
		frm.ordName.focus();

		return;
	}
	
	if (trim($('ordLastName').value) == "")
	{
		showError(frm,"Please input last name.","error",frm.ordLastName);
		frm.ordLastName.focus();

		return;
	}

	

	if (!isEmail(trim(frm.ordEmailAddress.value)))
	{
		showError(frm,"Email is invalid. Please input again.","error",frm.ordEmailAddress);
		frm.ordEmailAddress.focus();

		return;
	}	
	

	if (!isPhone(frm.ordPhoneNumber.value))
	{
		showError(frm,"Phone number is invalid. Please input again","error",frm.ordPhoneNumber);
		frm.ordPhoneNumber.focus();

		return;
	}

	

	if (trim(frm.ordAddress1.value)=="")
	{
		showError(frm,"Please input billing address.","error",frm.ordAddress1);
		frm.ordAddress1.focus();

		return;
	}

	
	if ($('ordCountry').value == '-1')
	{
		showError(frm,"Please select country.","error",frm.ordCountry);
		frm.ordCountry.focus();

		return;
	}

	
	if (trim(frm.ordCity.value)=="")
	{
		showError(frm,"Please input city.","error",frm.ordCity);
		frm.ordCity.focus();

		return;
	}

	

	if ($('ordProvince').value == '-1')
	{

		showError(frm,"Please select province.","error",frm.ordProvince);

		frm.ordProvince.focus();

		return;

	}

	var str = frm.ordPostalCode.value;
	frm.ordPostalCode.value = str.replace(/ /g, '');

	if (!isPostCode(frm.ordPostalCode.value, $('ordCountry').value))
	{

		showError(frm,"Please input postcode. Postcode is invalid.","error",frm.ordPostalCode);

		frm.ordPostalCode.focus();

		return;

	}

	

	//shipping

	if (trim($('shipName').value) == "")
	{
		showError(frm,"Please input first name.","error",frm.shipName);
		frm.shipName.focus();

		return;

	}	
	
	if (trim($('shipLastName').value) == "")
	{
		showError(frm,"Please input last name.","error",frm.shipLastName);
		frm.shipLastName.focus();

		return;

	}	

	

	if (!isEmail(trim(frm.shipEmailAddress.value)))
	{
		showError(frm,"Email is invalid. Please input again.","error",frm.shipEmailAddress);
		frm.shipEmailAddress.focus();

		return;
	}	

	

	if (!isPhone(frm.shipPhoneNumber.value))
	{
		showError(frm,"Phone number is invalid. Please input again","error",frm.shipPhoneNumber);
		frm.shipPhoneNumber.focus();

		return;
	}

	

	if (trim(frm.shipAddress1.value)=="")
	{
		showError(frm,"Please input billing address.","error",frm.shipAddress1);
		frm.shipAddress1.focus();

		return;
	}

	

	if ($('shipCountry').value == '-1')
	{
		showError(frm,"Please select country.","error",frm.shipCountry);
		frm.shipCountry.focus();

		return;
	}

	

	if (trim(frm.shipCity.value)=="")
	{
		showError(frm,"Please input city.","error",frm.shipCity);
		frm.shipCity.focus();

		return;
	}

	

	if ($('shipProvince').value == '-1')
	{
		showError(frm,"Please select province.","error",frm.shipProvince);
		frm.shipProvince.focus();

		return;
	}

	str = frm.shipPostalCode.value;
	frm.shipPostalCode.value = str.replace(/ /g, '');

	if (!isPostCode(frm.shipPostalCode.value, $('shipCountry').value))
	{
		showError(frm,"Please input postcode. Postcode is invalid.","error",frm.shipPostalCode);
		frm.shipPostalCode.focus();

		return;
	}
	
	if ($('shipCountry').value == 'CA')
	{
		url = web_path+'validate_postcode.php?country=CA&state='+$('shipProvince').value+'&city='+$('shipCity').value+'&code='+$('shipPostalCode').value;
		var myAjax = new Ajax(url, {method: 'get', onComplete : postShipping});
		myAjax.request();	
	}
	else
		frm.submit();	

}

function postShipping(response)
{
	fo = $('contactForm');
	if (response == 'correct')
	{
		fo.submit();
	}
	else
	{		
		showError(fo,"The address is invalid for the postcode. Please check again.","error",fo.shipPostalCode);
		$('contactForm').shipPostalCode.focus();
	}
}



function checkStep2(frm)
{		
	if (document.getElementById('email_to'))
	{
		if (!isEmail(trim($('email_to').value)))
		{
			showError($('email_form'),"Please input email.","error",$('email_to'));
			$('email_to').focus();
			return;
		}
		
		frm.gift_email_to.value = $('email_to').value;
	}

	if (document.getElementById('country_delivery0'))
	{
		var found_it = false;
		if (document.contactForm.country_delivery.checked)
			found_it = true;
		else
		{
			for (var i=0; i<document.contactForm.country_delivery.length; i++)  		
				if (document.contactForm.country_delivery[i].checked)  
				{		
					found_it = true;
					break;
				}		
		}
	
		if (found_it == false)
		{
			alert('Please select a shipping method.');
			return;
		}
	}
	
	frm.submit();

}


function goProcessCard(frm)
{		
	
	var amount_total = parseFloat($('trnAmount').value);
	if (amount_total != 0) 
	{		
		if ($('paymentMethod').value == 'CC')
		{
			if (trim($('trnCardOwner').value) == "")
			{	
				showError(frm,"Please input your name on the card.","error",frm.trnCardOwner);	
				frm.trnCardOwner.focus();	
				return;	
			}
					
			if (trim($('trnCardNumber').value) == "")	
			{	
				showError(frm,"Please input card number.","error",frm.trnCardNumber);
				frm.trnCardNumber.focus();
				return;
			}
					
			if (trim($('trnExpYear').value) == "")	
			{
				showError(frm,"Please input two last number of expiry year.","error",frm.trnExpYear);
				frm.trnExpYear.focus();
				return;
			}
	
			if (trim($('trnCardCvd').value) == "")	
			{
				showError(frm,"Please input card CVV.","error",frm.trnCardCvd);	
				frm.trnCardCvd.focus();	
				return;	
			}			
		}
	}


/*
	url_post = "https://www.beanstream.com/scripts/process_transaction.asp?" + frm.toQueryString();

	if ($('paymentMethod').value == 'IO')

		url_post = url_post + "&paymentMethod=IO";

	//alert(url_post);

	frm.action = url_post;

	//alert(url_post);

	

	frm.submit();

*/	

	//postCheckout();
/*
	$('contactForm').action = "?nav1=checkout";

	$('contactForm').send();
*/

	url = web_path+'checkout/keep/';

	var myAjax = new Ajax(url, {method: 'get', onComplete : postCheckout});

	myAjax.request();		

	

}



function postCheckout(response)
{
	if (response.indexOf('empty') != -1)
	{
		alert('Your shopping cart is empty.\n Please click ok to return product page.');
		window.location = web_path+'product-list/wall-tattoos/10/';
		return;
	}
	else if (response.indexOf('processing') != -1 && $('paymentMethod').value != 'IO')
	{
		alert('There is another transaction that is processing.\n The system process one transaction at a time.');
		return;
	}
	frm = $('contactFormFinal');
	
	var strtmp1 = $('ordName').value;
	var strtmp2 = $('shipName').value;
	$('ordName').value = $('ordName').value + ' ' + $('ordLastName').value;
	$('shipName').value = $('shipName').value + ' ' + $('shipLastName').value;
	
	url_post = "https://www.beanstream.com/scripts/process_transaction.asp?" + frm.toQueryString();

	if ($('paymentMethod').value == 'IO')
		url_post = url_post + "&paymentMethod=IO";
		
	$('post_url').value = url_post;
	
	$('ordName').value = strtmp1;
	$('shipName').value = strtmp2;
	
	/*var amount_total = parseFloat($('trnAmount').value);
	if (amount_total == 0) 
	{		
		url_post = "payment_approved.php";
	}
	else
	{
		url_post = "https://www.beanstream.com/scripts/process_transaction.asp?" + frm.toQueryString();

		if ($('paymentMethod').value == 'IO')
			url_post = url_post + "&paymentMethod=IO";
	
		//alert(url_post);			
	}

	frm.action = url_post;
	alert('This is a demo version from Sofresh.');
	return;*/

	frm.submit();
}


function goProcessInteract(frm)
{				
	if (trim(frm.ordName.value) == "")
	{	
		alert("Please input your name on the card.");	
		frm.ordName.focus();	
		return;	
	}					
	
	/*if (!isEmail(trim(frm.ordEmailAddress.value)))
	{
		alert("Email is invalid. Please input again.");	
		frm.ordEmailAddress.focus();
		return;
	}*/	

	
	if (!isPhone(frm.ordPhoneNumber.value))
	{
		alert("Phone number is invalid. Please input again");
		frm.ordPhoneNumber.focus();
		return;
	}

	
	if (trim(frm.ordAddress1.value)=="")
	{
		alert("Please input billing address.");
		frm.ordAddress1.focus();
		return;
	}

	if ($('ordCountry').value == '-1')
	{
		alert("Please select country.");
		frm.ordCountry.focus();
		return;
	}

	
	if (trim(frm.ordCity.value)=="")
	{
		alert("Please input city.");
		frm.ordCity.focus();
		return;
	}
	
	if ($('ordProvince').value == '-1')
	{
		alert("Please select province.");
		frm.ordProvince.focus();
		return;
	}

	var str = frm.ordPostalCode.value;
	frm.ordPostalCode.value = str.replace(/ /g, '');

	if (!isPostCode(frm.ordPostalCode.value, $('ordCountry').value))
	{
		alert("Please input postcode. Postcode is invalid.");
		frm.ordPostalCode.focus();
		return;
	}
		
			
	if (trim(frm.product_name.value) == "")
	{	
		alert("Please input product name.");	
		frm.product_name.focus();	
		return;	
	}
	
	if (!isNumber(frm.amount.value))
	{
		alert("Amount is invalid. Please input again.");	
		frm.amount.focus();
		return;
	}
	
	url_post = "https://www.beanstream.com/scripts/process_transaction.asp?" + frm.toQueryString();
	url_post = url_post + "&paymentMethod=IO";		
	$('post_url').value = url_post;
	
	frm.submit();
}

function goProcessCardDebit(frm)
{				
	if (trim(frm.ordName.value) == "")
	{	
		alert("Please input your name on the card.");	
		frm.ordName.focus();	
		return;	
	}					
	
	/*if (!isEmail(trim(frm.ordEmailAddress.value)))
	{
		alert("Email is invalid. Please input again.");	
		frm.ordEmailAddress.focus();
		return;
	}*/	

	
	if (!isPhone(frm.ordPhoneNumber.value))
	{
		alert("Phone number is invalid. Please input again");
		frm.ordPhoneNumber.focus();
		return;
	}

	
	if (trim(frm.ordAddress1.value)=="")
	{
		alert("Please input billing address.");
		frm.ordAddress1.focus();
		return;
	}

	if ($('ordCountry').value == '-1')
	{
		alert("Please select country.");
		frm.ordCountry.focus();
		return;
	}

	
	if (trim(frm.ordCity.value)=="")
	{
		alert("Please input city.");
		frm.ordCity.focus();
		return;
	}
	
	if ($('ordProvince').value == '-1')
	{
		alert("Please select province.");
		frm.ordProvince.focus();
		return;
	}

	var str = frm.ordPostalCode.value;
	frm.ordPostalCode.value = str.replace(/ /g, '');

	if (!isPostCode(frm.ordPostalCode.value, $('ordCountry').value))
	{
		alert("Please input postcode. Postcode is invalid.");
		frm.ordPostalCode.focus();
		return;
	}
		
			
	if (trim(frm.product_name.value) == "")
	{	
		alert("Please input product name.");	
		frm.product_name.focus();	
		return;	
	}
	
	if (!isNumber(frm.amount.value))
	{
		alert("Amount is invalid. Please input again.");	
		frm.amount.focus();
		return;
	}
	
	if (trim($('trnCardOwner').value) == "")
	{	
		alert("Please input your name on the card.");	
		frm.trnCardOwner.focus();	
		return;	
	}
			
	if (trim($('trnCardNumber').value) == "")	
	{	
		alert("Please input card number.");
		frm.trnCardNumber.focus();
		return;
	}
			
	if (trim($('trnExpYear').value) == "")	
	{
		alert("Please input two last number of expiry year.");
		frm.trnExpYear.focus();
		return;
	}

	if (trim($('trnCardCvd').value) == "")	
	{
		alert("Please input card CVV.");	
		frm.trnCardCvd.focus();	
		return;	
	}			
	
	url_post = "https://www.beanstream.com/scripts/process_transaction.asp?" + frm.toQueryString();
	$('post_url').value = url_post;
	
	frm.submit();
}


function goProcessTrade(frm)
{				
	if (trim(frm.ordName.value) == "")
	{	
		alert("Please input your name.");	
		frm.ordName.focus();	
		return false;	
	}					
	
	/*if (!isEmail(trim(frm.ordEmailAddress.value)))
	{
		alert("Email is invalid. Please input again.");	
		frm.ordEmailAddress.focus();
		return false;
	}	*/

	var cost = parseFloat(frm.cost.value);		
			
	if (totalOfProduct == 0 && cost <= 0)
	{	
		alert("Please choose at least a product.");	
		return false;	
	}
	
	if (trim(frm.trnCardOwner.value) == "")
	{	
		alert("Please input your name on the card.");	
		frm.trnCardOwner.focus();	
		return false;	
	}
			
	if (trim(frm.trnCardNumber.value) == "")	
	{	
		alert("Please input card number.");
		frm.trnCardNumber.focus();
		return false;
	}
			
	if (trim(frm.trnExpYear.value) == "")	
	{
		alert("Please input two last number of expiry year.");
		frm.trnExpYear.focus();
		return false;
	}

	if (trim(frm.trnCardCvd.value) == "")	
	{
		alert("Please input card CVV.");	
		frm.trnCardCvd.focus();	
		return false;	
	}			
				
	return true;
}

function goProcessTradeInteract(frm, type)
{				
	if (trim(frm.ordName.value) == "")
	{	
		alert("Please input your name.");	
		frm.ordName.focus();	
		return;	
	}					
	
	/*if (!isEmail(trim(frm.ordEmailAddress.value)))
	{
		alert("Email is invalid. Please input again.");	
		frm.ordEmailAddress.focus();
		return;
	}	*/
			
	var cost = parseFloat(frm.cost.value);		
			
	if (totalOfProduct == 0 && cost <= 0)
	{	
		alert("Please choose at least a product.");	
		return;	
	}	
	
	if (type == 'cash')
	{
		if (trim(frm.code.value) == "")
		{
			alert("Please input authorization code.");	
			frm.code.focus();
			return;
		}	
		
		$.post('tradeshow.php', { "code": frm.code.value, "action" : "authorize"}, 
			   									function(data) 
												{ 
														if (data.indexOf("authorized") != -1)
														{
															document.form1.submit();
														}
														else
														{
															alert('Authoriazion code is not correct.');
															frm.code.focus();
															return;
														}
												});
		
		return;
	}
	document.form1.submit();
}


function checkSendEmail()
{
	frm = $('contactForm');

	if (trim($('yourname').value) == "")
	{
		showError(frm,"Please input your name.","error",$('yourname'));
		$('yourname').focus();
		return;
	}

	if (trim($('youremail').value) == "")
	{
		showError(frm,"Please input your email.","error",$('youremail'));
		$('youremail').focus();
		return;
	}

	var has_value = 0;
	for (var i=1; i<=3; i++)
	{
		if (trim($('contactName'+i).value) != "")
		{
			has_value = 1;
			break;
		}

		if (isEmail($('contactEmail'+i).value))
		{
			has_value = 1;
			break;			
		}
	}

	if (has_value == 0)
	{
		showError(frm,"Please input at least one friend information.","error",frm.contactName1);
		$('contactName1').focus();

		return;
	}

	
	for (var i=1; i<=3; i++)
	{
		if (trim($('contactName'+i).value) != "" && !isEmail($('contactEmail'+i).value))
		{

			showError(frm,"Email is invalid.","error",$('contactEmail'+i));

			$('contactEmail'+i).focus();

			return;

		}

		else	if (trim($('contactName'+i).value) == "" && isEmail($('contactEmail'+i).value))

		{

			showError(frm,"Please input your friend's name.","error",$('contactName'+i));

			$('contactName'+i).focus();

			return;		

		}

	}

	

	if (trim($('sendMessage').value) == "")

	{

		showError(frm,"Please input your message to your friend.","error",$('sendMessage'));

		$('sendMessage').focus();

		return;		

	}



		

	$('contactForm').submit();

}



function changePayment()

{

	if ($('paymentMethod').value == 'IO')

	{

		$('trnCardOwner').disabled = true;

		$('trnCardNumber').disabled = true;

		$('trnExpMonth').disabled = true;

		$('trnExpYear').disabled = true;

		$('trnCardCvd').disabled = true;

	}

	else

	{

		$('trnCardOwner').disabled = false;

		$('trnCardNumber').disabled = false;
		
		$('trnExpMonth').disabled = false;

		$('trnExpYear').disabled = false;

		$('trnCardCvd').disabled = false;

	}

}



function copyInfo()
{
	if ($('same_billing').checked == true)
	{

		$('shipName').value = $('ordName').value;
		$('shipLastName').value = $('ordLastName').value;
		$('shipEmailAddress').value = $('ordEmailAddress').value;
		$('shipPhoneNumber').value = $('ordPhoneNumber').value;
		$('shipAddress1').value = $('ordAddress1').value;
		$('shipAddress2').value = $('ordAddress2').value;	
		$('shipCountry').selectedIndex = $('ordCountry').selectedIndex;
		changeCountry($('shipProvince'),$('shipCountry').value)
		$('shipProvince').selectedIndex = $('ordProvince').selectedIndex;
		$('shipCity').value = $('ordCity').value;
		$('shipPostalCode').value = $('ordPostalCode').value;
		$('shipCompany').value = $('ordCompany').value;
	}
}



function copyField(obj1, obj2, type)

{

	if ($('same_billing').checked == true && type == 'text')

	{

		obj2.value = obj1.value;

	}

	if ($('same_billing').checked == true && type == 'select')

	{

		obj2.selectedIndex = obj1.selectedIndex;

		if (obj2.name == 'shipCountry')

			changeCountry($('shipProvince'),$('shipCountry').value);

	}

}



function changeCountry(obj_select, country_code)

{

	if (country_code=='US')

	{

		var arrStateCode = Array('-1','AK','AL','AS','AR','AZ','CA','CO','CT','DC','DE','FL','GA','GU','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','FM','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','PR','RI','SC','SD','TN','TX','UT','VA','VI','VT','WA','WI','WV','WY');

		var arrStateName = Array('please choose','Alaska','Alabama','American Samoa','Arkansas','Arizona','California','Colorado','Connecticut','District of Columbia','Delaware','Florida','Georgia','Guam','Hawaii','Iowa','Idaho','Illinois','Indiana','Kansas','Kentucky','Louisiana','Massachusetts','Maryland','Maine','Michigan','Micronesia','Minnesota','Missouri','Mississippi','Montana','North Carolina','North Dakota','Nebraska','New Hampshire','New Jersey','New Mexico','Nevada','New York','Ohio','Oklahoma','Oregon','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Virginia','Virgin Islands','Vermont','Washington','Wisconsin','West Virginia','Wyoming');

	}

	else if (country_code=='CA')

	{

		var arrStateCode = Array('-1','AB','BC','MB','NB','NL','NS','NT','NU','ON','PE','QC','SK','YT');

		var arrStateName = Array('please choose','Alberta','British Columbia','Manitoba','New Brunswick','Newfoundland','Nova Scotia','Northwest Territories','Nunavut','Ontario','Prince Edward Island','Quebec','Saskatchewan','Yukon');

	}

	else

	{

		var arrStateCode = Array('-1','--');

		var arrStateName = Array('please choose','Outside U.S./Canada');

	}

	

	while (obj_select.options.length > 0) 

	{

		obj_select.options[(obj_select.options.length - 1)] = null;

	}

	

	for (var i=1; i <= arrStateCode.length; i++) 

	{

		var option = new Option(arrStateName[i-1],arrStateCode[i-1]);

		obj_select.options[i-1]=option;

	}

}