// Date functions

function popDate(Title, Form, Field, Value)
{
	var win = ColdFusion.Window.getWindowObject("popdate");
	win.setTitle(Title);

	var url = "month.cfm?form=" + Form + "&field=" + Field + "&value=" + Value;
	ColdFusion.navigate(url, "popdate"); 
	ColdFusion.Window.show("popdate"); 
}

function moveDate(Form, Field, Value)
	{ 
	var url = "month.cfm?form=" + Form + "&field=" + Field + "&value=" + Value;
	ColdFusion.navigate(url, "popdate");     
	}

function pushDate(Form, Field, Value)
	{ 
	document.forms[Form].elements[Field].value = Value;
	ColdFusion.Window.hide("popdate"); 
	}

// Link functions

function popLink(Module, Form, IDField, NameField)
{
	var win = ColdFusion.Window.getWindowObject("poplink");
	var Title = pCase(Module) + " Link";
	win.setTitle(Title);

	var url = Module + "_link.cfm?form=" + Form + "&idfield=" + IDField + "&namefield=" + NameField;
	ColdFusion.navigate(url, "poplink"); 
	ColdFusion.Window.show("poplink"); 
}

function pushLink(Form, IDField, IDValue, NameField, NameValue)
{
	document.forms[Form].elements[IDField].value = IDValue;
	document.forms[Form].elements[NameField].value = NameValue;
	ColdFusion.Window.hide("poplink"); 
}

function clearLink(Form, Field)
	{
	document.forms[Form].elements[Field].value = "";
	}

// Edit functions

function popEdit(Module, ID)
{
	var win = ColdFusion.Window.getWindowObject("popedit");
//	var Title = pCase(Module) + " Link";
//	win.setTitle(Title);

	var url = Module + ".cfm?id=" + ID;
	ColdFusion.navigate(url, "popedit"); 
	ColdFusion.Window.show("popedit"); 
}

// Div functions

function HideDiv(divId)
	{
	var div = document.getElementById(divId);
	div.style.display = "none";
	}

function UnhideDiv(divId)
	{
	var div = document.getElementById(divId);
	div.style.display = "block";
	}

function toggleDisplay(divId)
	{
	var div = document.getElementById(divId);
	div.style.display = "none";
	}

// List functions

function ListAll(box)
	{
	for(var i=0; i<box.length; i++)
		{
		box[i].selected = true;
		}
	}

function ListMove(fbox, tbox)
	{
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
          arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();
     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}


function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}
}


function LinkOn(ctrl)
	{
	ctrl.style.cursor = 'hand';	
	}

// Additional functions

function pCase(s) 
{ 
	return s.replace(/(\w)(\w*)/g,function 
	( 
		strMatch, 
		strFirst, 
		strRest, 
		intMatchPos, 
		strSource 
	) 
	{ 
		return strFirst.toUpperCase() 
		+strRest.toLowerCase(); 
	}); 
} 
