function isIE() {
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function addToCart(itemName, itemNumber, amount) {
    $("#item_name").val(itemName);
    $("#item_number").val(itemNumber);
    $("#amount").val(amount);
    $("#addToCart").submit();
}

function checkEmail(){
    var filter=/^.+@.+\..{2,3}$/

    if (filter.test($("#email").val()))
        result=true;
    else 
        result=false;
    return result;
}

function windowsMobileNotify() {
    if(checkEmail()) {
        $.ajax({
               type     : "POST",
               url      : "/scripts/windows-mobile-notify.php",
               data     : $(this).serialize(),
               dataType : 'json',
               complete  : function(data){
                    $("#wm_form_error").hide();                
                    $("#wm_form_success").show();
               }
        });        
    } else {
        $("#wm_form_error").show();                
        $("#wm_form_success").hide();        
    }    
    return false;
}

$(document).ready(function() {
    $(".fg-button,input[type='button'],input[type='submit']").hover(
        function(){ 
            $(this).addClass("ui-state-hover"); 
        },
        function(){ 
            $(this).removeClass("ui-state-hover"); 
        }
    );
    if(!isIE()) {
        $("#content").corners();    
    } 
    $(".accordion").accordion({
        collapsible : true,
        active      : false,
        autoHeight  : false
    });
    if( window.active_panel && ( active_panel != undefined ) ) {
        $(".accordion").accordion('activate', $("#" + active_panel) );
    }
    $('.dialog').dialog({ 
        autoOpen : false,
        width    : 700,
        height   : 500,
        modal    : true,
        buttons  : { "Close" : function() { $(this).dialog("close"); } }        
    });  
    $('.ui-accordion-content').each(function() {
        $(this).children('p:first').css('margin-top','0px'); 
    });
    
    $('#windows_mobile').submit(windowsMobileNotify);
    
    $("#wm_form_error,#wm_form_success").hide();
    
    $("a").each(function() {
        if ($(this).attr("href") && $(this).attr("rel") == "external")
            $(this).attr("target", "_blank");
    });
 
});
