// Standard Dreamweaver image swap JS
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 confirm_delete()
{
	return confirm ("Are you sure you wish to delete this product?");
}

function confirm_delete_cat()
{
	return confirm ("Are you sure you wish to delete this category?");
}

function confirm_delete_subcat()
{
	return confirm ("Are you sure you wish to delete this category and any of it's subcategories?");
}

function confirm_delete_content()
{
	return confirm ("Are you sure you wish to delete this content?");
}


function confirm_delete_location()
{
	return confirm ("Are you sure you wish to delete this content location?");
}

function confirm_delete_mailing_list()
{
	return confirm ("Are you sure you wish to delete this mailing list?");
}


function dochange(elt,action)
{
	this.location.href = "admin.php?action="+action+"&subaction=edit&id="+elt.value;
}

function content_check()
{
	if (this.document.contentform.datatype.value == "Product" && this.document.contentform.product_id.value > 0)
		return true;
	else if (this.document.contentform.datatype.value == "Text")
		return true;
	else
		return false;
}

function samebilling()
{
	if (this.document.checkoutform.same.checked == true)
	{
		this.document.checkoutform.billing_name.value = this.document.checkoutform.name.value;
		this.document.checkoutform.billing_address.value = this.document.checkoutform.address.value;
		this.document.checkoutform.billing_address2.value = this.document.checkoutform.address2.value;
		this.document.checkoutform.billing_city.value = this.document.checkoutform.city.value;
		this.document.checkoutform.billing_place.value = this.document.checkoutform.place.value;
		this.document.checkoutform.billing_postal_code.value = this.document.checkoutform.postal_code.value;
		this.document.checkoutform.country.selectedIndex = this.document.checkoutform.shipping_country.selectedIndex;
		changecountry();
	}
}

function orderchecked()
{
	if (this.document.checkoutform.name.value.length < 1)
	{
		alert ("You must fill out your name.");
		this.document.checkoutform.name.focus();
		return false;	
	}
	else if (this.document.checkoutform.address.value.length < 1)
	{
		alert ("You must fill out your address.");
		this.document.checkoutform.address.focus();
		return false;	
	}
	else if (this.document.checkoutform.city.value.length < 1)
	{
		alert ("You must fill out your city.");
		this.document.checkoutform.city.focus();
		return false;	
	}
	else if (this.document.checkoutform.place.value.length < 1)
	{
		alert ("You must fill out your State/Province.");
		this.document.checkoutform.place.focus();
		return false;	
	}
	else if (this.document.checkoutform.postal_code.value.length < 1)
	{
		alert ("You must fill out your Zip/Postal Code.");
		this.document.checkoutform.postal_code.focus();
		return false;	
	}
	else if (this.document.checkoutform.email.value.length < 1)
	{
		alert ("You must fill out your email address.");
		this.document.checkoutform.email.focus();
		return false;	
	}
	else if (echeck(this.document.checkoutform.email.value)==false)
	{
		alert ("Your email address is invalid.");
		this.document.checkoutform.email.focus();
		return false;	
	}
	else if (this.document.checkoutform.confirmation.value.length < 1)
	{
		alert ("You must fill out your confirmation email address.");
		this.document.checkoutform.confirmation.focus();
		return false;	
	}
	else if (echeck(this.document.checkoutform.confirmation.value)==false)
	{
		alert ("Your confirmation email address is invalid.");
		this.document.checkoutform.confirmation.focus();
		return false;	
	}
	else if (this.document.checkoutform.email.value != this.document.checkoutform.confirmation.value)
	{
		alert ("You must fill out your email address and confirmation email address must match.");
		this.document.checkoutform.email.focus();
		return false;	
	}
	else if (this.document.checkoutform.card_num.value.length < 1)
	{
		alert ("You must fill out the billing credit card number.");
		this.document.checkoutform.card_num.focus();
		return false;	
	}
	else if (this.document.checkoutform.exp_mm.value.length < 1)
	{
		alert ("You must fill out the billing expiration month.");
		this.document.checkoutform.exp_mm.focus();
		return false;	
	}
	else if (this.document.checkoutform.exp_yy.value.length < 1)
	{
		alert ("You must fill out the billing expiration year.");
		this.document.checkoutform.exp_yy.focus();
		return false;	
	}
	else if (this.document.checkoutform.billing_name.value.length < 1)
	{
		alert ("You must fill out the billing name.");
		this.document.checkoutform.billing_name.focus();
		return false;	
	}
	else if (this.document.checkoutform.billing_address.value.length < 1)
	{
		alert ("You must fill out the billing address");
		this.document.checkoutform.billing_address.focus();
		return false;	
	}
	else if (this.document.checkoutform.billing_city.value.length < 1)
	{
		alert ("You must fill out the billing city.");
		this.document.checkoutform.billing_city.focus();
		return false;	
	}
	else if (this.document.checkoutform.billing_place.value.length < 1)
	{
		alert ("You must fill out the billing state.");
		this.document.checkoutform.billing_place.focus();
		return false;	
	}
	else if (this.document.checkoutform.billing_postal_code.value.length < 1)
	{
		alert ("You must fill out the billing postal code.");
		this.document.checkoutform.billing_postal_code.focus();
		return false;	
	}
	else if (this.document.checkoutform.billing_country.selectedIndex < 1)
	{
		alert ("You must fill out the billing country.");
		this.document.checkoutform.billing_country.focus();
		return false;	
	}
	else
		return true;	
}

