/****************************************** begin c10 *********************************************/
if (typeof jQuery != 'undefined') { 
$(document).ready(function(){
	var top = $('div#leftcontent > ul').offset().top - parseFloat($('div#leftcontent > ul').css('marginTop').replace(/auto/, 0));
	$(window).scroll(function (event) {
		var y = $(this).scrollTop();
		if (y >= top) {
			$('div#leftcontent > ul').addClass('fixed');
		} else {
			$('div#leftcontent > ul').removeClass('fixed');
		}
	});

	$("#giftex li span").tooltip();
	$(".donorForm input[name='amount']").change(function(){

	if ($(this).val()!='other') {

		$("#tt-"+$(this).val()).tooltip().show();
		setTimeout("hideTooltip('"+"#tt-"+$(this).val()+"')",2000);
	}	
	});

	$(".donorForm input[name='anonym']").val(0)

	$("#anonym").attr("checked","");
	$("#anonym").change(function(){
		$(".donorForm fieldset.personal").each(function(){
			$(this).toggleClass("anonym");
			if (!$("#anonym").is(':checked')) {
				$(this).parent().height("auto");
				$(this).parent().children("input[name='anonym']").val(0)
			}else{
				$(this).parent().children("input[name='anonym']").val(1)
				$(this).parent().height($(this).parent().children(".right-info-bar").height() + 20);
			}
		});
	});
	$("#donor-nav a").click(function(){
		$("#anonym-par").show();
		$("#anonym-par").prev().css("margin-bottom",20);
		$("#donor-nav a.current").removeClass("current");
		$(this).addClass("current");
		$('.donorActiveForm').removeClass('donorActiveForm');
		$($(this).attr("href")).addClass('donorActiveForm');
		$('.donorActiveForm').height("auto");
		if ($("#anonym").is(':checked') && $('.donorActiveForm').children(".right-info-bar").length>0) {
			$('.donorActiveForm').height($('.donorActiveForm').children(".right-info-bar").height() + 20);
		}
		return false;
	});
	$("#cashPayment-anchor").click(function(){
		$("#anonym-par").prev().css("margin-bottom",75);
		$("#anonym-par").hide();
	if (!$.mygooglemap) {
		var myOptions = {
		    zoom: 17,
		    center: new google.maps.LatLng(50.087537, 14.398277),
		    mapTypeId: google.maps.MapTypeId.ROADMAP,
		    scrollwheel: false
		};
		$.mygooglemap = new google.maps.Map(document.getElementById("gmapy"),myOptions);
		 var image = new google.maps.MarkerImage('/cz/img/msf-logo-short.gif',
				 new google.maps.Size(42,32),new google.maps.Point(0,0), new google.maps.Point(0,32));
		 
		var myLatLng = new google.maps.LatLng(50.087537, 14.398277);
		 	
		var marker = new google.maps.Marker({
		    position: myLatLng,
		    map: $.mygooglemap,
		    icon: image,
		    title: "Lékaři bez hranic",
		    html: "al_marker",
		    zIndex: 100
		});
	}
	});
	$("#paysecPayment").submit(function(){
	var otherval = $("#paysecPayment input[name='amounto']").val();
	if ($("#paysecPayment input[name='amount']:checked").val() == 'other' && (otherval == "" || otherval == 0 )) {
		alert("Vyplňte prosím darovanou částku, děkujeme");
		return false;
	}
	if ($("#paysecPayment input[name='amount']:checked").val() == 'other'){
		$("#paysecPayment input[name='finalamount']").val(otherval);
	}else{
		$("#paysecPayment input[name='finalamount']").val($("#paysecPayment input[name='amount']:checked").val());
	}
	});
	$("#creditcardPayment").submit(function(){
	var otherval = $("#creditcardPayment input[name='amounto']").val();
	if ($("#creditcardPayment input[name='amount']:checked").val() == 'other' && (otherval == "" || otherval == 0 )) {
		alert("Vyplňte prosím darovanou částku, děkujeme");
		return false;
	}
	if ($("#creditcardPayment input[name='amount']:checked").val() == 'other'){
		$("#creditcardPayment input[name='finalamount']").val(otherval);
	}else{
		$("#creditcardPayment input[name='finalamount']").val($("#creditcardPayment input[name='amount']:checked").val());
	}
});

facebooksetup();
});
}
function hideTooltip(objekt){
	$(objekt).tooltip().hide();
}
function facebooksetup(){
if ($("#maincontent img[name='image']").length > 0){
	$("html").attr("xmlns:fb","http://ogp.me/ns/fb#");

var data = '<meta property="og:title" content="'+$("#maincontent h1").text()+'" />'+
'<meta property="og:type" content="non_profit" />'+
'<meta property="og:url" content="'+window.location+'" />'+
'<meta property="og:image" content="http://www.lekari-bez-hranic.cz'+$("#maincontent img[name='image']").attr("src")+'" />'+
'<meta property="og:site_name" content="Lékaři bez hranic" />'+
'<meta property="fb:admins" content="100000159255623" />';
$("head").append(data);
$("body").prepend('<div id="fb-root"></div>');
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/cs_CZ/all.js#xfbml=1&appId=160136494078856";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

$('<fb:like href="'+window.location+'" send="false" width="450" show_faces="false"></fb:like>').insertBefore("p.bottomspace:last");
}
}
/****************************************** end c10 *********************************************/
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function check_input_focus(welches_input, bezeichnung) {
  if (welches_input.value==bezeichnung) {welches_input.value="";}
}

