var country='';
var scountry='';
var usstates= new Array('AE','AA','AP','AL','AK','AS','AZ','AR','CA','CO','CT','DE','DC','FM','FL','GA','GU','HI','ID','IL','IN','IA','KS','KY','LA','ME','MH','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','MP','OH','OK','OR','PW','PA','PR','RI','SC','SD','TN','TX','UT','VT','VI','VA','WA','WV','WI','WY');
var castates= new Array('AB','BC','MB','NB','NL','NT','NS','NU','ON','PE','QC','SK','YT');

var htm="http://www.customizedgirl.com/";
var url='/cgi-bin/main.cgi';

sfHover = function() {
	if(menu==1){
   var sfEls = document.getElementById('nav').getElementsByTagName("LI");
   for (var i = 0; i < sfEls.length; i++) {
      sfEls[i].onmouseover = function() {
         this.className += " sfhover";
      }
      sfEls[i].onmouseout = function() {
         this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
      }
   }
	}
}
if (window.attachEvent) {
	window.attachEvent("onload", sfHover);
}

function pop_map(){
        var mapups="/templates/map_popup.htm"
        winpops=window.open(mapups,"","width=700,height=400,z-index=10,scrollbars=1")
        winpops.focus();
        }

function apply_tax() {
var state='';
var grand=0;

	country=document.checkout.BillTo_Country.options[document.checkout.BillTo_Country.selectedIndex].value;
	salestax=0;
	if(country == 'United States') {
	  state=usstates[document.checkout.BillTo_State.selectedIndex-1];
	  if(state == 'OH') {
	    salestax=Math.round((subtotal-gcsubtotal)* 6.75)/100;
	  }
	}

        document.getElementById('tax_field').innerHTML = "\$"+salestax;
	grand=Math.round((subtotal-repdiscount+delivery+salestax-GCtotal)*100)/100;
        document.getElementById('grand_field').innerHTML = "\$"+grand;
}

function use_textfield_bill() {
	document.getElementById('bill_state').innerHTML = "<label for='BillTo_State'>State:<span class='redstar'>*</span></label><input name='BillTo_State' type='text' size='30'  maxlength='64' value='' />";
}
function use_dropdown_bill() {
	document.getElementById('bill_state').innerHTML = "<label for='BillTo_State'>State:<span class='redstar'>*</span></label><select name='BillTo_State' size='1' onChange=\"javascript:apply_tax();\"><option selected='selected' value=''> </option></select>";
}

function switch_billstates() {
var m;
	country=document.checkout.BillTo_Country.options[document.checkout.BillTo_Country.selectedIndex].value;
if(country == 'United States') {
	use_dropdown_bill();
       	document.checkout.BillTo_State.options.length=usstates.length+1;
        document.checkout.BillTo_State.options[0]=new Option('');
	for(m=0;m<usstates.length;m++) {
            document.checkout.BillTo_State.options[m+1]=new Option(usstates[m]);
	}
        document.checkout.BillTo_State.selectedIndex=0;

	if(document.checkout.same_address[0].checked==1) {
		use_domestic();
	}
} else {
  if(country == 'Canada') {
	use_dropdown_bill();
       	document.checkout.BillTo_State.options.length=castates.length+1;
        document.checkout.BillTo_State.options[0]=new Option('');
	for(m=0;m<castates.length;m++) {
            document.checkout.BillTo_State.options[m+1]=new Option(castates[m]);
	}
        document.checkout.BillTo_State.selectedIndex=0;
  } else {
	use_textfield_bill();
  }

	if(document.checkout.same_address[0].checked==1) {
		use_international();
	}
}

apply_tax();
}

function use_textfield_ship() {
	document.getElementById('ship_state').innerHTML = "<label for='ShipTo_State'>State:<span class='redstar'>*</span></label><input name='ShipTo_State' type='text' size='30'  maxlength='64' value='' />";
}
function use_dropdown_ship() {
	document.getElementById('ship_state').innerHTML = "<label for='ShipTo_State'>State:<span class='redstar'>*</span></label><select name='ShipTo_State' size='1'><option value=''> </option></select>";
}

