﻿// JScript File
//------------------------//
//-   LoginIsValid       -//
//------------------------//

function LoginIsValid(id)
{
    if(document.getElementById(id).value != '')
    {
        return WebService.LoginIsValid(document.getElementById(id).value,id,OnComplete,OnError,OnTimeOut);
    }
}


function EmailAlreadyExists(id,oldValue)
{
    email  = document.getElementById(id).value;
    if (email !='')
    {
        MemberDidNotValidatePreviousInscription(email);
        if(document.getElementById(id).value != '' && document.getElementById(id).value != oldValue)
        {
            return WebService.EmailAlreadyExists(email,id,OnComplete,OnError,OnTimeOut);
        }
    }
}

function MemberDidNotValidatePreviousInscription(email)
{
    if (email !='')
    {
        return WebService.MemberHasOneValidatedInscription(email, OnComplete,OnError,OnTimeOut);
    }
}

function HideMsgEmailAlreadyExists()
{
    document.getElementById("MessageEmailExists").style.display = "none";
    //document.getElementById("MessageIncriptionNotValidated").style.display = "none";
}

function OnComplete(args,result, response, userContext)
{
    //retour test du Pseudo
    if(args[0]=='Pseudo')
    {
        alert('Pseudo déjà utilisé.');
        if(args[1] != null)
        {
            document.getElementById(args[1]).value='';
        }
    } 
     
    //retour test de l'Email
    if(args[0]=='Email')
    {
        //alert('Merci de choisir une autre adresse email.');
        document.getElementById("MessageEmailExists").style.display = "block";
        if(args[1] != null)
        {
            document.getElementById(args[1]).value='';
        }
    } 
    
   
    
    //retour du geocodage address
    if(args[0]=='Address')
    {
        LatLng.value = args[2];
        if(args[1] != "200")
        {
            document.getElementById('divMsgGooble').style.display = 'block';
        }
    }
    
    //retour email de confirmation
    if(args[0]=='validation')
    {
        if(args[1] != "")
        {
        //document.getElementById('MessageIncriptionNotValidated').innerText = re
        document.getElementById('MessageIncriptionNotValidated').style.display = 'block';
            //alert(args[1]);
        }
    }
    
}


function OnTimeOut(arg)
{
    alert('timeOut has occured');
}
function OnError(arg)
{
    //alert('error has occured');
}


//--------------------//
//-   geocodage      -//
//--------------------//


var geocoder = null;
var addressToCheck;
var address = null;
var zipCode = null;
var City = null;
var LatLng = null;

  

function InStr(strSearch, charSearchFor)
{
    return strSearch.indexOf(charSearchFor);
}

function TestAdress()
{
    var cpt = 0;
    document.getElementById('divMsgGooble').style.display = 'none';
    for(var i=0;i<document.forms[0].length;i++) 
    {
        if(InStr(document.forms[0][i].id,'txtAddress') > -1)
        {
            address = document.getElementById(document.forms[0][i].id);
        }
        
        if(InStr(document.forms[0][i].id,'txtPostCode') > -1)
        {
            zipCode = document.getElementById(document.forms[0][i].id);
        }

        if(InStr(document.forms[0][i].id,'txtCity') > -1)
        {
            City =  document.getElementById(document.forms[0][i].id);
        }

        if(InStr(document.forms[0][i].id,'hidLatLng') > -1)
        {
            LatLng =  document.getElementById(document.forms[0][i].id);      
        }
    }

    if(address.value != '' && zipCode.value != '' && City.value != '')
    {
        addressToCheck = address.value + '$' + zipCode.value + '$' + City.value;
        WebService.GetGpsInformation(addressToCheck,OnComplete,OnError,OnTimeOut);
    }
}
