/*
	21 jan 03 : jm
	added timer for second level div 
		showFirstDiv()
		timeRanOut()
		closeMain()

*/

// check for browser
var doCheck = (document.all!=null);
var isOpen = 0;
var openId = 'none';
var e = 0;					// for selectElemets
var endDiv='</div>';				// end div tag
var sidemenuId = "";
if (doCheck == false) {
	versionNN = navigator.appVersion;
	if (versionNN.search(/5.0/i) == -1){
		browser = "NN4";
	}else{
		browser = "NN6";
	}
} else {
	var agt = navigator.userAgent.toLowerCase();
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)){
		if(!document.getElementById){
			browser = "IE4";
		}else{
			browser = "IE5";
		}
	}else{
		browser = "OP";
	}
}

// opens div
function showDiv(id){
	//alert(id);
	//isOpen = 1;
	 var get = getLayer(id);
	  if (get != null){  
	  	hideAllDropDowns();
	     	if (browser != "NN4"){
	         	get.style.visibility = "visible";
	         	hideAllDropDowns();
	      	}else{
         		get.visibility = "show";
		}
		
         }
        
}
function setMenuId(id) {
sidemenuId == id;
}
// opens 1st Layer
function showFirstDiv(id){
	//alert(id);
	if (isOpen != 1){
		isOpen = 1;
	}
	var get = getLayer(id);
	if (get != null){
		hideAllDropDowns();
	     	if (browser != "NN4"){
	         	get.style.visibility = "visible";
	      	}else{
         		get.visibility = "show";
		}
	
	}
}
function showNote(id){
	 var get = getLayer(id);
	     	if (browser != "NN4"){
			  
	         	get.style.visibility = "visible";
	      	}
			else{
         		get.visibility = "show";

		
         }
        
}
function hideNote(id){
	 var get = getLayer(id);
	     	if (browser != "NN4"){
	         	get.style.visibility = "hidden";
	      	}
			else{
         		get.visibility = "hide";

		
         }
        
}
// hides div
function hideLayer(id) {
	var get = getLayer(id);  
	if (get != null){
		showAllDropDowns();
		if (browser != "NN4"){
			get.style.visibility = "hidden";
			
		}else{
			get.visibility = "hide";
		}
	
	}
}
// hides the DropDowns

function hideAllDropDowns(){
	// find the amount of select elements to find
	var num = calSelects();
	var theSelect = "selectElements0";
	var getSelectE = getLayer(theSelect);
	if (getSelectE != null){
		
		for(i=0;i<=num;i++){
			sElement = "selectElements" + i;
			s = getLayer(sElement);
			//alert(s);
			if (browser != "NN4"){
				s.style.visibility = "hidden";
			}else{
				s.visibility = "hide";
			}
		}
		
	}
	
}

// reshow DropDowns
function showAllDropDowns(){
	// find the amount of select elements to find
	var num = calSelects();
	var theSelect = "selectElements0";
	var getSelectE = getLayer(theSelect);
	if (getSelectE != null){

		for(i=0;i<=num;i++){
			sElement = "selectElements" + i;
			s = getLayer(sElement);
			//alert(s);
			if (browser != "NN4"){
				s.style.visibility = "visible";
			}else{
				s.visibility = "show";
			}
		}

	}
}
// gets the amount of <select> elements in the form
function calSelects(){
	selects = document.getElementsByTagName("select");
	var theLen = selects.length - 1;
	return theLen;
}

// added timeout 17 Jan 03 : jm
function timeRanOut(id){
	//alert("timer working");
	if (isOpen == 0) {
		//alert("close div");
		hideLayer(id);
	}
}

// call timeout function
function closeMain(id){
	isOpen=0;
	setTimeout("timeRanOut(\'" + id + "\')",100);
}

// gets layer id
function getLayer(id){
	if (browser == "IE4" || browser == "OP"){
		return document.all[id];
	}else if (browser == "NN4"){
		return document.layers[id];
	}else{
		return document.getElementById(id);
	}
	
}
// gets layer name (for select options)
function getTagName(name){
	
	if (browser == "IE4" || browser == "OP"){
		
		return document.all[name];
	}else if (browser == "NN4"){
		// need to fix this
		return document.layers[name];
	}else{
		
		return document.getElementById(name);
		
	}
	
}


