Cufon.replace('.nice');

$(document).ready(function(){
//	$("li.menu_short").hide();
//	$("ul.menu_short").append('<li style="text-align:center">Geef alle weer</li>')
});

function send_experience(company_id)
{

	$.post("?module=experience&company_id=" + company_id, {
			action:"post"
			, name:$("input[name=xp_name]").val()
			, email:$("input[name=xp_email]").val()
			, experience:$("textarea[name=xp_experience]").val()
			, company_id:company_id			
		}, 
		function(data) {
	  		if (data.status == true)
	  		{
	  			$("#experience").load("index.php?module=company&company_id=" + company_id + " div#experience");
	  		}
	  		else
	  		{
	  			$("div#experience input").removeClass("false");
	  			$("div#experience textarea").removeClass("false");
				$.each(data.error, function(index, value) { 
					$("*[name=xp_" + index + "]").addClass("false");
				});
	  		}
		}
	, "json");

}

function find_company()
{

	var find_zipcode = $("input[name=find_zipcode]").val().replace(" ", "");
	
	$("div#companies_result").html('<img src="templates/global/images/loading.gif" />');
	$("div#companies_result").load("?request=xmlhttp&module=register&action=find_company&find_zipcode=" + find_zipcode + "&find_housenumber=" + $("input[name=find_housenumber]").val() + "  div#companies_result", function() {  });
	
	/*
	$.post("?module=register&action=find_company", {
			request:"xmlhttp"
			, action:"find_company"
			, zipcode:
			, housenumber:$("input[name=find_housenumber]").val()		
		}, 
		function(data) {
	  		
		}
	, "json");
	*/
}

function register()
{
	var disclaimer = 0;
	if ($("input[name=disclaimer]:checked").val() == 1) disclaimer = 1;

	$.post("?request=json&module=register&action=register", {
			company:$("input[name=company]").val()	
			, registration_nr:$("input[name=registration_nr]").val()
			, tax_nr:$("input[name=tax_nr]").val()
			, street:$("input[name=street]").val()
			, housenumber:$("input[name=housenumber]").val()
			, zipcode:$("input[name=zipcode]").val()
			, city_id:$("select[name=city_id]").val()
			, website:$("input[name=website]").val()
			, email:$("input[name=email]").val()
			, category_id:$("select[name=category_id]").val()
			, disclaimer:$("input[name=disclaimer]").val()								
		}, 
		function(data) {
	  		if (data.status == true)
	  		{
	  			location.href = '?module=user&action=edit';
	  		}
	  		else
	  		{
	  			$("div#registration_form input").removeClass("false");
	  			$("div#registration_form textarea").removeClass("false");
				$.each(data.error, function(index, value) { 
					$("*[name=" + index + "]").addClass("false");
				});
	  		}
		}
	, "json");
}

function fill_company(registration_nr, company, street, housenumber, city_id)
{
	$("input[name=registration_nr]").val(registration_nr);
	$("input[name=company]").val(company);
	$("input[name=street]").val(street);
	$("input[name=housenumber]").val(housenumber);
	$("select[name=city_id]").val(city_id);
}

		
		  function codeAddress() {
		  var geocoder;
		  var map;
		  
		    geocoder = new google.maps.Geocoder();
		    var latlng = new google.maps.LatLng(52.06, 5.07);
		    var myOptions = {
		      zoom: 13,
		      center: latlng,
		      mapTypeId: google.maps.MapTypeId.ROADMAP,
		      disableDefaultUI: true
		    }
		    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		  
		    var address = $("input[name=zipcode]").val() + " Nederland";
		    
		    if (geocoder) {
		      geocoder.geocode( { 'address': address}, function(results, status) {
		        if (status == google.maps.GeocoderStatus.OK) {
		          map.setCenter(results[0].geometry.location);
		          var marker = new google.maps.Marker({
		              map: map, 
		              position: results[0].geometry.location
		          });
		          tmp = results[0].geometry.location;
		          coords = String(tmp).split(',');
		          $("input[name=location_lat]").val(coords[0].replace("(",""));
		          $("input[name=location_lon]").val(coords[1].replace(")",""));
		        } else {
		          alert("Geocode was not successful for the following reason: " + status);
		        }
		      });
		    }
		  }
