function externalLinks() {
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
     var anchor = anchors[i];
     if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
   }
}

// ANTISPAM email links
function antispam_emails() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anc = anchors[i];
        if ((email = anc.getAttribute("href")) && anc.getAttribute("type") == "antispam") {
			var vsebina = anc.innerHTML;
            // replacamo vsebino in link
            anc.href = antispam_replace(email);
            anc.innerHTML = antispam_replace(vsebina);
        }
    }
}
   
// funkcija za replace [AFNA] in [PIKA]
function antispam_replace(email) {
	var modified = email.replace(/%20/g, " "); // za IE
	modified = modified.replace(/ AFNA /g, "@");
	modified = modified.replace(/ PIKA /g, ".");
	return modified;
}

String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}

function isEmail(str) {
    
	var supported = 0;
	if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}  
	  
function contactCheck() {	//newsletter
	
	var form = document.getElementById('newslettersideboxform');
	if(!form) return;

	form.onsubmit = function() {

		/*
		var polje = document.getElementById("email");

		if (!isEmail(polje.value)) {
			var vrni = false;
			polje.style.cssText = 'border: 1px solid red; width:140px; margin-left:11px;';	
		}
		else { 
			polje.style.cssText = 'width:140px; margin-left:11px;';	
			var vrni = true;
		}
		*/
		
		var vrni = true;//brez validacije
		
		//ce je vse ok submitamo formo	
		if(vrni == true)
		{
			document.newslettersideboxform.action = 'e_novice';
			document.newslettersideboxform.submit();
		}
	return void(0);
	}
}



//stran - spremenljivka, ki nam pove iz katere strani je bil parametre poslan (TUI Potovalni center ali Sonček)

function Send(page, searchtyp) {
		
		//alert(page);
		
		//alert(searchtyp);
		
		//preverimo stranko. Če ni pravilnega parametra=adijo
		if (page == 'soncek') {
			var domain = 'www.ors.si/ibe/agencije/soncek';
		} else if (page == 'tui') {
			var domain = 'tuipotovalnicenter.ors.si';
		} else {
			return(0);
		}
		
		//preverjamo pravilne oz. dovoljene tipe. Če ni pravilnega=adijo
		if (searchtyp == 'form_pauschal') {
			var form_name = document.form_pauschal;
			var typ = document.form_pauschal.typ.value;
			var ahc = form_name.ahc.value; //odhodna letališča
		} else if (searchtyp == 'form_linienflug') {
			var typ = document.form_linienflug.typ.value;	
			var form_name = document.form_linienflug;
		} else if (searchtyp == 'form_eigenanreise') {
			var typ = document.form_eigenanreise.typ.value;	
			var form_name = document.form_eigenanreise;
			var ahc = form_name.ahc.value; //odhodna letališča
		} else {
			return(0);	
		}
		
	
		var zhc = form_name.zhc.value; // kraj potovanja
		var ktag = form_name.ktag.value; //dan odhoda
		var kmonat = form_name.kmonat.value; //mesec in leto odhoda
		
		var rueckktag = form_name.rueckktag.value; //dan povratka
		var rueckkmonat = form_name.rueckkmonat.value; //mesec in leto povratka
		//iz zgornji datumov sestavimo datumski format za ORS
		var vnd = kmonat + "-" + ktag; // spremenimo datum v format  2008-12-05
		var bsd = rueckkmonat + "-" + rueckktag; // spremenimo datum v format  2008-12-05
		
		var tdc = form_name.tdc.value; //trajanje

		window.location ="http://" + domain + "/search.php?ahc=" + ahc + "&zhc=" + zhc + "&vnd=" + vnd + "&bsd=" + bsd + "&tdc=" + tdc + "&typ=" + typ;

		return(0);

}


