/**
 * init()
 *
 * called needs to be in the document
 *
 */

/**
 * browserDetect()
 *
 * performs basic browser detection
 * isDOM1 will be set to true if browser is NS6+ or IE5.0+
 * isIE will be set to true if browser is IE5.0+
 * isNS will be set to true if browser is NS6+
 *
 * incompatible browsers should be rerouted at all entry points
 * to this web interface
 *
 */
function browserDetect() {
	isDOM1 = false;
	isIE = false;
	isIE5_0 = false;
	isNS = false;
	var an = navigator.appName;
	var av = navigator.appVersion;

	switch (an) {
	case 'Microsoft Internet Explorer':
		if (parseFloat(av) >= 4) {
			var versionStr = av.substring(av.indexOf('MSIE')+5);
			if (parseFloat(versionStr) >= 5) {
				isIE = true;
				if (parseFloat(versionStr) < 5.5) {
					isIE5_0 = true;
				}
			}
		}
		break;
	case 'Netscape':
		if (parseFloat(av) >= 5) {
			isNS = true;
		}
		break;
	}//end switch(navigator.appName)

	if (isIE||isNS) {
		isDOM1 = true;
	}
}//browserDetect()


/**
 * imageOut()
 *
 * @param Object event object - only passed by NS browsers
 * IE browsers must go find it in the window that triggered the event
 * 
 * performs image mouseout swap
 *
 */
function imageOut(event) {
	/*
	if ((typeof pageLoaded == 'undefined')||!pagedLoaded) {
		return;
	}
	*/
	 
   if (isIE) {
		event = window.event;
	}
	//grab the event target, image name and src to change target to
	var evtTarget = (isIE)?event.srcElement:event.target;
	var imageName = evtTarget.getAttribute('src').match(/(\w+Over.\w{3}$)/);
	//in case a mouseover occurs before preloads finish
	if (imageName==null) {
		return;
	}
	imageName = imageName[0].replace(/Over\./, 'Out.');
	var imageSrc = imageArray[imageName].getAttribute('src');
	
	if (imageSrc != null) {
		evtTarget.setAttribute('src', imageSrc);
	}
}//end imageOut(Object)

/**
 * imageOver()
 *
 * @param Object event object - only passed by NS browsers
 * IE browsers must go find it in the window that triggered the event
 * 
 * performs image mouseover swap
 *
 */
function imageOver(event) {
	/*
	if ((typeof pageLoaded == 'undefined')||!pagedLoaded) {
		return;
	}
	*/

   if (isIE) {
		event = window.event;
	}

	//grab the event target, image name and src to change target to
	var evtTarget = (isIE)?event.srcElement:event.target;
	var imageName = evtTarget.getAttribute('src').match(/(\w+Out.\w{3}$)/);
	//in case a mouseover occurs before preloads finish
	if (imageName==null) {
		return;
	}
	imageName = imageName[0].replace(/Out\./, 'Over.');
	var imageSrc = imageArray[imageName].getAttribute('src');
	
	if (imageSrc != null) {
		evtTarget.setAttribute('src', imageSrc);
	}
}//end imageOver(Object)


/**
 * imageClic()
 *
 * @param Object event object - only passed by NS browsers
 * IE browsers must go find it in the window that triggered the event
 * 
 * performs image mouseover swap
 *
 */
function imageClic(event) {
	/*
	if ((typeof pageLoaded == 'undefined')||!pagedLoaded) {
		return;
	}
	*/

   if (isIE) {
		event = window.event;
	}

	//grab the event target, image name and src to change target to
	var evtTarget = (isIE)?event.srcElement:event.target;
	var imageName = evtTarget.getAttribute('src').match(/(\w+Out.\w{3}$)/);
	
	if (imageName==null) {
		return;
	}
	imageName = imageName[0].replace(/Out\./, 'Clic.');
	var imageSrc = imageArray[imageName].getAttribute('src');
	
	if (imageSrc != null) {
		evtTarget.setAttribute('src', imageSrc);
	}
}//end imageOver(Object)


