function loginwindow()
{
	newwindow('/intranet/menu.fwx','menu_staff','top=0,left=0,width=950,height=700')
}

function trustloginwindow()
{
	newwindow('/trusts/menu.fwx','menu_trust','top=0,left=0,width=800,height=700,status,resizable,scrollbars','true')
}

function locumloginwindow()
{
	newwindow('/locums/menu.fwx','menu_locum','top=0,left=0,width=800,height=700,status,resizable,scrollbars','true')
}
function newwindow(url,target,windowproperties,forceurl) {
	cwindowproperties = ""
	if (windowproperties!="undefined")
		{cwindowproperties=windowproperties}
	if (forceurl == "undefined")
		{forceurl = false}

	whandle = window.open("",target,cwindowproperties)

	if( whandle.location.href == "about:blank" || forceurl == true)
	{
	whandle.location.replace( url );
	}
	whandle.focus()
}

function datepicker(id,justday) {
	cdate = eval('document.form.'+id+'.value');
	newwindow("datepicker.fwx?ID="+id+"&date="+cdate+"&justday="+justday,"datepicker","height=180,width=220");
}

function datepicker_return(cData,id) {
	eval('document.form.'+id+'.value = cData');
}

function find_trust(id,id2) {
	newwindow("trust_find.fwx?popup=yes&ID="+id+"&ID2="+id2,"trustfind","left=0,top=0,scrollbars,resizable,width=560,height=700");
}

function accounts_find_trust(id,id2) {
	newwindow("accounts_trust_find.fwx?popup=yes&ID="+id+"&ID2="+id2,"trustfind","left=0,top=0,scrollbars,resizable,width=560,height=700");
}

function find_trust_return(ref,name,id,id2) {
	eval('document.form.'+id+'.value = ref');
	eval('document.form.'+id2+'.value = name');
}

function find_locum(id,id2) {
	newwindow("locum_find.fwx?popup=yes&ID="+id+"&ID2="+id2,"locumfind","left=0,top=0,scrollbars,resizable,width=560,height=700");
}

function accounts_find_locum(id,id2) {
	newwindow("accounts_locum_find.fwx?popup=yes&ID="+id+"&ID2="+id2,"locumfind","left=0,top=0,scrollbars,resizable,width=560,height=700");
}

function find_locum_all(id,id2) {
	newwindow("locum_find_all.fwx?popup=yes&ID="+id+"&ID2="+id2,"locumfind","left=0,top=0,scrollbars,resizable,width=560,height=700");
}

function filledbylocum(id,id2,positionid) {
	newwindow("positions_filledby.fwx?popup=yes&ID="+id+"&ID2="+id2+"&PositionID="+positionid,"locumfind","left=0,top=0,scrollbars,resizable,width=560,height=700");
}

function find_locum_return(ref,name,id,id2) {
	eval('document.form.'+id+'.value = ref');
	eval('document.form.'+id2+'.value = name');
}

function resetfilter() {
	document.form.method.value = "reset";
	document.form.submit();
}

function positions_filter_cleartrust() {
	document.form.method.value = "cleartrust";
	document.form.submit();
}

function formvalidate(){
	return true;
}

function formsave() {
	if (formvalidate()==true){
	document.form.method.value = "save";
	document.form.submit();
	}
}

function formview() {
	if (formvalidate()==true){
	document.form.method.value = "view";
	document.form.submit();
	}
}

function formcancel() {
	document.form.method.value = "cancel";
	document.form.submit();
}

function formrestore() {
	document.form.method.value = "restore";
	document.form.submit();
}

function formsubmit(cObjectName,cValue) {
	eval('document.form.'+cObjectName+'.value = cValue');
	document.form.submit();
}

function formsubmitwithvalidate(cObjectName,cValue) {
	if (formvalidate()==true){
	eval('document.form.'+cObjectName+'.value = cValue');
	document.form.submit();
	}
}

function formforward() {
	if (formvalidate()==true){
	if (confirm("This will mark all selected locums as having been forwarded?") == true)
	{document.form.method.value = "forward";
	document.form.submit();
	}}
}

function formtrustpositionfill() {
	if (confirm("This will mark this position as being filled by you?") == true)
	{document.form.method.value = "filled";
	document.form.submit();
	}
}

function formsendemailalerts() {
	if (formvalidate()==true){
	if (confirm("This will send all selected locums a EMAIL alert?") == true)
	{document.form.method.value = "emailalert";
	document.form.submit();
	}}
}

function formsendsmsalerts() {
	if (formvalidate()==true){
	if (confirm("This will send all selected locums a SMS alert?") == true)
	{document.form.method.value = "smsalert";
	document.form.submit();
	}}
}

function formsendtosuppliers() {
	if (confirm("This will send this position to all secondery suppliers?") == true)
	{document.form.method.value = "sendtosuppliers";
	document.form.submit();
	}
}

function formconfirm() {
	if (formvalidate()==true){
	document.form.method.value = "confirm";
	document.form.submit();
	}
}

function registrationsavepage() {
	if (formvalidate()==true){
	document.form.method.value = "save";
	document.form.submit();
	}
}

