var submitcount=0;
//var _form = document.frmMain;
// quick browser tests
//var ns4 = (document.layers) ? true : false;
//var ie4 = (document.all && !document.getElementById) ? true : false;
//var ie5 = (document.all && document.getElementById) ? true : false;
//var ns6 = (!document.all && document.getElementById) ? true : false;

function ResetForm() {
 	var _form = document.frmMain;
    var _type = _form.ctrlNewReg_lstType;
    var _emp = document.getElementById('emp');
    var _emptodo = document.getElementById('emptodo');
    var _js = document.getElementById('js');
    var _jstodo =document.getElementById('jstodo');
	if (_type.value == JS) {
		_emp.style.display = "none";
		_emptodo.style.display = "none";
		_js.style.display = "";
		_jstodo.style.display = "";
	    }
	else if (_type.value == Emp) {
		_emp.style.display = "";
		_emptodo.style.display = "";
		_js.style.display = "none";
		_jstodo.style.display = "none";
	    }
	else {
		_emp.style.display = "none";
		_emptodo.style.display = "none";
		_js.style.display = "none";
		_jstodo.style.display = "none";
	}
}

function resetControl(obj) {
	obj.style.backgroundColor = "#D9E0E7";
	//if ((ie4 || ie5) ) obj.style.backgroundColor = "#D9E0E7";
	//else if (ns4) obj.style.backgroundColor = "#D9E0E7";
}

