//Task:9947 | July 6, 2005 | DT | Update to add a section linking to static logo page in a new window.
// Function:	openNewWindow
// Description:	Opens a new window with the specified options.
// Parameters:	nUrl - The url of the new browser window.
//				nName - The name of the new browser window.
//				nHeight - The height of the new browser window.
//				nWidth - The width of the new browser window.
function openNewWindow(nURL, nName, nHeight, nWidth) {
	
	// Retrieve the left and top position to center the window.
	var left = Math.floor( (screen.width - nWidth) / 2);
	var top = Math.floor( (screen.height - nHeight) / 2);
	
	// open the new window centered.
	var newwindow = window.open(nURL,nName,'top='+top+',left='+left+',height='+nHeight+',width='+nWidth+',scrollbars=yes,resizable=yes');
	// Bring the window into focus if it is not already
	if (window.focus) {newwindow.focus()}
}

//Task:10291 | DT | Added the maxlength property to the text area control | Begin Modification
// Initializes all of the text areas that contain the maxlength attribute with events to enforce
// the specified maxlength.

var isMozilla = navigator.userAgent.indexOf('Mozilla') != -1 && parseInt(navigator.appVersion.substring(0,1)) >= 5;
var isIE = navigator.userAgent.indexOf('MSIE') != -1;

function textAreasInit() {  
	var objs = document.getElementsByTagName("textarea");  
	var oi = 0; //oi is object index  var thisObj;  
	for (oi=0;oi<objs.length;oi++) {   
		currentTextArea = objs[oi];   
		if (currentTextArea.getAttribute('maxlength')) {    
			currentTextArea.onkeypress = checkMaxLength;
			currentTextArea.onkeyup = checkMaxLength;
			currentTextArea.onpaste = forcePasteMaxLength;
			currentTextArea.onblur = forceMaxLength;
		} 
	} 
} 

// Check if the max length has been exceeded.
function checkMaxLength(e) {  
	var maxLength = parseInt(this.getAttribute('maxlength'));  
	// Get the keycode.
	if (isIE) {
		keyCode = window.event.keyCode;
	} else {
		keyCode = e.keyCode;
	}
	if (this.value.length >= maxLength && !IsValidAscii(keyCode)) {
		return false;  
	} 
}

// Force the max length when text is pasted into the check box. 
function forcePasteMaxLength(e) {
	var maxLength = parseInt(this.getAttribute('maxlength'));  
	if (maxLength) {
		event.returnValue = false;
		maxLength = parseInt(maxLength);
		var oTR = document.selection.createRange();
		var iInsertLength = maxLength - this.value.length + oTR.text.length;
		var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
		oTR.text = sData;  
	}
}

function forceMaxLength() {
	var maxLength = parseInt(this.getAttribute('maxlength'));
	var content = this.value;
	this.value = content.substring(0, maxLength);
}

// Generic method used to add an event to an object.
function addEvent (elm, evType, fn, useCapture) {   
	if (elm.addEventListener) {  
		elm.addEventListener(evType, fn, useCapture);  
		return true;   
	} else if (elm.attachEvent){  
		var r = elm.attachEvent("on"+evType, fn);  
		return r;   
	} else {  
		alert("Handler could not be removed");   
	} 
}

// Check if the ascii value is valid.
function IsValidAscii(n_asciiCode) {
	var validAsciiCodes = new Array(8, 16, 35, 36, 37, 38, 39, 40, 46, 67);
	
	for(var i=0; i < validAsciiCodes.length; i++ ) {
		if(n_asciiCode == validAsciiCodes[i]) {
			return true;
		}
	}
	
	return false;
	
}

// Upon load of the window initialize the text areas.
addEvent(window, "load", textAreasInit);
//Task:10291 | DT | Added the maxlength property to the text area control | End Modification