function formupload() {
	if (formvalidate()==true){
	change_object_stat('UploadLayer','visibility','hidden');
	change_object_stat('PleaseWaitLayer','visibility','visible');
	document.form.submit();
	}
}

function formset() {
	if (formvalidate()==true){
	document.form.method.value = "set";
	document.form.submit();
	}
}

function formsend() {
	if (formvalidate()==true){
	document.form.method.value = "send";
	document.form.submit();
	}
}

function timesheetprocess() {
	if (confirm("This will stop users from entering timesheets into this pay period?") == true)
	{document.form.method.value = "process";
	document.form.submit();
	}
}

function timesheetlockdown() {
	if (confirm("This will lock these timesheets down?") == true)
	{document.form.method.value = "lockdown";
	document.form.submit();
	}
}

function parentrefresh() {
	opener.location.reload( true );
}

function refresh() {
	window.location.reload( true );
}

function formreset() {
	document.form.reset();
}

function passwordreset() {
	if (confirm("This will reset the password to its system default?") == true)
	{document.form.method.value = "reset";
	document.form.submit();
	}
}

function formdelete() {
	if (confirm("This will delete the current record?") == true)
	{document.form.method.value = "delete";
	document.form.submit();
	}
}

function formmultidelete() {
	if (confirm("This will delete all selected records?") == true)
	{document.form.method.value = "delete";
	document.form.submit();
	}
}

function showalert(cmessage){
	alert(cmessage);
}

function listbox_moveitem(clistboxfrom,clistboxto){
  olistboxfrom = eval("document.form."+clistboxfrom);
  olistboxto = eval("document.form."+clistboxto);
  if (olistboxfrom.selectedIndex != -1)
  {
    var strtext = new String(olistboxfrom.options[olistboxfrom.selectedIndex].text);
    var strvalue = new String(olistboxfrom.options[olistboxfrom.selectedIndex].value);

    var newItem = new Option();
    newItem.text=strtext.substr(0);
    newItem.value=strvalue.substr(0);
    olistboxto.options[olistboxto.options.length]=newItem;
    olistboxfrom.options[olistboxfrom.selectedIndex]=null;

    olistboxfrom.selectedIndex=-1;
    olistboxto.selectedIndex=-1;
   }else
	{
	alert('Please select from the list');
    return;
	}
}

function fillhiddenlistboxvalues(clistbox,chiddenfield){
 olistbox = eval("document.form."+clistbox);
 ohiddenfield = eval("document.form."+chiddenfield);
 n = olistbox.options.length;
 ncomma = 0
 cstring = ""

 for (var lintAvail=0; lintAvail < n; lintAvail++)
  {
	if (olistbox.options[lintAvail].value != "")
	{
		if (ncomma == 1) 
			{cstring += ","}
		cstring += olistbox.options[lintAvail].value;}
		ncomma = 1;
  }
ohiddenfield.value = cstring;

}

function listbox_remove(clistbox){
  olistbox = eval("document.form."+clistbox)

  var numItems = 0;
  var srcLen = olistbox.options.length;

  if(olistbox.selectedIndex == -1)
  {
    alert('Please, select from the list');
    return;
  } 
    
  olistbox.options[olistbox.selectedIndex]=null;

}

function listbox_add(clistbox,ctextbox){
  olistbox = eval("document.form."+clistbox);
  otextbox = eval("document.form."+ctextbox);

  var strtext = new String(otextbox.value);
  var strvalue = new String(otextbox.value);

  if (strvalue=="") return;

  var newItem = new Option();
  newItem.text=strtext.substr(0);
  newItem.value=strvalue.substr(0);
 
  olistbox.options[olistbox.options.length]=newItem;
  otextbox.value = "";

  olistbox.selectedIndex=olistbox.options.length-1;
}

function span_mouseover(objRow) {
	objRow.style.color = "#c70b27";
}

function span_mouseout(objRow) {
	objRow.style.color = "#3a2a7d";
}

function span_click(link) {
	document.location.href = link;
}

function change_object_stat(objectname,propertyname,newvalue) {
	eval("document.getElementById('"+objectname+"').style."+propertyname+" = '"+newvalue+"'")
}

function closeallwindows() {
	whandle = window.open("","trusts","left=0,top=0,width=10,height=10")
	whandle.close()
	whandle = window.open("","locums","left=0,top=0,width=10,height=10")
	whandle.close()
	whandle = window.open("","registragtions","left=0,top=0,width=10,height=10")
	whandle.close()
	whandle = window.open("","reports","left=0,top=0,width=10,height=10")
	whandle.close()
	whandle = window.open("","maintenance","left=0,top=0,width=10,height=10")
	whandle.close()
	whandle = window.open("","accounts","left=0,top=0,width=10,height=10")
	whandle.close()
	whandle = window.open("logout.fwx","menu_staff","width=950,height=700,top=0,left=0 ")
}

function comparedates(date1,date2) {
	datefrom = new Date(date1.substr(6,4),date1.substr(3,2),date1.substr(0,2));
	dateto = new Date(date2.substr(6,4),date2.substr(3,2),date2.substr(0,2));

	if (datefrom>dateto)
		{return false;}
	return true;
}

function optionchange(oObject) {

	return true;
}

function getselectedradio(buttonGroup) {
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i < buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
}