function contactCheck_kontakt() {
	
		var form = document.getElementById('pobuda_form');
	
		var obvezna = ["pobuda_ime", "pobuda_priimek", "pobuda_telefon", "pobuda_zadeva", "pobuda_besedilo"]; //pobuda_email preverjam posebaj
		// if something went wrong
		if(!form) return;
		
		form.onsubmit = function() {
			// for testing ONLY
			//return true;
			
			var vrni = true;
			
			var polje = document.getElementById("pobuda_email");
	
			if (!isEmail(polje.value)) {
				vrni = false;
				polje.style.cssText = 'border: 1px solid red;';
			}
			else {
				polje.style.cssText = '';
			}
			
			for(var i in obvezna) {
				var polje = document.getElementById(obvezna[i]);
				if(polje.value.trim().length < 2) {
					vrni = false;
					if (document.getElementById('pobuda_besedilo')) {
						polje.style.cssText = 'border: 1px solid red;';
					} else {
						polje.style.cssText = 'border: 1px solid red;';
					}
					
				} else polje.style.cssText = '';
			}
			//ce je vse ok submitamo formo	
			if(vrni == true)
			{
				document.pobuda_form.action = '/_action/pobude.php';
				//document.pobuda_form.submit();
				
				//onemogočimo gumb, da preprečimo večkratno pošiljanje forme
				var btnSubmit = document.getElementById("btnSubmit");
				btnSubmit.disabled=true;
			}
		return void(0);
		}
	}

/*		Posebna ponudba		*/
/*################################################################################################################*/

function show_podrobnosti(id, span) {
	var text = document.getElementById(span);
	if(document.getElementById(id)) {
      var obj = document.getElementById(id);
      if(obj.style.display != 'block'){
        obj.style.display = 'block';
		text.innerHTML = 'Skrij obračun rezervacije &raquo;';
      } else {
		obj.style.display = 'none';
		text.innerHTML = 'Prikaži obračun rezervacije &raquo;';
	  }
      return true;
    }
}






function show_cat(id) {
	if(document.getElementById(id)) {
      var obj = document.getElementById(id);
      if(obj.style.display != 'block'){
        obj.style.display = 'block';		
      } else {
		obj.style.display = 'none';
	  }
      return true;
    }
}


function validacija_termina() {
	var odhod_iz = document.getElementById("odhod_iz");
	var trajanje = document.getElementById("trajanje");
		
	if(odhod_iz.value == 0) {
		alert("Izberite Odhod iz!");
		return;
	}
	
	if(trajanje.value == 0) {
		alert("Izberite datum odhoda!");
		return;
	}
	
	var id_potniki = document.getElementById("id_potniki");
	var id_termin = document.getElementById("id_termin");
	var odhod_iz = document.getElementById("odhod_iz");
	var trajanje = document.getElementById("trajanje");
	var storitev = document.getElementById("storitev");
	
	if(id_termin.innerHTML == "Naprej") {
		id_termin.innerHTML = "Spremeni";
		id_potniki.style.display = 'block';
		odhod_iz.setAttribute('disabled','disabled');
		trajanje.setAttribute('disabled','disabled');
		storitev.setAttribute('disabled','disabled');
		
		var osebe = getOsebe(trajanje.value);
		dodaj_odrasle(osebe[1]);
		var ni = document.getElementById('div_otroci');
		ni.innerHTML = "";
	
	} else if(id_termin.innerHTML = "Spremeni") {
		id_termin.innerHTML = "Naprej";
		id_potniki.style.display = 'none';
		
		var potniki = document.getElementById("potniki");
		var odrasli = document.getElementById("odrasli");
		var otroci = document.getElementById("otroci");
		
		potniki.removeAttribute('disabled');
		odrasli.removeAttribute('disabled');
		otroci.removeAttribute('disabled');
		removeAllOptions(otroci);
			
		
		odhod_iz.removeAttribute('disabled');
		trajanje.removeAttribute('disabled');
		storitev.removeAttribute('disabled');
	}
}

function dodaj_odrasle(st_odraslih) {
	//napolni selectbox odrasli

	var selectbox = document.getElementById('odrasli');
	removeAllOptions(selectbox);
	addOption(selectbox,'-','0');
	for(i=2;i<=st_odraslih;i++){
		addOption(selectbox,i,i);
	}
}