function checkform(btnWaiter) {
	var _form = document.frmMain;
    var errors = "";
    var _type = _form.ctrlNewReg_lstType;
    var _pwd1 = _form.ctrlNewReg_txtPWD1;
    var _pwd2 = _form.ctrlNewReg_txtPWD2;
    var _name = _form.ctrlNewReg_txtName;
    var _lastname = _form.ctrlNewReg_txtLastName;
    var _address1 = _form.ctrlNewReg_txtAddress1;
    var _city = _form.ctrlNewReg_txtCity;
    var _province = _form.ctrlNewReg_lstProvince;
    var _country = _form.ctrlNewReg_lstCountry;
    var _postal =  _form.ctrlNewReg_txtPostalCode;
    var _phone1 = _form.ctrlNewReg_txtPhone1;
    var _phone2 = _form.ctrlNewReg_txtPhone2;
    var _restext = _form.ctrlNewReg_restext;
    if (win_ie_ver >= 5.5) {
		var TextOnly = editor_getText('ctrlNewReg:restext');
		//var TextOnly = editor_getText(_restext);
		_form.ctrlNewReg_body.value = TextOnly;
		//alert(TextOnly);
    }
    if ( _type.value == "0" ) {errors += "Please select a 'Registration Type'\n"; _type.style.backgroundColor = "yellow";}
    if ( !_name.value ) {errors += "Please enter your 'First name'\n"; _name.style.backgroundColor = "yellow";}
    //if ( _name.value && _name.value.length < 1 ) {errors += "'First name' must be at least 4 characters.\n"; _name.style.backgroundColor = "yellow";}
    if ( !_lastname.value ) {errors += "Please enter your 'Last name'\n"; _lastname.style.backgroundColor = "yellow";}
    if ( _lastname.value && _lastname.value.length < 3 ) {errors += "'Last name' must be at least 3 characters.\n"; _lastname.style.backgroundColor = "yellow";}
    if ( !_address1.value ) {errors += "Please enter your 'address'\n"; _address1.style.backgroundColor = "yellow";}
    if ( _address1.value && _address1.value.length < 5 ) {errors += "'address1' must be at least 5 characters.\n"; _address1.style.backgroundColor = "yellow";}
    if ( !_city.value ) {errors += "Please enter your 'City'\n"; _city.style.backgroundColor = "yellow";}
    if ( _city.value && _city.value.length < 5 ) {errors += "'City' must be at least 5 characters.\n"; _city.style.backgroundColor = "yellow";}
    if ( _province.value == "0" && _country.value == "1" ) {errors += "Please select a 'Province'\n"; _province.style.backgroundColor = "yellow";}
    if ( _country.value == "0" ) {errors += "Please enter a 'Country'\n"; _country.style.backgroundColor = "yellow";}
    if ( !_phone1.value ) {errors += "Please enter your 'phone number'\n"; _phone1.style.backgroundColor = "yellow";}
    if ( _phone1.value && _phone1.value.length < 13 ) {errors += "The 'Phone1' field is not valid Example: (999)999-9999\n"; _phone1.style.backgroundColor = "yellow";}
    if ( _phone2.value && _phone2.value.length < 13) {errors += "The 'Phone2' field is not valid Example: (999)999-9999\n"; _phone2.style.backgroundColor = "yellow";}
    if ( !_postal.value ) {errors += "Please enter your 'postal code'\n"; _postal.style.backgroundColor = "yellow";}
    if ( _postal.value && _postal.value.length < 6 ) {errors += "The 'postal code' field is not valid Example: X9X9X9\n"; _postal.style.backgroundColor = "yellow";}
    //if ( _form.ctrlNewReg_lstSecurityClearance.value == "0" ) errors += "Please enter your 'Security clearance'\n";
    if ( _form.ctrlNewReg_lstSecurityQuestion.value == "0" ) {errors += "Please select your 'Password security question'\n"; _form.ctrlNewReg_lstSecurityQuestion.style.backgroundColor = "yellow";}
    if ( !_form.ctrlNewReg_txtPwdSecurityAnswer.value ) {errors += "Please enter the 'Security question answer'\n";_form.ctrlNewReg_txtPwdSecurityAnswer.style.backgroundColor = "yellow";}
    // Job Seekers check
    if ( _type.value == JS && _form.ctrlNewReg_lstSecurityClearance.value == "0" ) {errors += "Please enter your 'Security clearance'\n";_form.ctrlNewReg_lstSecurityClearance.style.backgroundColor = "yellow";}
    if ( _type.value == JS && _form.ctrlNewReg_engprof.value == "0" ) {errors += "Please enter your 'English' proficiency level\n";_form.ctrlNewReg_engprof.style.backgroundColor = "yellow";}
    if ( _type.value == JS && _form.ctrlNewReg_frprof.value == "0" ) {errors += "Please enter your 'French' proficiency level\n";_form.ctrlNewReg_frprof.style.backgroundColor = "yellow";}
    //if ( _type.value == JS && !_form.ctrlNewReg_restext.value ) {errors += "Please copy and Paste your resume\n";_form.ctrlNewReg_restext.style.backgroundColor = "yellow";}
    //if ( _type.value == JS && _form.ctrlNewReg_restext.value && _form.ctrlNewReg_restext.value.length < 250) {errors += "Your resume is incomplete!\nMust contain a least 250 characters\n";_form.ctrlNewReg_restext.style.backgroundColor = "yellow";}


    if ( _type.value == JS && !_restext.value ) {errors += "Please copy and Paste your resume\n";_form.ctrlNewReg_restext.style.backgroundColor = "yellow";}
    if ( _type.value == JS && _restext.value && _restext.value.length < 250) {errors += "Your resume is incomplete!\nMust contain a least 250 characters\n";_form.ctrlNewReg_restext.style.backgroundColor = "yellow";}
    // Employer check
    if ( _type.value == Emp && !_form.ctrlNewReg_txtCompanyName.value ) {errors += "Please enter your 'Company Name'\n";_form.ctrlNewReg_txtCompanyName.style.backgroundColor = "yellow";}
    if ( _type.value == Emp && !_form.ctrlNewReg_txtPrimaryContact.value ) {errors += "Please enter your 'Primary Contact Name'\n";_form.ctrlNewReg_txtPrimaryContact.style.backgroundColor = "yellow";}
    
	//password fields match ?
	if (_pwd1.value != _pwd2.value) {errors += "Password fields to not match.\n";_pwd2.style.backgroundColor = "yellow";}
	//password min length ?
	if (_pwd1.value.length < 6) {errors += "Password must be at least 6 characters.\n";_pwd1.style.backgroundColor = "yellow";}
   
    // validate email
    emailre = /^[_a-zA-Z0-9]+([\.-]?[_a-zA-Z0-9]+)*@[_a-zA-Z0-9]+([\.-]?[_a-zA-Z0-9]+)*(\.[_a-zA-Z0-9]{1,5})+$/
    if( _form.ctrlNewReg_txtEmail.value.search( emailre ) == -1 ) {errors += "Please enter a valid 'email address'. Example: yourname@yourdomain.com\n";_form.ctrlNewReg_txtEmail.style.backgroundColor = "yellow";}
/*
	if ( _type.value == JS ){
		if ( !_form.ctrlNewReg_FileUp.value )
		{
		errors += "Please attach a 'resume'\n";
		}
		else
		{
		// validate doc type
		uploadresumere = /(rtf|doc|pdf)$/
		if( _form.ctrlNewReg_FileUp.value.search( uploadresumere ) == -1 ) errors += "Please ensure your resume document is either a .DOC, .RTF or .PDF type.\n";
		}
	}
	

	if ( _type.value == Emp ){
		if ( !_form.ctrlNewReg_txtCompanyName.value ) errors += "Please enter your 'Company name'\n";
		if ( !_form.ctrlNewReg_txtPrimaryContact.value ) errors += "Please enter your Company 'Primary Contact Name'\n";
	}
*/
	
	if (_form.ctrlNewReg_verifnum.value != verifynum) {errors += "Verification # does not match.\n";_form.ctrlNewReg_verifnum.style.backgroundColor = "yellow";}
    if ( _form.ctrlNewReg_agreetoterms.checked == false ) {errors += "Agreement to our Terms of Use is required.\n";_form.ctrlNewReg_agreetoterms.style.backgroundColor = "yellow";}

	if ( errors != "" ){
		alert( "Please verify the following data:\n\n" + errors );
		return false; }
	else {
		if (submitcount == 0)
			{ 
			if (confirm("Please confirm registration?")) 
				{
				submitcount++;
				_form.ctrlNewReg_cmdRegister.setAttribute("value","Please Wait...");
				document.body.style.cursor="wait";
				return true;
				}
			else return false;
			}
		else 
			{
			alert("This form has already been submitted.  Thanks!");
			return false;
			}
	}
	return false;
}

