function confirm_delete() {
  if (confirm("Naozaj zmazať?") == true)
    return true;
  else
    return false;
}

function GetRadioValue(el){
	for (var i=0; i < el.length; i++) if (el[i].checked) return el[i].value;
}

function recount(){
	var price_eur = document.getElementById("cena_eur").value;
	var price_sk = document.getElementById("cena_sk");
	price_sk.value = Math.floor(price_eur * 30.126);
}

function popup(filename, x, y, next) {
	var path = '';
	if (navigator.appName.match(/Explorer/)) path = '../';
	window.open(path + 'image.php?file=' + filename + '&next=' + next,'','toolbar=no,scrollbars=no,location=no,status=no,width=' + x +',height=' + y + ',resizable=0');
}

function change_section(id){
	if (id == 1 || id == 2) {
		document.getElementById('typ_moto').style.display = ''; 
	} else {
		document.getElementById('typ_moto').style.display = 'none'; 
	}  
}

//----------- inzercia ------------------
function change_mfg(id){
	var sel = document.getElementById("rubrika");
	window.location='index.php?inzercia=add&mfg=' + id + '&rubrika=' + sel.options[sel.selectedIndex].value + '&meno=' + document.addinzerat.meno.value + '&mesto=' + document.addinzerat.mesto.value;
}

function change_mfg_upd(advid, id){
	var sel = document.getElementById("rubrika");
	window.location='index.php?inzercia=modify&id=' + advid + '&mfg=' + id + '&rubrika=' + sel.options[sel.selectedIndex].value + '&meno=' + document.addinzerat.meno.value + '&mesto=' + document.addinzerat.mesto.value;
}

function filter_chg_mfg(typ_vozidla){
	var vyrobca = document.getElementById("vyrobca");
	var c_min = document.getElementById('cena_min').value;
	var c_max = document.getElementById('cena_max').value;
	var rv = document.getElementById('rok').value;
	var stav = GetRadioValue(document.extended_search.stav);
	var sort = GetRadioValue(document.extended_search.sort);
	
	window.location = '?inzercia=view&hladaj=ext&typ_vozidla=' + typ_vozidla + '&vyrobca=' + vyrobca.options[vyrobca.selectedIndex].value + '&cena_min=' + c_min + '&cena_max=' + c_max + '&rok=' + rv + '&sort=' + sort + '&stav=' + stav;
}

function filter_chg_typ(vyrobca){
	var typ_vozidla = GetRadioValue(document.extended_search.typ_vozidla);
	var stav = GetRadioValue(document.extended_search.stav);
	var sort = GetRadioValue(document.extended_search.sort);
	var c_min = document.getElementById('cena_min').value;
	var c_max = document.getElementById('cena_max').value;
	var rv = document.getElementById('rok').value;

	window.location = '?inzercia=view&hladaj=ext&typ_vozidla=' + typ_vozidla + '&vyrobca=' + vyrobca + '&cena_min=' + c_min + '&cena_max=' + c_max + '&rok=' + rv + '&sort=' + sort + '&stav=' + stav;
}

function vynuluj_limit_ceny(){
	var c_min = document.getElementById('cena_min');
	var c_max = document.getElementById('cena_max');
	c_min.value = 0;
	c_max.value = 100000;
}

//----------- MX CUP ------------------

function fillNumbers(t){
	var master = document.mxcup_registracia.cislo;
	master.length = 0;
	var cl = window['sc' + t];
	for (i = 0; i < cl.length; i++) master.options[master.options.length] = new Option(cl[i], cl[i], 0, 0);
}

function updClass(){
	var t = document.mxcup_registracia.trieda.value;
	document.getElementById('extra_info').value = document.mxcup_registracia.trieda[t].title;
	fillNumbers(t);
}

function chkOnlineReg(){
	var f = document.mxcup_registracia;
	var m = 0; lr = '#FCC'; wh = '#FFF';
	if (f[0].value.length < 3){
		m++;
		c = lr;
	} else c = wh;
	f[0].style.backgroundColor = c;

	if (f[1].value.length < 4){
		m++;
		c = lr;
	} else c = wh;
	f[1].style.backgroundColor = c;

	if (f[3].value.length < 4){		//mesto
		m++;
		c = lr;
	} else c = wh;
	f[3].style.backgroundColor = c;

	if (f[4].value[4] != '-' && f[4].value[7] != '-'){		//datum narodenia
		m++;
		c = lr;
	} else c = wh;
	f[4].style.backgroundColor = c;

	if (f[5].value.length < 4){		//telefonne cislo
		m++;
		c = lr;
	} else c = wh;
	f[5].style.backgroundColor = c;

	if (f[6].value.length < 4){		//motocykel
		m++;
		c = lr;
	} else c = wh;
	f[6].style.backgroundColor = c;

	if (f[7].value.length < 10){	//VIN
		m++;
		c = lr;
	} else c = wh;
	f[7].style.backgroundColor = c;

	if (f.trieda.value == 100){
		m++;
		c = lr;
	} else c = wh;
	f.trieda.style.backgroundColor = c;

	if (f.cislo.value == 'Vyber!'){
		m++;
		c = lr;
	} else c = wh;
	f.cislo.style.backgroundColor = c;

	if (m > 0) {
		alert('Vyplňte prosím chýbajúce údaje!!!');
		return false;
	} else return true;
}
//---------------------------------------
function submitForm() {
	updateEditor('txteditor');
	return true;
}

