function Trim(s) {
	if (s == "")
		return s;
		
	whitespace = " \t\r\n";
	
	// remove leading whitespace
	while ((whitespace.indexOf(s.substring(0, 1)) > -1) && (s.length > 0)) {
		s = s.substring(1, s.length);
	}
	
	// remove trailing whitespace
	while ((whitespace.indexOf(s.substring(s.length-1, s.length)) > -1) && (s.length > 0)) {
		s = s.substring(0, s.length-1);
	}
	
	return s;
}

function xreplace(checkMe,toberep,repwith){
	var temp = checkMe;
	var i = temp.indexOf(toberep);
	while(i > -1){
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	return temp;
}

function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

function decodeEstring(str){
	decodedString = ''
	str = str.split('\t')
	charSet = str[0];
	encodeSet = str[1];
	strValue = str[2];
	for(var i=0;i < strValue.length;i++){
		if(charSet.indexOf(strValue.substr(i,1)) > -1){
			decodedString = decodedString + encodeSet.substr(charSet.indexOf(strValue.substr(i,1)),1);
		}else{
			decodedString = decodedString + strValue.substr(i,1);
		}
	}
	//document.write(decodedString);
	return decodedString;
}

function eSend(str){
	decodedString = ''
	str = str.split('\t')
	charSet = str[0];
	encodeSet = str[1];
	strValue = str[2];
	for(var i=0;i < strValue.length;i++){
		if(charSet.indexOf(strValue.substr(i,1)) > -1){
			decodedString = decodedString + encodeSet.substr(charSet.indexOf(strValue.substr(i,1)),1);
		}else{
			decodedString = decodedString + strValue.substr(i,1);
		}
	}
	window.location.replace('mai' + 'lto:' + decodedString)
}

/*********************************************************
	checks if the length of text in textarea box exceeds limit
usage:
	<textarea size="3" cols="60" rows="5" name="textField" onkeyup="javascript:checkLength(this, 'charCount', 10)"></textarea>
	String Length: <span id="charCount">0</span>		
*********************************************************/
function TextAreaLength(textField, lengthToAlert){
	charCountSpan = textField.name + "CharCount"
	
	if (eval("document.getElementById('" + textField.name + "').value.length <= " + lengthToAlert)){
		//displays message
		eval("document.getElementById('" + charCountSpan + "').style.color='black'")
	}else
	{
		//changes color to red by only if lengthToAlert parameter was specified
		if (lengthToAlert != undefined){
		eval("document.getElementById('" + charCountSpan + "').style.color='red'")
		}
	}
	//determines if characters are being removed - if so the alert message is not displayed
	if(eval("document.getElementById('" + charCountSpan + "').innerText >= document.getElementById('" + textField.name + "').value.length")){
		//sets span equal to textarea length
		eval("document.getElementById('" + charCountSpan + "').innerText=document.getElementById('" + textField.name + "').value.length")
		//exits script
		return
	}
	//sets span equal to textarea length
	eval("document.getElementById('" + charCountSpan + "').innerText=document.getElementById('"+textField.name+"').value.length")
	//checks to see if the textarea length exceeds lengthToAlert - if so alerts message
	if (eval("document.getElementById('" + textField.name + "').value.length == " + lengthToAlert)){
		//displays message
		alert(eval("'You have reached your maxium allowed text length of " + lengthToAlert + "'"))
	}
}