function tccMovePic(img_name, img_src) {

    document[img_name].src = img_src;

}

function tccSetSelectionStart(field) {

    if (field.createTextRange) {
        var r = field.createTextRange();
        r.movestart('character', field.value.length);
        r.collapse();

    }

}

function tccValidateNonNumber (evt) {

    var keyCode = evt.which ? evt.which : evt.keyCode;
    return (keyCode >= 8 && keyCode <=9) || (keyCode >= 48 && keyCode <=57);

}

function tccShowPopUp(strName, ShowPage, intwidth, intheight, ShowScrollBar, intOffSet) {

	var leftpos = ((screen.width - intwidth - intOffSet) / 2);
	var toppos = ((screen.height - intheight - intOffSet) / 2);
	var winprops = 'toolbar=0, scrollbars=' + ShowScrollBar + ', location=0, statusbar=0, menubar=0, width=' + intwidth + ', height=' + intheight + ', left=' + leftpos + ', top=' + toppos + ', resizable=0';
    var popupwindow = window.open(ShowPage, strName, winprops);
    popupwindow.focus();
}

function tccChangeBG(objRow, mouseState) {

    if (mouseState == 'on')  {
		sColor = '#EDF7F9';
    }  else if (mouseState == 'off')  {
		sColor = 'transparent';
    }

    objRow.style.backgroundColor = sColor;

    if (mouseState == 'on') {
        objRow.style.cursor = 'hand';
    }
}

function tccEnableConfirmEmailOption(objForm) {
	
	if (objForm.emailformat.selectedIndex == 0) {
		objForm.confirmemail.disabled = true;
		var strColor = "#8c8c8c";
	} else {
		objForm.confirmemail.disabled = false;
		var strColor = "#000";
	}
	
	confirmemaillabel.style.color = strColor;

}

function tccConfirmCancel(intMessage) {

 switch(intMessage) {
  case 1:
   var strMessage = 'Are you sure you want to cancel your application for the selected vacancy?';
   break;
  case 2:
   var strMessage = 'Are you sure you want to cancel defining job alerts?';
   break;
  case 3:
   var strMessage = 'Are you sure you want to cancel your registration?';
   break;
  case 4:
   var strMessage = 'Are you sure you want to cancel defining the Email message?';
   break;
  case 5:
   var strMessage = 'Are you sure you want to cancel requesting a brochure?';
   break;
 };
 
    var blnConfirm = window.confirm(strMessage);

    if (blnConfirm) {
		
		if (intMessage == 5) {
			self.close();
		} else {
        	history.back();
		}
	}

    return blnConfirm;

}

