// June 12, 2000 Last Revised, phpYellow javascript by Dreamriver.com
// CHECK EMAIL AND PASSWORD fields from login.php and admin-login.php
// Credit: This function by dannyg@dannyg.com
// all fields are required
function checkForm(form) {
for (var i=0; i < form.elements.length; i++) {
	if (form.elements[i].value == "") {
		alert("Fill out all fields please.")
		form.elements[i].focus()
		return false
	}
}
return true
}



// VALIDATE THE STANDARD FORM used for insert and edit of listings
// Credit: This function by richardc@dreamriver.com
function validate(form) {

var myForm = document.forms[0];

	for (var i=0; i < form.elements.length; i++) {
		if(form.elements[i].type == "text" && form.elements[i].value == "") { // do only if a text input type
			alert("Fill out all fields please.\nEnter an empty space if not applicable.");

			form.elements[i].focus();
			return false;
		}
	}

// Company 
if ( myForm.ycompany.value.length <= 2 ) {
	alert("Enter a complete company name.\n Enter your name if applicable.");
	myForm.ycompany.focus()
	return false;
	}

/*
// Category
function checkCategory() {
	var list = myForm.ycategory
	chosenItem = list.options[i].value
	if(chosenItem == "") {
		alert("Choose a category.");
	}
}
*/

// Url
if ( myForm.yurl.value.substring(0,7) != "http://" ) {
	alert("You must enter a valid url.");
	myForm.yurl.focus()
	return false;
	}

// Description
if ( myForm.ydescription.value.length <= 0 ) {
	alert("Make your description 10 characters or longer.");
	myForm.ydescription.focus()
	return false;
	}

// Phone
if ( myForm.yphone.value.length <= 0 ) {
	alert("Your phone number must be at least 7 numbers or longer.");
	myForm.yphone.focus()
	return false;
	//needs validation for a number value, but allowing hyphens or dots
	}
	
// Fax
if ( myForm.yfax.value.length <= 0 ) {
	alert("Your fax number must be at least 7 numbers or longer.");
	myForm.yfax.focus()
	return false;
	}

// Email
if ( myForm.yemail.value.length < 6) {
	alert("Your email address must be valid.");
	myForm.yemail.focus()
	return false;
	//needs better validation
	}

// Street Address
if ( myForm.yaddress.value.length < 5 ) {
	alert("Your street address appears invalid.");
	myForm.yaddress.focus()
	return false;
	}

// City
if ( myForm.ycity.value.length < 3 ) {
	alert("The city appears invalid.");
	myForm.ycity.focus()
	return false;
	}

// ZIP or Postal code
if ( myForm.ypostalcode.value.length < 5 ) {
	alert("Your ZIP or postal code must contain at least 5 characters.\n Enter 5 spaces if necessary.");
	myForm.ypostalcode.focus()
	return false;
	}

	return true
}
