$(document).ready(function(){
	$('.home_block').mouseover(function(){
		var id = $(this).attr('id').replace('home_block_','');
		//alert(id);
		$('#home_content_'+id).addClass('home_content_active');
		//$('#home_bottom_'+id).addClass('home_bottom_active');
	});
	$('.home_block').mouseout(function(){
		var id = $(this).attr('id').replace('home_block_','');
		//alert(id);
		$('#home_content_'+id).removeClass('home_content_active');
		//$('#home_bottom_'+id).removeClass('home_bottom_active');
	});
	$(".home_bottom").mouseover(function(){
		$(this).addClass('home_bottom_active');
	});
	$(".home_bottom").mouseout(function(){
		$(this).removeClass('home_bottom_active');
	});
	
	$(".contactbtn").mouseover(function(){
		$(this).attr('src','/media/basic/images/identa_btn_contact_h.png');
	});
	$(".contactbtn").mouseout(function(){
		$(this).attr('src','/media/basic/images/identa_btn_contact.png');
	});
	$("#phonenumber").focus(function(){
		if($(this).val() == 'Telefoonnummer')
			$(this).val('');
	});
	$("#phonenumber").blur(function(){
		if($(this).val() == '')
			$(this).val('Telefoonnummer');
	});
	
	$("#name").focus(function(){
		if($(this).val() == 'Naam')
			$(this).val('');
	});
	$("#name").blur(function(){
		if($(this).val() == '')
			$(this).val('Naam');
	});
	
	$("#contact_btn").click(function(){
		var name = $("#naam").val();
		var phonenumber = $("#telefoon").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 == 'identa') && (message != 'Bericht' && message != '') && validateMail(email)){
			$.post('/media/basic/ajax/mail.php',{
				action : 'identamail',
				name : name,
				phonenumber: phonenumber,
				email: email,
				code : code,
				message : message
			},function(data){
				if(data == "SUCCESS"){
					//$("#contact_container").fadeOut('slow', function() {
						$("#contactform").html("<h2>Bedankt</h2>Wij hebben uw gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.");
					//	$("#contact_container").fadeIn('slow');
					//});
				}
			});
		}if((name == 'Naam' || name == '')){
			$("#naam").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#naam").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((email == 'E-mail' || email == '') || !validateMail(email)){
			$("#email").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#email").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((code == 'hier' || code == '') || code != 'identa'){
			$("#code").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#code").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((message == 'Bericht' || message == '')){
			$("#bericht").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#bericht").css({ 'border' : '1px solid #B3B3B3' });
		}
	});
	
	$("#pc_btn").click(function(){
		var name = $("#cname").val();
		var phone = $("#cphoneno").val();
		var email = $("#cemail").val();
		
		var relation_name = $("#relation_name").val();
		var relation_phone = $("#relation_phone").val();
		var relation_email = $("#relation_email").val();
		var relation_company = $("#relation_company").val();
		var relation_city = $("#relation_city").val();
		var code = $("#code").val();
		
		if($("#agree").is(":checked") && (name != 'Naam' && name != '') && (email != 'E-mailadres' && email != '') && (code != 'hier' && code != '' && code == 'identa') && (relation_company != 'Bedrijfsnaam' && relation_company != '') && (relation_city != 'Vestigingsplaats' && relation_city != '') && (relation_name != 'Contactpersoon' && relation_name != '') && (relation_email != 'E-mailadres Contactpersoon' && relation_email != '') && validateMail(email) && validateMail(relation_email)){
			$.post('/media/basic/ajax/mail.php',{
				action : 'identaPC',
				name : name,
				phone: phone,
				email: email,
				code : code,
				relation_company : relation_company,
				relation_city : relation_city,
				relation_name : relation_name,
				relation_email : relation_email,
				relation_phone : relation_phone
			},function(data){
				if(data == "SUCCESS"){
					//$("#contact_container").fadeOut('slow', function() {
						//$("#content_item").html("<h2>Bedankt</h2>Wij hebben uw gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.");
						window.location = '/bedankt-pcactie/';
					//	$("#contact_container").fadeIn('slow');
					//});
				}
			});
		}
		
		if(!$("#agree").is(":checked")){
			$("#agree_text").css({ 'color' : '#662D91' });
		}else{
			$("#agree_text").css({ 'color' : '#888888' });
		}
		if((name == 'Naam' || name == '')){
			$("#cname").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#cname").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((email == 'E-mailadres' || email == '') || !validateMail(email)){
			$("#cemail").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#cemail").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((relation_company == 'Bedrijfsnaam' || relation_company == '')){
			$("#relation_company").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#relation_company").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((relation_city == 'Vestigingsplaats' || relation_city == '')){
			$("#relation_city").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#relation_city").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((relation_name == 'Contactpersoon' || relation_name == '')){
			$("#relation_name").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#relation_name").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((relation_email == 'E-mailadres Contactpersoon' || relation_email == '') || !validateMail(relation_email)){
			$("#relation_email").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#relation_email").css({ 'border' : '1px solid #B3B3B3' });
		}
		
		
		if((code == 'hier' || code == '') || code != 'identa'){
			$("#code").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#code").css({ 'border' : '1px solid #B3B3B3' });
		}
	});
	
	$("#ipad_btn").click(function(){
		var name = $("#cname").val();
		var company = $("#ccompany").val();
		var email = $("#cemail").val();
		
		var code = $("#code").val();
		
		if((name != 'Naam' && name != '') && (email != 'E-mailadres' && email != '') && (company != 'Bedrijfsnaam' && company != '') && (code != 'hier' && code != '' && code == 'identa') && validateMail(email)){
			$.post('/media/basic/ajax/mail.php',{
				action : 'identaIPAD',
				name : name,
				company: company,
				email: email
			},function(data){
				if(data == "SUCCESS"){
					//$("#contact_container").fadeOut('slow', function() {
						//$("#content_item").html("<h2>Bedankt</h2>Wij hebben uw gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.<br /><br />Wilt u ook meedoen aan de PC actie? Ga dan naar <a href='http://www.identa.nl/pcactie/'>www.identa.nl/pcactie</a>");
						
						window.location = '/bedankt-ipad-actie/';
					//	$("#contact_container").fadeIn('slow');
					//});
				}
			});
		}
		
		if((name == 'Naam' || name == '')){
			$("#cname").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#cname").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((email == 'E-mailadres' || email == '') || !validateMail(email)){
			$("#cemail").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#cemail").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((company == 'Bedrijfsnaam' || company == '')){
			$("#ccompany").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#ccompany").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((code == 'hier' || code == '') || code != 'identa'){
			$("#code").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#code").css({ 'border' : '1px solid #B3B3B3' });
		}
	});
	
	$(".phone_btn").click(function(){
		var name = $("#name").val();
		var phonenumber = $("#phonenumber").val();
		
		if((phonenumber != 'Telefoonnummer' && phonenumber != '') && (name != 'Naam' && name != '')){
			$.post('/media/basic/ajax/mail.php',{
				action : 'identacall',
				name : name,
				phonenumber : phonenumber
			},function(data){
				if(data == "SUCCESS"){
					//$("#contact_container").fadeOut('slow', function() {
						$("#phone").html("Wij hebben uw gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.");
					//	$("#contact_container").fadeIn('slow');
					//});
				}
			});
		}if((phonenumber == 'Telefoonnummer' || phonenumber == '')){
			$("#phonenumber").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#phonenumber").css({ 'border' : '1px solid #B3B3B3' });
		}if((name == 'Naam' || phonenumber == '')){
			$("#name").css({ 'border' : '1px solid #662D91' });
		}else{
			$("#name").css({ 'border' : '1px solid #B3B3B3' });
		}
	});
	
	$("#address_btn").click(function(){
		getDirections();
	});

	//setTimeout(function(){close_header();},10000); 
	
	var config = {    
		     over: open_header, // function = onMouseOver callback (REQUIRED)    
		     timeout: 2000, // number = milliseconds delay before onMouseOut    
		     out: close_header // function = onMouseOut callback (REQUIRED)    
		};	
   //$('#top').hoverIntent(config);
});


