/****************************************
* JQuery - On Document Ready
****************************************/
$(document).ready(function() {
	callContactData(0);
	
	$('#contactBox_Locations').change(function(){
		location_id = $(this).val();
		callContactData(location_id);
	});
});

function callContactData(id){
	$.ajax({
		url: 'index.php?eID=contactData&id='+id,
    	type: 'post',
    	dataType: 'html',
    	error: function(){
        	alert('Error loading document');
    	},
    	success: function(html){
    		renderContactBox(html);
    		if (boxmode == 'extended') {
    			var url = parseAnfahrtsURL(html);
    			$("#anfahrtskarte").attr("src", url);
    		}
    	}
	});
}

function renderContactBox(json){
	var jsonarray = eval('('+json+')');
	if(jsonarray) {
		$('#contactbox_street').html(jsonarray['street']);
		$('#contactbox_city').html(jsonarray['city']);
		$('#contactbox_telefon').html(jsonarray['telefon']);
		$('#contactbox_fax').html(jsonarray['fax']);
		$('#contactbox_email').html('<a class="blue-link" href="index.php?id='+jsonarray['email']+'">zur Pflegegruppe</a>');
	}
}

function parseAnfahrtsURL(json) {
	var jsonarray = eval('('+json+')');
	if(jsonarray) {
		var url = 'http://maps.google.de/maps?f=q&source=s_q&hl=de&geocode=&q='+jsonarray['street']+','+jsonarray['city']+'&output=embed';
	}
	return url;
}
