function send_contact_us(host){
	var reason = document.getElementById('id_reason');
	var visitor_name = document.getElementById('id_name_visitor');
	var visitor_email = document.getElementById('id_email_visitor');
	var comment = document.getElementById('id_comment');
	var button = document.getElementById('id_button_send');
	var message_id = '';
	if (comment.value == ''){
		alert('Please fill at least the comment field.');
	} else {
		reason.disabled = true;
		visitor_name.disabled = true;
		visitor_email.disabled = true;
		comment.disabled = true;
		button.value = 'Sending...';
		button.disabled = true;
		var url = 'http://'+host+'/ajax/ajaxContactUs.php';
		//alert(url);
		var pars = 'reason='+escape(reason.value)+'&visitor_name='+escape(visitor_name.value)+'&visitor_email='+escape(visitor_email.value)+'&comment='+escape(comment.value)+'&browser='+escape(navigator.userAgent.toLowerCase())+'&resolution='+screen.width+'x'+screen.height;
		//alert(pars);
		//ajax/ajaxContactUs.php?reason=feedback&visitor_name=&visitor_email=&comment=toto

		/* send an email */
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: function(originalRequest) {change_content_contact_us(originalRequest); return true}
		});
	}
}

function change_content_contact_us(originalRequest){
	//alert(originalRequest.responseText);
	if (originalRequest.responseText == 'true'){
		document.getElementById('thanks').style.display = 'block';
		document.getElementById('tell').style.display = 'none';
		document.getElementsByTagName('h1')[0].style.display = 'none';
		document.getElementsByTagName('h1')[1].style.display = 'block';

		document.getElementsByTagName('p')[0].style.display = 'none';

		document.getElementById('id_reason').value = '';
		document.getElementById('id_name_visitor').value = '';
		document.getElementById('id_email_visitor').value = '';
		document.getElementById('id_comment').value = '';
	}
	else
	{
		document.getElementById('error_mess').style.display = 'block';
	}

	document.getElementById('id_reason').disabled = false;
	document.getElementById('id_name_visitor').disabled = false;
	document.getElementById('id_email_visitor').disabled = false;
	document.getElementById('id_comment').disabled = false;
	document.getElementById('id_button_send').disabled = false;
	document.getElementById('id_button_send').value= 'Submit';
}

function CreateBookmarkLink() {

	var browserName=navigator.appName;
	var title = "Ecocho: You search: We grow trees.";
	var url = "http://www.ecocho.com/";

	if (browserName == "Netscape"){
		window.sidebar.addPanel(title, url,"");
	}
	else {
		if (browserName == "Microsoft Internet Explorer"){
			window.external.AddFavorite( url, title );
		}
		else{
			if(browserName == "Opera") {
				window.sidebar.addPanel(title, url,"");
			}
			else{
				document.write('This Tool is not available for your browser');
			}
		}
	}
}

