var helpWindow;
function openHelpWindow (url) {
	if (!helpWindow || helpWindow.closed) {
		helpWindow = window.open(url,'helpWindow','width=810,height=600,left=200,top=80,scrollbars=yes');
	} else {
		helpWindow.focus();
		helpWindow.location.href=url;
	}
	return false;
}

var wikiWindow;
function openWikiWindow () {
	var url = '/index.php?modus=1&page_id=16702';		// using a constant modus=1
	if (openWikiWindow.arguments.length > 0 ) url = url + '&id=' + openWikiWindow.arguments[0];
	if (openWikiWindow.arguments.length > 1 ) url = url + '#' + openWikiWindow.arguments[1];
	if (!wikiWindow || wikiWindow.closed) {
		wikiWindow = window.open(url,'wikiWindow','width=980,height=690,left=10,top=10,scrollbars=yes,resizable=yes');
	} else {
		wikiWindow.focus();
		wikiWindow.location.href=url;
	}
	return false;
}

var imgWindow;
function openImgWindow (url,param) {
	if (!imgWindow || imgWindow.closed) {
		imgWindow = window.open(url,'imgWindow',param);
	} else {
		imgWindow.focus();
		imgWindow.location.href=url;
	}
	return false;
}

var contactWindow;
function openContactWindow (url,param) {
	if (!contactWindow || contactWindow.closed) {
		contactWindow = window.open(url,'adminWindow',param);
	} else {
		contactWindow.focus();
		contactWindow.location.href=url;
	}
	return false;
}

var newsletterWindow;
function openNewsletterWindow (url, mail, country) {
	url = url + '&mail=' + mail + '&country=' + country;
	if (!newsletterWindow || newsletterWindow.closed) {
		newsletterWindow = window.open(url,'newsletterWindow','width=860,height=640,left=40,top=50,scrollbars=yes');

	} else {
		newsletterWindow.focus();
		newsletterWindow.location.href=url;
	}
	return false;
}

function goto_page (url) {
	document.location.href=url;
	return false;
}

var sweepWindow;
function openSweepWindow (url, mail) {
	url = url + '&mail=' + mail;
	if (!sweepWindow || sweepWindow.closed) {
		sweepWindow = window.open(url,'sweepWindow','width=830,height=580,left=100,top=50,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');

	} else {
		sweepWindow.focus();
		sweepWindow.location.href=url;
	}
	return false;
}

var feedbackWindow;
function openFeedbackWindow (url) {
	url = url.replace("https://","http://");
	//alert("openFeedbackWindow: "+url);
	if (!feedbackWindow || feedbackWindow.closed) {
		feedbackWindow = window.open(url,'feedbackWindow','width=830,height=520,left=80,top=40');
	} else {
		feedbackWindow.focus();
		feedbackWindow.location.href=url;
	}
	return false;
}

var userOwnWindow;
function openUserOwnWindow (url) {
	if (!userOwnWindow || userOwnWindow.closed) {
		userOwnWindow = window.open(url,'userOwnWindow','width=830,height=700,left=20,top=20,scrollbars=yes,resizeable=yes,status=yes');

	} else {
		userOwnWindow.focus();
		userOwnWindow.location.href=url;
	}
	return false;
}

var SendaFriendWindow;
function openSendAFriendWindow (url, url_link) {
	/*
	url = url+"&sendafriend_page="+url_link;
	if (!SendaFriendWindow || SendaFriendWindow.closed) {
		SendaFriendWindow = window.open(url,'SendAFriendWindow','width=880,height=700,left=20,top=20,scrollbars=yes,resizeable=yes,status=yes');
	} else {
		SendaFriendWindow.focus();
		SendaFriendWindow.location.href=url;
	}
	return false;*/
}

var PrintAPageWindow;
function openPrintAPageWindow (url) {
	if (!PrintAPageWindow || PrintAPageWindow.closed) {
		PrintAPageWindow = window.open(url,'PrintAPageWindow','width=600,height=600,left=20,top=20,scrollbars=yes,resizeable=yes,status=yes');
	} else {
		PrintAPageWindow.focus();
		PrintAPageWindow.location.href=url;
	}
	return false;
}

var SendAFriendWindow;
function openSendAFriendWindow (url) {
	if (!SendAFriendWindow || SendAFriendWindow.closed) {
		SendAFriendWindow = window.open(url,'SendAFriendWindow','width=800,height=550,left=20,top=20,scrollbars=yes,resizeable=yes,status=yes');
	} else {
		SendAFriendWindow.focus();
		SendAFriendWindow.location.href=url;
	}
	return false;
}

