/*
The SoftAd Group
Copyright (c) 2000-2004 The SoftAd Group, Inc.  All rights reserved
*/
// -------------------------------------------------------------------------------
// File name        : channelnet.js
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 17, 2000
// 
// This file contains all client-side scripting functions required by the admin
// components of channelnet.
// -------------------------------------------------------------------------------
// Last Updated     : Wednesday, September 27, 2000
// Updated by       : Chad Peck
// -------------------------------------------------------------------------------
// Copyright © 2000 The SoftAd Group, Inc.

var MSG_VERR_ANYVALUE = 'The field is required';
var MSG_VERR_FIRSTNAME = 'A First Name must contain only letters and spaces.';
var MSG_VERR_INITIAL = 'An Initial must contain only a single letter.';
var MSG_VERR_LASTNAME = 'A Last Name must contain only letters, spaces, periods, dashes, and commas.';
var MSG_VERR_CITY = 'A City name must contain only letters, spaces, periods, dashes, and commas.';
var MSG_VERR_POSTALCODE = 'A Postal Code must contain only numbers, letters, spaces, and dashes.';
var MSG_VERR_PHONENUMBER = 'A Phone number must contain only numbers, letters, spaces, periods, dashes, pluses, and parentheses.';
var MSG_VERR_EMAIL = 'An Email address must contain an @ followed by a period followed by more than one letter.';
var MSG_VERR_COUNTRY = 'You must select a country';
var MSG_EXPIRATIONDATE = 'An expiration date is in the following format: mm/dd/yyyy';


// NOTE: Regular expression constants have been changed to allow for non-Latin chars.
var REGEXP_ANYVALUE_REQUIRED = '^.+$';
var REGEXP_FIRSTNAME_REQUIRED = '^.+$';	//'^[a-zA-Z ]+$';
var REGEXP_FIRSTNAME_OPTIONAL = '^.*$';	//'^[a-zA-Z ]*$';
var REGEXP_INITIAL_REQUIRED = '^.+$';	//'^[a-zA-Z]$';
var REGEXP_INITIAL_OPTIONAL = '^.*$';	//'^[a-zA-Z]?$';
var REGEXP_LASTNAME_REQUIRED = '^.+$';	//'^[a-zA-Z \\.\\-,\']+$';
var REGEXP_LASTNAME_OPTIONAL = '^.*$';	//'^[a-zA-Z \\.\\-,\']*$';
var REGEXP_LASTNAMENUMERIC_OPTIONAL = '^[a-zA-Z0-9 \\.\\-,\']*$';
var REGEXP_CITY_REQUIRED = '^.+$';	//'^[a-zA-Z \\.\\-,\']+$';
var REGEXP_CITY_OPTIONAL = '^.*$';	//'^[a-zA-Z \\.\\-,\']*$';
var REGEXP_PHONENUMBER_REQUIRED = '^[\\w()\\-. +]{1,20}$';
var REGEXP_PHONENUMBER_OPTIONAL = '^[\\w()\\-. +]{0,20}$';
var REGEXP_POSTALCODE_REQUIRED = '^[\\w \\-\\.]{1,13}$';
var REGEXP_POSTALCODE_OPTIONAL = '^[\\w \\-\\.]{0,13}$';
var REGEXP_EMAIL_REQUIRED = '^(.+@.+\\.[a-zA-Z]+)$';
var REGEXP_EMAIL_OPTIONAL = '^(.+@.+\\.[a-zA-Z]+)?$';
var REGEXP_COUNTRY_REQUIRED = '^.+$';
var REGEXP_EXPIRATIONDATE_REQUIRED = '^[0-1]{1}[0-9]{1}\/{1}[0-3]{1}[0-9]{1}\/{1}[1-2]{1}[0-9]{3}$';

// sets and initializes any global variables
//var isFieldError = false;	// boolean value determining whether validation can occur for a field
var previousFieldName;		// string name of the field which was previously validated
var imgs;
var wasSubmitted = false;   // boolean used to determine if the page has already been submitted

imgs = new Array();

// -------------------------------------------------------------------------------
// Function         : imagesToSwap(plainImage, highlightedImage)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function creates two images: a plain one and one that is highlighted on a
// mouseover event.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// plainImage       string		The name of the original image.
// highlightedImage	string		The name of the image to use when the onmouseover
//								event occurs.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function imagesToSwap(plainImage, highlightedImage) {
	
	this.plain = new Image();
	this.plain.src = plainImage;
	
	this.highlighted = new Image();
	this.highlighted.src = highlightedImage;

}

// -------------------------------------------------------------------------------
// Function         : preloadImages(imagesArray)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function preload images into memory which will be used for mouseover
// events.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// imagesArray		array		This is an array of the names of all of the images
//								which will be highlighted by mouseover events. 
//								This array contains only the original (plain)
//								 images.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function preloadImages(imagesArray)
{

	var imgIndex;
	var highlightedImage;

	if (imagesArray!=null) {
		for(imgIndex=0;imgIndex<imagesArray.length;imgIndex++) {
	
			highlightedImage = imagesArray[imgIndex];
			if(highlightedImage.lastIndexOf('.') >0){
				highlightedImage = highlightedImage.substring(0,highlightedImage.lastIndexOf('.')) + '-m' + highlightedImage.substring(highlightedImage.lastIndexOf('.'),highlightedImage.length);
				imgs[imgs.length] = new imagesToSwap(imagesArray[imgIndex],highlightedImage);
			}
			
		}
	}
}

// -------------------------------------------------------------------------------
// Function         : highlightImage(imgSource)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function changes the src of an Image whenever a mouseover event fires.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// imgSource		img			This is the image object in the HTML which will
//								have its src replaced.  imgSource should always be
//								referenced with this.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function highlightImage(imgSource)
{

	// loops through the imgs array to find the image
	for(i=0;i<imgs.length;i++) {
	if (imgSource.src.toUpperCase()==imgs[i].plain.src.toUpperCase()) {
			imgSource.src=imgs[i].highlighted.src;
			break;
		}
	}

}

// -------------------------------------------------------------------------------
// Function         : unhighlightImage(imgSource)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function changes the src of an Image back to the plain version whenever
// a mouseover event fires.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// imgSource		img			This is the image object in the HTML which will
//								have its src replaced.  imgSource should always be
//								referenced with this.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function unhighlightImage(imgSource)
{

	// loops through the imgs array to find the image
	for(i=0;i<imgs.length;i++) {
		if (imgSource.src.toUpperCase()==imgs[i].highlighted.src.toUpperCase()) {
			imgSource.src=imgs[i].plain.src;
			break;
		}
	}

}

