function replaceNonISOChars(strContent) {
	
	// list of ANSI characters not in ISO-8859-1 standard from:
	// http://www.alanwood.net/demos/charsetdiffs.html
	// replacements below based on best equivalents using standard alphanumeric characters
	
	strContent = strContent.replace(/(?:\u2018|\u2019|\u201A|\u2039|\u203A)/gi, "'"); // left and right "smart" single quotes, "low" quotes, and other quote-like characters
	strContent = strContent.replace(/(?:\u201C|\u201D|\u201E)/gi, "\"");			  // left and right "smart" double quotes and "low" quotes
	strContent = strContent.replace(/(?:\u2013|\u2014|\u2022)/gi, "-");				  // em and en dashes, and bullet symbol
	strContent = strContent.replace(/(?:\u2026)/gi, "...");							  // ellipsis
	strContent = strContent.replace(/(?:\u20AC)/gi, "[euro]");						  // Euro symbol
	strContent = strContent.replace(/(?:\u2122)/gi, "[TM]");						  // trademark symbol
	strContent = strContent.replace(/(?:\u0192)/gi, "f");							  // Latin small letter f with hook
	strContent = strContent.replace(/(?:\u2020|\u2021)/gi, "+");					  // dagger and double dagger
	strContent = strContent.replace(/(?:\u2030)/gi, "0/00");						  // per mille sign
	strContent = strContent.replace(/(?:\u0153)/gi, "oe");							  // Latin small ligature oe
	strContent = strContent.replace(/(?:\u0152)/gi, "OE");							  // Latin capital ligature OE
	strContent = strContent.replace(/(?:\u0161)/gi, "s");							  // Latin small s with caron
	strContent = strContent.replace(/(?:\u0160)/gi, "S");							  // Latin capital S with caron
	strContent = strContent.replace(/(?:\u0178)/gi, "Y");							  // Latin capital Y with diaresis
	strContent = strContent.replace(/(?:\u017E)/gi, "z");							  // Latin small z with caron
	strContent = strContent.replace(/(?:\u017D)/gi, "Z");							  // Latin capital Z with caron
	strContent = strContent.replace(/(?:\u02DC|\u02C6)/gi, "");						  // tilde and circumflex modifier
		
	return strContent;
}
function LTrim(s) {
	return s.replace(/^\s*/, "");
}
function RTrim(s) {
	return 	s.replace(/\s*$/, "");
}
function Trim(s) {
	return RTrim(LTrim(s));
}
function IsEmail(s) {
	var reEmail = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/;
	return s.match(reEmail) ? true : false;
}


//------------------------------------------------------------------------------

function FindPosition(objOptions, strItem) {
	//using a binary search, return the position (test) of the string 
	//newstring within the first size elements of the array names 
	//if newstring is not found, return -1 

	var intSize = objOptions.length;

	/* initializations */	
	var intLow = 0;
	var intHigh = intSize - 1;
	var intFound = -1;
	var intTest;
	
	if (objOptions[0].text > strItem)
		return 0;
		
	if (objOptions[intHigh].text < strItem)
		return objOptions.length;

	while ((intFound == -1) && (intLow <= intHigh)) { //search loop
		
		intTest = Div(intLow + intHigh, 2); 
		
		if ((objOptions[intTest].text == strItem) || 
			(objOptions[intTest].text > strItem && objOptions[intTest-1].text < strItem))

			return intTest; //newname found at test

		if (objOptions[intTest].text < strItem)
			intLow = intTest + 1; //adjust range

		else {
			intHigh = intTest - 1;
		}

	} //end while loop 

	return intFound;

}

function GetRadioButtonValue(objRadio) {

	//if (objRadio == undefined) {
	//	return undefined;
	//}
	
	if (objRadio.checked) {
		return objRadio.value;
	}
	
	for (var i=0; i < objRadio.length; i++) {
		if (objRadio[i].checked) {
			return objRadio[i].value;
		}
	}
}

function checkRadioButton(objRadio,strValue) {
	
	if (objRadio == undefined) {
		return undefined;
	}
	
	for (var i=0; i < objRadio.length; i++) {
		if (objRadio[i].value == strValue) {
			objRadio[i].checked = true;
			objRadio[i].focus();
		}
	}
}

function uncheckRadioButton(objRadio,strValue,blnNoFocus) {
	
	if (objRadio == undefined) {
		return undefined;
	}
	
	for (var i=0; i < objRadio.length; i++) {
		if (objRadio[i].value == strValue) {
			objRadio[i].checked = false;
			if (!blnNoFocus) objRadio[i].focus();
		}
	}
}

