//Acquired from http://office.microsoft.com/en-au/assistance/HA010745311033.aspx
function ExpandDiv(theDivName)
{
	InitializeGlobalData();

	if (null == theDivName || typeof(theDivName) == "undefined") return; var theDiv = allDivsInPage[theDivName]; if (null == theDiv || typeof(theDiv) == "undefined") return;
	theDiv.style.display = "block";
}

function CollapseDiv(theDivName)
{ 
	InitializeGlobalData();

	if (null == theDivName || typeof(theDivName) == "undefined") return; var theDiv = allDivsInPage[theDivName]; if (null == theDiv || typeof(theDiv) == "undefined") return;
	theDiv.style.display = "none";
}

function ToggleDiv(theDivName)
{
	InitializeGlobalData();

	if (null == theDivName || typeof(theDivName) == "undefined") return; var theDiv = allDivsInPage[theDivName]; if (null == theDiv || typeof(theDiv) == "undefined") return;

	if (theDiv.style.display.toUpperCase() != "BLOCK")
		ExpandDiv(theDivName);
	else
		CollapseDiv(theDivName);
}
function InitializeGlobalData()
{
	if ('undefined' != typeof(strRtl))
		strIsRtl = strRtl;

	var divs = document.body.getElementsByTagName("DIV");
	var spans = document.body.getElementsByTagName("SPAN");

	var countDiv = 0;
	var countSpan = 0;
	if (typeof(divs) != "undefined" && null != divs)
		countDiv = divs.length;

	if (typeof(spans) != "undefined" && null != spans)
		countSpan = spans.length;

	allDivsInPage = new Array();
	for (i=0; i < countDiv; i++)
		if (typeof(divs[i].id) != "undefined" &&
			null != divs[i].id &&
			divs[i].id.length > 0)
			allDivsInPage[divs[i].id] = divs[i];

	for (i=0; i < countSpan; i++)
		if (typeof(spans[i].id) != "undefined" &&
			null != spans[i].id &&
			spans[i].id.length > 0)
			allDivsInPage[spans[i].id] = spans[i];
}
function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1){
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
		j++;
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1){  
	    var i = s.length - 1;  
	    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
	        i--;
	    s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str)
{
	return RTrim(LTrim(str));
}
function validate_check(DocName, DocVal, Desc)
{
	if (Trim(document.forms[DocName].elements[DocVal].value) == "")
		{
		document.forms[DocName].elements[DocVal].value = Trim(document.forms[DocName].elements[DocVal].value);
		document.forms[DocName].elements[DocVal].focus();		
		alert(Desc);
		return false;
		}
	else
		return true;
}
function validate_email(DocName, DocVal, Desc){
	if (Trim(document.forms[DocName].elements[DocVal].value) != ""){
		var field = document.forms[DocName].elements[DocVal];  
		var str = Trim(field.value);
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if (reg1.test(str) || !reg2.test(str)){
			document.forms[DocName].elements[DocVal].focus();
			alert(Desc);
			return true;
		}
	}	
	else{
	    return false;
	}	
}

function open_popup(page,s_width,s_height) {
    top.window_handle = open(page,'popupWindowName','top=0,left=0,height=' + s_height + ',width=' + s_width + ',resizable=0,scrollbars=0,toolbar=0,location=0,directories=0,menubar=0,copyhistory=0,status=0');
    top.window_handle.focus();
    if (!top.window_handle.opener) top.window_handle.opener = self;
   // return false;
}

function open_timesheet(page,s_width,s_height) {
    top.window_handle = open(page,'popupWindowName','top=0,left=0,height=' + s_height + ',width=' + s_width + ',resizable=1,scrollbars=1,toolbar=1,location=0,directories=0,menubar=0,copyhistory=0,status=0');
    top.window_handle.focus();
    if (!top.window_handle.opener) top.window_handle.opener = self;
}

function ShowStatus(msg){
	window.status = unescape(msg)
	return true;
}
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