/**
 * setMouseOvers()
 * 
 * searchs document for images ending with 'Out.ext', where ext = gif, jpg, or png,
 * which it assumes is a mouseout image. 
 *
 * when found, it creates an image object accordingly and then
 * creates a mouseover image as well.  It also assigns event handlers to do
 * image swaps
 *
 * then goes looking for text mouseovers, and assigns event handlers for those as well
 * 
 */
function setMouseOvers() {

   count = 0;

	//first we set the image mouseovers
	var imageList = document.getElementsByTagName("IMG");
	for (var i=0; i<imageList.length; i++) {
		var imageSrc = imageList[i].getAttribute('src');
		var imageSrcClic = imageList[i].getAttribute('src');
				
		if (/Out.gif$/.test(imageSrc)||/Out.jpg$/.test(imageSrc)||/Out.png$/.test(imageSrc)) {
			//use actual image name, not html name, so we only preload what we need
			var imageName = imageSrc.match(/(\w+Out.\w{3}$)/);		
			//var imageNameClic = imageSrcClic.match(/(\w+roundOut.\w{3}$)/);
		

			//if it's not already preloaded, then we preload and set event handlers
         if (imageArray[imageName[0]] == null) {
	 
				//first the mouseout        
				imageArray[imageName[0]] = new Image();
				imageArray[imageName[0]].setAttribute('src', imageSrc);
				
				//now the mouseover
				imageSrc = imageSrc.replace(/Out\./, "Over.");
				imageName = imageSrc.match(/(\w+Over.\w{3}$)/);
				imageArray[imageName[0]] = new Image();
				imageArray[imageName[0]].setAttribute('src', imageSrc);

				//now the click
				imageSrc = imageSrc.replace(/Over\./, "Clic.");
				imageName = imageSrc.match(/(\w+Clic.\w{3}$)/);
				imageArray[imageName[0]] = new Image();
				imageArray[imageName[0]].setAttribute('src', imageSrc);

				//now mousedown
				imageSrc = imageSrc.replace(/Clic\./, "Out.");
				imageName = imageSrc.match(/(\w+Out.\w{3}$)/);
				imageArray[imageName[0]] = new Image();
				imageArray[imageName[0]].setAttribute('src', imageSrc);
				
			}
			
			//assign mouseover and mouseout event handlers
			imageList[i].onmouseover = imageOver;
			imageList[i].onmouseout = imageOut;
			//imageList[i].onmousedown = downSwap;		
			//imageList[i].onclick = clickSwap;
			
			count++
		}//end if
	}//end for

	//now we set the text mouseovers
	var linkList = document.getElementsByTagName("A");
	for (var i=0; i<linkList.length; i++) {
		//if we have a text link, assign mouseover and mouseout event handlers
		if (linkList[i].hasChildNodes() && linkList[i].childNodes[0].nodeType == 3) {
			linkList[i].onmouseover = textOver;
			linkList[i].onmouseout = textOut;
			count++
		}
	}//end for loop
}//end setMouseOvers()


/**
 * textOut()
 *
 * @param Object event object - only passed by NS browsers
 * IE browsers must go find it in the window that triggered the event
 * 
 * performs text mouseout swap
 *
 */
function textOut(event) { 
   if (isIE) {
		event = window.event;
	}

	var evtTarget = (isIE)?event.srcElement:event.target;
	//sometimes the target is the <a>, sometimes the text node, so we adjust accordingly
	evtTarget = (evtTarget.tagName == 'A')?evtTarget:evtTarget.parentNode;
	evtTarget.style.textDecoration = 'underline';
}//end textOut(Object)

/**
 * textOver()
 *
 * @param Object event object - only passed by NS browsers
 * IE browsers must go find it in the window that triggered the event
 * 
 * performs text mouseover swap
 *
 */
function textOver(event) { 
   if (isIE) {
		event = window.event;
	}

	var evtTarget = (isIE)?event.srcElement:event.target;
	//sometimes the target is the <a>, sometimes the text node, so we adjust accordingly
	evtTarget = (evtTarget.tagName == 'A')?evtTarget:evtTarget.parentNode;
	evtTarget.style.textDecoration = 'underline';
}//end textOver(Object)


