//insert <br> when it find chr(10) and chr(13)
function insertBR(str) {
	var sNewText = "";
	for (var ct = 0; ct < str.length; ct++) {
		var c = str.charAt(ct);
		if (c == '\n') sNewText = sNewText + "<br>";
		else sNewText = sNewText + c;
	}
	return sNewText;
} //insertBR(str)


//replace white space with nothing
function stripString(sText) {
	var sNewText = sText.toString().replace(/\s/g, '');
	return sNewText;
} //stripString(sText)


//replace invalid characters in string
function stringReplace(sText) {
	var sNewText = sText.toString().replace(/\"/g,"&quot;");
	sNewText = sText.toString().replace(/\'/g, "&rsquo;");
	return sNewText;
} //stringReplace(sText)


//pass in a value and return true if blank or contains only spaces
function isBlank(str) {
	if ((str == null) || (str == ""))
		return true;
	else
		for (var i = 0; i < str.length; i++) {
			var c = str.charAt(i);
			if ((c != ' ') && (c != '\n'))
				return false;
		}
	return true;
}


//verify email address format
function isEmail(strIn) {
	var emailExp = /^[a-z][a-z_0-9\.\-]+@[a-z_0-9\.\-]+\.[a-z]{2,4}$/i;
	return emailExp.test(strIn);
} //isEmail(strIn)


//verify string contains letter only
function hasSpace(strIn) {
	var space = /[\s]/g;
	return space.test(strIn);
} //hasSpace(strIn)


//verify that the value only contains number digits
function isNum(fieldObj) {
	var anum = /\D/;
	return anum.test(fieldObj);
}



//verify that the value contains letter, numeral or underscore
function hasChar(strIn) {
	var charExp = /\w/;
	return charExp.test(strIn);
}


//Original:  Cyanide_7 (leo7278@hotmail.com)
//Web Site:  http://www7.ewebcity.com/cyanide7
//The JavaScript Source!! http://javascript.internet.com
//pass in a value and it will format it with dollar sign and cents
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	cents = Math.floor((num*100+0.5)%100); 
	num = Math.floor(num).toString();
	if(cents < 10)
		cents = "0" + cents; 
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) 
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3)); 
	return ('$' + num + '.' + cents); 
}


//pass in a value and it will format it with a coma
function formatNumber(num) {
	num = num.toString().replace(/\$|\,/g,'');
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0, num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
	return num;
}


//take user to a new URL
function leapTo (newURL) {
   if (  (newURL != "")  &&  (newURL != null)  )
      window.location=new_url;
   else
      alert("\nYou must make a selection.");
}


//pass in the field object and it will format phone number
function phoneMask(phoneNum) {
	phoneNum = phoneNum.toString().replace(/\(|\)|\-/g,'');
	if ((phoneNum.length != 10) || (isNum(phoneNum))) {
		alert("\nPhone number \"" + phoneNum + "\" does not seems correct.\nPlease enter a 10 digits phone number.");
		return phoneNum;
	} else {
		var phone = "(" + phoneNum.substring(0,3) + ")" + phoneNum.substring(3,6) + "-" + phoneNum.substring(6);
		return phone;
	}
}


//change color to the link on mouse over
function changeColor(sColor) {
	src = event.toElement;
	if (src.tagName == "A") {
		src.oldcol = src.style.color;
		src.style.color = sColor; 
	}
}


//change color back to its original color when mouse move out
function changeBack() {
	src=event.fromElement;
	if (src.tagName == "A") {
		src.style.color = src.oldcol;
	}
}