function dodaj_otroke() {
	//doda otroke
	var odraslih = document.getElementById('odrasli').value;
	if(odraslih < 2) {
		alert("Minimalno 2 odrasli osebi.");
		return;
	}
	
	var ni = document.getElementById('div_otroci');
	ni.innerHTML = "";
		
	var otroci = document.getElementById('otroci');
	var trajanje = document.getElementById("trajanje");
	var osebe = getOsebe(trajanje.value);
	
	var max_oseb = osebe[0];
	var max_odraslih = osebe[1];
		
	
	var dodaj_otrok = (max_oseb - max_odraslih) + (max_odraslih - odraslih);
	
	removeAllOptions(otroci);
	addOption(otroci,'-','0');
	for(i=1;i<=dodaj_otrok;i++){
		addOption(otroci,i,i);
	}
}

function dodaj_obrazec_starost_otroci() {
//zaklene odrasle
	var odrasli = document.getElementById('odrasli');

	if(odrasli.value == 0) {
		alert("Minimalno 1 odrasla oseba!");
		return false;
	}
	//odrasli.setAttribute('disabled','disabled');
	
	var otrok = document.getElementById("otroci").value;
	var ni = document.getElementById('div_otroci');
	var inner = "";
	
	for(i=1;i <= otrok;i++){	
		inner = inner + 'Starost v letih <input type="text" class="input_size_30" id="otrok_'+i+'" name="otrok_'+i+'"/><br />';
	}
	ni.innerHTML = inner;
}

function dodaj_obrazec_starost_dojencki() {
	var otrok = document.getElementById("dojencki").value;
	var ni = document.getElementById('div_dojencki');
	var inner = "";
	for(i=1;i <= otrok;i++){
		inner = inner + 'Starost v mesecih <input type="text" class="input_size_30" id="dojencek_'+i+'" name="dojencek_'+i+'"/><br />';
	}
	ni.innerHTML = inner;
}

function getOsebe(id) {

	var page = "/_include/getOsebe.php?id="+id;
	
	var stuff = '';
	loadXMLPosDoc(page,stuff); // TODO

	var osebe = new Array(grabPosXML('oseb'), grabPosXML('odrasli'));
	return osebe;
}

function getOtroci_starost(id) {
	var page = "/_include/getOtroci_starost.php?id="+id;
	
	var stuff = '';
	loadXMLPosDoc(page,stuff); // TODO

	var starost = new Array(grabPosXML('min1'), grabPosXML('max1'),grabPosXML('min2'),grabPosXML('max2'));
	return starost;	
}

function getDelo_izkaznica(id) {

	var page = "/_include/getDelo_izkaznica.php?id_izkaznice="+id;
	
	var stuff = '';
	loadXMLPosDoc(page,stuff); // TODO

	var v_seznamu = grabPosXML('status');
	if(v_seznamu > 0)
		return true;
	else return false;
}

