function RG()
{
    l = document.ReviewGuide.language.value;
    user = document.ReviewGuide.user.value;
    pwd = document.ReviewGuide.pwd.value;
    review = document.ReviewGuide.review.value;
    score = document.ReviewGuide.score.options[document.ReviewGuide.score.selectedIndex].value;

    if(user == "" || pwd == "")
    {
        if(l=="it")
            m="Inserire il proprio nome utente e password";
        else
            m="Enter your username and password";

        alert(m);

        document.ReviewGuide.user.focus();

        return;
    }

    if(review == "")
    {
        if(l=="it")
            m="Inserire il testo per la recensione";
        else
            m="Enter a text for the review";

        alert(m);

        document.ReviewGuide.review.focus();

        return;
    }

    if(score == "-1")
    {
        if(l=="it")
            m="Selezionare il punteggio";
        else
            m="Select a score";

        alert(m);

        document.ReviewGuide.score.focus();

        return;
    }

    if(l=="it")
        m="Confermi l'invio della tua recensione?";
    else
        m="Confirm sending your review?";

    if(confirm(m))
        document.ReviewGuide.submit();
    else
        return;
}

function UR()
{
    l = document.ReviewGuide.language.value;
    review = document.ReviewGuide.review.value;
    score = document.ReviewGuide.score.options[document.ReviewGuide.score.selectedIndex].value;

    if(review == "")
    {
        if(l=="it")
            m="Inserire il testo per la recensione";
        else
            m="Enter a text for the review";

        alert(m);

        document.ReviewGuide.review.focus();

        return;
    }

    if(score == "-1")
    {
        if(l=="it")
            m="Selezionare il punteggio";
        else
            m="Select a score";

        alert(m);

        document.ReviewGuide.score.focus();

        return;
    }

    if(l=="it")
        m="Confermi l'aggiornamento della tua recensione?";
    else
        m="Confirm updating your review?";

    if(confirm(m))
        document.ReviewGuide.submit();
    else
        return;
}

function DSS(l, i)
{
    if(l == "it")
    {
        diamtxt = "Diamant";
        startxt = "Stella";
        diamsing = "e";
        diamplur = "i";
        congtxt = "e";
    }
    else
    {
        diamtxt = "Diamond";
        startxt = "Star";
        diamsing = "";
        diamplur = "s";
        congtxt = "and";
    }

    document.write("<option value=\"-1\"></option>\n");

    for(d=5; d>0; d--)
    {
        for(s=1; s>=0; s--)
        {
            v = "" + d + "" + s;

            document.write("<option value=\"" + v + "\"");

            if(i == v)
                document.write(" selected");

            document.write(">" + d + " " + diamtxt);

            if(d > 1)
                document.write(diamplur);
            else
                document.write(diamsing);

            if(s == 1)
                document.write(" " + congtxt + " " + s + " " + startxt);

            document.write("</option>\n");
        }
    }
}

function RVS(v)
{
    var cur = new Array(2);

    cur[0] = new Array("&euro;", "EUR");
    cur[1] = new Array("$", "USD");

    for(i=0; i<cur.length; i++)
    {
        c0 = cur[i][0];
        c1 = cur[i][1];

        document.write("<option value=\"" + c1 +"\"");

        if(v == c1)
            document.write(" selected");

        document.write(">" + c0 + "</option>\n");
    }
}

function ShowScore()
{
    var img;

    v = document.ReviewGuide.score.options[document.ReviewGuide.score.selectedIndex].value;

    if(v != "-1")
    {
        d = parseInt(v.substring(0,1));
        s = parseInt(v.substring(1));
    }
    else
    {
        d = 0;
        s = 0;
    }

    imgname = "/images/diamond.gif";

    ndx = 1;

    for(i=0; i<d; i++)
    {
        img = eval("document.images.ds" + ndx);

        img.src = imgname;

        ndx++;
    }

    imgname = "/images/star.gif";

    for(i=0; i<s; i++)
    {
        img = eval("document.images.ds" + ndx);

        img.src = imgname;

        ndx++;
    }

    imgname = "/images/dsnull.gif";

    for(i=ndx; i<=6; i++)
    {
        img = eval("document.images.ds" + ndx);

        img.src = imgname;

        ndx++;
    }
}