function createMarker(point, text) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(text);
  });
  return marker;
}

function checkpostreg() {
	if (document.komentar.postdata.value.length<2) {
		alert ('Zadajte komentár!');
		document.komentar.postdata.focus();
		return false;
	} else return true;
}

function checkadv() {
	var t = document.addinzerat.rubrika.value;
	if (t == 1){
		var id1 = false, id2 = false;
		if (document.addinzerat.mfg_year.value == 'x') {
			alert ('Vyberte rok výroby!');
			document.addinzerat.mfg_year.focus();
			id1 = true;
		}
		if (document.addinzerat.model.value == 'x') {
			alert ('Vyberte typ/model motocykla!');
			document.addinzerat.model.focus();
			id2 = true;
		}
		if (!id1 && !id2) return true; else return false;
	} else return true;
}

function checkmail() {
	var id1=false, id2=false, id3=false;
	if (document.newmail.subject.value.length<2) {
		alert ('Zadajte predmet!');
		document.newmail.subject.focus();
		id1 = true;
	}
	if (document.newmail.recipients.value.length<3) {
		alert ('Zadajte aspoň jedného adresáta!');
		document.newmail.recipients.focus();
		id2 = true;
	}
	if (document.newmail.body.value.length<2) {
		alert ('Zadajte text!');
		document.newmail.body.focus();
		id3 = true;
	}
	if (!id1 && !id2 && !id3) return true; else return false;
}

function checkTrat() {
	var id1=false, id2=false, id3=false;
	if (document.addtrat.title.value.length<3) {
		alert ('Zadajte názov trate!');
		document.addtrat.title.focus();
		id1 = true;
	}
	if (document.addtrat.body.value.length<3) {
		alert ('Zadajte popis trate!');
		document.addtrat.body.focus();
		id2 = true;
	}
	if (document.addtrat.x.value.length<3 || document.addtrat.y.value.length<3 || document.addtrat.z.value.length<1) {
		alert ('Kliknutím na mapu vyberte polohu trate!');
		id3 = true;
	}
	if (!id1 && !id2 && !id3) return true; else return false;
}

function smile(txt) {
	if (txt == 'http'){
		txt = prompt('Zadajte adresu odkazu:', 'http://www.');
		if (txt == null) return;
		txt = '[url]' + txt + '[/url]';
	}
	var txtArea = document.getElementById('postdata');
	txtArea.focus();

	if (txtArea.selectionStart) {	// Mozilla
  	var startPos = txtArea.selectionStart; 
	  txtArea.value=txtArea.value.substring(0, txtArea.selectionStart) + ' ' + txt + ' '
	  + txtArea.value.substring(txtArea.selectionEnd, txtArea.value.length);
	  txtArea.selectionStart = startPos + txt.length + 2;
	  txtArea.selectionEnd = startPos + txt.length + 2;
  	return;
  }
  if (document.selection) {	// IE
  	document.selection.createRange().text = ' ' + txt + ' ';
  	return;
  }
  txtArea.value = txtArea.value + ' ' + txt;
}

function toolBoxCmd(txtAreaId, tagOpen, tagClose) {

	var sampleText='';
	var txtarea = document.getElementById(txtAreaId);
	// IE
	if(document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if(!theSelection) { theSelection=sampleText;}
		txtarea.focus();
		if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var scrollTop=txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if(!myText) { myText=sampleText;}
		if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
		  txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();

		var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;
		txtarea.scrollTop=scrollTop;

	// All others
	} else {
		var copy_alertText=alertText;
		var re1=new RegExp("\\$1","g");
		var re2=new RegExp("\\$2","g");
		copy_alertText=copy_alertText.replace(re1,sampleText);
		copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
		var text;
		if (sampleText) {
			text=prompt(copy_alertText);
		} else {
			text="";
		}
		if(!text) { text=sampleText;}
		text=tagOpen+text+tagClose;
		document.infoform.infobox.value=text;
		// in Safari this causes scrolling
		if(!is_safari) {
			txtarea.focus();
		}
		noOverwrite=true;
	}
	// reposition cursor if possible
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();

	return false;
}

function selGal(optVal){
if(optVal=="") return false;
window.location='index.php?gallery=view&typ='+optVal;
}

function selReg(optVal){
	if(optVal=="") return false;
	var typ = '';
	var uri = window.location+'';
	var tbeg = uri.indexOf('&typ=');
	if (tbeg != -1){
		var tend = uri.indexOf('&',tbeg+1);
		if (tend == -1) typ = uri.substring(tbeg,uri.length);
			else typ = uri.substring(tbeg,tend);
	}
	window.location='index.php?mapa=view'+typ+'&kraj='+optVal;
}

