

function ui_test(){
  alert("test");
}

function extractFileName(path){
	if(navigator.platform=="Win32") fs = '\\';
	else fs = '/';
	return path.substr(path.lastIndexOf(fs)+1,path.lastIndexOf('.')-path.lastIndexOf(fs)-1);
}


function getMousePos (e){
  if(!e) e = window.event;
  var body = window.document.body;
  var mouse = {};
  // Position im Dokument
  mouse.Y = e.pageY ? e.pageY : e.clientY + body.scrollTop;
  mouse.X = e.pageX ? e.pageX : e.clientX + body.scrollLeft;
  
  // Position im Browserfenster
  mouse.clientX = e.clientX ? e.clientX : e.pageX - window.pageXOffset;
  mouse.clientY = e.clientY ? e.clientY : e.pageY - window.pageYOffset;
  return mouse;
}

function openInfoDiv(ctrl_id,obj_id,mouse_pos_x,mouse_pos_y){
  var elem = document.createElement("div");
  var content = document.createTextNode("Test234");
  var id = document.createAttribute("id");
  var width = 500;
  var height = 280;
  
  
  id.nodeValue=obj_id;
  elem.setAttributeNode(id);
  
  elem.innerHTML = "<div class=\"info_container_header\"><div onclick=\"document.getElementById(\'"+obj_id+"\').parentNode.removeChild(document.getElementById(\'"+ obj_id +"\'));\" style=\"cursor:pointer; float:right;\"><strong>X</strong></div><strong>Dialog</strong></div><div id=\""+obj_id+"_content\"></div>";
  
  
  // Here we need some browser specific code for MS IE, 
  // because the style attribute does not accept a string.
  // Alternatively we set the style object attributes directly on the new created object.
  // Also we are just handling MS IE v4 on Windows platforms for the moment.
  
  if(navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.substring(0,1)=="4"){
    var max_width = Math.round(document.body.clientWidth*0.8);
    var max_height = Math.round(document.body.clientHeight*0.8);
    
    if(width>max_width)
      width = max_width;
    
    if(height>max_height)
      width = max_width;
    
    elem.style.height=height + "px";
    elem.style.width=width + "px";
    elem.style.position="absolute";
    //elem.style.top=(document.body.clientHeight-height)/4 + "px";
    elem.style.top=mouse_pos_y + "px";
    elem.style.left=(document.body.clientWidth-width)/2 + "px";
    elem.style.zIndex="99";
    elem.style.backgroundColor="#f6f6f6";
    elem.style.color="#000";
    
    //elem.style.filter="Alpha(opacity=80)";
    //elem.style.overFlow="scroll";
  }else{
    var max_width = Math.round(window.innerWidth*0.8);
    var max_height = Math.round(window.innerHeight*0.8);
    
    if(width>max_width)
      width = max_width;
    
    if(height>max_height)
      width = max_width;
    
    var style = document.createAttribute("style");
    style.nodeValue = "height:"+height+"px; width:"+width+"px; position:absolute; top:" + mouse_pos_y + "px; left:" + (window.innerWidth-width)/2 + "px; z-index:99;"; //overflow:auto;
    elem.setAttributeNode(style);
  }
  
  var css_class = document.createAttribute("class");
  css_class.nodeValue = "info_container";
  elem.setAttributeNode(css_class);
  
  document.getElementsByTagName("body")[0].insertBefore(elem,document.getElementsByTagName("div")[0]);
}