// -------------------------------------------------------------------------------
// Function         : PopupWindow (myLocation, scroll, width, height, windowName)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function opens a new window with no menus or toolbars using the file
// specified by myLocation.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// myLocation	string		The name of the file/URL to open in the window.
// scroll		boolean		Will scrollbars appear on the window.
// width		integer		Width of the window in pixels.
// height		integer		Height of the window in pixels.
// windowName	string		Name of the window.
// -------------------------------------------------------------------------------
// Last Updated     : Tuesday, September 5, 2000
// Updated by       : Chad Peck
// -------------------------------------------------------------------------------

function PopupWindow (myLocation, scroll, width, height, windowName) {
	var oWin;
	
	//window.showModalDialog(myLocation,'','dialogHeight:'+height+'px;dialogWidth:'+width+'px;center:yes;resizeable:yes;help:no;status:no');
	if (!windowName) {
		windowName = '';
	}
	oWin = window.open(myLocation, windowName,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=' + scroll + ',resizable=yes,width=' + width + ',height=' + height);
	oWin.focus();
}

function previewPopUp(sCNURL, sTitle){
	var sTargetURL = "viewSite.aspx?URL=";
	sCNURL = escape(sCNURL);
	sCNURL = sCNURL.replace(/\+/g, '%2B');
	sTargetURL += sCNURL + '&title=' + sTitle;
	PopupWindow (sTargetURL, 'yes','1024','768');
}

function PopupWindow1 (myLocation, scroll, toolbar, width, height, windowName) {
	var oWin;
	
	//window.showModalDialog(myLocation,'','dialogHeight:'+height+'px;dialogWidth:'+width+'px;center:yes;resizeable:yes;help:no;status:no');
	if (!windowName) {
		windowName = '';
	}
	oWin = window.open(myLocation, windowName,'menubar=0,toolbar=' + toolbar + ',location=0,directories=0,status=0,scrollbars=' + scroll + ',resizable=yes,width=' + width + ',height=' + height);
	oWin.focus();
	
}

// -------------------------------------------------------------------------------
// Function         : validate(formElement, regExpText, errorMsg)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function validates the data entered into a form element using regular
// expressions and returns an user specified error if the value of the element
// doesn't match the regular expression.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// From CNForm
// args[0] = CNForm object
// args[1] = regExpText
// args[2] = sName
// args[3] = errorMsg
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// CNForm		object		CNForm object
// regExpText	string		The regular expression to validate the element with.
// sName		string		HTML form element name
// errorMsg		string		The message to display if the value of the form
//							element isn't valid.
// -------------------------------------------------------------------------------
// From Form:
// args[0] = formElement
// args[1] = regExpText
// args[2] = errorMsg
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formElement	object		Then form element which will have its value validated.
// regExpText	string		The regular expression to validate the element with.
// errorMsg		string		The message to display if the value of the form
//							element isn't valid.
// -------------------------------------------------------------------------------
// Last Updated     : November 12, 2003
// Updated by       : Ken Wimberley [provides for being called by either form or CNForm object
// -------------------------------------------------------------------------------

function validate() {
	try {
		var args = validate.arguments;		
		var bIsCNForm = (args[0].getValue)? true : false;
		if(bIsCNForm){	//called from CNForm object
			var oCNForm = args[0];
			var regExpText = args[1];
			var sName = args[2];
			var errorMsg  = args[3];
			var value = oCNForm.getValue(sName); 
			var regExpObj = new RegExp(regExpText,'');
			if (!regExpObj.test(Trim(value))) {

				// displays an error message
				alert('CHANNELNET FIELD VALIDATION ERROR\nThe current field contains an invalid value:\n' + errorMsg);
				return false;
			} else {
				return true;
			}		
		} else {	//called from Form object
			var formElement = args[0];
			var regExpText = args[1];
			var errorMsg = args[2];
			
			
			var regExpObj = new RegExp(regExpText,'');
			if (previousFieldName!=formElement.name) {
				// checks to see if the field value matches the regular expression
				if (!regExpObj.test(Trim(formElement.value))) {

					// displays an error message
					alert('CHANNELNET FIELD VALIDATION ERROR\nThe current field contains an invalid value:\n' + errorMsg);

					// sets the field value to ""
					if (formElement.type=="text" 
						|| formElement.type=="textarea" 
						|| formElement.type=="password" 
						|| formElement.type=="file" 
						|| formElement.type=="hidden") {
							formElement.value = "";
					}
					// selects the field value
					if (formElement.focus) formElement.focus();
					if (formElement.select) formElement.select();
					
				
					previousFieldName = formElement.name;
					return false;
				} else {
					return true;
				}
			}

			return true;		
		}
		
	}
	catch(e){
	}
}

// -------------------------------------------------------------------------------
// Function         : formHandler(formObj, strMessageText)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function concatenates all of the channelnet information which
// is required for the criteria string in the crt element of the form and makes
// sure that all of the required form fields exist.
// NOTE: THIS SHOULD BE CALLED AS FOLLOWS
// <form method="post" onsubmit="return submitForm(this)">
// if the return is omitted form submission won't be canceled when an
// error occurs
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formObj		form		Reference to the form which is being submitted.
//							formObj should always be this.
// strMessageText string	The text to dispaly if the form hasn't changed
// -------------------------------------------------------------------------------
// Last Updated     : March 22, 2004
// Updated by       : Ken Wimberley
// Enforced encodeURIComponent() escaping of criteria strings to allow for non-latin characters
// -------------------------------------------------------------------------------

function formHandler(formObj, strMessageText, escapeStrings, setcursor, dontValidate)
{
	if(formObj.oCNForm){
		return formObj.oCNForm.handleSubmit(formObj, strMessageText, escapeStrings, setcursor, dontValidate);	
	} else {
		var elementName;				// the name of a form element
		var elementIndex;				// index of the element in the form
		var optionIndex;				// index of the option in a select box
		var elementValue;				// value for a form element
		var formLength;
		var currentElement;
		var criteriaValue;
		
		// -------------------------------------------------------------------------------
		// The line below forces all formHandler calls to be escaped for non-Latin characters.
		// Removing this will break other components but will need to be done eventually
		// in order to support non-Latin characters.
		// -------------------------------------------------------------------------------
		//escapeStrings = true;
		
		// checks to make sure the form wasn't already submitted
		if(wasSubmitted) {
			//alert("The page has already been submitted.\nEither wait for a response or click the browser's refresh button to redisplay the page.");
			return false;
		} else {
			// checks to see if anything has changed on the form, if not submission is cancelled
			if (!hasFormChanged(formObj) && !dontValidate) {
		
				//***********************************************************************************
				// cpeck (9/28/2000) added strMessageText so the user can optionally specify the text
				// to display if the form hasn't changed
				//***********************************************************************************
				
				if (!strMessageText || strMessageText == '') {
					strMessageText =  "No changes have been made to the information on this page.  The page will not be saved!";
				}
				
				alert(strMessageText);
				return false;
			}
			
			// stops the form submission if the required elements and element values
			// aren't included in the form
			if (formObj.cn==null) {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have a context(cn)');
			} else if (formObj.cn.value=='') {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have a context value');
			} else if (formObj.act==null) {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have an action(act)');
			} else if (formObj.act.value=='') {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have an action value');
			} else if (formObj.debug==null) {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have a debug value');
			} else if (formObj.debug.value!='0' && formObj.debug.value!='1' && formObj.debug.value!='2'&& formObj.debug.value!='3') {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have a debug value of 0,1, 2, or 3');
			} else if (formObj.crt==null) {
				alert('The form does not adhere to ChannelNet grammar rules.\nMust have a criteria(crt)');
			} else {
		
				// initializes the criteria string value to null
				if(formObj.crt.defaultValue) {
					criteriaValue = formObj.crt.defaultValue;
				} else {
					criteriaValue='';
				}
				
				previousFieldName = '';

				formLength = formObj.elements.length;
				
				// loops through the elements of the form and adds them to the crt
				for(elementIndex=0; elementIndex < formLength; elementIndex++){
					if(eval('formObj.elements[' + elementIndex + ']')){
						currentElement = formObj.elements[elementIndex];

						var undefined;

						// calls the onchange event for every element on the form
						//if (currentElement.type!="hidden" && currentElement.onchange!=null && currentElement.onchange!="") {
						if (!currentElement.disabled && currentElement.type!="hidden" && currentElement.name != previousFieldName && currentElement.onchange!=null && currentElement.onchange!="" && currentElement.onchange != undefined && currentElement.type != 'select-one' && currentElement.type != 'textarea') {
							//if (!currentElement.onchange()) {
								// alert(currentElement.onchange());
							//	return false;
							//}
						}

						// doesn't add the cn, act, debug, style, and crt elements to the crt value
						// also excludes empty elements
						if (currentElement.value!="" && currentElement.name!="act" && currentElement.name!="cn" && currentElement.name!="crt" && currentElement.name!="debug" && currentElement.name!="style" && currentElement.name!="pageid" && currentElement.type) {

							elementName = currentElement.name;

							// ignores form elements that have a name that begins
							// with an underscore(_)
							if (elementName.charAt(0)!='_') {

								if (currentElement.type=="select-multiple") {

									// places an ampersand(&) between form elements
									if (criteriaValue!='' && criteriaValue!=null) {
										criteriaValue = criteriaValue + "&";
									}

									elementValue='';
									criteriaValue = criteriaValue + currentElement.name + "=";
									for (optionIndex=0;optionIndex<currentElement.length;optionIndex++) {
										if (currentElement.options[optionIndex].selected) {

											if (elementValue!='') {
												elementValue = elementValue + "|"
											}

											if (escapeStrings) {
												elementValue = elementValue + Trim(escapeValues(currentElement.options[optionIndex].value));
											} else {
												elementValue = elementValue + Trim(currentElement.options[optionIndex].value);
											}
										}
									}

									criteriaValue = criteriaValue + elementValue;
								} else if (currentElement.type=="select-one") {

									// places an ampersand(&) between form elements
									if (criteriaValue!='' && criteriaValue!=null) {
										criteriaValue = criteriaValue + "&";
									}

									if (escapeStrings) {
										criteriaValue = criteriaValue + Trim(formObj.elements[elementName].name) + "=" + Trim(escapeValues(currentElement.options[currentElement.selectedIndex].value));
									} else {
										criteriaValue = criteriaValue + Trim(formObj.elements[elementName].name) + "=" + Trim(currentElement.options[currentElement.selectedIndex].value);
									}

								} else if (currentElement.type=="radio") {

									if (currentElement.checked) {

										// places an ampersand(&) between form elements
										if (criteriaValue!='' && criteriaValue!=null) {
											criteriaValue = criteriaValue + "&";
										}

										if (escapeStrings) {
											criteriaValue = criteriaValue + currentElement.name + "=" + escapeValues(currentElement.value);
										} else {
											criteriaValue = criteriaValue + currentElement.name + "=" + currentElement.value;
										}

									}
								} else if (currentElement.type=="checkbox") {

									if (currentElement.checked) {

										// places an ampersand(&) between form elements
										if (criteriaValue!='' && criteriaValue!=null) {
											criteriaValue = criteriaValue + "&";
										}

										if (escapeStrings) {
											criteriaValue = criteriaValue + currentElement.name + "=" + escapeValues(currentElement.value);
										} else {
											criteriaValue = criteriaValue + currentElement.name + "=" + currentElement.value;
										}

									}
								} else {

									// places an ampersand(&) between form elements
									if (criteriaValue!='' && criteriaValue!=null) {
										criteriaValue = criteriaValue + "&";
									}

									if (escapeStrings) {
										criteriaValue = criteriaValue + currentElement.name + "=" + escapeValues(currentElement.value);
									} else {
										criteriaValue = criteriaValue + currentElement.name + "=" + currentElement.value;
									}
								}
								//alert(elementName);
							}
						}
					}
				}
				
				formObj.crt.value = criteriaValue;
				//alert(formObj.crt.value);
				// submits the form
				if(!setcursor){
					if(parent && parent.frames && parent.frames.length) {
						var frameLength = parent.frames.length;
						for(i=0; i < frameLength; i++) {
							parent.frames[i].document.body.style.cursor = 'wait';
						}
					}
				}
				document.body.style.cursor = 'wait';
				wasSubmitted = true;
				return true;
			}
		}	
	}
	// stops form submission
	return false;
}

// -------------------------------------------------------------------------------
// Function         : validateElement(formElement)
// -------------------------------------------------------------------------------
// Author           : George Pollard
// Created on       : Monday, October 9, 2000
// 
// This function validates the given form element returning false only if the 
// element has a well-defined onChange handler which fails.
// -------------------------------------------------------------------------------
// Last Updated     : Monday, October 9, 2000
// Updated by       : 
// -------------------------------------------------------------------------------
function validateElement(formElement) {
	setPreviousFileNameToNothing();	// we don't want to skip over validation simply because last time element was tested it was invalid
	if (!formElement.disabled && formElement.type!="hidden" && previousFieldName!=formElement.name && formElement.onchange!=null && formElement.onchange!="") {
	//if (!formElement.disabled && formElement.type!="hidden" && formElement.onchange!=null && formElement.onchange!="") {
		return formElement.onchange();
		//return !isFieldError;
	} else
		return true;
}


// -------------------------------------------------------------------------------
// Function         : concatFields(formElement)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function takes the values of textboxes which have identical names
// and concatenates the values which are separated by a bar(|)
// the the resulting values is stored in a hidden field.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formElement	element		The form element which calls this function.  It should
//							always be this.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function concatFields(formElement) {

	var elementIndex;
	var concatValue = '';
	var elementName = formElement.name;
	
	// loops through all of the elements that have the same name as the
	// one that called this function
	
	for(elementIndex=0;elementIndex<formElement.form.elements[elementName].length;elementIndex++) {
		
		if (formElement.form.elements[elementName][elementIndex].value!=null && formElement.form.elements[elementName][elementIndex].value!="") {
			// concatenates the values
			concatValue = concatValue + formElement.form.elements[elementName][elementIndex].value + '|';
		}
	}
	
	// removes the last bar(|)
	concatValue = concatValue.substring(0,concatValue.length-1);
	
	// takes the underscore off of the name
	elementName = elementName.substring(1,elementName.length);
	
	// stores the value a hidden field of the same name
	formElement.form.elements[elementName].value = concatValue;

}

