
/* --- BROWSER DETECTION --- */

var browserName = '';
var browserVersion = '';
var browserJavascript = '1.0';
var browserDHTML = '0';
var gnumMSIEVersion;

if (navigator) {
	if (navigator.userAgent) {
		if (navigator.userAgent != null) {
			if (navigator.userAgent.toUpperCase().indexOf('OPERA') != -1) {
				browserName = 'OP';
			}
			else if (navigator.userAgent.toUpperCase().indexOf('SAFARI') != -1) 
				{
				browserName = 'SA';
				}
			
		}
	}
	if (browserName == '' && navigator.appName) {
		if (navigator.appName=='Microsoft Internet Explorer') {
			browserName='IE';
			gnumMSIEVersion = parseFloat(navigator.userAgent.substr(navigator.userAgent.toLowerCase().indexOf("msie") + 5,3));
		} else if (navigator.appName=='Netscape') {
			browserName='NN';
		}
	}
	if (navigator.appVersion) {
		browserVersion = navigator.appVersion.substring(0,3);
	}
}

if (browserName=='IE' && browserVersion=='4.0')
	browserDHTML = '1.0';



/* --- WIZARD PAGE FUNCTIONS --- */
function resizeWizardIFrame(pbIFrameLoaded) {
	var strIframeElementId = document.getElementById('hidIframeElement').value;
	var oIframeDocument = getWizardIFrameDocument();
	var numHeight;
	var numWidth;
		
	if (oIframeDocument.body && oIframeDocument.body.innerHTML.replace(/^\s*|\s*$/g,'') != '') {
		
		if (pbIFrameLoaded && browserName != 'IE') {
			//Reset height to 0 since some browsers e.g. Opera/Firefox retain the previous
			//pages scrollHeight value unless the IFrame is collapsed
			document.getElementById(strIframeElementId).height = 0;
			//The IFrame height needs to be reset
			setTimeout('resizeWizardIFrame(false)', 1);
		} else {
			
			numHeight = oIframeDocument.body.scrollHeight + 0;
	
			if (document.getElementById(strIframeElementId).height != numHeight || document.getElementById(strIframeElementId).height == 0) {
				
				if (document.getElementById(strIframeElementId).height && numHeight == 0) {
					//Set height to 1 to get the ball rolling since some browsers e.g. Opera dont
					//adjust scrollHeight until the IFrame height is greater than zero 
					//and part of it's contents are displayed.
					numHeight = 1;
				} else if (browserName == 'NN') {
					//Add on 12 for Firefox to get correct gap at bottom
					numHeight = numHeight + 12;
				}
							
				//The IFrame height needs to be reset as i) it doesnt 
				//match the current scroll height of it's contents
				//or ii) has not yet been initialised and has zero height.
				//document.forms[0].elements['inpIFrameLoaded'].value = 'true';
				document.getElementById(strIframeElementId).height = numHeight;
				
				//Set timeout to attempt to resize IFrame again 
				//as IFrame contents scrollHeight value may not yet reflect full height 
				//of document at this point. This can occur
				//when css styling of elements is still occuring
				//after the IFrame has fired its onload event.
				setTimeout('resizeWizardIFrame(false)', 1);
				
			} else {
				
				// We have finally loaded the iFrame - add some extra space as a buffer
				document.getElementById(strIframeElementId).height = numHeight + 70;
			}
		}
	
	}
}

function getWizardIFrameDocument() {
	
	// Get ID of iframe element
	var strIframeElementId = document.getElementById('hidIframeElement').value;
	
	if (document.getElementById(strIframeElementId).contentDocument) { // firefox
		return document.getElementById(strIframeElementId).contentDocument;
	} else { // IE
		return document.frames(strIframeElementId).document;
	}
}


function loadWizardIFrame() {
	resizeWizardIFrame(true);
}


function redirectToLoginPage() {

	var strPathname = window.location.pathname;
	var strFullURL = window.location.href;
	var intPosQuestion = strFullURL.indexOf('?');
	var strQS = '';
	
	// Get the querystring if there is one
	if (intPosQuestion > 0) {
		strQS = escape(strFullURL.substring(intPosQuestion+1, strFullURL.length));
	}

	window.location.href = 'https://' + window.location.hostname + '/security/login/formslogin.asp?dnl=1&URL=' + strPathname + '&QS=' + strQS + '&inpOriginalProtocol=' + window.location.protocol.substring(0, window.location.protocol.length - 1);
}



