var JS_DEBUG_ENABLED = false;
if (location.search.indexOf("js_debug=on")>-1) {
  JS_DEBUG_ENABLED = true;;
}
var refDOM = "";
var refStyle = "";
var refLayer = "";
var refVisible = "";
var refHidden = "";
var DOMObj = "";
var CSSRef = "";
var win_zoom = null;

var ns,ns2,ns3,ns4,ns4up,ns47,nsonly,ns5,ns5up,ns6_1 = false;
var ie,ie3,ie4,ie4up,ie5,ie5up,ie6,ie9 = false;
var opera,opera72up = false;
var webtv,other = false;

function debug(text) {
   if (JS_DEBUG_ENABLED) alert(text);
}

function checkBrowser() {
            var agent = navigator.userAgent.toLowerCase();
            var min_version = parseInt(navigator.appVersion);
            var max_version = parseFloat(navigator.appVersion);
//debug("Browser detection:\n"+
//	  "agent="+agent+"\n"+
//	  "min_version="+min_version+"\n"+
//	  "max_version="+max_version+"\n");
            var version;
            var browser;

            ns  = ((agent.indexOf('mozilla') > -1) && (agent.indexOf('spoofer') == -1)
                && (agent.indexOf('compatible') == -1) && (agent.indexOf('opera') == -1)
                && (agent.indexOf('webtv') ==- 1));
            ns2 = (ns && (min_version == 2));
            ns3 = (ns && (max_version == 3));
            ns4 = (ns && (max_version == 4));
            ns4up = (ns && (max_version >= 4));
            ns47 = (ns && (max_version >= 4.7 && max_version <= 4.9));
            nsonly = (ns && ((agent.indexOf(";nav") > -1) ||
                   (agent.indexOf("; nav") > -1)) );
            ns5 = (ns && (max_version == 5));
            ns5up = (ns && (max_version >= 5));
            ns6_1 = (ns && (max_version > 6));

            ie   = (agent.indexOf("msie") > -1);
            ie3  = (ie && (max_version < 4));
            ie4  = (ie && (max_version == 4) && (agent.indexOf("msie 4.0")> -1) );
            ie4up  = (ie  && (max_version >= 4));
            ie5  = (ie && (max_version == 5) && (agent.indexOf("msie 5.0") > -1) );
            ie5up  = (ie && !ie3 && !ie4);
            ie6  = (ie && (agent.indexOf("msie 6.0") > 1));
            ie9  = (ie && (agent.indexOf("msie 9.0") > -1));
            /*if (ie4) {
                if (navigator.userAgent.indexOf('MSIE 5')>0) {
                ie5 = true;
               }
               if (ns5up) {
                ns5up = false;
               }
            } */

            opera = (agent.indexOf("opera") != -1);
            opera72up  = (opera  && (max_version >= 7));
            webtv = (agent.indexOf("webtv") != -1);

            other = (!ie && !ns && !opera && !webtv);

			if (ie) {
				if (ie9) {
				   refDOM = "document";
				   refStyle = "";
				   refLayer = "div";
				   refVisible = "visible";
				   refHidden = "hidden";
				   CSSRef = "setAttribute('id',value,'false');";
				} else if (ie5up) {
				   refDOM = "document";
				   refStyle = "style";
				   refLayer = "div";
				   refVisible = "visible";
				   refHidden = "hidden";
				   CSSRef = "setAttribute('id',value,'false');";
				} else {
				   refDOM = "document.all";
				   refStyle = "style";
				   refLayer = "div";
				   refVisible = "visible";
				   refHidden = "hidden";
				   CSSRef = "setAttribute('id',value,'false');";
				}
            } else { // ns
				if (ns5up || opera72up) {
				   refDOM = "document";
				   refStyle="style";
				   refLayer = "div";
				   refVisible = "visible";
				   refHidden = "hidden";
				   CSSRef = "id = value;";
				} else {
				   refDOM = "document";
				   refStyle="";
				   refLayer = "layer";
				   refVisible = "show";
				   refHidden = "hide";
				   CSSRef = "id = value;";
				} 
			}
            DOMObj = (ns5up || ie5up || opera72up) ? "getElementById('id')" : "id";
//debug("DOMObj="+DOMObj);			
}

