var SurveyWindowObjectReference = null; // global variable

function startSurvey(BaseURL, SurveyURL) {
	window.location.href = BaseURL;
	if(SurveyWindowObjectReference == null || SurveyWindowObjectReference.closed)
	{
		SurveyWindowObjectReference = window.open(SurveyURL,"Umfrage","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=740,height=600");
	} else {
		SurveyWindowObjectReference.focus();
	};
}

var VideoWindowObjectReference = null; // global variable

function startVideo(theURL) {
	if(VideoWindowObjectReference == null || VideoWindowObjectReference.closed)
	/* if the pointer to the window object in memory does not exist or if such pointer exists but the window was closed */
	{
		VideoWindowObjectReference = window.open(theURL,"Video","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=700,height=600");
		/* then create it. The new window will be created and will be brought on top of any other window. */
	} else {
		VideoWindowObjectReference.focus();
		VideoWindowObjectReference.location.href = theURL;
		/* else the window reference must exist and the window is not closed; therefore, we can bring it back on top of any other window with the focus() method. There would be no need to re-create the window or to reload the referenced resource. */
	};
}

var FullScreenWindowObjectReference = null; // global variable

function openFullScreen(theURL) {
	if(FullScreenWindowObjectReference == null || FullScreenWindowObjectReference.closed)
	/* if the pointer to the window object in memory does not exist or if such pointer exists but the window was closed */
	{
		FullScreenWindowObjectReference = window.open(theURL, '', 'fullscreen=yes,scrollbars=auto');
		/* then create it. The new window will be created and will be brought on top of any other window. */
	} else {
		FullScreenWindowObjectReference.focus();
		FullScreenWindowObjectReference.location.href = theURL;
		/* else the window reference must exist and the window is not closed; therefore, we can bring it back on top of any other window with the focus() method. There would be no need to re-create the window or to reload the referenced resource. */
	};
}

var QuizWindowObjectReference = null; // global variable

function startQuiz(theURL) {
	if(QuizWindowObjectReference == null || QuizWindowObjectReference.closed) {
		QuizWindowObjectReference = window.open(theURL,"Quiz","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=600,height=450");
	} else {
		QuizWindowObjectReference.focus();
	};
}

var AdWindowObjectReference = null; // global variable

function startAnzeige(theURL) {
	if(AdWindowObjectReference == null || AdWindowObjectReference.closed) {
		AdWindowObjectReference = window.open(theURL,"Anzeige","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=780,height=570");
	} else {
		AdWindowObjectReference.focus();
	};
}

var LexWindowObjectReference = null; // global variable

function startLexikon(theURL) {
	if(LexWindowObjectReference == null || LexWindowObjectReference.closed) {
		LexWindowObjectReference = window.open(theURL,"Lexikon","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=480");
	} else {
		LexWindowObjectReference.focus();
	};
}

var IFAPWindowObjectReference = null; // global variable

function startIFAP(theURL) {
	if(IFAPWindowObjectReference == null || IFAPWindowObjectReference.closed) {
		IFAPWindowObjectReference = window.open(theURL,"Profil","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=750");
	} else {
		IFAPWindowObjectReference.focus();
	};
}

var TeenWBWWindowObjectReference = null; // global variable

function startTeenWBW(){
	if(TeenWBWWindowObjectReference == null || TeenWBWWindowObjectReference.closed) {
		TeenWBWWindowObjectReference = window.open("/Guide_WBW/WBW1.html","Wettbewerb","toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500");
	} else {
		TeenWBWWindowObjectReference.focus();
	};
}

var TwenWBWWindowObjectReference = null; // global variable

function startTwenWBW(){
	if(TwenWBWWindowObjectReference == null || TwenWBWWindowObjectReference.closed) {
		TwenWBWWindowObjectReference = window.open("/Guide_WBW/WBW2.html","Wettbewerb","toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500");
	} else {
		TwenWBWWindowObjectReference.focus();
	};
}

var MapWindowObjectReference = null; // global variable

function startMap(theURL) {
	if(MapWindowObjectReference == null || MapWindowObjectReference.closed) {
		MapWindowObjectReference = window.open(theURL,"Karte","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=750,height=600");
	} else {
		MapWindowObjectReference.focus();
	};
}

function Set_Session_Cookie(name, value) {
	document.cookie = name + "=" +escape( value ) + "; path=/";
	window.location.reload();
}

function mail_link(user, domain, link_text) {
	if (link_text.length > 0) {
		document.write("<a href=" + "mail" + "to:" + user + "&#64;" + domain + ">" + link_text + "</a>")
	} else {
		document.write("<a href=" + "mail" + "to:" + user + "&#64;" + domain + ">" + user + "&#64;" + domain + "</a>")
	}
}

function check_search(form) {
	var result = false;
	if (form.IP_Searchtext.value!="") {
		result=true;
	}
	return result;
}

