var FORMAT_PHONE = "Phone numbers;((\\(\\d{3}\\) \\d{3}-\\d{4})|(\\d{3}-\\d{3}-\\d{4}));nnn-nnn-nnnn;(nnn) nnn-nnnn";

var FORMAT_SSN   = "Social Security Numbers;\\d{3}-\\d{2}-\\d{4};nnn-nn-nnnn";

var REGEXP_MONTH = "((0?[1-9])|(1[012]))";
var REGEXP_DAY   = "((0?[1-9])|([12]\\d)|(3[01]))";
var REGEXP_YEAR  = "(((19)|(20))?\\d{2})";
var FORMAT_DATE  = "A full date;" + REGEXP_MONTH + "/" + REGEXP_DAY + "/" + REGEXP_YEAR + ";mm/dd/yy;mm/dd/yyyy;(Values must be in range.)";
var FORMAT_APPROX= "Approximate dates;" + REGEXP_MONTH + "(/" + REGEXP_DAY + ")?/" + REGEXP_YEAR + ";mm/yy;mm/yyyy;mm/dd/yy;mm/dd/yyyy;(Values must be in range.)";
var REGEXP_YEAR4DIGIT = "(((19)|(20))\\d{2})";
var FORMAT_MONTH_YEAR4DIGIT= "Approximate dates;" + REGEXP_MONTH + "/" + REGEXP_YEAR4DIGIT + ";mm/yyyy;(Values must be in range.)";


var FORMAT_EMAIL = "e-Mail addresses;[\\w\\-\\.\\']+@(\\w[\\w\\-]*\\.)+[A-Za-z]{2,};name@domain";

var FORMAT_ZIP   = "ZIP codes;((\\d{5})|(\\d{5}-\\d{4}));nnnnn;nnnnn-nnnn";

var REGEXP_SAL_YR= "\\$?\\d{2,3}((,?\\d{3})|(k))?/yr";
var REGEXP_SAL_HR= "\\$?\\d{1,3}(\\.\\d{2})?/hr";
var FORMAT_SAL_YR= "A yearly salary;" + REGEXP_SAL_YR + ";\$nnnnnn/yr;\$nnn,nnn/yr;\$nnnK/yr\n\nwhere\tn = digit\n\t\$ is optional";
var FORMAT_SAL_HR= "An hourly salary;" + REGEXP_SAL_HR + ";\$nnn/hr;$nnn.nn/hr\n\nwhere\tn = digit\n\t\$ is optional";
var FORMAT_SALARY= "A salary;((" + REGEXP_SAL_YR + ")|(" + REGEXP_SAL_HR + "));\$nnn/hr;$nnn.nn/hr;\$nnnnnn/yr;\$nnn,nnn/yr;\$nnnK/yr\n\nwhere\tn = digit\n\t\$ is optional";

function Fmt(s) { return s.split(";")[1] }

function Invalid(format, ctrl, desc, required)
{
	if ( required == undefined ) required = true;
	
	with ( ctrl )
	{
		value = Trim(value);
		
		if ( value == '' )
		{
			if ( required )
				return Missing(ctrl, desc);
			else
				return false;
		}
		
		var a = format.split(';');
		var re = new RegExp('^' + a[1] + '$', 'i');
		
		if ( re.exec(value) == null )
		{
			var msg;
			if ( desc == undefined )
				msg = a[0] + " must be given";
			else
				msg = "Please provide " + desc;

			msg += "\nin " + (a.length == 3 ? "the following format" : "one of the following formats") + ":\n\n";
			
			for ( var i=2 ; i < a.length ; ++i ) msg += "\t" + a[i] + "\n";
			
			if ( !required )
				msg += "\nNote: This field is optional.";
				
			alert(msg);
			
			focus();
			return true;
		}
		else
			return false;
	}
}
		
function Missing(ctrl, desc)
{
	with ( ctrl )
	{
		value = Trim(value);
	
		if ( value == "")
		{
			alert('Please enter ' + desc +'.');
		   focus();
		   return true;
		}
		else
			return false;
	}
}
		
function NoChecks(ctrl, desc)
{
	var text = 'Please indicate ' + desc +'.';
	
	if ( (typeof ctrl.length) == "undefined" )
	{
		if ( ctrl.checked )
			return false;

		alert(text);
		ctrl.focus();
		return true;
	}
	else
	{
		for ( var i = 0; i < ctrl.length; i++ )
			if ( ctrl[i].checked )
				return false;
				
		alert(text);
		ctrl[0].focus();
		return true;
	}
}