function selType(optVal){
	if(optVal=="") return false;
	var kraj = '';
	var uri = window.location+'';
	var tbeg = uri.indexOf('&kraj=');
	if (tbeg != -1){
		var tend = uri.indexOf('&',tbeg+1);
		if (tend == -1) kraj = uri.substring(tbeg,uri.length);
			else kraj = uri.substring(tbeg,tend);
	}
	window.location='index.php?mapa=view'+kraj+'&typ='+optVal;
}

function checkLogin() {
	var id1=false, id2=false;
	if (document.login.username.value.length < 3) {
		alert ('Zadajte login!');
		document.login.username.focus();
		id1 = true;
	}
	if (document.login.password.value.length <= 3) {
		alert ('Zadajte heslo!');
		document.login.password.focus();
		id2 = true;
	}
	if (!id1 && !id2) return true; else return false;
}

function checkEvent() {
	var id1=false, id2=false, id3=false;
	if (document.addevent.date.value.length <= 3) {
		alert ('Zadajte dátum udalosti!');
		document.addevent.date.focus();
		id1 = true;
	}
	if (document.addevent.hint.value.length <= 3) {
		alert ('Zadajte názov udalosti!');
		document.addevent.hint.focus();
		id2 = true;
	}
	if (document.addevent.extended.value.length <= 3) {
		alert ('Zadajte bližší popis!');
		document.addevent.extended.focus();
		id3 = true;
	}
	if (!id1 && !id2 && !id3) return true; else return false;
}

function checkReg() {
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	var id1 = false, id2=false, id3=false, id4=false, id5=false, id6=false, id7=false;
	if (document.registracia.nick.value.length <= 3) {
		alert ("Zadajte login - minimálne 3 znaky!");
		document.registracia.nick.focus();
		id1 = true;
	} else {
		var id1 = /ktm|honda|suzuk(i|y)|kawasak(i|y)|yamaha|(kx|cr|yz|rm|sx)(125|250)|crf|yzf|kxf|sxf|pastrana|fox|husqvarna/.test(document.registracia.nick.value);
		if (id1) {
			alert ("Login nesmie obsahovať značku motocykla, slávneho jazdca, firmy...");
			document.registracia.nick.focus();
		}
	}
	if (document.registracia.meno.value.length <= 3) {
		alert ("Zadajte Vaše meno!");
		document.registracia.meno.focus();
		id2 = true;
	}
	if (re.test(document.registracia.mail.value) == false) {
		alert ("Neplatný e-mail!");
		document.registracia.mail.focus();
		id3 = true;
	}
	if (document.registracia.mesto.value.length <= 3) {
		alert ("Zadajte mesto!");
		document.registracia.mesto.focus();
		id4 = true;
	}
	if (document.registracia.motorka.value.length <= 3) {
		alert ("Zadajte typ motorky!");
		document.registracia.motorka.focus();
		id5 = true;
	}
	if (document.registracia.myself.value.length <= 20) {
		alert ("Napíšte niečo o sebe, aspoň dve vety - inak nebudete zaregistrovaný!");
		document.registracia.myself.focus();
		id6 = true;
	}
	if (document.registracia.myself.value.substr(0,8) == 'Očakávam') {
		alert ("Napíšte niečo o sebe, stačí len čítať, čo sa tu píše!");
		document.registracia.myself.value = '';
		document.registracia.myself.focus();
		id7 = true;
	}
	if (!id1 && !id2 && !id3 && !id4 && !id5 && !id6 && !id7) return true; else return false;
}

function check_update() {
	var id1 = false, id2=false, id3=false;
	if (document.update_me.meno.value.length <= 3) {
		alert ("Zadajte Vaše meno!");
		document.update_me.meno.focus();
		id1 = true;
	}
	if (document.update_me.mesto.value.length <= 3) {
		alert ("Zadajte mesto!");
		document.update_me.mesto.focus();
		id2 = true;
	}
	if (document.update_me.motorka.value.length <= 3) {
		alert ("Zadajte typ motorky!");
		document.update_me.motorka.focus();
		id3 = true;
	}
	if (!id1 && !id2 && !id3) return true; else return false;
}

function checkPW(){
	if (document.pwchng.new1.value != document.pwchng.new2.value) {
		alert ('Zopakujte heslo správne!');
		document.pwchng.new2.value = '';
		document.pwchng.new2.focus();
		return false;
	} else return true;
}

function update_ad_code(){
	var banner = document.getElementById('banner').value;
	var banner_array = banner.split('\\');
	var strFileName = banner_array[banner_array.length - 1];
	var customer = document.getElementById('customer').value;
	var new_code = '<a href="click.php?id=' + document.getElementById('new_id').value + '&link=http://www.xxxxxxx.sk" target=_blank><img src="ads/';
	if (customer == 'new') {
		new_code += document.getElementById('customer_new').value;
	}
	else {
		new_code += customer;
	}
	document.new_ad.code.value = new_code + '/' + strFileName + '" alt="' + document.getElementById('name').value + '"></a>';
}

function post_ev(prispevok, val){
	window.open('ocenit.php?prispevok=' + prispevok + '&hodnotenie=' + val,'','toolbar=no,scrollbars=no,location=no,status=no,width=200,height=80,resizable=0');
	window.location.reload();
}