function insert_flash (file,width,height,flashvars,winmode,id,classs,alternative) {
	var shockmode = false;
	if(id!=''){
		id=" id=\""+id+"\"";
	}
	if(classs!=''){
		classs=' class="'+classs+'"';
	}
	var mimetype = 'application/x-shockwave-flash';

	if (navigator.mimeTypes) {
		if (navigator.mimeTypes[mimetype] != null) {
			if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
				shockmode = true;
		      }
		}
	}
	if (!shockmode && navigator.appVersion.indexOf('MSIE') !=-1) {
		shockmode = true;
	}
	if (shockmode) {
		document.write("<object"+id+" type=\"application/x-shockwave-flash\" data=\""+file+"\""+classs+" width=\""+width+"\" height=\""+height+"\">");
		document.write("<param name=\"movie\" value=\""+file+"\" />");
		document.write("<param name=\"menu\" value=\"false\" />");
		document.write("<param name=\"wmode\" value=\""+winmode+"\" />");
		if(flashvars!=''){
			document.write("<param name=\"flashvars\" value=\""+flashvars+"\" />");
		}
		document.write(alternative);
		document.write("</object>");
	}
	else {
		document.write(alternative);
	}
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName])
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function selectArticlesBox(box)
{
	$('#hp-third-block > .headline > ul > li').each(function(){
		$(this).removeClass('active');
		$('#'+this.id+'-content').hide();
		$('#'+this.id+'-button').hide();
	});
	$('#box-'+box).addClass('active');
	$('#box-'+box+'-content').show();
	$('#box-'+box+'-button').show();

}

function jumpToSite(sl)
{
	if (sl.value != '')	newWin(sl.value);
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName])
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function sliderHP(frameNum)
{
    var m = getFlashMovieObject('hp_banner');
	m.Rewind();
	m.GotoFrame(frameNum);
}


// just new window
function newWin(URL) { var okno = window.open(URL,'blank'); okno.focus(); return false; }

function addFav()
{
    if (getBrowserType() == 'MSIE') {
        window.external.AddFavorite(location.href, document.title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(document.title,location.href,"");
    } else {
        alert('Do oblíbených tuto stránku přidáte obvykle stisknutím Ctrl+D (Cmd+D pro Mac)');
    }
}

function sendLink()
{
	var jmeno = document.getElementById('jmeno').value;
    if( jmeno=='' ){
    	alert('Není vyplněno jméno odesilatele.');
    	return false;
    }

	var sender = document.getElementById('odesilatel').value;
    if( sender=='' ){
    	alert('Není vyplněn email odesilatele.');
    	return false;
    }

	if(!testEmail(sender)) {
    	alert('Neplatný email odesilatele.');
    	return false;
    }

    var email = document.getElementById('email').value;
    if( email=='' ){
    	alert('Není vyplněn email adresáta.');
    	return false;
    }

	if(!testEmail(email)) {
    	alert('Neplatný email adresáta.');
    	return false;
    }

    var vzkaz = document.getElementById('vzkaz').value;
    if( vzkaz=='' ){
    	alert('Není vyplněn vzkaz pro adresáta.');
    	return false;
    }

	var link = location.href;
	var pagetitle = $('#pagetitle').val();

    $.post('/cs/smallapp/ajax/send-link', {name: jmeno, from:sender, to:email, text:vzkaz, link:link, pagetitle:pagetitle}, sendLinkCallback, 'json');
}

function sendLinkCallback(data)
{
	if (data.status == 'ERROR')
	{
		$('#sendresult').html(data.data);
	} else {
		$('#sendresult').html(data.data);
	}
}

function subscribe()
{
	$('#subscribeButton').attr('disabled', 'disabled');
	var email = $('#subscribemail').val();
	if (!testEmail(email))
	{
		alert('Neplatný email.');
		$('#subscribeButton').removeAttr('disabled');
    	return false;
	}

	$.post('/cs/smallapp/ajax/subscribe', {email: email}, subscribeCallback, 'json');
}

function subscribeCallback(data)
{
	$('#subscribeButton').removeAttr('disabled');
	alert(data.data);
}

function testEmail(email)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(email);
}

// get browser type
function getBrowserType()
{
    if (/Konqueror|KHTML/.test(navigator.userAgent) && !/Apple/.test(navigator.userAgent))
    {
        return "KHTML";
    }

    if (/KHTML/.test(navigator.userAgent) && /Apple/.test(navigator.userAgent))
    {
        return "Safari";
    }

    if (!!window.opera)
    {
        return "Opera";
    }

    if (!!(window.attachEvent && !window.opera))
    {
        return "MSIE";
    }

    if (/Gecko/.test(navigator.userAgent) && !/Konqueror|KHTML/.test(navigator.userAgent))
    {
        return "Gecko";
    }
}


function contactMapInit() {
    var latlng = new google.maps.LatLng(50.082391,14.422112);
    var myOptions = {zoom: 16,center: latlng,mapTypeControl: true,
    mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
    navigationControl: true,
    navigationControlOptions: {
      style: google.maps.NavigationControlStyle.SMALL
    },mapTypeId: google.maps.MapTypeId.ROADMAP};
    var map = new google.maps.Map(document.getElementById("mapa"),myOptions);
	var marker = new google.maps.Marker({position: latlng,map: map,title:"Pragoplyn, a.s."});
}
function loadGmapScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=contactMapInit&language="+language;
  document.body.appendChild(script);
}