function OnBlur_Zip(txtCtl)
{
	// Force to change to uppercase
	var strUpperText;
	strUpperText = txtCtl.value;
	txtCtl.value = strUpperText.toUpperCase();
	
	// Test for space in zip code
	var tempzip;
	tempzip = txtCtl.value
	if (tempzip.indexOf(" ") != -1)
	{
		alert("Please enter your postal code with no space");		
		txtCtl.value="";			
	}
}

function OnKeypress_Zip(text_ctrl)  // Added to kill Spaces
{		
	if (text_ctrl.value.indexOf(" ") != -1){
		while(text_ctrl.value.charAt(text_ctrl.value.length-1)==' '){ 
			text_ctrl.value=text_ctrl.value.substring(0,text_ctrl.value.length-1);
		}
	}
}

function onlynums() {
Key = window.event.keyCode;
if (Key < 48 || Key > 57) {
window.event.keyCode =""; 
}
}

function noquotes() {
Key = window.event.keyCode;
if (Key == 39 || Key == 96 || Key == 34) {
alert("No quotation marks please.");
window.event.keyCode =""; 
} 
}

// get n ext element in the form to tab over to
function getNextElement(iElement) {
 var parentForm = iElement.form;

 for (i=0; i<parentForm.length; i++) {
    if (parentForm.elements[i]==iElement)
	if (parentForm.elements[i+1])
	   return parentForm.elements[i+1];
 }
 return null;
}

// check if the textbox is full and tab over if appropriate
function autotab(iCtl, iMax) {
 var nextElement, textValue = iCtl.value;
 if (textValue.length==iMax) { 
		nextElement = getNextElement(iCtl);

		if (nextElement) {
		   nextElement.select();
	   	   nextElement.focus();
		}	

		eval(iCtl.name+"_autotab=false");
 }
}

function checkvals(iCtl, iMax) {
// if the length of the field before the key was pressed is less then max then reset the autotab value
	if (iCtl.value.length<iMax)	eval((iCtl.name+"_autotab=true"));
}


// HTML Editor for IE Only
_editor_url = "htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }




