/* CopyrightTag: Copyright (c) 2004-2008 Satmetrix Systems, Inc. All Rights Reserved. */
/* $Id: jsFunctions.js,v 1.1.1.1.2.1 2009/02/11 12:45:53 mmenghani Exp $ */
/*
 * Javascript functions for validation of form fields in efocus.
 *
 */

/* Strings for use in error messages.  These and the text in the "newError" function may be altered as desired. */
var MANDATORY_ERROR_STRING = " must be answered";
var INTEGER_ERROR_STRING = " must be a valid integer";
var DOUBLE_ERROR_STRING = " must be a valid number";


// DON'T CHANGE THESE!  They have to match values passed in from the server.
var INT_TYPE = "Int";
var DOUBLE_TYPE = "Double";
var STRING_TYPE = "String";
var DATE_TYPE = "Date";

// This note is tacked on to the beginning of the error message before shown to the user.  Change text as desired.
var errorNote = "";

var errors = "";

/*
 * Validates that one of the radio buttons has been selected.  
 * Returns an error message if not.
 */
function validateRadio (formName, radioName, radioDescr) {

	var radioObj = eval ("document." + formName + "." + radioName);
	for (var i=0; i<radioObj.length; i++) {
		if (radioObj[i].checked) {
			return "";
		}
	}
	return newError(MANDATORY_ERROR_STRING, radioName, radioDescr);
}


/*
 * Validated that at least one checkbox with the given name has been checked.  
 * Returns an error message if not.
 */
function validateCheckbox (formName, checkName, checkDescr) {
	var formObj	= eval("document." + formName);
	for (var i=0; i<formObj.elements.length; i++) {
		if (formObj.elements[i].name == checkName && formObj.elements[i].checked) {
			return "";
		}	
	}
	return newError(MANDATORY_ERROR_STRING, checkName, checkDescr);
}

/*
 * Validates that the selected item in the selection list has a non-emtpy value.  
 * Returns an error message if not.
 */
function validateSelect (formName, selName, selDescr, isMulti) {
	var selObj = eval ("document." + formName + "." + selName);
	var selIndex = selObj.selectedIndex;
	if (selIndex < 0) {
		return newError(MANDATORY_ERROR_STRING, selName, selDescr);
	} 
	var val = selObj.options[selIndex].value;
	if (isEmpty(val)) {
		return newError(MANDATORY_ERROR_STRING, selName, selDescr);
	}
	return "";
}

/*
 * Validates that the contents of the given text field are not empty.  
 * Also checks the type of the content if not empty.
 * Returns an error message if empty.
 */
function validateTextfield (formName, textName, textDescr, type) {
	
        var textObj = eval("document." + formName + "." + textName);
	var content = textObj.value;
        if (isEmpty(content)) {
                return newError(MANDATORY_ERROR_STRING, textName, textDescr);
	} 
	return validateTextType(formName, textName, textDescr, type);
}

/*
 * Validates that the contents of the given text field are not empty only if
 * the given that the multiple answer type is selected with the flagged value.
 * Also checks the type of the content if not empty.
 * Returns an error message if empty.
 */
function validateTextfieldBasedOn (formName, textName, textDescr, type, basedOnElementName, basedOnSelectedValue, basedOnType) {
    if (isBasedOnSelected( formName, basedOnElementName, basedOnSelectedValue, basedOnType )){
        //then this is required, thus the validation
        return validateTextfield (formName, textName, textDescr, type);
    }
    return "";
}

function isBasedOnSelected( formName, basedOnElement, basedOnSelectedValue, basedOnType ){
    
    if (basedOnType == "Select"){
        var selObj = eval ("document." + formName + "." + basedOnElement);
	
        for (var i=0; i < selObj.options.length; i++){  
            if (selObj.options[i].selected){
                if (selObj.options[i].value == basedOnSelectedValue){
                    return true;
                }
            }
        }
       
	return false;
    }

    if (basedOnType == "CheckBox"){
        var formObj	= eval("document." + formName);
	for (var i=0; i<formObj.elements.length; i++) {
            if (formObj.elements[i].name == basedOnElement){
                if (formObj.elements[i].checked) {
                    if (formObj.elements[i].value == basedOnSelectedValue) {
                        return true;
                    }
                }
            }	
	}
        return false;
    }

    if (basedOnType == "RadioButton"){
        var radioObj = eval ("document." + formName + "." + basedOnElement);
	for (var i=0; i<radioObj.length; i++) {
            if (radioObj[i].checked) {
                if (radioObj[i].value == basedOnSelectedValue){
                    return true;
                }
            }
	}
        return false;
    }

    return false;
}

