﻿/* -------------------------------------------------------------------
 AJAX -------------------------------------------------------------- */

	function createRequestObject() {
		var ro;
		if(browserName == "MSIE"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	var http = createRequestObject();
	

/*-------------------------------------------------------------
	Function validateSend
	Validate the send to a friend popin
---------------------------------------------------------------*/

function validateSend(path_query_url){
	goon = 0;
	
	if ( document.getElementById("stf_name").value == "" ){ document.getElementById("l_stf_name").className = "error"; goon = 1; }else{ document.getElementById("l_stf_name").className = ""; }
	if ( !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("stf_email").value)){ document.getElementById("l_stf_email").className = "error"; goon = 1; }else{ document.getElementById("l_stf_email").className = ""; }
	if ( document.getElementById("stf_friend_name").value == "" ){ document.getElementById("l_stf_friend_name").className = "error"; goon = 1; }else{ document.getElementById("l_stf_friend_name").className = ""; }
	if ( !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("stf_friend_email").value) ){ document.getElementById("l_stf_friend_email").className = "error"; goon = 1; }else{ document.getElementById("l_stf_friend_email").className = ""; }
	
	if (goon == 1){
		document.getElementById("div_stf_error").style.display = "block";
	}else{
		document.getElementById("div_stf_error").style.display = "none";
		sendFriend(document.getElementById('stf_name').value,document.getElementById('stf_email').value , document.getElementById('stf_friend_name').value , document.getElementById('stf_friend_email').value , document.getElementById('stf_comments').value);
	}
}


/*-------------------------------------------------------------
	Function sendFriend
	Send the email with Ajax.
---------------------------------------------------------------*/

function sendFriend(name,email,friendsname,friendsemail,comments,path_query_url){
	http.open('get', '/3084/db_envoyer.asp?friendsname=' + escape(friendsname) + '&name=' + escape(name) + '&friendsemail=' + friendsemail + '&email=' + email + '&comments=' + escape(comments) + '&path_query_url=');
	http.onreadystatechange = handleSend;
	http.send(null);
}


function handleSend(){
	if(http.readyState == 4){
		var response = http.responseText;
		
		if(response == "good"){
			document.getElementById("div_stf_thanks").style.display = "block";
			document.getElementById("b_send").style.visibility = "hidden";	
		}else{
		    alert("not good");
	    }
		
	}
}

/*function handleSend(){
alert(responseText);
	if(http.readyState == 4){
		if(http.responseText=="good"){
			document.getElementById("div_stf_thanks").style.display = "block";
			document.getElementById("b_send").style.visibility = "hidden";	
		}else{
		alert("not good");
	}
		
	}
}*/

    

/*-------------------------------------------------------------
	Function closeSendFriend
	Validate the send to a friend popin
---------------------------------------------------------------*/

function closeSendFriend(){
	document.getElementById("send_friend").style.display = "none";
	document.getElementById("form_send_friend").reset();
	document.getElementById("div_stf_thanks").style.display = "none";
	document.getElementById("b_send").style.visibility = "visible";
	
}
