var xmlhttp=false;

try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}


if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}

// FLASHED	
function member_flash(member_id){
	xmlhttp.open("GET", "member_process.php?do_action=member_flash&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var popup_flash_texte 		= document.getElementById('popup_flash_texte');
			switch (xmlhttp.responseText) {
				case "ok":
					HidePage('flash');
				break;
				case "bl_him_to_you":
					popup_flash_texte.innerHTML = "<span style='color:#FC66A9'>"+MISC_INFOS_FLASH_BL_HIM_TO_YOU+"</span>";
					HidePage('flash');
				break;
				case "bl_you_to_him":
					popup_flash_texte.innerHTML = "<span style='color:#FC66A9'>"+MISC_INFOS_FLASH_BL_YOU_TO_HIM+"</span>";
					HidePage('flash');
				break;
			}
		}
	}
	xmlhttp.send(null);
}

// FRIENDS
function member_friends(member_id, member_login){
	xmlhttp.open("GET", "member_process.php?do_action=member_friends&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200){
				
				switch (xmlhttp.responseText){
					case "ok":						
						Alerte(MISC_TITLE_ADD_FRIEND,MISC_ALERTE_ADD_FRIEND+"<strong>" +member_login + "</strong>");
					break;
					
					case "bl_him_to_you":			
						Alerte(MISC_TITLE_ADD_FRIEND,MISC_INFOS_ADD_FRIEND_BL_HIM_TO_YOU);
						
					break;
					
					case "bl_you_to_him":
						document.getElementById('link_yes').href ='javascript:member_friends_force(\'' + member_id + '\', \'' + member_login + '\');'
						Confirm(MISC_TITLE_ADD_FRIEND,MISC_CONFIRM_ADD_FRIEND_BL_HIM_TO_YOU, '');
					break;
					
					case "friends_you_to_him":	
						Alerte(MISC_TITLE_ADD_FRIEND,MISC_ALERTE_ADD_ALLREADY_FRIEND);
					break;
					
					case "friends_him_to_you":						
						document.getElementById('link_yes').href ='javascript:member_friends_accept(\'' + member_id + '\', \'' + member_login + '\');'
						document.getElementById('link_no').href ='javascript:member_friends_refuse(\'' + member_id + '\', \'' + member_login + '\');'
						Confirm(MISC_TITLE_ADD_FRIEND,MISC_CONFIRM_ADD_ALLREADY_FRIEND, '');
					break;
				}
			}
		}
	}
	xmlhttp.send(null);
}

function member_friends_force(member_id, member_login){
	xmlhttp.open("GET", "member_process.php?do_action=member_friends_force&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

			switch (xmlhttp.responseText){
				case "ok":
					ShowPage();
					Alerte(MISC_TITLE_ADD_FRIEND,MISC_ALERTE_ADD_FRIEND+"<strong>" + member_login + "</strong>");
				break;
			}
		}
	}
	xmlhttp.send(null);
}

function member_friends_accept(member_id, member_login){
	xmlhttp.open("GET", "member_process.php?do_action=member_friends_accept&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

			switch (xmlhttp.responseText){
				case "ok":
					Alerte(MISC_TITLE_ADD_FRIEND,MISC_ALERTE_ACCEPT_FRIEND+" <strong>" + member_login + "</strong> "+MISC_ALERTE_ACCEPT_FRIEND_2);
				break;
			}
		}
	}
	xmlhttp.send(null);
}

function member_friends_refuse(member_id, member_login){
	xmlhttp.open("GET", "member_process.php?do_action=member_friends_refuse&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var popup_friends_texte 		= document.getElementById('popup_friends_texte');
			var popup_friends_liste 		= document.getElementById('popup_friends_liste');
			
			switch (xmlhttp.responseText){
				case "ok":
					popup_friends_liste.innerHTML = '';
					popup_friends_texte.innerHTML = MISC_ALERTE_REFUSE_FRIEND+" <strong>" + member_login + "</strong>";
				break;
			}
		}
	}
	xmlhttp.send(null);
}

