function validNull(isthisnull){
	if (isthisnull == ""){
		return false;
	}
	return true;
}

function submitRequest(Update_Request){

	// State
	if (Update_Request.Edited_State.selectedIndex == -1){
		alert("Please select a State or Territory");
		Update_Request.Edited_State.focus();
		return false;
	}

	// Suburb
	if (!validNull(Update_Request.Edited_Suburb.value)){
		alert("Please enter suburb");
		Update_Request.Edited_Suburb.focus();
		return false;
	}

	//Postcode
	if (!validNull(Update_Request.Edited_Postcode.value)){
		alert("Please enter Postcode");
		Update_Request.Edited_Postcode.focus();
		return false;
	}

	//Treatment types
	if (Update_Request.Edited_TreatmentTypes.selectedIndex == -1){
		alert("Please Select a Treatment Type");
		Update_Request.Edited_TreatmentTypes.focus();
		return false;
	}

	//Service Sector
	if (Update_Request.Edited_SectorOfService.selectedIndex == -1){
		alert("Please Select a Service Sector");
		Update_Request.Edited_SectorOfService.focus();
		return false;
	}

	//Funding Source
	if (Update_Request.Edited_FundingSource.selectedIndex == -1){
		alert("Please Select a Funding Source");
		Update_Request.Edited_FundingSource.focus();
		return false;
	}
	
	return true;
}

// Author: Wisnu Hadi Prawoto (IBM SWGS)
// Date:	16/08/2002
// Update : Tony Palmer (IBM SWGS) Date 4/10/02 - Updated AlertBox Function
// Update : Dolph Page  (DoHA)     Date 8/04/03 - Added repeat() and pad() functions
// Update : Dolph Page  (DoHA)     Date 3/09/03 - Added textArea zoom Popup functions

var fieldlst;
var getBday, getBmonth, getByear;

function isLetter(theChar) {
    if ( (theChar >= "a" && theChar <= "z") ||  (theChar >= "A" && theChar <= "Z"))  return true;
    else return false;
}

function isNumber(theChar) {
    if (theChar >= "0" && theChar <= "9") return true;
    else return false;
}

