
function getmonthnumber(month) {
  if(month == "January") {
    return "01";
  } else if(month == "February") {
    return "02";
  } else if(month == "March") {
    return "03";
  } else if(month == "April") {
    return "04";
  } else if(month == "May") {
    return "05";
  } else if(month == "June") {
    return "06";
  } else if(month == "July") {
    return "07";
  } else if(month == "August") {
    return "08";
  } else if(month == "September") {
    return "09"; 
  } else if(month == "October") {
    return "10";
  } else if(month == "November") {
    return "11";
  } else if(month == "December") {
    return "12";
  } 
  
}

		function goBack(where) {
			/*window.location.href = tmp + (tmp.indexOf("?") > 0 ? '&' : '?') + 'b=1';*/
			if (historylen > 0) {
				var tmp = window.location.href;
				window.location.href = tmp + (tmp.indexOf("?") > 0 ? '&' : '?') + 'b=1';
			} else {
				window.location.href = admin_basedir;
			}
			return false;
		}


function getAgeFromBday(dob) {
  var str = dob.split(" ");	
  var day = str[1];
  var monthl = str[2].length - 1;
  var month = getmonthnumber(str[2].substr(0,monthl));
  var year = str[3];


  var bdate = new Date(year, month, day);

  //if ((bdate.getDate() != day) || (bdate.getMonth() != month) || (bdate.getFullYear() != year)) {
  //  alert('That date appears to be invalid!');
  //  return false;
  //}

  var today = new Date();
  today.setHours(0);
  today.setMinutes(0);
  today.setSeconds(0);
  if (bdate > today) {
    alert('Provided date must fall before today\'s date!');
    return false;
  }
  
  document.getElementById('form_age').value = Math.floor((today - bdate) / 31556952000);

}


function callIFrame(id, url, iframeid, value2) {
  var url = url;
  var id = id;
  var iframeid = iframeid;
  var value2 = value2;
  document.getElementById(iframeid).src = url + "?id=" + id + "&value2=" + value2;
}

//onChange=\"callIFrame(this.value, '/ajax/getcarerdetails.php', 'carerdetails');
function showCareRecipientDetails(id, url, iframeid, value2) {
  var url = url;
  var id = id;
  var iframeid = iframeid;
  var value2 = value2;
  document.getElementById(iframeid).src = url + "?id=" + id + "&value2=" + value2;
}



  function popup(URL) {

      var features =
        'width='        + '640' +
        ',height='      + '480' +
        ',directories=' + 'no' +
        ',location='    + 'no' +
        ',menubar='     + 'no' +
        ',scrollbars='  + 'yes' +
        ',status='      + 'yes' +
        ',toolbar='     + 'no' +
        ',Resizable='  + 'yes';
      info = window.open (URL, "uploadRev", features);
}

  function confirmSend(recipientList,numFiles) {
    if(recipientList) {
      return confirm("Do you wish to send " + numFiles + " file(s) to the following recipients:\r\n\r\n" + recipientList);  
    } else {
      alert("Please select one or more recipients");
      return false; 
    }    
    return false;  
    
  }
  
  function addRecipient(recipient,recFieldName) {
    recListField = document.getElementById(recFieldName);
    if(recListField.value) {
      recListField.value += "; " + recipient;
      document.form.form_findrecipient.value = "";
    } else {
      recListField.value = recipient;
      document.form.form_findrecipient.value = "";
    }
    return false;
    
  }
  
  function resetSearch(fieldID,fieldValue) {
    fID = document.getElementById(fieldID);
    fID.value = "";
    fValue = document.getElementById(fieldValue);
    fValue.value = "";
  } 
  
	function lookup(suggestName,inputString,tableName,fieldName) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
							$('#suggestions').hide();
		} else {
			$.post("/ajax/index.php?suggestName=" + suggestName + "&tableName=" + tableName + "&fieldName=" + fieldName + "&queryString=" + inputString, function(data){
				if(data.length >0) {
					$('#' + suggestName).show();
					$('#' + suggestName + '_list').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue,suggestField) {
    $('#inputString').val(thisValue);
    if(suggestField) {					
      setTimeout("$('#' + suggestField).hide();", 200);
    }
	}
	
	function suburbLookUp(suburb) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
							$('#' + suggestField).hide();
		} else {
			$.post("/ajax/index.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
//				  alert(suggestField);
					$('#' + suggestField).show();
					$('#' + suggestField).html(data);
				}
			});
		}
	} // lookup
	
