/*
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   File:	                Common.js
'
'   Description:            Commonly used utility functions
'
'   Written by:             Iftikhar Mumtaz
'
'	Language(s) Used:		JavaScript
'
'   Date Written:           January 06, 2001
'
'   Platform:               Microsoft Internet Explorer
'
'   Copyright:              © 2001 Cybergen Technolgies.
'                           All rights reserved
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
*/

function LTrim(theString)
{
	var x;
	var TrimmedString;
	
	for (x=0; x<theString.length; x++)
	  {
		if (!(theString.substring(x, x+1) == " ")) 
		{
		 break;
		}
	  }
	  
	TrimmedString = theString.substring(x);
	
	return TrimmedString;
}

function IsEmpty(theElement)
{
	if(LTrim(theElement.value) != "")
	{
		SetHighlight(theElement, false);
		return false;
	}
	else
	{
		alert(theElement.name + " is a required field. Please fill with a value.");
		SetHighlight(theElement, true);
		return true;
	}	
}

function ResetForm(theForm)
{
	document.forms[theForm].reset();
}

function SetHighlight(theElement, Highlight)
{
	if(Highlight)
	{
		theElement.focus();
		if(IsExplorer())
		{
			theElement.style.borderStyle = "double";
			theElement.style.borderWidth = 3;
			theElement.style.borderColor = "#569933";
		}
	}
	else
	{
		if(IsExplorer())
		{
			theElement.style.borderStyle = "inset";
			theElement.style.borderWidth = 1;
			theElement.style.borderColor = "Silver";
		}
	}
}

function IsExplorer()
{
	var userAgent = navigator.userAgent;
	
	if(userAgent.indexOf("MSIE") >= 0)
		return true;
	else
		return false;
}

function IsEmailValid(sEmailAddress)
{	
	if(sEmailAddress.indexOf("@")!=0)
		if(sEmailAddress.indexOf(".")!=0)
			if(sEmailAddress.lastIndexOf("@")!=(sEmailAddress.length-1))
				if(sEmailAddress.lastIndexOf(".")!=(sEmailAddress.length-1))
					if(sEmailAddress.lastIndexOf(".")!=-1)
						if(sEmailAddress.lastIndexOf("@")!=-1)
							if(sEmailAddress.indexOf(" ")<0)
								return true;

	alert("Invalid E-mail Address: " + sEmailAddress);
	return false;
}

function HandleMouseOver(oButton)
{
	oButton.style.backgroundColor="gold";
}

function HandleMouseOut(oButton)
{
	oButton.style.backgroundColor = "silver";
}
