
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  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) { //v3.0
  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); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GoVerify(p_url)
{
    if (confirm("Are You Sure?") == true) {
	    window.location = p_url;
	}
}
function GoDirect(p_url)
{
    window.location = p_url;
}
function GoClose(p_url)
{
    window.opener.location = p_url;
	window.close();
}
function Dialog(p_url,p_width,p_height,p_name,x_start,y_start,p_scroll)
{
	if (Dialog.arguments.length < 2) {
	    p_width = 500;
		p_height = 400;
	}

	if (Dialog.arguments.length < 4) {
		p_name = "dialog";
	}
	if (Dialog.arguments.length < 6) {
		x_start = 200;
		y_start = 200;
	}
	if (Dialog.arguments.length < 7) {
		p_scroll = "no";
	}	
}	

function HideDialog(p_url)
{
	newwin = window.open(p_url,null, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=10,height=10,screenX=0,left=0,screenY=0,top=0"); 
	if (newwin.focus) newwin.focus();
	if (!newwin.opener) {
		newwin.opener = self;
	}
}

function wclose() {
self.close();
}

function closeform() {
opener.document.Form1.submit();
window.close();
}

function Popup(p_url,p_width,p_height,p_scroll,p_name) {	
	var ScrWidth = screen.width;
	var ScrHeight = screen.height;
	var x = ((ScrWidth - p_width)/2);
	var y = ((ScrHeight - p_height)/2);
	if (Popup.arguments.length < 5) {
		p_name = "name"+x;
	}
	if (Popup.arguments.length < 4) {
		p_scroll = "yes";
	}
	 
	newwin = window.open(p_url,p_name, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars="+p_scroll+",status=no,toolbar=no,width="+p_width+",height="+p_height+",screenX="+x+",left="+x+",screenY="+y+",top="+y); 
	if (newwin.focus) newwin.focus();
	if (!newwin.opener) {
		newwin.opener = self;
	}
}

function Popup2(p_url,p_width,p_height,p_scroll,p_name) {	
	var ScrWidth = screen.width;
	var ScrHeight = screen.height;
	var x = ((ScrWidth - p_width)/2);
	var y = ((ScrHeight - p_height)/2);
	if (Popup2.arguments.length < 5) {
		p_name = "name"+ x;
	}

	if (Popup2.arguments.length < 4) {
		p_scroll = "yes";
	}
	 
	window.open(p_url,p_name, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars="+p_scroll+",status=no,toolbar=no,width="+p_width+",height="+p_height+",screenX="+x+",left="+x+",screenY="+y+",top="+y); 
}

function Popup3(p_url,p_width,p_height,p_scroll,p_name) {	
	var ScrWidth = screen.width;
	var ScrHeight = screen.height;
	var x = ((ScrWidth - p_width)/2);
	var y = ((ScrHeight - p_height)/2);
	if (Popup3.arguments.length < 5) {
		p_name = "name"+ x;
	}

	if (Popup3.arguments.length < 4) {
		p_scroll = "yes";
	}
	 
	var w=window.open(p_url,p_name, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars="+p_scroll+",status=no,toolbar=no,width="+p_width+",height="+p_height+",screenX="+x+",left="+x+",	screenY="+y+",top="+y); 
		
	w.focus();
}

function PopFull(p_url,p_name) {
	var ScrWidth = screen.width - 100;
	var ScrHeight = screen.height - 100;	
	window.open(p_url,p_name,"fullscreen=no,resizable=yes,menubar=yes,location=no,scrollbars=yes,toolbar=yes,status=no");
}

function PopNew(p_url,p_name) {
	var ScrWidth = screen.width - 100;
	var ScrHeight = screen.height - 100;	
	window.open(p_url,p_name,"width="+ScrWidth+",height="+ScrHeight+"screenX=0,screenY=0,left=0,top=0,menubar=yes,location=no,scrollbars=yes,toolbar=yes,status=no");
}

function DeleteVerify(p_url, p_msg)
{

	if (DeleteVerify.arguments.length < 2) {
		p_msg = "Are You Sure You want to Delete?";
	}
	
    if (confirm(p_msg) == true) {
	    window.location = p_url;
	}
}

function CopyVerify(p_url)
{
    if (confirm("Are You Sure You want to Copy?") == true) {
	    window.location = p_url;
	}
}

function CheckAll(Field, LoopMax, TrueFalse)
{	
	for(var loopndx = 0; loopndx < LoopMax; loopndx++)
	{
	Field(loopndx).checked = TrueFalse;
	}
}

function GetBrowser(){
	var DOM ,NS4, IE, IE4, Mac, IE4M, IE5M, IE5W, NS6, Safari; 

	DOM = (document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE = (document.all) ? true : false;
	IE4 = IE && !DOM;
	Mac = (navigator.appVersion.indexOf("Mac") != -1);
	IE4M = IE4 && Mac;

	if (DOM) {
		IE5M = IE && Mac;
		IE5W = IE && !Mac;
		NS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
		Safari = (navigator.vendor == ("Safari"))
	}

	if(NS4 || NS6){
		return "NS";
	}
	if(Safari){
		return "Safari";
	}
	if(Mac){
		return "Mac";
	}
	if(IE){
		return "IE";
		
	return "??";
	}
}


function SupportsDivs()
{
    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();
    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    if (is_ie6up) {
		return "True";
		
	return "False";
	}

}

function VerifyNumber(object)
{   
	if (object.value.length > 0)
	{
		if (isValidNumber(object.value)== false)
		{
			object.value = "";
			alert("Invalid Data Entered!  Please enter a number.");
		}
	}
}

function isValidNumber(inpString) {
   return /^[-+]?\d+(\.\d+)?$/.test(inpString);
}


function VerifyNumericWithExceptions(marks)
{	
	if (window.event.srcElement.value > "") 
	{
		if (isValidNumber(window.event.srcElement.value)== false)
		{
			marks = "|" + marks + "|"
			var pos=marks.indexOf("|" + window.event.srcElement.value + "|")
			if (pos<0)
			{
				window.event.srcElement.focus();
				window.event.srcElement.value = "";
				alert("Invalid Data Entered!");
			}
		}
	}
}


function VerifyAttCode(marks)
{	
	if (window.event.srcElement.value > "") 
	{
		marks = "|" + marks + "|"
		var pos=marks.indexOf("|" + window.event.srcElement.value + "|")
		if (pos<0)

		{
			window.event.srcElement.focus();
			window.event.srcElement.value = "";
			alert("Invalid Data Entered!");
		}
	}

}


function  NextAtt(marks) 
{
	var markstartpos;
	var marklen;
	var Done;
	var NewMark="";
	marks = "|" + marks + "|]";
	var oldval = "|" + window.event.srcElement.value.toLowerCase() + "|";
	var pos=marks.indexOf("|" + window.event.srcElement.value + "|");
		if (pos>=0)
		{
			markstartpos=(pos + window.event.srcElement.value.length + 2);
			if (marks.substr(markstartpos,1)=="]")
			{
				markstartpos = 1;
			}
		}
		else
		{
			markstartpos = 1;
		}
		for (var i=markstartpos;i<marks.length;i++) 
		{
			if (Done!="True")
			{
				if (marks.substr(i,1)=="|")
				{
					Done="True";
				}
				else
				{
					NewMark = NewMark + marks.substr(i,1);
				}
			}
		}
		
		if (Done=="True")
		{
			window.event.srcElement.value = NewMark;
			window.event.srcElement.focus();
			window.event.srcElement.select();
		}		
}

function VerifyDate() 
{

	if (isValidDate(window.event.srcElement.value) == false)
		{
			window.event.srcElement.focus();
			window.event.srcElement.select();
			alert("Invalid Date Entered!");	
		}
}



function isValidDate(dateStr, format) {
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || _
      (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
   }
   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else _
      if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else _
      if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else _
      if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}

///////////////////////////////////////////////
//added by louis
//these methods rely on the control having a distinct 
//portion in its name 
//look at checkboxes (elementname) for deletes
//if any are checked popup a confirm dialog (message)
function checkDeletes(elementName, message)
{				
	var check;
	var i;
	var check_count=0;
	
	for(i=0;i<document.all.length;i++)
	{
		check=document.all.item(i);
		if(check.id.indexOf(elementName)>-1)
		{
			if(check.checked)
			{
				check_count++;
			}
		}
	}
	
	if(check_count>0)
	{
		return confirm(message)			
	}
	else
	{
		return true;
	}					
}

//check an array of elements to see
//if they are an empty string
//optionally ignore the last element
//of the array
function checkFilled(elementName, ignoreLast)
{
	var retval=true;
	var count=0;
	var controls=0;
	var last=0;
		
	for(i=0;i<document.all.length;i++)
	{
		obj=document.all.item(i);
		if(obj.id.indexOf(elementName)>-1)
		{
			//this is one of the elements we seek
			controls++;

			if(obj.value=='')
			{
				//empty string
				count++;
				last=controls;
			}
		}				
	}

	if(count==0)
	{
		//none were empty
		return true;
	}	
	else
	{
		if(controls==last)		
		{
			//last control was empty
			if(ignoreLast==false)
			{
				//we're not ignoring it so return false
				return false;
			}
			else
			{
				if(count>1)
				{
					//we are ignoring it but there are
					//other empty controls
					return false;
				}
				else
				{
					//we are ignoring it and there are no
					//other empty controls
					return true;
				}
			}
		}
		else
		{
			//some other control besides
			//the last was empty
			//return false
			return false;
		}		
	}		
}

/*
Default all '<select>' elements beginning with the name [SelectName] to the
value [DefaultValue] in the form [Form].
*/
function DefaultSelect(Form, SelectName, DefaultValue) {
	for(var idx=0; idx < Form.length; idx++) {
		element = Form.elements[idx];
		if(element.name.substring(0, SelectName.length) == SelectName) {
			element.value = DefaultValue;
		}
	}
}

function openReport(HiddenReportFileName)
{
	var reportFilename = document.getElementById(HiddenReportFileName).value;
	
	if(reportFilename.length > 0) {
		PopNew("DisplayReport.aspx?F=" + reportFilename);
		document.getElementById(HiddenReportFileName).value = ""
	}
}