// JavaScript Document
function userSearch() {
	id="";
	if((!document.loginForm.login.value)||(!document.loginForm.password.value)) {
		alert(simpleText("missingLogin"));
	} else {
		$.ajax({
			type: "POST",
			url: "/phpInc/data_xmlHttpReturn.php",
			dataType: "xml",
			data: "_=001&__="+document.loginForm.login.value+"&___="+document.loginForm.password.value,
			async: false,
			success: function(xmlData) {
				id=$("id:eq(0)",xmlData).text();
			}});

		if(id!="")
		{
			$.ajax({
				type: "POST",
				url: "/phpInc/session_instancier.php",
				dataType: "html",
				data: "_="+id,
				async: false,
				success: function(returnValue) {
					$.ajax({
						type: "POST",
						url: "/forms/login.htm.php",
						dataType: "html",
						async: false,
						success: function(returnHTML) {
							$("div[name='signupForm']").html(returnHTML);
						}});
				}});
			sessionCounterDisplay();
			$(document).ready(function() {
				$("#searchLaunch").attr("disabled","");
		   });

			sessionUrl=getSessionValue("pWanted");
			if(sessionUrl!="") {window.location="http://"+sessionUrl;}
		}
		else
		{
			document.loginForm.login.value="";
			document.loginForm.password.value="";
			loginDialogOpen();
		}
	}
}

function userSearch2() {
	id="";
	if((!document.loginForm2.login.value)||(!document.loginForm2.password.value)) {
		alert(simpleText("missingLogin"));
	} else {
		$.ajax({
			type: "POST",
			url: "/phpInc/data_xmlHttpReturn.php",
			dataType: "xml",
			data: "_=001&__="+document.loginForm2.login2.value+"&___="+document.loginForm2.password2.value,
			async: false,
			success: function(xmlData) {
				id=$("id:eq(0)",xmlData).text();
			}});

		if(id!="")
		{
			$.ajax({
				type: "POST",
				url: "/phpInc/session_instancier.php",
				dataType: "html",
				data: "_="+id,
				async: false
				});
			//sessionCounterDisplay();
			$('#dialog').html("");
			$('#dialog').jqmHide();
			$.ajax({
				type: "POST",
				url: "/phpInc/horse_people_init.php",
				dataType: "html",
				data: "_="+id,
				async: false
				});
			$(document).ready(function() {
				$("#searchLaunch").attr("disabled","");
		   });
			if(getSessionValue("horse_chatmail_offer")=="2") {
				hChatOpenSession2();
			} else {
				sessionUrl=getSessionValue("pWanted");
				if(sessionUrl!="") {window.location="http://"+sessionUrl;}
			}
		}
		else
		{
			document.loginForm2.login.value="";
			document.loginForm2.password.value="";
			$('p[id="errorLogin"]').html("&nbsp;<br/>&nbsp;<br/>"+simpleText("error"));
		}
	}
}

function userHelp() {
	$.ajax({
		type: "POST",
		url: "/forms/login.htm.php",
		dataType: "html",
		data: "_=001&help=1",
		async: false,
		success: function(returnHTML) {
			$("div[name='signupForm']").html(returnHTML);
		}});
}

function userHelp2() {
	$.ajax({
		type: "POST",
		url: "/forms/login2.htm.php",
		dataType: "html",
		data: "_=001&help=1",
		async: false,
		success: function(returnHTML) {
			$("div[name='signupForm2']").html(returnHTML);
		}});
}

function userLoginSend() {
	if(!document.loginForm.mail.value) {
			alert(simpleText("missingMail"));
	} else {
		if(document.loginForm.mail.value) {mailValue=document.loginForm.mail.value;}
		$.ajax({
			type: "POST",
			url: "/phpInc/data_xmlHttpReturn.php",
			dataType: "xml",
			data: "_=002&__="+mailValue,
			async: false,
			success: function(xmlData) {
				if($("pseudo:eq(0)",xmlData).text()!=""){
					pseudo=$("pseudo:eq(0)",xmlData).text();
					password=$("password:eq(0)",xmlData).text();
					mail=$("mail:eq(0)",xmlData).text();
				} else {
					pseudo="";
				}
			},
			error: function () {
				pseudo="";
			}});
		if(pseudo!="") {
			$.ajax({
				type: "POST",
				url: "/phpInc/mailer.php",
				dataType: "html",
				data: "_=8&__=renvoiIdentifiants&___=pseudo|"+pseudo+"||password|"+password+"||mail|"+mail,
				async: true
			});
			alert(simpleText("sentMail"));
		}
		else
		{
			alert(simpleText("errorMail"));
		}
		$.ajax({
			type: "POST",
			url: "/forms/login.htm.php",
			dataType: "html",
			data: "_=001",
			async: false,
			success: function(returnHTML) {
				$("div[name='signupForm']").html(returnHTML);
			}});
	}
}

function userLoginSend2() {
	if(!document.loginForm2.mail2.value) {
			alert(simpleText("missingMail"));
	} else {
		if(document.loginForm2.mail2.value) {mailValue=document.loginForm2.mail2.value;}
		$.ajax({
			type: "POST",
			url: "/phpInc/data_xmlHttpReturn.php",
			dataType: "xml",
			data: "_=002&__="+mailValue,
			async: false,
			success: function(xmlData) {
				if($("pseudo:eq(0)",xmlData).text()!=""){
					pseudo=$("pseudo:eq(0)",xmlData).text();
					password=$("password:eq(0)",xmlData).text();
					mail=$("mail:eq(0)",xmlData).text();
				} else {
					pseudo="";
				}
			},
			error: function () {
				pseudo="";
			}});
		if(pseudo!="") {
			$.ajax({
				type: "POST",
				url: "/phpInc/mailer.php",
				dataType: "html",
				data: "_=8&__=renvoiIdentifiants&___=pseudo|"+pseudo+"||password|"+password+"||mail|"+mail,
				async: true
			});
			alert(simpleText("sentMail"));
			$('#dialog').jqmHide();
		}
		else
		{
			alert(simpleText("errorMail"));
		}
		$.ajax({
			type: "POST",
			url: "/forms/login.htm.php",
			dataType: "html",
			data: "_=001",
			async: false,
			success: function(returnHTML) {
				$("div[name='signupForm']").html(returnHTML);
			}});
	}
}

function sessionCounterDisplay() {
		$.ajax({
			type: "POST",
			url: "/phpInc/ajax_session_counter.php",
			dataType: "html",
			async: false,
			success: function(returnHTML) {
				$("#sessionCounter").html(returnHTML);
			}});
}

function loginDialogOpen() {
	$('#dialog').jqmShow();
}

function simpleText(itemName) {
	$.ajax({
		type: "POST",
		url: "/phpInc/ajax_simple_text_display.php",
		dataType: "html",
		data: "_="+itemName,
		async: false,
		success: function(returnHTML) {
			sT=returnHTML;
		}});
	return(sT);
}