// -------------------------------------------------------------------------------
// Function         : confirmPassword(formObj)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function checks to make sure that two the values of a password field and
// a confirm password field match.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formObj		form		Reference to a form object.  It should always be
//							by the this keyword.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function confirmPassword(formObj) {

	if (formObj.Password.value!=formObj.elements["_ConfirmPassword"].value) {
	
		formObj.Password.value="";
		formObj.elements["_ConfirmPassword"].value="";
		alert("Please reenter your password!\nThe two values do not match");
		return false;

	} else {

		return true;

	}

}

// -------------------------------------------------------------------------------
// Function         : focusOnFirstField()
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function gives focus to the first form element which can receive focus on
// a page.  If the field can be selected then it is.
// -------------------------------------------------------------------------------
// Last Updated     : Wednesday, October 11, 2000
// Updated by       : Chad Peck
// -------------------------------------------------------------------------------

function focusOnFirstField() {

	var formIndex;
	var elementIndex;

	for(formIndex=0; formIndex < document.forms.length; formIndex++) {

		for(elementIndex=0; elementIndex < document.forms[formIndex].elements.length; elementIndex++) {

			// finds the first element which accepts focus
			if (document.forms[formIndex].elements[elementIndex].type=="text" || document.forms[formIndex].elements[elementIndex].type=="textarea" || document.forms[formIndex].elements[elementIndex].type=="password" || document.forms[formIndex].elements[elementIndex].type=="file") {
				
				currentNode = document.forms[formIndex].elements[elementIndex].parentNode;
				hidden = false;
				while(currentNode) {
					if(currentNode.style && ((currentNode.style.visibility && currentNode.style.visibility == 'hidden') || (currentNode.style.display && currentNode.style.display == 'none'))) {
						hidden = true;
					}
					currentNode = currentNode.parentNode;
				}
				
				if(!hidden) {
					var oElement = document.forms[formIndex].elements[elementIndex];
					if(!(oElement.style && ((oElement.style.visibility && oElement.style.visibility == 'hidden') || (oElement.style.display && oElement.style.display == 'none'))) ){
						oElement.focus();
						oElement.select();

						return;
					}
				}
			} else if (document.forms[formIndex].elements[elementIndex].type == "select-one" && (!document.forms[formIndex].elements[elementIndex].size || document.forms[formIndex].elements[elementIndex].size == 1)) {
				
				if (document.forms[formIndex].elements[elementIndex].disabled == false) {
					currentNode = document.forms[formIndex].elements[elementIndex].parentNode;
					hidden = false;
					while(currentNode) {
						if(currentNode.style && ((currentNode.style.visibility && currentNode.style.visibility == 'hidden') || (currentNode.style.display && currentNode.style.display == 'none'))) {
							hidden = true;
						}
						currentNode = currentNode.parentNode;
					}
					if(!hidden) {
						var oElement = document.forms[formIndex].elements[elementIndex];
						if(!(oElement.style && ((oElement.style.visibility && oElement.style.visibility == 'hidden') || (oElement.style.display && oElement.style.display == 'none')))) {
							oElement.focus();
							return;
						}
					}
				}
			}

		}	

	}

}

