// Form Validation
// --------------------------------
// 8/23/2006
// photoProofPro v2.5.0
// Joe Pelosi (ilgstudio.com)
// --------------------------------


// set up array.push() function for older browsers
function Array_push() {
  var A_p = 0
  for (A_p = 0; A_p < arguments.length; A_p++) {
   this[this.length] = arguments[A_p]
   }
  return this.length
}
	
if (typeof Array.prototype.push == "undefined") {
 Array.prototype.push = Array_push
 }
// ######################################
	Array.prototype.inArray = function (value)
		// Returns true if the passed value is found in the
		// array.  Returns false if it is not.
		{
			var i;
			for (i=0; i < this.length; i++) {
				// Matches identical (===), not just similar (==).
				if (this[i] === value) {
					return true;
				}
			}
			return false;
		};
		
// FORM VALIDATION
function validate(formName, validationArr){
	//alert(validationArr);
	errors = new Array();
	if (validationArr!=null){
		for (i=0; i<validationArr.length; i++){
			var myParts = validationArr[i].split("|");
			//alert(myParts);
		
			type = myParts[0];
			field = myParts[1];
			msgStr = myParts[2];
		
			
			switch (type){
				
				case "email":
				if (!isValidEmail($F(field))){
					errors.push("A Valid Email Address");
				}
				break;
				// -------------
				case "empty":
				if (!emptyFieldCheck($F(field))){
					errors.push(msgStr);
				}
				break;
				// -------------
				case "time":
				 if (document.forms[0].eventTime){
				 	if (!isValidTime(document.forms[0].eventTime.value)){
						errors.push("A Valid time, use HH:MM");
					}
				}
				break;
				// -------------
				case "date":
				if (document.forms[0].dc){
					if (!isDate(document.forms[0].dc.value)){
						errors.push("A Valid Date, use DD/MM/YYYY");	
					}
				}
				break;
				// -------------
				case "title":
				if (!emptyFieldCheck('detail', 'title')){
						errors.push("Title is required");
					}
				break;
				// -------------
		
			}
		}
	}

	if (errors.length > 0){
		alertMsg = "The following required fields were incomplete:\n\n";
		for (i=0; i<errors.length; i++){
			alertMsg += "  - "+errors[i]+"\n";
		}
		alertMsg += "\nPlease correct and try again."
		alert (alertMsg);
		return false;
	} else {
		//MM_showHideLayers('loadingMsg','','show');
		//document.detail.Button.disabled=true;
		return true;
		//$(formName).submit();
	}
}
	
function isValidEmail(email){
	//var email = document.forms[0].email.value; 

	var objRegExp  = /(^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$)/i;

	  if(objRegExp.test(email)){
		return true;
	  } else {
		//alert("Please enter a valid email address.");
		return false;
	  }

}
function emptyFieldCheck(val){
	if(val == '' || val == ' ' || val == null){ 
		return false;
	} else {
		return true;
	}
}
function touchMe(){
	if ($('touched')!=null){
		
		$('touched').value=1;
		
	}	
}
	