   function Validovat(theForm)
   {
       if ((document.getElementById('autor').value=="")||(document.getElementById('autor').value.length < 3))
       {
         alert("Vaše jméno musíte vyplnit!");
         document.getElementById('autor').focus();
         return false;
       }

       var email = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");
       if (document.getElementById('email').value=="" || !email.test(document.getElementById('email').value))
       {
         alert("Zadejte svůj email.");
         document.getElementById('email').focus();
         return false;
       }

       if ((document.getElementById('predmet').value=="")||(document.getElementById('predmet').value.length < 3))
       {
         alert("Předmět zprávy je povinný.");
         document.getElementById('predmet').focus();
         return false;
       }

       if ((document.getElementById('obsah').value=="")||(document.getElementById('obsah').value.length < 5))
       {
         alert("Zadejte obsah komentáře.");
         document.getElementById('obsah').focus();
         return false;
       }

     return true;
   }


	 

var _mousePos = false;
var mouse = {
    getMouseOffset: function(target) { 
        var docPos = mouse.getPosition(target); 
        return {x:_mousePos.x - docPos.x, y:_mousePos.y - docPos.y}; 
    },
    getPosition: function(e) { 
        var left = 0; 
        var top  = 0; 
        while (e.offsetParent){ 
            left += e.offsetLeft; 
            top  += e.offsetTop; 
            e     = e.offsetParent; 
        } 
        left += e.offsetLeft; 
        top  += e.offsetTop; 
        return {x:left, y:top}; 
    },
    mouseCoords: function(ev) { 
        if(isNaN(window.scrollX)) {
            return {
                x:ev.clientX + document.documentElement.scrollLeft
                    + document.body.scrollLeft - 13, 
                y:ev.clientY + document.documentElement.scrollTop
                    + document.body.scrollTop
            };
        } else {
            return {
                x:ev.clientX + window.scrollX - ((document.documentElement.offsetWidth - document.body.offsetWidth)/2) - 13, 
                y:ev.clientY + window.scrollY - ((document.documentElement.offsetHeight - document.body.offsetHeight)/2)
            };
        }
    },
    mouseMove: function(ev) {
	    ev = ev || window.event; 
	    _mousePos = mouse.mouseCoords(ev); 
	}
}
	

var _kliknuto = false;
var hodnoceni = {
    add: function(id, hlas) {
        document.getElementById(id).style.display='none';
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        } else if (window.XMLHttpRequest) {
            xmlHttp =  new XMLHttpRequest();
        } else {
            return false;
        }
        xmlHttp.open("POST", "/ajax_hodnoceni.php", true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                alert(xmlHttp.responseText);
                hodnoceni.drop();
                return false;
            }
        };
        xmlHttp.send("id="+id+"&hlas="+hlas);
    },
    create: function(id) {
        if(_kliknuto) {
            return false;
        }
        _kliknuto = id;
        document.onmousemove = mouse.mouseMove; 
        var span = document.createElement('span');
        span.className='hodnoceni';
        span.setAttribute('id', 'hodnoceni-'+id);
        var star = document.createElement('span');
        star.className='star5';
        star.setAttribute('id', 'span-'+id);
        star.innerHTML='hvezdiček';
        star.onclick=function() {return hodnoceni.add(id,this.className);};
        star.onmousemove=function() {
            x = mouse.getMouseOffset(document.getElementById(id)).x;
            x = Math.round(x/10);
            if (x>5) x=5;
            if (x<1) x=1;
            star.className = 'star'+x;                
        };
        star.onmouseout=function(e) {
			star.className = 'star5';
            //hodnoceni.drop(id);
        };
        span.appendChild(star);
        var parent = document.getElementById(id);
        parent.style.position='relative';
        parent.appendChild(span);
        return false;
    },
    drop: function (id) {
        if(document.getElementById('hodnoceni-'+id)) {
            var child = document.getElementById('hodnoceni-'+id);
            var parent = document.getElementById(id);
            parent.removeChild(child);
            parent.style.position='static';
            _kliknuto = false;        
        }
    }
}

