/**Canadian Forms**/


function getActionPath(){
	var location = window.location.href;
	var url = String(document.location).split('//');
	var urlArr = url[1].split('/');


	if(location.indexOf("/en/") != -1){
		return	"/" + urlArr[1] + "/genworth/ca/en/";
	} 

	else if(location.indexOf("/fr/") != -1){
		return	"/" + urlArr[1] + "/genworth/ca/fr/";
	}
}


/*
*
*Newsletter signup Form
*
*/



// Validate form
function validate() {

	AlertMessage = "";
	RequiredFields = "Name,CompanyName,Address,Email,Phone";
	
	RequiredFields = RequiredFields.split(",");
	LengthValue = RequiredFields.length;
	for (LoopCount=0;LoopCount<LengthValue;LoopCount++){
		if (document.NewsletterSignUp[RequiredFields[LoopCount]].value == "") {
			AlertMessage = AlertMessage + "The " + document.NewsletterSignUp[RequiredFields[LoopCount]].name + " field is required.\n";
		}
	}
	
	if (AlertMessage != "") {
		alert(AlertMessage);
	} else {
		document.NewsletterSignUp.submit();
	}
	
}


/*
*
*French Newsletter signup Form
*
*/

// Validate form
function validateFr() {

	AlertMessage = "";
	RequiredFields = "Nom,Compagnie,Adresse,Courriel,Telephone";

	RequiredFields = RequiredFields.split(",");
	LengthValue = RequiredFields.length;
	for (LoopCount=0;LoopCount<LengthValue;LoopCount++){
		
		if (document.NewsletterSignUp[RequiredFields[LoopCount]].value == "") {
			AlertMessage = AlertMessage + "Le champ " + document.NewsletterSignUp[RequiredFields[LoopCount]].name + " est requis.\n";
		}
	}
	
	if (AlertMessage != "") {
		alert(AlertMessage);
	} else {
		document.NewsletterSignUp.submit();
	}
	
}




/*
*
* (English and French) Appraisers Form
*
*/



function PopulateTable(TargetRegion) {
	if (TargetRegion == "AB") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_AB.html";
 	}
	if (TargetRegion == "BC") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_BC.html";
 	}
	if (TargetRegion == "MB") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_MB.html";
 	}
	if (TargetRegion == "NB") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_NB.html";
 	}
	if (TargetRegion == "NF") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_NF.html";
 	}
	if (TargetRegion == "NS") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_NS.html";
 	}
	if (TargetRegion == "ON") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_ON.html";
 	}
	if (TargetRegion == "PEI") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_PEI.html";
 	}
	if (TargetRegion == "SK") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_SK.html";
 	}
	if (TargetRegion == "QC") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_QC.html";
 	}
	if (TargetRegion == "YT") { 
		window.location=getActionPath() + "tools/resources/appointed_appraisers/appraisers_YT.html";
 	}
}




/*
*
* (English and French) Energy Efficient form 
*
*/

function getPDFActionPath(){
	var url = String(document.location).split('//');
	var urlArr = url[1].split('/');

	return	"/" + urlArr[1] + "/etc/medialib/genworth_ca/";
}

function downloadPDF(){
	var pdfPath=getPDFActionPath();
	pdfPath = pdfPath + document.GetEEHPForm.EEHPQuickLink.options[document.GetEEHPForm.EEHPQuickLink.selectedIndex].value;
	window.open(pdfPath);
}


/*
*
*Event Registration
*
*/


// This function is run when a course is selected
function CheckCourse(aCourse) {
  
  if (aCourse == "Shut the door on fraud - October 21,2008" || aCourse ==  "Shut the door on fraud - October 28,2008") 
  {
  	alert("There are no more spaces available for this course.");
	document.HPRegister.course.options.selectedIndex =0; 
  }
  
  else if (aCourse == "Housing Market/Impact of new legislation - October 8,2008" )
  {alert("Please contact your Genworth Account Manager regarding sign-up for this event.");
	document.HPRegister.course.options.selectedIndex =0; }
}


