/*------------------ global js (Front End) ----------------------------*/

/*--------------- Change style css ----------------------*/
function celOver(obj) {
  var s = obj.className;
  s = s.replace(/-over/g, "");
  obj.className = s+"-over";
}

function celOut(obj) {
  var s = obj.className;
  s = s.replace(/-over/g, "");
  obj.className = s;
}


/*------------- Search field ----------------*/
function searchinfo() {
  var errors = '';
  var form = document.SearchFrm
  if (form.searchfield.value == "Search site" || form.searchfield.value == "") {
    errors = "True";
  }
  if (errors) {
    //alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}

function searchfocus(val) {
  if (val.value == "Search site") {
    val.value = "";
  }
}

function searchblur(val) {
  if (val.value == "") {
    val.value = "Search site";
  }
}

function verifEmail(chp) {
	
  var returnString = "";
  
  if (chp.value.length == 0) {
    returnString += "- Email is required\n";
  } else {
	regex = new RegExp("^[a-z0-9_]([.-]?[a-z0-9_]+)+@[a-z0-9_]([.-]?[a-z0-9_]+)+\.([a-z]{2,4}|[a-z]{6})$", "gi");
	if (!regex.exec(chp.value)) {
       returnString += "- Email is invalid\n";
	}				
  }
  return returnString
}

function chiffreok(valeur) {
	if (isNaN(valeur)) {
		return false;
	} else {
		return true;
	}
}


/*------------------end global js----------------------------*/

function MM_validateClass() {

  var form = document.form1;
  var errors = "";
  
  if (form.SectionID.value == 1) {
	errors += "- Section is required\n";
  }

  if (form.ClassifiedStart.value.length == 0) {
	errors += "- Start Date is required\n";
  }

  if (form.ClassifiedPeriod.value.length == 0) {
	errors += "- Weeks to include is required\n";
  } else {
    if (!chiffreok(form.ClassifiedPeriod.value)) {
	  errors += "- Weeks to include must be a Number\n";
    }
  }

  if (form.ClassifiedText.value.length == 0) {
	errors += "- Text for Classified is required\n";
  }

  if (form.ClassifiedNumber.value.length == 0) {
	errors += "- Contact Number for Advert is required\n";
  }

  if (form.ClassifiedName.value.length == 0) {
	errors += "- Your Name is required\n";
  }

  if (form.ClassifiedPhone.value.length == 0) {
	errors += "- Phone is required\n";
  }

  if (form.ClassifiedAddress.value.length == 0) {
	errors += "- Address is required\n";
  }

  errors += verifEmail(form.ClassifiedEmail);

  if (errors) {
    alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');

}