function write_link(host, TAF, GETB, BU, MEYHP, SI, LANG){
	var browserName=navigator.appName;

	if (browserName == "Netscape"){
		document.write('<a href="http://'+host+'/tell_a_friend.php">'+TAF+'</a> | <a href="http://'+host+'/ecocho-tools.php">'+GETB+'</a> | <a href="#" onclick="javascript:CreateBookmarkLink();">'+BU+'</a> | <a href="http://'+host+'/share_it.php">'+SI+'</a>');
		//alert("Hi Netscape User!");
	}
	else {
		if (browserName == "Microsoft Internet Explorer"){
			document.write('<a href="http://'+host+'/tell_a_friend.php">'+TAF+'</a> | <a href="http://'+host+'/ecocho-tools.php">'+GETB+'</a> | <a href="#" onclick="this.style.behavior = \'url(#default#homepage)\';this.setHomePage(\'http://'+host+'\');">'+MEYHP+'</a> | <a href="http://'+host+'/share_it.php">'+SI+'</a>');
		}
		else{
			document.write('<a href="http://'+host+'/tell_a_friend.php">'+TAF+'</a> | <a href="http://'+host+'/ecocho-tools.php">'+GETB+'</a> | <a href="http://'+host+'/share_it.php">'+SI+'</a>');
		}
	}

//	if (browserName == "Netscape"){
//		document.write('<a href="http://'+host+'/add_a_website.php" ><img src="http://'+host+'/images/ico_new.png" style="border:0px;" /></a>&nbsp;<a href="http://'+host+'/add_a_website.php" >Add a Website</a> | <a href="http://'+host+'/tell_a_friend.php">'+TAF+'</a> | <a href="http://'+host+'/ecocho-tools.php">'+GETB+'</a> | <a href="http://'+host+'/share_it.php">'+SI+'</a>');
//		//alert("Hi Netscape User!");
//	}
//	else {
//		if (browserName == "Microsoft Internet Explorer"){
//			document.write('<a href="http://'+host+'/add_a_website.php" ><img src="http://'+host+'/images/ico_new.png" style="border:0px;" /></a>&nbsp;<a href="http://'+host+'/add_a_website.php" >Add a Website</a> | <a href="http://'+host+'/tell_a_friend.php">'+TAF+'</a> | <a href="http://'+host+'/ecocho-tools.php">'+GETB+'</a> | <a href="#" onclick="this.style.behavior = \'url(#default#homepage)\';this.setHomePage(\'http://'+host+'\');">'+MEYHP+'</a> | <a href="http://'+host+'/share_it.php">'+SI+'</a>');
//		}
//		else{
//			document.write('<a href="http://'+host+'/add_a_website.php" ><img src="http://'+host+'/images/ico_new.png" style="border:0px;" /></a>&nbsp;<a href="http://'+host+'/add_a_website.php" >Add a Website</a> | <a href="http://'+host+'/tell_a_friend.php">'+TAF+'</a> | <a href="http://'+host+'/ecocho-tools.php">'+GETB+'</a> | <a href="http://'+host+'/share_it.php">'+SI+'</a>');
//		}
//	}

}

function send_email(host, err1, err2, err3, s_send, sending){
	var remote_email = document.getElementById('id_remote_email');
	var visitor_name = document.getElementById('id_visitor_name');
	var visitor_email = document.getElementById('id_visitor_email');
	var button = document.getElementById('id_button_send');
	var close_button = document.getElementById('div_close_main');

	if (remote_email.value == '' || visitor_name.value == '' || visitor_email.value == ''){
		alert(err1);
	}
	else
	{
		remote_email.disabled = true;
		visitor_name.disabled = true;
		visitor_email.disabled = true;
		//close_button.display = 'none';

		button.value = sending;
		button.disabled = true;

		var url = 'http://'+host+'/ajax/ajaxSendMail.php';
		var pars = 'remote_emails='+remote_email.value+'&visitor_name='+visitor_name.value+'&visitor_email='+visitor_email.value;
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: function(originalRequest) {change_content(originalRequest, err2, err3, s_send); return true}
		});
	}
}

function change_content(originalRequest, err2, err3, s_send){
	if (originalRequest.responseText == 'true'){
		show('id_main_thanks');
		hide('tell_a_friend');
	}
	else
	{
		if (originalRequest.responseText == 'email'){
			alert(err2);
		}
		else
		{
			alert(err3);
		}
	}
	document.getElementById('id_remote_email').disabled = false;
	document.getElementById('id_visitor_name').disabled = false;
	document.getElementById('id_visitor_email').disabled = false;
	document.getElementById('id_button_send').disabled = false;
	document.getElementById('id_button_send').value = s_send;
}

function get_mail_preview(domain){
	var visitor_name = document.getElementById('id_visitor_name');

	var url = 'http://'+domain+'/ajax/ajaxMailPreview.php';
	var pars = 'visitor_name='+visitor_name.value;

	/* send an email */
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'get',
		parameters: pars,
		onComplete: function(originalRequest) {display_mail_preview(originalRequest); return true}
	});
}

function display_mail_preview(originalRequest){
	var preview_div = document.getElementById('id_preview');
	document.getElementById('id_preview').innerHTML = originalRequest.responseText;
	preview_div.style.display = 'block';
}