function validacija_osebe() {
	
	var trajanje = document.getElementById("trajanje");
	var starost = getOtroci_starost(trajanje.value);
	//min1,max1,min2,max2
	//če ni vpisane starosti dobim vrnjeno 0
	//alert(starost);
	
	
//	var potniki = document.getElementById("potniki");
	var odrasli = document.getElementById("odrasli");
	var otroci = document.getElementById("otroci");
	var dojencki = document.getElementById("dojencki");

//	var podatki = document.getElementById("podatki");
//	if(potniki.innerHTML == "Naprej")
	
	if(odrasli.value == 0) {
		alert("Minimalno 2 odrasli osebi.");
		return;
	}

	for(i=1;i<=otroci.value;i++) {
		var dis = document.getElementById("otrok_"+i);
		
		if (dis.value == "") {
			alert("Vpišite starost " +i+". otroka!");
			return;	
		}
		
		if(!_isInteger(dis.value)) {
			alert("Vpišite starost otroka v celih številih!");
			return;	
		}
		
		if(i == 1) {
			if(dis.value < parseInt(starost[0]) || dis.value >= parseInt(starost[1])) {
				alert("Starost 1. otroka ne ustreza pogojem!");
				return;
			}
		}
		if(i == 2) {
			if(dis.value < parseInt(starost[2]) || dis.value >= parseInt(starost[3])) {
				alert("Starost 2. otroka ne ustreza pogojem!");
				return;
			}
		}
		
	}
	
	for(i=1;i<=dojencki.value;i++) {
		var dis = document.getElementById("dojencek_"+i);
		if (dis.value == "") {
			alert("Vpišite starost " +i+". dojenčka!");
			return;	
		}
		if (dis.value > 23) {
			alert("Dojenček je lahko star največ 23 mesecev!");
			return;		
		}
		if(!_isInteger(dis.value)) {
			alert("Vpišite starost dojenčka v celih številih!");
			return;	
		}
	}
	
	var odhod_iz = document.getElementById("odhod_iz");
	var trajanje = document.getElementById("trajanje");
	var storitev = document.getElementById("storitev");

	odhod_iz.removeAttribute('disabled');
	trajanje.removeAttribute('disabled');
	storitev.removeAttribute('disabled');
	
	var id = document.getElementById("id").value;

//	redirect
	// v primeru ko zaganjamo posebno ponudbo za pop, tuš
	//var ifpop = document.getElementById("ifpop").value;
	//id_iserja na katerega so vezane vse nastavitve
	var us = document.getElementById("us").value;
	
	//if (ifpop == 1 || us != 0) {
	if (us != 0) {
		if (us == 34) {
			document.osebe.action = '/export_ponudbe/index.php?us='+ us +'&id='+id+'&korak=2#scroll';
		} else {
			document.osebe.action = '/export_ponudbe/index.php?us='+ us +'&id='+id+'&korak=2';
		}
		
		/*document.osebe.action = '/_sites/posebna_ponudba.php?id='+id+'&korak=2&pop=1';*/
	} else {
		document.osebe.action = '/posebna_ponudba?id='+id+'&korak=2';	
	}
	
	
	document.osebe.submit();
}


function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
}
	
