function sendForm2WS(url) {
	if (!this.$) return true;
	var idForm = wsForm;	if (!idForm) idForm= "lavaForm";
	if (!($("#" + idForm).get(0))) return true;
	try {
		/* get all the fields in the form and put them as queryString */
		var parameters = $("#" + idForm).serialize();
		/* hide all the errors */
		$(".error").hide(); 
		$("#errFacebook").hide();
		/* send reg info to WS */
		$.post(url, parameters, function (data) {},"json");
		return false;
	} catch (err) {;}
	return true;
}
function processWSResponse(data) {
	if (!this.$) return;
	var idForm = wsResponseForm; if (!idForm) idForm= "lavaPostProcessForm";
	try {
		/* if success move to next URL */
		if (data.status == "OK" || data.status == "UNDERAGE") {
			/* get the url returned by ws and move there */
			var ppForm = $("#" + idForm).get(0); 
			if (!ppForm) return;
			ppForm.action = prepareUrlToSubmit(data.nextURL);
			ppForm.submit();
			return;
		} else if (data.status == "RELOAD") {
			sendForm2WS(data.reloadURL);
		}
		/* got errors - show them */
		showWsErr(data);
	} catch (err) {;}
}

function prepareUrlToSubmit(nextUrl) {
	if ((location.protocol).indexOf("https")>-1){
		return (nextUrl.replace("#", "___"));
	}

	return nextUrl;
}

  function showWsErr(errs) {
    $.each(errs.errorCodes, function(i, errorType) {
       $("#" + errorType).css("display","inline-block");
       if ($("#" + errorType).hasClass('hiddeForm')) {
          $(".loginSection").hide();
       }
    });
  }

  function submitForgotPwd(url) {
	return sendForm2WS(url);
  }

  function processFPwdResponse(data) {
	if (!this.$) return;
	var idForm = wsForm;	if (!idForm) return;
	try {
		if (data.valid == "false") {
		   if (data.validEmail == "false") {
				$("#errorInvalidEmail").show();
			} else if (data.memberExists == "false") {
				$("#errorMemberNotExists").show();
			}
		} else {
			$("#"+idForm).hide();
			$("#forgotPwdSuccess").show();
		}
	}catch(err) {
	}
  }