// -------------------------------------------------------------------------------
// Function         : concatFieldsAsXML(formObj, pageName)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function is called to concatenate fields in a form into an XML string.
// The root node is the name of the page, passed as the parameter pageName.  Then
// it concatenates any fields which begin with an underscore(_) into the XML
// string and stores the string in the content element of the string.
// This function will primarily be used within SiteBuilder
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME         TYPE        DESCRIPTION
// formObj		form		Reference to the form to concat fields.  The value
//							should always be this
// pageName		string		The name of the page that will be inserted as the 
//							root XML node.
// -------------------------------------------------------------------------------
// Last Updated     : Monday, June 12, 2000
// Updated by       : Chad Peck
// -------------------------------------------------------------------------------

function concatFieldsAsXML(formObj, pageName) {

	if (formObj.content!=null) {
	
		if (pageName!=null && pageName!='') {
			// creates the XML element for the name of the page
			formObj.content.value = '<' + pageName + '>';
		} else {
			formObj.content.value = '';
		}


		// loops through all of the form elements
		for (elementIndex=0; elementIndex < formObj.elements.length; elementIndex++) {
	
			elementName = formObj.elements[elementIndex].name;
			
			// adds the form elements whose names begin with an underscore(_) to the XML
			
			if (elementName.charAt(0)=='_') {
			
				elementName = elementName.substring(1,elementName.length);
				elementValue = formObj.elements[elementIndex].value;
				elementValue = XMLEncode(elementValue);
				elementValue = elementValue.replace(/\r\n/g,"<br/>");
				elementValue = escape(elementValue);
				formObj.content.value += '<' + elementName + '>' + elementValue + '</' + elementName + '>'	
			}
		}

		if (pageName!=null && pageName!='') {
			formObj.content.value += '</' + pageName + '>';
		}
		
	} else {
		alert("This form doesn't contain a content field!");
	}
}

// -------------------------------------------------------------------------------
// Function         : canProceed(formObj)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Monday, March 27, 2000
// 
// This function is called from the onclick event handler of a link to determine
// if changes have been made to the form specified by formObj and to see if the
// user wants to proceed the link.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formObj		form		Reference to a form object. This is the form which
//							should be reset.  If the form is contained in a layer
//							then it	must be called referenced from within the 
//							layer.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function canProceed(formObj) {

	// checks to see if the form has changed
	if (hasFormChanged(formObj)) {
	
		// prompts the user to proceed
			
		if (confirm("You have made changes to this page without saving.\nDo you want continue without saving?")) {
			return true;
		} else {
			return false;
		}
	
	} else {
		return true;
	}
}

