// phpYellow javascript by Dreamriver.com
// CHECK EMAIL AND PASSWORD fields from login.php3 and admin-login.php3
// 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("Rellene TODOS los campos.")
		form.elements[i].focus()
		return false
	}
}
return true
}
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}


// VALIDATE THE STANDARD FORM used for insert and edit of listings
// Credit: This function by info@dreamriver.com
function validate(form) {

	var myForm = document.forms[0];

	// Email
	if ( myForm.yemail.value.length < 6) {
		alert("Debe escribir una dirección de correo válida.");
		myForm.yemail.focus();
		return false;
		// needs better validation
	}
	//En teoría revisa la arroba con la funcion de arriba isEmailAddr
	  if (!isEmailAddr(myForm.yemail.value))
	  {
	    alert("Por favor escriba su dirección de correo correctamente: minombre@midominio.com");
	    myForm.yemail.focus();
	    return false;
	  }
	//Nombre de despacho  
	  if ( myForm.ycompany.value.length < 1) {
		alert("Escriba el nombre de su despacho.");
		myForm.ycompany.focus();
		return false;
	  }
	// Password
	if ( myForm.ypassword.value.length < 1) {
		alert("Escriba una contraseña.");
		myForm.ypassword.focus();
		return false;
	}
	// paste below this line

	// start of Url
	if ( myForm.yurl.value.substring(0,7) != "http://" ) {
		alert("Debe escribir una web válida, \ny debe comenzar con 'http://'");
		myForm.yurl.focus();
		return false;
	}
	// end of Url

	// paste above this line
/* 
	HOW TO MAKE DATA REQUIRED
	To require certain data to be entered by the user:
		1. save this file as yellowORIGINAL.js
		2. open yellow.js in your html editor
		3. find the data below: example: locate the // Phone section
		4. copy the phone section from the // start of ... to the // end of ... 
		5. paste the phone section in above where it says "paste below this line"
		6. save this file yellow.js and upload to your web server
		7. test by adding a new record
		8. [OPTIONAL] color code [red] the new fields you require in the file addForm.php
*/
/*
	// start of Company
	if ( myForm.ycompany.value.length < 3) {
		alert("You MUST enter a company name.");
		myForm.ycompany.focus();
		return false;
	}
	// end of Company

	// start of Phone
	if ( myForm.yphone.value.length < 7 ) {
		alert("Your phone number must be at least 7 numbers or longer.\nEnter 7 spaces if not applicable.");
		myForm.yphone.focus()
		return false;
		// needs validation for a number value, but allowing hyphens or dots
	}
	// end of Phone
	
	// start of Fax
	if ( myForm.yfax.value.length < 7 ) {
		alert("Your fax number must be at least 7 numbers or longer.");
		myForm.yfax.focus()
		return false;
	}
	// end of Fax
	
	// start of Street Address
	if ( myForm.yaddress.value.length < 6 ) {
		alert("Your street address appears invalid.\nEnter 6 spaces if not applicable.");
		myForm.yaddress.focus()
		return false;
	}
	// end of Street Address

	// start of City
	if ( myForm.ycity.value.length < 3 ) {
		alert("The city appears invalid.\nEnter 3 spaces if not applicable.");
		myForm.ycity.focus()
		return false;
	}
	// end of City

	// start of ZIP or Postal code
	if ( myForm.ypostalcode.value.length < 5 ) {
		alert("Your ZIP or postal code must contain at least 5 characters.\nEnter 5 spaces if not applicable.");
		myForm.ypostalcode.focus()
		return false;
	}
	// end of ZIP or Postal Code

	// start of Country
	var myCountryList = myForm.ycountry;
	var mySelectedCountryIndex= myCountryList.selectedIndex;
	countryItem = myCountryList.options[mySelectedCountryIndex].value;
	if(countryItem == "*") {
		alert("Choose a country.");
		myCountryList.focus();
		return false;
	}
	if(countryItem == "") {
		alert("Choose a country.");
		myCountryList.focus();
		return false;
	}
	// end of Country

	// start of Url
	if ( myForm.yurl.value.substring(0,7) != "http://" ) {
		alert("You must enter a clickable link.\nThe link must begin with 'http://'");
		myForm.yurl.focus();
		return false;
	}
	// end of Url
*/
	return true
}



function checkCategoryForm(form) {
var myForm = document.forms[0];
var goal = "<?php echo $goal;?>";
if (goal == "Add") {

// Category
	var mySelectList = myForm.category;
	var mySelectedIndex= mySelectList.selectedIndex;
	chosenItem = mySelectList.options[mySelectedIndex].value;
	if(chosenItem == "*") {
		alert("Elija una Especialidad.");
		mySelectList.focus();
		return false;
	}
	if(chosenItem == "") {
		alert("Elija una Especialidad.");
		mySelectList.focus();
		return false;
	}
} // if (goal == "Add"

// Description
//if ( myForm.description.value.length <= 9 ) {
//	alert("La descripción de su despacho debería contener al menos 10 caracteres.");
//	myForm.description.focus();
//	return false;
//	}
}
