function show(theElement)
{
	document.getElementById(theElement).style.display = "block"	
}
function hide(theElement)
{	
	document.getElementById(theElement).style.display = "none"
}
function isVisible(theElement)
{
	
	return (document.getElementById(theElement).style.display == "block")
}
function nt()
{
}
function getValue(theElement)
{
	return(document.getElementById(theElement).value)
}
function setValue(theElement, theValue)
{
	document.getElementById(theElement).value = theValue
}
function checkValue(theElement, theValue)
{
	return(document.getElementById(theElement).value == theValue)	
}
function setText(theElement, theValue)
{
	document.getElementById(theElement).innerHTML = theValue		
}
function getText(theElement)
{
	return(document.getElementById(theElement).innerHTML)
}
function setFocus(theElement)
{
	document.getElementById(theElement).focus()
}

function monthToStr(month)
{
	switch (month)
	{
		case 0: 
		case 12:
			return('January')
			break
		case 1: 
			return('February')
			break
		case 2:
			return('March')
			break
		case 3:
			return('April')
			break
		case 4:
			return('May')
			break
		case 5:
			return('June')
			break
		case 6: 
			return('July')
			break
		case 7:
			return('August')
			break
		case 8:
			return('September')
			break
		case 9:
			return('October')
			break
		case 10:
			return('November')
			break
		case 11:
		case -1:
			return('December')
			break
	}
}
function getLastDateOfMonth(thedate)
{
	var month = thedate.getMonth()
	var year = thedate.getYear()
	switch (month)
	{
		case 0:
		case 2:
		case 4: 
		case 6:
		case 7:
		case 9:
		case 11:
		{
				return(31)
		}
		break;
	
		case 3:
		case 5:
		case 8:
		case 10:
		{
				return(30)
		}
		break;	
		case 1:
		{
				if (year%4 == 0)
					return(29)
				else 
					return(28)
		}
		break;
	}
}

 
function extractNumber(obj, decimalPlaces, allowNegative)

{

	var temp = obj.value;

	

	// avoid changing things if already formatted correctly

	var reg0Str = '[0-9]*';

	if (decimalPlaces > 0) {

		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';

	} else if (decimalPlaces < 0) {

		reg0Str += '\\.?[0-9]*';

	}

	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;

	reg0Str = reg0Str + '$';

	var reg0 = new RegExp(reg0Str);

	if (reg0.test(temp)) return true;



	// first replace all non numbers

	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';

	var reg1 = new RegExp(reg1Str, 'g');

	temp = temp.replace(reg1, '');



	if (allowNegative) {

		// replace extra negative

		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';

		var reg2 = /-/g;

		temp = temp.replace(reg2, '');

		if (hasNegative) temp = '-' + temp;

	}

	

	if (decimalPlaces != 0) {

		var reg3 = /\./g;

		var reg3Array = reg3.exec(temp);

		if (reg3Array != null) {

			// keep only first occurrence of .

			// and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0

			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);

			reg3Right = reg3Right.replace(reg3, '');

			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;

			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;

		}

	}

	

	obj.value = temp;

}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)

{

	var key;

	var isCtrl = false;

	var keychar;

	var reg;

		

	if(window.event) {

		key = e.keyCode;

		isCtrl = window.event.ctrlKey

	}

	else if(e.which) {

		key = e.which;

		isCtrl = e.ctrlKey;

	}

	

	if (isNaN(key)) return true;

	

	keychar = String.fromCharCode(key);

	

	// check for backspace or delete, or if Ctrl was pressed

	if (key == 8 || isCtrl)

	{

		return true;

	}



	reg = /\d/;

	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;

	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

	

	return isFirstN || isFirstD || reg.test(keychar);

}

function notHereYet()
{ alert('This functionality has not yet been implemented')
}
function popupSmallWindow(address)
{
	window.open(address, "_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=339, height=190")
//window.open(address, "_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=600, height=600")
}

var blnChangesMade = false
function verifyChangeSubCompany()
{
	if (blnChangesMade)
	{
		return confirm("Are you sure you wish to view details of this subcompany?")	
	}
	else 
	{
		return true
	}
}
function isHoliday(dt)
{
	 day = dt.getDay();
	 month = dt.getMonth();
	 date = dt.getDate();
	 year = dt.getYear();
	 if ((month == 0) && (date == 1)) return true;//("New Year's Day");
	 if ((month == 4) && (day == 1) && (date > 24)) return true;//("Memorial Day");	
	 if ((month == 6) && (date == 4)) return true;//("Independence Day (USA)");
	 if ((month == 8) && (day== 1)&& (date > 0) && (date< 8)) return true;//("Labor Day (USA)");
	 if ((month == 10) && (day == 4) && (date > 23) && (date< 30)) return true;//("Thanksgiving (USA)");
	 if ((month == 10) && (date == 30) && (day == 4)) return true;//("Thanksgiving (USA)");
	 if ((month == 11) && (date == 25)) return true;//("Christmas");
	
}

function getRate(startHour, startMin, finishHour, finishMin, shiftDate, blnLongRate)
{
	
	
	if (isNaN(startHour) || isNaN(startMin) || isNaN(finishHour) || isNaN(finishMin))
	{
		return false
	}
	
	rate = "R"
	longRate = "Regular"
	
	fStartTime = parseFloat(startHour) + (parseFloat(startMin)/60)
	fFinishTime = parseFloat(finishHour) + (parseFloat(finishMin)/60)
	fTotalHours = ((24 + fFinishTime) - fStartTime) % 24
	
	if (((fStartTime + (fTotalHours/2)) >= 24) || ((fFinishTime - (fTotalHours/2)) <= 6))
	{
		rate = "3"
		longRate = "Overtime"
	}
	
	try
	{
		var vdate = shiftDate.split("-")
		var d = new Date();
		d.setDate(vdate[0]);
		d.setMonth(vdate[1] - 1);
		d.setYear(vdate[2]);
	}
	catch(er)
	{
	}
	if (isHoliday(d))
	{
		rate = "H"
		longRate = "Holiday"
	}
		
/*	The commented code below was included because of an initial request that 'premium' rate be paid if the shift begins within a day of posting. HooShang (email 20/3/2008) requested that this automatic setting of premium rate be removed.

	vDate = shiftDate.split("-")
	var dDate = new Date(vDate[2], vDate[1] - 1, vDate[0], startHour, startMin)	
	var dNow = new Date()
	var dTomoro = new Date
	dTomoro.setDate(dNow.getDate() + 1) 
	dTomoro.setHours(23) 
	dTomoro.setMinutes(59) 
	
	if (dDate < dTomoro)
	{		
		rate = "P"
		longRate = "Premium"
	}*/	
	
	if (blnLongRate)
	{	
		return longRate
	}
	else
	{
		return rate
	}
}