// -------------------------------------------------------------------------------
// Function         : hasFormChanged(formObj)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function checks all of the elements in a form to determine if they have
// changed from the default values which were set in the HTML.  It returns a
// boolean value.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formObj		form		Reference to a form object.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function hasFormChanged(formObj) {
	var elementIndex;
	var optionIndex;	

	if (formObj) {
		if (formObj._dontValidate != null)
			return true;
		// checks all of the form elements to see if the values have changed
		for(elementIndex=0; elementIndex < formObj.elements.length; elementIndex++) {
			if (formObj.elements[elementIndex].name=="_ignoreAllChanges_")
				continue;
			if ((formObj.elements[elementIndex].name=="_noinput") && (formObj.elements[elementIndex].value=="1")) {
				return true;
			} else if (formObj.elements[elementIndex].type=="text" || formObj.elements[elementIndex].type=="textarea" || formObj.elements[elementIndex].type=="password" || formObj.elements[elementIndex].type=="file" || formObj.elements[elementIndex].type=="hidden") {
				if (formObj.elements[elementIndex].value!=formObj.elements[elementIndex].defaultValue) {
					//alert("1: " + formObj.elements[elementIndex].name);
					return true;
				}
			} else if (formObj.elements[elementIndex].type=="checkbox" || formObj.elements[elementIndex].type=="radio") {
				if (formObj.elements[elementIndex].checked!=formObj.elements[elementIndex].defaultChecked) {
					//alert("2: " + formObj.elements[elementIndex].name);
					return true;
				}
			} else if (formObj.elements[elementIndex].type=="select-one" || formObj.elements[elementIndex].type=="select-multiple") {				
				var iDefautIndex = -1;
				for(var i=0; i<formObj.elements[elementIndex].options.length; i++){
					if(formObj.elements[elementIndex].options[i].defaultSelected){						
						iDefautIndex = i;
						break;				
					}
				}					
				//alert("iDefautIndex:" + formObj.elements[elementIndex].name + " = " + iDefautIndex);
				//alert("selectedIndex:" + formObj.elements[elementIndex].name + " = " +  formObj.elements[elementIndex].selectedIndex);
				if( formObj.elements[elementIndex].selectedIndex != iDefautIndex && formObj.elements[elementIndex].selectedIndex != -1
					&& formObj.elements[elementIndex].options[formObj.elements[elementIndex].selectedIndex] != ""){
					return true;
				}
			}	
		}
	}

	return false;
}

// -------------------------------------------------------------------------------
// Function         : moveOptionUp(selectBox)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Monday, March 27, 2000
// 
// This function moves an option down in the list of options for a select box.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// selectBox	select		Reference to the select box to use.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function moveOptionUp(selectBox) {

	var optionText;
	var optionValue;
	
	// moves the row up if it isn't already the first row
	if (selectBox.selectedIndex>0) {
	
		var currentOption = selectBox.options[selectBox.selectedIndex];
		var previousOption = selectBox.options[selectBox.selectedIndex - 1];
		
		// stores the text and value of the selected option
		optionText = currentOption.text;
		optionValue = currentOption.value;
		
		currentOption.text = previousOption.text;
		currentOption.value = previousOption.value;

		previousOption.text = optionText;
		previousOption.value = optionValue;
	
		currentOption.selected=false;
		previousOption.selected=true;
	}
	

}

// -------------------------------------------------------------------------------
// Function         : moveOptionDown(selectBox)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Monday, March 27, 2000
// 
// This function moves an option down in the options list for a select box.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// selectBox	select		Reference to the select box to use.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function moveOptionDown(selectBox) {

	var optionText;
	var optionValue;	
	
	// moves the row down if it isn't already the last row
	if (selectBox.selectedIndex != -1 && selectBox.selectedIndex < (selectBox.options.length-1)) {
	
		var currentOption = selectBox.options[selectBox.selectedIndex];
		var nextOption = selectBox.options[selectBox.selectedIndex + 1];
		
		// stores the text and value of the selected option
		optionText = currentOption.text;
		optionValue = currentOption.value;
		
		currentOption.text = nextOption.text;
		currentOption.value = nextOption.value;

		nextOption.text = optionText;
		nextOption.value = optionValue;
	
		currentOption.selected=false;
		nextOption.selected=true;
	}
}

// -------------------------------------------------------------------------------
// Function         : changePreviewImage()
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Wednesday, March 29, 2000
// 
// This function changes the preview image for the Sitebuilder page to selct a 
// theme according to what is selected from a select box.
// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function changePreviewImage() {

	var imgIndex;
	
	for (imgIndex = 0; imgIndex < themesArray.length; imgIndex++) {
		if (themesArray[imgIndex][0] == document.ChannelNet.ThemeKey.options[document.ChannelNet.ThemeKey.selectedIndex].value) {
			document.images["imgTheme"].src = themesArray[imgIndex][1];
		}
	}

}

// -------------------------------------------------------------------------------
// Function         : canDelete()
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, April 7, 2000
// 
// This function prompts the user to make sure that they want to delete the
// selected item.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function canDelete() {

	// prompts the user to confirm deletion
	if (confirm("Are you sure that you want to delete the selected item?")) {
		return true;
	} else {
		return false;
	}
}

// -------------------------------------------------------------------------------
// Function         : rowIsSelected()
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, April 7, 2000
// 
// This function checks to see if the form element that contaings the value of a
// row that has been selected has a value.  If it does it returns true otherwise
// it alerts the user and returns false.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function rowIsSelected(formElement) {

	if (formElement.value!='') {
		return true;
	} else {
		alert("You must select a list item!");
		return false;
	}
}

// -------------------------------------------------------------------------------
// Function         : urlencode_internal(sIn)
// -------------------------------------------------------------------------------
// Author           : 
// Created on       : Copied from urlencode in channelnet.js of ChannelNet Version 1.1
// 
// This function encodes a string to send in a URL using the supplied translation
// table.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME							TYPE        DESCRIPTION
// szIn							String			The plaintext for encoding
// sURLEncodedChars	String			The target character encodings
// -------------------------------------------------------------------------------
// Last Updated     : Dan Boresjo
// Updated by       : 
// -------------------------------------------------------------------------------

