// JavaScript for Edesirs Fashion Boutique
// Programmer: Dain Sanye
// Date of creation: 12/04/2008
// Last modified: 12/04/2008
// Notes: 

// Script to create rollover images
// Script created by Dreamweaver 8.0
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_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_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_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];}
}

// Script to create menu and submenus
// Script created by Dreamweaver 8.0
var time = 3000;
var numofitems = 7;
var menuitem1 = new menu(7,1,"hidden");
var menuitem2 = new menu(7,2,"hidden");
var menuitem3 = new menu(7,3,"hidden");
var menuitem4 = new menu(7,4,"hidden");
var menuitem5 = new menu(7,5,"hidden");
var menuitem6 = new menu(7,6,"hidden");
var menuitem7 = new menu(7,7,"hidden");

//menu constructor
function menu(allitems,thisitem,startstate){ 
  callname="gl"+thisitem;
  divname="subglobal"+thisitem;  
  this.numberofmenuitems = allitems;
  this.caller = document.getElementById(callname);
  this.thediv = document.getElementById(divname);
  this.thediv.style.visibility = startstate;
}

//menu methods
function ehandler(event,theobj){
  for (var i=1; i<= theobj.numberofmenuitems; i++){
    var shutdiv = eval("menuitem"+i+".thediv");
    shutdiv.style.visibility="hidden";
  }
  theobj.thediv.style.visibility="visible";
}
				
function closesubnav(event){
  if ((event.clientY <90)||(event.clientY > 150)){ /* originally 48-107 */
    for (var i=1; i<= numofitems; i++){
      var shutdiv = eval('menuitem'+i+'.thediv');
      shutdiv.style.visibility='hidden';
    }
  }
}

// Displays current date
function retrieveDate() {
	var currentDate=new Date();
	with (currentDate){
	newmonth = getMonth()+1;
	document.write(getDate() + "/" + newmonth + "/" + getYear())
	}
}

// Opens search windows in content frame
function openSearchWindow() {
	parent.frames[0].location.href="contactus.html";
}







// Script to validate Joe's Order Form before submission
function validateForm() {
	// Setting validation variable to default submit form
	valid="true";
	
	// Ensuring customer name field is not blank
	if (document.joesOrderForm.customer.value == ""){
	alert("Please enter your name before submitting your order");
	valid="false";
	}

	// Ensuring customer address and suburb fields are not blank
	if (joesOrderForm.address.value == "" || joesOrderForm.suburb.value == ""){
	alert("Please enter your address and suburb before submitting your order");
	valid="false";
	}

	// Ensuring customer postcode field is a 4-digit number
	var tempPostcode = new String(joesOrderForm.postcode.value);
	if (tempPostcode.length != 4 || isNaN(tempPostcode)){
	alert("Please enter a valid Australian postcode before submitting your order");
	valid="false";
	}

	// Ensuring customer email field is not blank, and includes an @ and at least one fullstop
	var tempEmail = new String(joesOrderForm.customerEmail.value);
	if (tempEmail == "" || tempEmail.indexOf("@") == -1 || tempEmail.indexOf(".") == -1){
	alert("Please enter a valid email address before submitting your order");
	valid="false";
	}

	// Ensuring customer credit card type is not blank
	if (joesOrderForm.creditCardType.value == ""){
	alert("Please enter your credit card type before submitting your order");
	valid="false";
	}

	// Ensuring customer credit card number is sixteen numbers long
	var tempCCNumber = new String(joesOrderForm.creditCardNumber.value);
	if (tempCCNumber.length < 15 || isNaN(tempCCNumber)){
	alert("Please correct your credit card number before submitting your order");
	valid="false";
	}

	// Ensuring customer credit card expiry date is not blank
	if (joesOrderForm.creditCardExpiryMonth.value == "" || joesOrderForm.creditCardExpiryYear.value == ""){
	alert("Please enter your credit card expiry date before submitting your order");
	valid="false";
	}

	// Returning false to submit command for form if any of the criteria above show true
	if (valid=="false"){
	return false;
	}
}


