// JavaScript Document
function swap(sample){
	document.tees.src = sample;
}
//submit any form
function sub_frm(obj){
	document.getElementById(obj).submit();
}
//submit CBM Apply
function sub_cbm(){
	var objs = document.getElementById("cbm-appl");
	var error = "";
	
	for(var p=0; p<objs.length; p++){
		if(objs.elements[p].value == ''){
			error = true;
		}
	}
	
	if(error == true){
		alert("All fields are required.");
	} else {	
		document.getElementById("cbm-appl").submit();
	}
}

//change page
function changePage(newLoc){
   nextPage = newLoc.options[newLoc.selectedIndex].value	
   if (nextPage != ""){
      document.location.href = nextPage
   }
}
//check shipping fields
function checkShippingFields(){
	if (document.checkout.elements["shipping_checked"].checked==true){
		document.checkout.elements["billing_name"].disabled=true;
		document.checkout.elements["billing_name"].value=document.checkout.elements["shipping_name"].value;
		document.checkout.elements["billing_phone"].disabled=true;
		document.checkout.elements["billing_phone"].value=document.checkout.elements["shipping_phone"].value;
		document.checkout.elements["billing_address1"].disabled=true;
		document.checkout.elements["billing_address1"].value=document.checkout.elements["shipping_address1"].value;
		document.checkout.elements["billing_city"].disabled=true;
		document.checkout.elements["billing_city"].value=document.checkout.elements["shipping_city"].value;
		document.checkout.elements["billing_zipcode"].disabled=true;
		document.checkout.elements["billing_zipcode"].value=document.checkout.elements["shipping_zipcode"].value;
	} else {
		document.checkout.elements["billing_name"].disabled=false;
		document.checkout.elements["billing_phone"].disabled=false;
		document.checkout.elements["billing_address1"].disabled=false;
		document.checkout.elements["billing_city"].disabled=false;
		document.checkout.elements["billing_zipcode"].disabled=false;
	}
}
//contact form
function sub_contact(){
	var errors="";
	if (document.contact.firstName.value == ''){
		//error
		errors+="- Your First Name\n";
	}
	if (document.contact.lastName.value == ''){
		//error
		errors+="- Your Last Name\n";
	}
	if (document.contact.city.value == ''){
		//error
		errors+="- Your City\n";
	}
	if (document.contact.school.value == ''){
		//error
		errors+="- Your School\n";
	}
	if (document.contact.emailAddress.value == ''){
		//error
		errors+="- Your friend's email address\n";
	}
	if (document.contact.what.value == ''){
		//error
		errors+="- What can Naked Threads do for you?\n";
	}
	if (errors !=""){
		alert('The following field(s) are missing:\n'+errors);
		return false;
	} 
	else {
		
		document.getElementById("contact").submit();
	}
}
//referral form
function sub_referrer(){
	var errors="";
	if (document.refer.email.value == '' || document.refer.email.value == 'Put E-Mail address here!'){
		//error
		errors+="- Your friend's email address\n";
	}
	
	if (errors !=""){
		alert('The following field(s) are missing:\n'+errors);
		return false;
	} 
	else {
		document.getElementById("refer").submit();
	}
}
//checkout form
function sub_checkout(){
	var errors="";
	if (document.checkout.shipping_country.value == ''){
		//error
		errors+="- Shipping Country\n";
	}
	if (document.checkout.shipping_name.value == ''){
		//error
		errors+="- Your name for the shipping address\n";
	}
	if (document.checkout.shipping_address1.value == ''){
		//error
		errors+="- Shipping Address\n";
	}
	if (document.checkout.shipping_city.value == ''){
		//error
		errors+="- Shipping City\n";
	}
	if (document.checkout.shipping_zipcode.value == ''){
		//error
		errors+="- Shipping Zip/Postal Code\n";
	}
	if (document.checkout.shipping_phone.value == ''){
		//error
		errors+="- Your phone number for the shipping address\n";
	}
	if (document.checkout.billing_email.value == ''){
		//error
		errors+="- Your email address\n";
	}
	if (document.checkout.billing_country.value == ''){
		//error
		errors+="- Billing Country\n";
	}
	if (document.checkout.billing_state.value == ''){
		//error
		errors+="- Billing State/Province type 'none' if this does not apply\n";
	}
	if (document.checkout.billing_name.value == ''){
		//error
		errors+="- Your name for the billing address\n";
	}
	if (document.checkout.billing_address1.value == ''){
		//error
		errors+="- Billing Address\n";
	}
	if (document.checkout.billing_city.value == ''){
		//error
		errors+="- Billing City\n";
	}
	if (document.checkout.billing_zipcode.value == ''){
		//error
		errors+="- Billing Zip/Postal Code\n";
	}
	if (document.checkout.billing_phone.value == ''){
		//error
		errors+="- Your phone number for the billing address\n";
	}
	if (document.checkout.ccFirstName.value == ''){
		//error
		errors+="- Your first name on the credit card\n";
	}
	if (document.checkout.ccLastName.value == ''){
		//error
		errors+="- Your last name on the credit card\n";
	}
	if (document.checkout.cc_type.value == ''){
		//error
		errors+="- Type of credit card\n";
	}
	if (document.checkout.cc_number.value == ''){
		//error
		errors+="- Your credit card number\n";
	}
	if (document.checkout.cc_exp_date_month.value == ''){
		//error
		errors+="- Expiration month\n";
	}
	if (document.checkout.cc_exp_date_year.value == ''){
		//error
		errors+="- Expiration year\n";
	}
	
	if (errors !=""){
		alert('The following field(s) are missing:\n'+errors);
		return false;
	} 
	else {
		
		document.getElementById("checkout").submit();
	}
}
//mailing list
function sub_list(){
	var errors="";
	if (document.list.name.value == '' || document.list.name.value == 'your name here!'){
		//error
		errors+="- Your name\n";
	}
	
	if (document.list.email.value == '' || document.list.email.value == 'your email here!'){
		//error
		errors+="- Your email address\n";
	}
	
	if (errors !=""){
		alert('The following field(s) are missing:\n'+errors);
		return false;
	} 
	else {
		document.getElementById("list").submit();
	}
}
//bookmark
function bookmark(url, description){
	netscape="Please hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer'){
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape'){
		alert(netscape);
	}
}