function RGF(l,x,y,rt,wd,v,rl)
{
    if(l == "it")
    {
        user = "Utente";
        pwd = "Password";
        vintagetag = "Annata";
        msg = "La Tua Recensione";
        cleft = "Caratteri disponibili";
        place = "Luogo Degustazione";
        price = "Prezzo";
        score = "Punteggio";
        btn = "Invia la Tua Recensione";
    }
    else
    {
        user = "User";
        pwd = "Password";
        vintagetag = "Vintage";
        msg = "Your Review";
        cleft = "Characters left";
        place = "Place of Tasting";
        price = "Price";
        score = "Score";
        btn = "Send Your Review";
    }

    document.write("<form action=\"/actions/AddReview" + "Guide.php\" name=\"ReviewGuide\" method=\"POST\">\n");
    document.write("<input type=\"hidden\" name=\"language\" value=\"" + l +"\">\n");
    document.write("<input type=\"hidden\" name=\"x\" value=\"" + x + "\">\n");
    document.write("<input type=\"hidden\" name=\"y\" value=\"" + y + "\">\n");
    document.write("<input type=\"hidden\" name=\"t\" value=\"" + rt + "\">\n");
    document.write("<input type=\"hidden\" name=\"wd\" value=\"" + wd + "\">\n");
    document.write("<table align=\"Center\" border=\"0\" class=\"large\" width=\"100%\">\n");
    document.write("<tbody><tr><td align=\"Left\" width=\"20%\">" + user + "</td>\n");
    document.write("<td width=\"80%\"><input type=\"text\" name=\"user\" value=\"\" class=\"large\" style=\"width: 15em;\">&nbsp;&nbsp;&nbsp;");
    document.write(pwd + "&nbsp;<input type=\"password\" name=\"pwd\" value=\"\" class=\"large\" style=\"width: 15em;\"></td>\n");
    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Left\" width=\"20%\">" + vintagetag + "</td>\n");
    document.write("<td width=\"80%\"><input type=\"text\" name=\"vintage\" size=\"4\" value=\"" + v + "\" class=\"large\"></td>\n");
    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Left\" width=\"20%\">" + place + "</td>\n");
    document.write("<td width=\"80%\"><input type=\"text\" name=\"place\" value=\"\" class=\"large\" style=\"width: 100%;\"></td>\n");
    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Left\" width=\"20%\">" + price + "</td>\n");
    document.write("<td width=\"80%\"><input type=\"text\" name=\"price\" value=\"\" class=\"large\" style=\"width: 5em; text-align: right;\">\n");
    document.write("<select name=\"cur\" size=\"1\" class=\"large\">\n");

    RVS();

    document.write("</select></td>\n");
    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Left\" valign=\"top\" width=\"20%\">" + msg + "</td>\n");
    document.write("<td width=\"80%\"><textarea name=\"review\" class=\"large\" style=\"width: 100%; height: 200px\" onkeyup=\"tl('review','cleft'," + rl + ")\"></textarea></td>\n");
    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Left\" width=\"20%\">&nbsp</td>\n");
    document.write("<td width=\"80%\" align=\"right\">" + cleft + "&nbsp;&nbsp;<input type=\"text\" name=\"cleft\" value=\"" + rl + "\" class=\"large\" style=\"width: 4em; text-align: right;\" readonly></td>\n");
    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Left\" width=\"20%\">" + score + "</td>\n");
    document.write("<td width=\"80%\"><select name=\"score\" size=\"1\" class=\"large\" onchange=\"ShowScore()\">\n");

    DSS(l, -1);

    document.write("</select>&nbsp;&nbsp;&nbsp;");

    for(i=1; i<=6; i++)
        document.write("<img src=\"/images/dsnull.gif\" name=\"ds" + i + "\" border=\"0\" style=\"width: 17; height: 16; vertical-align: middle;\">");

    document.write("</td>\n");

    document.write("</tr>\n<tr>\n");
    document.write("<td align=\"Center\" colspan=\"2\"><br class=\"hskip\">\n");
    document.write("<input type=\"button\" name=\"send\" value=\"" + btn + "\" class=\"large\" onclick=\"RG()\">\n");
    document.write("</td>\n</tr>\n</tbody></table>\n");
    document.write("</form>\n");
}

function tl(n, c, l)
{
    var item;

    item = eval("document.ReviewGuide." + n);
    cleft = eval("document.ReviewGuide." + c);

    if(item.value.length > l)
    {
        cleft.value = 0;

        txt=item.value.substring(0, l);

        item.value=txt;

        if(document.ReviewGuide.language.value=="it")
            m="La recensione non può essere\npiù lunga di " + l + " caratteri";
        else
            m="The review cannot be\nlonger than " + l + " characters";

        alert(m);
    }
    else
    {
        cl = l - item.value.length;

        cleft.value = cl;
    }
}
