﻿function scrollwin(pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
 
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }

    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=1,"
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open( pageToLoad,winName,args );
}

function noscrollwin(pageToLoad, winName, width, height, center) {
    xposition=0; yposition=0;
 
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }

    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=0,"
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open( pageToLoad,winName,args );
}


// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================
function URLEncode(p_text)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

    var plaintext = p_text;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(p_text)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = p_text;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
};





var pageFormAction = "";
var myForm = "";

function checkIEVersion() {
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null)
	  rv = parseFloat( RegExp.$1 );
	  return rv;
  }
}

function hideSelects(action) {
	//possible values for action are 'hidden' and 'visible'
	if (action!='visible'){action='hidden';}
	for (var S = 0; S < document.forms.length; S++){
		for (var R = 0; R < document.forms[S].length; R++) {
			if (document.forms[S].elements[R].options) {
				document.forms[S].elements[R].style.visibility = action;
			}
		}
	}
}

function disableForm(theform , inSetting) {
	if (document.all || document.getElementById) {
		
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			tempobj.disabled = inSetting;
		}
		if(inSetting == true) {
			pageFormAction = theform.action;
			theform.action = "";
		} else {
			theform.action = pageFormAction;	
		}
		return true;
	}
}


function showModalPopup(pTitle, pBody, pCSS, closeDisabled) {
    var myOverlay = document.getElementById('attentionOverlay');
    var myOverTitle = document.getElementById('overLayTabTitle');
    var myOverContent = document.getElementById('overLayContent');
    var myOverBack = document.getElementById('overlayBackground');
    var myOverTitleCloser = document.getElementById('overLayTabTitleCloser');
	if(closeDisabled)
	{
	    myOverBack.onclick = null;
        myOverTitle.onclick = null;
	    myOverTitleCloser.onclick = null;
	    myOverTitleCloser.innerHTML = '&nbsp;';
    }
    myOverTitle.innerHTML = '';
    myOverContent.innerHTML = ''; // specified as sometimes user can see previous content prior to next line finalising.
    myOverTitle.innerHTML = pTitle;
    myOverContent.innerHTML = pBody;
    hideSelects('hidden');	
    myOverBack.className = '';
    if(pCSS=='') 
        pCSS = 'over-large over-show';
    myOverlay.className = pCSS + ' over-show';
}

function showModalPopupDoc(incContent, incTitle, incSize, isWizard) {
	var myOverlay = document.getElementById('attentionOverlay');
	var myOverTitle = document.getElementById('overLayTabTitle');
	var myOverContent = 'overLayContent';
	var myOverBack = document.getElementById('overlayBackground');
	var myOverTitleCloser = document.getElementById('overLayTabTitleCloser');
	if(isWizard) // supporting setup wizard
	{
	    myOverBack.onclick = null;
	    //myOverTitle.onclick = null;
	    //myOverTitleCloser.onclick = null;
	    //myOverTitleCloser.innerHTML = '&nbsp;';

	    myOverTitleCloser.onclick = function(){
            window.parent.location.href = 'AutoLogout.aspx';
        }
        myOverTitle.onclick = function(){
            window.parent.location.href = 'AutoLogout.aspx';
        }
	}
	
	// Shows overlay
	myOverTitle.innerHTML = incTitle;
	document.getElementById(myOverContent).innerHTML = '<iframe border="0" style="border-width: 0px" width="100%" height="100%" src="' + incContent + '" allowtransparency="true" frameborder="0"></iframe>';
	
	myOverBack.className = '';
	
	// Need to check the form being accessed is the docroot, not inside the overlay...
	var myNodeList = document.body.childNodes;
	for(i = 0; i < myNodeList.length; i++) {
		if(myNodeList[i].nodeName == "FORM")	{
			myForm = myNodeList[i];
		}
	}
	disableForm(myForm , true);
	
	// IE 6 being an idiot code
	if (checkIEVersion()<7) {
		hideSelects('hidden');	
		var scrollPosition = f_scrollTop();
		myOverBack.style.top = scrollPosition;
		myOverlay.style.marginTop = 20;
		myOverlay.style.top = scrollPosition;
	}
	myOverlay.className = incSize + ' over-show';
}

function hideModalPopup() {
	var myOverlay = document.getElementById('attentionOverlay');
	var myOverBack = document.getElementById('overlayBackground');

	// Correct form should already have been defined on showing the overlay.
	disableForm(myForm , false);
	
	myOverlay.className = 'over-hidden';
	myOverBack.className = 'over-hidden';
	hideSelects('visible');		
}