// This function is run when a region is selected
function PopulateCourses(TargetRegion) {
NoRegionSelectedPrompt = "Please Select A Region" // If the user selects the first option, and not a specific region
RegionSelectPrompt = "Select Your Course" // This will be the first option in the course pulldown no matter the region


// Add courses where the email should be sent to another address seperate from the region recipient
// Course specific emails - as: course name|,|email
// The course name must match the drop down exactly
CourseSpecificEmails = new Array();


//Vee:Veemal.Ramburn@genworth.com
//Angela Baggio:angela.baggio@genworth.com



//LIST OF SPECIFIC EMAILS STARTS HERE

CourseSpecificEmails[0]="CBOC Report, Credit Reports, Genworth Overview (Kitchener) - 03/05/09|,|angela.baggio@genworth.com"
CourseSpecificEmails[1]="Genworth Lender/Broker Development Day (Ottawa) - 04/08/09|,|andrea.haines@genworth.com"
CourseSpecificEmails[2]="Negotiation Skills Training (Halifax) - 04/30/09|,|chris.johnson@genworth.com"
CourseSpecificEmails[3]="Time Management/Marketing Ideas Training (St. Johns) - 06/03/09|,|Christopher.Ryan@genworth.com"

ExceptionCourses = new Array();
ExceptionEmails = new Array();

LengthValue = CourseSpecificEmails.length
for (LoopCount=0;LoopCount<LengthValue;LoopCount++){

	ExceptionSplit = CourseSpecificEmails[LoopCount].split("|,|")
	ExceptionCourses[LoopCount] = 	ExceptionSplit[0]
	ExceptionEmails[LoopCount] = 	ExceptionSplit[1]
	//alert(ExceptionCourses[LoopCount]);
	//alert(ExceptionEmails[LoopCount]);
	
}



// For every regfon you must set an array, and populate the first option
OnLineCourse = new Array(); OnLineCourse[0] = RegionSelectPrompt;
AtlanticCourse = new Array(); AtlanticCourse[0] = RegionSelectPrompt;
GTACourse = new Array(); GTACourse[0] = RegionSelectPrompt;
OntarioCourse = new Array(); OntarioCourse[0] = RegionSelectPrompt;
PacificCourse = new Array(); PacificCourse[0] = RegionSelectPrompt;
PrairiesCourse = new Array(); PrairiesCourse[0] = RegionSelectPrompt;
QuebecCourse = new Array(); QuebecCourse[0] = RegionSelectPrompt;



AtlanticCourse[1] = "Negotiation Skills Training (Halifax) - 04/30/09"
AtlanticCourse[2] = "Time Management/Marketing Ideas Training (St. Johns) - 06/03/09"


GTACourse[1] = "Economic And Condo Market Update - October 22,2009"


OntarioCourse[1]="CBOC Report, Credit Reports, Genworth Overview (Kitchener) - 03/05/09"
OntarioCourse[2]="Genworth Lender/Broker Development Day (Ottawa) - 04/08/09"


//PacificCourse[1] = "Networking - 02/27/08"


//PrairiesCourse[1] = "CIMBL - Marketing Ideas - Calgary - 14/11/05"

//QuebecCourse[1] = "M\xE9dias Sociaux: Comprendre avant d'entreprendre - le 15 novembre 2011"
//QuebecCourse[2] = "M\xE9dias Sociaux: Comprendre avant d'entreprendre - le 30 novembre 2011"
//QuebecCourse[3] = "M\xE9dias Sociaux: Comprendre avant d'entreprendre - le 1er décembre 2011"

  // First we have to clear the target select box, so we set all of the options to null
  //LengthValueA = document.HPRegister.course.length-1
  LengthValueA = document.HPRegister.course.length
 //alert(LengthValueA); // for development - 
  for (LoopCountA=1;LoopCountA<LengthValueA;LoopCountA++){ // We start from 1 because the first is a comment
  	//alert(LoopCountA+":"+document.HPRegister.course.options[1].value); // for development - 
  	document.HPRegister.course.options[1] = null
  }
  
  
  if (TargetRegion != "") { // If the first item HAS NOT been selected
  
    	// We use the selected value to identify the array we need to pull from
	eval("LengthValueB="+TargetRegion+"Course.length")
	
	for (LoopCountB=0;LoopCountB<LengthValueB;LoopCountB++){

		// We loop through all the relevant courses and create a new option for it.
		eval("document.HPRegister.course.options[LoopCountB] = new  Option("+TargetRegion+"Course[LoopCountB],"+TargetRegion+"Course[LoopCountB])")
	
	}
  } else { // if the user select the first option, we ask them to select a regiom
  	alert(NoRegionSelectedPrompt)
  }
document.HPRegister.course.options.selectedIndex =0 //select nothing to start with L.T. Jan 09/08
}




