/**
 * test form before submit
 */
function WRSubmitForm()
{
    if( document.webref.url.value=='' && document.webref.sitemapurl.value=='') {
        alert("Saisir l'adresse de votre site web  ou de son fichier sitemap");
        return false;
    }else if( document.webref.code.value=='') {
        alert("Saisir le code de validation");
        return false;
    }else{
        document.webref.submit();
    }
}

/**
 * change src image for gstat
 * @param string nlleSource
 */
function WRChangeImgForGstat(nlleSource)
{
      if (document.getElementById("ImgForGstat"))
        document.images.ImgForGstat.src=nlleSource;
}

/**
 * lance un nouvel appel pour récupérer les infos de captcha
 *
 */
function WRCaptchaRefresh()
{
    var oScript = document.createElement("script");
    oScript.src = 'getCaptcha.php?d='+WRRandomString(10, false);
    oScript.type = "text/javascript";
    document.body.appendChild(oScript);
    document.body.removeChild(oScript);
}

/**
 * Callback de l'appel à de mise à jours des infos captcha
 * @param oJson
 */
function WRCallback(oJson)
{
    var oCaptchaContainerElt = document.getElementById('captcha_container');

    oCaptchaContainerElt.src = oJson.url;
    document.webref.validation_code.value = oJson.code;
}

/**
 * Generates a random string with the specified length
 * @param {Int} nLength The length of the random string
 * @param {Bool} bNoNumber When activated, no numbers will be used in the random string
 * @return {String} The random string generated
 */
function WRRandomString(nLength, bNoNumber)
{
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    if (bNoNumber)
        chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var randomstring = '';
    for (var i = 0; i < nLength; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}


