function trim(input) {
  var x=input;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function show(element) 
{
	if (document.getElementById)
	   {  // DOM3 = IE5, NS6
			document.getElementById(element).style.display = 'block';
		}
	else if (document.layers)
		{  // Netscape 4
			document.element.display = 'block';
		}
	else 
		{  // IE 4
			document.all[element].style.display = 'block';
		}
}

function hide(element) 
{
	if (document.getElementById)
	   {  // DOM3 = IE5, NS6
			document.getElementById(element).style.display = 'none';
		}
	else if (document.layers)
		{  // Netscape 4
			document.element.display = 'none';
		}
	else 
		{  // IE 4
			document.all[element].style.display = 'none';
		}
}

var objWin
 
function fnShowWindow(strURL, intWidth, intHeight)
{
	var leftVal, topVal

	leftVal = (screen.width - intWidth ) / 2;
	topVal = (screen.height - intHeight) / 2;
	
			
	objWin = window.open(strURL,null,"height="+ intHeight +",width= " + intWidth + ",left="+leftVal+",top="+topVal+",status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,resizable=1;",null); 
    //objWin = window.open (url, "win", "top=100,left=100,height=240,width=500,scrollbars=yes,status=no");
	document.onmousedown = mouseDown;
}


function fnOpenWindow(strURL, intWidth, intHeight)
{
	var leftVal, topVal

	leftVal = (screen.width - intWidth ) / 2;
	topVal = (screen.height - intHeight) / 2;
			
	objWin=window.open(strURL,null,"height="+ intHeight +",width= " + intWidth + ",left="+leftVal+",top="+topVal+",status=0,scrollbars=1,toolbar=0,menubar=0,location=0",null) 
	if (objWin==null) 
		objWin.opener=self;
			
}


function mouseDown(e)
{
	if (!objWin.closed) 
		objWin.focus()
	return true
}

String.prototype.trim = function()
{
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}


String.prototype.isDate = function()
{
	var re=/^((0?\d)|(1[0-2]))(\\|\/|-)((0?\d)|([1-2]\d)|(3[0-1]))(\\|\/|-)(\d{2}|\d{4})$/;
	return re.test(this);
}

Array.prototype.indexOf = function(val)
{
	for (var i=0; i<this.length; i++)
		if (this[i]==val) return i;
	return -1;
}

function VerifyDate(pYear, pMonth, pDay)
{
	var lDay = eval(pDay);
	var DateFrom = new Date(eval(pYear), eval(pMonth) - 1, lDay);
	if (DateFrom.getDate() != lDay)
		return(false);
	else
		return(true);
}
	
function GetMonthValue(MonthName)
	{
		var MN = new String();		
		MN = MonthName;
	
		var MonthValue;
		switch (MN.toUpperCase())
		{
			case "JAN":
			{
				MonthValue = 1;
				break;
			}
			case "FEB":
			{
				MonthValue = 2;
				break;
			}
			case "MAR":
			{
				MonthValue = 3;
				break;
			}
			case "APR":
			{
				MonthValue = 4;
				break;
			}
			case "MAY":
			{
				MonthValue = 5;
				break;
			}
			case "JUN":
			{
				MonthValue = 6;
				break;
			}
			case "JUL":
			{
				MonthValue = 7;
				break;
			}
			case "AUG":
			{
				MonthValue = 8;
				break;
			}
			case "SEP":
			{
				MonthValue = 9;
				break;
			}
			case "OCT":
			{
				MonthValue = 10;
				break;
			}
			case "NOV":
			{
				MonthValue = 11;
				break;
			}
			case "DEC":
			{
				MonthValue = 12;
				break;
			}
		}
		
		return(MonthValue);
	}


function IsNumeric(sText)
	{
		var ValidChars = "0123456789.,-";
		var IsNumber = true;
		var Char;
		var count = 0;
		
		var s = sText;
		
		if (s.trim() != "" && s.trim() != "-" && s.trim() != ".")
		{
			if (s.lastIndexOf("-") > 0)
				return(false);
		
			for (var i = 0; i < sText.length && IsNumber == true; i++) 
			{ 
				Char = s.charAt(i); 
				if (ValidChars.indexOf(Char) == -1) 
				{
					IsNumber = false;
				}
				else
				{
					if (Char == ".")
						count = count + 1;
				}
			}
		}
		else
		{
			IsNumber = false;
		}
		if (count > 1)
			IsNumber = false;
			
		return IsNumber;
	   
	}

function CheckNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
	
function FormatNumber(num, bolCommas)
{ 
	var DecimalPlace;
	DecimalPlace = 2;
	
	if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;
	
	tmpNum *= Math.pow(10, DecimalPlace);
	tmpNum = Math.round(Math.abs(tmpNum));
	tmpNum /= Math.pow(10, DecimalPlace);
	tmpNum *= iSign;
		
	var tmpNumStr = new String(tmpNum);

	if (bolCommas && (num >= 1000 || num <= -1000)) 
	{
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) 
		{
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length);
			iStart -= 3;
		}		
	}

	var Zero = "";
	var tmp = "";
	
	if (DecimalPlace > 0)
	{
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
		{
			while (iStart < DecimalPlace - 1)
			{
				Zero = Zero + "0";
				iStart++;
			}
			tmpNumStr = tmpNumStr + "." + Zero;
		}
		else
		{
			
			tmp = tmpNumStr.substring(iStart + 1, tmpNumStr.length)
			iStart = tmp.length;
			if (iStart < DecimalPlace)
			{
				
				while ( iStart < DecimalPlace)
				{
					Zero = Zero + "0";
					iStart++;
				}
				tmpNumStr = tmpNumStr + Zero;
			}
		}
	}
	
	return tmpNumStr;
}

function FormatEval(txt)
{
	return txt.replace(",", "");
}

function CheckNumericText(txt, lbl)
{
	if (!IsNumeric(txt.value))
	{
		lbl.className = "LabelError";
		return false;
	}
	else
	{
		lbl.className = "";
		return true;
	}
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}

function checkEmail(str) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

 function preview(fileSource, prefield){
// 		var fileTypes=["bmp","gif","png","jpg","jpeg"];
 		var fileTypes=["gif","png","jpg","jpeg"];
        var imgSource = fileSource.value; 
        var previewField = document.getElementById(prefield); 
        if(!fileSource || !fileSource.value || !previewField) return; 
        var patn = /\.jpg$|\.jpeg$|\.gif$/i; 
        if(patn.test(fileSource.value)){ 
            previewField.src = "file://localhost/" + imgSource; 
        }else{ 
            alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
        } 
    } 

function validButton(btn) {
    var cnt = -1;
	
	if (btn.length>0)
		{
			for (var i=btn.length-1; i > -1; i--) {
    	    	if (btn[i].checked) {cnt = i; i = -1;}
	    	}
	    	if (cnt > -1) return btn[cnt].value;
		    else 
				return false;	
		}		
	else
		{
			if(btn.value!='')
				return true;
			else return false;	
		
		}
			
   
}

			