function member_friends_force_add_ask(){
	var member_login   = document.getElementById("member_login_friend").value;
	
	var params = "do_action=member_friends_force_add_ask&member_login="+member_login;
	xmlhttp.open("POST", "my_process.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText == "ok"){
				document.friendlist_form.submit();
			}else{
				ShowBubble(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.send(params);
}


// BLACK LISTE
function member_bl(member_id, member_login){
	xmlhttp.open("GET", "member_process.php?do_action=member_bl&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			switch (xmlhttp.responseText){
				case "ok":
					Alerte(MISC_TITLE_ADD_BLACKLIST, "<strong>"+member_login+"</strong> "+MISC_ALERTE_ADD_BLACKLIST);
				break;
				case "friends_him_to_you":
					document.getElementById('link_yes').href ='javascript:member_bl_force(\'' + member_id + '\', \'' + member_login + '\');'
					Confirm(MISC_TITLE_ADD_BLACKLIST, MISC_CONFIRM_ADD_BLACKLIST_FRIEND_HIM_TO_YOU, '');
					
				break;
				case "friends_you_to_him":
					Alerte(MISC_TITLE_ADD_BLACKLIST, MISC_CONFIRM_ADD_BLACKLIST_FRIEND_YOU_TO_HIM);
				break;
				case "is_bl":
					Alerte(MISC_TITLE_ADD_BLACKLIST, MISC_ALERTE_ADD_ALLREADY_BLACKLIST );
				break;
			}
		}
	}
	xmlhttp.send(null);
}

function member_bl_force(member_id , member_login){
	xmlhttp.open("GET", "member_process.php?do_action=member_bl_force&ref="+member_id, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			switch (xmlhttp.responseText){
				case "ok":
					ShowPage();
					Alerte(MISC_TITLE_ADD_BLACKLIST,"<strong>" + member_login + "</strong> "+MISC_ALERTE_ADD_BLACKLIST);
				break;
			}
		}
	}
	xmlhttp.send(null);
}

// MAIL
function mail_change_read_status(ref_mail){
	var params = "do_action=mail_change_read_status&ref_mail="+ref_mail;
	xmlhttp.open("POST", "my_mail_process.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				
		}
	}
	xmlhttp.send(params);
}

// MAIL
function mail_change_read_author_status(ref_mail){
	var params = "do_action=mail_change_read_author_status&ref_mail="+ref_mail;
	xmlhttp.open("POST", "my_mail_process.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		
		}
	}
	xmlhttp.send(params);
}

function mail_send(){
	var msg = '';
	var mail_author_id     = current_author_id;
	var mail_destinator_id = current_destinator_id;
	var mail_title 		   = document.getElementById("mail_title").value;
	var mail_body 		   = document.getElementById("mail_body").value;
	
	
	if (document.getElementById("options_my_mail_1") && document.getElementById("options_my_mail_1").style.display=="block"){

		var friend_list        = document.getElementById("my_friend_list_1");
		if (friend_list.options[friend_list.selectedIndex].value != "" && friend_list.options[friend_list.selectedIndex].value != "-1"){
			var mail_member_login  = friend_list.options[friend_list.selectedIndex].value;
		}else{
			var mail_member_login  = document.getElementById("mail_member_login_1").value;
		}
		current_destinator_login=mail_member_login;
		if (mail_member_login == ""){
			msg += MISC_INFOS_SEND_MAIL_PSEUDO;
		}
	}
	
	if (mail_title == ""){
		msg += MISC_INFOS_SEND_MAIL_SUBJECT;
	}
	
	if (mail_body == ""){
		msg += MISC_INFOS_SEND_MAIL_BODY;
	}
	
	if (document.getElementById("mail_body").value == ''){
		document.getElementById("mail_body").focus();
	}
	if (document.getElementById("mail_title").value == ''){
		document.getElementById("mail_title").focus();
	}
	if (document.getElementById("mail_member_login") && document.getElementById("mail_member_login").style.display == 'block' && document.getElementById("mail_member_login").value == ''){
		document.getElementById("mail_member_login").focus();
	}
	
	if (msg == ""){
		var params = "do_action=mail_send&mail_author_id="+mail_author_id+"&mail_destinator_id="+mail_destinator_id+"&mail_title="+mail_title+"&mail_body="+mail_body+"&mail_member_login="+mail_member_login;
		xmlhttp.open("POST", "my_mail_process.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				switch (xmlhttp.responseText) {
					case "ok":
						ShowPage();
						Alerte(MISC_TITLE_SEND_MAIL,MISC_ALERTE_SEND_MAIL+current_destinator_login+' !');
					break;
					case "yourself":
						ShowBubble(MISC_INFOS_SEND_MAIL_YOURSELF);
					break;
					case "bl_him_to_you":
						ShowBubble(MISC_INFOS_SEND_MAIL_BL_HIM_TO_YOU);
					break;
					case "bl_you_to_him":
						ShowBubble(MISC_INFOS_SEND_MAIL_BL_YOU_TO_HIM);
					break;
					case "member_not_exist":
						ShowBubble(MISC_INFOS_SEND_MAIL_NOT_MEMBER);
					break;
					case "no_abonnement":
						document.location = "subscription_pass.php?action=mailed&ref="+mail_destinator_id;
					break;
				}
			}
		}
		xmlhttp.send(params);
	}else{
		ShowBubble(msg);
	}
}

