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 adv(uri)
{
	window.open(uri, "page", "width=800, height=600,menubar=yes, location=yes, status=no, toolbar=no, scrollbars=yes, resizable=yes,left=100,top=100");
	return false; 
}


function pop_adv(uri, width, height) {
	window.open(uri, "advertising", "width=" + width + ", height=" + height + ",menubar=no, location=no, status=no, toolbar=no, scrollbars=yes, resizable=no,left=70,top=70");
	return false; 
}


function w(uri)
{
	var result = adv(uri);
	return result;
}

function ws(uri)
{
	return w(uri);
}

function wi(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 make_corners(width, height)
{
	var left = Math.floor((465 - width) / 2);
	var right = Math.ceil(((465 - width) / 2) + width - 19);
	var bottom = height - 19;

	var el1 = document.getElementById('corner-lt');
	el1.style.visibility = 'visible';
	el1.style.top = '0px';
	el1.style.left = left + 'px';
	var el2 = document.getElementById('corner-rt');
	el2.style.visibility = 'visible';
	el2.style.top = 0;
	el2.style.left = right + 'px';
	var el3 = document.getElementById('corner-lb');
	el3.style.visibility = 'visible';
	el3.style.top = bottom + 'px';
	el3.style.left = left + 'px';
	var el4 = document.getElementById('corner-rb');
	el4.style.top = bottom + 'px';
	el4.style.left = right + 'px';
	el4.style.visibility = 'visible';
}


function is_int(val, string) {
	var intresult = true; var a = 1; var needle = '';
	for(a=1; a<val.length+1; a++) {
		needle = val.substring(a-1,a);
		if((needle < "0" || needle > "9") && (string.indexOf(needle) < 0 || string.length == 0)) intresult = false;
	}
	return intresult;
}


function change_js_input()
{
	var items = '';
	var i = 0;
	var error = false;
	var a;
	var report = '';
	var var_name = '';

	if (document.getElementById('required_items')) {
		items = document.getElementById('required_items');
		items = items.split(';');
	} else items = new Array('firma', 'osoba', 'telefon', 'email', 'gp_strojniku_dvoucestnych_rypadel', 'gp_strojniku_ostatnich_stavebnich_stroju', 'gp_ridicu_nakladnich_vozidel', 'fotbalovy_viceboj');

	options_error = '0';
	for (i = 0; i < items.length; i ++) {
		var_name = items[i];
		if (document.getElementById(var_name)) a = document.getElementById(var_name).value;
		// alert(a+' '+var_name);
		if (!a || a == '+420' || a == '@') {
			error = true;
			if (var_name == 'firma') report += 'Není zadána firma!\n';
			if (var_name == 'osoba') report += 'Není zadaná kontaktni osoba!\n';
			if (var_name == 'telefon' || a == '+420') report += 'Není zadán telefon!\n';
			if (var_name == 'email' || a == '@') report += 'Není zadán e-mail!\n';
			if ((var_name == 'gp_strojniku_dvoucestnych_rypadel' ||
			    var_name == 'gp_strojniku_ostatnich_stavebnich_stroju' ||
			    var_name == 'gp_ridicu_nakladnich_vozidel' ||
			    var_name == 'fotbalovy_viceboj') && options_error == '0')
			    {
			 	   window.alert(options_error);
			 	   report += 'Není zadán počet osob!\n';
			 	   options_error = '1';
			    }
		}
	}

	if (error) {
		alert(report);
		return false;
	}

	var el = document.getElementById('js_input');
	el.value = 1;
	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 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;
    return true;
}


function validate()
{
	var report = '';
	var error = false;

	var firstname = document.getElementById('firstname').value;
	firstname = trim(firstname);
	if (firstname.length == 0) {
		error = true;
		report += 'Nebylo zadáno jméno!\n';
	}
	var surname = document.getElementById('surname').value;
	surname = trim(surname);
	if (surname.length == 0) {
		error = true;
		report += 'Nebylo zadáno příjmení!\n';
	}
	var mail = document.getElementById('mail').value;
	mail = trim(mail);
	if (mail.length == 0) {
		error = true;
		report += 'Nebyl zadán e-mail!\n';
	} else {
		if (!zkontroluj_email(mail)) {
			error = true;
			report += 'E-mailová adresa nemá správný tvar!\n';
		}
	}
	var telefon = document.getElementById('telefon').value;
	telefon = trim(telefon);
	if (telefon.length == 0) {
		error = true;
		report += 'Nebyl zadán telefon!\n';
	}
	var region = document.getElementById('region').value;
	if (region.length == 0) {
		error = true;
		report += 'Není vybrán region!\n';
	}
	if (error) {
		alert(report);
		return false;
	} else {
		var chval = document.getElementById('check_value');
		chval.value = 1;
		return true;
	}
}

function test_contribution()
{
	var error = false;
	var report = '';
	var fullname = document.getElementById('fullname').value;
	fullname = trim(fullname);
	if (fullname.length == 0) {
		error = true;
		report += 'Nezadali jste jméno!\n';
	}
	var contribution = document.getElementById('contribution').value;
	contribution = trim(contribution);
	if (contribution.length == 0) {
		error = true;
		report += 'Nezadali jste text komentáře!\n';
	}
	if (error) {
		alert(report);
		return false;
	}

	var check_value = document.getElementById('check_value');
	check_value.value = 1;
	return true;
}