//scroll needs to be "yes" or "no"//
var win= null;
function OpenPopUp(mypage,myname,w,h,isScroll)
{
  var winl = (screen.width-w);//goes to left -- divided by 2 would go to center
  var wint = (screen.height-h);//goes to left -- divided by 2 would go to center
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      //settings +='top='+wint+',';//to make it go to center
      settings +='top=0,';
      settings +='left='+(winl-20)+',';
      settings +='scrollbars='+isScroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  //if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function OpenPopUp2(mypage,myname,w,h,isScroll)
{
  //var winl = (screen.width-w);//goes to left -- divided by 2 would go to center
  //var wint = (screen.height-h);//goes to left -- divided by 2 would go to center
  //var settings  ='height='+h+',';
     // settings +='width='+w+',';
      //settings +='top='+wint+',';//to make it go to center
     // settings +='top=0,';
     // settings +='left='+(winl-20)+',';
     // settings +='scrollbars='+isScroll+',';
     // settings +='resizable=yes';
  win=window.open(mypage, 'workshop', 'width=500,height=600', 'yes') 
  //if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function stay(name){
	if (check == true){
	document[name].src = eval(name + "stay.src");
	if (imageStay != name){
		if (imageStay != ""){
			document[imageStay].src = eval(imageStay + ".src");
		}
	}
	imageStay = name
	}
}

//from siemens code -- may need to change code on forecast reports
   function showDiv(thisDiv) {
      if (document.layers) {
         if (document != null && document.layers[thisDiv] != null) {
            document.layers[thisDiv].visibility = "show";
         }
      } else if (document.all) {
         if (document != null && document.all[thisDiv] != null && document.all[thisDiv].style != null) {
            document.all[thisDiv].style.visibility = "visible";
         }
      } else if (document.getElementById) {
         if (document != null && document.getElementById(thisDiv) != null) {
            document.getElementById(thisDiv).style.visibility = "visible";
         }
      }
   }

   function hideDiv(thisDiv) {
      if (document.layers) {
         if (document != null && document.layers[thisDiv] != null) {
            document.layers[thisDiv].visibility = "hide";
         }
      } else if (document.all) {
         if (document != null && document.all[thisDiv] != null && document.all[thisDiv].style != null) {
            document.all[thisDiv].style.visibility = "hidden";
         }
      } else if (document.getElementById) {
         if (document != null && document.getElementById(thisDiv) != null) {
            document.getElementById(thisDiv).style.visibility = "hidden";
         }
      }
   }

   function hideAllButMe(a) {
     var topLevelId = new Array(
     
          "div100001"
     
         ,"div100002"
     
         ,"div100003"
     
         ,"div100004"
     
         ,"div100005"     
        
     );
     
     if (a != topLevelId[0]) {
        hideDiv("div100001");
     }
     
     if (a != topLevelId[1]) {
        hideDiv("div100002");
     }
     
     if (a != topLevelId[2]) {
        hideDiv("div100003");
     }
     
     if (a != topLevelId[3]) {
        hideDiv("div100004");
     }
     
     if (a != topLevelId[4]) {
        hideDiv("div100005");
     }
     
     if (a != topLevelId[5]) {
        hideDiv("div100006");
     }
     
     if (a != topLevelId[6]) {
        hideDiv("div100007");
     }
     
   }

   function externalLinkHandler() {
      if ( true ) {
         alert('The link you are following is to a webpage that is not part of this site.  That webpage and the related site may not be provided, sponsored or controlled by Siemens AG, and its content may not have been prepared or approved by Siemens AG, in which case Siemens AG disclaims all responsibility for the content at that site and for the use of that site.  Please click "OK" to close this window.');
      }
   }

   function openImageViewer( myhref, popupName, height, width ) {
      window.open(myhref, popupName, "toolbar=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=auto,height=" + height + ",width=" + width + ","); 
   }
   
   function navBarRollover(theCell, hoverFlag) {
    	if (hoverFlag) {
    		  if (theCell) {
              if (theCell.className) {
                theCell.className = 'rollOver';
              } else {
                theCell.className = 'rollOver';
              }
           }
    	} else {
    		  if (theCell) {
              if (theCell.className) {
                theCell.className = 'rollOut';
              } else {
                theCell.className = 'rollOut';
              }
          }
    	}
   }