function rezervacija() {
	

	var form = document.getElementById('rezervacija');
	if(!form) return;

		var odraslih = document.getElementById("potnik_stevilo").value;
		var otrok = document.getElementById("otrok_stevilo").value;
		var dojenckov = document.getElementById("dojencek_stevilo").value;

//		vseh_potnikov = parseInt(odraslih) + parseInt(otrok) + parseInt(dojenckov);

		var i = 6 + (parseInt(odraslih)*2) + (parseInt(otrok)*2) + (parseInt(dojenckov)*2);
		var j = parseInt(otrok) + parseInt(dojenckov);
		
		var obvezna_starost = new Array(j);
		var obvezna_rojen = new Array(j);

		var obvezna = new Array(i);
		obvezna[0] = "placnik_ime"; 
		obvezna[1] = "placnik_priimek";
		obvezna[2] = "placnik_uica";
		obvezna[3] = "placnik_posta";
		obvezna[4] = "placnik_drzava"; 
		obvezna[5] = "placnik_telefon";
		
		var polj = 6;
		var polj_starost = -1;
		var polj_rojen = -1;	//preverjam datume rojstev
		
		//odrasli: ime, priimek
		//ostali: ime, priimek, starost
		for(i_odr=1; i_odr<=odraslih; i_odr++) {
			polj++;
			obvezna[polj] = 'potnik_'+i_odr+'_ime';
			polj++;
			obvezna[polj] = 'potnik_'+i_odr+'_priimek';
		}
		
		for(i_otr=1; i_otr<=otrok; i_otr++) {
			polj++;
			obvezna[polj] = 'otrok_'+i_otr+'_ime';
			polj++;
			obvezna[polj] = 'otrok_'+i_otr+'_priimek';
			
			polj_starost++;
			obvezna_starost[polj_starost] = 'otrok_'+i_otr+'_starost';
			polj_rojen++;
			obvezna_rojen[polj_rojen] = 'otrok_'+i_otr+'_rojen';
			
		}
		
		for(i_doj=1; i_doj<=dojenckov; i_doj++) {
			polj++;
			obvezna[polj] = 'dojencek_'+i_doj+'_ime';
			polj++;
			obvezna[polj] = 'dojencek_'+i_doj+'_priimek';
	
			polj_starost++;
			obvezna_starost[polj_starost] = 'dojencek_'+i_doj+'_starost';
			
			polj_rojen++;
			obvezna_rojen[polj_rojen] = 'dojencek_'+i_doj+'_rojen';
		}
		
		
		
		//placnik_email preverjam posebaj
		// if something went wrong

		form.onsubmit = function() {
			
			// for testing ONLY
			//return true;
			
			var vrni = true;
				
			var polje = document.getElementById("placnik_email");
			if (!isEmail(polje.value)) {
				vrni = false;
				polje.style.cssText = 'border: 1px solid red;';
			}
			else {
				polje.style.cssText = '';
			}

/**********************************************************************************/
//preverjanje postne stevilke

			var polje = document.getElementById("placnik_postna_st");
			if((polje.value.trim().length < 1) || !_isInteger(polje.value)) {
				vrni = false;
				polje.style.cssText = 'border: 1px solid red;';
			} else 
				polje.style.cssText = '';
/**********************************************************************************/

			
			/*for(var ro in obvezna_rojen) {
				var polje = document.getElementById(obvezna_rojen[ro]);
				
				alert(obvezna_rojen[ro]);
				return(0);
				
				
				if(!isDate(polje.value,'d.M.yyyy')) {
					vrni = false;
					polje.style.cssText = 'border: 1px solid red;text-align:right;width:89px;';
				} else polje.style.cssText = 'text-align:right;width:89px;';
			}
			*/
			
			for(var i in obvezna) {
				var polje = document.getElementById(obvezna[i]);

				if(polje.value.trim().length < 2) {
					vrni = false;
					polje.style.cssText = 'border: 1px solid red;';
				} else polje.style.cssText = '';
			}
			
			for(var k in obvezna_starost) {
				var polje = document.getElementById(obvezna_starost[k]);
				if((polje.value.trim().length < 1) || !_isInteger(polje.value)) {
					vrni = false;
					polje.style.cssText = 'border: 1px solid red;';
				} else polje.style.cssText = '';
			}
/***********************************************************************************
Preverjanje datuma rojstva plačnika*/

			var datum_rojstva_placnik = document.getElementById("placnik_datum_rojstva");
			
			if (!isDate(datum_rojstva_placnik.value,'d.M.yyyy')) {
				vrni = false;
				datum_rojstva_placnik.style.cssText = 'border: 1px solid red; width:90px';
			}
			else datum_rojstva_placnik.style.cssText = 'width:90px';
/************************************************************************************/			

			// validiranje naročniške stevike za tus in delo. 
			var valid_n_stevilka = document.getElementById("valid_n_stevilka");
			//za primer tuša, ki
			if (valid_n_stevilka.value == 34) {
				//validiramo alhko samo takrat, ko je polje prikazano
				var placnik_n_stevilka = document.getElementById("placnik_n_stevilka");
				if (placnik_n_stevilka.value.trim().length < 1) {
					vrni = false;
					placnik_n_stevilka.style.cssText = 'border: 1px solid red;';
				} else {
					placnik_n_stevilka.style.cssText = '';
				}

			} else if (valid_n_stevilka.value == 103) {
				
				//tu se proži preverjanje klubskih številk
				
				var placnik_n_stevilka = document.getElementById("placnik_n_stevilka");
				if(!getDelo_izkaznica(placnik_n_stevilka.value)) {
					placnik_n_stevilka.style.cssText = 'border: 1px solid red;';
					alert("Vnesena je napačna naročniška številka. \nProsimo vnesite jo ponovno.");
					return;
				} else {
					placnik_n_stevilka.style.cssText = '';	
				}
			}
			
			



			//var potrditev = document.getElementById("placnik_potrditev");
			if(!document.rezervacija.potrditev.checked) {
				alert("Strinjati se morate s splošnimi pogoji.");
			return;
			}
			
			if(!document.rezervacija.potrditev_cepljenja.checked) {
				alert("Strinjati se morate, da ste seznanjeni z informacijami o vizumih in zdravstveni zaščiti (cepljenja...).");
			return;
			}
				
			//ce je vse ok submitamo formo	
			if(vrni == true)
			{

				document.rezervacija.action = '/_action/ponudba_rezervacija.php';		
				//document.rezervacija.submit();
				//onemogočimo gumb, da preprečimo večkratno pošiljanje forme
				var btnSubmit = document.getElementById("btnSubmit");
				btnSubmit.disabled=true;		

			}
			
		return void(0);
		}	
}
	
