var idFriend = 0;

function form_feedback_subm()
{
    var error = '';
    
    if( $("#id_FirstName").val() == '' )
    {
        error = error + "<font color='red'>" + translates['name_required'] + "</font><br />";
    }
    
    if( $("#id_Email").val() == '' ) 
    {
        error = error + "<font color='red'>" + translates['email_required'] + "</font><br />";
    }
    else
    {   
        if (!validateEmail($("#id_Email").val()))
        {
            error = error + "<font color='red'>" + translates['incorrect_email'] + "</font><br />"; 
        }
    }
    
    if( $("#id_Company").val() == '' )
    {
        error = error + "<font color='red'>" + translates['company_required'] + "</font><br />";
    }

    if( $("#id_Phone").val() == '' )
    {
        error = error + "<font color='red'>" + translates['phone_required'] + "</font><br />";
    }

    if( $("#id_Comments").val() == '' )
    {
        error = error + "<font color='red'>" + translates['comments_required'] + "</font><br />";
    }

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

function form_loginExt_subm()
{
    var error = '';
    
    if( $("#login").val() == '' )
    {
        error = error + "<font color='red'>" + translates['login_required'] + "</font><br />";
    }
    
    if( $("#password").val() == '' ) 
    {
        error = error + "<font color='red'>" + translates['password_required'] + "</font><br />";
    }

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

function form_tellafriend_subm()
{
    var error = '';
    //alert(error);
    
    if( $("#emailfrom").val() == '' ) 
    {
        error = error + "<font color='red'>Your Email Address can't be empty</font><br />";
    }
    else
    {   
        if (!validateEmail($("#emailfrom").val()))
        {
            error = error + "<font color='red'>Incorrect e-mail</font><br />"; 
        }
    }
        
    if( $("#namefrom").val() == '' )
    {
        error = error + "<font color='red'>Name can't be empty</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'>Friend Email can't be empty</font><br />");
                noErrorFriend = false;
            }
            else
            {
                if (!validateEmail($(this).val()))
                {
                    $("#err_emailto"+ind).html("<font color='red'>Incorrect friend e-mail</font><br />"); 
                    noErrorFriend = false;
                }
            }
            
            
        }
    );
    //alert("==" + error + "==" + noErrorFriend);
    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)
{
    //alert(text_rest+"--");
    if ($("div[@id^='div_friend']").length >= 10)
    {
        alert('You are not permitted to send invitation to more than 10 friends');
    }
    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' />DELETE</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;
}

function mn(obj,len) {
    if (obj.value.length >= len) {
        for (var i = 0; i < document.fcm.elements.length; i++) {
            if(obj == document.fcm.elements[i] && document.fcm.elements[i+1].type != "hidden") {
                document.fcm.elements[i+1].focus();
                break;
            }
        }
    }
}

function sc() {
    var udsub = false;
    var sel = document.getElementById('sub_list')
    var sub = document.getElementById('id_Subject')
    if (udsub) {
        if (sel && sub) {
            if (sel.selectedIndex == 0) {
                if (sub.value.length < 2) {
                    sub.value = '';
                }
                sub.style.display = 'block';
                sub.focus();
            } else {
                sub.style.display = 'none';
            }
        }
    } else {
        sub.style.display = 'none';
    }
}