function openLookupDiv(ctrl_id,obj_id,mouse_pos_x,mouse_pos_y){
  var elem = document.createElement("div");
  var content = document.createTextNode("Test234");
  var id = document.createAttribute("id");
  var width = 500;
  var height = 280;
  
  
  id.nodeValue=obj_id;
  elem.setAttributeNode(id);
  
  elem.innerHTML = "<div class=\"info_container_header\"><div onclick=\"document.getElementById(\'"+obj_id+"\').parentNode.removeChild(document.getElementById(\'"+ obj_id +"\'));\" style=\"cursor:pointer; float:right;\"><img src=\"<?=DOCUMENT_ROOT_URL?>img/icons/dialog-cancel.png\" alt=\"Fenster schließen\" title=\"Fenster schließen\" /></div><strong>Gemeinde Lookup</strong></div><div id=\""+obj_id+"_options\"></div><div id=\""+obj_id+"_content\" style=\"height:"+ (height-25) +"px;\"></div>";
  
  
  // Here we need some browser specific code for MS IE, 
  // because the style attribute does not accept a string.
  // Alternatively we set the style object attributes directly on the new created object.
  // Also we are just handling MS IE v4 on Windows platforms for the moment.
  
  if(navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.substring(0,1)=="4"){
    var max_width = Math.round(document.body.clientWidth*0.8);
    var max_height = Math.round(document.body.clientHeight*0.8);
    
    if(width>max_width)
      width = max_width;
    
    if(height>max_height)
      width = max_width;
    
    elem.style.height=height + "px";
    elem.style.width=width + "px";
    elem.style.position="absolute";
    elem.style.top=(document.body.clientHeight-height)/4 + "px";
    elem.style.left=(document.body.clientWidth-width)/2 + "px";
    elem.style.zIndex="99";
    elem.style.backgroundColor="#f6f6f6";
    elem.style.color="#000";
    
    //elem.style.filter="Alpha(opacity=80)";
    //elem.style.overFlow="scroll";
  }else{
    var max_width = Math.round(window.innerWidth*0.8);
    var max_height = Math.round(window.innerHeight*0.8);
    
    if(width>max_width)
      width = max_width;
    
    if(height>max_height)
      width = max_width;
    
    var style = document.createAttribute("style");
    style.nodeValue = "height:"+height+"px; width:"+width+"px; position:absolute; top:" + (window.innerHeight-height)/4 + "px; left:" + (window.innerWidth-width)/2 + "px; z-index:99;"; //overflow:auto;
    elem.setAttributeNode(style);
  }
  
  var css_class = document.createAttribute("class");
  css_class.nodeValue = "info_container";
  elem.setAttributeNode(css_class);
  
  document.getElementsByTagName("body")[0].insertBefore(elem,document.getElementsByTagName("div")[0]);
}

function Coord(x, y){
  this.x = (!x)?0:x;
  this.y = (!y)?0:y;
  
  this.toString = objToString;
  this.equals = equalsCoord;
}

function Canvas(x, y, width, height){
  this.width =  (!width) ? 0 : parseInt(width, 10);
  this.height = (!height)? 0 : parseInt(height, 10);
  
  this.Coord = Coord;
  this.Coord(x, y);
  
  this.equalsCoord = this.equals;
  this.equals = equalsCanvas;
}

function objToString(obj){
  var o=obj || this;
  var ret = "{";
  for(p in o ){
    if (typeof o[p] == "function" || typeof o[p] == "object") continue;
    if(ret.length > 1)
      ret += ",";
    ret += p + ":" + o[p];
  }
  return ret + "}";
}

function equalsCoord(/*Coord*/ c){
  return (this.x == c.x && this.y == c.y);
}
function equalsCanvas(/*Canvas*/ c){
  return ( this.equalsCoord == c.equalsCoord && this.width == c.width && this.height == c.height);
}
Canvas.prototype.isCoordInside = /*boolean*/ function(/* Coord */ coord){
  if(coord.x > this.x && (coord.x < this.x + this.width) 
    && coord.y > this.y && (coord.y < this.y + this.height) ){
    return true;
  }
  return false;
}

// functions

function getLayerRef (id, document) {
  if (!document)
    document = window.document;
  if (document.layers) {
    for (var l = 0; l < document.layers.length; l++)
      if (document.layers[l].id == id)
        return document.layers[l];
    for (var l = 0; l < document.layers.length; l++) {
      var result = getLayerRef(id, document.layers[l].document);
      if (result)
        return result;
    }
    return null;
  }
  else if (document.all) {
    return document.all[id];
  }
  else if (document.getElementById) {
    return document.getElementById(id);
  }
}

