﻿// JScript File
//----------------------------------------------------------------------------------------------------
//-- Clears the default text from a text box...text box calls funtion onFocus
//----------------------------------------------------------------------------------------------------
function clearTextBox(obj) {
	obj.value = '';
}
//----------------------------------------------------------------------------------------------------
//-- Check for enter key and set focus and click object provided
//----------------------------------------------------------------------------------------------------
function CheckFormEnter(e, sButtonName) {
	var characterCode;
	if(e && e.which) { 
		e = e;
		characterCode = e.which; // (for NN4 support)
	} else {
		e = event;
		characterCode = e.keyCode; // (for IE)
	}
	if(characterCode == 13) { //(ascii 13 - enter key)
		var button = document.getElementById(sButtonName);
		button.focus();
		button.click();
	}
}
//----------------------------------------------------------------------------------------------------
//-- Opens Generic Locked Window
//----------------------------------------------------------------------------------------------------
function openGenericLockedWindow(loc, name, newWidth, newHeight) {
	var reportWindow;
	reportWindow = window.open(loc, name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=' + newWidth + ',height=' + newHeight);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Opens Generic Unlocked Window
//----------------------------------------------------------------------------------------------------
function openGenericUnLockedWindow(loc, name, newWidth, newHeight){
	var reportWindow;
	reportWindow = window.open(loc, name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=' + newWidth + ',height=' + newHeight);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Opens Generic Unlocked Window
//----------------------------------------------------------------------------------------------------
function openGenericLockedScrollWindow(loc, name, newWidth, newHeight){
	var reportWindow;
	reportWindow = window.open(loc, name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=' + newWidth + ',height=' + newHeight);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Opens Unlocked Window
//----------------------------------------------------------------------------------------------------
function openUnLockedWindow(loc, name){
	var reportWindow;
	reportWindow = window.open(loc, name);
	reportWindow.focus();
}
//----------------------------------------------------------------------------------------------------
//-- Allow user to bookmark a specific page.  Used in Support Sections.  Link is on the sidebar
//----------------------------------------------------------------------------------------------------
function bookmark() {
	if (document.all) {
		window.external.AddFavorite(location.href, document.title); return false;
	}
}
//----------------------------------------------------------------------------------------------------
//-- Pre loads images
//-- To use type the following on a page:
//-- jsLoadImages('/enterfoldername/enterimagename.gif or jpg',
//--              '/enterfoldername/enterimagename.gif or jpg');
//----------------------------------------------------------------------------------------------------
var images = new Array();
function jsLoadImages(){ 
	for (var i=0; i < jsLoadImages.arguments.length; i++) {
		images[i] = new Image();
		images[i].src = jsLoadImages.arguments[i];
	}
}
//----------------------------------------------------------------------------------------------------
//-- Redirect the browser to the url provided
//----------------------------------------------------------------------------------------------------
function redirectBrowser(url) {
	location.href = url;
}
//----------------------------------------------------------------------------------------------------
//-- Check for valid e-mail address
//----------------------------------------------------------------------------------------------------
function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	if (user.match(userPat)==null) {
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	if (len<2) {
		return false;
	}
	return true;
}
