function outLinks() {
    var outLink;
    if (document.getElementsByTagName('a')) {
        for (var i = 0; (outLink = document.getElementsByTagName('a')[i]); i++) {
            if (outLink.href.indexOf(location.host) == -1) {
                outLink.setAttribute('target', '_blank');
            }
        }
    }
}

function show_counter() {
    if(location.host=="director.lucian0308.com" || location.host=="localhost"){
        if(document.getElementById('counter')){
            $.get('counter.php', function(data){
                $('#counter').html(data);
            });

		
        }
    }
}


$(document).ready(function() {
    $(".bottom1").append('<a href="http://validator.w3.org/check?uri=http%3A%2F%2Fdirector.lucian0308.com%2F"><img src="img/xhtml.jpg" width="80" height="15" border="0" style="margin:5px;" /></a>');
    $(".bottom1").append('<a href="http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fdirector.lucian0308.com%2F"><img src="img/css.jpg" width="80" height="15" border="0" style="margin:5px;" /></a>');
	
    $("input#cauta")
    .mouseover(function(){
        this.src='img/search-input2o.jpg';
    })
    .mouseout(function(){
        this.src='img/search-input2.jpg';
    })
	
    $(".dir_table").not(".dir_table2")
    .mouseover(function(){
        this.style.backgroundColor='#E7F7FE';
    })
    .mouseout(function(){
        this.style.backgroundColor='';
    })
    ;
	
    $.getJSON('include/categorii.php', function(data) {
        $.each(data, function(entryIndex, entry) {
			
            entryIndex = entryIndex.toLowerCase();
            entryIndex = entryIndex.replace(/ /g,'-');
			
            $("a[href='"+entryIndex+"/']").each( function(){
                nr = parseInt(entry['nr_total']);
                $(this).append("<span>("+nr+")</span>");
            });
			 
        });
    });
	
	
    outLinks();
    show_counter();
	
    $("#counter").ajaxStop(function(){
        setTimeout('show_counter();',30000);
    });
	
    $("#counter").ajaxStart(function(){
        $(this).html('<img src="img/ajax_loader.gif" style="margin-top:8px; margin-bottom:9px;"/>');
    });
	
    if($('#add_form').length){
	
        $('#add_form').submit(function(){
            return(validare_site());
        });
                
        $('input[name="title"]').after('<input type="text" value="70" name="ch_title" maxlength="2" size="3" readonly="readonly">');
        $('textarea[name="descriere"]').after('<input type="text" value="1000" name="ch_descriere" maxlength="4" size="3" readonly="readonly">');
        $('textarea[name="keys"]').after('<input type="text" value="150" name="ch_keys" maxlength="3" size="3" readonly="readonly">');
	
        
        $('input[name="title"], textarea[name="descriere"], textarea[name="keys"]').each(function(){
			
            $(this).mousedown(function(){
                CountLeft(this);
            })
            .keydown(function(){
                CountLeft(this);
            })
            .keyup(function(){
                CountLeft(this);
            });

        })	
    }
    
});


