/* BMMSI, EK 8/2004

 */
var menuwidth='165px'
var menubgcolor='lightyellow'  
var disappeardelay=250 
var hidemenu_onclick="yes"

var ie4=document.all
var ns6=document.getElementById&&!document.all

var STATEMENT = 1;
var CLOBDOC = 2;
var Staticwind = 3;
var NewWindow;
var minYear=1800;
var maxYear=2101;
var dtStr = "/"
// Flag determines what window to open.
//1. for statement, 2 for clob-document, etc
function OpenWindow(MyWindow, flag )
{
	NewWindow = MyWindow; 
	if( STATEMENT ==  flag ){	     
		MyWindow.href = "javascript:OpenWindow2('" + MyWindow.href +"' )";   
	}else if ( flag == Staticwind ){	   
		MyWindow.href = "javascript:OpenWindow4('" + MyWindow.href +"' )";   
	}else{
		MyWindow.href = "javascript:OpenWindow3('" + MyWindow.href +"' )";   
	}
}
function OpenWindow2(url )
{
       NewWindow.href = url;  //reset the href
       w = window.open(url, 'new', 'scrollbars=2,width=600,height=400,resizable=yes, menubar=yes' );
		 w.focus()
}

function OpenWindow3(url )
{
       NewWindow.href = url;  //reset the href
       w = window.open(url, 'new', 'scrollbars=2,resizable=yes' );
       w.focus()
}

function OpenWindow4( url )
{
       NewWindow.href = url;  //reset the href
       w = window.open( url );
       w.focus()
}

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function daysInMonth( month, year ) {
	if (month == 4 || month ==6 ||  month == 9 ||  month == 11) {
		return 30;
	}
	else if (month == 2) { 
		return daysInFebruary(year);
	}
	return 31;
}

function isNumber( str ){
	var i;
    for (i = 0; i < str.length; i++){   
        var chr = str.charAt(i);
        if (((chr < "0") || (chr > "9"))) 
        return false;
    }
    return true;
}

function isValidDate( strDate){
	// rid of whitespace in the date string.
	if( strDate.length > 10 || strDate.length < 6 ){
		alert("Wrong Date format! Please use the following format and submit again: mm/dd/yyyy")
		return false
	}
	
	var separator1_pos = strDate.indexOf(dtStr);
	var separator2_pos = strDate.indexOf(dtStr, separator1_pos+1);
	var strMonth = strDate.substring(0,separator1_pos);
	var strDay = strDate.substring(separator1_pos+1,separator2_pos);
	var strYear = strDate.substring(separator2_pos+1);
	var nMonth = parseInt(strMonth, 10)
	var nDay = parseInt(strDay, 10 )
	var nYear = parseInt(strYear,10)
	if( separator1_pos <=  -1 || separator2_pos <= -1){
		alert("Please use the following format when entering dates: mm/dd/yyyy")
		return false	
	}
	if ( strMonth.length < 1 || nMonth < 1 || nMonth > 12 ||  !isNumber(strMonth)){	
		alert("Please enter a valid Month")	
		return false
	}
	if (strDay.length<1 || nDay < 1 || nDay > 31 || ( nMonth == 2 && nDay > daysInFebruary(nYear)) || nDay > daysInMonth(nMonth, nYear) ||  !isNumber(strDay)){
		alert("Please enter a valid Day of the Month")
		return false
	}
	if ( strYear.length != 4 || nYear==0 || nYear<minYear || nYear>maxYear ||  !isNumber(strYear)){
		alert(strYear +" is not a valid year, please enter a 4 digit year between "+minYear+" and "+maxYear)
		return false
	}	
	return true
}

function ValidateForm(){	
	var sl1 = document.forms[0].select1.options[document.forms[0].select1.selectedIndex].value;
	var sl2 = document.forms[0].select2.options[document.forms[0].select2.selectedIndex].value;
	var sl3 = document.forms[0].select3.options[document.forms[0].select3.selectedIndex].value;
	var sl4 = document.forms[0].select4.options[document.forms[0].select4.selectedIndex].value;
	if( (trim( document.forms[0].val1.value) != "" && document.forms[0].val1.value != null)
	  && (sl1 == "" ) ){	
		alert("You must select a search by field for: " + document.forms[0].val1.value);
		document.forms[0].select1.focus()
		return false;	
	}
	if( ( trim(document.forms[0].val2.value) != "" && document.forms[0].val2.value != null)
	  && (sl2 == "" ) ){	
		alert("You must select a search by field for: " + document.forms[0].val2.value);
		document.forms[0].select2.focus()
		return false;	
	}	
	if( (trim(document.forms[0].val3.value) != "" && document.forms[0].val3.value != null) 
	 && (sl3 == "" ) ){	
		alert("You must select a search by field for: " + document.forms[0].val3.value);
		document.forms[0].select3.focus()
		return false;	
	}	
	if( (trim( document.forms[0].val4.value) != "" && document.forms[0].val4.value != null) 
	&& (sl4 == "" ) ){	
		alert("You must select a search by field for: " + document.forms[0].val4.value);
		document.forms[0].select4.focus()
		return false;	
	}

	if( document.forms[0].name != 'statementsearch' ){
		
			
		var strDate = document.forms[0].date1.value;
		var strDate2 = document.forms[0].date2.value;
		strDate2 = trim(strDate2)
		strDate = trim(strDate)
		if( strDate.length == 0 && strDate2.length == 0  ){
			return true;
		}
		if( strDate.length > 0 && strDate2.length <= 0  ){
			alert("You need both dates to search for the appropriate admimission date range.")
			document.forms[0].date2.focus()
			return false;
		}
		
		if( strDate2.length > 0 &&  strDate.length <= 0  ){
			alert("You need both dates to search for the appropriate admimission date range.")
			document.forms[0].date1.focus()
			return false;
		}
		if (isValidDate(strDate) == false){
			document.forms[0].date1.focus()
			return false
		}
		if (isValidDate(strDate2)==false){
			document.forms[0].date2.focus()
			return false
		}
	}else{
		var strDate = document.statementsearch.statementdate.value;
		if( strDate.length == 0 ){
			return true;
		}
		if (isValidDate(strDate) == false){
			document.statementsearch.statementdate.focus()
			return false
		}
	}
	
    return true;
 }

