// JavaScript Document
function validateSubscription()
{
	if(document.subscribe.name.value==''||document.subscribe.name.value=='your name'||document.subscribe.email.value==''||document.subscribe.email.value=='you@yourdomain.com.au')
	{
		alert("A name and email must be entered to subscribe to flick");	
	}
	else
	{	
		document.subscribe.submit();
	}
}
function confirmDeleteOrder(id)
{
	ok=confirm("Are you sure you want to delete this order?");
	
	if(ok)
		window.location.href="editdelete_order.php?delete="+id;
}
function confirmDeleteSubscription(email)
{
	ok=confirm("Are you sure you want to delete this subscription?");
	
	if(ok)
		window.location.href="editdelete_subscription.php?delete="+email;
}
function checkOrder()
{
	if(document.order.product.value=='')
	{
		alert('A product must be selected please go back and select the product again.');
	}
	else if(document.order.name.value==''||document.order.email.value=='')
	{
		alert('Name and email are required fields');
	}
	else if(!IsValidEmail(document.order.email.value))
	{
		alert('Email must be a valid format');
	}
	else if(document.order.home.value!=''&&!IsPhone(document.order.home.value))
	{
		alert('Home phone must be a valid format');
	}
	else if(document.order.business.value!=''&&!IsPhone(document.order.business.value))
	{
		alert('Business phone must be a valid format');
	}
	else if(document.order.mobile.value!=''&&!IsPhone(document.order.mobile.value))
	{
		alert('Mobile phone must be a valid format');
	}
	else if(document.order.sizes.value!=''&&!IsInvalid(document.order.sizes.value))
	{
		alert('Sizes contains invalid characters');
	}
	else if(document.order.details.value!=''&&!IsInvalid(document.order.details.value))
	{
		alert('Colour/Style contains invalid characters');
	}
	else
	{
		document.order.submit();
	}
}

function checkLogin()
{
	if(document.login.username.value==''||document.login.password.value=='')
	{
		alert("You must enter a username and password to login");
		return false;
	}
	else
	{
		document.login.submit();	
	}
}

function IsValidEmail(str) 
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function IsPhone(sText)
{
   var ValidChars = "0123456789.()";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber; 
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.-";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber; 
}
function IsInvalid(sText)
{
   var ValidChars = "#'&^${}><" + '"';
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) != -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber; 
}
function checkProduct()
{
	if(document.add_product.product.value==""||document.add_product.product.value=="Product name/series")
	{
		alert("A product name must be entered");
	}
	else if(!IsInvalid(document.add_product.product.value))
	{
		alert("Product name contains invalid characters #'&^${}><");
	}
	else if(document.add_product.description.value==""||document.add_product.description.value=="Product description...")
	{
		alert("A product description must be entered");
	}
	else if(!IsInvalid(document.add_product.description.value))
	{
		alert("Product description contains invalid characters #'&^${}><");
	}
	else if(document.add_product.price.value==""||document.add_product.price.value=="00.00")
	{
		alert("A product must have a price");
	}
	else if(!IsNumeric(document.add_product.price.value))
	{
		alert("Product price must be numeric");
	}
	else if(document.add_product.type.value=="")
	{
		alert("A product type must be selected");
	}
	else if(document.add_product.action.value=='add'&&document.add_product.productimage.value=='')
	{
		alert("A product must have an image");
	}
	else if(document.add_product.action.value=='modify'||document.add_product.productimage.value!='')
	{
		
		var imageext = document.add_product.productimage.value.substring((document.add_product.productimage.value.length - 3), (document.add_product.productimage.value.length));
		
		if(document.add_product.action.value!='modify'&&(imageext != "jpg" && imageext != "gif"))
		{	
			alert("Product image must be in JPG or GIF  format (*.jpg, *.gif) " +imageext);
			return false;
		}
		else
		{
			if(document.add_product.action.value=='add')
				ok=confirm("Are you sure you want to add this product?");
			else
				ok=confirm("Are you sure you want to modify this product?");
			
			if(ok)
				document.add_product.submit();
		}
	}
}
function checkDistributor()
{
	if(document.add_distributor.name.value==""||document.add_distributor.name.value=="Store name")
	{
		alert("A distributor name must be entered");
	}
	else if(!IsInvalid(document.add_distributor.name.value))
	{
		alert("Distributor name contains invalid characters #'&^${}><");
	}
	else if(document.add_distributor.address.value==""||document.add_distributor.address.value=="Address of store...")
	{
		alert("A distributor address must be entered");
	}
	else if(!IsInvalid(document.add_distributor.address.value))
	{
		alert("Distributor address contains invalid characters #'&^${}><");
	}
	else if(document.add_distributor.location.value=="")
	{
		alert("A distributor location must be selected");
	}
	else if(document.add_distributor.action.value=='add'&&document.add_distributor.image.value=='')
	{
		alert("A distributor must have an image");
	}
	else if(document.add_distributor.action.value=='modify'||document.add_distributor.image.value!='')
	{
		
		var imageext = document.add_distributor.image.value.substring((document.add_distributor.image.value.length - 3), (document.add_distributor.image.value.length));
		
		if(document.add_distributor.action.value!='modify'&&(imageext != "jpg" && imageext != "gif"))
		{	
			alert("Distributor image must be in JPG or GIF  format (*.jpg, *.gif) " +imageext);
			return false;
		}
		else
		{
			if(document.add_distributor.action.value=='add')
				ok=confirm("Are you sure you want to add this distributor?");
			else
				ok=confirm("Are you sure you want to modify this distributor?");
			
			if(ok)
				document.add_distributor.submit();
		}
	}
}
function confirmDelete(type, id, image)
{
	ok=confirm("Are you sure you want to delete this product?");
	
	if(ok)
	{
		window.location.href="editdelete_product.php?type="+type+"&delete="+id+"&image="+image;
	}
}
function confirmDeleteDistributor(location, id, image)
{
	ok=confirm("Are you sure you want to delete this distributor?");
	
	if(ok)
	{
		window.location.href="editdelete_distributor.php?location="+location+"&delete="+id+"&image="+image;
	}
}
function mmLoadMenus() {
  if (window.mm_menu_0528105928_0) return;
  window.mm_menu_0528105928_0 = new Menu("root",103,20,"Courier New, Courier, mono",14,"#ffffff","#ffffff","#000000","#ed0a19","left","middle",3,0,1000,-5,7,true,false,true,1,true,true);
  mm_menu_0528105928_0.addMenuItem("Surfboards","window.open('catalogue.php?type=surfboard', '_parent');");
  mm_menu_0528105928_0.addMenuItem("Bodyboards","window.open('catalogue.php?type=bodyboard', '_parent');");
  mm_menu_0528105928_0.addMenuItem("Skimboards","window.open('catalogue.php?type=skimboard', '_parent');");
  mm_menu_0528105928_0.addMenuItem("Accessories","window.open('catalogue.php?type=accessory', '_parent');");
   mm_menu_0528105928_0.hideOnMouseOut=true;
   mm_menu_0528105928_0.menuBorder=0;
   mm_menu_0528105928_0.menuLiteBgColor='#000000';
   mm_menu_0528105928_0.menuBorderBgColor='#000000';
   mm_menu_0528105928_0.bgColor='#000000';

  mm_menu_0528105928_0.writeMenus();
} // mmLoadMenus()

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];}
}