<!--
//------------------------------------------------------------------------------

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.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];}
}
//------------------------------------------------------------------------------

/* Opens a default sized window with toolbar and menubar in the named window */
function openWin(url, name) 
{
	return openWin(url, name, 700, 500, 'yes', 'yes');
}
//------------------------------------------------------------------------------

/* New window function used by left menu */
function openNewApplication(url, name)
{
    var win = window.open(url, name);
    win.focus();
}
//------------------------------------------------------------------------------

/* This function opens a new window with the specified url in the specified target
window with the specified width and height. The new window
will have a toolbar and menubar only if those parameters are set to "yes"*/

function openWin (urlName, target, wid, ht, toolbar, menubar)
{
    if (toolbar==null || toolbar.length==0)
        toolbar='no';
    if (menubar==null || menubar.length==0)
        menubar='no';

    this.focus();
    newWin=window.open(urlName, target,'top=0,left=0,width='+wid+',height='+ht+',resizable=yes,location=no,directories=no,scrollbars=yes,menubar='+menubar+',toolbar='+toolbar+',history=no,status=no');
    newWin.focus();
    return newWin;
}
//------------------------------------------------------------------------------

/* This function takes in a date String as entered by the user and a time string
as selected by the user (in format hh:mm am) and validates the date. It returns
a javascript date if valid, else an empty string. */

function dateregexp (datestr, timestr) 
{
	var dateExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
	var val = datestr;
	var found = dateExp.test(datestr);
	if(!found)
	   val = "";
	else
	{
	    var i1 = datestr.indexOf("-");
	    var i2 = datestr.lastIndexOf("-");
		if (i1==-1)
		{
			i1 = datestr.indexOf("/");
			i2 = datestr.lastIndexOf("/");
		}
		if (i1==-1)
		{
			i1 = datestr.indexOf(".");
			i2 = datestr.lastIndexOf(".");
		}
	    var day;
	    var month;
	    var year;
	    var hours = timestr.substring(0,timestr.indexOf(":"));
	    var nohours = timestr.substr((timestr.indexOf(":")+1));
	    var minutes = nohours.substr(0,2);
	    if (nohours.indexOf("pm")!=-1 && hours!=12)
		hours = 12 + (new Number(hours));

	    if (nohours.indexOf("am")!=-1 && hours==12)
		hours = (new Number(hours)) - 12;

	    if (i1!=-1 && i1!=i2)
	    {
			day = datestr.substring(0,i1);
			month = datestr.substring((i1+1),i2) - 1;
			year = datestr.substr((i2+1),4);
			val = new Date(year, month, day, hours, minutes);
            // check to see if date was changed
            if ((parseFloat(day) != val.getDate()) || (parseFloat(month) != val.getMonth()))
                val = "";
	    }
	    else
			val = "";
	}
	return val;
}
//------------------------------------------------------------------------------

/* This function takes in a valid date String (col) as entered by the user in
format: dd.mm.yyyy or d/m/yyyy or d-m-yyyy and figures out the day of the week
that this date corresponds to. It then sets the field (dayName) to this value.
*/