function tccValidateApplyForm(objForm) {

	var strAlert = "";

	if (objForm.title.selectedIndex == 0) {
		strAlert += "\n  -  Title";
	}

	if (objForm.firstname.value == "") {
		strAlert += "\n  -  First Name";
	}

	if (objForm.lastname.value == "") {
		strAlert += "\n  -  Last Name";
	}

	if (objForm.daynumber.value == "") {
		strAlert += "\n  -  Daytime Telephone Number";
	}
	
	if ((objForm.emailaddress.value == "") || (objForm.emailaddress.value.indexOf('@') == -1) || 
	   (objForm.emailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Email Address";
	}
	
	if (strAlert != "") {
		strMessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before submitting your application." +
					 "\n\nYou need to complete the following fields:\n" + strAlert;
		alert(strMessage);
		blnFormValid = false;
	} else {
		blnFormValid = true;
	}
	
	if (blnFormValid == true) {
		objForm.submit(); 
	}

	return blnFormValid;
	
}

function tccValidateRegisterForm(objForm) {

	var strAlert = "";

	if (objForm.title.selectedIndex == 0) {
		strAlert += "\n  -  Title";
	}

	if (objForm.firstname.value == "") {
		strAlert += "\n  -  First Name";
	}

	if (objForm.lastname.value == "") {
		strAlert += "\n  -  Last Name";
	}

	if ((objForm.emailaddress.value == "") || (objForm.emailaddress.value.indexOf('@') == -1) || 
	   (objForm.emailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Email Address";
	}

//	if (objForm.emailformat.selectedIndex != 0 && objForm.confirmemail.checked == false) {
//		strAlert += "\n  -  Please confirm that you wish to receive Email";
//	}

	if (strAlert != "") {
		strMessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before submitting your registration." +
					 "\n\nYou need to complete the following fields:\n" + strAlert;
		alert(strMessage);
		blnFormValid = false;
	} else {
		blnFormValid = true;
	}
	
	return blnFormValid;
	
}

function tccValidateEmailForm(objForm) {

	var strAlert = "";

	if (objForm.sendername.value == "") {
		strAlert += "\n  -  Sender Name";
	}
	
	if ((objForm.senderemailaddress.value == "") || (objForm.senderemailaddress.value.indexOf('@') == -1) || 
	   (objForm.senderemailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Sender Email Address";
	}

	if (objForm.recipientname.value == "") {
		strAlert += "\n  -  Email To Name";
	}

	if ((objForm.recipientemailaddress.value == "") || (objForm.recipientemailaddress.value.indexOf('@') == -1) || 
	   (objForm.recipientemailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Email To Email Address";
	}

	if (strAlert != "") {
		strMessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before submitting your application." +
					 "\n\nYou need to complete the following fields:\n" + strAlert;
		alert(strMessage);
		blnFormValid = false;
	} else {
		blnFormValid = true;
	}
	
	if (blnFormValid == true) {
		objForm.submit(); 
	}

	return blnFormValid;

}
	
function tccValidateBrochureForm(objForm) {

	var strAlert = "";

	if (objForm.title.selectedIndex == 0) {
		strAlert += "\n  -  Title";
	}

	if (objForm.firstname.value == "") {
		strAlert += "\n  -  First Name";
	}

	if (objForm.lastname.value == "") {
		strAlert += "\n  -  Last Name";
	}

	if (objForm.address1.value == "") {
		strAlert += "\n  -  Address Line 1";
	}
	
	if (objForm.towncity.value == "") {
		strAlert += "\n  -  Town/City";
	}
	
	if (objForm.postcode.value == "") {
		strAlert += "\n  -  Postcode";
	}

	if ((objForm.emailaddress.value == "") || (objForm.emailaddress.value.indexOf('@') == -1) || 
	   (objForm.emailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Email Address";
	}
	
	if (strAlert != "") {
		strMessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before submitting your brochure request." +
					 "\n\nYou need to complete the following fields:\n" + strAlert;
		alert(strMessage);
		blnFormValid = false;
	} else {
		blnFormValid = true;
	}
	
	return blnFormValid;
	
}

function tccValidateJobAlertsForm(objForm) {

	var strAlert = "";

	if (objForm.title.selectedIndex == 0) {
		strAlert += "\n  -  Title";
	}

	if (objForm.firstname.value == "") {
		strAlert += "\n  -  First Name";
	}

	if (objForm.lastname.value == "") {
		strAlert += "\n  -  Last Name";
	}

	if ((objForm.emailaddress.value == "") || (objForm.emailaddress.value.indexOf('@') == -1) || 
	   (objForm.emailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Email Address";
	}

	intChecked = 0;
	
    for (var i=0, j=objForm.elements.length; i<j; i++) {
        strMyType = objForm.elements[i].type;
		objControl = objForm.elements[i];

        if (strMyType == 'checkbox') {
			if (objControl.checked) {
				intChecked++;
			}
        }
	}

	if (intChecked == 0) {
		strAlert += "\n  -  Choose at least one sector";
	}
	
	if (objForm.deliveryfrequency.selectedIndex == 0) {
		strAlert += "\n  -  Please confirm how frequently the Email should be delivered";
	}

	if (strAlert != "") {
		strMessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before submitting your job alert application." +
					 "\n\nYou need to complete the following fields:\n" + strAlert;
		alert(strMessage);
		blnFormValid = false;
	} else {
		blnFormValid = true;
	}

	return blnFormValid;
	
}

function tccValidateUnsubscribeForm(objForm) {

	var strAlert = "";

	if ((objForm.emailaddress.value == "") || (objForm.emailaddress.value.indexOf('@') == -1) || 
	   (objForm.emailaddress.value.indexOf('.') == -1)) {
		strAlert += "\n  -  Email Address";
	}

	intChecked = 0;
	
    for (var i=0, j=objForm.elements.length; i<j; i++) {
        strMyType = objForm.elements[i].type;
		objControl = objForm.elements[i];

        if (strMyType == 'checkbox') {
			if (objControl.checked) {
				intChecked++;
			}
        }
	}

	if (intChecked == 0) {
		strAlert += "\n  -  Choose at least one service";
	}

	if (strAlert != "") {
		strMessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before you unsubscribe from any of our services." +
					 "\n\nYou need to complete the following fields:\n" + strAlert;
		alert(strMessage);
		blnFormValid = false;
	} else {
		blnFormValid = true;
	}

//	if (blnFormValid == true) {
//		objForm.submit(); 
//	}

	return blnFormValid;
	
}
