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');

var sitedomain = "bridalpartytees.com";
var htm = "http://www." + sitedomain + "/";
var htmstatic = "http://static." + sitedomain + "/";
var url='/cgi-bin/main.cgi';
var showstring = "bptshowstring_amazon"

var addohsalestax = true;
var nofreeshippingminimum = 0
var shippingprice0 = 5.95
var freeshippingthreshold = 50

var sitenameproperspaces = "Bridal Party Tees"
var customerservicephonenumber = "1-800-721-9895";
var customerserviceemail = "bridalpartytees@eretailing.com";

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;
    salestaxstr = '';

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

    if ( (country == 'United States') && (state == 'OH') && ( salestax == 0 ) )
    {
        salestaxstr = "Included";
    }
    else
    {
        salestaxstr = "\$"+salestax.toFixed(2);
    }

    document.getElementById('tax_field').innerHTML = salestaxstr;

    update_page_order_total();
}

function update_page_order_total()
{
    var additionalCostTextbox = document.getElementById( "additionalcosts" );
    var discountPercentageTextbox = document.getElementById( "discountpercentage" );

    var additionalCost = 0;
    var discountPercentage = 0;

    if ( ( additionalCostTextbox != null ) && ( discountPercentageTextbox != null ) )
    {
        additionalCost = parseFloat( additionalCostTextbox.value );
        discountPercentage = parseFloat( discountPercentageTextbox.value );

        if ( isNaN( additionalCost ) )
        {
            additionalCost = 0;
        }
        if ( isNaN( discountPercentage ) )
        {
            discountPercentage = 0;
        }
    }

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

function use_textfield_bill() {
	document.getElementById('bill_state').innerHTML = "<label for='BillTo_State'>State:</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:</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;

    var netsub = subtotal - repdiscount - bulkdiscount;

    if ( subtotal - gcsubtotal > 0 )
    {
        if ( intl == '0' )
        {
            if ( op == '0' )
            {
                if ( ( nofreeshippingminimum ) || ( netsub >= freeshippingthreshold ) )
                {
                    fee = 0;
                }
                else
                {
                    fee = shippingprice0;
                    if( netsub - gcsubtotal > 100 )
                    {
                        fee = Math.round( ( subtotal - gcsubtotal ) * shippingprice0 ) / 100;
                    }
                }
            }
            else if ( op == '1' )
            {
                fee = 7.18;
                if( netsub - gcsubtotal > 100 )
                {
                    fee = Math.round( ( subtotal - gcsubtotal ) * 7.18 ) / 100;
                }
            }
            else if ( op == '2' )
            {
                fee = 9.74;
                if( netsub - gcsubtotal > 100 )
                {
                    fee = Math.round( ( subtotal - gcsubtotal ) * 9.74 ) / 100;
                }
            }
            else if ( op == '3' )
            {
                fee = 19.67;
                if( netsub - gcsubtotal > 100 )
                {
                    fee = Math.round( ( subtotal - gcsubtotal ) * 19.67 ) / 100;
                }
            }
            else if ( op == '4' )
            {
                fee = 29.83;
                if( netsub - gcsubtotal > 100 )
                {
                    fee = Math.round( ( subtotal - gcsubtotal ) * 29.83 ) / 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+"'";
    }

    update_page_order_total();
    
    if (intl == '0' && subtotal >= 100 && (op == '2' || op == '3' || op == '4')) {
        document.getElementById('sig_field').style.display =  'block';
    } else {
        document.getElementById('sig_field').style.display =  'none';
    }
}

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[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='" + showstring + "' align='middle'> <param name='allowScriptAccess' value='sameDomain' /> <param name='movie' value='" + htmstatic + "swf/" + showstring + ".swf?sid="+sid+"' /> <param name='quality' value='high' /> <param name='bgcolor' value='#ffffff' /> <param name='wmode' value='opaque' /> <embed src='" + htmstatic + "swf/" + showstring + ".swf?sid="+sid+"' quality='high' bgcolor='#ffffff' wmode='opaque' width='122' height='42' name='" + showstring + "' 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;
	
	// generate a query string for postback to main.cgi
	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");
	}
	
	// do the postback
	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.getElementsByTagName('input');
		var tmpcnt=0;
		for(var i=0; i<ids.length;i++){
            if (ids[i].name.indexOf('cart_quan_'+ip) == 0) {
                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") != -1){
			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;
}

// confirm cart quantity fields are valid on checkout
function cartquantitiesvalid() {
    var ids=document.getElementsByTagName('input');
    var cntMap=[];
    var regrslt, tmpcnt;
    for(var i=0; i<ids.length;i++) {
        if ((regrslt = /^cart_quan_(\d+)/.exec(ids[i].name)) != null) {
            if ( document.getElementById('purchase'+regrslt[1]).style.display != 'none' ) {
                tmpcnt=isNumeric(ids[i], "Please enter a numeric number for all item quantities.");
                if(tmpcnt != -1) {
                    if(cntMap[regrslt[1]] == undefined) {
                        cntMap[regrslt[1]] = 0;
                    }
                    cntMap[regrslt[1]] += tmpcnt;
                } else {
                    return false;
                }
            }
        }
    }
    for(tmpcnt in cntMap) {
        if(cntMap[tmpcnt]==0) {
            if (confirm("The quantity for one or more items in your cart is 0. Are you sure you want to remove these items? You might lose their designs if they are not saved.\n")) {
                return true;
            }
            return false;
        }
    }
    return true;
}

function updatepage(str){
	// key=ip;itemsub; f;delivery;repdiscount;est_total;num
	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')
                {
                    var iter = 9;

                    //----- Iterate through the price data array returned for each purchase
                    while ( ( values[iter] != undefined ) && ( values[iter] != '' ) )
                    {
                        var pricedataarray = values[iter].split( ',' );

                        //----- Separate the current purchase's price data into ID, item subtotal, per-item price, group subtotal, and group per-item price
                        var currentip = parseInt( pricedataarray[0] );
                        var itemsub = parseFloat( pricedataarray[1] );
                        var itemprice = parseFloat( pricedataarray[2] );
                        var groupsub = parseFloat( pricedataarray[3] );
                        var groupprice = parseFloat( pricedataarray[4] );

                        var subelement, priceelement, groupsubelement, grouppriceelement, grouplabel;

                        //----- Get the HTML price elements associated with this purchase
                        subelement = document.getElementById('sub'+currentip);
                        priceelement = document.getElementById('price'+currentip);
                        groupsubelement = document.getElementById('groupsub'+currentip);
                        grouppriceelement = document.getElementById('groupprice'+currentip);
                        grouplabel = document.getElementById('grouplabel'+currentip);

                        //----- Set the actual prices in the HTML elements
                        subelement.innerHTML = "\$"+itemsub.toFixed(2);
                        priceelement.innerHTML = "\$"+itemprice.toFixed(2);
                        groupsubelement.innerHTML = "\$"+groupsub.toFixed(2);
                        grouppriceelement.innerHTML = "\$"+groupprice.toFixed(2);

                        //----- Was there a group discount for this purchase, and is the overall group discount non-zero (this would be the case if
                        //      the promotional discount overrode the group discount)
                        if ( ( groupsub < itemsub ) && ( parseFloat( values[5] ) > 0 ) )
                        {
                            subelement.style.textDecoration = "line-through";
                            priceelement.style.textDecoration = "line-through";
                            groupsubelement.style.display = "block";
                            grouppriceelement.style.display = "block";
                            grouplabel.style.display = "block";
                        }
                        else
                        {
                            subelement.style.textDecoration = "none";
                            priceelement.style.textDecoration = "none";
                            groupsubelement.style.display = "none";
                            grouppriceelement.style.display = "none";
                            grouplabel.style.display = "none";
                        }

                        iter++;
                    }
		}
		
		var newsub = values[2]-values[4]-values[5];
                newsub = newsub.toFixed(2);

		set_discount(values[4], values[5]);
		document.getElementById('gtotal').innerHTML = newsub;

                //----- Display the promo code status message returned from the server, if any
                var promocodestatusfield = document.getElementById('promocodestatus');
                if ( values[8] == "Code applied!" )
                {
                    promocodestatusfield.className = "promocodeapplied";
                }
                else
                {
                    promocodestatusfield.className = "promocodenotapplied";
                }
                promocodestatusfield.innerHTML = values[8];

		if(key[0] == "remove")
		{
			var eid='purchase' + ip;
			document.getElementById(eid).style.display='none';

			if ( values[7] == 0 )
			{
				document.getElementById("upsellsection").style.display='none';
			}
		}
	}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>"
	}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");
	}
	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");
	}

	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");
		}
		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 cardnumber = document.checkout.Payment_Card_Number;

        var spochecked = 0;
        if ( document.getElementById('spo') != null )
        {
            spochecked = document.getElementById('spo').checked;
        }

        var nocccheck = false;
        var discountPercentageTextbox = document.getElementById( "discountpercentage" );
        if ( ( discountPercentageTextbox != null ) && ( discountPercentageTextbox.value == "100" ) )
        {
            nocccheck = true;
        }

        if ( ( ( document.getElementById('gc').checked != 1 ) && ( spochecked != 1 ) && ( !nocccheck ) ) || ( cardnumber.value != '' ) )
        {
	    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 ( document.getElementById('gc').checked == 1 )
        {
            var gcnumber = document.checkout.Payment_GC_Number;
            errMsg += checkErr(gcnumber, 2, "Gift Certificate Number");
            var gcpin = document.checkout.Payment_GC_Pin;
            errMsg += checkErr(gcpin, 2, "Gift Certificate Pin");
        }
        if ( spochecked == 1 )
        {
            var gcnumber = document.checkout.Payment_SPO_Number;
            errMsg += checkErr(gcnumber, 0, "School PO Number");
        }
	
	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.border="2px solid red";
		e.style.padding="1px";
		e.parentNode.className="labelhighLight";
	}
	return errMsg;
}

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