function findDayName (col, dayName) 
{
    if (col==null) return;

    daysInWeek=["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
    datestr = col.value;

    if (datestr==null) return;
    if (datestr.length==0) return;

    var i1 = datestr.indexOf("-");
    var i2 = datestr.lastIndexOf("-");

    if (i1==-1) 
    {
    	i1 = datestr.indexOf("/");
    	i2 = datestr.lastIndexOf("/");
    }
    if (i1==-1) 
    {
    	i1 = datestr.indexOf(".");
    	i2 = datestr.lastIndexOf(".");
    }
    val = "";
    if (i1!=-1 && i1!=i2)
    {
        day = datestr.substring(0,i1);
        month = datestr.substring((i1+1),i2) - 1;
        year = datestr.substr((i2+1),4);
        val = new Date(year, month, day, 0, 0);
        // check to see if date was changed
        if ((parseFloat(day) != val.getDate()) || (parseFloat(month) != val.getMonth()))
        	val = "";
    }

    obj = MM_findObj (dayName);
    if (val!="" && obj!=null)
    {
        theDay=val.getDay();
        obj.value = daysInWeek[theDay];
    }
}
//------------------------------------------------------------------------------

/* This function sets the cursor on the first textbox or select box or submit
button that exists on the form, if there is a form on the page. Else it does nothing.*/

function setFocus(formObj)
{
    var i=0;
    if (formObj!=null && formObj.elements!=null && formObj.elements.length>0)
    {
		while (i<formObj.elements.length && formObj.elements[i]!=null &&
			  formObj.elements[i].type!='text' && formObj.elements[i].type!='select-one'
			  && formObj.elements[i].type!='password' && formObj.elements[i].type!='submit')
		{
			i++;
		}

		if (i<formObj.elements.length && formObj.elements[i]!=null)
			formObj.elements[i].focus();
    }

    return true;
}
//------------------------------------------------------------------------------

/* This function sets the cursor on the field with the specified name on the page.
This field could exist on any form within the page. Else it does nothing.*/

function setFocusField(docRef, fieldName)
{
    if (docRef!="" && fieldName!="" && docRef.forms!=null && docRef.forms.length>0)
    {
        var bSuccess = false;
        for (var i=0; i<docRef.forms.length; i++)
        {
            var formObj = docRef.forms[i];
            if (formObj!=null && formObj.elements.length>0)
            {
                for (var j=0; j<formObj.elements.length; j++)
                {
                    var fieldObj = formObj.elements[j];
                    if (fieldObj!=null && fieldObj.name==fieldName)
                    {
                        fieldObj.focus();
                        bSuccess = true;
                        break;
                    }
                }

                if (bSuccess)
                    break;
            }
        }
    }

    return true;
}
//------------------------------------------------------------------------------

/* Gets the name of the first non-empty field on the form. */

function getFocusEmptyField(formObj)
{
    var fieldToFocus="";
    if (formObj!=null && formObj.elements.length>0)
    {
        for (var j=0; j<formObj.elements.length; j++)
        {
            var fieldObj = formObj.elements[j];
            if (fieldObj!=null && fieldObj.value=='' &&
                (fieldObj.type=='text' || fieldObj.type=='select-one' ||
	         fieldObj.type=='submit' || fieldObj.type=='textarea'))
            {
                fieldToFocus = fieldObj.name;
                break;
            }
        }
    }

    return fieldToFocus;
}
//------------------------------------------------------------------------------

// changes div background colour for left menu

function swapLayerBgColor(elementID, sColor, iWidth)
{
    var objDiv;
    if (document.getElementById)
        objDiv = document.getElementById(elementID);
    else if(document.all)
        objDiv = eval("window." + elementID);
    else if (document.layers)
        objDiv = document.layers[elementID];

    if (objDiv!=null)
    {
        if (document.layers)
        {
            if (iWidth!=null && iWidth!='')
                objDiv.width = iWidth;
            objDiv.backgroundColor = sColor;
        }
        else
        {
            if (iWidth!=null && iWidth!='')
                objDiv.style.width = iWidth;
            objDiv.style.backgroundColor = sColor;
        }
    }
}
//------------------------------------------------------------------------------

// checks to see if the field has been filled in correctly.

function isBlank(field, hideAlert)
{
    if (field==null || field.value==null || field.value=="")
    {
        if (!hideAlert)
            alert("Please complete all the mandatory fields to continue.");

		return true;
    }
    else
        return false;
}
//------------------------------------------------------------------------------

// checks to see if the field value is numeric

function isNumeric(number)
{
    if (number==null || number=="")
        return true;

    var bDecimalPoint = false;
    for (var i=0; i<number.length;i++)
    {
        var c = number.charAt(i);
        if (isNaN(c))
        {
            if (c!=',' && c!='.' && c!=' ')
                return false;
            if (c=='.')
            {
                if (!bDecimalPoint)
                    bDecimalPoint = true;
                else
                    return false;
            }
        }
    }

    return true;
}
//------------------------------------------------------------------------------

// checks that the date is a valid date

function validDate(sDate)
{
    if (sDate==null || sDate=="")
        return true;

    var dateExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
    var value = sDate;
    var valid = dateExp.test(sDate);
    if (!valid)
       return false;
    else
    {
        var i1 = sDate.indexOf("-");
        var i2 = sDate.lastIndexOf("-");
        if (i1==-1)
        {
            i1 = sDate.indexOf("/");
            i2 = sDate.lastIndexOf("/");
        }
        if (i1==-1)
        {
            i1 = sDate.indexOf(".");
            i2 = sDate.lastIndexOf(".");
        }

        var day, month, year;
        if (i1!=-1 && i1!=i2)
        {
            day = sDate.substring(0,i1);
            month = sDate.substring((i1+1),i2) - 1;
            year = sDate.substr((i2+1),4);
            value = new Date(year, month, day);

            // check to see if date was changed
            if ((parseFloat(day) != value.getDate()) || (parseFloat(month) != value.getMonth()))
                return false;
        }
        else
            return false;
    }

    return true;
}
//------------------------------------------------------------------------------

// Counts how many check boxes in the form are checked

function countChecked(formObj)
{
    var total = 0;
    for (var i=0;i < formObj.length;i++)
    {
		fldObj = formObj.elements[i];
		if (fldObj.type == 'checkbox')
		{
			if (fldObj.checked == true)
			total += 1;
		}
    }
    return total;
}
//------------------------------------------------------------------------------

// checks all checkboxes on the form, or inverts all checkboxes on the form

function selectAll(formObj, isInverse)
{
   for (var i=0;i < formObj.length;i++)
   {
      fldObj = formObj.elements[i];
      if (fldObj.type == 'checkbox')
      {
	  if(isInverse)
	      fldObj.checked = (fldObj.checked) ? false : true;
	  else
	      fldObj.checked = true;
      }
   }
}
//------------------------------------------------------------------------------

/* Scroll to the section of the page named by this anchor element. */

function goToAnchor(name)
{
    for (var i=0; i<document.anchors.length; i++)
    {
        if (document.anchors[i].name == name)
        {
            var a = document.anchors[i];
            if (ns4)
                window.scrollTo(a.x, a.y);
            else
                window.scrollTo(a.offsetLeft, a.offsetTop + a.offsetParent.offsetTop);
            break;
        }
    }
}
//------------------------------------------------------------------------------

/* Clears all the elements on the form to blank, and sets checkboxes to false. */

function clearForm(formObj)
{
    if (formObj!=null && formObj.elements.length>0)
    {
        for (var j=0; j<formObj.elements.length; j++)
        {
            var fieldObj = formObj.elements[j];
            if (fieldObj!=null)
            {
                if (fieldObj.type=='checkbox')
                    fieldObj.checked=false;
                else
                    fieldObj.value='';
            }
        }
    }
}
//------------------------------------------------------------------------------

/* Substitutes the processing button with the progress bar and submits the form */

function processForm( button, imageSrc )
{
    button.src = contextPath(imageSrc);
    button.disabled = true;
}
//------------------------------------------------------------------------------

/* changes the Image source for the specified image */

function changeImage( currentSrc, newSrc )
{
    for (i = 0; i < document.images.length; i += 1)
    {
        img = document.images[i];
        offset = img.src.length - currentSrc.length;
        if (img.src.substring(offset) == currentSrc)
            img.src = centextPath(newSrc);
    }
}
//------------------------------------------------------------------------------

// -->
