function w(url)
{
    window.open(url, "page", "menubar=yes, location=yes, status=yes, toolbar=no, scrollbars=yes, resizable=yes");
    return false;
}

function wf(url, width, height)
{
	width += 50; height += 50;
	window.open(url, 'foto', 'width='+width+', height='+height+', toolbar=no, location=no, resizable=yes, scrollbars=yes, top=100, left=100');
	return false; 
}


function change_js_input()
{
    var el = document.getElementById('js_input');
    el.value = 1;
    return true;
}

// ankety
function set_poll(html_id, poll_id)
{
    var el = document.getElementById('POLLS_answer_' + html_id);
    el.value = poll_id;
}

function send_poll(html_id)
{
    var el = document.getElementById('POLLS_form_' + html_id);
    el.submit();

    return true;
}

function trim(hodnota)
{
	if(hodnota.charAt(0) == " ") {
		hodnota = hodnota.substring(1,hodnota.length);
		hodnota = trim(hodnota);
	}
	if(hodnota.charAt(hodnota.length-1) == " ") {
		hodnota = hodnota.substring(0,hodnota.length-1);
		hodnota=trim(hodnota);
	}
	return hodnota;
}


function chsrc(anchor, src)
{
	var imgs = anchor.getElementsByTagName('img');
	imgs[0].src = src;
}


function tu_corr()
{
	var el = document.getElementById('top_up');
	el.style.marginLeft = '+8px';
	el.style.marginTop = '+0px';
}


function zkontroluj_email(adresa)
{
    var pozice_zavinace = adresa.indexOf("@");
    if (pozice_zavinace < 0)
        return false;
    var cast_pred_zavinacem = adresa.substring(0,pozice_zavinace);
    var cast_po_zavinaci = adresa.substring(pozice_zavinace+1,adresa.length);
    if (cast_po_zavinaci.indexOf("@") >= 0)
        return false;
    if (cast_pred_zavinacem.length <= 0)
        return false;
    if (cast_po_zavinaci.length <= 0)
        return false;
    var pozice_posledni_tecky = cast_po_zavinaci.lastIndexOf(".");
    if (pozice_posledni_tecky < 0)
        return false;
    var pocet_znaku_za_posledni_teckou = cast_po_zavinaci.length - pozice_posledni_tecky - 1;
    if (pocet_znaku_za_posledni_teckou < 2  ||  pocet_znaku_za_posledni_teckou > 4)
        return false;
    var pozice_dvou_tecek_vedle_sebe = adresa.indexOf("..");
    if (pozice_dvou_tecek_vedle_sebe >= 0)
        return false;
    if (cast_pred_zavinacem.charAt(0) == "."  ||  cast_pred_zavinacem.charAt(cast_pred_zavinacem.length-1) == ".")
        return false;
    if (cast_po_zavinaci.charAt(0) == "."  ||  cast_po_zavinaci.charAt(cast_po_zavinaci.length-1) == ".")
        return false;
    return true;
}



function anketa()
{
	// zjištění existence odpovědí
	var is_ans = false;
	var a = 0;
	var q = 0;
	var ans = '';
	do {
		a ++;
		q = 0;
		is_ans = false;
		do {
			q ++;
			ans = document.getElementById('odpoved_' + a + '_' + q);
			if (!ans) break;
			if (ans.checked) is_ans = true;
			if (q >= 1000) break; // sichr je sichr
		} while(true);
		if (q == 1) break;
		if (!is_ans) {
			alert('Na otázku č. ' + a + ' není odpovězeno!');
			return false;
		}
		if (a >= 1000) break; // sichr je sichr
	} while (true);

	// grafika
	q = 0;
	for (a = 1; a <= 5; a ++) {
		if (document.getElementById('grafika_' + a)) q = a;
	}
	if (!q) {
		alert('Hodnocení grafické úpravy magazínu není vyplněno!');
		return false;
	}
			
	// texty
	q = 0;
	for (a = 1; a <= 5; a ++) {
		if (document.getElementById('texty_' + a)) q = a;
	}
	if (!q) {
		alert('Hodnocení kvality textů magazínu není vyplněno!');
		return false;
	}

		
	// informace_1
	q = 0;
	for (a = 1; a <= 5; a ++) {
		if (document.getElementById('informace_' + a)) q = a;
	}
	if (!q) {
		alert('Hodnocení informativní hodnoty magazínu není vyplněno!');
		return false;
	}

	var jmeno_prijmeni = document.getElementById('jmeno_prijmeni').value;
	jmeno_prijmeni = trim(jmeno_prijmeni);
	if (!jmeno_prijmeni.length) {
		alert('Jméno a příjmení není vyplněno!');
		return false;
	}

	var mobil = document.getElementById('mobil').value;
	mobil = trim(mobil);
	if (!mobil.length) {
		alert('Nebyl zadán mobilní telefon!');
		return false;
	}

	var email = document.getElementById('email').value;
	email = trim(email);
	if (email.length) {
		if(!zkontroluj_email(email)) {
			alert('E-mail není vyplněn správně, nemá správný tvar!');
			return false;
		}
	} else {
		alert('Nebyla zadána e-mailová adresa!');
		return false;
	}

	change_js_input();
	return true;
}


function preload_images(images)
{
	var i;
	var im;
	for (i = 0; i < images.length; i ++) {
		im = new Image();
		im.src= images[i];
	}
}