function mail_send_private(){
	var msg = '';
	var mail_author_id     = document.getElementById("mail_author_id").value;
	var mail_destinator_id = document.getElementById("mail_destinator_id").value;
	var mail_title 		   = document.getElementById("mail_title").value;
	var mail_file 		   = document.getElementById("mail_file").value;
	
	
	if (document.getElementById("mail_member_login").style.display == 'block'){
		var friend_list        = document.getElementById("my_friend_list");
		if (friend_list.options[friend_list.selectedIndex].value != ""){
			var mail_member_login  = friend_list.options[friend_list.selectedIndex].value;
		}else{
			var mail_member_login  = document.getElementById("mail_member_login").value;
		}
		current_destinator_login=mail_member_login;
		if (mail_member_login == ""){
			msg += MISC_INFOS_SEND_MAIL_PSEUDO;
		}
	}
	
	if (msg == ""){
		var params = "do_action=mail_send_private&mail_author_id="+mail_author_id+"&mail_destinator_id="+mail_destinator_id+"&mail_title="+mail_title+"&mail_file="+mail_file+"&mail_member_login="+mail_member_login;
		xmlhttp.open("POST", "my_mail_process.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				switch (xmlhttp.responseText) {
					case "ok":
						ShowPage();
						Alerte(MISC_TITLE_SEND_MAIL,MISC_ALERTE_SEND_MAIL+current_destinator_login+' !');
					break;
					case "yourself":
						ShowBubble(MISC_INFOS_SEND_MAIL_YOURSELF);
					break;
					case "bl_him_to_you":
						ShowBubble(MISC_INFOS_SEND_MAIL_BL_HIM_TO_YOU);
					break;
					case "bl_you_to_him":
						ShowBubble(MISC_INFOS_SEND_MAIL_BL_YOU_TO_HIM);
					break;
					case "member_not_exist":
						ShowBubble(MISC_INFOS_SEND_MAIL_NOT_MEMBER);
					break;
					case "no_abonnement":
						document.location = "subscription_pass.php?action=mailed&ref="+mail_destinator_id;
					break;
				}
			}
		}
		xmlhttp.send(params);
	}else{
		ShowBubble(msg);
	}
}

//Search
function get_state(){
	var country_id   = name_div('country_id');
	var state_id     = name_div('state_id');
	var city     	 = name_div('city');
	var state_id_content = name_div('state_id_content');
	var city_content = name_div('city_content');
	
	var params = "country_id="+country_id.options[country_id.selectedIndex].value;
	
	xmlhttp.open("POST", "get_state.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			state_id_content.innerHTML = '<select name="state_id" id="state_id" class="geo" onchange="javascript:get_city();">'+xmlhttp.responseText+'</select>';
			city_content.innerHTML = '<select name="city" id="city" class="geo"><option value="-1"></option></select>';
		}
	}
	xmlhttp.send(params);
}

function get_city(){
	var country_id   = name_div('country_id').value;
	var state_id     = name_div('state_id');
	var city	     = name_div('city');
	var city_content = name_div('city_content');
	
	var params = "country_id="+country_id+"&state_id="+state_id.options[state_id.selectedIndex].value;
	xmlhttp.open("POST", "get_city.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			city_content.innerHTML = '<select name="city" id="city" class="geo">'+xmlhttp.responseText+'</select>';
		}
	}
	xmlhttp.send(params);
}

function get_count_search(action, target, redirect, form){
	form.do_action.value=action;
	form.action = 'my_search_count.php';
	if (action != '')
		form.submit();
	else
		return false;
}

/* ::::::::::::::::::::::::::::::::::::::::::
   ::::::::::::::::::::::::::::::::::::::::::
    GESTION DE LA VISIBILTE
   ::::::::::::::::::::::::::::::::::::::::::
   ::::::::::::::::::::::::::::::::::::::::::
*/

function change_visibility(){
	var params = "do_action=mode_visibility";
	xmlhttp.open("POST", "my_process.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			switch (xmlhttp.responseText) {
				case "ok":
					if(document.getElementById("btn_no_dispo").className=="btn_no_dispo_on"){
						document.getElementById("btn_no_dispo").className="btn_no_dispo_off";
						document.getElementById("btn_dispo").className="btn_dispo_on";
					}else{
						document.getElementById("btn_no_dispo").className="btn_no_dispo_on";
						document.getElementById("btn_dispo").className="btn_dispo_off";
					}if(!isIE){
						document.getElementById("btn_no_dispo").blur();
						document.getElementById("btn_dispo").blur();
					}
				break;
			}
		}
	}
	xmlhttp.send(params);
}

