/*		Author:	Matthew VanderMeer, mlvander@healthy.uwaterloo.ca
		
		Filename:	common_scripts.js
		
		Purpose:	These are common javascript functions that are used throughout most apps.




*/
function glbIsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function glb_select_all(field,value,colorchange)
	{	
		var theForm = document.form.elements;
		var theField = theForm[field];
		
		if (theField.length>=1)
			{
				for (i=0;i<theField.length;i++)
					{	theField[i].checked=value
					
						if(colorchange==true && value==false)
							{	document.getElementById(field+i).style.background='#FFFFFF';
								document.getElementById(field+i).style.color='#000000';
							}
						else if (colorchange==true && value==true)
							{	document.getElementById(field+i).style.background='#CAB192';
								document.getElementById(field+i).style.color='#777';
							}
					}
			}
		else
			{	theField.checked=value

				if(colorchange==true && value==false)
					{	document.getElementById(field+'0').style.background='#FFFFFF';
						document.getElementById(field+'0').style.color='#000000';
					}
				else if (colorchange==true && value==true)
					{	document.getElementById(field+'0').style.background='#CAB192';
						document.getElementById(field+'0').style.color='#777';
					}
			}
	}

function glb_select_user(field,number,doall)
	{
		var theForm = document.form.elements;
		var theField = theForm[field];

		if (theField.length>=1)
			{
				var thisField = theForm[field][number];
			}
		else
			{	
				var thisField = theForm[field];
			}

		if (thisField.checked==true)
			{	
				thisField.checked=false;
				document.getElementById(field + number).style.background='#FFFFFF';
				document.getElementById(field + number).style.color='#000000';
			}
		else
			{	
				thisField.checked=true;
				document.getElementById(field + number).style.background='#CAB192';
				document.getElementById(field + number).style.color='#777';
			}
	}

function glb_onmouse_highlight(ID)
	{	document.getElementById(ID).style.background='#CAB192';
	}
function glb_mouseout_unhighlight(ID)
	{	document.getElementById(ID).style.background='#FFFFFF';
	}
function glb_confirm_save()
	{
		if(document.form.formfieldupdate.value=='true')
		   	{	
			 	return_value = false;
				alert("You have changed the details on this form and you have not saved your changes.  Please save your changes before continuing.");	
			}
	}


function glb_hide_show(section,items)
	{
		for (var x = 1; x <= items; x++)
		   {
			var section_to_toggle=document.getElementById(section+x);
	
			if(section_to_toggle.style.display=="none")
				{
				section_to_toggle.style.display="block"
				} 
			else 
				{
				section_to_toggle.style.display="none"
				}
		   }
	}


function glb_confirm_delete(item_to_delete)
	{
		return_value = confirm("You are about to permanently delete the selected " + item_to_delete + ".\n\nThis action cannot be undone.\n\nClick 'OK' to confirm and continue, 'Cancel' to go back.");
	}

function glb_confirm_hide(item_to_delete)
	{
		return_value = confirm("You are about to move the selected " + item_to_delete + " to the deleted items box..\n\nYou can view deleted items by clicking on the link at the top of this page.\n\nAre you sure that you want to do this.\n\nClick 'OK' to confirm and continue, 'Cancel' to go back.");
	}

function glb_update_details(url)
	{
	test = confirm("You have chosen to match and register this person.  \nDo you want to update the information this person information to the information that they have provided in there registration?.\n\nClick 'OK' to update details for this person\nClick 'CANCEL' to match and register without updatding details");
	
	window.location= url + '&overwrite=' + test;
	}	


function glb_confirm_update()
	{	
		return_value = confirm("You are about to overwrite the details of this user with the information provided in thier registration.\n\nIf this i correct click 'OK', if this in in error please click 'CANCEL'.")
	}
// Auto tab for pre-defined fields like phone numbers //
function autotab(original,destination)
	{
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode != 9)
			{
				if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
					{
					destination.select();
					}
			}
	}