function SubmitTheForm() {

	
ValidationMessage_InvalidEmail = "Please enter a valid email address." // If the user has entered an email address without @ or .
ValidationMessage_EmptyEmail = "Please enter your email address." // If the user has not entered their email address.
ValidationMessage_EmptyCourse = "Please select your course." // If the user has not entered their email address.

ValidationMessage_EmptyCompany = "Employer's Name is a mandatory field." 
ValidationMessage_EmptyProvince ="Province is a mandatory field."
ValidationMessage_EmptyPosition= "Position is a mandatory field." 
ValidationMessage_EmptyFirstName= "Please enter your first name." 
ValidationMessage_EmptyLastName= "Please enter your last name." 

	//alert("SubmitTheForm Function Starts"); // for development - 
	
	if (document.HPRegister.Email_Address.value == "") {
		alert(ValidationMessage_EmptyEmail);
	} else if (IsEmail(document.HPRegister.Email_Address.value) == false) {
		alert(ValidationMessage_InvalidEmail);
	} else if (document.HPRegister.course.options.selectedIndex == 0) {
		alert(ValidationMessage_EmptyCourse);
	}

//	}else if (document.HPRegister.Employers_Name.value == "") {
//		alert(ValidationMessage_EmptyCompany); 
   else if (document.HPRegister.Province.value == "na") {
		alert(ValidationMessage_EmptyProvince); 
	}	
//	} else if (document.HPRegister.Position.value == "") {
//		alert(ValidationMessage_EmptyPosition); 

	 else if (document.HPRegister.First_Name.value == "") {
		alert(ValidationMessage_EmptyFirstName); 
	} else if (document.HPRegister.Last_Name.value == "") {
		alert(ValidationMessage_EmptyLastName); 
	} else {
		
		SelectedCourse = document.HPRegister.course.selectedIndex
		LengthValue = ExceptionCourses.length
		for (LoopCount=0;LoopCount<LengthValue;LoopCount++){
	
			if (ExceptionCourses[LoopCount] == document.HPRegister.course[SelectedCourse].value) {
				//alert(ExceptionEmails[LoopCount]); // for development - 
				document.HPRegister.EmailException.value = ExceptionEmails[LoopCount]
			}
			
		}
		
		document.HPRegister.submit()
	}

	
}



function IsEmail(TargetEmail) {
	
	TargetEmail = TargetEmail + " "
	
	//alert("IsEmail Function Starts"); // for development - 
	
	//alert(TargetEmail.indexOf("@")); // for development - 
	//alert(TargetEmail.indexOf("."));
	
	if (TargetEmail.indexOf("@") == -1 || TargetEmail.indexOf(".") == -1) {
		
		return false
	} else {
		return true
	}
}








/*
*
*French Event Registration
*
*/



// This function is run when a course is selected
function CheckCourseFr(aCourse) {
  
  
if (aCourse == "Fermez la porte a la fraude - 21 octobre 2008" || aCourse == "Fermez la porte a la fraude - 28 octobre 2008")
  {
  	alert("Enregistrement est complet.");
	document.HPRegister.course.options.selectedIndex =0; 
  }

}