function setSelectValue(objSelect, strValue) {
	
	if (objSelect == undefined) {
		return undefined;
	}
	
	for (var i=0; i < objSelect.options.length; i++) {
		if (objSelect.options[i].value == strValue) {
			objSelect.options[i].selected = true;
			break;
		}
	}
	
}


//------------------------------------------------------------------------------

function OpenNewWindowCentered(url,t,h,w,Loc,Re,Tb,Mb,Sb) {

var iMyWidth;
var iMyHeight;

// divide the current screen hright and width in half
var hN = Number(h)/2;
var wN = Number(w)/2;
// gets top and left positions based on user's resolution so hint window is centered.
iMyWidth = (window.screen.width/2) - (wN + 10); //half the screen width minus half the new window width (plus 5 pixel borders).
// check to see if the user wants the status bar to show up and size accordingly
   if (Loc == 'yes') {
		iMyHeight = (window.screen.height/2) - (hN + 25); //half the screen height minus half the new window height (plus title and status bars if necessary).
		} else {
		iMyHeight = (window.screen.height/2) - (hN + 50); //half the screen height minus half the new window height (plus title and status bars if necessary).
	}
// make the new window and give it focus
var win2 = window.open(url,t,"height="+ h +",width="+ w +",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" 
+ Sb + ",resizable=" + Re + ",menubar=" + Mb + ",dependent,location=" + Loc + ",toolbar=" + Tb + "");
win2.focus();
}



/**
	
	Form Validation Functions.
	


	The purpose of this script is to validate the values of the form fields ( specified in the aryValidateFieldList array )
	against a list of rules ( specified in the aryFieldRules array ).
	
	aryValidateFieldList contains just the name of the fields to be validated.
	aryFieldRules contains the rules to validate.
	aryFieldMsg - contains corresponding list of field names (sometimes the fieldnames don't correspond to what
			we want to display to the user, i.e. selCountryOrigin is the name of the field but we want to display
			'Country' ). 
	
	There must be a field for every rule specified and a rule for every field.
	
	Rules:
		Blank - Ensures that a value is entered into the field.
		Zero - This is to confirm that a selectbox's selected index is greater than 0.
		Number - Ensures that a number is entered.
		DateCompare - Compares two date fields to ensure that the range of the dates is valid.
		Date - Ensures that a valid date is entered.
		DateOrder - Ensures the first date is before the second date
		Currency - Ensures that the value is in a standard monitary format.
			
**/

