// JavaScript Document

function isEmailAddr (s){ 
	var rv = false
	if ((s == null) || (s.length == 0)) 
       rv = false;
  else {
		var reEmail =/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//reEmail = /.+\@.+\..+$/
		
		rv = reEmail.test(s)
    }
	if(rv){
	return rv
	}else{
		return false
	}
}

function isDate (d){ 
	var rv = false
	if ((d == null) || (d.length == 0)) 
       rv = false;
  else {
		var reDate =/^\d{1,2}(\/|\.)\d{1,2}\1\d{4}$/
		
		rv = reDate.test(d)
    }
	if(rv){
	return rv
	}else{
		return false
	}
}

function hazardVal(theForm){
  if (theForm.dateIdentified.value == ""){
    alert("Please enter the date the hazard was identified.");
    theForm.dateIdentified.focus();
    return (false);
  }  
  if (!isDate(theForm.dateIdentified.value)){
    alert("Please enter a complete date using the format of: dd/mm/yyyy");
    theForm.dateIdentified.focus();
    return (false);
  }
  if (theForm.identifiedBy.value == ""){
    alert("Please enter who identified the hazard.");
    theForm.identifiedBy.focus();
    return (false);
  }
  if (theForm.nextReviewDate.value == ""){
    alert("Please enter the date the hazard will be reviewed.");
    theForm.nextReviewDate.focus();
    return (false);
  }  
  if (!isDate(theForm.nextReviewDate.value)){
    alert("Please enter a complete date using the format of: dd/mm/yyyy");
    theForm.nextReviewDate.focus();
    return (false);
  }
  if (theForm.location.value == ""){
    alert("Please enter the hazard location.");
    theForm.location.focus();
    return (false);
  }
  if (theForm.category.value == ""){
    alert("Please select a hazard category.");
    theForm.category.focus();
    return (false);
  }
  if (theForm.description.value == ""){
    alert("Please enter a hazard description.");
    theForm.description.focus();
    return (false);
  }
  if (theForm.file1.value != ""){
	n = theForm.file1.value
	name = n.substring(n.lastIndexOf('.')+1,n.length).toLowerCase()
	if (name != "jpg"){
		alert("Please only use jpeg files.");
		theForm.file1.focus();
		return (false);
	}
  }
    if (theForm.hazardsAssociated.value == ""){
    alert("Please enter if the hazard is associated with p or a.");
    theForm.hazardsAssociated.focus();
    return (false);
  }
  if (theForm.significant[0].checked || theForm.significant[1].checked){
  }else{
    alert("Please answer if this hazard is significant.");
    theForm.significant[0].focus();
    return (false);
  }
  if (theForm.hazardAction[0].checked || theForm.hazardAction[1].checked || theForm.hazardAction[2].checked){
  }else{
    alert("Please check the actions to be taken for this hazard.");
    theForm.hazardAction[0].focus();
    return (false);
  }
  if ((theForm.hazardAction[0].checked && theForm.hazardAction[1].checked && theForm.hazardAction[2].checked) || (theForm.hazardAction[0].checked && theForm.hazardAction[1].checked) || (theForm.hazardAction[0].checked && theForm.hazardAction[2].checked)){
    alert("You can not check 'Eliminated' and another option.");
    theForm.hazardAction[0].focus();
    return (false);
  }
  if (theForm.actionsToTake.value == ""){
    alert("Please enter the actions to eliminate, isolate or minimise this hazard.");
    theForm.actionsToTake.focus();
    return (false);
  }
  if (theForm.trainingRequired.value == ""){
    alert("Please enter the training required.");
    theForm.trainingRequired.focus();
    return (false);
  }
  if (theForm.ppe.value == ""){
    alert("Please enter any needed personal protective equipment.");
    theForm.ppe.focus();
    return (false);
  }
  if (theForm.safetyEquipment.value == ""){
    alert("Please enter any safety equipment needed.");
    theForm.safetyEquipment.focus();
    return (false);
  }
  if (theForm.monitoring.value == ""){
    alert("Please enter what monitoring is required of people\'s health, behaviour and/or the environment.");
    theForm.monitoring.focus();
    return (false);
  }
  if (theForm.dueDate.value == ""){
    alert("Please enter the due date for completion./n");
    theForm.dueDate.focus();
    return (false);
  }
  if (theForm.responsibility.value == ""){
    alert("Please enter who's responsibility this hazard is.");
    theForm.responsibility.focus();
    return (false);
  }
  if(theForm.copy.value != ""){
	  if (!isEmailAddr(theForm.copy.value)){
		alert("Please enter a complete email address in the form: yourname@yourdomain.com./nOr leave this field blank");
		theForm.copy.focus();
		return (false);
	  }
  }
return (true)
 }
 
 
 function hazardValReview(theForm){
  if (theForm.nextReviewDate.value == ""){
    alert("Please enter the date the hazard will be reviewed.");
    theForm.nextReviewDate.focus();
    return (false);
  }  
  if (!isDate(theForm.nextReviewDate.value)){
    alert("Please enter a complete date using the format of: dd/mm/yyyy");
    theForm.nextReviewDate.focus();
    return (false);
  }
  if (theForm.category.value == ""){
    alert("Please select a hazard category.");
    theForm.category.focus();
    return (false);
  }
  if (theForm.description.value == ""){
    alert("Please enter a hazard description.");
    theForm.description.focus();
    return (false);
  }
  if (theForm.file1.value != ""){
	n = theForm.file1.value
	name = n.substring(n.lastIndexOf('.')+1,n.length).toLowerCase()
	if (name != "jpg"){
		alert("Please only use jpeg files.");
		theForm.file1.focus();
		return (false);
	}
  }
    if (theForm.hazardsAssociated.value == ""){
    alert("Please enter if the hazard is associated with p or a.");
    theForm.hazardsAssociated.focus();
    return (false);
  }
  if (theForm.significant[0].checked || theForm.significant[1].checked){
  }else{
    alert("Please answer if this hazard is significant.");
    theForm.significant[0].focus();
    return (false);
  }
  if (theForm.hazardAction[0].checked || theForm.hazardAction[1].checked || theForm.hazardAction[2].checked){
  }else{
    alert("Please check the actions to be taken for this hazard.");
    theForm.hazardAction[0].focus();
    return (false);
  }
  if ((theForm.hazardAction[0].checked && theForm.hazardAction[1].checked && theForm.hazardAction[2].checked) || (theForm.hazardAction[0].checked && theForm.hazardAction[1].checked) || (theForm.hazardAction[0].checked && theForm.hazardAction[2].checked)){
    alert("You can not check 'Eliminated' and another option.");
    theForm.hazardAction[0].focus();
    return (false);
  }
  if (theForm.actionsToTake.value == ""){
    alert("Please enter the actions to eliminate, isolate or minimise this hazard.");
    theForm.actionsToTake.focus();
    return (false);
  }
  if (theForm.trainingRequired.value == ""){
    alert("Please enter the training required.");
    theForm.trainingRequired.focus();
    return (false);
  }
  if (theForm.ppe.value == ""){
    alert("Please enter any needed personal protective equipment.");
    theForm.ppe.focus();
    return (false);
  }
  if (theForm.safetyEquipment.value == ""){
    alert("Please enter any safety equipment needed.");
    theForm.safetyEquipment.focus();
    return (false);
  }
  if (theForm.monitoring.value == ""){
    alert("Please enter what monitoring is required of people\'s health, behaviour and/or the environment.");
    theForm.monitoring.focus();
    return (false);
  }
  if (theForm.dueDate.value == ""){
    alert("Please enter the due date for completion./n");
    theForm.dueDate.focus();
    return (false);
  }
  if (theForm.responsibility.value == ""){
    alert("Please enter who's responsibility this hazard is.");
    theForm.responsibility.focus();
    return (false);
  }
  if(theForm.copy.value != ""){
	  if (!isEmailAddr(theForm.copy.value)){
		alert("Please enter a complete email address in the form: yourname@yourdomain.com./nOr leave this field blank");
		theForm.copy.focus();
		return (false);
	  }
  }
return (true)
 }


 var winl = (screen.width - 400) / 2;
 var wint = (screen.height) / 2;
 
 
