﻿// JScript File
var popup = null;

var myDateChooserCalendar = null;

// Custom Post Back Javascript
var aspnetForm = document.forms['aspnetForm'];

if (!aspnetForm) {
    aspnetForm = document.aspnetForm;
   }

function __doCustomPostBack(eventTarget, eventArgument) {
    if (!aspnetForm.onsubmit || (aspnetForm.onsubmit() != false)) {
        aspnetForm.__CUSTOMEVENTTARGET.value = eventTarget;
        aspnetForm.__CUSTOMEVENTARGUMENT.value = eventArgument;
        aspnetForm.submit();
    }
}

function doSleep(func, ms) {
	window.setTimeout(func, ms);
}


function getCalendar(oDiv, oControl, anchorId, dateFormat) {
	myDateChooserCalendar = null;
	
	myDateChooserCalendar = new CalendarPopup(oDiv);
	myDateChooserCalendar.showYearNavigation();
	myDateChooserCalendar.showYearNavigationInput();
	myDateChooserCalendar.select(oControl, anchorId, dateFormat);
}


function openPopupAndRefreshParentWhenClosed(url, name, options) {
	if (popup) {
		popup.close();
		popup = null;
	}

	popup = window.open(url, name, options);

	doSleep("refreshParentOfPopupOrWait()", 100);
}

function refreshParentOfPopupOrWait() {
	if (popup) {
		if (!popup.closed) {
			doSleep("refreshParentOfPopupOrWait()", 100);
		}
		else {
			popup = null;
			// Refresh this page to view changes
			window.location.href = window.location.href;
		}
	}
}


function toggleSelect(check, chks)
{
	//alert(check.checked);

	if( chks != undefined )
	{
		if( chks.length != undefined )
		{
			for( var i = 0; i < chks.length; i++ )
			{
				chks[i].checked = check.checked;
			}
		}
		else
		{
			chks.checked = check.checked;
		}
	}
}

function checkChecks(chks, checked) 
{
	//alert("checkChecks");
	if (chks != undefined) 
	{
		//alert(chks.length);
		if( chks.length != undefined )
		{
			for( var i = 0; i < chks.length; i++ )
			{
				chks[i].checked = checked;
			}
		}
		else
		{
			chks.checked = checked;
		}
	}
}

function toggleSelectedOptions(select, selected) 
{
	if (select.options != undefined && select.length != undefined) 
	{
		for (var i = 0; i < select.length; i++) 
		{
			select.options[i].selected = selected;
		}
	}	
}

function confirmAction(ask) 
{
	return confirm(ask);
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