/*
 * Validate that the contents of the text field are of the given type.
 */
function validateTextType(formName, textName, textDescr, type) {
	var textObj = eval("document." + formName + "." + textName);
	var content = trim(textObj.value);
	if (content == null || content == "") {
		return "";
	}
	if (type == "Int") {
		if (! isInteger(trim(content))) {
			return newError(INTEGER_ERROR_STRING, textName, textDescr);
		}
	} else if (type == "Double") {
		if (! isNumber(trim(content))) {
			return newError(DOUBLE_ERROR_STRING, textName, textDescr);
		}
	}
	return "";
}


/*
 * Creates an error string by appending the error to the description or name of the field.
 */
function newError(newError, name, descr) {
    errorStr = ((descr == null ? name : descr) + newError + "\r\n");
    return errorStr;
}


//
// Currency Range Validation Support
//

function removeCommasFromString(string){
	while (string.search(/,/) > -1){
		string = string.replace(/,/, "");
	}
	return string;
}

function isValidCurrencyInRange(fieldValue, min, max){

	var re = /^-?((\d*(\.\d{0,2})?)|(\d{1,3}(,\d{3})+(\.\d{0,2})?))$/;

	if (re.test(fieldValue)){
		
		//filter out any commas if present
		var cleanValue = removeCommasFromString(fieldValue);
		
		if (max != null){
			if (cleanValue > max){
				return false;
			}	
		}
		
		if (min != null){
			if (cleanValue < min){
				return false;
			}
		}
	
		return true;	
	}
	return false;
}

function validateCurrencyRangeField(fieldValue, min, max, errorMessage){
	
	//only validate if field is something
	if (fieldValue != null && fieldValue != ""){
		
		if (isValidCurrencyInRange(fieldValue, min, max)){
			return true;
		} else {
			alert(errorMessage);
			return false;
		}		
	}
}

var currencyRangeFieldsToValidate = new Dictionary();

//CurrencyRangeValidate 'object'
function CurrencyRangeValidateElement(element, min, max, displayFieldName, conceptDisplayName){
	this.element = element;
	this.min = min;
	this.max = max;
	this.displayFieldName = displayFieldName;
        this.conceptDisplayName = conceptDisplayName;
}

function addBatchCurrencyRangeValidator(element, min, max, displayFieldName, conceptDisplayName){
	
	//create new entry for validation
	var newElement = new CurrencyRangeValidateElement(element, min, max, displayFieldName, conceptDisplayName);
	
	//add element to the dictionary
        var key = element.name;
        if (conceptDisplayName != null && conceptDisplayName != ''){
            key += concept_seperator;
            key += conceptDisplayName;
        }
	currencyRangeFieldsToValidate.setAt(key, newElement);
}





//
// Number Range Validation Support
//

function isValidNumberAndInRange(fieldValue, min, max){

	var re = /^-?\d+$/;
	if (re.test(fieldValue)){
		if (max != null){
			if (fieldValue > max){
				return false;
			}
		}
		
		if (min != null){
			if (fieldValue < min){
				return false;
			}
		}
		
		return true;
	}
	return false;
}

function validateNumberRangeField(fieldValue, min, max, errorMessage){
	
	//only validate if field is something
	if (fieldValue != null && fieldValue != ""){
		
		if (isValidNumberAndInRange(fieldValue, min, max)){
			return true;
		} else {
			alert(errorMessage);
			return false;
		}		
	}
}

var numberRangeFieldsToValidate = new Dictionary();

//numberRangeValidate 'object'
function NumberRangeValidateElement(element, min, max, displayFieldName, conceptDisplayName){
	this.element = element;
	this.min = min;
	this.max = max;
	this.displayFieldName = displayFieldName;
        this.conceptDisplayName = conceptDisplayName;
}

