function HtmlEncode(strToReplace){ 			
	var strNew = document.getElementById("txtNew");
	var strFixString = strToReplace.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\'/g,"&apos;").replace(/\"/g,"&quot;"); 
	return strFixString; 		  
} 

function validEmail(value) {
	//check email against regular expression
	var reg = /[\w-.]+?@([\w-]+?\.)+[\w]{2,}/gi;
	var ar = reg.exec(value);
	
	//ar will be null if expression doesn't match
	return(ar != null);
}

function validMoney(value) {
	return validNumberPlus(value,',.-',true);
}

function validNumber(value) {
	return validNumberPlus(value,'.',true);
}

function validNumberPlus(value,plusChars,allowBlank) {
	var plusSize = plusChars.length + 0;
	var validChars = new Array(9+plusSize);
	var i, j, theChar, good, retVal, theSize;
	
	if(!allowBlank && value.length == 0)
		return false;
	
	validChars[0] = '0';
	validChars[1] = '1';
	validChars[2] = '2';
	validChars[3] = '3';
	validChars[4] = '4';
	validChars[5] = '5';
	validChars[6] = '6';
	validChars[7] = '7';
	validChars[8] = '8';
	validChars[9] = '9';
	
	for(i=1; i<=plusSize; i++) {
		validChars[i+9] = plusChars.substring(i-1,i);
		//alert(plusChars.substring(i-1,i));
		//alert(validChars[i+9]);
	}
		   
	//alert(value);
	retVal = true;
	theSize = value.length;
		   
	for(i=1; i<=theSize; i++) {
	   //alert(value.substring(i-1,i));
	   theChar = value.substring(i-1,i);
	   good = false;
			  
	   for(j=0; j<10+plusSize; j++) {
		  //alert(j + ' - ' + validChars[j]);
		  if(validChars[j] == theChar) {
			 //alert('good char');
			 good = true;
			 break;
		  }
	   }
			  
	   if(!good) {
		  retVal = false;
		  break;
	   }
	}
	
	// check for more than 1 period by splitting on periods and seeing if there are more than 2 resulting array items.
	var multPeriods = value.split('.');
	if (multPeriods.length > 2)
		retVal = false;
		   
	return retVal;
}


function checkNetNumber(oSrc, args) {
	var theVal = document.getElementById(oSrc.NumberControl).value;
	args.IsValid = validNumber(theVal);
}

//vars
 layerStyleRef="layer.style.";
 styleSwitch=".style";
 layerVis="visible";
 layerHid="hidden";

function getImage(name) {
	return eval('document.getElementsByName("' + name + '"');
}

function getImagePageLeft(img,offsetLeft) {
	var x, obj;

	x = 0;
	obj = img;
	while (obj.offsetParent != null) {
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	x += obj.offsetLeft;
	return x+offsetLeft;
}

function getImagePageTop(img,offsetTop) {
	var y, obj;
	y = 0;
	obj = img;
	while (obj.offsetParent != null) {
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	y += obj.offsetTop;
	return y+offsetTop;
}

//.NET email checker
function EmailChecker(oSrc, args){
	var theVal = args.Value + "";

	args.IsValid = validEmail(theVal);
}


function ValidateMultipleEmails(emailList)
{
	// Escape the entire string so all crazy characters show up as their %code, which we can then replace (this way we can
	// find commas, spaces AND carriage returns, and use all three as delimiters).
	var emails = escape(emailList);
	var newEmails = "";         // this will be the nicely formatted return string of email addresses
	
	// %2C is the comma, %0D%0A is the linefeed/carriage return chars, and %20 is a space. Replace all with commas.
	emails = emails.replace(/%2C/g, ",").replace(/%0D%0A/g, ",").replace(/%20/g, ",")
	
	// Now we can split just on commas.
	emailArray = emails.split(",");
		
	for (var i=0; i<emailArray.length; i++)
	{
		if (emailArray[i].replace(" ", "") != "")
			 if (ValidateEmail(emailArray[i]) == false)
			 {
				alert(emailArray[i] + " is not a valid email address.");
				return "";
			 }
			 else
				newEmails += emailArray[i] + ",";
	}
	// If all is good, send back the reformatted email addresses
	return newEmails;
}
		
function ValidateEmail(email)
{
	if (email.replace(" ", "") == "") return false;     // is empty string
	if (email.indexOf("@") < 1) return false;           // no @ char, or @ is first char in string
	if (email.indexOf(".") < 1) return false;           // no . char, or . is first char in string
	if (email.length < 5) return false;                 // too short to be a real email address
	
}

// Not really sure where to put this yet, so sticking it here for now.
function formatState(val)
{
	if (val.length == 2)
		return val.toUpperCase();
	else
		return val.substring(0, 1).toUpperCase() + val.substring(1).toLowerCase();
}

// 04/06/2007 Chandra Bhumireddy

// returns true if key pressed is number otherwise false.
// ex : onkeypress="return isNumberKey(event);"
function isNumberKey(evt) 
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
	   return false;
	}
	 return true;
}

// 04/06/2007 Chandra Bhumireddy
// returns true if key pressed is Decimal number otherwise false.
//ex : onkeypress="return isDecimalNumberKey(event);"
function isDecimalNumberKey(evt) 
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57)&&charCode!=46)
	{
	   return false;
	}
	 return true;
}

//04/24/07 Chandra Bhumireddy
// Check if duplicate item exist in Select Box
function IsSelectBoxItemExist(selectBox,itemValue)
{
  if(selectBox)
   {
	 for(var i=0;i<selectBox.length;i++)
		if(selectBox.options[i].value==itemValue)
		return true;
   }
   return false;
}