var latv;
var lngv;
var address='\'t veld 3 Heteren nederland';
var map;

function load() {
	if(GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("maps"));
		var customUI = map.getDefaultUI();
		customUI.maptypes.normal = false;
		customUI.maptypes.physical = false;
		customUI.maptypes.hybrid = false;
		customUI.maptypes.satellite = false;
		customUI.zoom.scrollwheel = true;
		customUI.zoom.doubleclick = true;
		customUI.keyboard = true;
		
		customUI.controls.largemapcontrol3d = false;
		customUI.controls.smallzoomcontrol3d = false;
		customUI.controls.maptypecontrol = false;
		customUI.controls.menumaptypecontrol = false;
		customUI.controls.scalecontrol = false;
	
		map.setUI(customUI);
		
		geocoder = new GClientGeocoder();
		var custIcon = new GIcon(G_DEFAULT_ICON);
		custIcon.image = "/media/basic/images/identa_maps_pointer.png";
		custIcon.shadow = "/media/basic/images/shadow.png";
		custIcon.iconSize = new GSize(118, 63);
		custIcon.shadowSize = new GSize(0, 0);
		custIcon.iconAnchor = new GPoint(60, 55);
		markerOptions = { icon:custIcon };

		geocoder.getLocations(address, function(point) {
			latv=point.Placemark[0].Point.coordinates[1];
			lngv=point.Placemark[0].Point.coordinates[0];
			map.setCenter(new GLatLng(latv,lngv), 11, G_PHYSICAL_MAP);
			var point = new GLatLng(latv,lngv);
			var marker = new GMarker(point,markerOptions);
			var html = "";
			map.addOverlay(marker);
		});
	}
}