function addBatchNumberRangeValidator(element, min, max, displayFieldName, conceptDisplayName){

    //create new entry for validation
    var newElement = new NumberRangeValidateElement(element, min, max, displayFieldName, conceptDisplayName);
	
    //add element to the dictionary
    var key = element.name;
    if (conceptDisplayName != null && conceptDisplayName != ''){
        key += concept_seperator;
        key += conceptDisplayName;
    }
    numberRangeFieldsToValidate.setAt(key, newElement);
}



//
// Expression Validation Support
//
function validateExpressionField(fieldValue, expression, errorMessage){
	
	if (fieldValue != null && fieldValue != ""){   
		if (expression.test(fieldValue)){
			return true;
		} else {
			alert(errorMessage);
			return false;
		}
	}
} 

//
// Expression Validation Support
//
function validateExpressionField2(fieldValue, expression, errorMessage){
	
	
	if (fieldValue != null && fieldValue != ""){   
		if (expression.test(fieldValue)){
			return "";
		} else {
			return (errorMessage);
		}
	}
} 

var expressionFieldsToValidate = new Dictionary();

var concept_seperator = "___CONCEPT_SEPERATOR___";

//expressionValidateElement 'object'
function ExpressionValidateElement(element, expression, displayFieldName, conceptDisplayName){
	this.element = element;
	this.expression = expression;
	this.displayFieldName = displayFieldName;
        this.conceptDisplayName = conceptDisplayName;
}

function addBatchExpressionValidator(element, expression, displayFieldName, conceptDisplayName){

	//create a new entry for validaiton
	var newElement = new ExpressionValidateElement(element, expression, displayFieldName, conceptDisplayName);
		
	//add the element to the dictionary
        var key = element.name;
        if (conceptDisplayName != null && conceptDisplayName != ''){
            key += concept_seperator;
            key += conceptDisplayName;
        }
	expressionFieldsToValidate.setAt(key, newElement);
}




/*
 * Method that handles mutual exclusive choices from a set.
 */