function check_input_blur(welches_input, bezeichnung) {
  if (welches_input.value=="" || welches_input.value==" " || welches_input.value=="  " || welches_input.value=="   ") {welches_input.value=bezeichnung;}
}

function geturl(url, target) {
  window.open(url,target);
}

function openCountryInfo(link) {
  window.open(link);
}

function check_hr_form() {
	var errortext = 'Prosím, vyplntě hvězdičkou označena políčka';
	if (false == selectFieldNotEmpty('f_salutation', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_first_name', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_last_name', errortext )) {
		return false;
	}
	if (false == selectFieldNotEmpty('f_profession', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_diploma', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_year_of_degree', errortext )) {
		return false;
	}
	if (false == selectFieldNotEmpty('f_good_english', errortext )) {
		return false;
	}
	if (false == formFieldNotEmail('f_email', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_street', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_street_number', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_zip', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_city', errortext )) {
		return false;
	}
	if (false == selectFieldNotEmpty('f_country', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('code', errortext )) {
		return false;
	}
	return true;
}

function check_hr_form_en () {
	var errortext = 'Please fill in all fields marked with *';
	if (false == selectFieldNotEmpty('f_salutation', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_first_name', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_last_name', errortext )) {
		return false;
	}
	if (false == selectFieldNotEmpty('f_profession', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_diploma', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_year_of_degree', errortext )) {
		return false;
	}
	if (false == selectFieldNotEmpty('f_good_english', errortext )) {
		return false;
	}
	if (false == formFieldNotEmail('f_email', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_street', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_street_number', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_zip', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_city', errortext )) {
		return false;
	}
	if (false == selectFieldNotEmpty('f_country', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('code', errortext )) {
		return false;
	}
	return true;
}

function check_donation_form() {
	var errortext = 'Prosím, vyplntě hvězdičkou označena políčkaka';
	if (false == formFieldNotEmail('f_email', errortext)) {
		return false;
	}
	return true;
}

function check_contact_form() {
	var errortext = 'Prosím, vyplntě hvězdičkou označena políčkaka';
	if (false == selectFieldNotEmpty('f_salutation', errortext)) {
		return false;
	}
	if (false == formFieldNotEmpty('f_first_name', errortext)) {
		return false;
	}
	if (false == formFieldNotEmpty('f_last_name', errortext)) {
		return false;
	}
	if (false == formFieldNotEmail('f_email', errortext)) {
		return false;
	}
	if (false == formFieldNotEmpty('f_message', errortext)) {
		return false;
	}
	return true;
}

function check_contact_form_en() {
	var errortext = 'Please fill in all fields marked with *';
	if (false == selectFieldNotEmpty('f_salutation', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_first_name', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_last_name', errortext )) {
		return false;
	}
	if (false == formFieldNotEmail('f_email', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_message', errortext )) {
		return false;
	}
	return true;
}

function check_nl_form() {
	var errortext = 'Prosím, vyplntě hvězdičkou označena políčka';
	if (false == selectFieldNotEmpty('f_salutation', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_first_name', errortext )) {
		return false;
	}
	if (false == formFieldNotEmpty('f_last_name', errortext )) {
		return false;
	}
	if (false == formFieldNotEmail('f_email', errortext )) {
		return false;
	}
	return true;
}

function check_flager_form() {
	var errortext = 'Prosím, vyplntě hvězdičkou označena políčkaka';
	if (false == selectFieldNotEmpty('f_salutation', errortext)) {
		return false;
	}
	if (false == formFieldNotEmpty('f_first_name', errortext)) {
		return false;
	}
	if (false == formFieldNotEmpty('f_last_name', errortext)) {
		return false;
	}
	if (false == formFieldNotEmail('f_email', errortext)) {
		return false;
	}
	return true;
}

function formFieldNotEmpty(elementId, messageIfEmpty) {
	var obj;
	obj = document.getElementById(elementId);
	if (obj) {
		if (obj.value.length == 0) {
			alert(messageIfEmpty);
			obj.focus();
			return false;
		}
		return true;
	}
	throw "Element with id '" + elementId + "' not found";
}

function selectFieldNotEmpty(elementId, messageIfEmpty) {
	var obj;
	obj = document.getElementById(elementId);
	if (obj) {
		if ( (obj.options[obj.selectedIndex].text == "Vyberte") || (obj.options[obj.selectedIndex].text == "Please select") || (obj.options[obj.selectedIndex].text == "") ) {
			alert(messageIfEmpty);
			obj.focus();
			return false;
		}
		return true;
	}
	throw "Element with id '" + elementId + "' not found";
}



function formFieldNotEmail(elementId, messageIfEmpty) {
	var obj;
	obj = document.getElementById(elementId);
	if (obj) {
		if (!validEmail(obj.value)) {
			alert(messageIfEmpty);
			obj.focus();
			return false;
		}
		return true;
	}
	throw "Element with id '" + elementId + "' not found";
}

function validEmail (emailStr) {
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
	  }
	}
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		return false;
	}

	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
	  }
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

String.prototype.ncr2c = function( ) {
	return this
		.replace( /&#x([\da-f]{2,4});/gi,
		function( $0, $1 ) { return String.fromCharCode( "0x" + $1 ) } )
}
String.prototype.c2ncr = function( ) {
	return this	.ncr2c( ).replace( /./g,
		function( $0 ) { return "&#x" + $0.charCodeAt( ).toString( 16 ).toUpperCase( ) + ";" } )
}

