// JavaScript Document
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_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 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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function fn_deleteItem(itemName, actionId, formName){
	
	deleteItem = confirm('Do you want to delete: \'' + itemName + '\' from the database');
	
	if(deleteItem==true){
	
		 var formDOMObj = document[formName];
			 
		//set the forms action id to 3: delete
		 formDOMObj.intActionId.value = actionId;
		 formDOMObj.submit();
	}
}

function fn_validateFieldIsEmpty(formDOMObj, fieldname, identifier){
	/* this function validates a form filed, basically it checks to 
	see if a parameter sent to it and if it is, return false */
	if(formDOMObj[fieldname].value.length < 1){
		
		formDOMObj.formAlert.value='Enter a value for \'' + identifier + '\'';
		return false;
	}
	return true;
}

function fn_validateFieldsMatch(formDOMObj, fieldname1, fieldname2, identifier){
	/* this function compares two strings sent as parameters.  These strings represent 
	two fields in a form, eg. password and password confirm fields.
	If the fields do not match, return false
	*/
	if(formDOMObj[fieldname1].value != formDOMObj[fieldname2].value){
		formDOMObj.formAlert.value=identifier + ' fields do not match';
		return false;
	}
	return true;
}

function onSubmitForm(formDOMObj){
	
	//write validation for the form 'frmUser'
	if(formDOMObj.name =='frmContactUs'){
		 
		 /*this condidtional statement uses "or" arguments.  If a is false, or b is false or c is false, return false
		 If any of the validation functions called evaluate to false, the form will not be submitted. */
		 if(fn_validateFieldIsEmpty(formDOMObj, 'Last_Name', 'Last Name') == false
			|| fn_validateFieldIsEmpty(formDOMObj, 'Best_Tel_Number', 'Best Tel Number') == false)
		 	return false;
		
		//otherwise return true
		return true;
	}
	
	
			

}