function Trim(strText)
{
	strText = strText.toString();
	var leading  = /^\s+/.exec(strText); leading = (leading==null) ? 0 : leading.lastIndex;
	var trailing = /\s+$/.exec(strText); trailing = (trailing==null) ? strText.length : trailing.index;
	return strText.substr(leading, trailing-leading);
}

/* THIS FUNCTION SHOULD BE IDENTICAL TO THE FUNCTION OF THE SAME NAME IN EEO.ASP */
function ShowEthnicity(race)
{
	switch (race)
	{
		case 1:
		case 6:
		case 13:
			alert("A person descended from any of the original people of Europe, North Africa,\nor the Middle East.");
			break;
				
		case 2:
		case 14:
			alert("A person descended from any of the black racial groups of Africa.");
			break;
					
		case 3:
			alert("A person descended from the original people of the FarEast, Southeast\nAsia, the Indian-Subontinent, or the Pacific Islands. This area includes,\nbut is not limited to China, Japan, Korea, the Philipine Islands, India\nand Vietnam.");
			break;	
					
		case 4:
		case 11:
			alert("A person descended from Puerto Rico, Cuban, Central or South\nAmerican or other Spanish culture or origin regardless of race.");
			break;	
					
		case 5:
		case 15:
			alert("A person descended from any of the original peoples of North America\nand who continues his or her cultural heritage as a member of a tribe or\nwho is recognized in the community as an American Indian or Alaskan\nNative through tribal affiliation or community recognition.");
			break;
			
		case 7:
			alert("A person descended from any of the black racial groups of Africa\n(except those of Hispanic origin).");
			break;	
					
		case 8:
			alert("A person descended from any of the original peoples of North America\nand who continues his or her cultural heritage as a member of a tribe or\nwho is recognized in the community as an Native American or Alaska\nNative through tribal affiliation or community recognition.");
			break;
			
		case 9:
			alert("A person descended from any of the original peoples of these islands.");
			break;
		case 10:
			alert("A person having origins in any of the original peoples of the Far East,\nSoutheast Asia, or the Indian subcontinent including, for example, Cambodia,\nChina, India, Japan, Korea, Malaysia, Pakistan, the Philippine Islands,\nThailand, and Vietnam.");
			break;
	}
}

//this code writes browser type in hidden field
var DOM = (document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE = (document.all) ? true : false;
var IE4 = IE && !DOM;
var Mac = (navigator.appVersion.indexOf("Mac") != -1);
var IE4M = IE4 && Mac;
var browser = NS4 ? "NS4" : DOM ? "DOM" : "IE4";

var frameDoc = document;

function getElement(id) 
{     
	//IF IE OR NETSCAPE
	//RETURN ELEMENT THAT MATCHES ID
	switch(browser)
	{
		case "NS4":
			return frameDoc.layers[id]; 
		case "DOM":
			return frameDoc.getElementById(id);  
		case "IE4":
			return frameDoc.all[id];
	}
	
}

//sets visible property of DIV tag to hidden or hide
//depending on IE or Netscape	 
function hideElement(id) 
{  
			
	var buttonDiv = getElement(id);  
	
	switch(browser)
	{
		case "NS4":
			buttonDiv.visibility ="hide";     
			break;
		case "DOM":
			buttonDiv.style.visibility = "hidden"; 
			break;    
		case "IE4":
			buttonDiv.style.visibility = "hidden"; 
			break;
	}
}

	 
//sets visible property of DIV tag to visible or show
//depending on IE or Netscape
function showElement(id) 
{             
 
	var buttonDiv = getElement(id);        

	switch(browser)
	{
		case "NS4":
			buttonDiv.visibility ="show";     
			break;
		case "DOM":
			buttonDiv.style.visibility = "visible"; 
			break;    
		case "IE4":
			buttonDiv.style.visibility = "visible"; 
			break;
	}
}


//sets visible property of DIV tag to visible (vis==true) or show (vis == false)
function visElement(id, vis)
{
	if ( vis )
		showElement(id);
	else
		hideElement(id);
}


//Get's a value from a drop down for reload capabilities on NS Browser
function getdropdownvalue(obj)
{
	with ( obj ) { return options[selectedIndex == -1 ? 0 : selectedIndex].value; }
}


//Get's a text from a drop down for reload capabilities on NS Browser
function getdropdowntext(obj)
{
	with ( obj ) { return options[selectedIndex == -1 ? 0 : selectedIndex].text; }
}
