function RemoveInvalidChars(theinput, pattern) {
	reg = new RegExp(pattern, 'g');
	newstring = theinput.value.replace(reg, '');
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}
function FormatDate(theinput) {
	reg = new RegExp('[^0-9]', 'g');
	numbersonly = theinput.value.replace(reg, '');

	if (numbersonly.length > 4) {
		newstring =  numbersonly.substr(0, 4) + '-' + numbersonly.substr(4, 2) + '-' + numbersonly.substr(6, 2);
	} else if (numbersonly.length > 6) {
		newstring = numbersonly.substr(0, 2);
	} else {
		newstring = numbersonly;
	}
	// only update the input if the text has changed
	// to avoid annoying behavior (e.g. moving cursor to end of text)
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function ForceUppercase(theinput) {
	newstring = theinput.value.toUpperCase();
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function ForceLowercase(theinput) {
	newstring = theinput.value.toLowerCase();
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function FormatPhoneNumber(theinput) {
	reg = new RegExp('[^0-9]', 'g');
	numbersonly = theinput.value.replace(reg, '');

	if (numbersonly.length > 1) {
		newstring = numbersonly.substr(0, 14);
	} else if (numbersonly.length > 14) {
		newstring = numbersonly.substr(0, 14);
	} else {
		newstring = numbersonly;
	}
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function MatchesPattern(theString, pattern) {
	reg = new RegExp(pattern, 'g');
	return Boolean(reg.exec(theString));
}

function IsValidEmail(emailstring) {
	return MatchesPattern(emailstring, '\\w[\\w\\-\\.]*\\@\\w[\\w\\-]+(\\.[\\w\\-]{2,})+');
}

function SetElementTextColor(theelement, thecolor) {
	if (theelement.style) {
		theelement.style.color = thecolor;
	}
	return true;
}

function HighlightThis(theelement) {
	if (theelement.style) {
		theelement.style.background = '#bdc4cd';
	}
	return true;
}

function UnHighlightThis(theelement) {
	if (theelement.style) {
		theelement.style.background = '#eeeeee';
	}
	return true;
}

function White(theelement) {
	if (theelement.style) {
		theelement.style.background = '#ffffff';
	}
	return true;
}

function UnHighlight2(theelement) {
	if (theelement.style) {
		theelement.style.background = '#cccccc';
	}
	return true;
}

function MM_preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

function popup(a,msg,look,x,y){ //v1.0.5
  var d=document; if (!a){var ln='pLayer';dx="";dy="";b=(d.layers)?1:0;
    nn=(b||d.getElementById &&!d.all)?1:0;l = new Object();
    l.s=b?d.layers[ln]:MM_findObj(ln).style;l.r=b?d.layers[ln].document:MM_findObj(ln);
    l.w=function (t) {if(b){l.r.write(t);l.r.close()}else l.r.innerHTML=t}
	if(b) d.captureEvents(Event.MOUSEMOVE);d.onmousemove=function(e)
	{dx=(nn)?e.pageX:event.x;dy=(nn)?e.pageY:event.y;}}if (a=='1') {l.s.visibility='hidden'}
  if (a=='2') {l.w('<span class="'+look+'">'+unescape(msg)+'</span>')
	if(d.all) dy=dy+d.body.scrollTop;x=(!x)?50:Number(x);
	y=(!y)?-20:Number(y);l.s.left=dx+x; l.s.top=dy+y;l.s.visibility='visible'}
}
function nr(theinput) {
	reg = new RegExp('[^0-9]', 'g');
	numbersonly = theinput.value.replace(reg, '');
	if (numbersonly.length > 1) {
		newstring = numbersonly.substr(0, 6);
	} else if (numbersonly.length > 6) {
		newstring = numbersonly.substr(0, 6);
	} else {
		newstring = numbersonly;
	}
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}
function pr(theinput) {
	reg = new RegExp('[^0-9.]', 'g');
	numbersonly = theinput.value.replace(reg, '');
	if (numbersonly.length > 1) {
		newstring = numbersonly.substr(0, 10);
	} else if (numbersonly.length > 10) {
		newstring = numbersonly.substr(0, 10);
	} else {
		newstring = numbersonly;
	}
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}