function setPosition(objLayer, coords){

    if (document.layers) {
      objLayer.top = coords.y;
      objLayer.left = coords.x;
    } else if (window.opera) {
      objLayer.style.top = coords.y;
      objLayer.style.left = coords.x;
    } else if (document.all) {
      objLayer.style.top = coords.y;
      objLayer.style.pixelLeft = coords.x;
    } else if (document.getElementById) {
      objLayer.style.top = coords.y + 'px'; 
      objLayer.style.left = coords.x + 'px';
    }
}

function setVisibility(objLayer, visible) {

  if(document.layers){
    objLayer.visibility  = 
        (visible == true) ? 'show' : 'hide';
  } else {
    objLayer.style.visibility = 
        (visible == true) ? 'visible' : 'hidden';
  }

}

function setVisibility4DivByPrefix(prefix, visible, d){
  if (!d)
    d = window.document;

  if(document.layers){
    for (var l = 0; l < d.layers.length; l++){
      if(d.layers[l].id.substr(0, prefix.length ) == prefix)
        setVisibility(d.layers[l], visible);
      setVisibility4DivByPrefix(prefix, 
                                visible, 
                                d.layers[l].document);
    }

  } else if(document.all) {

    var layers = document.all.tags("div"); 
    for(i=0; i < layers.length; i++) { 
      if(layers[i].id.substr(0, prefix.length ) == prefix )
        setVisibility(document.all.tags("div")[i], visible);
    }

  } else if(document.getElementsByTagName) {

    var layers = document.getElementsByTagName("div");
    for(i=0; i < layers.length; i++){
      if(layers[i].id.substr(0, prefix.length ) == prefix)
        setVisibility(layers[i], visible);
    }

  }
}

function getMouseXY(ev) {
	var pos = new Coord();
	if(ev.pageX){
		pos.x = ev.pageX;	
		pos.y = ev.pageY;
	} else if(window.event && window.event.clientX) {
		var isStrictMode = document.compatMode && document.compatMode != 'BackCompat' ? true : false;
		var scrollX = isStrictMode ? document.documentElement.scrollLeft : document.body.scrollLeft;
		var scrollY	= isStrictMode ? document.documentElement.scrollTop : document.body.scrollTop;
		pos.x = window.event.clientX + scrollX;
		pos.y = window.event.clientY + scrollY;
	}
	return pos;
}

function getPageCoords (element) {
  var coords = new Coord();
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
} 

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    __method.apply(object, arguments);
  };
};
function registerNodeListener(obj, evType, fn ) {
  try {
    if( obj.addEventListener ) {
      obj.addEventListener(evType, fn, false);
    } else if( obj.attachEvent ) {
      obj.attachEvent( "on"+evType, fn );
    } else {
      throw "Unsupported browser!";
    }
  } catch(e) {
    alert('exception ' + e.message + ' while trying to add a listener to ' + obj + ', event: ' + evType + ', function: ' + fn);
  }
  return {'owner' : obj, 'type' : evType, 'func' : fn };
}
function removeNodeListener( nodeInfo ) {
  if(!nodeInfo){
    return;
  }
  if( nodeInfo.owner.removeEventListener ) {
    nodeInfo.owner.removeEventListener(nodeInfo.type, nodeInfo.func, false);
  } else if( nodeInfo.owner.detachEvent ) {
    nodeInfo.owner.detachEvent("on" + nodeInfo.type, nodeInfo.func);
  } else {
    throw "Unsupported browser!";
  }
}

function checkAll(field){
  for (i = 0; i < field.length; i++){
  	field[i].checked = true ;
  }
}

function uncheckAll(field){
  for (i = 0; i < field.length; i++){
  	field[i].checked = false ;
  }
}