function check_empfehlung(form) {
	var result = false;
	if (form.abs_name.value!="") {
		result=true;
	} else {
		alert("Bitte geben Sie Ihren Namen ein.");
		result=false;
		form.abs_name.focus();
		return result;
	}
	if (form.abs_mail.value!="") {
		if (isValidEmail(form.abs_mail.value)) {
			result=true; 
		} else {
			alert("Bitte geben Sie eine korrekte Mailadresse ein.");
			result=false;
			form.abs_mail.focus();
			return result;
		}
	} else {
		alert("Bitte geben Sie Ihre Mailadresse ein.");
		result=false;
		form.abs_mail.focus();
		return result;
	}
	if (form.empf_mail.value!="") {
		if (isValidEmail(form.empf_mail.value)) {
			result=true; 
		} else {
			alert("Bitte geben Sie eine korrekte Mailadresse ein.");
			result=false;
			form.empf_mail.focus();
			return result;
		}
	} else {
		alert("Bitte geben Sie die Mailadresse ein.");
		result=false;
		form.empf_mail.focus();
		return result;
	}
	if (containsNoLink(form.Mitteilung.value)) {
		result=true; 
	} else {
		alert("Bitte verwenden Sie keine Link-Tags.");
		result=false;
		form.Mitteilung.focus();
		return result;
	}
	return result;
}

function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (strEmail.search(validRegExp) == -1) {
		return false;
	}
	return true;
}

function containsNoLink(strNote){
	linkRegExp = "<a.*?>";
	if (strNote.search(linkRegExp) == -1) {
		return true;
	}
	return false;
}

// The following code is used to support the small popups that
// give the full description of an event when the user move the
// mouse over it.

// Developer's note:
// I (Benoit Maisonny <benoit@synclude.com>) tested this code with Mozilla 0.8.1 (on Linux),
// with IE5.5 SP1 (on WinNT4) and with Netscape Communicator 4.74 (on Linux).
// Netscape 6.0 and 6.01 seem to have a bug related to the visibility attribute.
// I suppose it will be corrected as soon as they release a new version, based on
// a more recent Mozilla source code.
// I'm not able to test this javascript code with IE4. It'd be glad to know if it works.

NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0;	
// W3C stands for the W3C standard, implemented in Mozilla (and Netscape 6) and IE5

// Function show(evt, name)
//	evt is a pointer to the Event object passed when the event occurs
//	name is the ID attribute of the element to show
function show ( evt, name ) {
  if (IE4) {
    evt = window.event;  //is it necessary?
  }

  var currentX,		//mouse position on X axis
      currentY,		//mouse position on X axis
      x,		//layer target position on X axis
      y,		//layer target position on Y axis
      docWidth,		//width of current frame
      docHeight,	//height of current frame
      layerWidth,	//width of popup layer
      layerHeight,	//height of popup layer
      ele;		//points to the popup element

  // First let's initialize our variables
  if ( W3C ) {
    ele = document.getElementById(name);
    currentX = evt.clientX,
    currentY = evt.clientY;
    docWidth = document.width;
    docHeight = document.height;
    layerWidth = ele.style.width;
    layerHeight = ele.style.height;

  } else if ( NS4 ) {
    ele = document.layers[name];
    currentX = evt.pageX,
    currentY = evt.pageY;
    docWidth = document.width;
    docHeight = document.height;
    layerWidth = ele.clip.width;
    layerHeight = ele.clip.height;

  } else {	// meant for IE4
    ele = document.all[name];
    currentX = evt.clientX,
    currentY = evt.clientY;
    docHeight = document.body.offsetHeight;
    docWidth = document.body.offsetWidth;
    //var layerWidth = document.all[name].offsetWidth;
    // for some reason, this doesn't seem to work... so set it to 200
    layerWidth = 200;
    layerHeight = ele.offsetHeight;
  }

  // Then we calculate the popup element's new position
  if ( ( currentX ) > 500 ) {
    x = ( currentX - 200 );
  }
  else {
    x = currentX;
  }
  if ( ( currentY + layerHeight ) >= docHeight ) {
     y = ( currentY - layerHeight - 20 );
  }
  else {
    y = currentY + 20;
  }
  if ( IE4 ) {
    x += document.body.scrollLeft;
    y += document.body.scrollTop;
  } else if ( NS4)  {
  } else {
    x += window.pageXOffset;
    y += window.pageYOffset;
  }

  // Finally, we set its position and visibility
  if ( NS4 ) {
    //ele.xpos = parseInt ( x );
    ele.left = parseInt ( x );
    //ele.ypos = parseInt ( y );
    ele.top = parseInt ( y );
    ele.visibility = "show";
  } else {  // IE4 & W3C
    ele.style.left = parseInt ( x );
    ele.style.top = parseInt ( y );
    ele.style.visibility = "visible";
  }
}

function hide ( name ) {
  if (W3C) {
    document.getElementById(name).style.visibility = "hidden";
  } else if (NS4) {
    document.layers[name].visibility = "hide";
  } else {
    document.all[name].style.visibility = "hidden";
  }
}

function unhide ( name ) {
  if (W3C) {
    document.getElementById(name).style.visibility = "visible";
  } else if (NS4) {
    document.layers[name].visibility = "show";
  } else {
    document.all[name].style.visibility = "visible";
  }
}
