//** This is a JavaScript file for TangoDB */
var img_wait = new Image();
		img_wait.src = 'images/progress.gif';
var img_error = new Image();
		img_error.src = 'images/error.gif';
var tdb_js_errors = new Array();
var errors = null;
var IE = (document.all != null);
var DEBUG = true;
var DEBUG_ALERT = true;

window.onerror = tdb_error_handling;

function $debug(msg, alertMsg) {
	if (!DEBUG)
		return false;
	//alert("DEBUG:"+msg);
	var div = $('javascriptDebug');
	if (!div) {
		alertMsg = true;
		msg = '!!!!!Konnte Debug-Div nicht finden!!!!\n\n'+msg;
		alert(msg);
	}
	if (DEBUG_ALERT)
		alertMsg = true;
	if (alertMsg == true) {
		alert(msg);
		return true;
	}
	var obj = $c('span');
	obj.innerHTML = msg;
	obj.appendChild($c('br'));
	div.appendChild(obj);
	return true;
}

function $(e) {
	return document.getElementById(e);
}
function $n(e) {
	return ((!e) || (!e.length) || (e.length == 0));
}
function $c(e) {
	return document.createElement(e);
}
function $t(e) {
	return document.createTextNode(e);
}
function $ci(e, val) {
	var x = $c(e);
	x.innerHTML = val;
	return x;
}
function $cc(e, o) {
	var x = $c(e);
	x.appendChild(o);
	return x;
}
function window_top_get() {
  if (typeof window.pageYOffset == "number")
    return window.pageYOffset ;
  if (typeof document.body.scrollTop == "number")
    return document.body.scrollTop;
  return window.pageYOffset;
}
function window_left_get() {
  if (typeof window.pageXOffset == "number")
    return window.pageXOffset ;
  if (typeof document.body.scrollLeft == "number")
    return document.body.scrollLeft;
  return window.pageXOffset;
}

function setAttribute(id, attr, value) {
	var obj = id;
	if ((id.length) && (id.length > 0))
		obj = $(id);	
	if (!obj) {
		$debug("setAttribute:"+id+" - obj:"+obj);
		return false;		
	}
	if (!IE) {
		obj.setAttribute(attr, value);
		return true;
	}
	//$debug("setAttribute:"+id+" - obj:"+obj+" - attr:"+attr+" - value:"+value);	
	switch (attr) {
	  case "class":
			obj.className = value;
	    break;	  
	  default:
    	obj.setAttribute(attr, value);
	    break;
	}
	return true;
}

function setStyle(oObject, txtStyle) {
	//$debug("setStyle");	
	//var debug = DEBUG;
	if (IE){
		oObject.setAttribute('style', txtStyle);		
		//$debug("IE = true"+IE+oObject+txtStyle);
		var id = oObject.id;
		if (!id) id = oObject;
		//var obj = $(id);
		//$debug("IE:"+id);
		var old = document.all[id].getAttribute("style");
		//$debug(old.style+"\n"+old.visibility+"\n"+old+"\n"+old.display);
		//var txt = old+"\n"+txtStyle;
		//document.all[id].setAttribute("style", txtStyle);
		//$debug(txt);
		if (!old) {
			$debug("Konnte "+id+" Objekt nicht finden! html.js::setStyle()");
			return false;
		}
		var styles = txtStyle.split(";");
		var i = 0; var styleName = ''; var styleVal = ''; var tmp = '';
		//if (DEBUG)
			//$debug("setStyle:A:"+id+".setStyle:"+styles+":"+styles.length);
		if (styles.length == 0) {
			//if (DEBUG)
				//$debug("ID:"+id+" lösche style "+old);
			document.all[id].removeAttribute("style");
			old = null;
			return true;
		}
		for (i = 0; i<styles.length; i++) {
			tmp = styles[i].split(":");
			if (tmp.length == 2) {
				styleName = tmp[0].replace(/\s/, '');
				styleVal = tmp[1].replace(/\s/, '');
			} else {
				styleName = '';
				styleVal = '';
			}
			if (styleName.length == 0)
				continue;
			
			//check for the following:
			/*Eine wichtige Regel müssen Sie kennen: Wenn in einem Script eine CSS-Angabe ausgelesen oder verändert werden soll, entfällt der Bindestrich, und der erste Buchstabe des Wortes hinter dem Bindestrich wird großgeschrieben. Die CSS-Eigenschaft background-color wird innerhalb eines JavaScripts also zu backgroundColor.*/
			tmp = styleName.split("-");
			if (tmp.length > 1) {
				styleName = tmp[0]+tmp[1].charAt(0).toUpperCase()+tmp[1].substr(1).toLowerCase();
				//$debug("muss style zusammensetzen:"+tmp+":"+styleName);				
			}
			if ((styleName == "display") && (styleVal == "normal")) {
				//if (DEBUG)
					//$debug("style == normal => ändere auf block");
				styleVal = "";
			}
			
			//if (DEBUG)
				//$debug("setStyle:B:"+id+".setStyle("+styleName+","+styleVal+")");
			old.setAttribute(styleName, styleVal);
			if (styleVal.length == 0)
				old.removeAttribute(styleName);
			
		}//for
	}
	else{
		oObject.setAttribute('style', txtStyle);		
	//oObject.style = txtStyle;
	}
	return true;
}

