// Session("verJSFunctions") = "1.2"



// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
		
// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (obj.options==null) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].value] = to.options[i].text;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		var o=from.options[i]; 
		if (o.selected) { 
			from.options[i] = null; 
			} 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}

// -------------------------------------------------------------------


function CalPop(sInputName)
{
	window.open('/Common/Calendar.asp?N=' + escape(sInputName) + '&DT=' + escape(window.eval(sInputName).value), 'CalPop', 'toolbar=0,width=378,height=225');
}


function initPage()
{
	var defaultResolution = '76%';  // Optimized for 800x600

	// Trap ALT + SHIFT
	if( document.captureEvents ) { document.captureEvents( Event.KEYDOWN ); }
	document.onkeydown = keypressed; 


	// Draw Menu
	if (window.drawMenuLayer) 
	{
		drawMenuLayer();
	}
	
	// Get Maximum Resolution
	if (window.doGetResolution) 
	{
		defaultResolution = doGetResolution();
	}

	// Get Browser Resolution
	if (window.calcBrowserResolution()) 
	{
		defaultResolution = calcBrowserResolution();
	}

	// Set Resolution
	if (window.doSetResolution) 
	{
		doSetResolution(defaultResolution);
	}

	// ReSize Menus
	if (window.reSizeMenu) 
	{
		reSizeMenu(document.body.style.fontSize);
	}

	if (window.runClock) 
	{
		 runClock(); 
	}

}

// Trap ALT + SHIFT
function keypressed(myEvent)
{
	// Determine if ALT and SHIFT pressed together!
	
	if (event.shiftKey && event.altKey) 
	{ 
		if (document.body.style.fontSize == '100%')
		{
			alert('Switching website to Normal mode...'); 
			doSetResolution('76%');
		}
		else
		{
			alert('Switching website to High Visibility mode...'); 
			doSetResolution('100%');
		}
	}
}

// Get screen resolution
function doGetResolution()
{
	var scrnWidth;
	
	scrnWidth = screen.width;

	if (screen.width <= 640)
	{
		return '60%';
	}
	if (screen.width > 640 && screen.width <= 800)
	{
		return '76%';
	}
	if (screen.width > 800 && screen.width <= 1152)
	{
		return '109%';
	}
	if (screen.width > 1152 && screen.width <= 1280)
	{
		return '121.95%';
	}
}
// Set screen resolution
function doSetResolution(varRes)
{
	var newResolution = varRes;

	document.body.style.fontSize = newResolution;

	if (window.reSizeMenu) // If reSizeMenu function available execute it!
	{
		reSizeMenu(document.body.style.fontSize);
	}
}

// Calculate browser resolution
function calcBrowserResolution()
{
	var varModifier = 10.44;

	var browserWidth = document.body.offsetWidth-20;

	var newRes = browserWidth / varModifier;

	return newRes + '%';
}


// Place clock in staus bar

function runClock() {
	theTime = window.setTimeout("runClock()", 1000);
	var today = new Date();
	var display = today.toLocaleString();
	window.status = display;
}

bBool=false
var copiedtext=""
var tempstore=""

function initiatecopy() {
bBool=true;
}

function copyit() 
{
	if (bBool) {
		tempstore=copiedtext
		document.execCommand("Copy")
		copiedtext=window.clipboardData.getData("Text");
		bBool=false;
	}
}



// Copy element to clipboard
function pasteClipBoard(strElement) 
{
	Copied =document.getElementById(strElement).createTextRange();
	Copied.execCommand("RemoveFormat");
	Copied.execCommand("Copy");
}

function copyClipboard()
{

	document.getElementById('systemClipboard').value = window.clipboardData.getData('Text');
	pasteClipBoard("systemClipboard")
	frames.message.document.execCommand("paste");
}


function DisplayMessage(strAlert)
{
	if (strAlert != '')
	{
		alert(strAlert);
	}
}

/* ##############################################

    suycTextBoxLength - use this function to 
    dynamically resize an INPUT TYPE="text" element
    
   ##############################################*/
   
var MIN_SIZE = 15 ;
var MAX_SIZE = 40 ;