function urlencode_internal(sIn, sURLEncodedChars){
   var LenStr = sIn.length;
   var sOut = "";
   var sReplace = "";
   var sURLChars = " ,~,!,#,$,%,^,&,(,),+,=,[,{,],},\,|,`,',:,;,/,<,>";
   var aURLChars = sURLChars.split(",");
   var aURLEncodedChars = sURLEncodedChars.split(",");

   for (Count=0; Count<=LenStr; Count++) {
      StrChar = sIn.substring(Count, Count+1);
      for (j=0; j<=25; j++) {
         if (StrChar==aURLChars[j]) {
           sReplace = aURLEncodedChars[j];
         } 
      }
      if (sReplace != "") {
        sOut = sOut + sReplace;
        sReplace="";
      } else {
        sOut = sOut + StrChar;
      }
		 }
  return(sOut.substring(0, sOut.length-3));
}

// -------------------------------------------------------------------------------
// Function         : urlencode(sIn)
// -------------------------------------------------------------------------------
// Author           : Dan Boresjo
// Created on       : 10 Oct 2000
// 
// This function encodes a string to send in a URL.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME							TYPE        DESCRIPTION
// szIn							String			The plaintext for encoding
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function urlencode(sIn){
   var sURLEncodedChars = "+,%7E,%21,%23,%24,%25,%5E,%26,%28,%29,%2B,%3D,%5B,%7B,%5D,%7D,%5C,%7C,%60,%27,%3A,%3B,%2F,%3C,%3E";
   return urlencode_internal(sIn, sURLEncodedChars);
}

// -------------------------------------------------------------------------------
// Function         : urlencode_field(sIn)
// -------------------------------------------------------------------------------
// Author           : Dan Boresjo
// Created on       : 10 Oct 2000
// 
// This function encodes a string to send in a URL, including double-encoding of
// ampersands so that they pass through the responseloop correctly.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME							TYPE        DESCRIPTION
// szIn							String			The plaintext for encoding
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function urlencode_field(sIn){
   /*var sURLEncodedChars = "+,%7E,%21,%23,%24,%25,%5E,%25%32%36,%28,%29,%2B,%3D,%5B,%7B,%5D,%7D,%5C,%7C,%60,%27,%3A,%3B,%2F,%3C,%3E";
   return urlencode_internal(sIn, sURLEncodedChars);*/
   return escape(sIn);
}

// -------------------------------------------------------------------------------
// Function         : getFieldFromURL(fieldName)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Tuesday, May 2, 2000
// 
// This function returns the value of the field specified by fieldName in the
// querystring of the current URL.  If the field doesn't exist then it returns an
// empty string.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// fieldName	string      The name of the field to find in the querystring of
//                          the URL.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function getFieldFromURL(fieldName) {

	var startIndex;
	var endIndex;
	var returnValue = "";
	
	if(location.search.indexOf(fieldName + "=")!=-1) {
		startIndex = location.search.indexOf(fieldName + "=") + fieldName.length + 1;
		
		if(location.search.indexOf("&",startIndex)==-1) {
			endIndex = location.search.length;
		} else {
			endIndex = location.search.indexOf("&", startIndex);
		}
		
		returnValue = location.search.substring(startIndex, endIndex);
	}
	
	return returnValue;
}

function itemIsSelected(listBox) {
	
	if(listBox.selectedIndex!=-1) {
		return true;
	} else {
		alert("You must select an item from the list");
		return false;
	}
}

function submitAndClose(form) {	
	if (form.onsubmit()) {
		if(window.opener) {
			// name windows carefully so as not to finish up with duplicate
			// window names even if the windows that go through this code are
			// in a grandparent, parent,child sequence, as can happen.
			window.opener.name = "targetWindow";
			form.target = "targetWindow";
		}
		form.submit();
		if(window.opener) 
			window.opener.name = "mainWindow"; // call it something different now
		window.close();
	}
}

// -------------------------------------------------------------------------------
// Function         : clearImage(imgName, inputObject)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Wednesday, September 27, 2000
// 
// This function clears the value stored for the path of an image and changes the
// the image shown to the "No image available" image.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// imgName      string      The name of the image to clear.
// inputObject  input field The hidden form object which will be cleared.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function clearImage(imgName, inputObject) {
	
	if (document.images[imgName]) {
		document.images[imgName].src = '/themes/default/en-us/common/admin/images/noimage_sml.gif';
	}
	
	if (inputObject) {
		inputObject.value = '';
	}
	
	return false;
	
}

// -------------------------------------------------------------------------------
// Function         : getHelpWindow(pageName)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, October 6, 2000
// 
// This function opens the help window and sets the page if one is specified.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// pageName             string      The name of the page to display.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function getHelpWindow(pageName) {

	var oWin;
	var hash = "";
	
	if (pageName && pageName != '') {
		hash = "#" + pageName;
	}
	
	oWin = window.open('/admin/help/channelnethelp.htm' + hash, 'help','menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=yes,resizable=yes,width=620,height=465');

	oWin.focus();
	
	return false;
}

// -------------------------------------------------------------------------------
// Function         : canPublish()
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Thursday, October 12, 2000
// 
// This function checks to see if publishing can occur.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// pageName             string      The name of the page to display.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function canPublish() {

	alert("You currently must do all publishing from the Foundation tab");
	return false;
}


/**
 * returns null if the specified day, month and year represent a valid date
 * otherwise returns a string detailing the problem
 */
function isValidDate(day, month, year) {
	if ((month<1)||(month>12))
		return month+" is not a valid month.";
	
	// A leap year occurs every four years except for those multiples of 100 which are not also multiples of 400.
	// eg 1600, 2000 and 2400 are leap years but 1700, 1800, 1900 and 2100 etc are not
	var isLeap = ( ((year%4)==0) && ((year%100)!=0) ) || ((year%400)==0);
	if (month==1) len=31; // jan
	if ((month==2)&&!isLeap) len=28; // feb (non-leap year)
	if ((month==2)&&isLeap) len=29;  // feb (leap year)
	if (month==3) len=31; // mar
	if (month==4) len=30; // apr
	if (month==5) len=31; // may
	if (month==6) len=30; // jun
	if (month==7) len=31; // jul
	if (month==8) len=31; // aug
	if (month==9) len=30; // sep
	if (month==10) len=31; // oct
	if (month==11) len=30; // nov
	if (month==12) len=31; // dec
	
	if ((day<1)||(day>len)) {
		if ((day==29)&&(month==2))
			return year + " is not a leap year.";
		if ((day>0)&&(day<32))
			return day + " is not a valid day for month " + month + ".";
		return day + " is not a valid day of the month.";
	}
	
	return null;
}

/**
 * returns true if the string in the specified control is a valid date and displays appropriate error messages as a side effect
 * todo: add support for non-US date formats
 */