function checkMutEx(choiceIsMutEx, elementsToCheck, widget, mutExElements){

    	if (choiceIsMutEx){
    	
    		//this widget is flagged as being mutually exclusive	
    		
    		if (widget.checked){
    		
    			//loop through all other elements and if any are checked fail
    			for (i=0; elementsToCheck != null && i < elementsToCheck.length; i++){

    				if (elementsToCheck[i].checked && elementsToCheck[i] != widget){
    					alert("You cannot select this choice because it is mutually exclusive and other choices are checked.");
						widget.checked = false;
    					return false;
    				}
    			}
    		}
    			
		} else {			
	
			//this widget it NOT flagged as being mutually exclusive
			
			if (widget.checked){
			
				//since it is checked we need to make sure none of the mutual exclusive checkboxes are checked.
			
    			//loop through all others and if one of the mutExElements are seleceted fail
    		
				for (x=0; elementsToCheck != null && x < elementsToCheck.length; x++){
				
					var tempCheckbox = elementsToCheck[x];
				
					//if the one being iterated through matches the one that called this method then skip it
					if (tempCheckbox == widget){
						continue;
					}
				
					if (tempCheckbox.checked){
					
						var tempCheckboxName = tempCheckbox.value;
						
						for (n=0; mutExElements != null && n < mutExElements.length; n++){
							if (tempCheckboxName == mutExElements[n]){
								alert("You cannot select this choice because a mutually exclusive choice is already checked.");
								widget.checked = false;
								return false;
							}
						}
					}
				}
			} else {
				//ignore it if the widget is not being checked, which just means that the user unchecked the box
			}
    	}
    	return true;    
    }



    //
    // Mutual Exclusive MulitSelect support
    //

   var lastGoodStatesForMultiSelects = new Dictionary();
    
    function checkMultiSelectMutEx(multiSelect, mutExIndexesArray){
       	
    	//first make sure that something is actually selcted
    	if (multiSelect == null || multiSelect.selectedIndex < 0){
    		return;
    	}
    	
    	var multiSelectSelected = false;
    	var nonMultiSelectSelected = false;
    	
    	//
    	//validate
    	//
    	
    	//iterate through all options
    	for (var i = 0; i < multiSelect.length; i++){
     		
     		if (multiSelect.options[i].selected){		

				//check to see if this is a mutex choice
				if (isObjectInArray(i, mutExIndexesArray)){
					
					//reject if another mutext already selected
					if (multiSelectSelected){
						alert("A mutually exclusive choice has already been selected, thus you cannot select this choice.");
						revertBack(multiSelect, lastGoodStatesForMultiSelects.lookUp(multiSelect.name));
						return;
					}
					
					//reject if any non mutex are selected
					if (nonMultiSelectSelected){
						alert("A non-mutually exclusive choice has already been selected, thus you cannot select this choice.");
						revertBack(multiSelect, lastGoodStatesForMultiSelects.lookUp(multiSelect.name));
						return;
					}
					
					multiSelectSelected = true;
				} else {
					//not mutex
					
					//reject if mutex already selected				
					if (multiSelectSelected){
						alert("A mutually exclusive choice has already been selected, thus you cannot select this choice.");
						revertBack(multiSelect, lastGoodStatesForMultiSelects.lookUp(multiSelect.name));
						return;
					}
					
					nonMultiSelectSelected = true;
				}
    		}
    	}
    	
      	//
    	//save 'last-good' state
    	//
    	var selectedIndexes = new Dictionary();
    	for (var i = 0; i < multiSelect.length; i++){
     		if (multiSelect.options[i].selected){		
    			selectedIndexes.setAt(i, i);
      		}
    	}	
    	lastGoodStatesForMultiSelects.setAt(multiSelect.name, selectedIndexes);
    }
    
    
    
    function revertBack(multiSelectElement, selectedChoicesDictionary){
    	
    	//if we don't have any selected choices, that means that none are saved
    	if (selectedChoicesDictionary == null){
      		for (var i = 0; i < multiSelectElement.options.length; i++){
    			multiSelectElement.options[i].selected = false;
			}
    		return;
    	}
		
    	//loop thorugh all items and set selected if necessary...
    	for (var i = 0; i < multiSelectElement.options.length; i++){
    		
    		if (selectedChoicesDictionary.lookUp(i) != null ){
    			multiSelectElement.options[i].selected = true;
    		} else {
    			multiSelectElement.options[i].selected = false;
    		}
    	}
    	
    }
	
	function isObjectInArray(object, array){
		
		for (var i = 0; i < array.length; i++){
			if (array[i] == object){
				return true;
			}
		}
		return false;
	}
    


  function selectItem( select, item ) {

    for (var i = 0;i < select.length;i++ ) {
      if ( select.options[i].text == item ) {
	select.options[i].selected = true;
        i = select.length;
      }
    }
  }

  function selectItemByValue( select, item ) {

    for (var i = 0;i < select.length;i++ ) {
      if ( select.options[i].value == item ) {
        select.options[i].selected = true;
        i = select.length;
      }
    }
  }
  
  function selectRadioByValue (formName, radioName, value) {

	var radioObj = eval ("document." + formName + "." + radioName);
	for (var i=0; i<radioObj.length; i++) {
		if (radioObj[i].value==value) {
			radioObj[i].checked=true;
			i = radioObj.length;
		}
	}

}


/*
 * @(#)util.js    1.0 4/17/00 Gregory D. Clemenson
 *
 * Copyright (c) 2000
 * Recipio
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Recipio;
 * the contents of this file may not be disclosed to third parties, copied or
 * duplicated in any form, in whole or in part, without the prior written
 * permission of Recipio.
 *
 */

// History:
//   Jan 03 2000   jwalton - added checkTextLength255 function
//   Nov 17 2000   jwalton - isEmpty now uses trim instread of regexp so it works with Mac Netscape
//   Nov 15 2000     manda - changed method trim to fix 'single char not taken as idea' bug
//   Nov 10 2000   jwalton - added isInteger, isDouble, and isEmpty
//   Aug 14 2000     mchen - changed parameter name for
//                           isWhiteSpaceChar to fix bug in Netscape

// Byte-by-byte hex strings:
var hexDigits = "0123456789ABCDEF"
function hexString(n) {
    var str = ""
    if(n > 255) {
        str = hexString(n >> 8)
        n &= 255
    }
    return str + hexDigits.charAt(n >> 4) + hexDigits.charAt(n & 15)
}