function switch_shipstates() {
var m;
	scountry=document.checkout.ShipTo_Country.options[document.checkout.ShipTo_Country.selectedIndex].value;
	if(scountry == 'United States') {
	use_dropdown_ship();
       	document.checkout.ShipTo_State.options.length=usstates.length+1;
        document.checkout.ShipTo_State.options[0]=new Option('');
	for(m=0;m<usstates.length;m++) {
            document.checkout.ShipTo_State.options[m+1]=new Option(usstates[m]);
	}
        document.checkout.ShipTo_State.selectedIndex=0;

		use_domestic();
	} else {
	if(scountry == 'Canada') {
	use_dropdown_ship();
       	document.checkout.ShipTo_State.options.length=castates.length+1;
        document.checkout.ShipTo_State.options[0]=new Option('');
	for(m=0;m<castates.length;m++) {
            document.checkout.ShipTo_State.options[m+1]=new Option(castates[m]);
	}
        document.checkout.ShipTo_State.selectedIndex=0;
	} else {
		use_textfield_ship();
	}

		use_international();
	}
}

function change_delivery(op,intl) {
var fee;
var grand;

fee=0;
if(subtotal - gcsubtotal > 0) {
if(intl == '0') {
	if(op == '0') {
		if(subtotal < 50) {
			fee=5.95;
		}
	} else if(op == '1') {
	  	fee=7.95;
	} else if(op == '2') {
		fee=20;
		if(subtotal - gcsubtotal > 100) {
			fee=Math.round((subtotal - gcsubtotal) * 20)/100;
		}
	} else if(op == '3') {
		fee=40;
		if(subtotal - gcsubtotal > 100) {
			fee=Math.round((subtotal - gcsubtotal) * 40)/100;
		}
	}
} else {
	if(op == '0') {
		fee=15.95;
	} else if(op == '1') {
	  	fee=24.95;
	} else if(op == '2') {
		fee=39.95;
	}
}
}

	delivery=fee;
	if(fee !=0 ){
		document.getElementById('delivery_field').innerHTML = "\$"+fee+"<input type='hidden' name='delivery_fee' id='delivery_fee' value='"+fee+"'";
	} else {
		document.getElementById('delivery_field').innerHTML = "FREE <input type='hidden' name='delivery_fee' id='delivery_fee' value='"+fee+"'";
	}
	grand=Math.round((subtotal-repdiscount+fee+salestax-GCtotal)*100)/100;
	document.getElementById('grand_field').innerHTML = "$"+grand;
}

function use_domestic() {
	var str=" ";
	var delivery_option= new Array("<b>Economy</b> (9 business days) - \$5.95 or FREE over \$50", "<b>Standard</b> (7 business days) - \$7.95", "<b>Rush</b> (5 business days) - \$20 or 20\% of orders over \$100", "<b>Priority</b> (3 business days) - \$40 or 40\% of orders over \$100");
	var checked= new Array(" ", " checked='checked' ", " "," ");

	for(i=0; i<4; i++) {
		if(i+special_delivery<4) {
			str = str + "<div class='deloptstr'><input type='radio' name='Delivery' value='" + i + "' " + checked[i]  + " onClick=\"javascript:change_delivery('" + i + "',0 );\">";
			str += delivery_option[i];
			str += "</div>";
		}
	}
	if(subtotal >= 100) {
		str +="<p>All FEDEX packages over \$100 require a signature upon delivery. If you would like to waive this policy, please click here:<input name='waive_sig' type='checkbox' value='waive' />";
	}

	document.getElementById('delivery_options').innerHTML = str;
	change_delivery('1','0');
}

function use_international() {
	var str='';
	var delivery_option= new Array("10 business days - \$15.95", "8 business days - \$24.95", "5 business days - \$39.95");
	var checked= new Array(" checked='checked' ", " ", " "," ");
	for(i=0; i<3; i++) {
		if(i+special_delivery<4) {
			str = str + "<div class='deloptstr'><input type='radio' name='Delivery' value='" + i + "' " + checked[i]  + " onClick=\"javascript:change_delivery('" + i + "', 1);\">";
			str += delivery_option[i];
			str += "</div>";
		}
	}
	document.getElementById('delivery_options').innerHTML = str;
	change_delivery('0','1');
}