function ValidateReportForm(){
		var strDate = document.forms[0].date1.value;
		var strDate2 = document.forms[0].date2.value;
		strDate2 = trim(strDate2)
		strDate = trim(strDate)
		if( strDate.length == 0 && strDate2.length == 0  ){
			alert("You need a date range for this report. Please try again. ")
			return false;
		}
		if ( ( strDate.length > 0 && strDate2.length <= 0  )
			||  (strDate2.length > 0 &&  strDate.length <= 0  ) ) {
			alert("Both dates are required for this Report.")
			document.forms[0].date2.focus()
			return false;
		}		
		if (isValidDate(strDate) == false){
			document.forms[0].date1.focus()
			return false
		}
		if (isValidDate(strDate2)==false){
			document.forms[0].date2.focus()
			return false
		}
		if( CheckClients() == false ){
			document.report.selclts.focus();
			return false;
		}		
				
    	return true;
 }


function CheckClients() {
   var Counter = 0;
    var pass = true;
   for (i=0; i<document.report.selclts.length; i++){
      if (document.report.selclts[i].selected == true){
         Counter++;
      }
   }
   if (document.report.selclts.value != "") {
      Counter = 1;
   }
   if (Counter == 0 ){
      alert("You must select at least one client.");
      return false;
   } else  if ( Counter > 4 ){
      pass = confirm("You have selected more than 5 clients, please note the following:\nIt may take the system a little longer to process the report.\nYour computer (browser) may not have enough memory to hold the results.\nPress OK to continue or Cancel to change your search.  ");
   }
   return true;
}

function trim(strIn) { 
    //white space in the front
    while (strIn.charAt(0) == " ") 
        strIn = strIn.substring(1, strIn.length);

    //trailing whitespace
    while (strIn.charAt(strIn.length-1,strIn.length) ==  " ")
        strIn = strIn.substring(0, strIn.length-1);
   return strIn;
  }

function onDateChange(){
	var selectedDate = document.forms[0].datesel.options[document.forms[0].datesel.selectedIndex].value;	
	if( selectedDate == "datin" ){
		document.forms[0].searchdate.value = "3";
	}else if( selectedDate == "Purge" ){
		document.forms[0].searchdate.value  = "1"; 
	}else if( selectedDate == "Queue" ){
		document.forms[0].searchdate.value  = "2";
	}else{
		document.forms[0].searchdate.value  = "0";
	} 
}

servicesrt = new Image();
servicesrt.src = 'images/servicesrt.gif';
servicesdn = new Image();
servicesdn.src = 'images/servicesdn.gif';
servicesup = new Image();
servicesup.src = 'images/servicesup.gif';

companyrt = new Image();
companyrt.src = 'images/companyrt.gif';
companydn = new Image();
companydn.src = 'images/companydn.gif';
companyup = new Image();
companyup.src = 'images/companyup.gif';

homert = new Image();
homert.src = 'images/homert.gif';
imghome = new Image();
imghome.src = "images/imghome.gif";
newsrt = new Image();
newsrt.src = "images/newsrt.gif";
news = new Image();
news.src = "images/newswt.gif";
affrt = new Image();
affrt.src = "images/affrt.gif";
aff = new Image();
aff.src = "images/affwt.gif";


reportsrt = new Image();
reportsrt.src = "images/affrt.gif";
reportswt = new Image();
reportswt.src = "images/affwt.gif";

pdfrt = new Image();
pdfrt.src = "images/affrt.gif";
pdfwt = new Image();
pdfwt.src = "images/affwt.gif";

a50rt = new Image();
a50rt.src = 'images/a50rt.gif';
a50dn = new Image();
a50dn.src = 'images/a50dn.gif';
a50up = new Image();
a50up.src = 'images/a50up.gif';

a100rt = new Image();
a100rt.src = 'images/a100rt.gif';
a100dn = new Image();
a100dn.src = 'images/a100dn.gif';
a100up = new Image();
a100up.src = 'images/a100up.gif';

a499rt = new Image();
a499rt.src = 'images/a499rt.gif';
a499dn = new Image();
a499dn.src = 'images/a499dn.gif';
a100up = new Image();
a100up.src = 'images/a499up.gif';

