  $(document).ready(function(){
	$("#contact-SEND").click(function(){
		var valid = '';
		var isr = ' is required. ';
		var name = $("#contact-name").val();
		var mail = $("#contact-email").val();
		var text = $("#contact-message").val();

		
		if (name.length<1) {
			valid += 'Name'+isr;
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += 'A valid Email'+isr;
		}
		if (text.length<1) {
			valid += 'A message'+isr;
		}
		
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html(valid);
			setTimeout('$("#response").fadeOut("slow")',4000);
		}
		else {
		
			var datastr ='contact-name=' + name + '&contact-email=' + mail + '&contact-message=' + text;
			$("#response").css("display", "block");
			$("#response").html("Sending message .... ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
}); 
 
 
/*
 $(document).ready(function(){
	$("#sendmail").click(function(){
		var valid = '';
		var isr = ' is required.';
		var name = $("#contact-name").val();
		var mail = $("#contact-email").val();
		var text = $("#contact-message").val();

		
		if (name.length<1) {
			valid += '<br />Name'+isr;
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />A valid Email'+isr;
		}
		if (text.length<1) {
			valid += '<br />Text'+isr;
		}
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Error:"+valid);
		}
		else {
		
		
			var datastr ='name=' + name + '&mail=' + mail + '&text=' + text + '&recaptcha_challenge_field=' + $("#recaptcha_challenge_field").val() + '&recaptcha_response_field=' + $("#recaptcha_response_field").val();
			$("#response").css("display", "block");
			$("#response").html("Sending message .... ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
});
function send(datastr){
	$.ajax({	
		type: "POST",
		url: "includes/mail_verify.php",
		data: datastr,
		cache: false,
		success: function(msg){
		
			var msgdisplay = "";
			
			if( msg == "success" ){
				msgdisplay = "<font color='green'>Message was successfully sent. Thank you.</font>"; 
				setTimeout('disablePopup()',3000);				
			}
			else if( msg == "incorrect-captcha-sol" ){
				msgdisplay = "<font color='red'>reCAPTCHA was not entered correctly.</font>"; 		
			}
			else if( msg == "empty" ){
				msgdisplay = "<font color='red'>Please enter all fields.</font>"; 			
			}
			else{  
				msgdisplay = "<font color='red'>There was an error.</font>"; 			
			}	
			
			$("#response").fadeIn("slow");
			$("#response").html(msgdisplay);
			setTimeout('$("#response").fadeOut("slow")',2000);
	}
	});
}
*/

//POPUP
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

var popupStatus = 0;

function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": 500+(windowHeight/2-popupHeight/2),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

$(document).ready(function(){
	$("#contact-open").click(function(){
	
		if( $("#contact-name").val() == "" || $("#contact-email").val() == "" || $("#contact-message").val() == ""){
		}
		else{
			centerPopup();
			loadPopup();
		}
	});
				
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