function sameaddress(flag){
	var country='';
	if(flag==1){
		document.getElementById('shippingaddress').style.display =  'none';
		country=document.checkout.BillTo_Country.options[document.checkout.BillTo_Country.selectedIndex].value;
	}else{
		document.getElementById('shippingaddress').style.display =  'block';
		country=document.checkout.ShipTo_Country.options[document.checkout.ShipTo_Country.selectedIndex].value;
	}
	if(country == 'United States') {
		use_domestic();
	} else {
		use_international();
	}
}
function change_same_address() {

	country=document.forms[1].BillTo_Country.options[document.forms[1].BillTo_Country.selectedIndex].value;
	scountry=document.forms[1].ShipTo_Country.options[document.forms[1].ShipTo_Country.selectedIndex].value;

	if(document.forms[1].same_address.checked) {
		if(country == 'United States') {
			use_domestic();
		} else {
			use_international();
		}
	} else {
		if(scountry == 'United States') {
			use_domestic();
		} else {
			use_international();
		}
	}
}

function pop_cardcode(){

winpops=window.open("","","width=600,height=300,z-index=10");
winpops.document.writeln("<html><head><title>What Is The Card Code</title></head><body bgcolor='#FFFFFF'><font size=2 face=Verdana><b>What is the Card Code</b><br><br>Visa calls this code Card Verification Value (CVV); MasterCard calls it Card Validation Code (CVC); Discover calls it a Card IDentification (CID) number. Here we use Card Code to refer to it.<br>Card code is the last 3 digits on the Signature Panel on the back of the card.</font><br><br><img src=/images/site/cardcode.jpg>");

winpops.document.writeln("</body></html>");
winpops.document.close();
winpops.focus();
}
function cm_mode(f) {
var t=document.forms[1].cm_m.options[document.forms[1].cm_m.selectedIndex].value;
if(f == 'cm') {
	window.location.href=htm+"gallery/bypopular/"+t;
} else {
	window.location.href=htm+"mygallery/bypopular/"+t;
}
}
function cm_item(f) {
var i=document.forms[1].cm_i.options[document.forms[1].cm_i.selectedIndex].value;
if(f == 'cm') {
	window.location.href=htm+"gallery/byitem/"+i;
} else {
	window.location.href=htm+"mygallery/byitem/"+i;
}
}
function cm_display(f) {
var d=document.forms[1].cm_d.options[document.forms[1].cm_d.selectedIndex].value;
if(f == 'cm') {
	window.location.href=htm+"gallery/perpage/"+d;
} else {
	window.location.href=htm+"mygallery/perpage/"+d;
}
}
function show_post(sid,did,pn,nid) {
  var httpurl=htm+"index.htm";
  var myspacer="/a/images/myspacer.gif";
  var nstr="";
  if(nid == 1){
    nstr="<tr><td></td><td align='left'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='122' height='42' id='showstring2007b2' align='middle'> <param name='allowScriptAccess' value='sameDomain' /> <param name='movie' value='/swf/showstring2007b2.swf?sid="+sid+"' /> <param name='quality' value='high' /> <param name='bgcolor' value='#ffffff' /> <param name='wmode' value='opaque' /> <embed src='/swf/showstring2007b2.swf?sid="+sid+"' quality='high' bgcolor='#ffffff' wmode='opaque' width='122' height='42' name='showstring2007b2' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' /> </object></td></tr> <tr><td></td><td><div class='greys'>Enter number shown above:&nbsp;<input type='text' name='post_ssid' size=6 maxlength=6></div></td></tr>";
  }
  document.getElementById('postacomment').innerHTML="<form method='post' action='"+httpurl+"'><INPUT TYPE = 'hidden' NAME = 'did' VALUE = '"+did+"'><table border=0 width='100%'><tr><td align='right'><div class='greys'>name:&nbsp;</div></td><td align='left'><input type='text' name='post_name' size=16 maxlength=64 value='"+pn+"'></td></tr> <tr><td align='right'><div class='greys'>comment:</div></td><td align='left'><textarea name='post_comment' rows=5 cols=32></textarea></td></tr>"+nstr+"<tr><td colspan=2><div><img src='"+myspacer+"' width='390' height='10' alt='' /></div></td></tr> <tr><td colspan=2 align='center'><input type='submit' name='post_btn' value='Post'></td></tr></table> </form>";
}
function pop_tag(){
winpops=window.open("","","width=600,height=300,z-index=10");
winpops.document.writeln("<html><head><title>What Is Tag</title></head><body bgcolor='#FFFFFF'><font size=2 face=Verdana>Tags help you share your designs while also allowing you to navigate and explore designs from the community.  Does your design make a funny joke about Paris Hilton? Then you might want to tag it: \"funny, paris hilton, celebrity, joke, etc.\".  Is your design a more personal tribute to your boyfriend that you think might be less relevant to the comunity? Then just tag it \"personlaized\".  Easy as that!</font>");
winpops.document.writeln("</body></html>");
winpops.document.close();
winpops.focus();
}
function checkEnter(e){
var charCode;
if(e && e.which) {
	e=e;
	charCode=e.which;
} else {
	e=event;
	charCode=e.keyCode;
}
if(charCode == 13) {
	document.forms[0].submit();
	return false;
} else {
	return true;
}
}

