$(document).ready(function(){
		//CONTINENT   SELECTION
		$("#continent").change(function(){
			var cont = document.getElementById("continent").options[document.getElementById("continent").selectedIndex].value;
			var coun = 0;
			$.getJSON('contact-us/jSonFindContact',
					   {continent:cont,country:coun},
					   function(json){
							updateCountrySelectBox(json.countries,json.ids);
							updateContact(json.contact);
					   });
		});
		
		//COUNTRY SELECTION
		$("#country").change(function(){
			var cont = document.getElementById("continent").options[document.getElementById("continent").selectedIndex].value;
			var coun = document.getElementById("country").options[document.getElementById("country").selectedIndex].value;
			$.getJSON('contact-us/jSonFindContact',
					   {continent:cont,country:coun},
					   function(json){
							updateContact(json.contact);
					   });
		});	
})

// Update  the   displayed   contact
function updateContact(contact){
	if(contact != "undefined"){
		var sel = '<h3>'+contact.name+'</h3>';
		sel += '<p>Visiting Adress : <br />'+contact.adress+', '+contact.zip+' '+contact.city+'<br />';
		if(contact.correspondence != '')
			sel += 'Postal Adress : <br />'+contact.correspondence;
		sel += '</p>';
		if(contact.state != '')
			sel += '<p>'+contact.state.toUpperCase()+'</p>';
		if(contact.phone1 != '')
			sel += '<p>Phone : '+contact.phone1;
		if(contact.phone2 != '')
			sel += '<br \>Phone 2 : '+contact.phone2;
		if(contact.phone3 != '')
			sel += '<br \>Phone 3 : '+contact.phone3;
		if(contact.phone4 != '')
			sel += '<br \>Phone 4 : '+contact.phone4;
		sel += '</p>';
		sel += '<p>Fax : '+(contact.fax)+'</p>';
		if(contact.email != ''){
			var content = 'sjfskjfskfwuwuiewieiqueiqajddaadkskjsf';
			var email = contact.email.replace('@', '@<span class="hide">'+content+'</span>');
			sel += '<p>Email : '+email+'</p>';
		}
		$('#us').html(sel);
	}
}

// CREATION  OF   THE    COUNTRY   SELECTBOX
function updateCountrySelectBox(countries,ids){
	var cont = document.getElementById("continent").options[document.getElementById("continent").selectedIndex].value;
	var sel = '';
	for(var i=0 ; i < countries.length ; i++){
		if(countries.length == 1 && countries[i].toLowerCase() == "unknown"){
			countries[i] = "Countries";
		}
		sel += '<option value="'+ids[i]+'">'+countries[i]+'</option>';
	}
	// INSERT   THE    COUNTRY  SELECTBOX   CONTENT
	$('#country').html(sel);
}
