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

sfHover = function() {
   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-repdiscount-bulkdiscount)* 6.75)/100;
	  }
	}

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

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 set_wmonth(cy) {
var wy;
var wyear;
var daysinmonth;

  var wm=document.getElementById('wmonth').selectedIndex;
  var wd=document.getElementById('wday').selectedIndex;
  if( wm > 0 ) {
	wy=document.getElementById('wyear').selectedIndex;
	if(wy <= 0) {
        	document.getElementById('wyear').selectedIndex=1;
		wyear=cy;
	} else {
		wyear=cy+wy-1;
	}

	if(wm == 1 || wm == 3 || wm == 5 || wm == 7 || wm == 8 || wm == 10 || wm == 12) {
		daysinmonth=31;
	} else if(wm == 4 || wm == 6 || wm == 9 || wm == 11) {
		daysinmonth=30;
	} else if(wyear % 4 == 0) {
		daysinmonth=29;
	} else {
		daysinmonth=28;
	}
       	document.getElementById('wday').options.length=daysinmonth+1;
        document.getElementById('wday').options[0]=new Option('Day');
        for (var i = 1; i <= daysinmonth; i++) {
            document.getElementById('wday').options[i]=new Option(i);
        }
	if( wd <= daysinmonth) {
        	document.getElementById('wday').selectedIndex=wd;
	} else {
        	document.getElementById('wday').selectedIndex=0;
	}
  }	
}

function set_wyear(cy) {
  var wm=document.getElementById('wmonth').selectedIndex;
  var wy=document.getElementById('wyear').selectedIndex;
  var wd=document.getElementById('wday').selectedIndex;
  var daysinmonth;
  if( wm > 0 && wy > 0 ) {
	wyear=cy+wy-1;
	if(wm == 1 || wm == 3 || wm == 5 || wm == 7 || wm == 8 || wm == 10 || wm == 12) {
		daysinmonth=31;
	} else if(wm == 4 || wm == 6 || wm == 9 || wm == 11) {
		daysinmonth=30;
	} else if(wyear % 4 == 0) {
		daysinmonth=29;
	} else {
		daysinmonth=28;
	}
       	document.getElementById('wday').options.length=daysinmonth+1;
        document.getElementById('wday').options[0]=new Option('Day');
        for (var i = 1; i <= daysinmonth; i++) {
            document.getElementById('wday').options[i]=new Option(i);
        }
	if( wd <= daysinmonth) {
        	document.getElementById('wday').selectedIndex=wd;
	} else {
        	document.getElementById('wday').selectedIndex=0;
	}
  }	
}

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 - repdiscount - bulkdiscount < 50) {
			fee=5.95;
		}
	} else if(op == '1') {
	  	fee=8.95;
	} else if(op == '2') {
		fee=19.95;
		if(subtotal - gcsubtotal > 100) {
			fee=Math.round((subtotal - gcsubtotal) * 20)/100;
		}
	} else if(op == '3') {
		fee=29.95;
		if(subtotal - gcsubtotal > 100) {
			fee=Math.round((subtotal - gcsubtotal) * 30)/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-bulkdiscount+fee+salestax-GCtotal)*100)/100;
	grand=grand.toFixed(2);
	document.getElementById('grand_field').innerHTML = "$"+grand;
}


function use_domestic() {

	document.getElementById('DeliveryPanel0').style.display = "block";
	document.getElementById('DeliveryPanel1').style.display = "none";
	change_delivery( getRadioCheckedValue( 'Delivery0' ), '0');
	document.getElementById('domwarn').style.display = "block";
	document.getElementById('intlwarn').style.display = "none";
}

