// Javascript validation functions
// http://www.designplace.org/


//function to check empty fields

function isEmpty(strfield1, strfield2, strfield3) {


//change "field1, field2 and field3" to your field names
strfield1 = document.forms[0].name.value
strfield2 = document.forms[0].city.value
strfield3 = document.forms[0].item1.value
strfield4 = document.forms[0].item1specs.value

  //Name Field
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    document.getElementById("sell-it-error_name").style.display = "block";
		return false;
    }

  //City Field
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
		{
		document.getElementById("sell-it-error_city").style.display = "block";
		return false
    }

  //Item 1 field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    document.getElementById("sell-it-error_item1").style.display = "block";
    return false;
    }

	//Item 1 Specifics Field
		if (strfield4 == "" || strfield4 == null || strfield4.charAt(0) == ' ')
		{
		document.getElementById("sell-it-error_item1specs").style.display = "block";
		return false;
		}
    return true;
}


//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      document.getElementById("sell-it-error_email").style.display = "block";
      return false;
    } 
    return true; 
}


//Check for Valid Phone Number
function isValidPhone(strPhone){
	validRegExp = (/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
	strPhone = document.forms[0].number.value;

	if (strPhone.search(validRegExp) == -1)
	{
		document.getElementById("sell-it-error_number").style.display = "block";
		return false;
	}
	return true;
}


//function that performs all functions, defined in the onsubmit event handler

function check(form){
if (isEmpty(form.name)){
  if (isEmpty(form.city)){
//		if (isValidPhone(form.number)){
			if (isValidEmail(form.email)){
				if (isEmpty(form.item1)){
					if (isEmpty(form.item1specs)){
		  return true;
					}
				}
			}
//	  }
  }
}
return false;
}