// keeps parent div open
function keepOpen(childDiv,parentDiv){
	
	isOpen=2;
	openIdDiv = childDiv;
	theMainDiv = parentDiv;
	showDiv(theMainDiv);
	showDiv(openIdDiv);
}

// closes sub div
function closeSub(childDiv,parentDiv){
	
	hideLayer(childDiv);
	openId = parentDiv;
	
}
	
// open the calendar control 
function openCal(name){
	xHeight = parseInt((screen.Height/2) - 100); 
	yWidth = parseInt((screen.Width/2) - (175/2));
	
	var winFeatures='width=275,';			// width of window
	winFeatures += 'height=200,';			// height of window
	winFeatures += 'toolbar=no,';			// toolbars
	winFeatures += 'titlebar=no,';			// titlebar
	winFeatures += 'location=no,';			// location
	winFeatures += 'directories=no,';		// directories
	winFeatures += 'status=no,';			// status
	winFeatures += 'menubar=no,';			// menubar
	winFeatures += 'scrollbars=no,';		// scrollbars
	winFeatures += 'resizeable=no,'	;		// resizable
	winFeatures += 'copyhistory=no,';		// copy history
	winFeatures += 'top='+ xHeight+',';		// ie specific top
	winFeatures += 'left='+ yWidth + ',';		// ie specific left positioning		
	winFeatures += 'screenX='+ xHeight+',';		// ns specific top positioning
	winFeatures += 'screenY='+ yWidth + '';		// ns specific left pos
	
	// jsp version
	window.open('tools/cal.jsp?n='+ name +'','sub',winFeatures);
	
	// html version :: for layout testing only
	//window.open('tools/cal.htm?n='+ name +'','sub',winFeatures);
	
}

function getNextDD(action,parent,child,level){
	
	var theAction = action;
	var theParent = parent;
	var theChild = child;
	var theLevel = level;
	var parentValue;
	var childValue;
	var theLink;
	
	var theWin = window.document.forms[1];

	// loop thru form elements to find the correct form element name for parent
	for(i=0;i<theWin.elements.length;i++){
		if (theWin.elements[i].name == theParent){
			parentValue = theWin.elements[i].value;
			//alert(parentValue);
		}
	}
	
	if (theChild != ""){
		// get the child value
		for(i=0;i<theWin.elements.length;i++){
			if (theWin.elements[i].name == theChild){
				childValue = theWin.elements[i].value;
				//alert(childValue);
			}
		}
	}

	theLink = theAction + ".do?parentName=" + theParent + "&parent=" + parentValue + "&level=" + theLevel;
	if (theChild != ""){
		theLink += "&childName=" + theChild + "&child=" + childValue;
	}
		//alert(theLink);
		window.location = theLink;
}

function formCancel(loc){
	// when hits cancel button on forms
	window.location = loc;
}

function writeBeginDiv(){
	var beginDiv = '<div id=selectElements' + e + '>';
	e++;
	return beginDiv;
}


function getToday(field1, field2, value1){
    var d = new Date();
    var dStr;
	var mStr = d.getMonth() + 1;
	if (mStr < 10){
		var newM = '0' + mStr;
		mStr = newM;
	}
	
	
    dStr = d.getFullYear();
    dStr += '-' +  mStr  + '-' + d.getDate();
	//alert(dStr);	
    var theWin = document.forms[0];  // or which ever your form is
	//alert(theWin.name);
     // loop thru form elements to find the correct from element name
     var i;
     for(i=0;i<theWin.elements.length;i++){
	// alert(theWin.elements[i].name);
          if (theWin.elements[i].name == field1){
		       theWin.elements[i].value = dStr;
               break;
   
          }
     }
	 
	 for(i=0;i<theWin.elements.length;i++){
	// alert(theWin.elements[i].name);
          if (theWin.elements[i].name == field2){
		       theWin.elements[i].value = value1;
               break;
   
          }
     }
}
function submitDisable(theForm)
{
 for (i=0; i < theForm.length; i++)
 {
   var obj = theForm.elements[i];
   if (obj.type.toLowerCase() == "submit" || obj.type.toLowerCase() == "reset")
   {
   obj.disabled = true;
   }
 }
}
