// *******************************************************************************
//
// Collection of JavaScript functions.
// This library is included by those Topaustria pages that that use
// at least one function.
//
// *******************************************************************************

// General function used to warn about deletion (link will only be requested if user confirms).
// @param Seite - link to submition page.
function confirm_delete(Seite) {
	if (confirm("Eintrag wirklich löschen?")) location.replace(Seite);
}

// Opens the link in a new window. Used tipically for short help pages.
// @param Hilfeseite - link to help page.
function open_help(HilfeSeite) {
	helpWindow = window.open(HilfeSeite, "helpWindow", "width=280,height=400,left=500,top=100,scrollbars=yes");
	helpWindow.focus();
}

// Opens the link in a new window. Used tipically for News pages.
// @param NewsSeite - link to the News page.
function open_news(NewsSeite) {
	newWindow = window.open(NewsSeite,"newWindow","width=400,height=300,left=100,top=60,scrollbars=yes");
}

// Opens the link in a new window. Used tipically for Bildergallerie pages.
// @param  Bildergallerie 
function open_bild(BGSeite) {
	newWindow = window.open(BGSeite,"newWindow","width=650,height=620,left=100,top=100,scrollbars=yes");
}

// Selects all the elements of a SELECT input.
// @param yesorno - boolean value to specify if elements should be selected (true) or deselected (false).
function selectall(yesorno) {
	var sel = document.forms[0].elements[2];
	if (sel.type == "select-multiple") {
		for (i=0; sel.options[i]; i++) {
			sel.options[i].selected = yesorno;
		}
	}
}

// Checks the form and submits if ok or user confirms.
// Used on Rundbrief (to check completed fields).
function checkandsubmit() {
	var form = document.forms[0];
	if ((form.EmailBetreff.value!="" && form.EmailText.value!="") || confirm("Betreff oder Text leer!\nTrotzdem senden?")) {
		form.submit();
	}
}	

// Function to synchronize combos on the "Gruppen" admin page. Either Ort+Kat 
// or only ZKat is allowed to be set.
// @param combo - combo control that was changed. Function acts depending on 
//                which of the three combos was changed.
function comboChanged(combo) {
	var comboort = document.forms[0].elements[3];
	var combokat = document.forms[0].elements[4];
	var combozkat = document.forms[0].elements[5];
	//
	if (combo == combozkat) {
		if (combozkat.selectedIndex != 0) {
			comboort.selectedIndex = 0;
			combokat.selectedIndex = 0;
		}
	} else if (combo == comboort || combo == combokat) {
		if ((comboort.selectedIndex != 0) || (combokat.selectedIndex != 0)) {
			combozkat.selectedIndex = 0;
		}
	}
}

// Function called from "Lageplan einrichten" links
// @param id= dummy (e.g. xy) for pinpointing the user's position on the map
// @param id= ortID for pinpointing the Ort's position on the map
function open_Map(id) {
	newWindow = window.open("/topaustria/_lageplaene/index.php?edit="+id,"newWindow","width=620,height=600,left=300,top=100,scrollbars=yes");
	newWindow.focus();
}

// Replaces the current page with the Map24 page, transmitting the given parameters.
// @param aid - string  parameters of the map page.
function showMap(aid,typ) {
	if (aid!="0")
		window.location = "/topaustria/_lageplaene/index.php?aid="+aid+"&typ="+typ;
}

// Clears value of specified control. Used on forms where default value of
// textboxes must be emptied when user clicks them.
// @param obj - control (tipically a TEXT input).
// @param text - default text of this control. If equals current value, this 
//               value will be set to empty.
function clearOnFocus(obj, text) {
	if (obj.value == text) {
		obj.value = "";
	}
}

// Function used to refresh Ort combo when Reg combo changes.
// Values of RegArray must be provided (dinamically) by the page that uses this 
// function.
function changeReg() {
	var regionen = document.forms[0].reg;
	var orte = document.forms[0].ort;
	var OrtArray = RegArray[regionen.selectedIndex];
	//remove all Orte
	for (i=orte.options.length-1; i>=0; i--) {
		orte.options[i] = null;
	}
	//add Orte
	newOptionName = new Option("alle", "0", false, false);
	orte.options[0] = newOptionName; 
	for (i=0; i<OrtArray.length; i++) {
		newOptionName = new Option(OrtArray[i]);
		orte.options[i+1] = newOptionName; 
	}
}

// Used in Aufgliederung
function addOrt() {
	var oin = document.forms[0].ortein;
	var oout = document.forms[0].orteout;
	for (i=oout.options.length-1; i>=0; i--) {
		if (oout.options[i].selected) {
			newOptionName = new Option(oout.options[i].text, oout.options[i].value, false, false);
			oin.options[oin.options.length] = newOptionName; 
			oout.options[i] = null;
		}	
	}
}

// Used in Aufgliederung
function removeOrt() {
	var oin = document.forms[0].ortein;
	var oout = document.forms[0].orteout;
	for (i=oin.options.length-1; i>=0; i--) {
		if (oin.options[i].selected) {
			newOptionName = new Option(oin.options[i].text, oin.options[i].value, false, false);
			oout.options[oout.options.length] = newOptionName; 
			oin.options[i] = null;
		}
	}
}

// Used in Aufgliederung
function newOrt(){
	var oin = document.forms[0].ortein;
	for (i=0; i<=oin.options.length-2; i++) {
	document.forms[0].ortinreg.value=document.forms[0].ortinreg.value+oin.options[i].value+', ';
	}
	document.forms[0].ortinreg.value=document.forms[0].ortinreg.value+oin.options[i++].value;
}

// Used in Rundbrief for checking prior to send it
function checkandsubmit() {
	var form = document.forms[0];
	if ((form.EmailBetreff.value!="" && form.EmailText.value!="") || confirm("Betreff oder Text leer!\nTrotzdem senden?")) {
		form.submit();
	}
}

// Used to call the Uebersicht page for Ort, Region or Zkat
// @param Typ - ['ort', 'reg', 'zkat']
// @param id - Numeric code from ptl_adm (ptl_adm_ext) 
function uebersicht(typ,id){
	//confirm("typ="+typ+" id="+id);
	if (id>0)
		window.location = "../_urlaubsziele/uebersicht.php?tab="+typ+"&id="+id;
}


function openPictureWindow_Fever(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {  // v4.01
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	if (imageType == "swf"){
	newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');
	newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('</embed></object>');	}else{
	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 	}
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function route(server,sid,szip,scity,scountry,destination,type){

var parameters= "sid="+sid; 
if (szip!="" && szip!="PLZ")
	 parameters= parameters+ "&szip="+szip;
if (scity!="" && scity!="ORT")
	 parameters= parameters+ "&scity="+scity;
if (scountry!="")
	 parameters= parameters+ "&scountry="+scountry;
if (destination!="")
	 parameters= parameters+ destination+ "&dcountry=at";
if (type!="")
	 parameters= parameters+ "&type="+type;

window.scroll(0,0);
document.rc.src = "http://"+server+"/topaustria/_lageplaene/router.php?"+ parameters;
//prompt("route params.",document.rc.src);
}

// Show/Hide a DIV
function divis(divid)
{
  var divObj = null;
  //
  if (document.getElementById)
  {
    divObj = document.getElementById(divid);
  }
  else if (document.all)
  {
    divObj = document.all[divid];
  }
  else if (document.layers)
  {
    divObj = document.layers[divid];
  }
  //
  if (divObj != null)
  {
    if (divObj.style.display == 'block')
    {
      divObj.style.display = 'none';
    }
    else
    {
      divObj.style.display = 'block';
    }
  }
}


