//*---------------------------------------------------
// IMAGES ROLL OVERS
// DESCRIPTION:
// 	general image swapping script
// MM_swapImgRestore():
//	restores all images on screen to original
// MM_preloadImages():
//	preloads all roll over images
//	call with location of image
//	EX: MM_preloadImages('images/imagename.gif')
// MM_swapImage()
//	switches out an image
//	USE: MM_swapImage('imagename','','imagelocation',1)
//--------------------------------------------------*/

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) { //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 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];}
}


//*---------------------------------------------------
// POP-UP WINDOW
// INPUTS:	url 		- location of file
//		toolbar		- show toolbar [yes/no]
//		location	- show location bar [yes/no]
//		menubar		- show menu bar [yes/no]
//		scrollbars	- show scroll bars [yes/no]
//		resizable	- resizable window [yes/no]
//		width		- integer width of window
//		height		- integer height of window
// OUTPUTS:
//	shows pop-up window centered in screen with
//	specified parameters
//--------------------------------------------------*/

function openWin(url, toolbar, location, menubar, scrollbars, resizable, width, height) {
    x = (800 - width)/2, y = (600 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

    msgWindow=open(url,'win','toolbar='+toolbar+',location='+location+',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable+',width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);

    if (msgWindow.opener == null) msgWindow.opener = self;
    msgWindow.focus();
}



//*---------------------------------------------------
// FORMS
//--------------------------------------------------*/

//*** Checks if text field is empty, alerts, focuses ***//
function isEmpty(field, msg) {
	if (field.value == "") {
		alert(msg);
		field.focus();
		return false;
	} else {
		return true;
	}
}

//*** Verify number ***//
function isNumber(iString) {
        if (iString.substring(0,1) == "0") {
		iString = iString.substring(1,iString.length);
	}
	if (("" + parseInt(iString)) == iString)  {
		return true;
	} else {
		return false;
	}
}

//*** Verify date ***//
function isDate(dateval) {

	a=dateval;
	
	slash1=a.indexOf("/");

	if ((slash1 == 0) || (slash1 == -1))
		return (0);

	d1 = slash1 + 1;
	
	slash2=a.indexOf("/", d1);
	
	if (slash2 == -1)
		return (0);
		
	y1 = slash2 + 1;
	
	mm = a.substring(0, slash1);	// month
	dd = a.substring(d1, slash2);	// day
	yy = a.substr(y1, 2);		// year
	
	if (yy.length != 2)
		return (0);

	//basic error checking
	if (mm<1 || mm>12) return (0);
	if (dd<1 || dd>31) return (0);
	if (yy<0 || yy>99) return (0);
	if (!isNumber(dd)) return (0);
	if (!isNumber(mm)) return (0);
	if (!isNumber(yy)) return (0);
	
	//advanced error checking

	// months with 30 days
	if (mm==4 || mm==6 || mm==9 || mm==11)
		{
		if (dd==31) return (0);
		}

	// february, leap year
	if (mm==2)
		{
		// feb
		var g=parseInt(yy/4);
		if (isNaN(g)) 
			{
			return (0);
			}

		if (dd>29) return (0);
		if (dd==29 && ((yy/4)!=parseInt(yy/4))) return (0);
		}

	return true;

}


//*** trim leading or trailing whitespace ***//
function trim(strText) { 
    // 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;
}


//*---------------------------------------------------
// SUBMITS FORM VIA DROPDOWN
// INPUTS: object
//--------------------------------------------------*/

function dropSubmit(object) {
	if (object.value != "")
		object.form.submit();
}