<!--

function messageWindow(title, msg)
{
	var width="300", height="125";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var msgWindow = window.open("","msgWindow", styleStr);
	var head = '<head><title> '+ title + ' </title></head>';
	var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"></form>';
	msgWindow.document.write(head + body);
}
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 VV_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=VV_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=Trim(val.value))!="") {
    if (test.indexOf('isDate') !=-1){
	  if (isValidDate(val)==false)errors +='- '+nm+' must contain a valid date.\n';} 
	  else if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)){ errors+='- '+nm+' must contain a number.\n';}
        else{
        if (test.indexOf('isWhole') != -1){if (isWhole(val)==false) errors+= '- '+nm+' must contain a whole number.\n';}
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(15,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } }} else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  if (document.MM_returnValue==false)
  {var obj= MM_findObj(nm); obj.focus();}
}

function Trim(mStr)
{
	var strText = new String(mStr);
	
	  // this will get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
    strText = strText.substring(1, strText.length);

	// this will get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);
	return strText;
}

function isValidDate(dateStr) {

		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;		
		
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
			
			return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		//if(year.length != 4)
		// The database will throw a overflow error incase the year value is less than 1752(SQL Server 2000)
		if(year < 1753)
		{
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			
			return false;
		}
		if (day < 1 || day > 31) {
			
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			
			return false
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
			
				return false;
		   }
		}
		return true;  // date is valid
}

function ChangeDateFormat(date1,inFormat,outFormat,sep)
{
	/* Changes the input date sent in inFormat to outFormat */
	 var yr,mm,dd
	 var datArray
	 var outDate
	 var tempDate
	
	 outDate = "Invalid";
	 if (inFormat != 3)	
	 {
	   datArray = date1.split(sep);	  
	 }
	 
	 
	switch (inFormat)
	{
		case 1: // dd/mm/yyyy
				yr = datArray[2];
				mm = datArray[1];
				dd = datArray[0];
				

				break;
		case 2: // mm/dd/yyyy
				yr = datArray[2];
				mm = datArray[0];
				dd = datArray[1];
				break;
		case 3: // Javascript date
				tempDate = new Date(date1);
				
				yr = tempDate.getYear();
				mm = tempDate.getMonth()+1;
				dd = tempDate.getDate();
				
				break;

		case 4: // yyyy/mm/dd
				yr = datArray[0];
				mm = datArray[1];
				dd = datArray[2];
				break;
				
		default:
				yr = datArray[2];
				mm = datArray[1];
				dd = datArray[0];

				break;					
				
	}
	switch (outFormat)
	{
		case 1:
				
				
				outDate = dd+"/"+mm+"/"+yr;				
				break;
		case 2:
				
				outDate = mm+"/"+dd+"/"+yr;
				break;
		case 4:
				
				outDate = yr+"/"+mm+"/"+dd;
				break;

		default:	
				
				outDate = dd+"/"+mm+"/"+yr;
				break
	}	
	
	
	return outDate;	
				
}

function isWhole(mVal) //Regular expression for checking alphabetic characters
{	
		if(parseInt(mVal)!= mVal-0){
			return false;}
		else{
			return true;}
					   
}
//-->