tempTimer1      = null;
var tmp         = null;
var mousex, mousey;
var deactivateImageSwap=false;


onerror = keinfehler;
function keinfehler()
{return true;}

function init() {
    if (window.event) {
        if (document.captureEvents){
          document.captureEvents(Event.MOUSEMOVE);
        } else {
          window.captureEvents(Event.MOUSEMOVE);
        }
    }
  document.onmousemove = getXY;
}

init();

function getXY(e) {
    if(!e) e = window.event;
    var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
    window.document.documentElement : window.document.body || null;

    mousey = e.pageY ? e.pageY : e.clientY + body.scrollTop;
    mousex = e.pageX ? e.pageX : e.clientX + body.scrollLeft;
}


function createInfo(layerContent) {
	document.getElementById('mouseInfoLayer').innerHTML=layerContent;
	document.getElementById('mouseInfoLayer').style.left = mousex+15+'px';
	document.getElementById('mouseInfoLayer').style.top = mousey+'px';
	document.getElementById('mouseInfoLayer').style.visibility = 'visible';
}

function closeInfo() {
	document.getElementById('mouseInfoLayer').innerHTML='';
	document.getElementById('mouseInfoLayer').style.visibility = 'hidden';
}

function centerPopup(popup_name,popup_url,popup_width,popup_height,myWidth,myHeight,myScrollbar) {
	if(!myWidth) {myWidth = 10;}
	if(!myHeight){myHeight = 50;}
	if(!myScrollbar){myScrollbar = 0;}
	var popup_left = (window.screen.width/2)  - (popup_width/2 + myWidth);
	var popup_top  = (window.screen.height/2) - (popup_height/2 + myHeight);
	window.open(popup_url ,popup_name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popup_width + ",height=" + popup_height + ",left=" + popup_left + ",top=" + popup_top + ",screenX=" + popup_left + ",screenY=" + popup_top);
}

function swapImages(which)
  {
	    document.getElementById("startImage").src=which;
	    
  }
  

/// change the given image path to one with/without "_hl" appended to the name
/// depending on the current value
/// e.g. if the current source is "search/search.jpg" it will be set to "search/search_hl.jpg"
/// and vice versa
/// @param element - the image source path that should be changed
/// @param extension - the "extension" that should be added/removed
/// @return the new name with the "extension" removed or added
function _swapHlName(source,extension)
{
    var ext=source.substr(source.length-4,4);
    source=source.substring(0,source.length-4);
    if(source.substr(source.length-3,3)==extension)
    {
        source=source.substr(0,source.length-3);
       
    }
    else if(source.substr(source.length-4,4)==extension)
    {
    	source=source.substr(0,source.length-4);
    }
    else if(source.substr(source.length-7,7)=="_sel_hl")
    	{
    		var tmp=source.split("_");
    		var sourcetmp=source.substr(0,source.length-6);
    		source=sourcetmp+tmp[2];
    	}
    else
    {
        source+=extension;
        
    }

    return source+ext;
    
}


/// swap the src of the given element to one with/without "_hl" appended to the name
/// depending on the current value
/// e.g. if the current source is "search/search.jpg" it will be set to "search/search_hl.jpg"
/// and vice versa
/// @param element - the (image) element whose source should be changed
function swapHl(element)
{
    element.src=_swapHlName(element.src,"_hl");
}


/// swap the src of the given element to one with/without "_sel" appended to the name
/// depending on the current value
/// e.g. if the current source is "search/search.jpg" it will be set to "search/search_sel.jpg"
/// and vice versa
/// @param element - the (image) element whose source should be changed
/// @date 07 jan 2009
/// @author jc/pn
function swapSel(element)
{
  if(typeof(element)=="string") { element=document.getElementById(element); }
  element.src=_swapHlName(element.src,"_sel");
}


/// check that the given element has a non-empty (actually that it has a minimal length) value
/// @param elem - the element
/// @param minlen - the minimal length required
/// @param name - the name of the element for the message to the user
/// @return a message string if the element did not meet the requirements, otherwise an empty string
function checkNotEmpty(elem, minlen, name)
{
  if(elem.value.length<minlen)
  {
    return name+" muss mindestens "+minlen+" Zeichen lang sein\n";
  }
  return "";
}

/// check if the value of the given element is an email address
/// currently this is pretty simplistic
/// @param elem - the element
/// @return a message string if the element did not meet the requirements, otherwise an empty string
function checkIsEmail(elem)
{
  if(!elem.value.match(/.+@.+\..+/))
  {
    return "Bitte geben Sie eine gültige E-Mailadresse ein\n";
  }
  return "";
}

/// check if the values of the given elements are equal
/// @param elem1 - first element to be compared
/// @param elem2 - the element elem1 is compared to
/// @param text - the text returned if elem1 and elem2 are not equal
/// @return text if the elements were not equal
function checkIsEqual(elem1,elem2,text)
{
  if(elem1.value!=elem2.value)
  {
    return text+"\n";
  }
  return "";
}


