var toggleExtendedCopy = {
	init:function() {
		$('.extendCopy').click(function () {
			var str = this.href;
			var ele = str.substr(str.indexOf('#')+1, str.length);
			$('#'+ele).toggle();

			if ( typeof( resetOverlay ) == 'function' ) {
				resetOverlay();
			}
			return false;
		});
	}
}

var emailFormHandler = {
	init: function() {
		$('#emailForm').submit(function() {
			var f = $('#emailForm');
			var action = f.attr('action');
			var serializedForm = f.serialize();
			$.ajax({
				type: 'post',
				url: action,
				data: serializedForm + '&url=' + document.URL,
				dataType: 'json',
				success: function( json ){
					//console.log( json.Error );
					if ( json.Error ) {
						var errorMessages = '<ul>';
						for( msg in json.ErrorMessage ) {
							errorMessages += '<li>' + json.ErrorMessage[msg] + '</li>';
						}
						errorMessages += '</ul>';
						$('#errorMsgsEmail').html( errorMessages );
					}
					if ( json.Submitted ) {
						var submitMessage = '<div class="responseMessage"><p>' + json.SubmitMessage + '</p></div>';
						$('#contentBlock').html( submitMessage );
					}
				},
				error: function () {
					$('#errorMsgsEmail').html( '<p>Unable to initiate process.</p>' );
				}
			});
			return false;
		});
	}
}

/*var registerFormHandler = {
	init: function() {
		$('#myform').submit(function() {
			if ( $('#USERNAME').val().length < 4 ) {
				alert( "Username must be at least 4 characters long" );
				return false;
			}
			if ( $('#PASSWORD').val().length < 4 ) {
				alert( "Password must be at least 4 characters long" );
				return false;
			}
			$('#myform').submit();
		});
	}
}

$(document).ready(function() {
	//registerFormHandler.init();
});
*/

/*
 * Legacy JavaScript from BT Telconsult
 */
function checkTextEntry() {
	var textStr = document.myform.NewSkill.value + document.myform.chkSkill.value;
	if (textStr != "") {
		var textArray = textStr.split("|");
		var theCounter = 0;
		while (theCounter < textArray.length) {	
			theCounter += 1;
		}
		theCounter = theCounter - 1;
		if (theCounter == 255) {
			alert("There are already 255 skills selected on the form. To add more, clear those first.");
		} else {
			openPopupSkill();
		}
	} else {
		openPopupSkill();
	}
}


function openPopupSkill() {
	Param = "scrollbars=yes,resizable=no,toolbar=no,status=yes,menubar=no,width=400,height=420";
	Param += ",top=" + String(window.screen.Height / 2 - 130);
	Param += ",left=" + String(window.screen.Width / 2 - 200);
	windowReference = window.open("../../webrecruit/includes/HATS-candskills.asp?hatID=80810C0182828480&formname=amend&elemname1=skill&elemname2=NewSkill", "SkillsPopup", Param);
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
}


function clearSkills() {
	if (myform.skills.value != "") {
		myform.skills.value = "";
	}
}


function clearAllSkills() {
	if (myform.CurrentSkill.value != "") {
		myform.CurrentSkill.value = "";
	}
	if (myform.NewSkill.value != "") {
		myform.NewSkill.value = "";
	}
	if (myform.skills.value != "") {
		myform.skills.value = "";
	}
	if (myform.chkSkill.value != "") {
		myform.chkSkill.value = "";
	}
}


function checkIndTextEntry() {
	var textStr = document.myform.NewIndustry.value + document.myform.chkIndustry.value;
	if (textStr != "") {
		var textArray = textStr.split("|");
		var theCounter = 0;
		while (theCounter < textArray.length) {
			theCounter += 1;
		}
		theCounter = theCounter - 1;
		if (theCounter == 3) {
			alert("There are already 3 industries selected on the form. To add more, clear those first.");
		} else {
			openPopupIndustry();
		}
	} else {
		openPopupIndustry();
	}
}


function openPopupIndustry() {
	Param = "scrollbars=yes,resizable=no,toolbar=no,status=yes,menubar=no,width=400,height=420";
	Param += ",top=" + String(window.screen.Height / 2 - 130);
	Param += ",left=" + String(window.screen.Width / 2 - 200);
	windowName = "Industries";
	windowReference = window.open("../../webrecruit/includes/HATS-newindustries.asp?hatID=80810C01CB828480&formname=amend&elemname1=skill&elemname2=NewSkill", "SkillWindow", Param);
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
}


function clearIndustry() {
	if (myform.INDUSTRY.value != "") {
		myform.INDUSTRY.value = "";
	}
	if (myform.NewIndustry.value != "") {
		myform.NewIndustry.value = "";
	}
	if (myform.CurrentIndustry.value != "") {
		myform.CurrentIndustry.value = "";
	}
	if (myform.chkIndustry.value != "") {
		myform.chkIndustry.value = "";
	}
}


function doSubmit() {
	if ( document.myform.USERNAME.value.length < 4 ) {
		alert( "Username must be at least 4 characters long" );
		return false;
	}
	if ( document.myform.PASSWORD.value.length < 4 ) {
		alert( "Password must be at least 4 characters long" );
		return false;
	}
	document.myform.submit();
}


function openEAAWindow() {
	Param = "scrollbars=yes,resizable=no,toolbar=no,status=yes,menubar=no,width=500,height=600";
	Param += ",top=" + String(window.screen.Height / 2 - 130);
	Param += ",left=" + String(window.screen.Width / 2 - 200);
	windowReference = window.open("EAA-Text.asp", "EAAPopup", Param);
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
}

function doSubmitLogin() {
	if ( document.candlogin.username.value.length < 4 ) {
		alert( "Username must be at least 4 characters long" );
		return false;
	} else {
		document.candlogin.submit();
	}
	if ( document.candlogin.password.value.length < 4 ) {
		alert( "Password must be at least 4 characters long" );
		return false;
	} else {
		document.candlogin.submit();
	}
}