function xmlhttpPost(flag,ip,sz) {
	var xmlHttpReq = false;
	var sendstr=getquerystring(flag,ip,sz);
	if(sendstr == "") return;
	if(flag == 'remove') {
		if( !confirm('Are you sure you want to remove this item? You might lose your design for this item if not saved')) return;
	}
	
	
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', url, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
			if (self.xmlHttpReq.readyState == 4) {
					updatepage(self.xmlHttpReq.responseText);
			}
	}
	self.xmlHttpReq.send(sendstr);
}

function getquerystring(flag, arg1, arg2) {
	var str="";
	var strhead="ajax=1";
	var ip=arg1;
	var sz=arg2;
	if(flag == 'promo')
	{
		var id=document.getElementById('repid').value;
		str = strhead + '&repid='+escape(id);
	} else if(flag == 'quant_all') {
		str = strhead + "&updatep="+ip;
		var cnt=0;
		var ids=document.getElementsByName('cart_quan_'+ip);
		var tmpcnt=0;
		for(var i=0; i<ids.length;i++){
			tmpcnt=isNumeric(ids[i], "Please enter a numeric number");
			if(tmpcnt != -1) {
				cnt += tmpcnt;
				str += "&"+ids[i].id+"="+ ids[i].value;
			} else {return '';}
		}
		if(cnt == 0) {
			if(confirm("The quantity for this item is 0. Are you sure you want to remove this item? You might lose this design if not saved\n")){
				str = strhead + "&remove="+ip;
			}
			else str='';
		}
	} else if(flag == 'quant') {
		var eid=document.getElementById('cart_quan_'+ip+'_'+sz);
		if(isNumeric(eid, "Please enter a numeric number")){
			var cnt=document.getElementById(eid).value;
			if(cnt >=0) {
				str = strhead + "&updatep="+ ip + "&sz=" + sz +"&q=" + cnt;
				return str;
			}
		}
	} else if(flag == 'remove') {
		str = strhead + "&remove=" + ip;
	}	else if(flag == 'email') {
		str = strhead + "&e=" + arg1 + "&p=" + arg2;
	}

	return str;
}

function updatepage(str){
	var key=str.split('=');
	
	if(key[0] == "repid") {
		var values=key[1].split(';');
		set_discount(values[0]);
		document.getElementById('gtotal').innerHTML =  values[1];
	}else if(key[0] == "quant" || key[0] == "remove") {
		var values=key[1].split(';');
		var ip=values[0];
		if(ip!='-1') {
			document.getElementById('sub'+ip).innerHTML = "\$"+values[1];
			document.getElementById('subtotalfield').innerHTML = "\$"+values[2];
		}
		if(values[1]>=50 || values[3]=='0') {
			document.getElementById('freeshipid').style.display='none';
			document.getElementById('shipfeeid').innerHTML = 'FREE';
		} else {
			var less=(50.00-values[2]+(1.0*values[4])).toFixed(2);
			document.getElementById('freeshipid').innerHTML = "FREE shipping on U.S. orders over \$50! <span class='blackbold'>$" + less + "</span> to free shipping.";
			document.getElementById('shipfeeid').innerHTML = "\$5.95";
			document.getElementById('freeshipid').style.display='block';
		}
		set_discount(values[4]);
		document.getElementById('gtotal').innerHTML = values[5];
		if(key[0] == "remove") {
			var eid='purchase' + ip;
			document.getElementById(eid).style.display='none';
		}
		document.getElementById('itemcnt').innerHTML = values[6] + " items";
	}else if(key[0] == "e") {
		document.getElementById('mycontainer').innerHTML = "<h2 class='mycenter'>Empty Cart</h2><div class='mycenter'><a href=" + htm + "><img src='/a/images/ContinueShopping.jpg' border==0></a></div>"
		document.getElementById('itemcnt').innerHTML = "0 item";
	}else if(key[0] == "a") {
		if(key[1]==0){
			document.getElementById('newemailerr').innerHTML = "The email address already existed in our database with a different password.<br>Please re-enter your password or enter a new email address";
		}
	} 
	return true;
}

