//========== POPUP WINDOWS ==========
function PopWinSm(url, name)
{
	var ops = 'width=550, height=450, scrollbars=1, menubar=0, resizable=1, titlebar=1, status=1';
	var win = window.open(url, name, ops);
}

function PopWinMed(url, name)
{
	var ops = 'width=790, height=590, scrollbars=1, menubar=0, resizable=1, titlebar=1, status=1';
	var win = window.open(url, name, ops);
}

function PopWinLg(url, name)
{
	var ops = 'width=1000, height=750, scrollbars=1, menubar=0, resizable=1, titlebar=1, status=1';
	var win = window.open(url, name, ops);
}

function PopWinXLg(url, name)
{
	var ops = 'width=1100, height=800, scrollbars=1, menubar=0, resizable=1, titlebar=1, status=1';
	var win = window.open(url, name, ops);
}

function PopWinSubRes(url, name)
{
	var ops = 'width=800, height=475, scrollbars=1, menubar=0, resizable=1, titlebar=1, status=1';
	var win = window.open(url, name, ops);
}

function PopPay()
{
	PopWinMed('/Emp/PayTools.aspx','_popPayTools');
}

function PopCheck(checkno)
{
	var ops = 'width=790, height=350, scrollbars=1, menubar=0, resizable=1, titlebar=1, status=1';
	var win = window.open('/Emp/PayView.aspx?id=' + checkno, '_popPayView', ops);
}

function PopBio(empid)
{
	PopWinSm('/Emp/Bio.aspx?empid=' + empid, '_popBio');
}

function PopNews(id)
{
	PopWinMed('/Emp/News.aspx?id=' + id, '_popNews');
}

function PopBuzz(id)
{
	PopWinSm('', '_popBuzz');
}

function PopList(mode)
{
	PopWinSm('/Emp/Listing.aspx?mode=' + mode, '_popList');
}

function PopPhotoSet(empid)
{
	PopWinSm('/Photos/Set.aspx?empid=' + empid, '_popPhotoSet');
}

function EndSession()
{
	if(confirm("Would you like to end your current secure session?"))
	{
		document.location.href = "/Emp/Logout.aspx";
	}
}

function PopUrl(url, name, size)
{
	if(size == 'Sm')
	{
		PopWinSm(url, name);
	}
	else if(size == 'Lg')
	{
		PopWinLg(url, name);
	}
	else if(size == 'SubRes')
	{
		PopWinSubRes(url, name);
	}
	else
	{
		PopWinMed(url, name);
	}
}

function PopEmp(emp)
{
	if(emp > 0)
	{
		PopWinSm('EmpView.aspx?id=' + emp, '_popEmp');
	}
}

function PopTime(tsid)
{
	if(tsid > 0)
	{
		PopWinSm('../admin/TimeView.aspx?id=' + tsid, '_popTime');
	}
}

function NavHome()
{
	if(confirm("Would you like to navigate to the \"Highland Home\" page."))
	{
		document.location.href = "/";
	}
}

function PopContactUs()
{
	PopWinSm('/Etc/ContactUs.aspx','_popContactUs');
}

function PopRequirement()
{
	PopWinSm('/Etc/ContactClientReq.aspx','_popRequirement');
}

function CloseAndRefreshOpener()
{
	window.opener.document.location.href = window.opener.document.location.href;
	window.close();
}

function Close()
{
	window.close();
}

//========== PANEL MENU - PAGE LOAD ==========

var menu_speed = 10;
var menu_grow = 10;

//========== PANEL MENU - GROUP CLICK ==========

function MenuClickGroup(groupName)
{
	var group_clicked = document.getElementById(groupName);
	
	if(group_clicked==null){return false;}
		
	MenuCollapseAll(group_clicked.id);
	
	if(group_clicked.style.display == "block")
	{
		return false;
	}
	else
	{
		group_clicked.style.height = menu_grow;
		group_clicked.style.display = "block";
		MenuExpandGroup(group_clicked.id);
	}
}

//========== PANEL MENU - EXPAND ONE GROUP ==========

function MenuExpandGroup(groupName)
{
	var group_to_expand = document.getElementById(groupName);
	
	if(group_to_expand.offsetHeight + menu_grow < group_to_expand.scrollHeight)
	{
		group_to_expand.style.height = group_to_expand.offsetHeight + menu_grow;
		window.setTimeout("MenuExpandGroup('" + group_to_expand.id + "')", menu_speed);
	}
	else
	{
		group_to_expand.style.height = group_to_expand.scrollHeight;
	}
}

//========== PANEL MENU - COLLAPSE ONE GROUP ==========

function MenuCollapseGroup(groupName)
{
	var group_to_collapse = document.getElementById(groupName);
	
	group_to_collapse.style.height = menu_grow;
	group_to_collapse.style.display = "none";
}

//========== PANEL MENU - COLLAPSE ALL GROUPS ==========

function MenuCollapseAll(groupName)
{
	var group_to_collapse = null;
	
	for(i = 0 ; i < menu_array.length ; i++)
	{
		var group_to_collapse = document.getElementById(menu_array[i]);
		if(group_to_collapse != null && group_to_collapse.id != groupName)
		{
			if(group_to_collapse.style.display == "block")
			{
				MenuCollapseGroup(group_to_collapse.id);
			}
		}
	}
}

//========== TIMESHEET REMINDER SCRIPTS ==========

function TsRmdCol(col) {
	var e = null;
	for (i=col ; i<=document.forms[0].elements.length-1 ; i+=5) {
		e = document.forms[0].elements['lstReminders_' + i];
		if (e!=null) {e.checked = true;}
	}
}

function TsRmdRow(row)
{
	var e = null;
	for (i=row ; i<=row+4 ; i++)
	{
		e = document.forms[0].elements['lstReminders_' + i];
		if (e!=null) {e.checked = true;}
	}
}

function TsRmdClear()
{
	var e = null;
	for (i=0 ; i<=34 ; i++)
	{
		e = document.forms[0].elements['lstReminders_' + i];
		if (e!=null) {e.checked = false;}
	}
}

//========== WINDOW REFRESH & CLOSE ==========

function RefreshParent()
{
	parent.opener.location.href='/Emp/';
}

function CloseWin()
{
	top.window.close();
}

//========== FORMATTING ==========

function FormatUSPhone(caller)
{
	var v = caller.value;
	
	v = v.replace(/\W/g,'');
	if(v.length==10)
	{
		v = v.substr(0,3) + '-' + v.substr(3,3) + '-' + v.substr(6,4);
	}
	caller.value = v;
}

function FormatUSZip(caller)
{
	var v = caller.value;
	
	v = v.replace(/\W/g,'');
	if(v.length==9)
	{
		v = v.substr(0,5) + '-' + v.substr(5,4);
	}
	caller.value = v;
}



function StringReplace(caller, findThis, replaceWith)
{
	var v = caller.value;
	
	v = v.replace(v, findThis, replaceWith)
	
	return v;
}