function changeTextBoxLength ( e ) {
// The function is called and we pass in a 
// reference to the calling element.

    var bigSize ;
    var f = e.form ;
    
    // If no size has been specified in the textbox then
    // default our maximum width to our MAX_SIZE
    // value.
    if((f.maxSize.value == null ) || (f.maxSize.value == "" )) {  
		bigSize = MAX_SIZE ;
	} else {
	// If a value has been typed into max. value then
	// check to see if it is a number, and, if so assign it
	// as the maximum size to use.
	    bigSize = parseInt(f.maxSize.value) ;
	    if ( isNaN( bigSize ) ) bigSize = MAX_SIZE;
	}
    
    // Now we finish off by determining whether or
    // not the length of text that has been entered
    // into the text box exceeds our maximum length
    // value.  If not we grow the box according to the
    // length of the value in the box until we reach
    // max value size.
    if ( e.value.length < MIN_SIZE )
        e.size = MIN_SIZE;
    else if (e.value.length < bigSize) 
        e.size =  e.value.length + 1;
    else
        e.size = bigSize;
       
}

/* ##############################################

    suycTextAreaLength - use this function to 
    dynamically resize a TEXTAREA element
    
   ##############################################*/


var MIN_ROWS = 1 ;
var MAX_ROWS = 8 ;
var MIN_COLS = 15 ;
var MAX_COLS = 0 ;

function changeTextAreaLength ( e ) {
// The function is called and we pass in a 
// reference to the calling element.

	if (MAX_COLS == 0)
	 {
			alert('Width : ' + e.offsetWidth + '\n' + 'Font Width : ' + this.document.body.style.fontSize);
		MAX_COLS = e.offsetWidth / e.style.fontSize;
	}

    var txtLength = e.value.length;
    var numRows = 0 ;
   // Split the textarea value at each linebreak.
    var arrNewLines = e.value.split("\n");
    
    for(var i=0; i<=arrNewLines.length-1; i++){
    // Iterate through the array for each element in the
   // array we add 1 row to the TEXTAREA..
        numRows++;
        if(arrNewLines[i].length > MAX_COLS-5) {
        // Within each element in our array, determine
        // whether the length of text is greater that our
        // MAX_COLS value.  If so, then we need another
        // row for each time that the length is greater than
        // the MAX_COLS value.
            numRows += Math.floor(arrNewLines[i].length/MAX_COLS)
        }   
    } 
    
    if(txtLength == 0){
    // If there is no text in the TEXTAREA we default
    // to our minimum values.
        e.cols = MIN_COLS ;
        e.rows = MIN_ROWS ;
    } else {
    // If there is only 1 row, then all we need to
    // determine is how many COLS we need.  It will be
    // somewhere between our MIN_COLS & MAX_COLS 
    // values.
        if(numRows <= 1) {
            e.cols = (txtLength % MAX_COLS) + 1 >= MIN_COLS 
                ? ((txtLength % MAX_COLS) + 1) 
                : MIN_COLS ;
        }else{
        // If there is more than 1 row then we immediately
        // default to our MAX_COLS value, and then determine
        // how many ROWS we need.
            e.cols = MAX_COLS ;    
            e.rows = numRows > MAX_ROWS ? MAX_ROWS : numRows ;
        }
    }
}

/* ##############################################

    Here's the sample code for using 
    these functions in your own pages.
    Watch out for line wrapping - 
    I've. added _'s to indicate a line
    wrap - you'll need to remove them.

	
	// Sample for using dynamic TEXTBOX.>
    <INPUT TYPE="text" 
          NAME="eText1" 
          SIZE="15" 
          onFocus="myInterval = window.setInterval( _
                       'changeTextBoxLength(document.frm.eText1)', 1)" 
          onBlur="window.clearInterval(myInterval) ;" />
               
    // Sample for using dynamic TEXTAREA.>
    <TEXTAREA NAME="eTxtArea1" 
              ROWS="1" 
              COLS="15" 
              onFocus="myInterval = 
                  window.setInterval( _
                       'changeTextAreaLength(document.frm.eTxtArea1)', 1) ;" 
              onBlur="window.clearInterval(myInterval) ;">

   ##############################################*/

function CheckNumericKey(iWnd)
{
	if (((window.event && window.event.keyCode >= 48) && window.event.keyCode <= 57) || window.event.keyCode == 32) 
    {
		return true;
	}
	window.event.keyCode = '';
	alert('Please only use numeric keys!');
	return false;
}

function CheckAlphaNumericKey(iWnd)
{
	if (window.event && window.event.keyCode != 39) 
    {
		return true;
	}
	window.event.keyCode = '';
	alert('Please only use alpha-numeric keys!');
	return false;
}