var memoWindow;
function openMemoWindow (url) {
	if (!memoWindow || memoWindow.closed) {
		memoWindow = window.open(url,'memoWindow','width=650,height=800,left=300,top=100,toolbar=yes,menubar=yes,scrollbars=yes,resizeable=yes,location=yes,status=yes');

	} else {
		memoWindow.focus();
		memoWindow.location.href=url;
	}
	return false;
}

var offerTxtWindow;
function openOfferTxtWindow (url) {
	if (!offerTxtWindow || offerTxtWindow.closed) {
		offerTxtWindow = window.open(url,'memoWindow','width=600,height=200,left=610,top=330,toolbar=no,menubar=no,scrollbars=yes,resizeable=yes,location=no,status=no');

	} else {
		offerTxtWindow.focus();
		offerTxtWindow.location.href=url;
	}
	return false;
}

var calendarWindow;
function openCalendarWindow (url) {
	if (!calendarWindow || calendarWindow.closed) {
		calendarWindow = window.open(url,'calendarWindow','width=725,height=320,left=400,top=360,scrollbars=yes,resizeable=yes');

	} else {
		calendarWindow.focus();
		calendarWindow.resizeTo(725,320);
		calendarWindow.location.href=url;
	}
	return false;
}

function markCheckbox (id) {
	var box  = document.getElementById('checkbox_' + id);
	var cell = document.getElementById('tab_cell_' + id);
	cell.style.background = box.checked ? '#ffff80' : '#ffffff';
}

function setOpenerIframeSrc(id, height, width, src) {
	var iframe = opener.document.getElementById(id + "_iframe");
	if (iframe) {
		iframe.src = src;
	} else {
		appendOpenerIframe(id, height, width, src);
	}
	return false;
}

function appendOpenerIframe (id, height, width, src) {
	var parent = opener.document.getElementById(id);
	var iframe = opener.document.createElement("iframe");
	iframe.setAttribute("id", id + "_iframe");
	iframe.setAttribute("height", height);
	iframe.setAttribute("width", width);
	iframe.setAttribute("src", src);
	parent.appendChild(iframe);
}

function removeIframe (id) {
	var parent = document.getElementById(id);
	var iframe = document.getElementById(id + "_iframe");
	if (iframe) parent.removeChild(iframe);
	return false;
}


//######################## DROPDOWN ###########################
var dd_supported     = false;
var dd_menuEl        = null;
var dd_submenuEls    = new Array();
var dd_activeSubmenu = false;
var dd_hideTimer     = null;

function dd_init() {
  if (!document.getElementById) return;
  dd_menuEl = document.getElementById('dd');
  if (!dd_menuEl) return;
  dd_supported = true;
  dd_addBasicMouseHandlers(dd_menuEl.getElementsByTagName('A'));
  dd_findSubmenuElemens(dd_menuEl);
}

function dd_findSubmenuElemens(elem) {
  if (!dd_supported) return;
  var elems = elem.childNodes;
  //alert("länge-elems: "+elems.length);
  for (var i = 0; i < elems.length; i++) {
    var node = elems[i];
    if (node.nodeName != 'TD') continue;
    var submenu = node.getElementsByTagName('UL');
    if (submenu.length > 0) {
      dd_submenuEls[i] = submenu[0];
    }
    dd_addMouseHandlers(node, i);
  }
}

function dd_addMouseHandlers(elem, index) {
  if (!dd_supported) return;
  var elems = elem.childNodes;
  for (var i = 0; i < elems.length; i++) {
    var node = elems[i];
    if (node.nodeName == 'A') {
      node.onmouseover = new Function('dd_SubmenuMouseOverHandler(' + index + ')');
    }
  }
}

function dd_addBasicMouseHandlers(elems) {
	//alert("dm: "+elems.length);
  for (var i = 0; i < elems.length; i++) {
    var node = elems[i];
    node.onmouseover = dd_BasicMouseOverHandler;
    node.onmouseout  = dd_BasicMouseOutHandler;
  }
}

function dd_SubmenuMouseOverHandler(index) {
  if (!dd_supported) return;
  //alert("dm: "+dd_hideTimer);
  if (dd_hideTimer) {
    window.clearTimeout(dd_hideTimer);
    dd_hideTimer = null;
  }
  for (var i = 0; i < dd_submenuEls.length; i++) {
    if (i == index) continue;
    if (!dd_submenuEls[i]) continue;
    dd_submenuEls[i].style.visibility = 'hidden';
  }
  dd_activeSubmenu = index;
  if (dd_submenuEls[index]) dd_submenuEls[index].style.visibility = 'inherit';
}