function tdb_ctrl_clear(ctrl) {
	var c = $(ctrl);
	if (!c)
		return false;
	c.innerHTML = '';
	return true;
}
	
function tdb_button_go_url(url) {
	window.open(url, "_top");
	window.focus();
	return true;
}

function tdb_error_handling(err, file, row) {
	var fehler = "Fehlermeldung:\n" + err + "\n" + file + "\n" + row;
	tdb_js_errors.push(fehler);
	tdb_js_errors_show();
	return true;
}

function tdb_js_errors_show() {
	var obj = $('tdb_js_errors');//this is to early, cause the page is not loaded yet
	if (!obj) 
		return false;
	errors = document.createTextNode(tdb_js_errors.join(';\n'));
	obj.appendChild(errors);
	return true;
}
function tdb_js_debug(msg) {
	$debug('js: '+msg);
//	console.debug("js:"+msg);//Firefox FireBug-Extension needed!
}
function tdb_js_debug_p(msg, p) {
	$debug('js: '+msg+'\n'+p);
//	console.debug("js:"+msg, p);//Firefox FireBug-Extension needed!
}
function $d(func, msg) {
	$debug(func+": "+msg);
}


function tdb_addEvent(obj, type, fn){  //adds an event to a certain object 
	if (obj.addEventListener) 
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) { 
		obj["e"+type+fn] = fn; 
		obj[type+fn] = function() { 
		obj["e"+type+fn](window.event); 
	}
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}

function toggle_visible(element) {
	element = $(element);
	if (!element)
		return false;
	var vis = true;
	if (element.style) {
		if (element.style.display)
			vis = !(element.style.display == "none");
	}
	return toggle_visible_set(element, !vis);
}

function toggle_visible_set(element, vis) {
	element = $(element);
	if (!element)
		return false;
	if (IE) {
		//$debug("toggle_visible_set:"+element+":"+element.style);
		if (vis) {
			//element.style.setAttribute('visibility', 'visible');
			//element.style.setAttribute('display', 'inline');
			setStyle(element, "visibility:visible;display:inline;");
		} else {
			//element.style.setAttribute('visibility', 'hidden');
			//element.style.setAttribute('display', 'none');		
			setStyle(element, "visibility:hidden;display:none;");
		}
		return true;
	}
	if (vis) {
		element.style.visibility = "visible";
		element.style.display = "inline";
	} else {
		element.style.visibility = "hidden";
		element.style.display = "none";	
	}
	return true;	
}

function toggle_visility(capA, capB, element) {
	element = $(element);
	capA		= $(capA);
	capB		= $(capB);	
	if (!element)
		return false;
	var vis = true;
	if (element.style) {
		if (element.style.display)
			vis = !(element.style.display == "none");
	}

	if (IE) {
		//$debug("toggle_visility:"+element+":"+element.style);
		if (vis) {
			//element.style.setAttribute('visibility', 'visible');
			//element.style.setAttribute('display', 'inline');
			//capA.style.setAttribute('display', 'none');
			//capB.style.setAttribute('display', 'inline');
			setStyle(element, "visibility:visible;display:inline;");
			setStyle(capA, "display:none;");
			setStyle(capB, "display:inline;");
		} else {
			//element.style.setAttribute('visibility', 'hidden');
			//element.style.setAttribute('display', 'none');		
			//capA.style.setAttribute('display', 'inline');
			//capB.style.setAttribute('display', 'none');
			setStyle(element, "visibility:hidden;display:none;");
			setStyle(capA, "display:inline;");
			setStyle(capB, "display:none;");
		}
		return true;
	}

	if (!vis) {
		element.style.visibility = "visible";
		element.style.display = "inline";
		capA.style.display = "none";
		capB.style.display = "inline";
	} else {
		element.style.visibility = "false";
		element.style.display = "none";	
		capA.style.display = "inline";
		capB.style.display = "none";
	}
	return true;
}

