$(document).ready(function(){
	$("#belme_button").mouseover(function(){
		$(this).addClass('belme_button_h');
	});
	$("#belme_button").mouseout(function(){
		$(this).removeClass('belme_button_h');
	});
	$("#bellen_naam").focus(function(){
		if($(this).val() == 'naam'){
			$(this).val('');
		}
	});
	$("#bellen_naam").blur(function(){
		if($(this).val() == ''){
			$(this).val('naam');
		}
	});
	$("#bellen_telefoonnummer").focus(function(){
		if($(this).val() == 'telefoonnummer'){
			$(this).val('');
		}
	});
	$("#bellen_telefoonnummer").blur(function(){
		if($(this).val() == ''){
			$(this).val('telefoonnummer');
		}
	});
	$("#belme_button").click(function(){
		var name = $("#bellen_naam").val();
		var phone = $("#bellen_telefoonnummer").val();
		if((name != 'naam' && name != '') && (phone != 'telefoonnummer' && phone != '') && phone.length > 9){
			$.post('/media/basic/ajax/mail.php',{
				action : 'bel',
				name : name,
				phone : phone
			},function(data){
				if(data == "SUCCESS"){
					$("#footer_title").html('wij bellen je terug! wij hebben je gegevens ontvangen.');
					$("#footer_title").animate({ top : '+=60'}, 500);
					$("#footer_form").animate({ top : '+=60'}, 500);
				}
			});
		}else if((name == 'naam' || name == '') || (phone == 'telefoonnummer' || phone == '')){
			$("#footer_title").html('wij bellen je terug! maar je moet beide velden wel invullen.');
		}else if(phone.length < 10){
			$("#footer_title").html('wij bellen je terug! maar je moet wel een juist telefoonnummer invullen.');
		}
	});
	$("#contact_button").click(function(){
		var name = $("#naam").val();
		var company = $("#bedrijf").val();
		var email = $("#email").val();
		var code = $("#code").val();
		var message = $("#bericht").val();
		if((name != 'Naam' && name != '') && (email != 'E-mail' && email != '') && (code != 'hier' && code != '' && code == 'ifthen') && (message != 'Bericht' && message != '') && validateMail(email)){
			$.post('/media/basic/ajax/mail.php',{
				action : 'mail',
				name : name,
				company: company,
				email: email,
				code : code,
				message : message
			},function(data){
				if(data == "SUCCESS"){
					//$("#contact_container").fadeOut('slow', function() {
						$("#contact_container").html("<div style=\"padding-right: 25px;\">Wij hebben je gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.</div>");
					//	$("#contact_container").fadeIn('slow');
					//});
				}
			});
		}if((name == 'Naam' || name == '')){
			$("#naam").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#naam").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((email == 'E-mail' || email == '') || !validateMail(email)){
			$("#email").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#email").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((code == 'hier' || code == '') || code != 'ifthen'){
			$("#code").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#code").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((message == 'Bericht' || message == '')){
			$("#bericht").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#bericht").css({ 'border' : '1px solid #B3B3B3' });
		}
	});
	
	lineWidth();
	smalllineWidth();
});

$(window).resize(function () {
	lineWidth();
	smalllineWidth();
});

function validateMail(email){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
		return false;
	}else{
		return true;
	}
}

function lineWidth(){
	
	var documentwidth = $(window).width();
	var linewidth = (documentwidth / 2) + (340);
	$(".line").css({ width: linewidth+'px' });
	linewidth -= 800;
	$(".line #subnav, .line .subnav").css({ left: linewidth+'px' });
}

function smalllineWidth(){
	var documentwidth = $(window).width();
	//alert(documentwidth);
	var linewidth = (documentwidth / 2 - 85);
	//alert(linewidth);
	$(".smallline").css({ width: linewidth+'px' });
	//linewidth -= 800;
	$(".smallline #subnav, .smallline .subnav").css({ left: '' });
}