function isNumeric(elem, helperMsg) {
	if(elem.value.match(/^\s*[0-9]+\s*$/)) {
		return parseInt(elem.value);
	} 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 promise()
{
	winpops=window.open("","","width=600,height=300,z-index=10");
	winpops.document.writeln(
"<html>\
<head>\
<title>The " + sitenameproperspaces + " Promise</title>\
</head>\
<body bgcolor='#FFFFFF'>\
<font size=2 face=Verdana>\
<h4>The " + sitenameproperspaces + " Promise</h4>\
<p>We stand behind our products and the custom decoration that goes into each and every item. It \
does not happen often, but if we do 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 customer errors (such as spelling, colors, \
etc) made in the Design Center. If you find a problem with your order, please contact one of our \
customer service representatives at <a href='mailto:" + customerserviceemail + "'>" +
customerserviceemail + "</a>, or call " + customerservicephonenumber + " within 30 days of \
receiving your order and we will promptly address the issue.</p>\
<p>Thanks for shopping with us!</p>"
        );

	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>South Korea<li>United Kingdom</ul>");

	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}
function whatoutofarea()
{
    winpops=window.open("","","width=600,height=300,z-index=10");
	winpops.document.writeln("<html><head><title>What is the 'Out of Area' Charge?</title></head>");
    winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>What is the 'Out of Area' charge?</h4><p>The shipping address you provided is outside of FedEx's normal delivery area, so FedEx will charge an additional fee to make the delivery.  Customers in the United States may avoid this charge by changing their shipping method to USPS.");
	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}

function pop_authpo() {
    winpops=window.open("","","width=600,height=300,z-index=10");
	winpops.document.writeln("<html><head><title>How do I order using a School Purchase Order?</title></head>");
    winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>How do I order using a School Purchase Order?</h4><p>1) Call us at 800-361-8811.<br><br>2) We will create an authorized account for you that will allow you to place orders using a School PO.<br><br>3) You will need to be signed in to this account during Checkout.<br><br>4) Once you are signed in to your authorized account, go to the Checkout page. Under \"Payment\", choose \"I have a School Purchase Order\" and enter your PO number. Complete checkout.</p>");
	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 Unites States</title></head>");
		winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>Arrival Estimates in United States</h4><ul><li>15 business days - $3.94 or FREE on orders $60 and up<li>10 business days - $7.18 (or 7.18% of the order total if over $100)<li>8 business days - $9.74 (or 9.74% of the order total if over $100)<li>5 business days - $19.67 (or 19.67% of the order total if over $100)<li>3 business days - $29.83 (or 29.83% of the order total if over $100)</ul>");
		winpops.document.writeln("For orders shipping to APO, DPO, and FPO addresses, we cannot provide arrival estimates - these orders will usually arrive within 21 business days but we cannot guarantee delivery time to these addresses.</font>");
	} 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 show_spo()
{
	if (document.getElementById('spo').checked == false) {
		document.getElementById('spo_number').style.display = 'none';
	} else {
		document.getElementById('spo_number').style.display = 'block';
	}
}