/// do a shallow copy of the given object
/// @param obj - the object to copy
/// @returns  the copy of the object
function shallowCopy(object)
{
	var tmp=new Object();
	for(var property in object)
	{
		tmp[property]=object[property];
	}
	return tmp;
}




function _toStringHelper(object, deep)
{
  var string="";

	for(var property in object)
	{
		if(typeof object[property]!='object' && typeof object[property]!='function')
		{
		  string+=property+"=>"+object[property]+"\n";
		}
		else if(typeof object[property]=='function')
		{
		  string+=property+" is a function\n";
		}
		else
		{
		  string+=property+" _object_ [\n";
		  string+=_toStringHelper(property,deep+1);
		  string+="\n]\n";
		}
	}
	return string;
}


/// helper function used during development
/// tries to get a displayable representation of the objects properties
/// @param object - the object whose properties we want to see
function toString(object)
{
  return _toStringHelper(object,0);
}


/// see if the given text fits into the given element or if it will be cut
/// @param text - the text
/// @param elem - the element that should hold the text
/// @returns  true if the text fits, false if it doesn't
function isTextFitting(text, elem)
{
  var copy=shallowCopy(elem);
  copy.style=shallowCopy(elem.style);
  copy.style['height']="";
  copy.innerText=text;
  copy=eval(copy);
  elem.innerText=text;
  document.write("<pre>"+toString(copy.style)+"</pre>");
  alert(elem.offsetHeight);
  alert(copy.offsetHeight);
}


function isFittingHeight(innerElement, holderElement)
{
	var res=innerElement.offsetHeight<=holderElement.offsetHeight;
	return res;
}


function simplePreloader(imgurl)
{
	var img=new Image;
	img.src=imgurl;
}


function simpleHlPreloader(imageObject)
{
   simplePreloader(_swapHlName(imageObject.src));
}


/// function to remove whitespace from beginning and end of the given string
/// @param myString - the string to trim
/// @return the trimmed string
function trim(myString)
{
  return myString.replace(/^\s+/,'').replace(/\s+$/,'');
}

function changeVideoPic(Bildname,BildURL)
{
	document.images[Bildname].src = BildURL;
}

// Checks, if a TipdooObject has Pictures or not
// If there are no pictures, the "Foto"-Button will be changed to grey.
// When there´s a better way to check this, feel free to change or substitute this function
function dirtCheckForPics() {
	firstCheckString="NoImageBig.jpg";
	secondCheckString="NoImageSmall.jpg";
	checkImg1=document.getElementById('image1Image').src;
	checkImg2=document.getElementById('image2Image').src;
	checkImg3=document.getElementById('image3Image').src;
	checkImg4=document.getElementById('image4Image').src;
	checkImg5=document.getElementById('image5Image').src;

	firstCheckImg1 =checkImg1.indexOf(firstCheckString);
	secondCheckImg1=checkImg1.indexOf(secondCheckString);
	firstCheckImg2 =checkImg2.indexOf(firstCheckString);
	secondCheckImg2=checkImg2.indexOf(secondCheckString);
	firstCheckImg3 =checkImg3.indexOf(firstCheckString);
	secondCheckImg3=checkImg3.indexOf(secondCheckString);
	firstCheckImg4 =checkImg4.indexOf(firstCheckString);
	secondCheckImg4=checkImg4.indexOf(secondCheckString);
	firstCheckImg5 =checkImg5.indexOf(firstCheckString);
	secondCheckImg5=checkImg5.indexOf(secondCheckString);

	if ((firstCheckImg1!=-1) || (secondCheckImg1!=-1)) {
		bild1=0;
	} else {
		bild1=1;
	}
	
	if ((firstCheckImg2!=-1) || (secondCheckImg2!=-1)) {
		bild2=0;
	} else {
		bild2=1;
	}

	if ((firstCheckImg3!=-1) || (secondCheckImg3!=-1)) {
		bild3=0;
	} else {
		bild3=1;
	}

	if ((firstCheckImg4!=-1) || (secondCheckImg4!=-1)) {
		bild4=0;
	} else {
		bild4=1;
	}

	if ((firstCheckImg5!=-1) || (secondCheckImg5!=-1)) {
		bild5=0;
	} else {
		bild5=1;
	}
	
	if ((bild1==0) && (bild2==0) && (bild3==0) && (bild4==0) && (bild5==0)) {
		document.getElementById('showPhotoButton').innerHTML='<img src="/tipdoo/img/elemente/Icons/Icon_Fotos_0.gif" alt="Keine Fotos verfügbar" border="0" />';
	}
}


function setCaretToEnd (control)
{
  if (control.setSelectionRange)
  {
    control.focus();
    var length = control.value.length;
    control.setSelectionRange(length, length);
  }
  else if (control.createTextRange)
  {
    var range = control.createTextRange();
    range.collapse(false);
    range.select();
  }
}

function setCaretToStart (control)
{
  if (control.createTextRange)
  {
    var range = control.createTextRange();
    range.collapse(true);
    range.select();
  }
  else if (control.setSelectionRange)
  {
    control.focus();
    control.setSelectionRange(0, 0);
  }
}