//Macromedia stuff
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function confirmOut() {
/*
<option value="XS">XS</option>
<option value="S">S</option>
<option value="M" selected>M</option>
<option value="L">L</option>
<option value="XL">XL</option>
<option value="XXL">XXL</option>
<input type="hidden" id="QXS" name="QXS" value="<? echo $row[2] ?>">
<input type="hidden" id="QS" name="QS" value="<? echo $row[3] ?>">
<input type="hidden" id="QM" name="QM" value="<? echo $row[4] ?>">
<input type="hidden" id="QL" name="QL" value="<? echo $row[5] ?>">
<input type="hidden" id="QXL" name="QXL" value="<? echo $row[6] ?>">
<input type="hidden" id="QXXL" name="QXXL" value="<? echo $row[7] ?>">
*/

if (document.purchase.size.value == 'XS') {
	if (document.purchase.QXS.value == '0') 
		var agree=confirm("You have selected an item on backorder, we will ship as soon as we have it in stock.");
	else
		agree = true;
} else if(document.purchase.size.value == 'S') {
	if (document.purchase.QS.value == '0') 
		var agree=confirm("You have selected an item on backorder, we will ship as soon as we have it in stock.");
	else
		agree = true;
} else if(document.purchase.size.value == 'M') {
	if (document.purchase.QM.value == '0') 
		var agree=confirm("You have selected an item on backorder, we will ship as soon as we have it in stock.");
	else
		agree = true;
} else if(document.purchase.size.value == 'L') {
	if (document.purchase.QL.value == '0') 
		var agree=confirm("You have selected an item on backorder, we will ship as soon as we have it in stock.");
	else
		agree = true;
} else if(document.purchase.size.value == 'XL') {
	if (document.purchase.QXL.value == '0') 
		var agree=confirm("You have selected an item on backorder, we will ship as soon as we have it in stock.");
	else
		agree = true;
} else if(document.purchase.size.value == 'XXL') {
	if (document.purchase.QXXL.value == '0') 
		var agree=confirm("You have selected an item on backorder, we will ship as soon as we have it in stock.");
	else
		agree = true;
}

if (agree)
	return true ;
else
	return false ;
}