function formvalid()
{
	var rtn= checkNewEmail() + checkPayment() + checkShipping() + checkBilling();
	if(rtn==0) return true;
	else return false;
}

function checkBilling()
{
	var errMsg='';
	var billingfname = document.checkout.BillTo_First_Name;
	errMsg += checkErr(billingfname,0,"Billing First Name");
	var billinglname = document.checkout.BillTo_Last_Name;
	errMsg += checkErr(billinglname,0,"Billing Last Name");
	var billingst1 = document.checkout.BillTo_Street_Line1;
	errMsg += checkErr(billingst1,0,"Billing Address");
	var billingcity = document.checkout.BillTo_City;
	errMsg += checkErr(billingcity,0,"Billing City");
	var billingcountry=document.checkout.BillTo_Country.options[document.checkout.BillTo_Country.selectedIndex].value;
	var billingstate='';
	var  billingstate=document.checkout.BillTo_State;
	if( billingcountry == 'United States' || billingcountry == 'Canada') {
		errMsg += checkErr(billingstate,-1,"Billing State");
	} else {
		errMsg += checkErr(billingstate,0,"Billing State");
	}
	var billingzip = document.checkout.BillTo_Zip;
	errMsg += checkErr(billingzip,'zip',"Billing ZIP Code");
	var phone = document.checkout.Phone_Number;
	errMsg += checkErr(phone,'phone',"Phone Number");
	if ( !( document.checkout.Email_Address_Fb === undefined ) )
	{
		var fbemailaddress = document.checkout.Email_Address_Fb;
		errMsg += checkErr(fbemailaddress,'email',"Email Address");
	}

	if(errMsg != '') {
		document.getElementById('billingerr').innerHTML = "<br>" + errMsg +"<br>Please re-enter it below.";
		document.getElementById('billingerr').scrollIntoView(); 
		document.getElementById('billingbox').style.height='auto'; 
		document.getElementById('billingbox').style.overflow='auto'; 
		return -1;
	} else {
		document.getElementById('billingerr').innerHTML = "";
		return 0;
	}
}

function checkShipping()
{
	var errMsg='';
	if(document.checkout.same_address[1].checked==1) {
		var shipingfname = document.checkout.ShipTo_First_Name;
		errMsg += checkErr(shipingfname,0,"Shipping First Name");
		var shipinglname = document.checkout.ShipTo_Last_Name;
		errMsg += checkErr(shipinglname,0,"Shipping Last Name");
		var shipingst1 = document.checkout.ShipTo_Street_Line1;
		errMsg += checkErr(shipingst1,0,"Shipping Address");
		var shipingcity = document.checkout.ShipTo_City;
		errMsg += checkErr(shipingcity,0,"Shipping City");
		var shipingcountry=document.checkout.ShipTo_Country.options[document.checkout.ShipTo_Country.selectedIndex].value;
		var shipingstate='';
		var shipingstate=document.checkout.ShipTo_State;
		if( shipingcountry == 'United States' || shipingcountry == 'Canada') {
			errMsg += checkErr(shipingstate,-1,"Shipping State");
		} else {
			errMsg += checkErr(shipingstate,0,"Shipping State");
		}
		var shipingzip = document.checkout.ShipTo_Zip;
		errMsg += checkErr(shipingzip,'zip',"Shipping ZIP Code");
	}
	if(errMsg != '') {
		document.getElementById('shippingerr').innerHTML = "<br>" + errMsg +"<br>Please re-enter it below.";
		document.getElementById('shippingerr').scrollIntoView(); 
		return -1;
	} else {
		document.getElementById('shippingerr').innerHTML = "";
		return 0;
	}
}