// Turn an array to a tab-delimited string.
// Converts contained tabs to 4 spaces.
function packArray(ar) {
    var str = ""
    if(!ar || ar.length == 0) {
        return str
    }
    var len = ar.length
    for(var i = 0; i < len; ++i) {
        if(i > 0) {
            str += "\t"
        }
        var val = ar[i]
        if(typeof val == "string") {
            // Convert tabs:
            var x0 = 0
            var x1
            while((x1 = val.indexOf("\t", x0)) >= 0) {
                str += val.substring(x0, x1)
                str += "    "
                x0 = x1 + 1
            }
            str += x0 > 0 ? val.substring(x0, val.length) : val
        } else {
            str += val
        }
    }
    return str;
}

// Returns the input string minus leading and trailing whitespace
function trim(str) {
    if (!str) {
        return ""
    }
    var len = str.length
    var x0 = 0
    var xn = len-1
    while (x0 <= xn && isWhiteSpaceChar(str.charAt(x0))) {
        ++x0
    }
    while (xn >= x0 && isWhiteSpaceChar(str.charAt(xn))) {
        --xn
    }
	return str.substring(x0, xn+1)
//    return (x0 == xn) ? "" : str.substring(x0, xn+1)
}

function isWhiteSpaceChar(checkChar) {
    return " \t\n\r\f".indexOf(checkChar) >= 0 ? 1 : 0
}

/* Return true if the value passed in can be interpreted as an integer (negative or positive) */
function isInteger(val) {
	str = new String(val);
	for (var i=0; i<str.length; i++) {
		var ch = str.charAt(i);
		if (i == 0 && ch == "-") {
			continue;
		}
		if (ch < "0" || ch > "9") {
			return false;
		}
	}
	return true;
}

/* Return true if the value passed in can be interpreted as a number (integer or double) */
function isNumber(val) {
	oneDecimal = false;
	str = val.toString();
	for (var i=0; i<str.length; i++) {
		var ch = str.charAt(i);
		if (i == 0 && ch == "-") {
			continue;
		}
		if (ch == "." && !oneDecimal) {
			oneDecimal = true;
			continue;
		}
		if (ch < "0" || ch > "9") {
			return false;
		}
	}
	return true;	
}

/* Return true if the string is all whitespace (of any kind) */
function isEmpty(inString) {
	var trimmedStr = trim(inString);
	return (trimmedStr == null || trimmedStr == "");
	//var re = /\w+/;
	//answer = re.exec(inString);
	//return (answer == null || answer == "");
}

/* Check if the widget passed in has more than 255 characters entered.  
 * If so, show an alert message and trim the string to 255.  This is 
 * done because the database will not accept more than 255 characters.
 */
function checkTextLength255(textWidget) {
    var len = textWidget.value.length;
        if (len > 255) {
            window.alert('You may only enter up to 255 characters');
            textWidget.value = textWidget.value.substring(0, 255);
        }
}

/* --JavaScript Collection Object-- */
//~~Author~~. John Call jcall@sark.com

function CCollection() {
/* --CCollection object-- */
	var lsize = 0;

	this.add = _add;
	this.remove = _remove;
	this.isEmpty = _isEmpty;
	this.size = _size;
	this.clear = _clear;
	this.clone = _clone;

	function _add(newItem) {
	/* --adds a new item to the collection-- */
		if (newItem == null) return;

		lsize++;
		this[(lsize - 1)] = newItem;
	}

	function _remove(index) {
	/* --removes the item at the specified index-- */
		if (index < 0 || index > this.length - 1) return;
		this[index] = null;

		/* --reindex collection-- */
		for (var i = index; i <= lsize; i++)
			this[i] = this[i + 1];

		lsize--;
	}

	function _isEmpty() { return lsize == 0 }	/* --returns
boolean if collection is/isn't empty-- */

	function _size() { return lsize }	/* --returns the size of
the collection-- */

	function _clear() {
	/* --clears the collection-- */
		for (var i = 0; i < lsize; i++)
			this[i] = null;

		lsize = 0;
	}

	function _clone() {
	/* --returns a copy of the collection-- */
		var c = new CCollection();

		for (var i = 0; i < lsize; i++)
			c.add(this[i]);

		return c;
	}
}

