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 tccValidateContactForm(objform) {

	var showalert = "";
	var showmessage = "";
	
	if (objform.enquirytype.selectedIndex == 0) {
		showalert += "\n  -  Contact Type";
	}

	if (objform.fullname.value == "") {
		showalert += "\n  -  Fullname";
	}

	if ((objform.emailaddress.value == "") || (objform.emailaddress.value.indexOf('@') == -1) || 
	   (objform.emailaddress.value.indexOf('.') == -1)) {
		showalert += "\n  -  Email Address";
	}

	if (objform.enquirydetails.value == "") {
		showalert += "\n  -  Enquiry Details";
	}


	if (showalert != "") {
		showmessage = "All the highlighted fields are required.  Please ensure that you have completed\nthe required fields before submitting your enquiry." +
					 "\n\nYou need to complete the following fields:\n" + showalert;
		alert(showmessage);
		formvalid = false;
	} else {
		formvalid = true;
	}
	
	if (formvalid) {
		objform.submit();
	}
	
	return formvalid;
	
}

function tccDoSearch() {
	
	document.vsearch.submit();
	return true;
	
}

function tccValidateForm(objform) {

    var validated = true;

    for (var i=0, j=objform.elements.length; i<j; i++) {
        controltype = objform.elements[i].type;
		fieldname = objform.elements[i].name;
		
		usedclass = objform.elements[i].className;
		
		if (usedclass.substring(0,3) == 'req') {
			if (objform.elements[i].disabled == false) {
				if (controltype == 'password' || controltype == 'text' || controltype == 'textarea') {
					if (objform.elements[i].value == '') {
						validated = false;
					}
				}
		
				if (controltype == 'select-one' || controltype == 'select-multiple') {
					objlist = objform.elements[i];
					if (objlist.options.selectedIndex == 0) {
						validated = false;
					}
				}
			}
		}
    }

    return validated;
}

function tccValidateRegisterForm() {
	
	var state = false;
	
	state = tccValidateForm(document.register);

	if (state) {
		document.register.submit()
	} else {
		alert('Please ensure that all the fields have been completed.');
	}

	return state;
	
}

function tccValidateRemoveForm() {
	
	var objform = document.unsubscribe;
	var state = true;
	
	if ((objform.emailaddress.value == "") || (objform.emailaddress.value.indexOf('@') == -1) || 
	   (objform.emailaddress.value.indexOf('.') == -1)) {
		state = false;
	}

	if (state) {
		document.unsubscribe.submit()
	} else {
		alert('Please ensure you have provided your email address.');
	}

	return state;
	
}

function toggleLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function tccResetSearch() {
	
	var objform = document.jobsearch;

    for (var i=0, j=objform.elements.length; i<j; i++) {
        controltype = objform.elements[i].type;
		
		if (controltype == 'text') {
			objform.elements[i].value = '';
		}

		if (controltype == 'select-one' || controltype == 'select-multiple') {
			objlist = objform.elements[i];
			objlist.options.selectedIndex = 0;
		}
    }

	objform.keywords.focus();
}