// This function is run when a region is selected
function PopulateCoursesFr(TargetRegion) {


RegionSelectPrompt = "S\351lectionnez votre cours" // This will be the first option in the course pulldown no matter the region
NoRegionSelectedPrompt = "Veuillez s\351lectionner une r\351gion" // If the user selects the first option, and not a specific region

// Add courses where the email should be sent to another address seperate from the region recipient
// Course specific emails - as: course name|,|email
// The course name must match the drop down exactly
CourseSpecificEmails = new Array();




CourseSpecificEmails[0] ="Fermez la porte \340 la fraude - 21 octobre 2008|,|annie.carpentier@genworth.com"
CourseSpecificEmails[1] ="Fermez la porte \340 la fraude - 28 octobre 2008|,|annie.carpentier@genworth.com"




ExceptionCourses = new Array();
ExceptionEmails = new Array();

LengthValue = CourseSpecificEmails.length
for (LoopCount=0;LoopCount<LengthValue;LoopCount++){

	ExceptionSplit = CourseSpecificEmails[LoopCount].split("|,|")
	ExceptionCourses[LoopCount] = 	ExceptionSplit[0]
	ExceptionEmails[LoopCount] = 	ExceptionSplit[1]

}



// For every region you must set an array, and populate the first option
// For every region you must set a string array (this is only for french form) the string array will be the value on the option combo box
// the Course String is used to have the name of the course without any special characters, so we can compare that String on the sendRegMail.jsp
OnLineCourse = new Array(); OnLineCourse[0] = RegionSelectPrompt;
AtlanticCourse = new Array(); AtlanticCourse[0] = RegionSelectPrompt;
GTACourse = new Array(); GTACourse[0] = RegionSelectPrompt;
OntarioCourse = new Array(); OntarioCourse[0] = RegionSelectPrompt;
PacificCourse = new Array(); PacificCourse[0] = RegionSelectPrompt;
PrairiesCourse = new Array(); PrairiesCourse[0] = RegionSelectPrompt;
QuebecCourse = new Array(); QuebecCourse[0] = RegionSelectPrompt;


// Now we set variables with all the available courses


//QuebecCourse[1] = "M\xE9dias Sociaux: Comprendre avant d'entreprendre - le 15 novembre 2011"
//QuebecCourse[2] = "M\xE9dias Sociaux: Comprendre avant d'entreprendre - le 30 novembre 2011"
//QuebecCourse[3] = "M\xE9dias Sociaux: Comprendre avant d'entreprendre - le 1er d\xE9cembre 2011"

  // First we have to clear the target select box, so we set all of the options to null
  LengthValueA = document.HPRegister.course.length-1

  for (LoopCountA=1;LoopCountA<LengthValueA;LoopCountA++){ // We start from 1 because the first is a comment
  	document.HPRegister.course.options[1] = null
  }
  
  
  if (TargetRegion != "") { // If the first item HAS NOT been selected

	eval("LengthValueB="+TargetRegion+"Course.length")
	for (LoopCountB=0;LoopCountB<LengthValueB;LoopCountB++){

		// We loop through all the relevant courses and create a new option for it.
		eval("document.HPRegister.course.options[LoopCountB] = new  Option("+TargetRegion+"Course[LoopCountB],"+TargetRegion+"Course[LoopCountB])")
		
	
	}
  } else { // if the user select the first option, we ask them to select a regiom
  	alert(NoRegionSelectedPrompt)
  }

}

function SubmitTheFormFr() {

	ValidationMessage_InvalidEmail = "Veuillez entrer une adresse \351lectronique valide." // If the user has entered an email address without @ or .
	ValidationMessage_EmptyEmail = "Veuillez entrer votre adresse \351lectronique." // If the user has not entered their email address.
	ValidationMessage_EmptyCourse = "Veuillez selectionner votre cours." // If the user has not entered their email address.

	ValidationMessage_EmptyCompany = "Employer's Name is a mandatory field." 
	ValidationMessage_EmptyProvince ="Province is a mandatory field."
	ValidationMessage_EmptyPosition= "Position is a mandatory field." 
	ValidationMessage_EmptyFirstName= "Please enter your first name." 
	ValidationMessage_EmptyLastName= "Please enter your last name." 

	//alert("SubmitTheForm Function Starts"); // for development - 
	
	if (document.HPRegister.Email_Address.value == "") {
		showFrErrors();
	} else if (IsEmail(document.HPRegister.Email_Address.value) == false) {
		showFrErrors();
	} else if (document.HPRegister.course.options.selectedIndex == 0) {
		showFrErrors();

//	}
//	else if (document.HPRegister.Employers_Name.value == "") {
//		alert(ValidationMessage_EmptyCompany); 
	} else if (document.HPRegister.Province.value == "na") {
		showFrErrors();
//	} else if (document.HPRegister.Position.value == "") {
//		alert(ValidationMessage_EmptyPosition); 

	} else if (document.HPRegister.First_Name.value == "") {
		showFrErrors(); 
	} else if (document.HPRegister.Last_Name.value == "") {
		showFrErrors();
		
	} else {
		SelectedCourse = document.HPRegister.course.selectedIndex
		LengthValue = ExceptionCourses.length
		for (LoopCount=0;LoopCount<LengthValue;LoopCount++){
	
			if (ExceptionCourses[LoopCount] == document.HPRegister.course[SelectedCourse].value) {
				//alert(ExceptionEmails[LoopCount]); // for development - 
				document.HPRegister.EmailException.value = ExceptionEmails[LoopCount]
			}
			
		}		
		document.HPRegister.submit()
	}
}

