/***************************************
* Bunch of common functions to use in validation
* Created: 17.12.04 -> 11:33pm
* Modified: GS -> 19.12.04 @ 10:53pm
			GS -> 20.12.04 @ 02:08am
			GS -> 25.12.04 @ 14:33pm
* Note: Added TD row over functions
***************************************/

/**********************************************
* COMMON VALIDATION FUNCTIONS	  			  *
**********************************************/
// validate that the user made a selection other than default
function isChosen(select) {
    if (select.selectedIndex == 0) {
    } else {
        return true;
    }
}

// validates that the entry is formatted as an e-mail address
function isEMailAddr(elem) {
	var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}

//validates that the entry is a positive or negative number
function isNumber(elem) {
	var str = elem.value;
    var re = /^(\+\d{1,3} ?)?(\(\d{1,5}\)|\d{1,5}) ?\d{3,4} ?\d{0,7} ?(x|xtn|ext|extn|extension)??\.? ?\d{1,5}?$/i;
	//var re = /^[-]?\d*\.?\d*$/;
    str = str.toString();
    if (!str.match(re)) {

        return false;
    }
    return true;
}

/**********************************************
* TERMS AND CONDITIONS						  *
**********************************************/
// Function to make sure that the terms and condotions have been checked.
var checkobj

function agreesubmit(el){
	checkobj=el
		if (document.all||document.getElementById){
			for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
			var tempobj=checkobj.form.elements[i]
		if(tempobj.type.toLowerCase()=="submit")
		tempobj.disabled=!checkobj.checked
		}
	}
}

function defaultagree(el){
	if (!document.all&&!document.getElementById){
		if (window.checkobj&&checkobj.checked)
		return true
	else{
		alert(commonARR[0]);
		return false;
		}
	}
}

// Function to swap the status of the login icon
function swapStatus(){
	var fp = document.getElementById('fpp');
	if (document.getElementById){
		if (fp.innerHTML == ''){
			fp.innerHTML = "Forgot Password?";
		}else {
			fp.innerHTML = "";
		}
	}
}

/*****************
Function to make sure that you have selected a qualification
*****************/

function chkQualifications(whichForm,whichCheckBoxArray) {

	var _countChecked = 0;
	var err = 0;
	/* iterate through all the elements in the checkbox array */
	for(i=0;i<document[whichForm][whichCheckBoxArray].length;i++){
		/* and check to see if each is checked */
		if(document[whichForm][whichCheckBoxArray][i].checked==true){
			/* if it is, increment a counter */
			 _countChecked++;
		}
	}
	if(_countChecked < 1) {
		alert('You must select at least one qualification');
		//return false;
		}
}


/*****************
Function displays and hides content, changing an image (FAQ's)
*****************/
function tierContent(objMenu,objImage)
{
   var myElement = document.getElementById(objMenu,objImage); 
   if (myElement.style.display == "none")
   {
       myElement.style.display = "block";
       objImage.src = "images/cross.up.gif";
   }
   else
   {
       myElement.style.display = "none";
       objImage.src = "images/cross.down.gif";
   }
}

/*****************
	handy function that is purely to open a window
*****************/
function OpenThis(name, URL,width,height, scroll)
	// scroll = display scroll bar 1 = TRUE 0 = FALSE
  {
      window.open(URL,name,'left=100,top=100,toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars='+scroll+',resizable=0,width='+width+',height='+height);
  }
 
// BEGIN ROW CHANGE FUNCTIONS
var activeRow = null;

// Funstion to set the roll over color 
function datarowever(whichEl) {
	if ((!activeRow) || (activeRow && activeRow != whichEl)) whichEl.className = "row-over";
}

// Funstion to set the roll Out color 
function datarowout(whichEl) {
	if ((!activeRow) || (activeRow && activeRow != whichEl)) whichEl.className = "row";
}

// Funstion to set the Click on colours 
function datarowclick(whichEl) {
	if (activeRow && activeRow != whichEl) activeRow.className = "row";
	whichEl.className = "row-active";
	activeRow = whichEl;
}

	function swapText (id,txt){
		var elem = document.getElementById('t');
		if (document.getElementById){
			if (elem.innerHTML == ''){
				document.getElementById('m').className = 'mid';
				elem.innerHTML = txt;
			}
			else {
				document.getElementById('m').className = '';
				elem.innerHTML = '';
			}
		}
	}
	function swapText2 (txt){
		var elem = document.getElementById('t');
		if (document.getElementById){
			if (elem.innerHTML == ''){
				document.getElementById('m').className = 'mid';
				document.getElementById('r2').src = "images/top.on.jpg";
				elem.innerHTML = txt;
			}
			else {
				document.getElementById('m').className = '';
				document.getElementById('r2').src = "images/top.off.jpg";
				elem.innerHTML = '';
			}
		}
	}

	
  // Function to check that one or more radio buttons are selected
  function is_multiple_checked(form,elem) {
  
  var formObj = document[form][elem];
  var count = 0;
  	for (i=0;i<formObj.length; i++)
  	{
  		if(formObj[i].type == 'checkbox')
  		if(formObj[i].checked)
  		count++;
  	}
      //alert(count)
  	if (count < 1)
  	{
  	return false;
  	}
  	else {
  		
  		return true;
  	}
  }