//Signup
function member_signup(){
	
	if (document.getElementsByName("member_sexe")[0].checked){
		var member_sexe = document.getElementsByName("member_sexe")[0].value;
	}else if (document.getElementsByName("member_sexe")[1].checked){
		var member_sexe = document.getElementsByName("member_sexe")[1].value;
	}else{
		var member_sexe = "";
	}
	
	if (document.getElementsByName("member_sexe_seek")[0].checked){
		var member_sexe_seek = document.getElementsByName("member_sexe_seek")[0].value;
	}else if (document.getElementsByName("member_sexe_seek")[1].checked){
		var member_sexe_seek = document.getElementsByName("member_sexe_seek")[1].value;
	}else{
		var member_sexe_seek = "";
	}
	
	var member_login   = document.getElementById("member_login").value;
	var member_password= document.getElementById("member_password").value;
	
	var member_email   = document.getElementById("member_email").value;
	var date_d 		   = document.getElementById("date_d");
		date_d		   = date_d.options[date_d.selectedIndex].value;
	var date_m 		   = document.getElementById("date_m");
		date_m		   = date_m.options[date_m.selectedIndex].value;
	var date_y 		   = document.getElementById("date_y");
		date_y		   = date_y.options[date_y.selectedIndex].value;
		
	var country_id 	   = document.getElementById("country_id");
		country_id	   = country_id.options[country_id.selectedIndex].value;
	var state_id 	   = document.getElementById("state_id");
		state_id	   = state_id.options[state_id.selectedIndex].value;
	var city 		   = document.getElementById("city");
		city		   = city.options[city.selectedIndex].value;
	
	var member_condition 		   = document.getElementById("member_condition").checked;
	
	
	var params = "do_action=my_signup_ask&member_sexe="+member_sexe+"&member_sexe_seek="+member_sexe_seek+"&member_login="+member_login+"&member_password="+member_password+"&member_email="+member_email+"&date_d="+date_d+"&date_m="+date_m+"&date_y="+date_y+"&country_id="+country_id+"&state_id="+state_id+"&city="+city+"&member_condition="+member_condition;
	xmlhttp.open("POST", "my_process.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText == 1){
					document.form_signin.submit();
			}else{
				ShowBubble(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.send(params);
}

function member_signup_get_conf(){
	var ref 		   = document.getElementById("ref").value;
	
	var params = "do_action=my_signup_get_conf&ref="+ref;
	xmlhttp.open("POST", "my_process.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText == 1){
				Alerte(MISC_TITLE_SIGNUP,MISC_ALERTE_SIGNUP);
			}else{
				Alerte(MISC_TITLE_SIGNUP,MISC_ALERTE_SIGNUP_ERROR);
			}
		}
	}
	xmlhttp.send(params);
}

// account
function reloadDiv(div1, div2){
	document.getElementById(div1).innerHTML = document.getElementById(div2).innerHTML;
}
function my_update_account(){
	var account_content 	 = document.getElementById("account_content");
	var old_pass 			 = document.getElementById("old_pass");
	var new_pass 			 = document.getElementById("new_pass");
	var verif_pass			 = document.getElementById("verif_pass");
	
	var params = "do_action=my_update_account&old_pass="+old_pass.value+"&new_pass="+new_pass.value+"&verif_pass="+verif_pass.value;
	xmlhttp.open("POST", "my_process.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			switch (xmlhttp.responseText) {
				case "infos_ok":
					HideBubble();
					account_content.innerHTML = MISC_INFOS_UPDATE_ACCOUNT
					+'<div class="btn_fermer"><a href="javascript:ShowPage();location.reload()" title=/"'+MISC_CLOSE+'/"><span>'+MISC_CLOSE+'</span></a></div>'
				break;
				case "no_old":
					old_pass.value = '';
					ShowBubble(MISC_INFOS_UPDATE_ACCOUNT_OLD_MDP);
				break;
				case "infos_noegal":
					new_pass.value = '';
					verif_pass.value = '';
					ShowBubble(MISC_INFOS_UPDATE_ACCOUNT_WRONG_MDP);
				break;
				case "infos_empty":
					verif_pass.value = '';
					new_pass.value = '';
					ShowBubble(MISC_INFOS_UPDATE_ACCOUNT_SPEC_MDP);
				break;
				case "close":
					ShowPage();
				break;
			}
		}
	}
	xmlhttp.send(params);
}
function signout(){
	var member_login_signout = document.getElementById("member_login_signout").value;
	var member_password      = document.getElementById("member_password").value;
	
	var params = "do_action=signout&member_login_signout="+member_login_signout+"&member_password="+member_password;
	xmlhttp.open("POST", "my_process.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			switch (xmlhttp.responseText) {
				case "ok":
					Submit_signout();
				break;
				default :
					ShowBubble(MISC_INFOS_SIGNOUT);
				break;
			}
		}
	}
	xmlhttp.send(params);
}