function getField(theStr) {
var z, zz;
z = theStr.indexOf(";");

if (z >0)  {
     zz = theStr.substring(0, z);
     fieldlst = theStr.substring(z + 1, theStr.length);
}
else { 
     zz = theStr;
     fieldlst = "";
}
return zz;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function submitForm() {
    var form = parent.document.forms[0];
     form.submit();
    
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function selectItem ( SelectBox, SelectText ){
	SelectBox.selectedIndex = 0;  //  Default setting is always the first item in the list.
	for (var i = 0; i < SelectBox.options.length; i++) {
		if (SelectBox.options[i].text == SelectText ) SelectBox.selectedIndex = i;
	}	
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function getFieldValue ( theField, vType ) {
  theValue = "";
  sep = "";
  hits = 0;

  //text is the user-entered value as a string
  if ( vType == "text" ) return ( theField.value );

  //textarea is the user-entered value as a string array of one element
  if ( vType == "textarea" )     return ( theField.value );

/*
  //checkboxes & radio buttons are not so simple
  if ( vType == "checkbox" || vType =="radio" ) {

      if ( theField.value == null ) {

      //if we're here, we are validating a radio button or a nn multi-element checkbox
           for ( i = 0; i < theField.length; i++ ) {
               if ( theField[i].checked ) {
                   hits++;
                   if ( hits > 1 ) {
                       sep = "; ";
                    }
                    theValue += sep + theField[i].value;
               }
           }
       }

    else {

   //if we are here, must be an ie checkbox, or nn with a one-element checkbox
          //nn one-element checkbox, see if its checked ...
           if (theField.checked ) {
                return ( theField.value );
           } else {
             return ( "" );
           }
    }   

    return ( theValue );
   }
*/

   if ( vType == "checkbox" || vType == "radio" ) {
       for ( i = 0; i < theField.length; i++ ) {
           if ( theField[i].checked ) {
               if ( theValue != "" ) theValue += ","
               theValue += theField[i].value;
           }
       }
    }

   if ( vType == "select" ) {
       for ( i = 0; i < theField.options.length; i++ ) {
           if ( theField.options[i].selected ) {
               if ( theValue != "" ) theValue += ","
               theValue += theField.options[i].text;
           }
       }
    }

   return ( theValue );
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//alertBox FUNCTION
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function alertBox (vField, vMessage, vType ) {
  alert ( vMessage );

  if ( vType == "text" ) {
     vField.focus();
     vField.select();
  } else {
               vField.focus();
             
     } // end else text
  return;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function failNull( vField, vMessage, vType) {
  theValue = getFieldValue (vField, vType);
  if ( theValue == "" ) {
    alertBox ( vField, vMessage, vType );
    return ( true );
  }
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function failContains( vField, vValue, vMessage, vType ) {
  theValue = getFieldValue (vField, vType);
  var count = ( failContains.arguments.length == 6 ) ? vValue.length-1 : 0;
  var value = ( failContains.arguments.length == 6 ) ? vValue.substring(0,1) : vValue;

  for ( i = 0; i <= count; i++) {
    if ( theValue.indexOf(value) > -1) {
    alertBox ( vField, vMessage, vType );
    return (true);
    }
    value = ( count > 0 ) ? vValue.substring(i+1,i+2) : vValue;
  }
   
  //otherwise continue...
  return (false)
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function trimBlanks ( theString, repChar ) {
//this function replaces the spaces in a string with the provided character
trimString="";
 for ( i = 0; i < theString.length; i++) {
  theChar=theString.substring ( i, i+1);
  if ( theChar == " ") {
   trimString += repChar
  } else {
   trimString+=theString.substring ( i, i+1);
  }
 }
 return (trimString);
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function isDate(inputStr)
{
	count = 0;
	counter = 0;
	tempstr = inputStr;
	for (var i = 0; i < inputStr.length; i++)
		if (inputStr.substring(i, i + 1) == "/")
			counter ++;		
	for (var i = 0; i < 2; i++)
	{
		strlen = inputStr.length;
		position = inputStr.indexOf("/", i);
		if (i == 0)
			sday = inputStr.substring(0, position);
		if (i == 1)
		{
			smonth = inputStr.substring(0, position );
			syear = inputStr.substring(position + 1, strlen);
		}
		inputStr = inputStr.substring(position + 1, strlen);
	}
	if (sday > 31)
		return false;
	if((parseInt(sday, 10) > 0) && (parseInt(sday, 10) < 32))
	{
		if((smonth == 2) && (parseInt(sday, 10) > 29))
			return false;
		else if (((smonth == 4) || (smonth == 6) || (smonth == 9) || (smonth == 11)) && (sday > 30))
			return false;
		else if (smonth > 12)
			return false;
	getBmonth = smonth;

	}
	if (counter != 2)
		return false;
                getBday = sday;
	inputStr = tempstr;
 
	for (var i = 0; i < inputStr.length; i++)
	{
		var oneChar = inputStr.substring(i, i + 1);
                          	if ((oneChar < "0" || oneChar > "9") && oneChar != "/" )
			return false;
		// check month
		if (oneChar == "/" && count == 0)
		{
			month = inputStr.substring(i+1, i + 2);

			// check month > 12
			if (month > 1 && inputStr.substring(i+2, i + 3) != "/")
				return false;
			if (month == 1 && inputStr.substring(i+2, i + 3) > 2)
				return false;
			if (month == 0 && inputStr.substring(i+2, i + 3) == "/")
				return false;
			count ++;
		
		}		
	}

	var sChar1 = inputStr.substring(inputStr.length, inputStr.length - 1);
	var sChar2 = inputStr.substring(inputStr.length - 1, inputStr.length - 2);
	var sChar3 = inputStr.substring(inputStr.length - 2 , inputStr.length - 3)	;
	var sChar4 = inputStr.substring(inputStr.length - 3, inputStr.length - 4);
                var sChar5 = inputStr.substring(inputStr.length - 4, inputStr.length - 5);
                 
                if (sChar5 != "/") {
	return false;
                }
                getByear = sChar4+ sChar3 + sChar2 + sChar1;

	if( (sChar1 >= "0" && sChar1 <= "9")  && (sChar2 >= "0" && sChar2 <= "9")  && (sChar3 >= "0" && sChar3 <= "9") && sChar4 == "/" )
		return false;
	if( (sChar1 >= "0" && sChar1 <= "9")  && (sChar2 >= "0" && sChar2 <= "9")  && sChar3 == "/" )
		return false;
	if( (sChar1 >= "0" && sChar1 <= "9")  && sChar2 == "/" )
		return false;

	return true;
}

function appendUrl(path) {			
	var z = parent.location.href.indexOf(".nsf");
	var zz = parent.location.href.substring(0, z + 4) + "/" + path;
	return zz; 
}

function checkToday() {

var errors
var errorMessage
invalidDate = "False"
errors = 0
var today = new Date()
todayDay = today.getDate()
todayMonth = today.getMonth() + 1

if(navigator.appName == "Netscape"){
	todayYear = today.getYear() + 1900
	}
else{
	todayYear = today.getYear()
	}

todayYear = parseInt(todayYear);
todayMonth = parseInt(todayMonth);
todayDay = parseInt(todayDay);
getBday = parseInt(getBday);
getBmonth = parseInt(getBmonth);
getByear = parseInt(getByear);

if(getByear > todayYear){
	errorMessage = "tYou can't enter a date after today!"
	alert("The year of your birthday is greater than this year.")
                invalidDate = "True"
	return false
	}

if(getByear == todayYear && getBmonth > todayMonth){
	errorMessage = "The month of your birthday is greater than this month"
	alert(errorMessage)
                invalidDate = "True"
                return false
	}
if(getByear == todayYear && getBmonth == todayMonth && getBday > todayDay){
	errorMessage = "The day of your birthday is greater than today"
                alert(errorMessage)
                invalidDate = "True"
	return false
}
}

function repeat(schar, times) {
	ans = "";
	for (var i = 0; i < times; i++) {
		ans += schar;
	}
	return ans;
}

function pad(times, schar, svalue) {
	//check if values requires padding
	if (svalue.length >= times) return svalue;
	spads = repeat(schar, times);
	var padded = spads + svalue;
	//alert(padded);
	
	ans = "";

	if (padded != spads) {
		for (var i = 0; i < times; i++) {
			schar = padded.substr(padded.length + i - times, 1);
			ans += schar;
			//alert("ans = " + ans);
		}
	}
	return ans;
}





//=================Text Area Zoom Popup Functions===============================
// This global variable holds a reference to the active textbox
// that is being edited. This is set in the openZoomWindow
// function.
var globalTextArea;
/*
openZoomWindow(textarea);
This function opens up the zoom window (provided 
one isn't already open) and sets the global variable 
globalTextArea to reference the textarea in the 
HTML based upon the name of the textarea passed in.
*/
function openZoomWindow(textarea, popupFile) {
    
    // Only allow one window open at a time
    if (globalTextArea != null) {
        alert('There is already a zoom window open. ' +
        'You may only open one zoom window at a time');
        return; 
    } else {
        globalTextArea = textarea;
        //alert(globalTextArea);
        //alert(popupFile);
        // Open the child window
        var props = 'scrollBars=yes,resizable=yes,toolbar=no,' + 
        'menubar=no,location=no,directories=no,width=700,height=500';
        newWindow = window.open(popupFile, "zoom", props);
    }
    
}

/*
assignValueToTextArea(zoomTaValue, saveChanges)
If saveChanges is true, this function assigns the value 
of the textarea in the child window to the textarea that's 
referenced in the global variable globalTextArea. If it's 
false, the original value is left in place.
*/

function assignValueToTextArea(zoomTaValue, saveChanges) {
    
    // Assign the text in the zoom window to the textarea
    // if saveChanges is true
    if (saveChanges == true) {
        globalTextArea.value = zoomTaValue;
    }
    
    // Unassign the global variable so that other windows can be 
    // opened
    if (globalTextArea) {
        globalTextArea = null;
    }
}
