function switchPic(pic_id, pic_src) {
	var el;
	el = document.getElementById(pic_id);
	el.src = pic_src;
}

function popwindowopenEZ(url,targetwin,winsize) {
	var d = document;
	if (targetwin == '') {targetwin = '_blank'}
	var twidth, theight;
	if (winsize == 'full') {twidth = screen.width; theight = screen.height;}
	else if (winsize == 'win') {twidth = 800; theight = 600;}
	else {twidth = 660; theight = 500;}
	window.open(url, targetwin, 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width='+twidth+',height='+theight+',left='+(d.body.clientWidth-500)/2+',top='+(d.body.clientHeight-420)/2);
}

function popwindowopen(url,targetwin,width,height,fullscreen) {
	var d=document;
	if (targetwin == '') { targetwin = '_blank' }
	var twidth, theight;
	if (fullscreen == 'yes') {twidth = screen.width; theight = screen.height;}
	else {twidth = width; theight = height;}
	window.open(url, targetwin, 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width='+twidth+',height='+theight+',left='+(d.body.clientWidth-900)/2+',top='+(d.body.clientHeight-720)/2);
	//was 420 for top; 500 for left
}


function AddRowsToTable(tableId,copyrows,orowcount)
{
	 var oMyTable = document.getElementById(tableId);
	 var oNewRow;

	 var rowCount = orowcount.value;
	 rowCount++;
	 orowcount.value = rowCount;

	 for (var i = 0 ; i < copyrows ; i++)
	 {
		  oNewRow = oMyTable.rows[i].cloneNode(true);
		  ReInitRow(tableId,oNewRow,rowCount);
		  oMyTable.tBodies[0].appendChild(oNewRow);
	 }
}


function DelRowsFromTable(tableId,delrows,orowcount)
{
	var tbl = document.getElementById(tableId);
	var rowCount = orowcount.value;
	for (var i = 0 ; i < delrows ; i++)
	{
		if(rowCount != delrows)
		{
		tbl.deleteRow(rowCount - 1);
		orowcount.value = rowCount-1;
		}
	}
}

function ReInitRow(tableId,oNewRow,rowcount)
{

	var strrowcount;
	 if (! oNewRow)
	 {
		  return;
	 }
	// previous rows valuename
	if (rowcount-1 == 1) {
		strrowcount = '';
	} else {
		strrowcount = rowcount-1;
		//alert(strrowcount);
	}

	 for (var i = 0 ; i < oNewRow.childNodes.length ; i++)
	 {
		  if ((oNewRow.childNodes[i].tagName == "INPUT") || (oNewRow.childNodes[i].tagName == "SELECT") || (oNewRow.childNodes[i].tagName == "TEXTAREA"))
		  {
			   oNewRow.childNodes[i].name += rowcount;

			   if ((oNewRow.childNodes[i].tagName == "INPUT") && (oNewRow.childNodes[i].name == "TimeSheetDate"+rowcount))
			   {
					//oNewRow.childNodes[i].value = "";
					//if (i == 0) {
						var e=document.getElementsByName("TimeSheetDate"+strrowcount);
						if (e.length > 0) {
							//oNewRow.childNodes[i].value = e[0].value;
							oNewRow.childNodes[i].value = '<%=Date()%>';
						} else {
							//alert('nothing');
						}
					//}
			   }
			   if ((oNewRow.childNodes[i].tagName == "SELECT") && ((oNewRow.childNodes[i].name == "begin_time_h"+rowcount)))
			   {
					//lookup minutes first...
					var h_add = 0;
					var e=document.getElementsByName("end_time_m"+strrowcount);
					if (e.length > 0) {
						if (e[0].selectedIndex > 1) {
							h_add = 1;
						}
					}

					var e=document.getElementsByName("end_time_h"+strrowcount);
					if (e.length > 0) {
						oNewRow.childNodes[i].selectedIndex = e[0].selectedIndex+h_add;
					} else {
						//alert('nothing');
					}
			   }
			   if ((oNewRow.childNodes[i].tagName == "SELECT") && ((oNewRow.childNodes[i].name == "begin_time_m"+rowcount)))
			   {
					var m_add = 2;
					if (h_add == 1) { m_add = 0; }
					var e=document.getElementsByName("end_time_m"+strrowcount);
					if (e.length > 0) {
						if (e[0].selectedIndex > 1 && h_add == 1) {
							// add an hour, remove 30 minutes
							m_add = -2;
						}
						oNewRow.childNodes[i].selectedIndex = e[0].selectedIndex+m_add;
					} else {
						//alert('nothing');
					}
			   }

			   if ((oNewRow.childNodes[i].tagName == "SELECT") && (oNewRow.childNodes[i].name == "end_time_h"+rowcount))
			   {
					var e=document.getElementsByName("end_time_h"+strrowcount);
					if (e.length > 0) {
						oNewRow.childNodes[i].selectedIndex = e[0].selectedIndex+1;
					} else {
						//alert('nothing');
					}
			   }
			   if ((oNewRow.childNodes[i].tagName == "SELECT") && (oNewRow.childNodes[i].name == "end_time_m"+rowcount))
			   {
					var e=document.getElementsByName("end_time_m"+strrowcount);
					if (e.length > 0) {
						oNewRow.childNodes[i].selectedIndex = e[0].selectedIndex+2;
					} else {
						//alert('nothing');
					}
			   }
				if ((oNewRow.childNodes[i].tagName == "INPUT") && (oNewRow.childNodes[i].type == "text"))
					{
					oNewRow.childNodes[i].value = "";
					}

			   if ((oNewRow.childNodes[i].tagName == "TEXTAREA"))
			   {
					oNewRow.childNodes[i].value = "";
			   }
		  }

		  ReInitRow(tableId,oNewRow.childNodes[i],rowcount);
	 }
}


function printPage(func)
{
	var OLECMDID = func;
	/* OLECMDID values:
	* 1 - open link prompt
	* 2 - close ALL browser windows
	* 6 - print
	* 7 - print preview
	* 1 - open window
	* 4 - Save As
	* 8 - Page setup (doesn't always work)
	* 10 - Document properties
	*/
	var PROMPT = 2; // 2 DONT PROMPT USER; 1 PROMPT
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	WebBrowser1.ExecWB(OLECMDID, PROMPT);
	WebBrowser1.outerHTML = "";
}

function isNotBlank(checked_element, disp_message)
{
	if (checked_element == '' || checked_element == 'undefined' || checked_element == null)
	{
		alert(disp_message);
		return false;
	}
	else {return true;}
}