//function changecountry(elt,action)
function changecountry()
{
	this.document.hiddenform.name.value 				= this.document.checkoutform.name.value;
	this.document.hiddenform.company.value 				= this.document.checkoutform.company.value;
	this.document.hiddenform.address.value 				= this.document.checkoutform.address.value;
	this.document.hiddenform.address2.value 			= this.document.checkoutform.address2.value;
	this.document.hiddenform.city.value 				= this.document.checkoutform.city.value;
	this.document.hiddenform.place.value 				= this.document.checkoutform.place.value;
	this.document.hiddenform.postal_code.value 			= this.document.checkoutform.postal_code.value;
	this.document.hiddenform.shipping_country.value 	= this.document.checkoutform.shipping_country.value;
	this.document.hiddenform.email.value 				= this.document.checkoutform.email.value;
	this.document.hiddenform.confirmation.value 		= this.document.checkoutform.confirmation.value;
	this.document.hiddenform.phone.value 				= this.document.checkoutform.phone.value;
	this.document.hiddenform.fax.value 					= this.document.checkoutform.fax.value;
	this.document.hiddenform.billing_name.value 		= this.document.checkoutform.billing_name.value;
	this.document.hiddenform.billing_address.value 		= this.document.checkoutform.billing_address.value;
	this.document.hiddenform.billing_address2.value		= this.document.checkoutform.billing_address2.value;
	this.document.hiddenform.billing_city.value 		= this.document.checkoutform.billing_city.value;
	this.document.hiddenform.billing_place.value	 	= this.document.checkoutform.billing_place.value;
	this.document.hiddenform.billing_postal_code.value	= this.document.checkoutform.billing_postal_code.value;
	this.document.hiddenform.country.value 				= this.document.checkoutform.country.value;
	this.document.hiddenform.message.value 				= this.document.checkoutform.message.value;

	this.document.hiddenform.submit();
//	this.location.href = "cart_checkout.php?action="+action+"&country="+elt.value;
}

function change_affiliate(elt)
{
	this.location.href = elt.value;
}

function customer_care_form()
{
	if (this.document.careform.email.value.length < 1)
	{
		alert ("You must fill out your email address.");
		this.document.careform.email.focus();
		return false;	
	}
	else if (echeck(this.document.careform.email.value)==false)
	{
		alert ("Your email address is invalid.");
		this.document.careform.email.focus();
		return false;	
	}
	
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