var directionsPanel;
var directions;

function getDirections() {
	//alert('');
	$("#gmapform").html('<h1>Routebeschrijving</h2>');
	map = new GMap2(document.getElementById("maps"));
	geocoder = new GClientGeocoder();
	directionsPanel = document.getElementById("gmapform");
	var customUI = map.getDefaultUI();
	customUI.maptypes.normal = false;
	customUI.maptypes.physical = false;
	customUI.maptypes.hybrid = false;
	customUI.maptypes.satellite = false;
	customUI.zoom.scrollwheel = true;
	customUI.zoom.doubleclick = true;
	customUI.keyboard = true;
	
	customUI.controls.largemapcontrol3d = false;
	customUI.controls.smallzoomcontrol3d = false;
	customUI.controls.maptypecontrol = false;
	customUI.controls.menumaptypecontrol = false;
	customUI.controls.scalecontrol = false;

	map.setUI(customUI);
		
		geocoder = new GClientGeocoder();
		var custIcon = new GIcon(G_DEFAULT_ICON);
		custIcon.image = "/media/basic/images/identa_maps_pointer.png";
		custIcon.shadow = "/media/basic/images/shadow.png";
		custIcon.iconSize = new GSize(118, 63);
		custIcon.shadowSize = new GSize(0, 0);
		custIcon.iconAnchor = new GPoint(60, 55);

		markerOptions = { icon:custIcon };
		geocoder.getLocations(address, function(point) {
		latv=point.Placemark[0].Point.coordinates[1];
		lngv=point.Placemark[0].Point.coordinates[0];
		map.setCenter(new GLatLng(latv,lngv), 15, G_PHYSICAL_MAP);
			var point = new GLatLng(latv,lngv);
			var marker = new GMarker(point,markerOptions);
			var html = "";
			map.addOverlay(marker);
		directions = new GDirections(map, directionsPanel);
		fromadd=$('#gmap_address').val()+" nederland";
		directions.load("from: "+fromadd+" to:"+address,{ locale: 'nl' });
	});
	$("#gmapform").css({display: 'block'});
	//$("#gmapbutton").css({display: 'block'});
	//$("#contactform").css({display: 'none'});
}

function showFormulier(){
	$("#gmapform").css({display: 'none'});
	$("#gmapbutton").css({display: 'none'});
	$("#contactform").css({display: 'block'});
}

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 close_header(){
	if($("#header_10years").css("margin-top") == '0px'){
		$('#header_10years').animate({
		  "margin-top": "-243px"
		}, "slow");
	}
}

function open_header(){
	if($("#header_10years").css("margin-top") == '-243px'){
		$('#header_10years').animate({"margin-top": "0"}, "slow");
	}
}