function validateDate(ctrl, ctrlname) {
	var regExpObj = new RegExp("^(\\d{1,2})/(\\d{1,2})/((\\d{2})|(\\d{4}))$")
	if (!regExpObj.test(ctrl.value)) {
		alert("'" + ctrl.value + "' is not a valid "+ctrlname+" date.\nThe date must be entered in mm/dd/yy format");
		return false;
	}
						
	regExpObj.exec(ctrl.value);
	var month = RegExp.$1;
	var day = RegExp.$2;
	var year = RegExp.$3;
	var err = isValidDate(day,month,year);
	if (err!=null) {
		alert(month + "/" + day + "/" + year + " is not a valid "+ctrlname+" date.\n"+err);
		return false;
	}
	return true;
}

/**
 * returns the millisecond tick equivalent for the date in the specified control
 */					
function getDateTicks(ctrl) {
	var regExpObj = new RegExp("^(\\d{1,2})/(\\d{1,2})/((\\d{2})|(\\d{4}))$")
	if (!regExpObj.test(ctrl.value)) 
		return 0;
	regExpObj.exec(ctrl.value);
	var month = RegExp.$1;
	var day = RegExp.$2;
	var year = RegExp.$3;
	var err = isValidDate(day,month,year);
	if (err!=null)
		return 0;
	if (day.length==1) day = "0"+day;
	if (month.length==1) month = "0"+month;
	if (year.length==2) year = "20"+year;
	//alert(day +" "+ month +" "+ year);
	return Date.UTC(year, month-1, day);
}

/**
 * Useful in XSL-based scripts that don't like < symbols
 */
function lessthan(a,b) {
	return (a<b);
}

function XMLEncode(sIn) {

	sIn = sIn.replace(/&/g, "&amp;");
	sIn = sIn.replace(/</g, "&lt;");
	sIn = sIn.replace(/>/g, "&gt;");
	sIn = sIn.replace(/"/g, "&quot;");
	sIn = sIn.replace(/'/g, "&apos;");
	

	return sIn;

}

function escapeValues(stringToEscape) {

	/*	
	 * This exposes a bad methodolgy.
	 * CMC style sheets often mix name value pairs within one field.
	 * This exposes a vulnerabilty when supporting non-Latin characters.		
	 */
	
	var regExp = /^[^&\?]*&\w+=(.+)/g	
	
	if(stringToEscape.search(regExp)==-1) {
		// escapes the string if it doesn't contain any name/value pairs
		return encodeURIComponent(Trim(stringToEscape));
	} else {
		return stringToEscape;
	}	
}

function setPreviousFileNameToNothing() {
	previousFieldName='';
}

function validateFormDivAndSwitch(formObj, oldDiv, newDiv) {
	var elementIndex;
	previousFieldName = '';
	var undefined;
	for(elementIndex=0;elementIndex<formObj.elements.length;elementIndex++){
		var field = formObj.elements[elementIndex];
		if (oldDiv.contains(field)) {
			if (!field.disabled && field.type != "hidden") {
				if (field.onchange != null && field.onchange != "" && field.onchange != undefined) {
					if (!field.onchange()) {
						return false;
					}
				}
			}
		}
	}
	oldDiv.style.display = 'none';
	newDiv.style.display = '';
	return true;
}

// -------------------------------------------------------------------------------
// Function         : LTrim(str)
// -------------------------------------------------------------------------------
// This function removes spaces from the beginning of a string.
// -------------------------------------------------------------------------------
// Returns the trimmed string
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// str              string      The string to remove spaces from.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function LTrim(str) {

	if(str) {
		str = str.replace(/^\s+/,"");
	} else {
		str = '';
	}
	
	return str;
}

// -------------------------------------------------------------------------------
// Function         : RTrim(str)
// -------------------------------------------------------------------------------
// This function removes spaces from the end of a string.
// -------------------------------------------------------------------------------
// Returns the trimmed string
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// str              string      The string to remove spaces from.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function RTrim(str) {

	if(str) {
		str = str.replace(/\s+$/,"");
	} else {
		str = '';
	}
	
	return str;
}

// -------------------------------------------------------------------------------
// Function         : Trim(str)
// -------------------------------------------------------------------------------
// This function removes spaces from the beginning and end of a string.
// -------------------------------------------------------------------------------
// Returns the trimmed string
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// str              string      The string to remove spaces from.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function Trim(str) {
	return RTrim(LTrim(str));
}

function MM_findObj(n, d) { //v3.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);
  return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) {
    if ((obj=MM_findObj(args[i]))!=null) {
      v=args[i+2];
      if (obj.style) {
        obj=obj.style;
        v=(v=='show')?'visible':(v='hide')?'hidden':v;
      }
      obj.visibility=v;
    }
  }
}

function showPane(formObj){

  var optionsLength = formObj.options.length;
  
  for(i=0; i < optionsLength; i++) {
    var currentOption = formObj.options[i];
    if(i == formObj.selectedIndex) {
      MM_showHideLayers(currentOption.value,'','show');
    } else {
      MM_showHideLayers(currentOption.value,'','hidden');
    }
  }
}


// -------------------------------------------------------------------------------
// Function         : checkCookiesOn(checkFlags)
// -------------------------------------------------------------------------------
// This function checks, on the client, whether cookies are enabled in the browser. 
// The function will check for Per-session cookies and/or for Stored cookies.
// A bit mask is returned indicating which types of cookies are enabled.  The  
// return value will be 0 if no cookie types are enabled; 1 if Per-session cookies 
// are enabled; 2 if Store cookies are enabled; 3 if both types are enabled.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// checkFlags	number		A bit mask indicating which type of cookie(s) to check;
//							1 indicates check Per-session cookies; 2 indicates 
//							check Stored cookies; 3 or 0 indicates check both 
//							cookie types.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME             DESCRIPTION
// 06/19/2000   Barry Cline		 Created
//
var PERSESSION_COOKIE_FLAG = 1;
var STORED_COOKIE_FLAG = 2;
function checkCookiesOn(checkFlags)
{
	var index;
	var enabledFlags = 0;
		
	if (checkFlags == 0)
		//If we're not asked to check anything, then, obviously, we'll check everything.
		checkFlags = PERSESSION_COOKIE_FLAG + STORED_COOKIE_FLAG;
			
	if ((checkFlags & PERSESSION_COOKIE_FLAG) != 0)
	{	
		//Check whether Per-session cookie already exists
		index = document.cookie.indexOf(perSessionCookieName + "=");
		if (index == -1)
		{
			//Issue per-session check cookie
			var perSessionCookieName = "CNPerSessionCookieCheck";
			document.cookie = perSessionCookieName + "=True";
			//Try to retrieve per-session check cookie
			index = document.cookie.indexOf(perSessionCookieName + "=");
		}
		if (index != -1)
			enabledFlags += PERSESSION_COOKIE_FLAG;
	}	
	if ((checkFlags & STORED_COOKIE_FLAG) != 0)
	{
		//Check whether SITESERVER stored cookie already extant & available
		index = document.cookie.indexOf("SITESERVER=");
		if (index == -1)
		{
			//Issue stored check cookie
			var storedCookieName = "CNStoredCookieCheck";
			var today = new Date();
			var expiration = new Date(today.getTime() + 1 * 24 * 60 * 60 * 1000);
			document.cookie = storedCookieName + 
								"=True ; path=/; expires=" + expiration.toGMTString();
			//Try to retrieve stored check cookie
			index = document.cookie.indexOf(storedCookieName + "=");
			if (index != -1)
			{
				enabledFlags += STORED_COOKIE_FLAG;
				//Delete stored check cookie
				document.cookie = storedCookieName + 
									"=; path=/; expires=Tue, 01-Jan-80 00:00:01 GMT";
			}
		}
		else
		{
			enabledFlags += STORED_COOKIE_FLAG;
		}
	}
	return enabledFlags;
}


