var idFriend = 0;

/**
* @descr    submit feedback form
*/
function form_feedback_subm()
{
    var error = '';
    
    if( $("#email").val() == '' ) 
    {
        error = error + "<font color='red'>" + translates['required_email'] + "</font><br />";
    }  
    else
    {   
        if (!validateEmail($("#email").val()))
        {
            error = error + "<font color='red'>" + translates['incorrect_email'] + "</font><br />"; 
        }
    }
    
    if( $("#name").val() == '' )
    {
        error = error + "<font color='red'>" + translates['required_name'] + "</font><br />";
    }
    
    if( $("#text").val() == '' )
    {
        error = error + "<font color='red'>" + translates['required_message'] + "</font><br />";
    }

    if( error == '' )
    {
        $("#form_feedback").submit();
    }
    else
    {
        $("#errors").html(error);
    }
    return false;
}

/**
* @descr    submit form tell-a-friend
*/
function form_tellafriend_subm()
{
    var error = '';
    
    if( $("#emailfrom").val() == '' ) 
    {
        error = error + "<font color='red'>" + translates['required_your_email'] + "</font><br />";
    }
    else
    {   
        if (!validateEmail($("#emailfrom").val()))
        {
            error = error + "<font color='red'>" + translates['incorrect_email'] + "</font><br />"; 
        }
    }
        
    if( $("#namefrom").val() == '' )
    {
        error = error + "<font color='red'>" + translates['required_name'] + "</font><br />";
    }
    noErrorFriend = true;
    $("input[@id^='emailto']").each(
        function(i)
        {
            var ind = this.id.substr(7);
            if(this.value == '')
            {
                $("#err_emailto"+ind).html("<font color='red'>" + translates['required_friend_email'] + "</font><br />");
                noErrorFriend = false;
            }
            else
            {
                if (!validateEmail($(this).val()))
                {
                    $("#err_emailto"+ind).html("<font color='red'>" + translates['incorrect_friend_email'] + "</font><br />"); 
                    noErrorFriend = false;
                }
            }
            
            
        }
    );
    if( (error == '') && (noErrorFriend == true))
    {
        $("#form_tellafriend").submit();
    }
    $("#errors").html(error);

    return false;
}

/**
* @descr    add the area to input new friend email
*/
function addFriend(img_url)
{
    if ($("div[@id^='div_friend']").length >= 10)
    {
        alert(translates['invitations_limit']);
    }
    else
    {
        var i = idFriend+1;
        $('#div_friend'+idFriend).after('<div id="div_friend'+i+'"></div>');
        
        var html = "<table width='90%'>";
        html    += "<tr><td align='left'><input name='emailto[" + i + "]' id='emailto" + i + "' rows='5' class='form_text' /><br /><span id='err_emailto" + i + "' ></span></td>";
        html    += "<td align='right'><a href='javascript:;' onclick='deleteCurFriend(" + i + ")' id='del_friend" + i + "' class='form_butt butt1 red'><img src='"+img_url+"/butt_left_r.gif' alt='' style='position:absolute; left:0; top:0' /><img src='"+img_url+"/butt_right_r.gif' alt='' style='position:absolute; right:-1px; top:0' />" + translates['del'] + "</a></td></tr></table>";
        $('#div_friend'+i).html(html);
        idFriend++;
    }
    return false;
}

/**
* @descr    free the area of friend email
*/
function deleteCurFriend(id)
{
    $('#div_friend'+id).remove();
    return false;
}