function CheckDateKey(iWnd)
{
var tmpValue = '';

	tmpValue = iWnd.value;

	if (window.event && (window.event.keyCode >= 48 && window.event.keyCode <= 57)) 
    {
		if (tmpValue.length < 10)
		{
			
			if (tmpValue.length + 1 == 2 || tmpValue.length + 1 == 5)
			{
				iWnd.value = tmpValue + String.fromCharCode(window.event.keyCode) + '/';	

			}
			else
			{
				iWnd.value = tmpValue + String.fromCharCode(window.event.keyCode);

			}
			window.event.keyCode = '';

			return true;
		}
		else
		{
			window.event.keyCode = '';
			return false;
		}
	}
	window.event.keyCode = '';
	alert('Please only use numeric keys!');
	return false;
}

function ValidateDate(strMessage, objName)
{
	var datefield = objName;

	objName.value = trim(objName.value);
	if (chkdate(objName) == false) {
		datefield.select();
		alert(strMessage + "The date you have enetered is invalid.  Please try again.");
		datefield.focus();
		return false;
	}
	else {
		return true;
   }
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function chkdate(objName) {
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;
	if (strDate.length < 1) {
	return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
	strDateArray = strDate.split(strSeparatorArray[intElementNr]);
	if (strDateArray.length != 3) {
	err = 1;
	return false;
	}
	else {
	strDay = strDateArray[0];
	strMonth = strDateArray[1];
	strYear = strDateArray[2];
	}
	booFound = true;
	   }
	}
	if (booFound == false) {
	if (strDate.length>5) {
	strDay = strDate.substr(0, 2);
	strMonth = strDate.substr(2, 2);
	strYear = strDate.substr(4);
	   }
	}
	if (strYear.length == 2) {
	strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") {
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
	err = 2;
	return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
	for (i = 0;i<12;i++) {
	if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
	intMonth = i+1;
	strMonth = strMonthArray[i];
	i = 12;
	   }
	}
	if (isNaN(intMonth)) {
	err = 3;
	return false;
	   }
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
	err = 4;
	return false;
	}
	if (intMonth>12 || intMonth<1) {
	err = 5;
	return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
	err = 6;
	return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
	err = 7;
	return false;
	}
	if (intMonth == 2) {
	if (intday < 1) {
	err = 8;
	return false;
	}
	if (LeapYear(intYear) == true) {
	if (intday > 29) {
	err = 9;
	return false;
	}
	}
	else {
	if (intday > 28) {
	err = 10;
	return false;
	}
	}
	}
	if (strDatestyle == "US") {
	datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else {
	datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
	}
	function LeapYear(intYear) {
	if (intYear % 100 == 0) {
	if (intYear % 400 == 0) { return true; }
	}
	else {
	if ((intYear % 4) == 0) { return true; }
	}
	return false;
	}
	function doDateCheck(from, to) {
	if (Date.parse(from.value) <= Date.parse(to.value)) {
	alert("The dates are valid.");
	}
	else {
	if (from.value == "" || to.value == "") 
	alert("Both dates must be entered.");
	else 
	alert("To date must occur after the from date.");
   }
}
function CheckEmailKey()
{
	if (window.event && ((window.event.keyCode >= 48 && window.event.keyCode <= 57) || (window.event.keyCode >= 97 && window.event.keyCode <= 122) || (window.event.keyCode >= 65 && window.event.keyCode <= 90)) || (window.event.keyCode == 45 || window.event.keyCode == 46 || window.event.keyCode == 95 || window.event.keyCode == 64) )
    {
		return true;
	}
	window.event.keyCode = '';
	alert('Please enter a valid email address!');

	return false;
}

function ValidateEmail(email){

var atPos = email.indexOf("@",1)

var dotPos = email.indexOf(".")

var invChar = "/,;"



	//check that  email addrs. are not empty

	if(email == null || email == ""){

		alert("You must enter an email addess in both fields")

		return false



	//check if email addrs. has an @ symbol

	} else if(atPos== -1){

		alert("Missing @ symbol or charcters before the symbol")

		return false



	//check if email addrs. are missing a period

	} else if(dotPos == -1){

	alert("Missing period'.'")

	return false

	

	//if email addrs. are ok to this point
	//check for invalid characters

	} else if(email != false){

	for(i=0; i < invChar.length; i++){

	badChar=invChar.charAt(i)

		if(email.indexOf(badChar,0) > -1){

			alert("Invalid character ' " + badChar + " '")
	
			return false
			}

		}

	}
	if (email.lastIndexOf('.') == email.length - 1) 
	{
		alert("No domain name specified.")
		return false;
	}

	//if email addrs. are ok at this point 

	return true
}