function dd_BasicMouseOutHandler() {
  if (!dd_supported) return;
  if (dd_hideTimer)  return;
  dd_hideTimer = window.setTimeout('dd_hideSubmenu(' + dd_activeSubmenu + ')', 300);
}

function dd_BasicMouseOverHandler() {
  if (!dd_supported) return;
  if (!dd_hideTimer) return;
  window.clearTimeout(dd_hideTimer);
  dd_hideTimer = null;
}
 
function dd_hideSubmenu(index) {
  if (!dd_supported) return;
  if (!dd_submenuEls[index]) return;
  dd_submenuEls[index].style.visibility = 'hidden';
}

//################### ENDE DROPDOWN #########################//

//################### LANDKARTEN ... #######################//
function schieben(nummer) {
	position = nummer * 200 * (-1);
	document.getElementById("aktkarte").style.left = position+"px";
}

function schieben_events_close_by_400(nummer) {
	position = nummer * 190 * (-1);
	document.getElementById("events_close_by_400_all").style.left = position+"px";
}

function schieben_gastros_close_by_400(nummer) {
	position = nummer * 190 * (-1);
	document.getElementById("gastros_close_by_400_all").style.left = position+"px";
}

function schieben_user_memory(nummer) {
	position = nummer * 190 * (-1);
	document.getElementById("user_memory_all").style.left = position+"px";
}

function moveleft(nummer) {
	position = nummer * 200 * (-1);
	document.getElementById("aktkarte").style.left = position+"px";
}

function senden() {
	document.f.submit();
}

//################### ENDE LANDKARTEN #########################//


//################### SUCHFUNKTIONEN ###########################//
function search_change_state() {
	x = 0;
	//subsel löschen 
	for (j=0;j<document.forms[0].fstate_sel.length;j++) {
		try { 
			document.forms[0].fstate.remove(document.forms[0].fstate.options[j]); // firefox 
		} catch (ex) { 
			document.forms[0].fstate.remove(j); // ie 
		} 
	}
	// 0 - Wert einfügen
	state('','(alle)',0,x);
	x++;
	//Überprüfen
	for (i=0;i<document.forms[0].fcountry.length;i++) {
		if (document.forms[0].fcountry.options[i].selected==true) {
			wert =  document.forms[0].fcountry.options[i].value;
			for (j=0;j<document.forms[0].fstate_sel.length;j++) {
				state_value = document.forms[0].fstate_sel.options[j].value;
				//alert(j+" --- Regionen gesamt: "+document.f.region_sel.length+"    value: "+region_value);
				wortlaut = document.forms[0].fstate_sel.options[j].text;
				//Format: 1_2 ---> "country_id"_"state_id" (==> Österreich_Niederösterreich)
				akt_werte = state_value.split("_");
				sele=0;
				if (document.forms[0].fstate_sel.options[j].selected==true) sele=1;
				if (akt_werte[0]==wert) {
					state(akt_werte[1],wortlaut,sele,x);
					x++;
				}
			}
		}
	}
}

 
function state(wert, wortlaut, sele, x) {
	state_option = document.createElement('option'); 
	
	state_option.text = wortlaut; 
	state_option.id = wert;
	state_option.value = wert;
	
 
	//alert(state_option.text+"("+state_option.value+"): "+"("+state_option.id+"): "+state_option.selected);
	try {
		document.forms[0].fstate.add(state_option, document.forms[0].fstate.options[x]); // firefox 
	} catch (ex) { 
		document.forms[0].fstate.add(state_option, (x)); // ie 
	}
	
	if (sele==1) {
		//if (sele==1) fstate2_option.selected = true;
		document.forms[0].fstate.options[x].selected = true;
		//alert(x);
	}
}


