/* opakujuce sa JS funkcie pozberane z roznych sablon */

function AddFavorite(linkObj,addUrl,addTitle)
{
	if (document.all && !window.opera)
	{
		window.external.AddFavorite(addUrl,addTitle);
		return false;
	}
	else if (window.opera && window.print)
	{
		linkObj.title = addTitle;
		return true;
	}
	else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
	{
		if (window.confirm('Přidat oblíbenou stránku jako nový panel?'))
		{
			window.sidebar.addPanel(addTitle,addUrl,'');
			return false;
		}
	}
	window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k Vašim oblíbeným odkazům.');
	return false;
}

function cancel_criteria(criteria) {
	criteria.selectedIndex=-1;
	msubm(criteria);
}

function change_region(kraj_id) {
	var frm = document.getElementById('f_search');
	frm.kraj_id.value = kraj_id;
	frm.submit();
}

function email_subm() {
	aForm = document.getElementById('send_mail');
	if (aForm.email.value != "" && aForm.email.value != "E-mail adresa") {
		if (!is_email(aForm.email.value)) {
			alert('Neplatný tvar E-mail adresy!');
		} else {
			window.open("", "send_email_window", "resizable=1,height=100,width=300");
			aForm.target = 'send_email_window';
			aForm.submit();
			aForm.email.value = "E-mail adresa";
		}
	}
	return false;
}

function gocar(car_id) {
	document.location = "showcar.php?id=" + car_id;
	return false;
}

function is_email(s)	{
	r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (s == "" || !(r1.test(s) || !r2.test(s)));
}

function msubm(aItem) {
	if (aItem.name == 'znacka' && aItem.options[aItem.selectedIndex].value == 0) {
		if (!document.f1.model.options[document.f1.model.length - 1].value) {
			document.f1.model.selectedIndex = document.f1.model.length - 1;
		}
	}
	document.f1.action='i_search1.php';
	document.f1.submit();
}


function switch_leasing(el, next_el) {
	if (!el.checked) {
		next_el.value = '0';
	}
}

function zmsel_add(frm) {
	var id, txt, i;
	if (frm.znacka.selectedIndex <= 0)
		return;
	id = frm.znacka.value;
	txt = frm.znacka.options[frm.znacka.selectedIndex].text;
	if (frm.model.selectedIndex > 0) {
		id += "_" + frm.model.value
		txt += " " + frm.model.options[frm.model.selectedIndex].text;
	} else {
		id += "_0";
	}
	for (i = 0; i < zm_arr.length; i++) {
		if (zm_arr[i][0] == id)
			return;
	}
	zm_arr.push(new Array(id, txt));
	zmsel_render();
}

function zmsel_del(id) {
	for (var i = 0; i < zm_arr.length; i++) {
		if (zm_arr[i][0] == id) {
			zm_arr.splice(i, 1);
			break;
		}
	}
	zmsel_render();
	return false;
}

function zmsel_render() {
	frm = document.getElementById('f1');
	el_ids = document.getElementById('znacka_text');
	frm.znacka_model_ids.value = '';
	el_ids.innerHTML = '';
	for (var i = 0; i < zm_arr.length; i++) {
		frm.znacka_model_ids.value += zm_arr[i][0];
		el_ids.innerHTML += "<a href=\"#\" onclick=\"return zmsel_del('" + zm_arr[i][0] + "')\" title=\"Odstranit\" >" + zm_arr[i][1] + "</a>";
		if (i < zm_arr.length - 1) {
			frm.znacka_model_ids.value += ",";
			el_ids.innerHTML += ", ";
		}
	}
}

