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.01
  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 && d.getElementById) x=d.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];}
}

function showLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.visibility = "visible";
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.visibility = "visible";
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].visibility = "visible";
	}
}

function hideLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.visibility = "hidden";
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.visibility = "hidden";
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].visibility = "hidden";
	}
}

function hideLayerDisplay(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.display = "none";
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichlayer].style.display = "none";
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].display = "none";
	}
}

function toggleDisplay(elementID) {
	if (document.getElementById) {
		// this is the way the standards work
		if (document.getElementById(elementID).style.display == "none")
		{
			document.getElementById(elementID).style.display = "inline";	
		}
		else {
			document.getElementById(elementID).style.display = "none"
		}
	}
	else if (document.all) {
		// this is the way old msie versions work
		if (document.all[elementID].style.display == "none")
		{
			document.all[elementID].style.display = "inline";	
		}
		else {
			document.all[elementID].style.display = "none"
		}
	}
	else if (document.layers) {
		// this is the way nn4 works
		if (document.layers[elementID].display == "none")
		{
			document.layers[elementID].display = "inline";	
		}
		else {
			document.layers[elementID].display = "none"
		}
	}
}

function validateform(myform) {
	var elementname;						// name attribute
	var elementvalue						// value attribute
	var valid = true;						// becomes false when any error is encountered
	var errData = "";						// names of bad Data fields
	var errReq = "";						// names of missing required fields
	var id, arrid;							// array with contents of form element's id attribute
	var req;								// temp variable for required field check
	var friendly;							// friendly field name string
	var datatype;							// data type, string, eg txt, num, eml, dte
	var strError = "";
	var iTmp1;
	var sTmp1;
	var sTmp2;
	var sTmp3;
	var arremail;
	var bgColor="#D6E4EF"
	for (j = 0; j < myform.elements.length; j++) {
		
		elementname = myform.elements[j].name;
		elementvalue = myform.elements[j].value;
		
		req = false;
		friendly = "";
		datatype = "";
		
		// check for an id attribute, and draw out friendly name, etc.
		if (myform.elements[j].id != "") {
			id = myform.elements[j].id;
			arrid = id.split(",")
			friendly = arrid[0];
			if (parseInt(arrid[1])) req = true;
			datatype = arrid[2];
		}

		// reset borders in case they were already highlighted
		//myform.elements[j].style.borderWidth = "";
		//myform.elements[j].style.borderStyle = "";
		//myform.elements[j].style.borderColor = "";
		myform.elements[j].style.backgroundColor = "";

		// check for invalid data type if type was specified and field is not blank
		// as this will be handled later.
		if ((datatype != "") && !(elementvalue == "")) { 
			if (datatype == "num") {
				elementvalue = elementvalue.replace("$", "");
				elementvalue = elementvalue.replace(",", "");
				if (isNaN(elementvalue)) {
					valid = false;
					errData += " -  " + friendly + " must be numeric.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
			}
			if (datatype == "num+") {
				elementvalue = elementvalue.replace("$", "");
				elementvalue = elementvalue.replace(",", "");
				if (isNaN(elementvalue)) {
					valid = false;
					errData += " -  " + friendly + " must be numeric.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
				else if (parseFloat(elementvalue) <= 0) {
					valid = false;
					errData += " -  " + friendly + " must be a positive number.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
			}
			if (datatype == "int") {
				elementvalue = elementvalue.replace("$", "");
				elementvalue = elementvalue.replace(",", "");
				if (isNaN(elementvalue) || (parseInt(elementvalue) != parseFloat(elementvalue))) {
					valid = false;
					errData += " -  " + friendly + " must be a whole number.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
			}
			if (datatype == "int+") {
				elementvalue = elementvalue.replace("$", "");
				elementvalue = elementvalue.replace(",", "");
				if (isNaN(elementvalue) || (parseInt(elementvalue) != parseFloat(elementvalue))) {
					valid = false;
					errData += " -  " + friendly + " must be a positive whole number.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
				else if (parseFloat(elementvalue) <= 0) {
					valid = false;
					errData += " -  " + friendly + " must be a positive whole number.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
			}
			if (datatype == "dte") {
				if (isNaN(Date.parse(elementvalue))) {
					valid = false;
					errData += " -  " + friendly + " must be a valid date.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
			}
			if (datatype == "eml") {
				// put into an array to enable test for multiple email addresses
				arremail = elementvalue.split(",")
				for (var loop=0; loop < arremail.length; loop++) { 
					// new and improved RegExp
					myRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (arremail[loop].search(myRegExp) == -1  && arremail[loop] !='') {
						valid = false;
						errData += " -  " + friendly + " has an invalid e-mail address:'" + arremail[loop] + "'\n";
						if (loop > 0) {
							errData += "    (separate multiple addresses with ',')\n";
						}
						// highlight this problem field
						myform.elements[j].style.backgroundColor = bgColor; 
					}
				} 
			}
			if (datatype == "phone") {
				elementvalue = elementvalue.replace("(", "");
				elementvalue = elementvalue.replace(")", "");
				elementvalue = elementvalue.replace(/[\s]+/g, "");
				if (isNaN(elementvalue)) {
					valid = false;
					errData += " -  " + elementvalue + " has an invalid format.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
				else if (parseFloat(elementvalue) <= 0) {
					valid = false;
					errData += " -  " + friendly + " must be a positive number.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
			}
			if (datatype == "tme") {
  				iTmp1 = elementvalue.indexOf(":") 
  				if (iTmp1 == -1) { 
					valid = false;
					errData += " -  " + friendly + " must be a valid time.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = bgColor; 
				}
  				else { 
					sTmp1 = elementvalue.substr(0 , iTmp1) 
					sTmp2 = elementvalue.substr(iTmp1 + 1, 2) 
					sTmp3 = elementvalue.substr(iTmp1 + 4, 2) 
					sTmp4 = elementvalue.substr(iTmp1 + 7)
  				  	if (!((!isNaN(sTmp1)) && (!isNaN(sTmp2)) && (!isNaN(sTmp3)) && (sTmp1>=0) && (sTmp1<24) && (sTmp2>=0) && (sTmp2<60) && (sTmp3>=0) && (sTmp3<60))) {
						valid = false;
						errData += " -  " + friendly + " must be a valid time.\n";
						// highlight this problem field
						myform.elements[j].style.backgroundColor = bgColor; 
					}
				} 
			}
		}
		// check for required field being blank
		if (req && (elementvalue == "")) {
			valid = false;
			errReq += " -  " + friendly + " is required.\n";
			// highlight this problem field
			myform.elements[j].style.backgroundColor = bgColor; 
		}
	}

	if (!valid) {	// if an error occurred, generate the error report display
		
		strError = "The data in these fields are invalid:\n\n"
		if (errReq != "") strError += errReq;
		if (errData != "") strError += errData;
		strError += "\nThe fields requiring attention have been highlighted.\n";
		
		alert(strError);
	}

	return valid;
}


if(!window.Node){
	var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}
function checkNode(node, filter){
	return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}
function getChildren(node, filter){
	var result = new Array();
	var children = node.childNodes;
	for(var i = 0; i < children.length; i++){
		if(checkNode(children[i], filter)) result[result.length] = children[i];
	}
	return result;
}
function getChildrenByElement(node){
	return getChildren(node, "ELEMENT_NODE");
}
function getFirstChild(node, filter){
	var child;
	var children = node.childNodes;
	for(var i = 0; i < children.length; i++){
		child = children[i];
		if(checkNode(child, filter)) return child;
	}
	return null;
}
function getFirstChildByText(node){
	return getFirstChild(node, "TEXT_NODE");
}
function getNextSibling(node, filter){
	for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
		if(checkNode(sibling, filter)) return sibling;
	}
	return null;
}
function getNextSiblingByElement(node){
	return getNextSibling(node, "ELEMENT_NODE");
}

var activeMenu = null;

function showMenu(){
	if(activeMenu){
		activeMenu.className = "";
		getNextSiblingByElement(activeMenu).style.display = "none";
	}
	if(this == activeMenu){
		activeMenu = null;
	}else{
		this.className = "active";
		getNextSiblingByElement(this).style.display = "block";
		activeMenu = this;
	}
	return false;
}
function initMenu(){
	var menus, menu, text, a, i;
	menus = getChildrenByElement(document.getElementById("expand_menu"));
	for(i = 0; i < menus.length; i++){
		menu = menus[i];
		text = getFirstChildByText(menu);
		a = document.createElement("a");
		menu.replaceChild(a, text);
		a.appendChild(text);
		a.href = "javascript:;";
		a.onclick = showMenu;
		a.onfocus = function(){this.blur()};
	}
}

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function openBrWindow(theURL,winName,features) { //v2.0
	winName = window.open(theURL,winName,features);
	winName.focus()
}

function cFont(toValue){
    var allDivs=document.getElementsByTagName("DIV");
    for (i=0;i<allDivs.length;i++){
		if (toValue=="smaller")
		{
			if (allDivs[i].className=="small")
			{
				allDivs[i].className="small"
			}
			if (allDivs[i].className=="medium")
			{
				allDivs[i].className="small"
			}
			if (allDivs[i].className=="large")
			{
				allDivs[i].className="medium"
			}
		}
		if (toValue=="larger")
		{
			if (allDivs[i].className=="large")
			{
				allDivs[i].className="large"
			}
			if (allDivs[i].className=="medium")
			{
				allDivs[i].className="large"
			}
			if (allDivs[i].className=="small")
			{
				allDivs[i].className="medium"
			}
		}
    }
} 

function ChangingBorders(toValue){
	var allDivs=document.getElementsByTagName("TABLE");
    for (i=0;i<allDivs.length;i++){
		if (toValue=="border-black")
		{
			if (allDivs[i].className=="border-black")
			{
				allDivs[i].className="border-black"
			}
			if (allDivs[i].className=="border-red")
			{
				allDivs[i].className="border-black"
			}
		}
		if (toValue=="border-red")
		{
			if (allDivs[i].className=="border-red")
			{
				allDivs[i].className="border-red"
			}
			if (allDivs[i].className=="border-black")
			{
				allDivs[i].className="border-red"
			}
		}
	}
} 

function confirmUpload(filename,referencefield) {
	if (filename=="") {
		// if there is no file to upload, then return true
		return true;
	}
	ok = 1;
	max = document.frmFileList.strFiles.length;
	thefile = filename.substring(filename.lastIndexOf("\\") + 1, filename.length);
	SetElementValue(referencefield,thefile);
	for (var idx = 0; idx < max; idx++) {
		if (document.frmFileList.strFiles[idx].value == thefile) ok = 0;
	}
	if (ok == 0) {
		return confirm("The file '"+thefile+"' already exists. Overwrite it?");
	}
	else {
		return true;
	}
}

var func
function visible() {
document.getElementById("FormContent").disabled=false;
document.getElementById("FormContent").focus();
}
function hide() {
document.getElementById("FormContent").disabled=true;
document.getElementById("FormContent").value='';
}

function ShowHelp(div, title, desc)
{
	div = document.getElementById(div);
	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = '170';
	div.style.padding = '10px';
	div.innerHTML = '<b>' + title + '</b><br><div>' + desc + '</div>';
}

function HideHelp(div)
{
	div = document.getElementById(div);
	div.style.display = 'none';
}

function selectdate(form, fieldname) {
	querystring = "?field=document." + form.name + "." + fieldname;
	myfield = eval('document.'+form.name + "."+fieldname);
	// sometimes we have two fields with the same name to separately edit the date and time
	// in this case we select the first one to work with
	if (myfield.length) myfield = myfield[0]
	if (myfield.value != "") {
		var myDate = new Date(myfield.value)
		querystring += "&d=" + myDate.getDate() + "&m=" + (myDate.getMonth() + 1) + "&y=" + myDate.getFullYear()
	}
	window_popup = window.open('/includes/calendar.asp' + querystring, 'selectdate', 'width=210,height=203');
	window_popup.focus();
	return false;
}

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.01
  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 && d.getElementById) x=d.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];}
}

var my_Timeout1 = 0
	var my_Timeout2 = 0

function initTimeoutServices(montremanu,image_name){
	my_Timeout1 = setTimeout("montre('"+montremanu+"')", 700);
	my_Timeout2 = setTimeout("MM_swapImage('menu','','/images/public_only/"+image_name+".jpg',1)",700);
}

function initTimeoutStop(){
for(i=my_Timeout1-100;i<my_Timeout2+10;i++)clearTimeout(i);
}

function flashListeningPost(){
		initTimeoutStop()
		for(i=my_Timeout1-500;i<my_Timeout2+100;i++)clearTimeout(i);
		MM_swapImage('menu','','../images/public_only/menu_services.jpg',1);
}