function use_international() {

	document.getElementById('DeliveryPanel0').style.display = "none";
	document.getElementById('DeliveryPanel1').style.display = "block";
	change_delivery( getRadioCheckedValue( 'Delivery1' ), '1');
	document.getElementById('domwarn').style.display = "none";
	document.getElementById('intlwarn').style.display = "block";
}

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['gallery'].cm_m.options[document.forms['gallery'].cm_m.selectedIndex].value;
if(f == 'cm') {
	window.location.href="http://www.bridalpartytees.com/gallery/bypopular/"+t;
} else {
	window.location.href="http://www.bridalpartytees.com/mygallery/bypopular/"+t;
}
}
function cm_item(f) {
var i=document.forms['gallery'].cm_i.options[document.forms['gallery'].cm_i.selectedIndex].value;
if(f == 'cm') {
	window.location.href="http://www.bridalpartytees.com/gallery/byitem/"+i;
} else {
	window.location.href="http://www.bridalpartytees.com/mygallery/byitem/"+i;
}
}
function cm_display(f) {
var d=document.forms['gallery'].cm_d.options[document.forms['gallery'].cm_d.selectedIndex].value;
if(f == 'cm') {
	window.location.href="http://www.bridalpartytees.com/gallery/perpage/"+d;
} else {
	window.location.href="http://www.bridalpartytees.com/mygallery/perpage/"+d;
}
}
function show_post(sid,did,pn,nid) {
  var httpurl="http://www.bridalpartytees.com/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['search'].submit();
	return false;
} else {
	return true;
}
}

