// JavaScript Document

//GOOGLE MAPS **********************************************************************************************************************************************
//**********************************************************************************************************************************************************

function Initialize(adresa) {
  var myLatlng = new google.maps.LatLng(49.056116,20.310168);
  var myOptions = {
    zoom: 16,
    center: myLatlng,
	navigationControl: true,
	mapTypeControl: true,
    scaleControl: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
  
  google.maps.event.addListener(map, 'zoom_changed', function() {
    setTimeout(moveToDarwin, 3000);
  });
  
  var marker = new google.maps.Marker({
      position: myLatlng, 
      map: map
  });
  
  var zoomLevel;
  var infowindow = new google.maps.InfoWindow(
    { content: adresa,
        size: new google.maps.Size(40,40),
        position: myLatlng
    });
  infowindow.open(map);
}
  
function moveToDarwin() {
  var darwin = new google.maps.LatLng(49.056116,20.310168);
  map.setCenter(darwin);
}


//GENERALY AJAX*********************************************************************************************************************************************
//**********************************************************************************************************************************************************

function send_xmlhttprequest(obsluha,method, url, data, block, loading) {
	document.getElementById(block).innerHTML='';
	//document.getElementById('loading'+loading).style.display='block';
	
    var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
    if (!xmlhttp) {
        return false;
    }
	
	xmlhttp.open(method, url);	
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlhttp.setRequestHeader("cache-control", "content='no-cache'");
	xmlhttp.onreadystatechange = function() {
        obsluha(xmlhttp,block,loading);
    };
	
    xmlhttp.send(data);
    return true;
}

function obsluha_generaly (xmlhttp,block,loading) {
    if (xmlhttp.readyState == 4) {
        // aktualizace odpovedí na základe aktuálního stavu		
	 	//window.alert(xmlhttp.responseText);
		
		document.getElementById(block).innerHTML = xmlhttp.responseText;
		//document.getElementById('loading'+loading).style.display='none';
    }
}

//VOLANIE AJAX***********************************************************************************************************************************************
function Search_project(id)
{
	if (!send_xmlhttprequest(obsluha_generaly, 'POST', '/projekt.php', 'app=1&id='+id, 'rel_portfolio', ''))
	{
		window.alert('Zlyhanie sytému. Kontaktujte administrátora');
		return false;
	}
}


//OSTATNE FUNKCIE
function correctPNG()
{
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
				
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}

function Text_meno()
{
	var text=document.getElementById('meno').value;
	
	if (text=='')
	{
		document.getElementById('meno').value='Vaše meno a priezvisko';
		document.getElementById('meno').style.color="#999999";
	}
}

function Napis_meno()
{
	var text=document.getElementById('meno').value;
	
	if (text=='Vaše meno a priezvisko')
	{
		document.getElementById('meno').value='';
		document.getElementById('meno').style.color="#000000";	
	}
}

function Text_tel()
{
	var text=document.getElementById('tel').value;
	
	if (text=='')
	{
		document.getElementById('tel').value='Telefonický kontakt';
		document.getElementById('tel').style.color="#999999";	
	}
}

function Napis_tel()
{
	var text=document.getElementById('tel').value;
	
	if (text=='Telefonický kontakt')
	{
		document.getElementById('tel').value='';
		document.getElementById('tel').style.color="#000000";
	}
}

function Text_mail()
{
	var text=document.getElementById('mail').value;
	
	if (text=='')
	{
		document.getElementById('mail').value='E-mailový kontakt';
		document.getElementById('mail').style.color="#999999";	
	}
}

function Napis_mail()
{
	var text=document.getElementById('mail').value;
	
	if (text=='E-mailový kontakt')
	{
		document.getElementById('mail').value='';
		document.getElementById('mail').style.color="#000000";	
	}
}

function Text_sprava()
{
	var text=document.getElementById('text').value;
	
	if (text=='')
	{
		document.getElementById('text').value='Váš text pre nás';
		document.getElementById('text').style.color="#999999";	
	}
}

function Napis_sprava()
{
	var text=document.getElementById('text').value;
	
	if (text=='Váš text pre nás')
	{
		document.getElementById('text').value='';
		document.getElementById('text').style.color="#000000";	
	}
}

function fbs_click(t,u) {
if(t == undefined) {
    t=document.title;
  }
  
  window.open('http://www.facebook.com/share.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent('Crystal palace, shoping center Žilina'),'sharer','toolbar=0,status=0,width=626,height=436');
}


//Odošli kontakt form********************
function Odoslat_form()
{	
	if (!send_xmlhttprequest(obsluha_generaly, 'POST', '/spracuj_form.php', 'app=1&meno='+document.getElementById('meno').value+'&tel='+document.getElementById('tel').value+'&mail='+document.getElementById('mail').value+'&text='+document.getElementById('text').value, 'kontaktny_form', ''))
	{
		window.alert('Zlyhanie sytému. Kontaktujte administrátora');
		return false;
	}
}
