function SendMail()
{
	
	var  senderemail = $("form#mailform input.senderemail").attr("value");
	var  sendername = $("form#mailform input.sendername").attr("value");
	var receiveremail = $("form#mailform input.receiveremail").attr("value");
	var receivername = $("form#mailform input.receivername").attr("value");
	var comment = $("form#mailform textarea .comment").attr("value");
	
	var title = $("div.middle h1:first").text().replace(/\n|\r\n|\t/g, '');
	if(title == "")
	{
		title = $("div.left_large h1:first").text().replace(/\n|\r\n|\t/g, '');
	}
	if(title == "")
	{
		title = $("div.fullpage h1:first").text().replace(/\n|\r\n|\t/g, '');
	}	
	if(title == "")
	{
		title = document.title;
	}
	
	$("#mailform input.pagetitle").attr("value", title);
	
	if(senderemail!=null && sendername != null && receiveremail!=null && receivername!=null)
	{
		if(echeck(senderemail) && echeck(receiveremail))
		{
			var submit = {submit:"1"}
			$("form#mailform").attr("action","/templates/dispatcher.asp?page_id=emailform")			
			
			$("form#mailform").ajaxSubmit({success:SendSuccessfull, data:submit})
		}else{
			alert("Geen geldig(e) email adres(sen) ingevuld.");
		}
	}else{
		alert("Niet alle velden zijn ingevuld");
		//$("div#mailform").prepend("<div class=\"error\">Niet alle velden ingevuld.</div>");
	}
}

function echeck(str) {
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
	}

function SendSuccessfull(data)
{
	$("div.mailform").html(data);
	$("div.mailform").animate({height:"50px"});
	var time = window.setTimeout('$("div.mailform").animate({height:"0px"}, function(){$("div.mailform").css("display", "none");});', 5000);
};

function ShowMailForm(objectname)
{
	if($("div.mailform").html() == null)
	{
		$(objectname).prepend("<div class=\"mailform\"></div>");
		$("div.mailform").load("/EmailForm",{},function(){SetMailformInputBackgrounds();});
	}
	if($("div.mailform").css("height")=="0px")
	{
		$("div.mailform").load("/EmailForm",{},function(){SetMailformInputBackgrounds();});
		$("div.mailform").animate({height:"350px"});
	}
	else
		$("div.mailform").animate({height:"0px"}, function(){$("div.mailform").css("display", "none");});
}

function ResetForm()
{
	$("input:not(\"input.submit, input.reset\")").attr("value", "");
	$("textarea.comment").attr("value", "");
	$("div.mailform").animate({height:"0px"}, function(){$("div.mailform").css("display", "none");});
}
