var email = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");
function zkontroluj(formular) {
if( !document.getElementById('podminky').checked ) {
	alert("Musíte souhlasit s obchodními podmínkami!");
	document.getElementById('podminky').focus();
	return false;
}
if (formular.name.value=="")
{
alert("Vaše jméno musíte vyplnit!");
formular.name.focus();
return false;
}
else if (formular.surname.value=="")
{
alert("Vaše přijmení musíte vyplnit!");
formular.surname.focus();
return false;
}
else if (formular.email.value=="")
{
alert("Vaši emailovou adresu musíte vyplnit!");
formular.email.focus();
return false;
}
else if (formular.phone.value=="")
{
alert("Vaš telefon musíte vyplnit!");
formular.phone.focus();
return false;
}
else if (formular.street.value=="")
{
alert("Vaší adresu - ulici musíte vypnit!");
formular.street.focus();
return false;
}
else if (formular.city.value=="")
{
alert("Vaší adresu - obec musíte vyplnit!");
formular.city.focus();
return false;
}
else if (formular.zip.value=="")
{
alert("Vaší adresu - PSČ musíte vyplnit!");
formular.zip.focus();
return false;
}

if (formular.email.value!="") {
  if (!email.test(formular.email.value)) {
    alert("Zadaný email neodpovídá formátu elektronické pošty (např. neco@neco.cz)!");
    formular.email.focus();
    return false;
  }
}

if (formular.phone.value!="") {
	if (formular.phone.value.length < 9) {
    alert("Zadaný telefon neodpovídá formátu (např. +420123456789)!");
    formular.phone.focus();
    return false;
  }
}

return true;
}

function contact() {
	if (document.getElementById('contactName').value=="") {
		alert("Vaše jméno musíte vyplnit!");
		document.getElementById('contactName').focus();
		return false;
	}
	if (document.getElementById('contactPhone').value=="" || document.getElementById('contactPhone').value=="+420" || document.getElementById('contactPhone').value.length<9 ) {
		alert("Váš telefon musíte vyplnit!");
		document.getElementById('contactPhone').focus();
		return false;
	}
	if (document.getElementById('contactEmail').value=="" || document.getElementById('contactEmail').value=="@" ) {
		alert("Váš e-mail musíte vyplnit!");
		document.getElementById('contactEmail').focus();
		return false;
	}
	if (document.getElementById('contactEmail').value!="") {
	  if (!email.test(document.getElementById('contactEmail').value)) {
	    alert("Zadaný email neodpovídá formátu elektronické pošty!");
			document.getElementById('contactEmail').focus();
	    return false;
	  }
	}
	if (document.getElementById('contactText').value=="" || document.getElementById('contactText').value.length<5) {
		alert("Vaši zprávu musíte vyplnit!");
		document.getElementById('contactText').focus();
		return false;
	}
	if (document.getElementById('contactPriklad').value=="") {
		alert("Napište výsledek: devět!");
		document.getElementById('contactPriklad').focus();
		return false;
	}
	document.getElementById('contactForm').submit;
}

var Page = function() {
	this.mapScale = 15;
	this.googleDisabled = false;
}

Page.prototype.showAddress = function(address, staticMarker) {
	if(this.googleDisabled) {
		return true;
	}
	if(!address) {
		//var address = $('#contactAddress').val();
		var address = $('#contactStreet').val() + ' ' + $('#contactCity').val() + ' ' + $('#contactPsc').val();
		if(!address || address.length < 5) {
			//alert('Neuvedena adresa');
			return false;
		}
	}
	if(!this.map) {
		this.geocoder = new google.maps.Geocoder();
		$('#contactMap').css('display', 'block');
	    var myOptions = {
	      zoom: this.mapScale,
	      disableDefaultUI: true,
	      navigationControl:true,
	      navigationControlOptions: {
	    	    style: google.maps.NavigationControlStyle.ZOOM_PAN
    	  },
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
	    this.map = new google.maps.Map(document.getElementById('contactMap'), myOptions);
	}
	this.geocoder.geocode({"address": address}, function(results, status) {
		//alert(this.geocoder);
		if (status == google.maps.GeocoderStatus.OK) {
            Page.map.setCenter(results[0].geometry.location);
            if(!Page.marker) {
	            Page.marker = new google.maps.Marker({
	                map: Page.map, 
	                position: results[0].geometry.location,
	                draggable: staticMarker ? false : true
	            });
	            if(!staticMarker) {
	            	google.maps.event.addListener(Page.marker, 'drag', Page.saveCoords);
	            }
            } else {
            	Page.marker.setPosition(results[0].geometry.location);
            }
            if(!staticMarker) {
            	Page.saveCoords();
            }
          } else {
            alert("Geocode was not successful for the following reason: " + status);
          }
	});

}

Page.prototype.saveCoords = function() {
	if(!document.getElementById('contactMapX')) {
		return false;
	}
	var point = Page.marker.getPosition();
	document.getElementById('contactMapX').value = point.lng()-0;
	document.getElementById('contactMapY').value = point.lat()-0;
	document.getElementById('contactMapGPS').value = (new String(point.lat()).substr(0,6)) + ' ' + (new String(point.lng()).substr(0,6));
	//document.getElementById('contactMapGPS').innerHTML = (new String(point.lat()).substr(0,6).replace('.', '°')+'′'+'N') + ' ' + (new String(point.lng()).substr(0,6).replace('.', '°')+'′'+'E');
}

Page = new Page(); 

PageClass = function() {
  this.cetelemCalculator = false; // Use onw calculator or redirect to cetelem.cz
  this.useCookies = false;
  this.cookies = new Array();
  this.maxBuyngItems = 900;
  this.orderDisabled = false;
  this.orderId = 0;
  this.emailLastTested = '';
  this.searchHelperTimeout = 0;
  this.searchHelperInProgress = 0;
  this.searchHelperLast = '';
  this.questionType = '';
  this.domain = document.location.hostname;
  this.defaultTransport = 0;
  this.defaultPayment = 0;
  this.affilateCodePrevious = '';
}

PageClass.prototype.slideOut = function(holder, checkbox, height) {
    var myEffect = new Fx.Morph(holder, {transition: Fx.Transitions.Sine.easeOut});
    if(checkbox.checked) {
      myEffect.start({'height': [0, height]});
    } else {
      myEffect.start({'height': [height, 0]});
    }
}

var PageC = new PageClass();

function targetBlank (url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
  return false;
}