/* --JavaScript Collection Object-- */
//~~Author~~. John Call jcall@sark.com

function Dictionary() {
// --Dictionary Object--
	this.setAt = _setAt;
	this.lookUp = _lookUp;
	this.remove = _remove;
	this.clear = _clear;
	this.keys = _keys;
	this.toString = _toString;
	
	this.length = 0;
	this._skeys = new Object();
	
	function _setAt(key, val) {
		if (key != null) {
			this.length++;
			this._skeys[key] = val;
		}
	}
	
	function _remove(key) {
		if (this._skeys[key]) {
			this.length--;
			return delete this._skeys[key];
		}
		else
			return false;
	}
	
	function _clear() {
		this._skeys = new Object();
		this.length = 0;
	}
	
	function _lookUp(key) { return this._skeys[key] }
	
	function _keys() { return this._skeys }
	
	function _toString() { return "[object Dictionary]" }
}


//GENERIC DROP DOWN NAVIGATION
function goDropDown(strForm,strElement) {
	var objElement = eval('document.' + strForm + '.' + strElement);
	var objElementValue = objElement[objElement.selectedIndex].value;
	if (objElementValue != "") {
		window.location = objElementValue;
	}
}

//RETURN FROM CHILD WINDOW
function returnParent(strURL) {
	if(window.opener) {
		window.opener.location = strURL;
	}
	else if(window.parent) {
		window.parent.location = strURL;
	}
	window.close();
}

//GLOBAL POPUP
var objChildWindow;
function doChildWindow(strURL, objWin, strOptions) {
	//check for open windows and close them
	if (objChildWindow && objChildWindow.closed == false) {
		objChildWindow.close();

		objChildWindow = window.open(strURL, objWin, strOptions);
		objChildWindow.focus();
	}
	else {
		objChildWindow = window.open(strURL, objWin, strOptions);
		objChildWindow.focus();
	}
}

function openPrintPage(strURL) {
	var strOptions;
	strOptions = "toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,left=100,top=100,width=620,height=500";

	doChildWindow(strURL, 'child_window', strOptions);
	objChildWindow.focus();
}



//VIEW LARGE IMAGE
function openNewImgWin(strImg, strTitle, intWidth, intHeight) {
	var strOptions;
	//check for parameters and set defaults
	if ((intWidth == '') || (intHeight == '')) {
		strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=400,height=400";
	}
	else {
		intWidth += 45;
		intHeight += 45;
		strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
	}
	//check for browser and execute
	if (!(objBrowser.bMacNN4)) {
		doChildWindow('', 'child_window', strOptions);
		var strHTML;
		strHTML  = '<html><head><title>Bose&#174; ' + strTitle + '</title></head><body marginwidth="10" marginheight="10" leftmargin="10" topmargin="10" alink="#999999" vlink="#666666" bgcolor="#ffffff"><font face="verdana" size="1">';
		strHTML += '<div align="center"><img src="' + strImg + '" /></div>';
		strHTML += '<div align="right"><a title="Close window" href="javascript:window.close();"><font color="#000000">Close window</font></a></div></font></body></html>';
		objChildWindow.document.open();
		objChildWindow.document.write(strHTML);
		objChildWindow.document.close();
	}
	else {
		doChildWindow(strImg, 'child_window', strOptions);
	}
	//focus the new window
	objChildWindow.focus();
}

//EMAIL NEWS LETTER EMAIL VALIDATE
function checkInputEmail(theForm) {
	if ((theForm.enews.value=="") || (theForm.enews.value.indexOf("@") == -1) || (theForm.enews.value.indexOf(".") == -1)) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}

//SEARCH FIELD VALIDATE
function checkInputSearch(theForm) {
	if ((theForm.words) && (theForm.words.value=="")) {
		alert("Please enter your search criteria.");
		return false;
	}
	return true;
}

//PRINT FUNCTION
function doPrint() {
	window.print();
}

//IMAGE PRELOAD
//imgObj - the name of the object associated with the image 
//imgSrc - the source filename (url) of the image
function doPreload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj + ' = new Image()');
		eval(imgObj + '.src = "' + imgSrc + '"');
	}
}



