// I know this part is dirty, yet it is needed to check for the visibility tag in different browsers.
var explorer;
var netscape4;
var netscape6;
var theDOM, theSuffix, hiddenKeyword, dhtml;

if (document.all) {
explorer = true;
}
else if (document.layers) {
netscape4 = true;
} else {
netscape6 = true;
}

if(explorer){
   theDOM = 'document.all';
   theSuffix = '.style';
   hiddenKeyword = 'hidden';
   dhtml = true;
}

if(netscape4){
   theDOM = 'document';
   theSuffix = '';
   hiddenKeyword = 'hide';
   dhtml = true;
}

if (netscape6) {
  theDOM = "document.getElementsByTagName('*')";
  theSuffix = ".style";
  hiddenKeyword = "hidden";
  dhtml = true;
}


function CheckRequiredFields(f) {
   var sFieldValue = "";
   var iIndex = 0;
   var iElement = 0;
   var iRadio = 0;
   var iCheck = 0;
   
   // Retrieve the list of field names and labels
   var aFieldList = f.valFieldList.value.split(",");
   
   // Loop through the list of fields
   for (iIndex = 0; iIndex < aFieldList.length; iIndex++) {
      
      // Inform the user of what's happening
      window.status = "Validating field " + aFieldList[iIndex + 1] + " ...";
      
      // Loop through all elements in the form to find the field
      for (iElement = 0; iElement < f.elements.length; iElement++) {
         // Check whether the selected element is a required field
         if (f.elements[iElement].name == aFieldList[iIndex]) {
            // Check whether the field contains a value or not
            switch (f.elements[iElement].type) {
               // Text fields
               case "text" :
                  sFieldValue = f.elements[iElement].value;
                  break;
               // Text areas
               case "textarea" :
                  sFieldValue = f.elements[iElement].value;
                  break;
               // Listboxes
               case "select-one" :
                  if (f.elements[iElement].selectedIndex == 0) {
                     sFieldValue = "";
                  } else {
                     sFieldValue = String(f.elements[iElement].selectedIndex);
                  }
                  break;
               // Checkboxes
               case "checkbox" :
                  for (iCheck = 0; iCheck < f.elements[aFieldList[iIndex]].length; iCheck++) {
                     if (f.elements[iElement + iCheck].checked == false) {
                        sFieldValue = "";
                     } else {
                        sFieldValue = String(f.elements[iElement + iCheck].value);
                        break;
                     }
                  }
                  break;
               // Radiobuttons
               case "radio" :
                  for (iRadio = 0; iRadio < f.elements[aFieldList[iIndex]].length; iRadio++) {
                     if (f.elements[iElement + iRadio].checked == false) {
                        sFieldValue = "";
                     } else {
                        sFieldValue = String(f.elements[iElement + iRadio].value);
                        break;
                     }
                  }
                  break;
            }

            // Warn the user that the selected field is a required field
            if (sFieldValue == "") {
               alert(aFieldList[iIndex+1] + " is a required field. Make sure that " +
               aFieldList[iIndex+1] + " and all other required fields are filled out before saving the document.");
               f.elements[iElement].focus();
               return false;
            }
            break;
         }
      }
      iIndex++;
   }
   return true;
}

function QuerySave(f){
return CheckRequiredFields(f);
}

function insertEmoticon(number)
{
	//insert emoticon in comments field
	var current = document.frmWComment.comBody.value;
	this.number = number;
	document.frmWComment.comBody.value = current + " !em" + number + "! ";
	document.frmWComment.comBody.focus();
}

// this function is to make the drop-down menu work in IE
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menu");
		if (navRoot!=null) {
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	}
}
window.onload=startList;

// function to load an email address, gives basic protecting from spammers. Provided by codestore.net
function mailto(name, domain) 
{ 
 location.href = "mailto:" + name + "@" + domain; 
} 

function writeSearchResults(){  
    for(var i=0;i<a.length;i++){
       document.write(a[i] + "\n");
    }
}

function toggleDisplay(theObject){
	var theObjectReference = eval(theDOM + '.' + theObject + theSuffix);
	if(theObjectReference.visibility == hiddenKeyword){
     	theObjectReference.visibility = 'visible';
    	} else {
		theObjectReference.visibility = hiddenKeyword;
		}
	}
	
function getDisplay(theObject){
	var theObjectReference = eval(theDOM + '.' + theObject + theSuffix);
	if(theObjectReference.visibility == hiddenKeyword){
     	return false;
    	} else {
		return true;
		}
	}
	
function hideObject(theObject){
	var theObjectReference = eval(theDOM + '.' + theObject + theSuffix);
	theObjectReference.visibility = hiddenKeyword;
	}
	
function refreshPreview() {
	if ( getDisplay('preview') ) {
		var txtSource = document.getElementById("txtContent").value;
		var divTarget = document.getElementById("txtOutput");
		divTarget.innerHTML = txtSource;
		}
}


