//Setup Locking Variables
var iLock = 0;
var iDelay = 500;
function checkControlPanel()
{
if (iLock == 0)
	{
	iLock = 1;
	window.setTimeout('moveControlPanel()', iDelay);
	}
}

function moveControlPanel()
{
	iLock = 0;
	window.document.Form1.all('tblControlPanel').style.marginTop = (document.body.scrollTop + 1) + 'px';
}

function fselect_deselectAll(chkVal, idVal, idParentName) 
{ 
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++) 
    {
        // Look for our Header Template's Checkbox
        if (idVal.indexOf (idParentName) != -1) 
        {
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
            if(chkVal == true) 
            {
                frm.elements[i].checked = true;
            } 
            else 
            {
                frm.elements[i].checked = false;
            }
        } 
    }
}

function fselect_deselectOne(chkVal, idVal, idChildName) 
{ 
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++) 
    {
		if (idVal.indexOf (idChildName) != -1) 
        {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(frm.elements[i].checked == false) 
            {
                frm.elements[1].checked = false; //Uncheck main select all checkbox
            }
        }
    }
}

function fGoToAnchor(dropdown) 
{
	var myIndex = dropdown.selectedIndex
	var mySelValue = dropdown.options[myIndex].value
	var myAnchor = '#'+ mySelValue	
	location.href = myAnchor;		
}

function Paste_Html(editorID,value)	
{
	EditorID = editorID+"_editBox";	
	
	var editor	= document.getElementById(EditorID);
	editor.focus();
	
	var sel = editor.document.selection.createRange();
	
	if (editor.document.selection.type == 'Control') 
	{
		return;
	}
	
	sel.pasteHTML(value);
}

function hideElement(elmID,x,y,w,h)
{	
	if (document.all)
	{	
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{
			obj = document.all.tags(elmID)[i];
			//window.alert(obj.name);
			if (! obj || ! obj.offsetParent)
				continue;
	
			// Find the element's offsetTop and offsetLeft relative to the BODY tag.
			objLeft   = obj.offsetLeft;
			objTop    = obj.offsetTop;
			objParent = obj.offsetParent;
			while (objParent.tagName.toUpperCase() != "BODY")
			{
				objLeft  += objParent.offsetLeft;
				objTop   += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}
			
			name = obj.name.substr(9);
			//Adjust the element's offsetTop relative to the dropdown menu
			/*if (x > (objLeft + obj.offsetWidth) || (objLeft > (x + eval(w))))
				obj.left = x;
			else if ((objTop > y + eval(h)) || (y > (objTop+obj.offsetHeight)))
				;
			else*/
			
			//window.alert('Obj Name: '+ name);
			
			if ((name != 'MonthSelect') && (name != 'YearSelect'))
			{
				obj.style.visibility = "hidden";
			}
		}
	}
}

function showElement(elmID)
{
	if (document.all)
	{
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{	
			obj = document.all.tags(elmID)[i];
			if (! obj || ! obj.offsetParent)
				continue;
			obj.style.visibility = "";
		}
	}
}

function ftoggledivgroup(iMode)
{			
	var x = window.document.getElementsByTagName('div');
	var sSwtich;
	var sCookie;
	
	sCookie = readCookie('togglediv');
	if (sCookie == null) 
	{
		sCookie = 0;
	}	
	if (iMode == '1')
	{
		if (sCookie =='1')
		{
			sSwitch = 'block';			
			window.document.all('lnkHSDetails').innerText = 'Hide Details'
		}
		else if (sCookie == '0')
		{	
			sSwitch = 'none';			
			window.document.all('lnkHSDetails').innerText = 'Show Details'				
		}
	}
	else
	{
		if (sCookie =='1')
		{
			sSwitch = 'none';			
			createCookie('togglediv', '0', '365')
			window.document.all('lnkHSDetails').innerText = 'Show Details'
		}
		else if (sCookie == '0')
		{	
			sSwitch = 'block';			
			createCookie('togglediv', '1', '365')
			window.document.all('lnkHSDetails').innerText = 'Hide Details'				
		}
		else
		{
			sSwitch = 'none';			
			createCookie('togglediv', '0', '7')
			window.document.all('lnkHSDetails').innerText = 'Show Details'		
		}
	}
	
	for (var i = 0; i < x.length; i++)
	{			
		if (window.document.all('kb' + i))
		{
			window.document.all('kb' + i).style.display=sSwitch;
		}
		if (window.document.all('is' + i))
		{
			window.document.all('is' + i).style.display=sSwitch;
		}
		if (window.document.all('ca' + i))
		{
			window.document.all('ca' + i).style.display=sSwitch;
		}
		if (window.document.all('cl' + i))
		{
			window.document.all('cl' + i).style.display=sSwitch;
		}
		if (window.document.all('ws' + i))
		{
			window.document.all('ws' + i).style.display=sSwitch;
		}
		if (window.document.all('gen' + i))
		{
			window.document.all('gen' + i).style.display=sSwitch;
		}																									
	}
} 

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function fnTrapKeyBoard(btn, event)
{

	if (document.all)
	{
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if (document.getElementById)
	{
		if (event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if(document.layers)
	{

		if(event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
}