function CheckRegion() {
	
	var form = document.getElementById('iskalnik1');
	var vrni = false;
	if(!form) return;
	
	form.onsubmit = function() {
		
		var polje = document.getElementById("regija");

		if (polje.value != "-1") {
			vrni = true;
		}
		//ce je vse ok submitamo formo	
		if(vrni == true)
		{
			//alert("korak 3");
			document.iskalnik1.action = '/?iskalnik=1&korak=3&regija='+ polje.value;
			
		} else {
			document.iskalnik1.action = '/?iskalnik=1&korak=2';
			//alert("korak 3");
		} 
		
		document.iskalnik1.submit();
	return void(0);
	}
}

function CheckRegion_letalo() {
	
	var form = document.getElementById('letalski_prevoz_iskanje');
	var vrni = false;
	if(!form) return;
	
	form.onsubmit = function() {
		
		var polje = document.getElementById("regija");

		if (polje.value != "-1") {
			vrni = true;
		}
		//ce je vse ok submitamo formo	
		if(vrni == true)
		{
			//alert("korak 3");
			document.letalski_prevoz_iskanje.action = '/?iskalnik=1&korak=3&regija='+ polje.value;
			
		} else {
			document.letalski_prevoz_iskanje.action = '/?iskalnik=1&korak=2';
			//alert("korak 3");
		} 
		
		document.letalski_prevoz_iskanje.submit();
	return void(0);
	}
}

		
function contactCheck_enovice() {

	var form = document.getElementById('enovice_form');

	var obvezna = ["enovice_name"]//, "enovice_email", "enovice_telefon", "enovice_naslov", "enovice_posta", "enovice_kraj"]; 
	// if something went wrong
	if(!form) return;
	
	form.onsubmit = function() {
		// for testing ONLY
		//return true;
		
		var vrni = true;
			
		var polje = document.getElementById("enovice_email");

		if (!isEmail(polje.value)) {
			vrni = false;
			polje.style.cssText = 'border: 1px solid red;';
		}
		else {
			polje.style.cssText = '';
		}

		for(var i in obvezna) {
			var polje = document.getElementById(obvezna[i]);
			if(polje.value.trim().length < 2) {
				vrni = false;
				polje.style.cssText = 'border: 1px solid red;';
			} else polje.style.cssText = '';
		}
		//ce je vse ok submitamo formo	
		if(vrni == true)
		{
			document.enovice_form.action = '/_action/enovice.php';
			//document.enovice_form.submit();
			
			var btnSubmit = document.getElementById("btnSubmit");
			btnSubmit.disabled=true;
		}
	return void(0);
	}
}


// onload
 function funkcije() {

	antispam_emails();
	externalLinks();
	contactCheck();
	rezervacija();
	
	//iskanje, 1. korak
	if(document.getElementById('iskalnik1')) CheckRegion();	
	//letalski prevozi
	if(document.getElementById('letalski_prevoz_iskanje')) CheckRegion_letalo();
	
	//se zazene na strani e-novice
	if(document.getElementById('enovice_form')) contactCheck_enovice();
	//se zazene na strani kontakt
	if(document.getElementById('pobuda_form')) contactCheck_kontakt();
	//rezervacija termina, 5. korak
	if(document.getElementById('form_rezervacija')) contactCheck_rezervacija();
	
	
}