function clear_txt(){
  if(document.forms[0].cm_s.value == "Search for a design") {
    document.forms[0].cm_s.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 ) && ( domesticshipmethod != 1 ) ) || ( 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.border="2px solid red";
		e.style.padding="1px";
		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 != "cgshowstring_amazon" && 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';
			}
		}
	}
}

function whatcopydesign() {
    winpops=window.open("","","width=600,height=300,z-index=10");
	winpops.document.writeln("<html><head><title>What is this Copy Design button?</title></head>");
    winpops.document.writeln("<body bgcolor='#FFFFFF'><font size=2 face=Verdana><h4>What is this Copy Design button?</h4><p>The copy design button will take you back to the design center, where you can further customize your design. Clicking Add to Cart from there will then add a new item to your cart. (It's just like editing your design, but it will result in an addtional item in your cart.)<br><br>This is a great feature if you want to put one design on many different items. Let's say you are making Family Reunion shirts for everyone in your family. You can put your design on a Men's basic tee, add it tor your cart, then click on the copy design button to get back to the design center. Simply click on the Swap Out Item tab, choose a toddler shirt, click Add to Cart again, and now you have a Men's tee and a Toddler tee.<br><br>It's also great if you are making shirts for a bachelorette party and you want each girl's nickname to be printed on their own personal shirt.</p>");
	winpops.document.writeln("</body></html>");
	winpops.document.close();
	winpops.focus();
}