function xmlhttpPost(flag,ip,sz) {
	var xmlHttpReq = false;
	var sendstr=getquerystring(flag,ip,sz);
	if(sendstr == "") return;
	var url='/cgi-bin/main.cgi';
	
	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?\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], '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];
		}

		var newsub = values[2]-values[4]-values[5];
                newsub = newsub.toFixed(2);
		if(newsub >= 50 || values[3]=='0') {
			document.getElementById('freeshipid').innerHTML = "Your order qualifies for free shipping!";
			document.getElementById('freeshipid').style.display='block';
		} else {
			var less=(50.00 - newsub).toFixed(2);
			document.getElementById('freeshipid').innerHTML = "FREE shipping on U.S. orders over \$50! <span class='blackbold'>$" + less + "</span> to free shipping.";
			document.getElementById('freeshipid').style.display='block';
		}
		set_discount(values[4], values[5]);
		document.getElementById('gtotal').innerHTML = newsub;
		if(key[0] == "remove") {
			var eid='purchase' + ip;
			document.getElementById(eid).style.display='none';
		}
		document.getElementById('itemcnt').innerHTML = values[7] + " 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= 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 != null){
		var email = document.checkout.Email_Address;
		errMsg += checkErr(email,0,"Email Address");
		if (checkErr(email,0,"Email Address") == ''){
			var email = document.checkout.Email_Address;
			errMsg += checkErr(email,'email',"Email Address");
		}
	}
	poErrMsg = '';
	if ( ( document.checkout.same_address[0].checked == 1 ) )
	{
		poErrMsg += checkPOBoxShipping( document.checkout.BillTo_Street_Line1 );
	}

	if ( (errMsg != '') || (poErrMsg != '') ) {

		document.getElementById('billingerr').innerHTML = '';
		if ( poErrMsg != '' )
		{
			document.getElementById('billingerr').innerHTML += "<br>" + poErrMsg;
		}
		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");
	}

	poErrMsg = '';
	if ( ( document.checkout.same_address[1].checked == 1 ) )
	{
		poErrMsg += checkPOBoxShipping( document.checkout.ShipTo_Street_Line1 );
	}

	if ( (errMsg != '') || (poErrMsg != '') ) {

		document.getElementById('shippingerr').innerHTML = '';
		if ( poErrMsg != '' )
		{
			document.getElementById('shippingerr').innerHTML += "<br>" + poErrMsg;
		}
		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 usegc = document.checkout.gc.checked;
        var cardnumber = document.checkout.Payment_Card_Number;
        
        if ( ( usegc ) && ( cardnumber.value == '' ) )
        {
            return 0;
        }

	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");
	
	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(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(); // set the focus to this input
		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, bulkval)
{
	document.getElementById('promoline').innerHTML = "";

	if (val != 0 )
	{
		document.getElementById('promoline').innerHTML = "<div class='total_l'>Promotional Discount</div><div class='total_r'>-\$" + val +"</div>";
	}
	if( bulkval != 0 )
	{
		document.getElementById('promoline').innerHTML += "<div class='total_l'>Group Discount</div><div class='total_r'>-\$" + bulkval +"</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  <a href='mailto:bridalpartytees\@eretailing.com'>customer service representative</a> or call 800-721-9895 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>Dominican Republic<li>Hungary<li>Ireland<li>Liechtenstein<li>Luxemburg<li>Monaco<li>Puerto Rico<li>United Kingdom</ul>");

	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}
function showdelivery(val)
{
	var slowshipping = false;

	winpops=window.open("","","width=600,height=300,scrollbars=1");
	if(val==0){
		winpops.document.writeln("<html><head><title>Arrival Estimates in United States</title></head>");
		if ( slowshipping )
		{
			winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>Arrival Estimates in United States</h4><ul><li>12 business days  $5.95 or <b>free</b> on orders over $50<li>9 business days  $8.95<li>6 business days  $19.95 or 20% of orders over $100<li>3 business days  $29.95 or $30% of orders over $100</ul>");
		}
		else
		{
			winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>Arrival Estimates in United States</h4><ul><li>10-12 business days  $5.95 or <b>free</b> on orders over $50<li>7-9 business days  $8.95<li>5-6 business days  $19.95 or 20% of orders over $100<li>3 business days  $29.95 or 30% 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 popupBdate(leftPos, topPos)
{
	winpops=window.open("","","width=300,height=100, left=" + leftPos + ", top=" + topPos + ", z-index=10");
	winpops.document.writeln("<html><head><title>Why we ask for birth date?</title></head><body>We ask for your age to confirm that you are<br />over the age of 13 as required by the law.");
	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}
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_cm_s(){
	if(document.forms[0].cm_s.value == "Search for a design") {
		document.forms[0].cm_s.value="";
	}
}
function clear_txt(){
  if(document.forms[0].designdesc.value == "Thanks for viewing my design. Feel free to leave a comment!") {
    document.forms[0].designdesc.value="";
  }
}

function getRadioCheckedValue( radio_name )
{
    var oRadio = document.forms[0].elements[radio_name];

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

        if(oRadio[i].checked)
        {
            return oRadio[i].value;
        }

    }

    return '';
}

function checkPOBoxShipping( e )
{
	var errMsg = '';

	var bcountry = document.checkout.BillTo_Country.options[document.checkout.BillTo_Country.selectedIndex].value;
	var scountry = document.checkout.ShipTo_Country.options[document.checkout.ShipTo_Country.selectedIndex].value;

	var domesticshipmethod = getRadioCheckedValue('Delivery0');

        var sameaddress = getRadioCheckedValue('same_address');

	if( sameaddress == 1 ) {

		country = bcountry;

	} else {

		country = scountry;
	}

	//----- Is the user using something other than thedomestic shipping economy option?
	if ( ( domesticshipmethod != 0 ) || ( country != 'United States' ) )
	{
		var address;

		address = e.value;

		address = address.toLowerCase();

		//----- Are they also trying to ship to a PO Box?
		if ( address.match( /^\s*p[\.|\s]?o[\.|\s]?\s+box/ ) )
		{
			//----- If so, inform them that we can't do rush or priority delivery to PO boxes
			errMsg += "We apologize, but FedEx does not deliver to P.O. Boxes.  Please enter a different address or choose a different delivery option.  Thank you.<br>";
		}
	}

	if(errMsg != ''){
		e.style.backgroundColor="yellow";
		e.parentNode.className="labelhighLight";
	}

	return errMsg;
}

function set_bmonth(cy) {
var wy;
var byear;
var daysinmonth;

  var wm=document.getElementById('bmonth').selectedIndex;
  var wd=document.getElementById('bday').selectedIndex;
  if( wm > 0 ) {
	wy=document.getElementById('byear').selectedIndex;
	if(wy <= 0) {
        	document.getElementById('byear').selectedIndex=1;
		byear=cy;
	} else {
		byear=cy+wy-1;
	}

	if(wm == 1 || wm == 3 || wm == 5 || wm == 7 || wm == 8 || wm == 10 || wm == 12) {
		daysinmonth=31;
	} else if(wm == 4 || wm == 6 || wm == 9 || wm == 11) {
		daysinmonth=30;
	} else if(byear % 4 == 0) {
		daysinmonth=29;
	} else {
		daysinmonth=28;
	}
       	document.getElementById('bday').options.length=daysinmonth+1;
        document.getElementById('bday').options[0]=new Option('Day');
        for (var i = 1; i <= daysinmonth; i++) {
            document.getElementById('bday').options[i]=new Option(i);
        }
	if( wd <= daysinmonth) {
        	document.getElementById('bday').selectedIndex=wd;
	} else {
        	document.getElementById('bday').selectedIndex=0;
	}
  }	
}

function set_byear(cy) {
  var wm=document.getElementById('bmonth').selectedIndex;
  var wy=document.getElementById('byear').selectedIndex;
  var wd=document.getElementById('bday').selectedIndex;
  var daysinmonth;
  if( wm > 0 && wy > 0 ) {
	byear=cy+wy-1;
	if(wm == 1 || wm == 3 || wm == 5 || wm == 7 || wm == 8 || wm == 10 || wm == 12) {
		daysinmonth=31;
	} else if(wm == 4 || wm == 6 || wm == 9 || wm == 11) {
		daysinmonth=30;
	} else if(byear % 4 == 0) {
		daysinmonth=29;
	} else {
		daysinmonth=28;
	}
       	document.getElementById('bday').options.length=daysinmonth+1;
        document.getElementById('bday').options[0]=new Option('Day');
        for (var i = 1; i <= daysinmonth; i++) {
            document.getElementById('bday').options[i]=new Option(i);
        }
	if( wd <= daysinmonth) {
        	document.getElementById('bday').selectedIndex=wd;
	} else {
        	document.getElementById('bday').selectedIndex=0;
	}
  }	
}

function initCreateAccountPage() 
{
  document.getElementById("register_email").onblur = checkUsername;

  document.getElementById("register_email2").onblur = checkUsername2;
  
  document.getElementById("register_password").onblur = checkPassword;
  document.getElementById("register_password2").onblur = checkPassword2;
  document.getElementById("register_ssid").onblur = checkCaptcha;
  
  form = document.getElementById("register_form");

  for(i = 0; i < form.length; i++){
	  
	  element = form.elements[i];
	  element.onfocus = clearFollowingFields;
  }

}

function createRequest() {
	  try {
	    request = new XMLHttpRequest();
	    if (request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            request.overrideMimeType('text/html');
         }
	  } catch (tryMS) {
	    try {
	      request = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (otherMS) {
	      try {
	        request = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (failed) {
	        request = null;
	      }
	    }
	  }	
	  return request;
	}
function checkUsername() {
	var emailElement = document.getElementById("register_email");
	document.getElementById("email_icon").className = "thinking";
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(!emailElement.value.match(emailExp)){
        document.getElementById("email_icon").className = "denied";
	    document.getElementById("invalid_email").innerHTML = "Invalid email address";
	    document.getElementById("invalid_email").className = "display";
	}
	else 
	{

	  usernameRequest = createRequest();
	  if (usernameRequest == null)
	    alert("Unable to create request");
	  else {
	    var theName = document.getElementById("register_email").value;
	    var username = encodeURIComponent(theName);
	    var url= "cgi-bin/main.cgi";
	    var param = "reg_email=" + username;
	    usernameRequest.onreadystatechange = showUsernameStatus;
	    usernameRequest.open("POST", url, true);
	    usernameRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	    usernameRequest.send(param);
	  }
	}
}
function checkUsername2() {
	
	var emailElement = document.getElementById("register_email2");

	document.getElementById("email2_icon").className = "thinking";
	
	if(emailElement.value != document.getElementById("register_email").value ){
        document.getElementById("email2_icon").className = "denied";
	    document.getElementById("invalid_email2").innerHTML = "Email address does not match";
	    document.getElementById("invalid_email2").className = "display";
	}
	else 
	{
        document.getElementById("email2_icon").className = "approved";
	    document.getElementById("invalid_email2").className = "hide";
	}
}
function showUsernameStatus() {
  if (usernameRequest.readyState == 4) {
    if (usernameRequest.status == 200) {
      if (usernameRequest.responseText == "okay") {
        document.getElementById("email_icon").className = "approved";
        document.getElementById("invalid_email").className = "hide";

        usernameValid = true;
      } else {
        document.getElementById("email_icon").className = "denied";

        document.getElementById("invalid_email").innerHTML = "Email already exists";
        document.getElementById("invalid_email").className = "display";

        usernameValid = false;
      }
    }
  }
}

function checkPassword() {
	var passwordElement = document.getElementById("register_password");

	document.getElementById("password_icon").className = "thinking";
	
	if(passwordElement.value.length < 6 ){
		document.getElementById("password_icon").className = "denied";
	    document.getElementById("invalid_password").innerHTML = "Password must be at least 6 characters.";
	    document.getElementById("invalid_password").className = "display";
	}
	else 
	{
		document.getElementById("password_icon").className = "approved";
	    document.getElementById("invalid_password").className = "hide";
	}
}

function checkPassword2() {
	var passwordElement = document.getElementById("register_password2");

	document.getElementById("password2_icon").className = "thinking";
	
	if(passwordElement.value != document.getElementById("register_password").value ){
		document.getElementById("password2_icon").className = "denied";
	    document.getElementById("invalid_password2").innerHTML = "Password does not match.";
	    document.getElementById("invalid_password2").className = "display";
	}
	else 
	{
		document.getElementById("password2_icon").className = "approved";
	    document.getElementById("invalid_password2").className = "hide";
	}
}

function checkCaptcha() {
	var captchaElement = document.getElementById("register_ssid");

	document.getElementById("captcha_icon").className = "thinking";
	captchaRequest = createRequest();
	if (captchaRequest == null)
		alert("Unable to create request");
	else {
		var captcha = document.getElementById("register_ssid").value;
	    var captcha = encodeURIComponent(captcha);
	    var url= "cgi-bin/main.cgi";
	    var param = "captcha=" + captcha;
	    captchaRequest.onreadystatechange = showCaptchaStatus;
	    captchaRequest.open("POST", url, true);
	    captchaRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	    captchaRequest.send(param);
	}
}

function showCaptchaStatus() {
	  if (captchaRequest.readyState == 4) {
	    if (captchaRequest.status == 200) {
	      if (captchaRequest.responseText == "okay") {
	    	  document.getElementById("captcha_icon").className = "approved";
	        document.getElementById("invalid_captcha").className = "hide";
	      } else {
	    	  document.getElementById("captcha_icon").className = "denied";
	        document.getElementById("invalid_captcha").className = "display";
	        document.getElementById("invalid_captcha").innerHTML = "Invalid verification number";
	      }
	    }
	  }
	}

function checkFormStatus() {
	var register_email = document.getElementById("register_email").value.length;
	var register_email2 = document.getElementById("register_email2").value.length;
	var register_password = document.getElementById("register_password").value.length;
	var register_password2 = document.getElementById("register_password2").value.length;
	var register_ssid = document.getElementById("register_ssid").value.length;
	

	if(register_email == 0 || register_email2 == 0 || register_password == 0 || register_password2 == 0 || register_ssid == 0)

	{
		alert("Please complete the remaining fields!");
		return false;
	}

	var invalid_email = document.getElementById("invalid_email").className;
	var invalid_email2 = document.getElementById("invalid_email2").className;
	var invalid_password = document.getElementById("invalid_password").className;
	var invalid_password2 = document.getElementById("invalid_password2").className;
	var invalid_captcha = document.getElementById("invalid_captcha").className;
	
	var classes = invalid_email + invalid_email2 + invalid_password + invalid_password2 + invalid_captcha;
	if(classes.match('display'))
	{
		alert('Please fix the errors above!');
		return false;
	}
	else
	{
		return true;
	}

}

function getElementIndex(input){

	var form = input.form;

	for (var i=0;i<form.length;i++)
	{
		if(form.elements[i].name.localeCompare(input.name) == 0)
		{
			return i;
		}
	}
	return 0;
}

function clearFollowingFields()
{

	var form = this.form;
	var errors = new Array();
	errors['register_email'] = 'invalid_email';
	errors['register_email2'] = 'invalid_email2';
	errors['register_password'] = 'invalid_password';
	errors['register_password2'] = 'invalid_password2';
	errors['register_ssid'] = 'invalid_captcha';
	
	var icons = new Array();
	icons['register_email'] = 'email_icon';
	icons['register_email2'] = 'email2_icon';
	icons['register_password'] = 'password_icon';
	icons['register_password2'] = 'password2_icon';
	icons['register_ssid'] = 'captcha_icon';
	
	var index = getElementIndex(this);
	for( i = index ; i < form.length; i++){
		
		element = form.elements[i];
		if(element.name != "showstring2007b2" && element.name != "register_sub" ){
			
			errorDivId = errors[element.name];
			iconDivId = icons[element.name];
			errorDiv = document.getElementById(errorDivId);
			iconDiv = document.getElementById(iconDivId);
			 if( iconDiv.className == "denied")
			{
				iconDiv.className = 'hide';
				errorDiv.className = 'hide';
			}
		}
	}

	
}