//SUBMIT A FORM FUNCTION
//theForm - the name or id of the form to be submitted
//validateFunction - the name of the client side validation function to be called.
function submitForm(theForm, validateFunction) {
	document.forms[theForm].submit();
	if (validateFunction != "") {
		eval(validateFunction + '(' + theForm + ')');
	}
}

//HISTORY NAVIGATION
//i - the place in the history array ( can be a negative | positive number )
function goHistory(i) {
	var i;
	history.go(i);
}

//CONFIRM WINDOW GENERIC
//strMessage - the confirmation message to be displayed
function confirmDialogue(strMessage) {
		if (window.confirm(strMessage)) {
			return true;
		}
	return false;
}



function openHelpWindow(url) {
	var helpWindow = window.open(url, 'help', 'width=600,height=650,scrollbars=yes,resizable=yes,toolbar=no');
	helpWindow.focus();
}


function launchWindow(url, width, height)
{
	if (width == null)
		width = 600;
	if (height == null)
		height = 155;

	var popUpWindow = window.open(url,'newwin', 'width=' + width + ',height=' + height + ',scrollbars=yes,resizable=yes,toolbar=no');
	popUpWindow.focus();
}



function launchPopup(url)
{
	launchWindow(url, 800, 600);
}



function launchSession(session)
{
	launchWindow(session, 800, 600);
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}




//Note:These scripts are used to detect the browser, browser version, and platform, of the client computer.
//Note:Dependencies here they must execute in this order - used by other global scripts, and page specific scripts.
//Author: Tim Dunham 5/22/03

//generic object containing the x-browser properties of the navigator object
var objAgent = new objAgent();
function objAgent()
{
	this.userAgent = navigator.userAgent.toLowerCase();
	this.codeName = navigator.appCodeName.toLowerCase();
	this.name = navigator.appName.toLowerCase();
	this.version = navigator.appVersion.toLowerCase();
	this.platform = navigator.platform.toLowerCase();
	this.plugins = navigator.plugins; //array
}

//client object variables
var strApplication  = getApplication();
var strApplicationMinor = getApplicationMinor();
var strPlatform = getPlatform();
var intAppVersion = getVersion();

//client object for generic client description
var objClient = new objClient();

function objClient()
{
	//calculate the application being used
	this.application = strApplication;
	//calculate the Minor application being used
	this.applicationMinor = strApplicationMinor;
	//calculate the platform being used
	this.platform = strPlatform;
	//calculate the version being used
	this.version = intAppVersion;
}

//client object for specific client description
var objBrowser = new objBrowser();

function objBrowser()
{
	//windows
	this.bWinIE4 = ((objClient.platform == "win") && (objClient.application == "ie") && (objClient.version == "4")) ? true : false;
	this.bWinIE5 = ((objClient.platform == "win") && (objClient.application == "ie") && (objClient.version == "5")) ? true : false;
	this.bWinIE6 = ((objClient.platform == "win") && (objClient.application == "ie") && (objClient.version == "6")) ? true : false;
	this.bWinIE7 = ((objClient.platform == "win") && (objClient.application == "ie") && (objClient.version == "7")) ? true : false;
	this.bWinNN6 = ((objClient.platform == "win") && (objClient.application == "nn") && (objClient.version >= 5)) ? true : false;
	this.bWinNN4 = ((objClient.platform == "win") && (objClient.application == "nn") && (objClient.version == "4")) ? true : false;
	this.bWinAOL = ((objClient.platform == "win") && (objClient.applicationMinor == "aol")) ? true : false;
	this.bWinOP = ((objClient.platform == "win") && (objClient.applicationMinor == "op")) ? true : false;
	//mac
	this.bMacIE4 = ((objClient.platform == "mac") && (objClient.application == "ie") && (objClient.version == "4")) ? true : false;
	this.bMacIE5 = ((objClient.platform == "mac") && (objClient.application == "ie") && (objClient.version == "5")) ? true : false;
	this.bMacNN6 = ((objClient.platform == "mac") && (objClient.application == "nn") && (objClient.version >= 5)) ? true : false;
	this.bMacNN4 = ((objClient.platform == "mac") && (objClient.application == "nn") && (objClient.version == "4")) ? true : false;
	this.bMacAOL = ((objClient.platform == "mac") && (objClient.applicationMinor == "aol")) ? true : false;
	this.bMacOP = ((objClient.platform == "mac") && (objClient.applicationMinor == "op")) ? true : false;
	this.bMacSA = ((objClient.platform == "mac") && (objClient.applicationMinor == "safari")) ? true : false;
}