function checkPayment()
{
	var errMsg='';
	var cardnumber = document.checkout.Payment_Card_Number;
	errMsg += checkErr(cardnumber,2,"Credit Card Number");
	var expmon = document.checkout.Payment_Card_Exp_Month;
	errMsg += checkErr(expmon, -1, "Expire Month");
	var expyr = document.checkout.Payment_Card_Exp_Year;
	errMsg += checkErr(expyr, -1, "Expire Year");
	var cardcode = document.checkout.Payment_Card_Code;
	errMsg += checkErr(cardcode,2,"Credit Card Code", 2);
	
	if(errMsg != '') {
		document.getElementById('paymenterr').innerHTML = "<br>" + errMsg +"<br>Please re-enter it below.";
		document.getElementById('paymenterr').scrollIntoView(); 
		return -1;
	} else {
		document.getElementById('paymenterr').innerHTML = "";
		return 0;
	}
}

function checkNewEmail()
{
	if(new_customer==0) return 0;
	var errMsg='';
	var emailaddress = document.checkout.Email_Address;
	errMsg += checkErr(emailaddress,'email',"Email");
	var emailaddress2 = document.checkout.Email_Address2;
	errMsg += checkErr(emailaddress2,'match',"Email2", emailaddress );
	var password = document.checkout.Password;
	errMsg += checkErr(password,'password',"Password");
	var password2 = document.checkout.Password2;
	errMsg += checkErr(password2,'match',"Password2", password );
	if(errMsg != '') {
		document.getElementById('newemailerr').innerHTML = "<br>" + errMsg +"<br>Please re-enter it below.";
		document.getElementById('newemailerr').scrollIntoView(); 
		return -1;
	} else {
		//xmlhttpPost("email", escape(emailaddress.value), escape(password.value));
		document.getElementById('newemailerr').innerHTML = "";
		return 0;
	}
}

/* flag:-1:select 0:none, 1:letter, 2:number, 3:letter+number, 4:email address, zip, phone, match*/
function checkErr(e, flag, name, match)
{
	var errMsg='';
	var rtn=1;

	if(flag ==-1){
		var idx=e.selectedIndex;
		if(idx==0){
			var errMsg=name+" is empty.<br>";
			rtn=0;
		}
	}else{
		var val=e.value;
		var numericExpression = /^[0-9]+$/;
		var alphaExp = /^[a-zA-Z]+$/;
		val=val.replace(/^\s+/g,""); val=val.replace(/\s+$/g,"");
		if(val.length==0) {
			errMsg=name+" is empty.<br>";
			rtn=0;
		}else if(flag==1) {
			var alphaExp = /^[a-zA-Z]+$/;
			if(!val.match(alphaExp)){
				errMsg = name + " should only contain letters.<br>";
				rtn=0;
			}
		}else if(flag=='match') {
			if(val != match.value){
				errMsg = name + " does not match. <br>";
				rtn=0;
			}
		}else if(flag=='phone') {
			var str=val.replace(/[\(\)\.\-\ ]/g, '');
			if(isNaN(parseInt(str)) || parseInt(str)!=0+str){
				errMsg = name + " contains invalid characters.<br>";
				rtn=0;
			}
		}else if(flag==2) {
			if(!val.match(numericExpression)){
				errMsg = name + " should only contain numbers.<br>";
				rtn=0;
			}else if(val.length<=match){
				errMsg = name + " should contain 3 or 4 digits.<br>";
				rtn=0;
			} 
		}else if(flag=='email'){
			if(valid_email(val)==0){
				errMsg = "Invalid Email Address.<br>";
				rtn=0;
			}
		}else if(flag==3){
			var alphaExp = /^[0-9a-zA-Z]+$/;
			if(val.match(alphaExp)){
				errMsg = name + " should only contain numbers or letters.<br>";
				rtn=0;
			}
		}else if(flag==4){
			var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
			if(val.match(emailExp)){
				errMsg = name + " is not a valid email address.<br>";
				rtn=0;
			}
		}
	}
	if(errMsg != ''){
		e.style.backgroundColor="yellow";
		e.parentNode.className="labelhighLight";
	}else{
		e.style.backgroundColor="white"; 
		e.parentNode.className="labelgrey";
	}
	return errMsg;
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); 
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	var tmpcnt=elem.value;
	tmpcnt=tmpcnt.replace(/^\s+/g,""); tmpcnt=tmpcnt.replace(/\s+$/g,"");
	if(tmpcnt.match(numericExpression)){
		return tmpcnt;
	}else{
		alert(helperMsg);
		elem.value=0;
		elem.focus();
		return -1;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		elem.focus();
		return false;
	}
}
function valid_email(inemail){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(!inemail.match(emailExp)){
    return 0;
  }else {return 1;}
}

