//*********************** ES COPYRIGHT START  *********************************
// @copyright(disclaimer) 
// Licensed Materials - Property of IBM
// IBM OmniFind Enterprise Edition V8.4 (Program Number:  5724-C74)
// (c ) Copyright IBM Corp. 2003, 2006.  All Rights Reserved.
// 
// US Government Users Restricted Rights                                  
// Use, duplication or disclosure restricted by GSA ADP Schedule          
// Contract with IBM Corp.     
// 
// DISCLAIMER OF WARRANTIES :                                             
//                                                                        
// Permission is granted to copy and modify this  Sample code, and to           
// distribute modified versions provided that both the copyright        
// notice,- and this permission notice and warranty disclaimer  appear in all copies and modified  
// versions. 
// 
// THIS SAMPLE CODE IS LICENSED TO YOU AS-IS. 
// IBM  AND ITS SUPPLIERS AND LICENSORS  DISCLAIM     
// ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, IN SUCH SAMPLE CODE, INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL IBM OR ITS LICENSORS OR SUPPLIERS BE LIABLE FOR ANY DAMAGES ARISING OUT OF THE USE OF  OR INABILITY TO USE THE SAMPLE CODE, DISTRIBUTION OF THE SAMPLE CODE, OR COMBINATION OF THE SAMPLE CODE WITH ANY OTHER CODE. IN NO EVENT SHALL IBM OR ITS LICENSORS AND SUPPLIERS BE LIABLE FOR ANY LOST REVENUE, LOST PROFITS OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,-, EVEN IF IBM OR ITS LICENSORS OR SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.                                     
//                                                                  
// @endCopyright       
//*********************** ES COPYRIGHT END  ***********************************
	//*****************************************************************
	// Get browser
	//
	// Returns 0 if the browser type is IE and 1 for all other browsers
	//*****************************************************************
	function GetBrowserType() {
		if (navigator.appName == "Microsoft Internet Explorer") {
			return 0;
		} else {
			return 1;
		}
	}

	//****************
	// Find x & y position
	//****************
	function findPosX(obj) {
	    var rtl = isRTL();
		var curleft = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curleft += obj.offsetLeft - obj.scrollLeft;
				if (rtl) {
					var delta = obj.scrollWidth - obj.offsetWidth;
					if (delta > 0)
						curleft += delta;
				}
				obj = obj.offsetParent;
			}
		} else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	function findPosY(obj) {
		var curtop = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

    function getDocumentElement() {
		if (document.documentElement && document.documentElement.scrollTop)
			return document.documentElement; //IE6
		else if (document.body)
			return document.body;
    }
    
    function isRTL() {
		if (THIS_LANGUAGE_CODE.indexOf("ar")==0 || THIS_LANGUAGE_CODE.indexOf("he")==0 || THIS_LANGUAGE_CODE.indexOf("iw")==0) {
           return true;
        } else {
           return false;
        }   
    }
    
	//****************
	// Popup menu
	//****************
	function enablePopup(event, obj, popupElement) {
		popupElement.style.top = "-1000px";
		popupElement.style.display = "block";
		var scrollTop = getDocumentElement().scrollTop;
		var scrollLeft = getDocumentElement().scrollLeft;
		if (isRTL()) { // RTL 
		    if (window.event) { //IE
		    	popupElement.style.left = eval(event.clientX - popupElement.offsetWidth)+"px";
		    } else {
		    	popupElement.style.left = eval(event.clientX + scrollLeft - popupElement.offsetWidth)+"px";
		    }	
		} else {
	    	popupElement.style.left = eval(event.clientX + scrollLeft)+"px";
		}
		popupElement.style.top = eval(event.clientY + scrollTop)+"px";
		var frame = document.getElementById("toolTipIFrame");
		frame.style.top = popupElement.style.top;
		frame.style.left = popupElement.style.left;
		frame.style.width = popupElement.offsetWidth;
		frame.style.height = popupElement.offsetHeight;
		frame.style.display = "inline"; 
		return false;
	}
	
	//****************
	// Tooltip
	//****************
	function enableToolTip(event, obj, contentElement, tooltipName) {
	    if (!tooltipName) tooltipName = "toolTipDiv";
		var tooltipElement = document.getElementById(tooltipName);
		if (contentElement) {
			tooltipElement.innerHTML = contentElement.innerHTML;
		}
		tooltipElement.style.top = "-1000px";
		tooltipElement.style.display = "block";
		var scrollTop = getDocumentElement().scrollTop;
		var scrollLeft = getDocumentElement().scrollLeft;
		if (isRTL()) { // RTL 
		    if (window.event) { // IE
		    	tooltipElement.style.left = eval(event.clientX - tooltipElement.offsetWidth)+"px";
	    	} else {
	    	tooltipElement.style.left = eval(event.clientX + scrollLeft - tooltipElement.offsetWidth)+"px";
	    	}
		} else {
	    	tooltipElement.style.left = eval(event.clientX + scrollLeft)+"px";
		}
		tooltipElement.style.top = eval(event.clientY + scrollTop)+"px";
		var frame = document.getElementById("toolTipIFrame");
		frame.style.top = tooltipElement.style.top;
		frame.style.left = tooltipElement.style.left;
		frame.style.width = tooltipElement.offsetWidth;
		frame.style.height = tooltipElement.offsetHeight;
		frame.style.display = "inline"; 
		return false;
	}
	function hideToolTip(div) {
	    if (!div) div = "toolTipDiv";
		var element = document.getElementById(div);
    	element.style.display = "none";
	    element.style.left = "-1000px";
		var frame = document.getElementById("toolTipIFrame");
		frame.style.display = "none";
	}
 	var delayhide;
	function clearHideToolTip(){
		if (typeof delayhide!="undefined")
			clearTimeout(delayhide);
	}
 	function delayHideToolTip(div) {
	    if (!div) div = "toolTipDiv";
		delayhide = setTimeout("hideToolTip('"+div+"')", 2000);
 	}
	
	//****************
	// Get/Set Cookie
	//****************
	function getCookieVal(offset) {
	   var endstr = document.cookie.indexOf (";", offset);
	   if (endstr == -1) endstr = document.cookie.length;
	   return unescape (document.cookie.substring(offset, endstr));
	}
	function GetCookie(name) {
	   var arg = name+"=";
	   var alen = arg.length;
	   var clen = document.cookie.length;
	   var i = 0;
	   while (i < clen) {
    	 var j = i + alen;
 	     if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
	     i = document.cookie.indexOf(" ", i) + 1;
	     if (i == 0) break;
  	   }
	   return null;
	}
	function SetCookie (name, value) {
         var argv = SetCookie.arguments;
         var argc = SetCookie.arguments.length;
         var expires = (argc > 2) ? argv[2] : null;
         
         //use persistent cookie
         expires = new Date ();
         expires.setYear(expires.getFullYear()+ 5);
         
         var path = (argc > 3) ? argv[3] : null;
         var domain = (argc > 4) ? argv[4] : null;
         var secure = (argc > 5) ? argv[5] : false;
         document.cookie = name + "=" + escape (value) +
         ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
         ((path == null) ? "" : ("; path=" + path)) +
         ((domain == null) ? "" : ("; domain=" + domain)) +
         ((secure == true) ? "; secure" : "");
	}
	
	//****************
	// Get Values
	//****************
	function getHTMLValue(name) {
	   if (document.getElementById(name)) {
		   return "&" + name + "=" + escape(document.getElementById(name).value);
	   } else {
	       alert('Could not find element with id=['+name+']');
	       return "";
	   }    
	}
	function getIndexedLabelValueHTMLValue(prefix) {
	   var parms = "";
	   for (var i = 0 ; ; i++) {
	          var labelID = prefix + "["+i+"].label";
	          var valueID = prefix + "["+i+"].value"
	          if (document.getElementById(labelID)) {
	          	  parms = parms + getHTMLValue(labelID) + getHTMLValue(valueID);
	          } else {
	          	  break;
	          }
	   }
	   return parms;
	}
	function getIndexedLabelValueObject(prefix) {
   	   var objectArray = new Array();
	   for (var i = 0 ; ; i++) {
	          var labelID = prefix + "["+i+"].label";
	          var valueID = prefix + "["+i+"].value";
	          if (document.getElementById(labelID)) {
	              objectArray[objectArray.length] = { label: document.getElementById(labelID).value, 
	                                                  value: document.getElementById(valueID).value };
	          } else {
	          	  break;
	          }
	   }
	   /*for (var i = 0 ; i < objectArray.length ; i++) {
	      alert(objectArray[i].label+" v="+objectArray[i].value);
	   }*/
	   return objectArray;
	}
	
	function getXMLHTTPRequest(){
		var xreq = null;
		if (window.XMLHttpRequest) {
			xreq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		    try {
		 	  xreq = new ActiveXObject("Msxml2.XMLHTTP");
		 	} catch (theexception) {
		 	  try {
			 	  xreq = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (failed) {
			  } 	  
		 	}  
		}
		if (xreq == null) {
	    	alert("Cannot create XMLHTTPRequest");
		}
		return xreq;
	}

    //**********************************
    // Change cursor when button pressed	
    //**********************************
    var clickedButton = "";
    function buttonPressStart(button) {
    	var lastButton = clickedButton;
		clickedButton = button;
        if (lastButton) {
        	lastButton.style.cursor = "";
        }
        if (button) {
			button.style.cursor = "wait";
		}	
	   	document.body.style.cursor = "wait";
	}
    function buttonPressStop(button) {
        if (button) {
			button.style.cursor = "";
		}	
	   	document.body.style.cursor = "";
	}
	
    //**********************************
    // verifyBackgroundImagePadding	
    //**********************************
    function verifyBackgroundImagePadding() {
       //Get the background image 
	   var backgroundImageTD = document.getElementById('theBackgroundImage');
	   if (backgroundImageTD) {
		   var backgroundImage = backgroundImageTD.style.backgroundImage;
		   var backgroundImageSrc = backgroundImage.substring(4, backgroundImage.length - 1);
	   
	       //Add the background image to the document in order to get the image's height
		   var newDiv = document.createElement("div");
		   newDiv.style.display="block";
		   var newImg = document.createElement("img");
		   newImg.src = backgroundImageSrc;
		   newDiv.appendChild(newImg);
		   document.body.appendChild(newDiv);
		   //alert('td.clientHeight='+backgroundImageTD.clientHeight+' newImg.height='+newImg.height+' naturalHeight='+newImg.naturalHeight);
	       //If the height of the background image container < total height of the background image, add more height via padding 
		   if (newImg.height > backgroundImageTD.clientHeight) {
		       //var table = document.getElementsByTagName("table")[0];
		       //alert(table);
			   var table = document.getElementById("theBackgroundImageTable");
			   var tbody = document.createElement("tbody");
			   table.appendChild(tbody);
			   var tr = document.createElement("tr");
			   tbody.appendChild(tr);
			   var td = document.createElement("td");
			   tr.appendChild(td);
		       var padding = newImg.height - backgroundImageTD.clientHeight;
			   //alert(padding);
			   td.style.paddingTop = padding + "px";
			   var textNode = document.createTextNode(" ");
			   td.appendChild(textNode);
		   }
		   newDiv.style.display="none";
		   document.body.removeChild(newDiv);
	   }   
    }		
    
	function trimString(str) {
	  while (str.charAt(0) == ' ')
    	str = str.substring(1);
	  while (str.charAt(str.length - 1) == ' ')
    	str = str.substring(0, str.length - 1);
	  return str;
	}
    
    function submitFormWhen(event, keyCodeValue, command) {
	  if (window.event) {
		  if (window.event.keyCode == keyCodeValue) { // ie 
		      submitForm(command);
		  }    
	   } else if (event) { // firefox
	      if (event.which == keyCodeValue) {
		      submitForm(command);
		  }     
	   }	 
    }
    
    function addEvent(obj, evType, fn) { 
	  if (obj.addEventListener){ 
	     obj.addEventListener(evType, fn, false); 
	     return true; 
	  } else if (obj.attachEvent){ 
		 var r = obj.attachEvent("on"+evType, fn); 
		 return r; 
	  } else { 
		 return false; 
	  } 
	}
    
