//produces a confirm box for deletion
function confirmDelete()
{
var agree=confirm("Are you sure you want to delete this item?");
if (agree)
	return true ;
else
	return false ;
}

function confirmDeleteVacancy(){
var agree=confirm("Are you sure you want to delete this vacancy?" );
if (agree)
	return true ;
else
	return false ;
}

function confirmDeleteUser(){
var agree=confirm("Are you sure you want to delete this User?" );
if (agree)
	return true ;
else
	return false ;
}

function confirmDeleteNewsItem(){
var agree=confirm("Are you sure you want to delete this News item?" );
if (agree)
	return true ;
else
	return false ;
}

function confirmEmail(){
alert("Your application was sent successfully" );
}
function emailError(){
alert("Your application was not sent successfully.\n\nPlease try again" );
}


function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


//Check for required fields
//FORM: onSubmit="return checkreqfields(this)" 

function checkreqfields(theForm){
var ok=true
errTxt = ""

	if (document.images){
		for (i=0;i<theForm.length;i++){
			var tmpFormElement=theForm.elements[i]
			tmpFormElement.value=trim(tmpFormElement.value)
			if (tmpFormElement.id.substring(0,4)=="req_"){
				if (((tmpFormElement.type=="text"||tmpFormElement.type=="textarea"||tmpFormElement.type=="password")&&tmpFormElement.value=='')||(tmpFormElement.type.toString().charAt(0)=="s"&&tmpFormElement.value==-1)){
				ok=false
				errTxt = errTxt + tmpFormElement.id + "\n"
				errTxt = errTxt.replace("req_", "");    
				}
			}
		}
	}
	if (!ok){
	alert("You must fill in the following required fields: \n\n" + errTxt );
	return false
	}
	else
	return true
}

function checkMail(theValue)
{
	var x = theValue;//document.forms[0].email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) ;//alert('YES! Correct email address');
	else {
		alert('Incorrect email address');
	}
	return document.enquiry_form.req_email.focus();
}


//focus 
function setFocus()
  {
  document.getElementById('req_email').focus()
  }
function loseFocus()
  {
  document.getElementById('req_email').blur()
  }


// Reloads the current window
// onclick="reload()"
function reload()
{
window.location.reload()
}

function formSubmit()
{
document.getElementById("form1").submit()
}

//Show or Hide table rows
//CALL: show('objectID')
function show(object) {
		window.document.getElementById(object).style.display=''
}
function hide(object) {	 
		window.document.getElementById(object).style.display='none'		
}
/*Boxes*/
function hideShowColumn(theCol, theCol2){
//displays a hidden colum and hides another
//this swaps over two buttons for display
		document.getElementById(theCol).style.display = 'none'
		document.getElementById(theCol2).style.display = ''
}

function showBox(theBox){//, theBox2, theBox3
//takes readonly textboxes and displays them for editing  
		document.getElementById(theBox).style.background='#FFFFFF'
		document.getElementById(theBox).style.border='#cccccc solid 1px'
		document.getElementById(theBox).style.padding='2px'
		document.getElementById(theBox).readOnly=false
}
function undisableElement(theElement){//, theBox2, theBox3
//takes readonly textboxes and displays them for editing  
		document.getElementById(theElement).disabled=''
}

function changeBgRed(theName){
//change the background of a textbox to light red
	document.getElementById(theName).style.background='#FDC6D0'
}

//used with SELECT element to change a displayed image when an option is selected
//CALL: onchange="displayImage('display_image', this.options[this.selectedIndex].value, 'images/products/')"
function displayImage(theElement, theValue, thePath){
	document.getElementById(theElement).src = thePath + theValue;
}

//used with SELECT element to check an images size and change a displayed image when an option is selected
//CALL: onchange="checkAndDisplayImage(theElement, theValue, thePath, errorElement, maxWidth, maxHeight, imageWidth, imageHeight)"
function checkAndDisplayImage(theElement, theValue, thePath, errorElement, maxWidth, maxHeight, imageWidth, imageHeight){
	if(imageWidth > maxWidth || imageHeight > maxHeight){
		document.getElementById(errorElement).innerHTML='The selected image is too large'; }
	else{
	 displayImage(theElement, theValue, thePath)
	}
}