//calculate the application
function getApplication()
{
	var strApp;

	if (objAgent.name.indexOf("microsoft") != -1)
	{
		strApp = "ie";
	}
	else if (objAgent.name.indexOf("netscape") != -1)
	{
		strApp = "nn";
	}
	else
	{
		strApp = "ie";
	}
	return strApp;
}

//calculate the Minor application
function getApplicationMinor()
{
	var strAppMinor;

	if (objAgent.userAgent.indexOf("opera") != -1)
	{
		strAppMinor = "op";
	}
	else if (objAgent.userAgent.indexOf("aol") != -1)
	{
		strAppMinor = "aol";
	}
	else if (objAgent.userAgent.indexOf("safari") != -1)
	{
		strAppMinor = "safari";
	}
	else
	{
		strAppMinor = false;
	}
	return strAppMinor;
}

//calculate the platform
function getPlatform()
{
	var strPlat;

	if (objAgent.platform.indexOf("win") != -1)
	{
		strPlat = "win";
	}
	else if ((objAgent.platform.indexOf("mac") != -1) || (objAgent.platform.indexOf("ppc") != -1))
	{
		strPlat = "mac";
	}
	else
	{
		strPlat = "win";
	}
	return strPlat;
}

//calculate the version of the application
function getVersion()
{
	var intApp;

	intApp = parseInt(objAgent.version);
	//IE4
	if ((strApplication == "ie") && (objAgent.userAgent.indexOf("msie 4") != -1))
	{
		intApp = 4;
	}
	//IE5
	else if ((strApplication == "ie") && (objAgent.userAgent.indexOf("msie 5") != -1))
	{
		intApp = 5;
	}
	//IE6
	else if ((strApplication == "ie") && (objAgent.userAgent.indexOf("msie 6") != -1))
	{
		intApp = 6;
	}
	//IE6
	else if ((strApplication == "ie") && (objAgent.userAgent.indexOf("msie 7") != -1))
	{
		intApp = 7;
	}
	//NN6
	else if ((strApplication == "nn") && ((objAgent.userAgent.indexOf("gecko") != -1) || (intApp >= 5)))
	{
		intApp = 6;
	}
	else
	{
		intApp = 4;
	}
	return intApp;
}


	function getValFromCookie(cookieName) 
	{
		var cookie = document.cookie;
		var index0 = cookie.indexOf(cookieName);
		
		if (index0 == -1 || cookieName == "") 
		{
			return "";
		}
		
		var index1 = cookie.indexOf(';',index0);
		if (index1 ==-1) 
		{
			index1 = cookie.length;
		}
		
		return unescape(cookie.substring(index0 + cookieName.length + 1, index1));
	}


function getValFromLPCookie(cookieName) {
 var cookie = getValFromCookie("listeningPostCookie");
 var index0 = cookie.indexOf(cookieName);

 if (index0 == -1 || cookieName == "") {
  return "";
 }

 var index1 = cookie.indexOf('@@',index0);

 if (index1 ==-1) {
   index1 = cookie.length;
 }
 return unescape(cookie.substring(index0 + cookieName.length + 1, index1));
}


function inf_popupWin(targetURL,winName,h,w,resizable,scrollbars) {
  var myName = (winName) ? winName : '_blank';
  var props,height,width,sb;
	
  height = (h) ? h : '490';
  width = (w) ? w : '500';
  sb = (scrollbars==0) ? 'no' : 'yes'
	
  props = 'height=' + height + ',';
  props += 'width=' + width + ',';
  props += 'menubar=0,resizable=';
  props += (resizable)?resizable:'0';
  props += ',scrollbars='+sb+',status=no';
  var myWin = window.open(targetURL, myName, props);
  
  myWin.focus();
}
