function UserConfirm(WhatToConfirm)
{
	var TheirAnswer = confirm (WhatToConfirm);
	return TheirAnswer;
}

function DateInPayPeriod(RawUserDate)
{
	// RawUserDate should be passed in the format of yyyy/mm/dd
	if (RawUserDate.length != 10) {
		alert ("ERROR: The date specified is invalid or not in the proper format: yyyy-mm-dd")
		return 0;
	}
	var ChoppedDate = new Array();
	ChoppedDate[0] = RawUserDate.substring(0,4);
	ChoppedDate[1] = (RawUserDate.substring(5,7) - 1);
	ChoppedDate[2] = RawUserDate.substring(8,10);
	var UserDate = new Date(ChoppedDate[0], ChoppedDate[1], ChoppedDate[2]);

	// Declare and initialize our variables. "TestDate" will = "KnownEnd" which = 10/27/06.
	var KnownStart = new Date(2006, 9, 14);
	var KnownEnd = new Date(2006, 9, 27, 23, 59, 59);
	var Counter = 0;
	var Today = new Date();
	var TestDate = new Date(KnownEnd);

	// Loop until TestDate becomes greater than the user's date.
	// Increment TestDate by two weeks (14 days) with each pass.
	while (TestDate < Today)
	{
		TestDate.setDate(TestDate.getDate() + 14);
		Counter++;
	}

	// Make PeriodEnd equal TestDate.  This variable equals the end of
	// the pay period because it is the first date we encountered that was
	// greater than the user's date after being incremented in two week intervals.
	var PeriodEnd = new Date(TestDate);

	// Next, make PeriodStart equal KnownStart, then increment it's value
	// in two week intervals the same number of times we did to PeriodEnd.
	var PeriodStart = new Date(KnownStart);
	PeriodStart.setDate(PeriodStart.getDate() + (Counter * 14));

	// Then create two "Clean" variables that contain formatted &
	// sanitized copies of the two dates contained in PeriodStart and PeriodEnd.
	var CleanStart = (PeriodStart.getFullYear() + "/" + (PeriodStart.getMonth() + 1) + "/" + PeriodStart.getDate());
	var CleanEnd = (PeriodEnd.getFullYear() + "/" + (PeriodEnd.getMonth() + 1) + "/" + PeriodEnd.getDate());

	return ((UserDate >= PeriodStart) && (UserDate <= PeriodEnd));
}

function gel(id)
{
	return document.getElementById(id);
}

function geln(name)
{
	return document.getElementsByName(name)[0];
}

function move_calendar(theObject)
{
	//var theObject = document.getElementsByName(objname)[0];
	var currentX = theObject.offsetLeft;
	var currentY = theObject.offsetTop;

	if(theObject.offsetParent)
	{
		while(theObject = theObject.offsetParent)
		{
			currentX += theObject.offsetLeft;
			currentY += theObject.offsetTop;
		}
	}

	ggPosX = currentX;
	ggPosY = currentY;
}

function addBookmark(url,title)
{
	if(navigator.appVersion.indexOf("MSIE") != -1)
		window.external.AddFavorite(url,title);
	else
		window.sidebar.addPanel(title,url,"");
}

// Clone of the real PHP function for JavaScript!
// Tests for "", 0, "0", null, false, or zero-length (including arrays).
function empty(tester)
{
	if(tester == "" || tester == 0 || tester == "0" || tester == null || tester == false || tester.length == 0 || Number(tester) == 0)
		return true;
	else
		return false;
}

function emptyd(tester)
{
	if(tester == "" || tester == 0 || tester == "0" || tester == null || tester == false || tester.length == 0 || Number(tester) == 0 || tester == "0000-00-00" || tester == "0000-00-00 00:00:00")
		return true;
	else
		return false;
}

function round(x, places)
{
	if(places == null)
		places = 2;
	fac = Math.pow(10, places);
	return Math.round(Number(x) * fac)/fac;
}
function popup(url, width, height, left, top)
{
	var myWidth = 0, myHeight = 0, screenWidth = 0, screenHeight = 0;
	if(typeof(window.innerWidth) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	if(typeof(window.screenX) == 'number')
	{
		screenWidth = window.screenX;
		screenHeight = window.screenY;
	}
	else
	{
		screenWidth = window.screenLeft;
		screenHeight = window.screenTop;
	}
	
	if (left == null)
		left = ((myWidth-width)/2) + screenWidth;
	if (top == null)
		top = ((myHeight-height)/2) + screenHeight;
	
	window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,top='+top+',left='+left+',width='+width+',height='+height+',scrollbars=yes');
}
function formatCurrency(num) {
	num = isNaN(num) || num === '' || num === null ? 0.00 : num;
    return parseFloat(num).toFixed(2);
}

// dynamic validation:
// dfv = dynamic field validation
var skip_validation = false;
function dfv(strExceptions)
{
	// basic variables
	var ErrorMsg = "Please correct the highlighted fields and try again.";
	var ErrorColor = "#FFC0CB";
	var ResultCode = true;
	var arrErrors = new Array();
	
	// if we're suppose to skip...then so be it.
	if (skip_validation)
		return true;
	
	// Remove the spaces from the exception list
	strExceptions = strExceptions.split(' ').join('');
	
	// Break apart all the exception words
	var arrExceptions = strExceptions.split(",");

	// loop through all forms
	for (var iForm = 0; iForm < document.forms.length; iForm++)
	{
		// Loop through every element on the form
		for(var iElm = 0; iElm < document.forms[iForm].elements.length; iElm++)
		{
			var ele			= document.forms[iForm].elements[iElm];
			
			// to test if the the object is an exception
			var isException = false;
	
			// Remove any background colors, only on textboxes and dropdowns
			if(ele.type == "text" || ele.type == "select-one")
				ele.style.backgroundColor = "white";
			
			// check for any exceptions
			for (var iException = 0; iException < arrExceptions.length; iException++)
			{
				if (arrExceptions[iException] == ele.name)
					isException = true;
				
				// check wild card as well
				var iWildCard = arrExceptions[iException].indexOf('*');
				if (iWildCard >= 0 && iWildCard <= ele.name.length)
					if(arrExceptions[iException].substring(0, iWildCard) == ele.name.substring(0, iWildCard))
						isException = true;
			}
			
			// don't proceed if we have an exception
			if (!isException)
			{
				// Determine the element's Type in order to select the proper validation method.
				switch(ele.type)
				{
					case "text":
						if (ele.value == "")
						{
							ResultCode = false;
							ele.style.backgroundColor = ErrorColor;
						}
						break;
					case "select-one":
						if (ele.value == "")
						{
							ResultCode = false;
							ele.style.backgroundColor = ErrorColor;
						}
						break;
				}
				
				var strNoSpace = ele.value.split(' ').join('').toLowerCase();
				switch(ele.name)
				{
					case "firstname":
						if (strNoSpace == "firstname")
						{
							ResultCode = false;
							ele.style.backgroundColor = ErrorColor;
						}
						break;
					case "lastname":
						if (strNoSpace == "lastname")
						{
							ResultCode = false;
							ele.style.backgroundColor = ErrorColor;
						}
						break;
				}
			}
		}
	}
	
	if(!ResultCode)
	{
		alert(ErrorMsg);
		//alert(arrErrors.length + " errors");
		//for (var iErrors = 0; iErrors < arrErrors.length; iErrors++)
		//	alert (arrErrors[iErrors]);
	}
	return ResultCode;
}

function hasClass(ele,cls)
{
    return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls)
{
    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls)
{
    if (hasClass(ele,cls))
    {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        ele.className=ele.className.replace(reg,' ');
    }
}
