function SetFocustoLastElementWithFocus(CurElem, DefaultElem)
{
	var Obj = CurElem;
	var DefObj = DefaultElem
	if (Obj !='' && Obj !=null)
	 {
		if (document.getElementById(""+Obj).disabled==false){
		document.getElementById(""+Obj).focus();} 
	 }else{
		 if (DefObj !='' && DefObj !=null){
			 if (document.getElementById(""+DefObj).disabled==false){
			 document.getElementById(""+DefObj).focus();}
		 }
	 }
}

function Alerts(PopupMsg, RedirectIndicator, URL)
{
	var strMsg = PopupMsg
	if (strMsg != "") {
		alert(PopupMsg)
	}
	
	if (RedirectIndicator=='True') {
		location.replace(URL)
	}
}

function IsValid(documentelement,actiontype){
	var theExpression;
	var mystring;
	
	mystring = documentelement;
	if (actiontype =="1")
	{
		theExpression=/^[0-9a-zA-Z]+$/;
	}
	
	if (actiontype =="2")
	{
		theExpression=/^[0-9]+$/;
	}
	
	if (actiontype =="3")
	{
		theExpression=/^[a-zA-Z]+$/;
	}
	
	if (actiontype =="4")
	{
		theExpression=/^[a-z A-Z-]+$/;
	}

	if (actiontype =="5")
	{
		theExpression=/^[\r\n,0-9a-z A-Z().#-/]+$/;
	}

	if(mystring.match(theExpression))
	{
		return true;
	}else{
		return false;
	}	
}


function IsValidTime(timeStr) {
// Checks if time is in HH:MM format.

	var timePat = /^(\d{1,2}):(\d{2})+$/;
	
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		alert("Time is not in a valid format.\n Example 12:00");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	
	
	if (hour < 1  || hour > 12) {
		alert("Hour must be between 1 and 12");
		return false;
	}
	
	if (minute<0 || minute > 59) {
		alert ("Minute must be between 0 and 59.");
		return false;
	}
	
	return true;
}

function IsEmail(str) {
  
  var supported = 0;
  if (str==""){
  return true;
  }
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function textLimit(field, maxlen) {
	if (field.value.length > maxlen + 1)
	alert('Your input has been truncated! Maximum lenght allowed is '+ maxlen);
	if (field.value.length > maxlen)
	field.value = field.value.substring(0, maxlen);
	field.focus();
}

function NumberOfDaysPassed(mydate)
{
	var numofdays = 0;
	var difference = 0;
	var vardate = new Date(mydate);
	vartoday  = new Date();
	difference = vartoday - vardate;
	numofdays = Math.round(difference/(1000*60*60*24));
	return numofdays;
}

function hidediv(divname) {

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(""+divname).style.visibility = 'hidden';
	} else {
		if (document.layers) { // Netscape 4
			document.DivMenu.visibility = 'hidden';
			document.DivFilters.visibility = 'hidden';
		} else { // IE 4
			document.all.DivMenu.style.visibility = 'hidden';
			document.all.DivFilters.style.visibility = 'hidden';
		}
	}
}

function divhide (itemid) {
	var whichitem = document.getElementById(""+itemid);
		whichitem.className="commenthidden"; 
}

function divshow (itemid) {
	var whichitem = document.getElementById(itemid);
		whichitem.className="commentshown"; 
}

function showdiv(divname) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(""+divname).style.visibility = 'visible';
	}
	else {
		if (document.layers) { // Netscape 4
			//document.DivMenu.visibility = 'visible';
			document.DivFilters.visibility = 'visible';
		} else { // IE 4
			//document.all.DivMenu.style.visibility = 'visible';
			document.all.DivFilters.style.visibility = 'visible';
		}
	}
} 

function PrintPage()
{
	//hidediv('DivMenu');
	hidediv('DivFilters');
	divhide('DivFilters');
	window.print();
	//showdiv('DivMenu');
	showdiv('DivFilters');
	divshow('DivFilters');
}