﻿function ValidateCountries(sender, args)
{   
    args.IsValid = $(".countries").val() > 0;
}

$(document).ready(function() {

    $('.ta').keyup(function() {
        var len = this.value.length;
        if (len >= 1200) {
            this.value = this.value.substring(0, 1200);
        }
        $('#charLeft').text(1200 - len);
    });

    $('input.love').hover(

        function() {
            
            $(this).attr('src', '/images/loveA.gif');
        },

        function() {

            $(this).attr('src', '/images/love.gif');
        }
    )

    $('input.hate').hover(

        function() {

            $(this).attr('src', '/images/hateA.gif');
        },

        function() {

            $(this).attr('src', '/images/hate.gif');
        }
    )

    $('li.control').hover(

        function() {

            $(this).addClass('hover');
        },

        function() {

            $(this).removeClass('hover');
        }
    )

    $('li.controlhome').hover(

        function() {

            $(this).addClass('homehover');
        },

        function() {

            $(this).removeClass('homehover');
        }
    )

    $('li.controlhome').click(function() {

        window.location = "/";

    });

    $('div.news').slice(0, 1).addClass("first");


    $('div.article1 div.articlewide').slice(0, 1).addClass("first");
    $('div.article2 div.articlewide').slice(0, 1).addClass("first");
    $('div.article3 div.articlewide').slice(0, 1).addClass("first");
    $('div.article4 div.articlewide').slice(0, 1).addClass("first");

    $('div.articlewide').slice(0, 1).addClass("first");

    /*
    try {
    $('.rotator').innerfade({ speed: 'slow', timeout: 1000, type: 'sequence', containerheight: '185px' });
    }
    catch (err) { }*/

    try {
        if (edit && auth) {
            $('.edititem').show();
            $('div.column').addClass('editgrey');
            $('div.full').addClass('fullbottom');
        }
        else {
            $('.edititem').hide();
            $('div.column').removeClass("editgrey");
            $('div.full').removeClass('fullbottom');
        }
    }
    catch (error) {

    }

    $('img#logoButton').click(function() {

        try {

            var tsTimeStamp = new Date().getTime();

            if (edit && auth) {
                $('.edititem').hide();
                $('div.column').removeClass("editgrey");
                $('div.full').removeClass('fullbottom');
                $.get('/action/edit.ashx', { edit: false, time: tsTimeStamp }, function(data) { ; });
            }
            else {
                $('.edititem').show();
                $('div.column').addClass("editgrey");
                $('div.full').addClass('fullbottom');
                $.get('/action/edit.ashx', { edit: true, time: tsTimeStamp }, function(data) { ; });
            }

            edit = !edit;
        }
        catch (error) {

        }
    });

    $('span.readmore').click(function() {

        $('p.summary').show();
        $('div.shownews').hide();
        $("p." + ($(this).attr("id"))).hide();
        $("div." + ($(this).attr("id"))).show();

    });

    $('#getnewcode').click(function() {

        $('img#captchaimage').attr('src', '/captcha/image.ashx?cache=' + (new Date().getTime()));
    });

    $('#forgot').click(function() {

        $('table.sendpassword').show();
    });

    $('span.toggle').click(function() {

        $("tr.toggleclose").attr("style", "display:none;");
        $("tr.toggle" + ($(this).attr("id"))).attr("style", "");
    });

    $('span.mailtoggle').click(function() {

        $("tr.toggleclose").attr("style", "display:none;");
        $("tr.toggle" + ($(this).attr("id"))).attr("style", "");
        $.get('/action/misc/mailread.ashx', { mid: $(this).attr('id'), time: new Date().getTime() }, function(data) { ; });
    });

    $('a.viewcomments').click(function() {

        $('div.comments').show();
    });

    $('.preview').mouseover(function() {

        $('.preview').addClass('previewlow');
        $(this).removeClass('previewlow');

        if ($(this).attr('ref')) {
            $('p#preview_description').html($(this).attr('ref'));
        }
        else {
            $('p#preview_description').html('');
        }
    });

}); 

function ValidateCountries(sender, args)
{
    args.IsValid = $(".countries").val() > 0;
}

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function nav_open() {
    
    nav_canceltimer();
    nav_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function nav_close() {
    if (ddmenuitem) ddmenuitem.css('visibility', 'hidden');
    
 }

function nav_timer()
{ closetimer = window.setTimeout(nav_close, timeout); }

function nav_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    } 
}

$(document).ready(function() {
    $('.nav > li').bind('mouseover', nav_open)
    $('.nav > li').bind('mouseout', nav_timer)
});

document.onclick = nav_close;