/**

	NOTE: The following lines need to be added to the specific form validation will be performed on
	
	aryValidateFieldList = new Array('Owner', 'datCreateDate', 'ClientName', 'Title', 'Contact' ,'selClientBus', 'Office', 'selCtryOrigin', 'selLanguage');
	aryFieldRules = new Array('Blank', 'Date', 'Blank', 'Blank', 'Blank', 'Blank', 'Blank', 'Blank', 'Blank');
	aryFieldMessages = new Array ('Document Owner', 'Document Date', 'Client', 'Document Title', 'C & W Client Leader' , 'Client Business Industry', 'Office', 'Country', 'Language');
**/	

	function validateForm(objForm){
		blnValidate = true;
		for(i = 0; i < aryValidateFieldList.length; i++)
		{			
			if(aryFieldRules[i] != 'DateCompare' && aryFieldRules[i] != 'DateOrder' && aryFieldRules[i] != 'BlankAlt' ) 
			{
				blnValidate = eval('checkFor' + aryFieldRules[i] + '(objForm.' + aryValidateFieldList[i] + ')');			
			}
			else
			{			
			blnValidate = eval('checkFor' + aryFieldRules[i] + '(objForm.' + aryValidateFieldList[i] + ',' + 'objForm.' + aryValidateFieldList[++i] + ')')			
			}
			if(!blnValidate) break;
		}
		return blnValidate;
	}

	
	function showerrormessage(what){
			alert("'"+what+"' is a required field.");
	          return true
	 }	
	 
	function checkForBlank(objField){
		//alert("checkForBlank");
		blnReturnValue = true;
		if(objField.value == ''){
			blnReturnValue = false;
			showerrormessage(aryFieldMessages[i]);
		     if (objField.name == "Title")
				objField.focus();
		}
		return blnReturnValue;
	}
	
	function checkForZero(objField){
		blnReturnValue = true;
		if(objField.selectedIndex == 0){
			blnReturnValue = false;
			showerrormessage(aryFieldMessages[i]);
			objField.focus();
		}
		return blnReturnValue;
	}

	function checkForLessZero(objField){
		blnReturnValue = true;
		if(objField.selectedIndex < 0){
			blnReturnValue = false;
			showerrormessage(aryFieldMessages[i]);
			objField.focus();
		}
		return blnReturnValue;
	}
	
	function checkForNumber(objField){
		blnReturnValue = true;
		if(objField.value.match(/\(\d+\)/g)){
			objField.value = objField.value.replace(/\(/g,'-');
			objField.value = objField.value.replace(/\)/g,'');
		}
		if(!objField.value.match(/[-]{0,1}\d/g)){
			blnReturnValue = false;
			alert('You must input a number.')
			objField.focus();
		}
		return blnReturnValue;
	}
	
	function checkForDateCompare(objFieldL,objFieldG){
		blnReturnValue = true;
		if(checkForDate(objFieldL) && checkForDate(objFieldG)){
			aryDateL = objFieldL.value.split('/');
			aryDateG = objFieldG.value.split('/');
			
			objDateL = new Date(aryDateL[2], aryDateL[0], aryDateL[1]);						
			objDateG = new Date(aryDateG[2], aryDateG[0], aryDateG[1]);
						
			if(objDateL.getTime() > objDateG.getTime()){
				alert('The start date cannot come after the end date.');
				blnReturnValue = false;
				objFieldL.focus();
			}
			else if(objDateL.getTime() == objDateG.getTime()){
				blnEquals = confirm('The start date and end date are the same date.\n Do you want to continue with these dates?');
				blnReturnValue = blnEquals;
				if(!blnReturnValue)objFieldG.focus();
			}
		}
		return blnReturnValue;
	}
	
	function checkForDateOrder(objFieldS,objFieldE){		
		// verify start date is before end date
		blnReturnValue = true;				
		var dtStartDate = new Date(objFieldS.value);				
		
		var dtEndDate = new Date(objFieldE.value);
		
		if (dtEndDate < dtStartDate)
		{
			alert('The start date cannot come after the end date.');
			blnReturnValue = false;
			objFieldE.focus();			
		}				
		return(blnReturnValue);			
	}
	
	function checkForDateLimit(objField,datDate,strDate){		
		// verify start date is before end date
		blnReturnValue = true;		
		var dtObjDate = new Date(objField.value);
		var dtLimitDate = new Date(datDate);	
		var strLimitDate = strDate;
	
		if (dtLimitDate < dtObjDate)
		{
			alert('This date must be before '+ strLimitDate);
			//blnReturnValue = false;
			//objField.focus();			
			objField.value = "";
		}
		//return(blnReturnValue);	
	}
	
	function checkForDate( objField ) {
		blnReturnValue = checkForBlank( objField );
		strMonths = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV";
		strDate = objField.value;

		if( blnReturnValue ){
			if(!strDate.match(/\d{1,2} \D{3} \d{4}$/) ){
				alert('You have entered an invalid date.');
				objField.focus();
				return false;
			}

			aryDate = strDate.split("/");

			if (aryDate[2] < 100) {
				aryDate[2] = "20" + aryDate[2];
			}

			objDate = new Date();
			objDate.setYear(aryDate[2]);
			year = objDate.getYear();

			if(eval(aryDate[0] - 1) > 11){
				alert('You have selected an invalid month.');
				objField.focus();
				return false;
			}

			aryDays = new Array(31,((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)?29:28,31,30,31,30,31,31,30,31,30,31);

			if(aryDate[1] > aryDays[eval(aryDate[0].replace(/^[0]/,'') - 1)]) {
				alert('You have entered an invalid date.');
				objField.focus();
				return false;
			}
		}

		return blnReturnValue;
	}

	function checkForCurrency(objField){
		blnNumber = true;
		objField.value = objField.value.replace(/[\$\,]+/gi,'');
		blnNumber = checkForNumber(objField)
		return blnNumber;
	}
	
	function checkForBlankAlt(objFieldA,objFieldB){
	//one of two fields must be filled out
	//only one of these two fields is allowed to be filled out		
		blnReturnValue = true;
		if(objFieldA.value == ''){
			if(objFieldB.value == ''){
				blnReturnValue = false;				
				errMsg = "Please enter a value in either of the '" + aryFieldMessages[i] + "' fields.";
				alert(errMsg);
				objFieldA.focus();
			}
		}else
		{
			if(objFieldB.value != ''){
				blnReturnValue = false;				
				errMsg = "Please fill out only one of the '" + aryFieldMessages[i] + "' fields.";
				alert(errMsg);
				objFieldA.focus();
			}
		}
				
		return blnReturnValue;
	}

	function checkForSelect(objSelect) {
		if (objSelect.options.length == 0) {
			errMsg = "There must be at least one " + aryFieldMessages[i] + " entry.";
			alert(errMsg);
			objSelect.focus();
			return false;
		}

		return true;
	}

	function checkForRadio(objRadio) {
		if (typeof(GetRadioButtonValue(objRadio)) == "undefined") {
			showerrormessage(aryFieldMessages[i]);
			objRadio[0].focus();
			return false;
		}

		return true;
	}
