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_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_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); 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 selOn(ctrl) //for buttons
{
	ctrl.style.borderColor = '#1E51AA';
	ctrl.style.color = '#1E51AA';
	ctrl.style.backgroundColor = '#FFFFFF';
	ctrl.style.cursor = 'pointer'; //for hand ('hand' works in ie but not nn)
}
function selOff(ctrl) //for buttons
{
	ctrl.style.borderColor = '#FFFFFF'; 
	ctrl.style.color = '#FFFFFF';
	ctrl.style.backgroundColor = '#1E51AA';
}

// Removes leading and trailing spaces, & consecutive spaces. 
function trim(inputString) 
{
   if (typeof inputString != "string") 
   	  return inputString; //(If something besides a string is passed in (null, custom object, etc.) then return the input.
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ")  //Check for spaces at the beginning of the string
   {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") //Check for spaces at the end of the string
   { 
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) //two consecutive spaces in the string
   { 
   	  //split in two and check again, for more consec spaces:
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}


// Set Netscape 4 up to run the "captureMousePosition" function whenever the mouse is moved. For Internet Explorer and Netscape 6, we can capture the movement a little easier.
if (document.layers) { // Netscape 4
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netscape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) 
{
    if (document.layers) 
	{
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } 
	else if (document.all) 
	{
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } 
	else if (document.getElementById) 
	{
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function buildLayer(lcontent,adjtop,adjleft,width)
{
	//alert(lcontent+", "+adjtop+", "+adjleft+", "+width);
	if(document.all)
	{
		document.all['inclLayer'].innerHTML = "<table class='layer' cellspacing=2 cellpadding=3 width="+width+"><tr><td class='layer'>"+lcontent+"</td></tr></table>";
		//document.all['inclLayer'].style.top=self.event.y+document.body.scrollTop;
		//document.all['inclLayer'].style.left=self.event.x+document.body.scrollLeft-250;
		document.all['inclLayer'].style.top=yMousePos+adjtop;
		document.all['inclLayer'].style.left=xMousePos+adjleft;
		document.all['inclLayer'].style.width=width;
		document.all['inclLayer'].style.visibility='visible';
	}
	else
	{
		if(document.layers)
		{
			x = document.layers['inclLayer'];
			x.document.open();
			x.document.write("<table border=1 bordercolor='#1E51AA' bgcolor='#CEDDF0' cellspacing=0 cellpadding=3 width=300><tr><td>"+lcontent+"</td></tr></table>");
			x.document.close();
			document.layers['inclLayer'].top=yMousePos+adjtop;
			document.layers['inclLayer'].left=xMousePos+adjleft+40;
			document.layers['inclLayer'].width=width;
			document.layers['inclLayer'].visibility='show';
		}
		if(document.getElementById)	
		{
			var docContents = document.getElementsByTagName("*"); 
			docContents['inclLayer'].innerHTML = "<table class='layer' cellspacing=0 cellpadding=3 width=100%><tr><td class='layer'>"+lcontent+"</td></tr></table>";
			docContents['inclLayer'].style.top=yMousePos+adjtop;
			docContents['inclLayer'].style.left=xMousePos+adjleft;
			docContents['inclLayer'].style.width=width;
			docContents['inclLayer'].style.visibility='visible';
		}
	}
}

function showPosLayer(lname,adjtop,left,width)
{
	if(document.all)
	{
		document.all[lname].style.top=yMousePos+adjtop;
		document.all[lname].style.left=left;
		document.all[lname].style.width=width;
		document.all[lname].style.visibility='visible';
	}
	else
	{
		if(document.layers)
		{
			document.layers[lname].top=yMousePos+adjtop;
			document.layers[lname].left=left+40;
			document.layers[lname].width=width;
			document.layers[lname].visibility='show';
		}
		if(document.getElementById)	
		{
			var docContents = document.getElementsByTagName("*"); 
			docContents[lname].style.top=yMousePos+adjtop;
			docContents[lname].style.left=left;
			docContents[lname].style.width=width;
			docContents[lname].style.visibility='visible';
		}
	}
}

function showLayer(lname)
{
	if(document.all)
	{
		document.all[lname].style.visibility='visible';
	}
	else
	{
		if(document.layers)
		{
			document.layers[lname].visibility='show';
		}
		if(document.getElementById)	
		{
			var docContents = document.getElementsByTagName("*"); 
			docContents[lname].style.visibility='visible';
		}
	}
}

function hideLayer(lname)
{
	if(document.all)
		document.all[lname].style.visibility='hidden';
	else
	{
		if(document.layers)
			document.layers[lname].visibility='hide';
		if(document.getElementById)	
		{
			var docContents = document.getElementsByTagName("*"); 
			docContents[lname].style.visibility='hidden';
		}
	}
}

function validDate(pdate)
{
	var pyear, pmonth, pday
	dateArray = pdate.split("/");
	pyear = dateArray[2]
	pmonth = dateArray[1]
	pday = dateArray[0];
	
	if(isNaN(pyear))
		return false;
	else if(isNaN(pmonth))
		return false;
	else if(isNaN(pday))
		return false;
	
	var lr=leapyear(pyear);
	if(pmonth<1 || pmonth>12)
		return false;
	else if(pmonth==2 && lr==true && pday>29)
		return false;
	else if(pmonth==2 && lr==false && pday>28)
		return false;
	else if(pmonth==4&&pday>30)
		return false;
	else if(pmonth==6&&pday>30)
		return false;
	else if(pmonth==9&&pday>30)
		return false;
	else if(pmonth==11&&pday>30)
		return false;
	else if(pday>31)
		return false;
	return true;
}

function leapyear(pyear)
{
	if((pyear%4)==0 && ( ((pyear%100)!=0) || ((pyear%400)==0) ))
		return true;
	else
		return false;
}

var imgWin;
function openImgWin(imFileName,labelName,aptName)
{
	if (imgWin) // if window has been opened
  		if (!imgWin.closed) // and hasn't been manually closed
   			imgWin.focus(); // bring to the front
	imgWin = window.open("viewPhoto.php?i="+imFileName+"&n="+labelName+"&a="+aptName, "imgWin", "width=700, height=500, top=10, left=10, scrollbars=1, resizable=1, toolbars=0, location=0, status=0, menubar=0");
}