function showFrErrors(){
   var genericError = "SVP vous assurer de fournir l'information requise dans les champs"+
                   " obligatoires identifi\351s par un ast\351risque : R\351gion, Cours, Pr\351nom, Nom de"+
                   " famille, Province et Adresse courriel."				   
	alert(genericError);
}




/*
*
*Event Registration for ELearning page
*
*/

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}




function SubmitTheELearningForm() {

	ValidationMessage_InvalidEmail = "Please enter a valid email address." // If the user has entered an email address without @ or .
	ValidationMessage_EmptyEmail = "Please enter your email address." // If the user has not entered their email address.
	ValidationMessage_EmptyCourse = "Please select your course." // If the user has not entered their email address.

	ValidationMessage_EmptyCompany = "Employer's Name is a mandatory field." 
	ValidationMessage_EmptyProvince ="Please select a Province."
	ValidationMessage_EmptyPosition= "Please enter your Position." 
	ValidationMessage_EmptyFirstName= "Please enter your first name." 
	ValidationMessage_EmptyLastName= "Please enter your last name." 

	//alert("SubmitTheForm Function Starts"); // for development - 
	if (document.HPRegister.Email_Address.value == "") {
		alert(ValidationMessage_EmptyEmail);
	} else if (IsEmail(document.HPRegister.Email_Address.value) == false) {
		alert(ValidationMessage_InvalidEmail);
	} 
	else if (trim(document.HPRegister.First_Name.value) == "") {
		alert(ValidationMessage_EmptyFirstName);
	}
	else if (trim(document.HPRegister.Last_Name.value) == "") {
		alert(ValidationMessage_EmptyFirstName);
	}	
    else if (trim(document.HPRegister.Employers_Name.value) == "") {
		alert(ValidationMessage_EmptyCompany); 
	} 
	else if (document.HPRegister.Province.value == "na") {
		alert(ValidationMessage_EmptyProvince); 
	} 
	else if (trim(document.HPRegister.Position.value) == "") {
		alert(ValidationMessage_EmptyPosition); 
	}
	
	else {
		document.HPRegister.submit()
	}
}



/*
*
*French Event Registration for ELearning page
*
*/



function SubmitTheELearningFormFr() {


	ValidationMessage_InvalidEmail = "Veuillez entrer une adresse \351lectronique valide."; // If the user has entered an email address without @ or .
	ValidationMessage_EmptyEmail = "Veuillez entrer votre adresse \351lectronique."; // If the user has not entered their email address.
	ValidationMessage_EmptyFirstName ="Veuillez entrer votre Prenom.";
	ValidationMessage_EmptyLastName ="Veuillez entrer votre Nom de famille."

	ValidationMessage_EmptyCompany = "Nom de l'employeur est un champ obligatoire." 
	ValidationMessage_EmptyProvince ="Veuillez SVP selectionner une province."
	ValidationMessage_EmptyPosition= "Veuillez SVP entrer votre poste dans la compagnie." 



	//alert("SubmitTheForm Function Starts"); // for development - 
	if (document.HPRegister.Email_Address.value == "") {
		alert(ValidationMessage_EmptyEmail);
	} else if (IsEmail(document.HPRegister.Email_Address.value) == false) {
		alert(ValidationMessage_InvalidEmail);
	} 
	
	else if (trim(document.HPRegister.First_Name.value) == "") {
		alert(ValidationMessage_EmptyFirstName);
	}
	else if (trim(document.HPRegister.Last_Name.value) == "") {
		alert(ValidationMessage_EmptyLastName);
	}
    else if (trim(document.HPRegister.Employers_Name.value) == "") {
		alert(ValidationMessage_EmptyCompany); 
	} 
	else if (document.HPRegister.Province.value == "na") {
		alert(ValidationMessage_EmptyProvince); 
	} 
	else if (trim(document.HPRegister.Position.value) == "") {
		alert(ValidationMessage_EmptyPosition); 
	}

	else {
		document.HPRegister.submit()
	}
}



