function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


CLOSE_SEC = 0;

function swap_logo_to(_s) 
{
    $('#img_logo').attr('src',_s);
}

function swap_to(_s) 
{
    $('#visor').attr('src',_s);
}

function open_secmenu()
{
    if (!CLOSE_SEC) 
    {
        $("#topmenu_portfolio").css("text-decoration","underline");
        $('#secmenu').slideDown('slow',function() {CLOSE_SEC=1});
    }
}

function close_secmenu()
{
    if (CLOSE_SEC) 
    {
        $("#topmenu_portfolio").css("text-decoration","none");
        $('#secmenu').slideUp('slow', function() {CLOSE_SEC=0;});
    }
}
function submit_contact() {

    if (trim($('#contact_name').val()) == '') 
    {
        $('#form_status').css('background','#f66');
        $('#form_status').html('&nbsp;Woops, you forgot to fill out your name...&nbsp;');
        if ($('#form_status').css('display') == 'none') $('#form_status').fadeIn('normal');
    }
    else if (trim($('#contact_email').val()) == '' && trim($('#contact_email').val()) == '')
    {
        $('#form_status').css('background','#f66');
        $('#form_status').html('&nbsp;An Email or a Contact Number perhaps?&nbsp;');
        if ($('#form_status').css('display') == 'none') $('#form_status').fadeIn('normal');
    }
    else if (trim($('#contact_msg').val()) == '')
    {
        $('#form_status').css('background','#f66');
        $('#form_status').html('&nbsp;I think you left out your message...&nbsp;');
        if ($('#form_status').css('display') == 'none') $('#form_status').fadeIn('normal');
    }
    else
    {
        $('#contact_submit').fadeOut('normal', function() {
            $('#form_status').html('&nbsp;Submitting Form...&nbsp;');
            $('#form_status').fadeIn('normal');
            $.post("handler.php", 
                {
                    name: $('#contact_name').val(),
                    email: $('#contact_email').val(),
                    phone: $('#contact_no').val(),
                    msg: $('#contact_msg').val()
                 }, 
                 function(data)
                 {
                        $('#form_status').css('background','#0f0');
                        $('#form_status').html(data)
                 }
            );
            }
        );
    };
}

$(function() {
        $("#secmenu").mouseover(function() {$("#topmenu_portfolio").css("text-decoration","underline")});
        })
