$(function() {
  
  //make entire row clickable
	$("#serp thead tr th").css("cursor","pointer").click(function(){
		if(($(this).find("a").attr("href"))!=undefined)
			window.location = $(this).find("a").attr("href");
		});
	$(".sitebox tbody tr, #serp tbody tr, #nearbyRooms tbody tr").css("cursor","pointer").click(function(){window.location=$(this).find("a").attr("href");});

  //table striping on hover
  $("table tbody tr").mouseover(function(){$(this).addClass("tr-over");}).mouseout(function(){$(this).removeClass("tr-over");});
  
  $(".sitemap").treeview({
		persist: "location",
		collapsed: true,
		unique: true
	});
  
  $("#head-inset form").submit(function(){mailFriend($('#tellfriend').val(this.value));return false;});
  
  $('a[rel="external"]').each(function(i) {this.target="_blank";});
  $('a[rel="external nofollow"]').each(function(i) {this.target="_blank";}); 
  
//  $('.more').click(function(){$('.serp_descr').css("display","block")});
   
 });

function mailFriend(mailAddress){	
	document.getElementById('btnTellfriend').disabled = true;	
	if(isValidEmail(mailAddress)){	
		
		if(mailAddress!=document.getElementById('tellfriend').defaultValue){
			$.get("/tellafriend.php?mailAddress="+mailAddress, function(data){var data = data.split('msg:');
			
			if(data[0]=='error')
				$('#head-inset form fieldset').html('<p class="message-error">Bericht niet verzonden</p>');
			else if(data[0]=='succes')				
				$('#head-inset form fieldset').html('<p class="message-ok">Bericht verzonden</p>');
			});
		}
		else{
			alert("Voer een emailadres in.");
			document.getElementById('btnTellfriend').disabled = false;
		}
//			$('#mail-a-friend-return').html = "Voer een emailadres in.";
	}
	else{
		alert("Voer een geldig emailadres in.");
		document.getElementById('btnTellfriend').disabled = false;
	}
//		$('#mail-a-friend-return').html = "Voer een geldig emailadres in.";
	
	return false;
}

function isValidEmail(mailAddress){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(mailAddress)) {
		return true;
	}
	return false;
}
