// JavaScript Document

//default colors
var cSelectCol = "#00CCFF";
var cUnselectCol =  "#CCCCCC";

//functions for validating form
function checkFormH(form){
	
	//check incidentday incidentmonth incidentyear 
	 if(invalidDate(form.incidentDay,form.incidentMonth,form.incidentYear))
	 {
	 	//date no good (returns are in datelib.js)
		
		
	 	return false;
	 }
	 else {
		 //check if todays date and ask are you sure it occured today????
	 	//date is fine set date in hidden field to make it easier to read for receiptient
		form.incidentFullDate.value = pad(form.incidentDay.value,2,"0",1)+"/"+pad(form.incidentMonth.value,2,"0",1)+"/"+pad(form.incidentYear.value,2,"0",1);	
	 }
	
	//check incidentlocation and otherlocation
	if(form.incidentlocation.value == '0'){
		alert("Please select incident location.")
		form.incidentlocation.focus();
		return false;
	}
	else if(form.incidentlocation.value == 'Other' && form.otherlocation.value.length == 0 ){
		alert("You selected other incident location.  Please fill in other location.")
		form.incidentlocation.focus();
		form.otherlocation.focus();
		return false;
	}

		
	//check incidentnature
	if(form.incidentnature.value == '0'){
	
		alert("Please select the nature of the incident.");
		form.incidentnature.focus();
		return false;	
	}
	
	//check whathappened
	if(form.whathappened.value.length == '0'){
		alert("Please tell us in your own words what happened.");
		form.whathappened.focus();
		return false;	
	}
	
	
	//check relationtohate and otherhate
		if(form.relationtohate.value == '0'){
		alert("Please select your relation to the incident.")
		form.relationtohate.focus();
		return false;
	}
	else if(form.relationtohate.value == 'Other' && form.otherhate.value.length == 0 ){
		alert("You selected other relation to incident.  Please fill in that other relation type.")
		form.relationtohate.focus();
		form.otherhate.focus();
		return false;
	}


	//check injury and injurydescription
	if (checkBoolText(form.injury,form.injurydescription,'Please answer the question. Did you or the victim suffer physical injuries?',
	'You answered yes to: Did you or the victim suffer physical injuries? Please fill in the details of the injury',cSelectCol,cUnselectCol) ==false ){return false};
	
	//check witnesses witnessdescription
		if (checkBoolText(form.witnesses,form.witnessdescription,'Please answer the question. Where there any witnesses?',
	'You answered yes to: Where there any witnesses? Please provide witness details.',cSelectCol,cUnselectCol) ==false ){return false};

	
	//check incidentmotivation and othermotivation
	if(form.incidentmotivation.value == '0'){
		alert("Please select main motivation.")
		form.incidentmotivation.focus();
		return false;
	}
	else if(form.incidentmotivation.value == 'Other' && form.othermotivation.value.length == 0 ){
		alert("You selected other as the main motivation type.  Please fill in that other motivation type.")
		form.incidentmotivation.focus();
		form.othermotivation.focus();
		return false;
	}
	
	//check actalone
	var btn = valButton(form.actalone);
	if (btn == null) {
		alert('Please specify the number of your offenders.');
		colButton(form.actalone,cSelectCol);
		form.elements["actalone"][0].focus();
		return false;
	}
	else {
		//uncolor
		colButton(form.actalone,cUnselectCol);
	}
	
	//check gendertype
	var btn = valButton(form.gendertype);
	if (btn == null) {
		alert('Please specify the gender of the offenders.');
		colButton(form.gendertype,cSelectCol);
		form.elements["gendertype"][0].focus();
		return false;
	}
	else {
		//uncolor
		colButton(form.gendertype,cUnselectCol);
	}

	//check knowthem
	var btn = valButton(form.knowthem);
	if (btn == null) {
		alert('Please answer the question. Do you know them?');
		colButton(form.knowthem,cSelectCol);
		form.elements["knowthem"][0].focus();
		return false;
	}
	else {
		//uncolor
		colButton(form.knowthem,cUnselectCol);
	}
	
	
	//namethem and offendernames
	if (checkBoolText(form.namethem ,form.offendernames,'Please answer the question. Can you name them?',
	'You entered yes to: Can you name them.  Please enter thier names.',cSelectCol,cUnselectCol) ==false ){return false};

	//check vehicle and vehicledescription
	if(checkBoolText(form.vehicle,form.vehicledescription,'Please answer the question.  Did they have a vehicle?',
	'You entered yes to: Did they have a vehicle.  Please enter vehicle description.',cSelectCol,cUnselectCol) == false){return false};

	//check if incidentreported 
	
	//check incidentreportedto and reportedtoother
	//check incidentreported
	var btn = valButton(form.incidentreported);
	if (btn == null) {
		alert('Please answer the question. Was this incident reported to anyone else beside stopracism?');
		colButton(form.incidentreported,cSelectCol);
		form.elements["incidentreported"][0].focus();
		return false;
	}
	else {

		//button is not null then check and see if yes
		if(form.incidentreported[0].checked){
			if(form.incidentreportedto.value == '0'){
				alert("Please select who was informed.")
				form.incidentreportedto.focus();
				return false;
			}
	
			if(form.reportedtoother.value.length == 0 ){
				alert("Please specify who was informed.")
				form.reportedtoother.focus();
				return false;
			}

		}//uncolor

		else {
		  colButton(form.incidentreported,cUnselectCol);

		}
	
	}



   //check contactreporter if selected 
   	//check contactreporter and if yes then

	var btn = valButton(form.contactreporter);
	if (btn == null) {
		alert('Please answer the question. Would you like Stopracism Canada to contact you?');
		colButton(form.contactreporter,cSelectCol);
		form.elements["contactreporter"][0].focus();
		return false;
	}
	else {

		//button is yes then enter something
		if(form.contactreporter[0].checked){
			//must enter name
			if(form.reportername.value.length == 0 ){
				alert("You asked us to contact you, please provide your name.");
				form.reportername.focus();
				return false;
			}

			//must enter either phone or email 	
			
			if(form.reporterphone.value.length == 0 && form.email.value.length == 0 ){
				alert("You selected yes to us contacting you. Please enter either a phone number or email address.");
				form.reporterphone.focus();
				return false;
			}
			else if(isEmail(form.email.value) == false && form.email.value.length >0){
				alert("Invalid Email. Please enter a valid email adress");
				form.email.focus();
				return false;
			}
			else if(form.reporterphone.value.length > 0){
				if(form.reporterphone.value.length < 14){
					alert("Please enter a valid phone number");
					form.reporterphone.focus();
					return false;
				}
			}
		//if phone number is not blank check the right length

		}//uncolor
		else {
		  colButton(form.contactreporter,cUnselectCol);
		}
	}
   
			
}


function enableContactRep(form)
{
form.reportername.disabled = false
form.reporterstate.disabled = false
form.reportercity.disabled = false
form.reporterphone.disabled = false
form.email.disabled = false 
}

function disableContactRep(form)
{
form.reportername.disabled = true
form.reporterstate.disabled = true
form.reportercity.disabled = true
form.reporterphone.disabled = true
form.email.disabled = true
} 

	
