function validEmail(email) {
  invalidChars = " /:,;";
  if (email == "") {
     return false;
	 }
  for  (i=0; i < invalidChars.length; i++) {
  	badChar = invalidChars.charAt(i);
	if (email.indexOf(badChar, 0) > -1) {
	   return false;
	}   
  }
  atPos = email.indexOf("@",1);
  if (atPos == -1) {
     return false;
  } 
  if (email.indexOf("@", atPos+1) != -1) {
  	return false;
  }  
  periodPos = email.indexOf(".", atPos);
  if (periodPos == -1) {
  	return false;
  }
  if (periodPos+3 > email.length) {
  	return false;
  }


 return true;

}

function formCheck(formobj){
	var fieldRequired = Array("MC_Name", "address", "postcode", "email", "tel", "MC_Recipients_Name", "MC_Recipients_Address[0]", "MC_Recipients_Address[1]", "MC_Recipients_Address[2]", "MC_Recipients_Address[3]", "MC_Recipients_Postcode", "MC_Recipients_Telephone",  "MC_Card_Message");
	var fieldDescription = Array("Your Name", "Your Address", "Your Postcode", "Your Email Address", "Your Telephone Number", "Recipient\'s Name", "Recipient\'s House Name/Number", "Recipient\'s Street Name", "Recipient\'s Town", "Recipient\'s County", "Recipient\'s Postcode/Zip code", "Recipient\'s Telephone Number", "The Card Message");
	var excludedPostcodes = Array("BT", "PO3", "JE");
	var alertMsg = "Please complete the following fields:\n";
	var postcodeMsg = "We are sorry but Easyflower cannot deliver to the destination address you have selected \n Postcode: ";	 
	var l_Msg = alertMsg.length;
	var alertFlag = "N";
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj) {
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
					alertFlag = "Y";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
					alertFlag = "Y";					
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					alertFlag = "Y";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					alertFlag = "Y";
				}
			}
		}
	}
	if (alertFlag == "N"){
		var obj = formobj.elements[fieldRequired[10]];
		opostcode = obj.value;
		opostcode = opostcode.toUpperCase();
		alertFlag = "N";
  		for (var i = 0; i < excludedPostcodes.length; i++){
			var matchLength = excludedPostcodes[i].length;			
			var pcMatch = opostcode.substring(0, matchLength);
			if (pcMatch == excludedPostcodes[i]) {
				alertMsg = postcodeMsg + opostcode;
				alertFlag = "Y";
			}
	 	}
	}
	if (alertFlag == "N"){
		var obj = formobj.elements[fieldRequired[3]];
		oemail = obj.value;
		alertFlag = "N";
        if (!validEmail(oemail)) { 
  			alertMsg = "Please enter a valid email address";
			alertFlag = "Y";
	 	}
	}
	
	if (alertFlag == "Y") {
		alert(alertMsg);
		return false;
	} else {	
		return true;
	}	
}

function confirmation(nextloc) {
	var answer = confirm("Are you sure you want to delete this item?")
	if (answer){		
		window.location = nextloc;
	}
	else{
		alert("Action Cancelled")
	}
}

function confirmationmsg(nextloc, msg) {
	var answer = confirm("Are you sure you want to delete this item?\n" + msg)
	if (answer){		
		window.location = nextloc;
	}
	else{
		alert("Action Cancelled")
	}
}

function launchAM(){
showModalDialog('/admin/wysiwig/assetmanager/assetmanager.php',window,'help:0;edge:raised;status:no;resizable:yes;dialogWidth:640px;dialogHeight:540px');
}

function flvFPW1(){//v1.44
// Copyright 2002-2004, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16;v11=new Array("width,left,"+v4,"height,top,"+v5);for (i=0;i<v11.length;i++){v12=v11[i].split(",");l_iTarget=parseInt(v12[2]);if (l_iTarget>1||v1[2].indexOf("%")>-1){v13=eval("screen."+v12[0]);for (v6=0;v6<v2.length;v6++){v10=v2[v6].split("=");if (v10[0]==v12[0]){v14=parseInt(v10[1]);if (v10[1].indexOf("%")>-1){v14=(v14/100)*v13;v2[v6]=v12[0]+"="+v14;}}if (v10[0]==v12[1]){v16=parseInt(v10[1]);v15=v6;}}if (l_iTarget==2){v7=(v13-v14)/2;v15=v2.length;}else if (l_iTarget==3){v7=v13-v14-v16;}v2[v15]=v12[1]+"="+v7;}}v8=v2.join(",");v9=window.open(v1[0],v1[1],v8);if (v3){v9.focus();}document.MM_returnValue=false;return v9;}


function startList() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace	(" over", "");
   }
   }
  }
 }
}

function init () {
	startList();	
}