function element(id) {
         var rString = "";
         rString = refDOM+"."+DOMObj.replace("id",id);
         if (rString!="" && rString!=".") return eval(rString);
         else return null;
}

function getStyle(id) {
         return eval(styleAsString(id));
}

function styleAsString(id) {
         var rString = "";
         rString = refDOM+"."+DOMObj.replace("id",id);
         if (rString!=".") {
           if (refStyle!="") {
			rString += "."+refStyle;
		   }
           return rString;
         } else return null;
}

function setStyleAttrValue(objId,attrName,value) {
//if (objId=="content_frame") debug("utils.js - setStyleAttrValue(\""+objId+"\",\""+attrName+"\",\""+value+"\")");
         var s = styleAsString(objId) + "." + CSSRef.replace("id",attrName).replace("value",value);
//if (objId=="content_frame") debug("utils.js - setStyleAttrValue: s="+s);
//if (objId=="navigation_div") debug("utils.js - setStyleAttrValue: document.getElementById('"+objId+"')="+document.getElementById(objId));
//if (objId=="navigation_div") debug("utils.js - setStyleAttrValue: document.getElementById('"+objId+"').style="+document.getElementById(objId).style);
         if (s!="" && s!="." && s!="null.") return eval(s);
         else return null;
}

function setStyle(objId,attrName,value) {
         return setStyleAttrValue(objId,attrName,value);
}

function getWindowInnerHeight() {
             var height = screen.availHeight; // default
               if (typeof(window.innerHeight)=='number') {
                  // Non-IE
                    height = window.innerHeight;
               } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                  //IE 6+ in 'standards compliant mode'
                    height = document.documentElement.clientHeight;
               } else if (document.body && (document.body.clientHeight || document.body.clientWidth)) {
                  // IE 4 compatible
                    height = document.body.clientHeight;
               }
               return height;
}

function getWindowInnerWidth() {
             var width = screen.availWidth; // default
               if (typeof(window.innerWidth)=='number') {
                  // Non-IE
                    width = window.innerWidth;
               } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                  //IE 6+ in 'standards compliant mode'
                    width = document.documentElement.clientWidth;
               } else if (document.body && (document.body.clientHeight || document.body.clientWidth)) {
                  // IE 4 compatible
                    width = document.body.clientWidth;
               }
               return width;
}

function setInnerText(objId,text) {
             	 var obj = element(objId);
                 if (!obj) return;
                 var tokens = new Array();
                 var pos1 = 0;
                 var pos2 = -1;
                 while ((pos2=text.indexOf("<br>",pos1))>-1) {
                         tokens[tokens.length] = text.substring(pos1,pos2);
                    pos1 = pos2+"<br>".length;
                 }
                 if (tokens.length>0) {
                    tokens[tokens.length] = text.substring(pos1);
                 }

                 while (obj.hasChildNodes()) {
                    obj.removeChild(obj.lastChild);
                 }

                 if (tokens.length==0) {
                    obj.appendChild(document.createTextNode(text))    ;
                 } else {
                    for (var i=0; i<tokens.length; i++) {
                            obj.appendChild(document.createTextNode(tokens[i]));
                                 if (i<tokens.length-1) {
                                    obj.appendChild(document.createElement("br"));
                                 }

                         }
                 }
}

function printButton() {
             document.write("<div align=\"right\" id=\"printbutton\" class=\"printbutton\">\n"+
                           "<font>\n"+
                                      "[<a href=\"javascript:printPreview()\">print</a>]\n"+
                                   "</font>\n"+
                        "</div>\n\n");
}


function printPreview() {
             /*var win_print = window.open(addParam(self.location.href,"print_preview","yes"),"print_preview","");
             win_print.print();*/
             self.print();
}