function set_discount(val)
{
		if(val==0){
			document.getElementById('promoline').innerHTML = "";
		}else{
			document.getElementById('promoline').innerHTML = "<div class='total_l'>Discount</div><div class='total_r'>-\$" + val +"</div>";
		}
}

function moneyback()
{
	winpops=window.open("","","width=600,height=300,z-index=10");
	winpops.document.writeln("<html><head><title>30 Day Money Back Guarantee</title></head><body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>30 Day Money Back Guarantee</h4><p>We stand behind our products and the custom decoration that goes into each and every item. If we make a mistake with your order, we will replace your items immediately. Please review your design and the product size chart prior to ordering as each order is made individually to your specifications and cannot be resold. For this reason we cannot exchange or refund orders based on size discrepancy or errors made while creating your design. If we have made a mistake with your order please contact one of our customer service representative at <a href='mailto:customizedgirl\@eretailing.com'>customer service</a> or call 1-800-361-8811 within 30 days of receiving your order.<p>Thanks for shopping with us.");

	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}
function whichcountry()
{
	winpops=window.open("","","width=600,height=300,scrollbars=1");
	winpops.document.writeln("<html><head><title>Which countries do we ship to? </title></head>");
	winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>We ship to the following countries:</h4><ul><li>United States<li>Canada<li>Australia<li>Austria<li>Belgium<li>Bermuda<li>China<li>Czech Republic<li>Denmark<li>Dominican Republic<li>Finland<li>France<li>Germany<li>Greece<li>Hong Kong<li>Hungary<li>Ireland<li>Italy<li>Japan<li>Liechtenstein<li>Luxemburg<li>Malaysia<li>Mexico<li>Monaco<li>Netherlands<li>Norway<li>Philippines<li>Portugal<li>Puerto Rico<li>Singapore<li>South Korea<li>Spain<li>Sweden<li>Switzerland<li>United Kingdom</ul>");

	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}
function showdelivery(val)
{
	winpops=window.open("","","width=600,height=300,scrollbars=1");
	if(val==0){
		winpops.document.writeln("<html><head><title>Arrival Estimates in Unites States</title></head>");
		winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>Arrival Estimates in Unites States</h4><ul><li>9 business days  $5.95 or <b>free</b> on orders over $50<li>7 business days  $7.95<li> 5 business days  $20 or 20% of orders over $100<li> 3 business days  $40 or $40% of orders over $100</ul>");
	} else {
		winpops.document.writeln("<html><head><title>Arrival Estimates for International Orders</title></head>");
		winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>Arrival Estimates For International Orders</h4><ul><li>10 business days  $15.95<li> 8 business days  $24.95<li> 5 business days  $39.95</ul>");
	}

	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}
function popup(mylink, windowname)
{
	var win=window.open(mylink,windowname,"width=800,height=400,scrollbars=yes");
	win.focus();
}
function popup2(mylink, windowname)
{
	if(! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
		 href=mylink;
	else
		 href=mylink.href;
	window.open(href, windowname, 'width=800,height=400,scrollbars=yes');
	return false;
}
function show_gc()
{
	if(document.getElementById('gc').checked == false){
		document.getElementById('gc_number').style.display =  'none';
	} else {
		document.getElementById('gc_number').style.display =  'block';
	}
}
function clear_txt(){
  if(document.forms[0].cm_s.value == "Search for a design") {
    document.forms[0].cm_s.value="";
  }
}