/*#############################################################################################*/
//pridobivanje terminov
// Ajax nabor terminov
function getTermini(id, kraj) {
	if(kraj == 0) return;
	kraj= encodeURIComponent(kraj);
	selectboxId = "trajanje";
	
	var selectbox = document.getElementById(selectboxId);	
	if (id == 0) {
		removeAllOptions(selectbox);
		addOption(selectbox,'Ni zapisov','');
	} else {	
		var page = "/_include/getTermini.php?id="+id+"&q="+kraj;
		
		var stuff = '';
		loadXMLPosDoc(page,stuff); // TODO
		var vsehTerminov = grabPosXML('status');

		removeAllOptions(selectbox);
		addOption(selectbox,'--Izberi--','0');
		
		if (grabPosXML('selected') != 'null') {
			var selected = grabPosXML('selected');
		}
		
		var str_datum_odhoda = document.getElementById("str_datum_odhoda");
		if(vsehTerminov == 1) {
			str_datum_odhoda.innerHTML = "Datum odhoda: ";
		} else if(vsehTerminov == 2) {
			str_datum_odhoda.innerHTML = "Datuma odhodov: ";
		} else if(vsehTerminov > 2) {
			str_datum_odhoda.innerHTML = "Datumi odhodov: ";
		}
		
		
		for(i=1;i<=vsehTerminov;i++) {
			if (selected /*== grabPosXML('termin_uri_' + i)*/) {
				addOption(selectbox,grabPosXML('termin_termin_' + i),grabPosXML('termin_uri_' + i),selected);
			} else {
				addOption(selectbox,grabPosXML('termin_termin_' + i),grabPosXML('termin_uri_' + i),null);
			}
		}						
		
	}
}

/*#############################################################################################*/






//pridobivanje regij
// Ajax nabor obin
function getRegije(id) {
	
	selectboxId = "regija";
	
	var selectbox = document.getElementById(selectboxId);	
	if (id == 0) {
		removeAllOptions(selectbox);
		addOption(selectbox,'Ni zapisov','');
	} else {	
		var page = "/_include/getRegije.php?q="+id;
		
		var stuff = '';
		loadXMLPosDoc(page,stuff); // TODO
		var vsehObcin = grabPosXML('status');

		removeAllOptions(selectbox);
		addOption(selectbox,'--Izberi--','0');
		
		if (grabPosXML('selected') != 'null') {
			var selected = grabPosXML('selected');
		}
		
		for(i=1;i<=vsehObcin;i++) {
			if (selected == grabPosXML('podrocje_id_' + i)) {
				addOption(selectbox,grabPosXML('podrocje_title_' + i),grabPosXML('podrocje_id_' + i),selected);
			} else {
				addOption(selectbox,grabPosXML('podrocje_title_' + i),grabPosXML('podrocje_id_' + i),null);
			}
		}						
		
	}
}

// DOM - dodajanje/brisanje select opcij
function removeAllOptions(selectbox) {
	var i;
	for(i=selectbox.options.length-1;i>=0;i--) {
		selectbox.remove(i);
	}
}

function removeOptions(selectbox) {
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)	{
		if(selectbox.options[i].selected) {
			selectbox.remove(i);
		}
	}
}

function addOption(selectbox,text,value,selected) {
	var optn = document.createElement("OPTION");
	var id = value;
	var name = text;
	if (selected) {
		optn.selected = 'selected';
	}
	optn.text = name;
	optn.value = id;
	selectbox.options.add(optn);
}



function popup(url) {
	window.open(url, "myWindow", 
	"status = 1, height = 300, width = 600, resizable = 1" )
}


function show_cat(id) {
    if(document.getElementById(id)) {
      var obj = document.getElementById(id);
      if(obj.style.display != 'block'){
        obj.style.display = 'block';		
      } else {
		obj.style.display = 'none';
	  }
      return true;
    }
}

function popImage(imageURL,imageTitle){

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;


if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;


if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<a href="javascript:close()"><img name="George" src='+imageURL+' style="display:block" border="0"></a></body></html>');
close();		
}}


function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}
	
// date validation
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { 
		return false; 
	}
	return true;
}

function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
}

function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