var _preposlano = false;
var _drop = true;
var preposlat = {
    send: function() {
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        } else if (window.XMLHttpRequest) {
            xmlHttp =  new XMLHttpRequest();
        } else {
            return false;
        }
        xmlHttp.open("POST", "/ajax_preposlat.php", true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                alert(xmlHttp.responseText);
                preposlat.drop();
                _preposlano = false;
                return false;
            }
        };
        xmlHttp.send("jmeno="+document.getElementById('jmeno').value+"&odesilatel="+document.getElementById('odesilatel').value+"&prijemce="+document.getElementById('prijemce').value+"&zprava="+document.getElementById('zprava').value);
    },
    create: function() {
        if(_preposlano) {
            _preposlano = false;
            return false;
        }
        if(document.getElementById('span-dotaz')) {
    		dotaz.drop();
    	}
        _preposlano = true;
        var span = document.createElement('span');
        var span = document.createElement('span');
        span.className='preposlat';
        span.setAttribute('id', 'span-preposlat');
        var label = document.createElement('label');
        label.innerHTML='Vaše jméno:';
        span.appendChild(label);
        var input = document.createElement('input');
        input.type='text';
        input.setAttribute('id', 'jmeno');
        span.appendChild(input);
        var label = document.createElement('label');
        label.innerHTML='Váš e-mail:';
        span.appendChild(label);
        var input = document.createElement('input');
        input.type='text';
        input.setAttribute('id', 'odesilatel');
        span.appendChild(input);
        var label = document.createElement('label');
        label.innerHTML='E-mail příjemce:';
        span.appendChild(label);
        var input = document.createElement('input');
        input.type='text';
        input.setAttribute('id', 'prijemce');
        span.appendChild(input);
        var label = document.createElement('label');
        label.innerHTML='Zpráva:';
        label.setAttribute('style','position:relative;top:-20px;');
        span.appendChild(label);
        var textarea = document.createElement('textarea');
        textarea.setAttribute('id', 'zprava');
        span.appendChild(textarea);
        var input = document.createElement('input');
        input.type='button';
        input.value='Přeposlat';
        input.className='submit';
        input.onclick=function() {return preposlat.validate();};
        span.appendChild(input);
        var input = document.createElement('input');
        input.type='button';
        input.value='Storno';
        input.className='storno';
        input.onclick=function(e) {preposlat.drop();if(!document.all){e.stopPropagation(); } return false;};
        span.appendChild(input);
        var parent = document.getElementById('preposlat');
        parent.style.position='relative';
        parent.appendChild(span);
        parent.onclick = "return false;";
        return false;
    },
    drop: function () {    	
    	if(document.getElementById('span-preposlat')) {
            var child = document.getElementById('span-preposlat');
            var parent = document.getElementById('preposlat');
            parent.removeChild(child);
            parent.style.position='static';
            parent.onclick = function() {preposlat.create();return false; };
            _preposlano = false;
        }
        return false;
    },
    validate: function () {
        var email = new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$");
        if (document.getElementById('jmeno').value=="")
        {
            alert("Vaše jméno musíte vyplnit !");
            document.getElementById('jmeno').focus();
            return false;
        } else if (document.getElementById('odesilatel').value=="") {
            alert("Vaši emailovou adresu musíte vyplnit !");
            document.getElementById('odesilatel').focus();
            return false;
        } else if (document.getElementById('odesilatel').value!="" && !email.test(document.getElementById('odesilatel').value)) {
            alert("Zadaný email neodpovídá formátu elektronické pošty (např. odesilatel@domena.cz) !");
            document.getElementById('odesilatel').focus();
            return false;
        } else if (document.getElementById('prijemce').value=="") {
            alert("Emailovou adresu příjemce musíte vyplnit !");
            document.getElementById('prijemce').focus();
            return false;
        } else if (document.getElementById('prijemce').value!="" && !email.test(document.getElementById('prijemce').value)) {
            alert("Zadaný email neodpovídá formátu elektronické pošty (např. prijemce@domena.cz) !");
            document.getElementById('prijemce').focus();
            return false;
        } else if (document.getElementById('zprava').value=="") {
            alert("Vaši zprávu musíte vyplnit !");
            document.getElementById('zprava').focus();
            return false;
        }
        preposlat.send();
    }
}

function showPassForm(flag) {
	$('passTr').style.display = flag ? '' : 'none';
	$('passCheckTr').style.display = flag ? '' : 'none';
	$('profilePassword').disabled = flag ? '' : 'disabled';
	$('profilePasswordCheck').disabled = flag ? '' : 'disabled';
	$('profilePassword').value = '';
	$('profilePasswordCheck').value = '';
}

var Page = function() {
	this.mapScale = 15;
	this.googleDisabled = false;
}

Page.prototype.showAddress = function(address) {
	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: true
	            });
	            google.maps.event.addListener(Page.marker, 'drag', Page.saveCoords);
            } else {
            	Page.marker.setPosition(results[0].geometry.location);
            }
            Page.saveCoords();
          } else {
            alert("Geocode was not successful for the following reason: " + status);
          }
	});

}

Page.prototype.saveCoords = function() {
	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();