function search_change_county() {
	x = 0;
	country = document.forms[0].fcountry.value;

	//subsel löschen 
	for (j=0;j<document.forms[0].fcounty_sel.length;j++) {
		try { 
			document.forms[0].fcounty.remove(document.forms[0].fcounty.options[j]); // firefox 
		} catch (ex) { 
			document.forms[0].fcounty.remove(j); // ie 
		} 
	}
	// 0 - Wert einfügen
	county('','(alle)',0,x);
	x++;
	//Überprüfen
	for (i=0;i<document.forms[0].fstate.length;i++) {
		if (document.forms[0].fstate.options[i].selected==true) {
			wert =  document.forms[0].fstate.options[i].value;
			for (j=0;j<document.forms[0].fcounty_sel.length;j++) {
				county_value = document.forms[0].fcounty_sel.options[j].value;
				//alert(j+" --- Regionen gesamt: "+document.f.region_sel.length+"    value: "+region_value);
				wortlaut = document.forms[0].fcounty_sel.options[j].text;
				//Format: 1_2_19 ---> "country_id"_"state_id"_"county_id" (==> Österreich_Niederösterreich_Waidhofen/Thaya)
				akt_werte = county_value.split("_");
				//if (j<5) alert(akt_werte[0]+"_"+akt_werte[1]+"=="+country2+"_"+wert);
				sele=0;
				if (document.forms[0].fcounty_sel.options[j].selected==true) sele=1;
				if ((akt_werte[0]+"_"+akt_werte[1])==(country+"_"+wert)) {
					county(akt_werte[2],wortlaut,sele,x);
					x++;
				}
			}
		}
	}
	state3 = document.forms[0].fstate.value;
	county3 = document.forms[0].fcounty.value;
	//alert("Land: "+country2+"\n\rBundesland: "+state3+"\n\rCounty: "+county3);
}

function county(wert, wortlaut, sele, x) {
	county_option = document.createElement('option'); 
	
	county_option.text = wortlaut; 
	county_option.id = wert;
	county_option.value = wert;
 
	//alert(county_option.text+"("+county_option.value+"): "+county_option.selected);
	try {
		document.forms[0].fcounty.add(county_option, document.forms[0].fcounty.options[x]); // firefox 
	} catch (ex) { 
		document.forms[0].fcounty.add(county_option, (x)); // ie 
	}
	//if (sele==1) fcounty2_option.selected = true;
	if (sele==1) document.forms[0].fcounty.options[x].selected = true;
}
//################ ENDE SUCHFUNKTIONEN #########################//


//################### GOOGLE-MAP .... #########################//
var map;
var geocoder;
var icon;

function initialize() {
	map = new GMap2(document.getElementById("kartenuebersicht"));
	map.setCenter(new GLatLng(document.f2.q2.value, document.f2.q1.value), 5);
	geocoder = new GClientGeocoder();
	
	icon = new GIcon();
	icon.image = "/img/all/icon.googlemap.pointer.png";
	icon.shadow = "/img/all/icon.googlemap.shadow.png";
	icon.iconSize = new GSize(32, 32);
	icon.shadowSize = new GSize(50, 32);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
}

function addAddressToMap(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		point = new GLatLng(document.f2.q2.value,document.f2.q1.value);
		map.setCenter(new GLatLng(document.f2.q2.value, document.f2.q1.value), 10);
	} else {
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
		map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 10);
	}
	marker = new GMarker(point, icon);
	map.addOverlay(marker);
	_mPreferMetric = true;
	
	map.addControl(new GLargeMapControl3D());
	//map.addControl(new GOverviewMapControl());
	map.addControl(new GScaleControl());
	map.addControl(new GMapTypeControl()); 
	
	var publisher_id = "pub-4054499081432294";
	var adsManagerOptions = {maxAdsOnMap:1, style:'adunit', channel:'0770836849'};
	adsManager = new GAdsManager(map, publisher_id, adsManagerOptions);
	adsManager.enable();
}


function inputCheck(feld, okfeld, verify, min_len) {
	var eingabe = document.getElementById(feld).value;
	regx = new RegExp(verify);
	if (feld!="mail") {
		if (eingabe.length >= min_len) {
			if (regx.test(eingabe)) document.getElementById(okfeld).src = "/img/all/form.verify.ok.gif";
		} else {
			document.getElementById(okfeld).src = "/img/all/form.verify.notok.gif";
		}
	} else {
		document.getElementById(okfeld).src = "/img/all/form.verify.notok.gif";
	}
	if (feld=="mail") {
		//if (echeck(eingabe)) document.getElementById(okfeld).src = "/img/all/form.verify.ok.gif";
		if (EMail(eingabe))  document.getElementById(okfeld).src = "/img/all/form.verify.ok.gif";
	}
}

function EMail(s) {
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function') {
		var b = new RegExp('abc');
		if(b.test('abc') == true) {a = true;}
	}
	if(a == true) {
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));
	} else {
		res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s.lastIndexOf('.') >= s.length-5);
	} return(res);
} 




function showLocation() {
	geocoder.getLocations(document.f2.q.value, addAddressToMap);
}