function email(num){
var popUpWin=0
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open('email.asp?hid='+num, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=no,resizable=no,copyhistory=yes,width=400,height=100,left='+winl+', top='+(wint-100)+',screenX='+winl+',screenY='+(wint-100)+'');
}

function question(num, width, height){
var popUpWin=0
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open('indexQuestion.asp?pageID='+num, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height='+height+',left='+winl+', top='+(wint-height)+',screenX='+winl+',screenY='+(wint-height)+'');
}

function client(num, id){
var popUpWin=0
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(num+'?id='+id, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=no,resizable=no,copyhistory=yes,width=400,height=400,left='+winl+', top='+(wint-200)+',screenX='+winl+',screenY='+(wint-200)+'');
}


function register(theForm){
 if (theForm.company.value == ""){
    alert("Please enter your company name.");
    theForm.company.focus();
    return (false);
  }  
  if (theForm.contactName.value == ""){
    alert("Please enter your first name.");
    theForm.contactName.focus();
    return (false);
  }
  if (theForm.lastName.value == ""){
    alert("Please enter your surname name.");
    theForm.lastName.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email.value)){
	alert("Please enter a complete email address in the form: yourname@yourdomain.com./nOr leave this field blank");
	theForm.email.focus();
	return (false);
  }
  if (theForm.phone.value == ""){
    alert("Please enter a contact phone number.");
    theForm.phone.focus();
    return (false);
  }
return (true)
 }

