// ###############################################################################################
// ACHTUNG: .js Dateien immer mit ANSI Codierung speichern, da es sonst Probleme beim IE/Mac gibt.
// ###############################################################################################

// #############################################################################
// (C) 2005 BBH, 80538 Muenchen, Thierschstr. 5, contact@bergerbaaderhermes.de
// #############################################################################
//
// 13.05.2004, JM: adapted to .com
// 19.10.2004, JM: Übergangslösung Skalierung für Fullscreen-Modus-Problem
// 08.02.2005, JM: Neu - openDownload() um Probleme beim Filedownload im IE zu umgehen

function preload(imgObj, imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

var preloadsFinished = false;

function changeImage(imgName,imgObj) {
	if (document.images && preloadsFinished) {
		document.images[imgName].src = imgObj.src
	}
}

function openExternal(strUrl, blnTargetBlank)
{
	/*
		Externe Website oeffnen
	*/
	if (blnTargetBlank) {
		var oWnd = window.open(strUrl, 'jagexternal', '');
	}
	else {
		document.location.href = strUrl;
	}
}

function openJAG()
{
	/*
		Hauptfenster oeffnen
	*/
	var oWnd = window.open('/base.aspx', 'jagcommain', 'location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,width=1000,height=700,top=0,left=0')
}

function openLC(idW)
{
	/*
		Hauptfenster oeffnen
	*/
	var oWnd = window.open('/localchapter.aspx?idW=' + idW, 'jagcommain', 'location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,width=1000,height=700,top=0,left=0')
}

function openWindow(strArea, strModul, strSessionID, strProductID) {
	var sw;
	var sh;
	var w;
	var h;
	var x;
	var y;
	var strURL = '';	
	var strTarget = 'jagpopup';
	var strArgs = '';
	var oWnd;

	if (screen)
	{
		sw = screen.width;
		sh = screen.height;
	}
	
	switch(strArea)
	{
		case 'a01':
			switch(strModul)
			{
				/*
					Upload Karriere
				*/
				case 'm400':
					debugMsg('Upload Karriere');
					w = 400;
					h = 300;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/all/upload.jobs.aspx';
					strURL += "?sid=" + strSessionID;
					strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
					break;
			}
			break;
		case 'a02': 
			switch(strModul)
			{
				case 'm100':
					w = 800;
					h = 510;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/gewinnspiel/default.aspx';
					strURL += "?sid=" + strSessionID;
					strArgs +='width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
					break;
				case 'm300':
					w = 400;
					h = 300;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = 'http://jaegermeister.affiliate.handy.de/index.php';
					strURL += "?productid=" + strProductID;
					strArgs +='width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
					break;
			}
			break;
		case 'a05':
			switch(strModul)
			{
				/*
					Upload Jaegerettes
				*/
				case 'm210':
					debugMsg('Upload Bandsupport');
					w = 400;
					h = 300;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/all/upload.jaegerettes.aspx';
					strURL += "?sid=" + strSessionID;
					strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
					break;
			}
			break;
		case 'a06':
			switch(strModul)
			{
				/*
					Upload Bandsupport
				*/
				case 'm120':
					debugMsg('Upload Bandsupport');
					w = 400;
					h = 300;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/all/upload.bandsupport.aspx';
					strURL += "?sid=" + strSessionID;
					strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
					break;
					
				case 'm530':
					debugMsg('Foto Review Private Concert');
					w = 448;
					h = 452;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/him/foto_review/frameset.html';
					strURL += "?sid=" + strSessionID;
					strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
					break;
			}
			break;
		case 'techfaq':
			w = 600;
			h = 400;
			if (screen)
			{
				x = (sw - w) / 2
				y = (sh - h) / 2
				strArgs += 'top=' + y + ',left=' + x + ',';
			}
			strURL = '/all/techfaq.com.aspx';
			strArgs +='width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no';
			break;
		case 'terms':
			w = 600;
			h = 400;
			if (screen)
			{
				x = (sw - w) / 2
				y = (sh - h) / 2
				strArgs += 'top=' + y + ',left=' + x + ',';
			}
			strURL = '/all/termsconditions.com.aspx';
			strArgs +='width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no';
			break;
		case 'privacy':
			w = 600;
			h = 400;
			if (screen)
			{
				x = (sw - w) / 2
				y = (sh - h) / 2
				strArgs += 'top=' + y + ',left=' + x + ',';
			}
			strURL = '/all/privacy.com.aspx';
			strArgs +='width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no';
			break;
		case 'demosound':
			w = 400;
			h = 300;
			if (screen)
			{
				x = (sw - w) / 2
				y = (sh - h) / 2
				strArgs += 'top=' + y + ',left=' + x + ',';
			}
			strURL = '/_swf/local/' + escape(strModul) + '/events-popup/upload.aspx';
			strURL += "?sid=" + strSessionID;
			strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';
			break;
		case 'aboutus':
			w = 600;
			h = 470;
			if (screen)
			{
				x = (sw - w) / 2
				y = (sh - h) / 2
				strArgs += 'top=' + y + ',left=' + x + ',';
			}
			strURL = '/all/aboutus.aspx';
			strArgs +='width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no';
			break;
		default:
			alert('Fehler: unbekanntes Popup');
	}
	
	if (strURL != '')
	{
		oWnd = window.open(strURL, strTarget, strArgs);
		oWnd.focus();
	}
}

function htmlPrint(strArea, strModul, strValue) {
	var sw;
	var sh;
	var w;
	var h;
	var x;
	var y;
	var strURL = '';	
	var strTarget = 'jagpopup';
	var strArgs = '';
	var oWnd;

	if (screen)
	{
		sw = screen.width;
		sh = screen.height;
	}
	
	switch(strArea)
	{
		case 'a04':
			switch(strModul)
			{
				/*
					drink recipe
				*/
				case 'm100':
				case 'm300':
					w = 600;
					h = 300;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/_xml/a04.m100.print.aspx';
					strURL += "?id=" + strValue;
					strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no';
					break;

				case 'm200':
					w = 600;
					h = 300;
					if (screen)
					{
						x = (sw - w) / 2
						y = (sh - h) / 2
						strArgs += 'top=' + y + ',left=' + x + ',';
					}
					strURL = '/_xml/a04.m200.print.aspx';
					strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no';
					break;
			}
			break;
		default:
			alert('Error: unknow parameter');
	}
	
	if (strURL != '')
	{
		oWnd = window.open(strURL, strTarget, strArgs);
		oWnd.focus();
	}
}

/*
	cross-browser object reference
*/
function getObj(name)
{
  if (document.getElementById)
  {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
		this.obj = document.all[name];
		this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

//var blnDebug = true;
var blnDebug = false;

function debugMsg(s) {
	if (blnDebug)
	{
		alert(s);
	}
}
	
/*
	############################################################################
	isValid: checkt einen String gegen einen regulären Ausdruck
	----------------------------------------------------------------------------
	input:
	sValue - zuprüfender String
	sRe - regulärer Ausdruck (siehe vordefinierte Konstanten)
	output:
	'True' wenn String dem regulären Ausdruck genügt, sonst 'False'
	############################################################################
*/
var RE_TELEFON = '^[0-9 /\\-\\(\\)+]*$';
var RE_EMAIL = '^[\\!\\%\\w\\.\\-+=/]+@[\\w\\.\\-]+$';
var RE_DATUM = '^(([1-9])|([0-2][0-9])|(3[0-1]))[\\.](([1-9])|(0[1-9])|(1[0-2]))[\\.]([1-2][0,9][0-9][0-9])$';
var RE_DBL = '^(([0-9]+)|([0-9]+[\\,][0-9]+))$';
var RE_INT = '^([0-9]+)$';
var RE_PLZ = '^[0-9]{5}$';


function isValid(sValue, sRE) {
	var re = new RegExp(sRE);
	return re.test(sValue);
}

function isValidDbl(theFormObject) {
	if (theFormObject.value == '') {
		theFormObject.value = 0;
	}
	if (!isValid(theFormObject.value, RE_DBL)) {
		return false;
	}
	else {
		return true;
	}
}

function isValidInt(theFormObject) {
	if (theFormObject.value == '') {
		theFormObject.value = 0;
	}
	if (!isValid(theFormObject.value, RE_INT)) {
		return false;
	}
	else {
		return true;
	}
}

function isValidDate(theFormObject) {
	var re;
	var datDate;
	var strDate = '';
	
	if (isValid(theFormObject.value, RE_DATUM)) {
		re = new RegExp(RE_DATUM);
		re.exec(theFormObject.value);
		datDate = new Date(RegExp.$9, RegExp.$5 - 1, RegExp.$1);
		
		if (datDate.getDate() < 10) {
			strDate += '0';
		}
		strDate += datDate.getDate() + '.';
		if ((datDate.getMonth()+1) < 10) {
			strDate += '0';
		}
		strDate += datDate.getMonth()+1 + '.' + datDate.getFullYear();
	
		theFormObject.value = strDate;
		return true;
	}
	else {
		return false;
	}
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded(theMovie)
{
  // First make sure the movie's defined.
  if (typeof(theMovie) != "undefined")
	{
    // If it is, check how much of it is loaded.
    return theMovie.PercentLoaded() == 100;
  }
	else
	{
    // If the movie isn't defined, it's not loaded.
    return false;
  }
}

function getFlashMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  } else {
    return document[movieName]
  }
}

function openDownload(filename, target)
{
	var sw;
	var sh;
	var w;
	var h;
	var x;
	var y;
	var strURL = '';	
	var strTarget = 'jagpopup';
	var strArgs = '';
	var oWnd;

	if (screen)
	{
		sw = screen.width;
		sh = screen.height;
	}
	
	if (is_ie)
	{
		w = 400;
		h = 300;
		if (screen)
		{
			x = (sw - w) / 2
			y = (sh - h) / 2
			strArgs += 'top=' + y + ',left=' + x + ',';
		}
		if (target == 'hubertus')
		{
			strURL = '/all/download.hubertus.aspx?filename=' + filename;
		}
		else {
			strURL = '/all/download.aspx?filename=' + filename;
		}
		strArgs += 'width=' + w + ',height=' + h + ',location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no';

		oWnd = window.open(strURL, strTarget, strArgs);
		oWnd.focus();
	}
	else
	{
		document.location = filename;
	}
}