

/* Focus this window */
//window.focus( "AllRegsOnline" );

/*
	Window opener script. For child popup windows.
*/
function openWindow( url, name, width, height, wWidth, wHeight )
{
	// compute our centered left and top coordinates
	var left = ( wWidth / 2 ) - ( width / 2 );
	var top = ( wHeight / 2 ) - ( height / 2 );
	var winHdl = window.open( url, name, "status=0,resizable,scrollbars,height=" + height + ", width=" + width + ", top=" + top + ", left=" + left + "", true );
	if(winHdl != null)
		winHdl.focus();
}
/* 
	Modal window popups. For opening modal popup windows.
*/
function openModal( url, width, height )
{
	// compute our cented left and top coordinates
	window.showModalDialog( url, "modal", "status=0;help=0;dialogHeight=" + height + "px; dialogWidth=" + width + "px;" );
}

function OpenAllRegsHome()
{
	var openerActive = false;
	try{openerActive = (window.opener && !window.opener.closed);}
	catch(e){}

	if(openerActive)
	{
		if( window.opener.location.href.indexOf( "/home/default.aspx" ) < 0 )
			window.opener.location.href = "/home/default.aspx";
		window.opener.focus();
	}
	else
		redirectOpener( "/home/default.aspx" )
	
}

// Opens links in the window that spawned AllRegs. Alternately opens a new window when opener is null.
function redirectOpener( url )
{
	var openerActive = false;
	// Determine whether our window.opener is NULL
	try{openerActive = (window.opener && !window.opener.closed);}
	catch(e){}

	if(!openerActive)
	{
		var oHandle = window.open( url, "parent" );
		if(oHandle != null)
			oHandle.focus();
	}
	else
	{
		window.opener.location.href=url;
		window.opener.focus();
	}
}

var printWindow;
function openPrintWindow(pUrl, pName, pOptions, pReplace)
{
	printWindow = window.open(pUrl, pName, pOptions, pReplace);
	if(printWindow!=null)
	{
		window.attachEvent("onbeforeunload",ClosePrintWindow);
		printWindow.focus();
	}
}

function ClosePrintWindow()
{
	if(printWindow!=null && !printWindow.closed)
	{
		printWindow.close();
		window.detachEvent("onbeforeunload",ClosePrintWindow);
	}
	else if(printWindow!=null && printWindow.closed)
		window.detachEvent("onbeforeunload",ClosePrintWindow);
}

/*************** Progress Bar script. Needs Work! *************/ 

var mInterval;
var cont;
var maskElem;
var indElem;
var gradElem;

var dom = document.getElementById && !document.all;

function getElem( elem ) {
	var div = dom ? document.getElementById( elem ) : document.all[ elem ];
	return div;
}

function startProgressBar() {
	window.loadingspan.style.zIndex = 1000;
	window.loadingspan.style.display="block";
}

function hideProgress()
{
	cont = getElem( "loadingspan" );
	cont.style.background = "#bfccd9";
	cont.style.display = "none";
	cont.style.zIndex = -1000;
}

function reset() {
	maskElem.style.left = "0px";
	maskElem.style.width = cont.offsetWidth + "px";
	indElem.style.zIndex  = 10;
	maskElem.style.display = "block";
	//indElem.innerHTML = "0%";
}

function doProgress() 
{
	curWidth = parseInt( maskElem.offsetWidth )-2;
	curLeft = parseInt( maskElem.offsetLeft )+2;

	if( curLeft >= 101 ) {
		clearInterval( mInterval );
		maskElem.style.display = "none";
		return;
	}


	maskElem.style.left = curLeft + "px";
	if( parseInt( maskElem.offsetWidth ) > 10 )
		maskElem.style.width = curWidth + "px";
	//indElem.innerHTML = Math.floor((curLeft / parseInt(gradElem.offsetWidth))*100) + "%";

}

// Post Office Box Regex validation. We cannot accept them for addresses.
function valAddressInput( source, arguments )
{
	var regex = /(((P\.? *O\.? *)|(POST *OFFICE)) *BOX)/i;
	if( regex.test( arguments.Value ) ) 
		arguments.IsValid = false;
	else 
		arguments.IsValid = true;	
}