/* Copyright 2003 WarmStal D!sign
 * 26-10-2003
*/ 


//-------------------------------------------------------------------------------------------------------
// Highlight text
/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */

function doHighlight(textElement, searchTerm, fgColor, bgColor) 
{
  if (searchTerm == "" ) {
  	return
  }
  var bodyText = textElement.innerHTML;
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!fgColor) || (!bgColor)) {
     fgColor = "blue";
     bgColor= "yellow";        
 }
  
 highlightStartTag = "<font style='color:"+fgColor+"; background-color:"+bgColor+";'>";
 highlightEndTag = "</font>";
 
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
   
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }

 textElement.innerHTML = newText;
}

//-------------------------------------------------------------------------------------------------------
// functie om eind van een string te extraheren
function getEnd(mainStr, searchStr){
	foundOffset = mainStr.lastIndexOf(searchStr)
	if (foundOffset == -1){return null}
	return mainStr.substring(foundOffset+searchStr.length, mainStr.length)
}

//-------------------------------------------------------------------------------------------------------
// open iframe in new window with celsius
//

function open_iframe(path,this_iframe){
	// path relative to document root . docRoot = ""
	// path is /..../.....
	var docname = eval('document.'+this_iframe+'.document.URLUnencoded')
	docname = getEnd(docname,"/");
	var urlArray = path.split("/");
    	var celsiusPath = "celsius/celsius.php"
	
	// count levels deep to docroot and form path to celsius    
       for (var i=0 ; i<urlArray.length-1 ;  i++) {
       	  celsiusPath =  "../"+ celsiusPath 
        }
      
      
       var windowName = "" 
       var options = "" 
       options += "width=800"
       options += ",height=600"
       options += ",top=10"
       options += ",left=10"
       options += ",scrollbars=yes"
       options += ",status=yes"
       options += ",resizable=yes"
       options += ",title=yes"
       options += ",menubar=no"
       options += ",toolbar=no"
     
	var url = celsiusPath+'?newdir='+path+'&ToDo=Edit&FileName='+docname+'&External=1'

	window.open(url, windowName, options); 
	
}
//-------------------------------------------------------------------------------------------------------
// get element positions
//
function GetElementLeft(eElement)
{
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}

function GetElementTop(eElement)
{
    var nTopPos = eElement.offsetTop;            // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nTopPos += eParElement.offsetTop;        // appending top offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nTopPos;                              // return the number calculated
}
//-------------------------------------------------------------------------------------------------------
//  position on resize
//
function positionLayer(eLayer, eElement){
	eLayer.style.top = GetElementTop(eElement);
	eLayer.style.left = GetElementLeft(eElement);
}
//-------------------------------------------------------------------------------------------------------
//  show properties of an object
//
function showObject(obj){
	var msg = ""
	for (var i in obj){
	  	msg+= i+" = "+obj[i] + "\n"
	}
	alert(msg);
}
// ------------------------------------------------------------------------------------------------------------
// test enviroment       
function isNav() {
	return (navigator.appName == "Netscape")
}

function isIE() {
	return (navigator.appName == "Microsoft Internet Explorer")
}

// operating system platforms
function isWindows() {
	return (navigator.appVersion.indexOf("Win") != -1)
}

function isWin95NTXP() {
	return (isWindows() && (navigator.appVersion.indexOf("Win16") == -1 && navigator.appVersion.indexOf("Windows 3.1") == -1))
}

function isMac() {
	return (navigator.appVersion.indexOf("Mac") != -1)
}

function isMacPPC() {
	return (isMac() && (navigator.appVersion.indexOf("PPC") != -1 || navigator.appVersion.indexOf("PowerPC") != -1))
}

function isUnix() {
	return (navigator.appVersion.indexOf("X11") != -1)
}

// browser versions IE
function brVersionIE(){
	var agt=navigator.userAgent.toLowerCase();
       var is_major = parseInt(navigator.appVersion);
     
	 var brVersion = 0
        var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        if (!is_ie) {return 0}
      	 if (is_ie && (is_major < 4)) {
      	 	brVersion = 3;
        	if (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) ){
        		brVersion = 4;
        		if (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) ){
        			brVersion = 5;
        			if (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1)){
        				brVersion = 5.5;
        				if (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) ){
        					brVersion = 6
        				} else { 
        					brVersion = 7
        				}
        			}
        		};
        	}
        }
        return brVersion
}

function isNav4_7() {
	return (isNav() && parseFloat(navigator.appVersion) == 4.7)
}


function isNN6Min() {
	return (isNav() && parseInt(navigator.appVersion) >= 5)
}

   

//--------------------------------------------------------------------------------------------------------------
//Cookie functions
function setCookie(cookieName, cookieValue, cookiePath, cookieExpires) { 
	cookieValue = escape(cookieValue); 
	if (cookieExpires == "") 	{ 
		var nowDate = new Date(); 
		nowDate.setMonth(nowDate.getMonth() + 6); 
		cookieExpires = nowDate.toGMTString(); 
	}

	if (cookiePath != "") { cookiePath = ";Path=" + cookiePath; }
	newCookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath; 
	document.cookie = newCookie
}

function getCookieValue(name) { 
	var cookieString = document.cookie; 
	var index = cookieString.indexOf(name + "=");
	if (index == -1) return null;
	index = cookieString.indexOf("=", index) + 1; 
	var endstr = cookieString.indexOf(";", index);
	if (endstr == -1) endstr = cookieString.length; 
	return unescape(cookieString.substring(index, endstr));
}
//-------------------------------------------------------------------------------------------------------------
// Get radio value
function getRadioValue(radio) {
	for (var i=0; i < radio.length; i++){
		if (radio[i] .checked){
			return radio[i].value
	 	 }
	}
}