function checkAllCookies()
{	
	var checkFlags = PERSESSION_COOKIE_FLAG + STORED_COOKIE_FLAG;
	if ((checkCookiesOn(checkFlags) & checkFlags) == checkFlags)
		return 1;
	else
		return 0;
}

function checkStoredCookie()
{	
	var checkFlags = STORED_COOKIE_FLAG;
	if ((checkCookiesOn(checkFlags) & checkFlags) == checkFlags)
		return 1;
	else
		return 0;
}

function checkPerSessionCookie()
{	
	var checkFlags = PERSESSION_COOKIE_FLAG;
	if ((checkCookiesOn(checkFlags) & checkFlags) == checkFlags)
		return 1;
	else
		return 0;
}

// -------------------------------------------------------------------------------
// Function         : Date_Validation(dt)
// -------------------------------------------------------------------------------
// This function checks whether the passin string is the valid date format
// (mm-dd-yyyy)
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// dt			String	    A string indicating a date
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME             DESCRIPTION
// 05/30/2003   	Xiaoyun Wang	 Created
//

function Date_Validation(dt){
	if(dt.value.length > 0 ){
		if (isDate(dt.value)==false){
			dt.focus();
			dt.select();
			return false;
		}
	}
}

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
   for (var i = 1; i <= n; i++) {
	this[i] = 31
	if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
	if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf("-");
	var pos2=dtStr.indexOf("-",pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	var m;
	var d;
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm-dd-yyyy");
		return false;
	}
	if (month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (year < 1990 || year > 2100){
	    alert("Please enter a valid year between 1990 to 2100.");
	    return false;
	}	
	if (strYr.length < 4){
	    alert("Please enter a valid year in yyyy format");
	    return false;
	}
	if (dtStr.indexOf("-",pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, "-"))==false){
		alert("Please enter a valid date");
		return false;
	}
	//alert(year + "" + m + "" + d);
	if(month < 10)
	   m = "0" + month;
	else
	   m = "" + month;
	 
	if(day < 10)
	   d = "0" + day;
	else
	   d = day;
	   	
	return true;
}
// -------------------------------------------------------------------------------
// End of Date_Validation Function        
// -------------------------------------------------------------------------------

//************************************************** 
// This code will be executed at the top of all 
// ChannelNet XSL template-derived Web pages
if (checkStoredCookie() == 0)
	document.location.href="/_mem_bin/nocookie.asp";

/******************************************************
	canProceed?
******************************************************/	

function canProceed2(){
	var bCanProceed2 = false;
	if(!OKtoNavigate()) {		
		bCanProceed2 = false;
	} else {
		bCanProceed2 = true;
	}
	return bCanProceed2;
}

function OKtoNavigate(){
	var bOKtoNavigate = false;
	if(top.frames.frmPage){
		bOKtoNavigate =  top.isChanged(top.frames.treePage);
		if(null == bOKtoNavigate) bOKtoNavigate = true;
	}
	return bOKtoNavigate;
}

function disablePageButtons(){
	var oDiv = document.createElement("DIV");
	oDiv.id = "divShield";
	oDiv.style.zIndex = 10000;
	oDiv.style.position = "absolute";
	oDiv.style.height = "100%";
	oDiv.style.width = "100%";
	oDiv.style.left = "0px";
	oDiv.style.top = "0px";
	oDiv.style.cursor = "wait";
	oDiv.style.backgroundColor = "Red";	
	oDiv.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
	document.body.appendChild(oDiv);
}

/******************************************************
	Timer code below to let the user know that something's happening
******************************************************/	

function initMeter() {
  if (!meter.running) {
    meter.loopCount = 0
    meter.run();
    document.body.style.cursor='wait';
  }
}

var timerList = new Array();
 
function Timeline() {
  this.list = new Array
  this.max = 0
  this.index = timerList.length
  this.counter = 0
  this.loopCount = 0
  timerList[this.index] = this
  this.add = Timeline_Add;
  this.run = Timeline_Run;
  this.running = false
  if (arguments[0]==null)
    this.loop = 1
  else
    this.loop = arguments[0]

}

function Timeline_Add(ms, fn) {
  if (this.list[ms]==null)
    this.list[ms] = new Array
  var idx = this.list[ms].length
  this.list[ms][idx] = new Object
  var item = this.list[ms][idx]
  item.fn = fn
  if (ms>this.max)
    this.max = ms 
  var args = new Array
  for (var i=2; i < arguments.length; i++)
    args[i-2] = arguments[i]
  item.args = args
}


function Timeline_Run() {
  this.running = true
  for (var item in this.list[this.counter])  
      this.list[this.counter][item].fn(this.list[this.counter][item].args)

  if (this.counter>=this.max)   {
    if (this.loop>0)
      this.loopCount++
    this.counter = 0
  }
  var next = 100
  this.counter+=100
  while ((this.counter<this.max) && (this.list[this.counter]==null)) {
    this.counter+=100
    next += 100
  }
  if ((this.counter<=this.max)  && ((this.loop==0) || ((this.loopCount<this.loop) && (this.loop>0)))  )
    this.timerID = setTimeout("timerList["+this.index+"].run()",next)
  else 
    this.running=false
}  

var meter = new Timeline(0);

function showMeter(args) {
  args[0].filters[0].apply()
  args[0].style.visibility = "visible"
  args[0].filters[0].play()
}
 
function hideMeter(args) {
  args[0].filters[0].apply()
  args[0].style.visibility = "hidden"
  args[0].filters[0].play()
}  