function sb_action(src_id, dest_id, all) {
			var src  = document.getElementById(src_id);
			var dest = document.getElementById(dest_id);
			var opt;

			if (src.options.length > 0) {
				for (var i=0; i<src.options.length; i++) {
					if (all == 1 || src.options[i].selected == true) {
						opt = new Option;
						opt.value = src.options[i].value;
						opt.text = src.options[i].text;

						dest.options[dest.options.length] = opt;
						src.options[i] = null;
						i--;
					}
				}
			}
		}

		function sb_onsubmit(box_id) {
			var src  = document.getElementById(box_id);
			if (src.disabled == true) {
				src.disabled = false;
			}

			if (src.options.length > 0) {
				for (var i=0; i<src.options.length; i++) {
					src.options[i].selected = true;
				}
			}

		}
	
	
	function formSubmit() {
  var formobj=document.getElementById("htmlformelement");
  var elements=formobj.elements;
  formElements = document.htmlformelement.length;
  for(var i=0; i < formElements; i++) {
    elements[i].disabled=false;
  }
  var frmelem = ''
  if (arguments.length == 1) {
    frmelem = arguments[0];
  } else {
    frmelem = frm;
  }
  sb_onsubmit('form_groups[]');  return true;
}


function retagNull(formField,retagAjax) {
	checkField = document.getElementById("retag_" + formField);
	textField = document.getElementById(formField);
	if(checkField.checked) {
		if(confirm("This will remove any existing values for this field")) {
			textField.value = "";
			textField.disabled = 1;	
			if(retagAjax) {
				ajaxField = document.getElementById(formField + "_val");
				ajaxField.value = "";
			}	
		} else {
			checkField.checked = 0;
		}	
	} else {
		textField.disabled = 0;
	}
}


function updateReqd(fieldName,value) {  
  /*currRow = document.getElementById("row_" + fieldName);  
  if(value) {
    currRow.setAttribute("class","requiredNotEmpty");
  } else {
    currRow.setAttribute("class","requiredEmpty");
  }*/
}



 function sameAs() {
  	document.form.form_currentstreet.value = document.form.form_usualstreet.value;
  	document.form.form_currentsuburb.value = document.form.form_usualsuburb.value;
  	document.form.form_currentpostcode.value = document.form.form_usualpostcode.value;
  	document.form.form_currentstate.selectedIndex = document.form.form_usualstate.selectedIndex;
  	document.form.form_currentlga.value = document.form.form_usuallga.value;
//  	document.form.form_currentstd.value = document.form.form_usualstd.value;
//  	document.form.form_currentphone.value = document.form.form_usualphone.value;
}


function updateBuffer(formID) {

  content = $('#' + formID).serialize();
  bufferFrame = document.getElementById('buffer');
  bufferFrame.src =  "OK"; 
  var windowURL = window.location;
  if(!windowURL) var windowURL = parent.document.location.href;

  bufferFrame.src = "/buffer.php?title=" + window.document.title + "&url=" + windowURL + "&" + content;
}

function rowSwitch(rowName,newMode) {
  thisRow = document.getElementById(rowName);
  if(newMode == "on") {
    thisRow.style.backgroundColor = "#FAE003";
  } else {
    thisRow.style.backgroundColor = "inherit";
  }
}


function gotoPage(url) {
  window.location = url;
}
