﻿var fs_tabs_timeout = 100;
var fs_tabs_closetimer = 0;
var fs_tabs_ddmenuitem = 0;

function fs_tabs_open() {
    
    fs_tabs_canceltimer();
    fs_tabs_close();
    
    //var height = $(this).find('ul').css('height');
    //$(this).find('ul').slideDown("slow");
    fs_tabs_ddmenuitem = $(this).find(':hidden').show();  //.find('ul').show(); // css('visibility', 'visible');
}

function fs_tabs_close() {
    if (fs_tabs_ddmenuitem) fs_tabs_ddmenuitem.hide(); //.css('visibility', 'hidden'); 
}

function fs_tabs_timer()
{ fs_tabs_closetimer = window.setTimeout(fs_tabs_close, fs_tabs_timeout); }

function fs_tabs_canceltimer() {
    if (fs_tabs_closetimer) {
        window.clearTimeout(fs_tabs_closetimer);
        fs_tabs_closetimer = null;
    }
}


$(function () {

    $('._lnk_blank').attr('target', '_blank');

    $('.lnk_login').click(function () {
        showLogin();
        return false;
    });


    $('._loading_image').each(function () {
        $(this).attr('src', $(this).attr('rel')).removeAttr('rel');

    })

    $('.watermark').each(function () {

        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        } else {
            $(this).removeClass('watermark');
        }


    }).focus(
    function () {
        if ($(this).hasClass('watermark')) {
            $(this).val('').removeClass('watermark');
        }
        //focus
    }
    ).blur(
    function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title')).addClass('watermark');
        }

    }
    );


    $('.tabs > ul > li').bind('mouseover', fs_tabs_open)
    $('.tabs > ul > li').bind('mouseout', fs_tabs_timer)




}).click(function () { fs_tabs_close(); });

function SetBookmark(Site) { switch (Site) { case "del.icio.us": location.href = "http://del.icio.us/post?v=4;url=" + encodeURIComponent(location.href) + ";title=" + encodeURIComponent(document.title); break; case "linkatopia.com": var wd = window.document, s = wd.createElement("script"); s.id = "ks"; s.type = "text/javascript"; s.src = "http://linkatopia.com/innerpop_js.php"; void (wd.body.appendChild(s)); break; case "simpy.com": if (window.getSelection) { txt = window.getSelection() } else { if (document.getSelection) { txt = document.getSelection() } else { if (document.selection) { txt = document.selection.createRange().text } } } location.href = "http://www.simpy.com/simpy/LinkAdd.do?title=" + encodeURIComponent(document.title) + "&href=" + encodeURIComponent(location.href) + "&note=" + encodeURIComponent(txt) + "&_doneURI=" + encodeURIComponent(location.href) + "&v=7&src=bookmarklet"; break; case "reddit.com": location.href = "http://reddit.com/submit?url=" + encodeURIComponent(location.href) + "&title=" + encodeURIComponent(document.title); break; case "taggly.com": x = document; a = encodeURIComponent(x.location.href); t = encodeURIComponent(x.title); if (navigator.appName.indexOf("Explorer") != -1) { d = encodeURIComponent(document.selection.createRange().text) } else { d = encodeURIComponent(window.getSelection()) } location.href = "http://www.taggly.com/bookmarks/?action=add&address=" + a + "&title=" + t + "&description=" + d; void 0; break; case "diigo.com": (function() { s = document.createElement("script"); s.type = "text/javascript"; s.src = "http://www.diigo.com/javascripts/webtoolbar/diigolet_b_h_b.js"; document.body.appendChild(s) })(); break; case "wink.com": var e = encodeURIComponent, d = document; if (navigator.appName.indexOf("Explorer") != -1) { void (location.href = "http://wink.com/_/tag?url=" + e(location.href) + "&ttl=" + e(d.title)) } else { void (open("http://wink.com/_/tag?url=" + e(location.href) + "&ttl=" + e(d.title) + "&d=" + e(d.selection ? d.selection.createRange().text : d.getSelection()), "wink", "dialog=1,modal=1,width=400,height=300")) } break; case "thisnext.com": (function() { var x = document.getElementsByTagName("head").item(0); var so = document.createElement("script"); var s = "http://www.thisnext.com/js/bookmarklet/" + location.hostname.split(".").reverse().join("/") + "/"; if (typeof so != "object") { so = document.standardCreateElement("script") } so.setAttribute("src", s); so.setAttribute("type", "text/javascript"); x.appendChild(so) })(); break; case "wists.com": (function() { if (document.getElementById) { var x = document.getElementsByTagName("head").item(0); var o = document.createElement("script"); if (typeof o != "object") { o = document.standardCreateElement("script") } o.setAttribute("src", "http://www.wists.com/wistlet.js?x=" + Math.floor(Math.random() * 9999)); o.setAttribute("type", "text/javascript"); x.appendChild(o) } })(); break; case "kaboodle.com": if (navigator.appName.indexOf("Explorer") != -1) { var _mg56v = "0.2"; (function() { var d = document; var s; try { s = d.standardCreateElement("script") } catch (e) { } if (typeof (s) != "object") { s = d.createElement("script") } s.type = "text/javascript"; s.src = "http://www.kaboodle.com/zg/g.js"; s.id = "c_grab_js"; d.getElementsByTagName("head")[0].appendChild(s) })() } else { var _mg56v = "0.3"; (function() { var d = document; var s; try { s = d.standardCreateElement("script") } catch (e) { } if (typeof (s) != "object") { s = d.createElement("script") } try { s.type = "text/javascript"; s.src = "http://www.kaboodle.com/zg/g.js"; s.id = "c_grab_js"; d.getElementsByTagName("head")[0].appendChild(s) } catch (e) { window.location = "http://www.kaboodle.com/za/selectpage?p_pop=false&amp;pa=url&amp;u=" + window.location } })() } break; case "trezr.com": window.location = "http://www.trezr.com/post"; break; case "facebook.com": window.location = "http://www.facebook.com/share.php?u=" + window.location + "&t=Share"; break; case "twitter.com": window.location = "http://twitter.com/home?status=Browsing%20" + window.location + "+@Fotoshoot"; break; case "buzz.yahoo.com": window.location = "http://buzz.yahoo.com/buzz?targetUrl=" + window.location + "&headline=" + document.title + "&src=EF"; break; case "propeller.com": window.location = "http://www.propeller.com/submit/?U=" + window.location + "&T=" + document.title + ""; break; case "stumbleupon.com": window.location = "http://www.stumbleupon.com/submit?url=" + window.location + "&title=" + document.title + ""; break } };