/* found on: http://forum.de.selfhtml.org/archiv/1999/4/t2874/ */
function now()
{
    var Act = new Date();
    return Act;
}

function sleep()
{
    var DelaySeconds = 1; /* 5 Sekunden Verzoegerung */
    var DelayMinutes = 0; /* 0 Minuten  Verzoegerung */
    var DelayHours   = 0; /* 0 Stunden  Verzoegerung */
    var DelayDays    = 0; /* 0 Tage     Verzoegerung */
    var DelayMonths  = 0; /* 0 Monate   Verzoegerung */
    var DelayYears   = 0; /* 0 Jahre    Verzoegerung */

    var ActTime   = new Date();
    var Seconds   = ActTime.getSeconds();
    var Minutes   = ActTime.getMinutes();
    var Hours     = ActTime.getHours();
    var Days      = ActTime.getDate();
    var Months    = ActTime.getMonth();
    var Years     = ActTime.getYear();
    var FinalTime = ActTime;

    if ((60 - Seconds) < DelaySeconds)
    {
        Seconds = Seconds + DelaySeconds - 60;
        DelayMinutes = DelayMinutes + 1;
    }
    else
    {
        Seconds = Seconds + DelaySeconds;
    }

    if ((60 - Minutes) < DelayMinutes)
    {
        Minutes = Minutes + DelayMinutes - 60;
        DelayHours = DelayHours + 1;
    }
    else
    {
        DelayMinutes = Minutes + DelayMinutes;
    }

    if ((24 - Hours) < DelayHours)
    {
        Hours = Hours + DelayHours - 24;
        DelayDays = DelayDays + 1;
    }
    else
    {
        DelayHours = Hours + DelayHours;
    }

    switch (Months)
{
  case 0, 2, 4, 6, 7, 9, 11:
   if ((31 - Days) < DelayDays)
   {
    Days = Days + DelayDays - 31;
    DelayMonths = DelayMonths + 1;
   }
   else
   {
    DelayDays = Days + DelayDays;
   }
   break;
  case 3, 5, 8, 10:
   if ((30 - Days) < DelayDays)
   {
    Days = Days + DelayDays - 30;
    DelayMonths = DelayMonths + 1;
   }
   else
   {
    DelayDays = Days + DelayDays;
   }
   break;
  case 1:
   if ((Year % 400) == 0)
   {
    if ((29 - Days) < DelayDays)
    {
     Days = Days + DelayDays - 29;
     DelayMonths = DelayMonths + 1;
    }
    else
    {
     DelayDays = Days + DelayDays;
    }
   }
   else
   {
    if (((Year % 100) == 0) ((Year % 4) != 0))
    {
     if ((28 - Days) < DelayDays)
     {
      Days = Days + DelayDays - 28;
      DelayMonths = DelayMonths + 1;
     }
     else
     {
      DelayDays = Days + DelayDays;
     }
    }
    else
    {
     if ((29 - Days) < DelayDays)
     {
      Days = Days + DelayDays - 29;
      DelayMonths = DelayMonths + 1;
     }
     else
     {
      DelayDays = Days + DelayDays;
     }
    }
   }
   break;
    }

    if ((11 - Months) < DelayMonths)  {
        Months = Months + DelayMonths - 24;
        DelayYears = DelayYears + 1;
    } else {
        DelayMonths = Months + DelayMonths;
    }
    Years = Years + DelayYears;
    FinalTime.setSeconds(Seconds);
		FinalTime.setMinutes(Minutes);
		FinalTime.setHours(Hours);
		FinalTime.setDate(Days);
		FinalTime.setMonth(Months);
		FinalTime.setYear(Years);

    while (now() < FinalTime)
    {
    }
}