function startWithScreenTest() {
        var x = prompt("screen width","1024");
          var y = prompt("screen height","768");
          top.resizeTo(x,y);
          var currentWidth = getWindowInnerWidth();
          var currentHeight = getWindowInnerHeight();
          window.status  = "inner window size = " + getWindowInnerWidth() + " x " + getWindowInnerHeight();
}

function popup(url,title,dimensions) {
       if (win_zoom!=null) win_zoom.close();
        win_zoom = window.open(url,'team_zoom',dimensions);
        win_zoom.title = title;
        win_zoom.focus();
}

 function getCookie(name) {
   var search;
   search = name + "=";
   offset = document.cookie.indexOf(search);
   if (offset != -1) {
      offset += search.length ;
         end = document.cookie.indexOf(";", offset) ;
         if (end == -1) end = document.cookie.length;
         return decodeURI(document.cookie.substring(offset, end));
   } else return "";
 }

 function setCookie(name,value) {
   var expdate = new Date();
   expdate.setTime(expdate.getTime() + (JS_COOKIE_DAYS * 24 * 60 * 60 * 1000));
   var expires = expdate.toGMTString();
   document.cookie = name+"="+value+"; expires=" + expires;
 }

 function getParamValue(paramName) {
    var url = self.location.search;
         var value = "";
   if (paramName==null || paramName=="") return value;
   var pos1,pos2;
         pos1 = url.indexOf(paramName+"=");
         if (pos1>-1) {
            pos2 = url.indexOf("&",pos1)
            if (pos2>-1) {
                         value = url.substring(pos1+paramName.length+1,pos2);
                 } else {
                         value = url.substring(pos1+paramName.length+1);
                 }
         }
         return value;
 }

 function addParam(url,paramName,paramValue) {
         if (paramValue==null || paramValue=="") return url;
         var pos1,pos2,length,prefix;
         //check if param exists and needs to be replaced
         pos1 = url.indexOf(paramName+"=");
         if (pos1>-1) {
            pos2 = url.indexOf("&",pos1)
            if (pos2>-1) {
                         url = url.substring(0,pos1) + url.substring(pos2+1);
                 } else {
                         url = url.substring(0,pos1);
                 }
         }

         if (url.substring(url.length-1)=="?" || url.substring(url.length-1)=="&") {
            prefix = "";
         } else {
            prefix = (url.indexOf("?")>-1) ? "&" : "?";
         }
         if (paramName!=null && paramName!="") {
            url += prefix + paramName + "=" + encodeURI(paramValue);
         } else {
            url += prefix + paramValue;
         }
   return url;
 }

 function myescape(str) {
    str = escape(str);
    for (var i=0; i<str.length; i++) {
    if (str.charAt(i)=="+")
            str = str.substring(0,i) + "%2b" + str.substring(i+1, str.length);
    }
    for (var i=0; i<str.length; i++) {
    if (str.charAt(i)=="/")
            str = str.substring(0,i) + "%2F" + str.substring(i+1, str.length);
    }
    return str;
 }

 function swapImg(imgName,imgSrc) {
  var img = document.images[imgName];
  if (img!=null && img.src!=null) {
   img.src = imgSrc;
  }
 }

 function encode_utf8(rohtext) {
  rohtext = rohtext.replace(/\r\n/g,"\n");
  var utftext = "";
  for(var n=0; n<rohtext.length; n++) {
    var c=rohtext.charCodeAt(n);
    if (c<128)
      utftext += String.fromCharCode(c);
    else if((c>127) && (c<2048)) {
      utftext += String.fromCharCode((c>>6)|192);
      utftext += String.fromCharCode((c&63)|128);}
    else {
      utftext += String.fromCharCode((c>>12)|224);
      utftext += String.fromCharCode(((c>>6)&63)|128);
      utftext += String.fromCharCode((c&63)|128);}
    }
  return utftext;
 }
