// JavaScript Document
var errorMessage = "Our system has found the following error(s). \n\n";


function validateEmailStructure (data) {

	var foundAc = 0;
	var foundDot = 0;
	var customError = "E-mail address is in an incorrect format. Please try again \n";
	var ok = 0;
	
	for (var i=0; i <= data.length; i++) {
	
		if(data.charAt(i) == "@") {
		
			foundAc = 1;
			
		} else if(data.charAt(i) == ".") {
	    
			foundDot = 1;
		
		}
	}//end for
	
	var errorSummary = 0;
	errorSummary = foundAc + foundDot;
	
	///alert("running inside js file");
	
	if(errorSummary < 2) {
	
		errorMessage += customError;
		//formOK = false;
		return false;
		//ok = 1;
		//return ok;
		//alert(errorMessage);
	} else {
	
	
		return true;
		//ok = 0;
		//return ok;
	}//end if
	
	

}//end function

function validateEmailBoolean (data) {

	var foundAc = 0;
	var foundDot = 0;
	var customError = "E-mail address is in an incorrect format. Please try again \n";
	var ok = 0;
	
	for (var i=0; i <= data.length; i++) {
	
		if(data.charAt(i) == "@") {
		
			foundAc = 1;
			
		} else if(data.charAt(i) == ".") {
		
			foundDot = 1;
		
		}
	}//end for
	
	var errorSummary = 0;
	errorSummary = foundAc + foundDot;
	
	///alert("running inside js file");
	
	if(errorSummary < 2) {
	
		errorMessage += customError;
		//formOK = false;
		return false;
		//ok = 1;
		//return ok;
		//alert(errorMessage);
	} else {
	
	
		return true;
		//ok = 0;
		//return ok;
	}//end if
	
	

}//end function

function matchData(data1, data2, message) {

	var ok = 0;
	
	if (data1 != data2) {
	
		addMessage(message);
		//return false;
		ok = 1;
		
	} 
	
	return ok;
}

function isAMatch(data1, data2, message) { 

	var ok = true;
	
	if (data1 != data2) {
	
		addMessage(message);
		//return false;
		ok = false;
		
	} 
	
	return ok;
}

	
function addMessage (message) {
	
		errorMessage += message + " \n";
}


function chekcWeMeReCDomainMail (email) {

	//check that registered email does not belong to the @wemerec.com
	//if email comes form this domain, it indicates that this is the first time user
	//whoes email address has been generated automatically by the system
	
	//var notFound  = true;
	 var notFound  = 0;
	
	if (email.indexOf('@wemerec.com') != -1) {
		
		//notFound = false;
		notFound = 1;
		addMessage("Please enter an alternative email address");
	
	}
		
	//alert("Domaincheck : " + notFound);	
		
	return notFound;

} //end funcion


function checkSecurityQuestions () {

	var securityQ = document.getElementsByName("securityq[]");
	var securityA = document.getElementsByName("securitya[]");
	var found = 0;
	
	for (var i=0; i < securityQ.length; i++) {
		
		if(securityQ[i].value == "" || securityA[i].value == "") {
			
			found = 1;
			break;
				
		}
		
	}
	
	if(securityQ[0].value == securityQ[1].value) {
	
		found = 2;
	}
	
	if(found == 1) {
		
		
		addMessage("Please answer all of the security questions before proceeding");
		
	} 
	
	if(found == 2) {
		
		addMessage("You cannot answer the same security question. Please select an alternative.");
	}
	//alert(found);
	return found;
	
}