function loadPage(url, container, callback) { container.animate({ opacity: 0.25 }, 500); $.get(url, function(data) { container.html(data).animate({ opacity: 1 }, 250); if (callback) { eval(callback); } }); }

function validateSubmitForm(frm) {
    
    if (!validateForm(frm))
        return false;

    var action = frm.attr('action');
    var data = frm.serialize();

    var retval = false;

    $.ajax({ url: action, type: 'POST', data: data, success: function (txt) { retval = true; }, async: false });

    return retval; 
}

function validateForm(frm) {
    var isValid = true;

    frm.find('._v_required').each(function() {
        if ($(this).val() == '') {
            $(this).addClass('input-validation-error').blur(
                function() { if ($(this).val() != '') { $(this).removeClass('input-validation-error'); } }
                );

            isValid = false;
        } else {
            $(this).removeClass('input-validation-error');
        }
    });

    frm.find('._v_number').each(function() {

        var val = $(this).val().replace(',', '');
        $(this).val(val);

        if (!isNumber(val)){
                $(this).addClass('input-validation-error')
                isValid = false;
            }

        });

        frm.find('._v_money').each(function() {

            var val = $(this).val().replace(',', '').replace('$', '');
            $(this).val(val);

            if (!isDecimal(val)) {
                $(this).addClass('input-validation-error')
                isValid = false;
            }

        });

        

    if (!isValid) {frm.find('.input-validation-error:first').focus();}
    
    return isValid;
}



function isNumber(val) {
    if (val == '')
        return true;
    
    var r = /[\d]+/;
    return r.test(val);
}

function isDecimal(val) {
    if (val == '')
        return true;

    var r = /[0-9]+(\.[0-9]+)?$/;
    if (r.test(val) && parseFloat(val) == val) { return true; } else { return false; }
}


function showLogin(){
    if ($('#dlg_login').length == 0) {

        var html ='<div class="genericpopup-container" id="dlg_login">'; 
        html += '<div class="genericpopup-container-popup" style="top:50px; height:168px; "><h2>Login</h2><form action="/Account/Logon" method="post">';
        html += '<div class="genericpopup-container-content">';
        html += '<div class="clearfix" style="margin-top:10px;"><label style="width:120px; font-size:14px; display:block; float:left; padding-top:4px;">Username / Email : </label><input type="text" name="username" style="font-size:18px;" /></div>';
        html += '<div class="clearfix" style="margin-top:10px;"><label style="width:120px; font-size:14px;display:block; float:left;padding-top:4px;">Password : </label><input type="password" name="password" style="font-size:18px;" /></div></div>';
        html += '<div class="genericpopup-container-action" style="text-align:right;vertical-align:bottom;"><input type="button" value="Cancel"  style="margin-right:25px;" onclick="$(this).parents(\'.genericpopup-container\').fadeOut(\'fast\');"/><input type="submit" value="Login" /></div></form></div></div>';
        /* @'<div id="signin_controls">
        <fieldset id="signin_menu" class="common-form standard-form" style="display: block; ">
  
        <form  action="/Account/Logon" method="post">
  
        <p class="textbox">
        <label for="username">Username or email</label>
        <input type="text" id="username" name="session[username_or_email]" value="" title="username" tabindex="4">
        </p>

        <p class="textbox">
        <label for="password">Password</label>
        <input type="password" id="password" name="session[password]" value="" title="password" tabindex="5">
        </p>

        <p class="remember">
        <input type="submit" class="btn_blue"  value="Sign in" tabindex="7">
        </p>

        <p class="forgot">
        <a href="/Account/ForgotPassword">Forgot password?</a>
        </p>

        <p class="complete">
        <a href="/Account/Register">Register</a>
        </p>
        </form>
        </fieldset>
        </div>'; 
        */

        $('body').append(html);
        $('#dlg_login input[name=username]').focus(); 
    }

    $('#dlg_login').show();
}

