function trans(tpl, itemt) {
	window.open('/index.php?section=trans&page=edit&tpl='+tpl+'&item='+itemt,"","scrollbars=yes,resizable=yes,status=no,location=no,toolbar=no,width=800,height=300");
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function createpoststring(){
    var emailvalue=document.getElementById("myform").EmailAddress.value //get value to post from a form field
    var email2value=document.getElementById("myform").EmailAddress2.value //get value to post from a form field
    var messagevalue=document.getElementById("myform").message.value //get value to post from a form field
    var titlevalue=document.getElementById("myform").title.value //get value to post from a form field
    var urlvalue=document.getElementById("myform").url.value //get value to post from a form field
    var poststr = "EmailAddress2=" + encodeURI(email2value) + "&EmailAddress=" + encodeURI(emailvalue) + "&title=" + encodeURI(titlevalue) + "&url=" + encodeURI(urlvalue) + "&message=" + encodeURI(messagevalue)
    return poststr
}

$(document).ready(function() {
//FROM VIEW SITE INDEX

	var tabContainers = $('div.tabs > div');
    tabContainers.hide().filter(this.hash).show();
	$('#popcodes').show();
	$('div.tabs ul.tabNavigation li:first').addClass('currenttab');

    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('div.tabs ul.tabNavigation a').parent().removeClass('currenttab');
        $(this).parent().addClass('currenttab');
        
        return false;
    }).filter(':first').hover();

    if ($("a.commentOnCode").length > 0) {
            $("a.commentOnCode").click(function() {
                    var id = $(this).attr('id');
                    $("#codeComments_"+id).load(siteURL+'index.php?section=code&action=ajax-list-comments&id='+id);
            })
    }


    jQuery.copy=function(t)//copy
    {
            if(typeof t=='undefined')
            {
                    t='';
            }

            if(t.createTextRange){
                    var tr = t.createTextRange();
                    if(tr)
                    tr.execCommand("Copy");
            }
            else
            {
                    d=document;
                    var f='flashcopier';
                    if(!d.getElementById(f))
                    {
                            var dd=d.createElement('div');
                            dd.id=f;
                            d.body.appendChild(dd);
                    }
                    d.getElementById(f).innerHTML='';
                    var i='<embed src="/public/js/copy.swf" FlashVars="clipboard='+encodeURIComponent(t)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
                    d.getElementById(f).innerHTML=i;
            }
    }

    if ($('#siteArea').length > 0) {
            $('#siteArea').change(function(){
                    window.location = $(this).find('option:selected').val();
            });
    }


    if ($("#searchFormField").length > 0) {
            $("#searchFormField").keypress(function() {
                    $("#searchResults").load('/user/search/'+$("#searchFormField").val(), null, function(){
                            $("#searchResultList li").click(function() {
                                    $('#searchFormField').val($(this).text());
                                    $('#resultId').val(this.id);
                                    $("#searchResults").empty();
                            });
                    });
            });

    }


    if($("a.toggle-email-alerts").length > 0) {
            $("a.toggle-email-alerts").click(function() {
                    var id = this.id;
                    $.ajax({
                    url: siteURL+'email-notification/change-alert/'+id,
                    type: 'GET',
                    timeout: 1000,
                    dataType: 'html',
                    error: function() {alert('Failed to Update.');},
                    success: function(text) {$("#"+id).text(text);}
                    })
            });
    }


//Poll Voting
    if($(".submit_vote").length > 0) {
            $(".submit_vote").click(function() {
                    var id = this.id;
                    $.ajax({
                            url: siteURL+'poll/ajax_vote/'+id,
                            type: 'POST',
                            timeout: 1000,
                            dataType: 'html',
                            data: {pollValue: $('input[name=option_'+id+']:checked').val()},
                            error: function() {alert('Could not vote on poll.');},
                            success: function(html) {
                                    $('#poll_results_'+id).fadeOut('slow', function(){
                                    $('#poll_results_'+id).html(html);
                                            $('#poll_results_'+id).fadeIn("slow");}
                                    );
                            }
                    })
            });
    }


//Expand/Collapse Div
    $('.expandLink').html('<img src="'+siteURL+'public/expand.png" alt="" title="Expand"> ');
    $('.expand').hide();
            $('.expandLink').click(function() {
                    $(this).parent().parent().next().slideToggle();
            });



//Vote On A Profile
    if ($("a.profile-vote").length > 0) {
            $("a.profile-vote").click(function() {

                    var id = this.id;
                    var profile = id.split('_');
                    var profileId = profile[1];

                    if(profile[0] == 'up') {
                            var URL = siteURL+'user/vote-up/'+profileId;
                    } else {
                            var URL = siteURL+'user/vote-down/'+profileId;
                    }

                    $.ajax({
                    url: URL,
                    type: 'GET',
                    timeout: 1000,
                    dataType: 'html',
                    error: function() {alert('Vote failed.');},
                    success: function(html) {$('span#voteid_'+profileId).html(html);}
                    });
            });
    }

    if($(".smileyClick").length > 0) {
            $(".smileyClick").click(function() {
                    var text = $("#postTextArea").val()+this.id;
                    $("#postTextArea").val(text);
            });
    }


    //Adam's whacked a cheeky bit of script in here (Naughty!)

    $("ul.tabNavigation li a").click(function(){
            $("ul.tabNavigation li").removeClass("currenttab");
            $(this).parent().addClass("currenttab");
    });
            $("ul.tabNavigation li a").hover(
                    function(){
                            $(this).parent().addClass("hovertab");
                    },
                    function(){
                            $(this).parent().removeClass("hovertab");
                    }
            );
	

});

function bookmarksite(title,url) {

    if (window.sidebar) { // firefox
            window.sidebar.addPanel(title, url, "");
    } else if (window.opera && window.print) { // opera
            var elem = document.createElement('a');
            elem.setAttribute('href',url);
            elem.setAttribute('title',title);
            elem.setAttribute('rel','sidebar');
            elem.click();
    } else if (document.all) {// ie
            window.external.AddFavorite(url, title);
    }
}


function CheckAll() {

    for (var i=0; i < document.posting.elements.length; i++) {
        var e = document.posting.elements[i];

            if ((e.name != 'allbox') && (e.type=='checkbox')) {
                    e.checked = document.posting.allbox.checked;
            }
    }

}

$(function(){
$(".code_listing .store a").mouseover(function(){
        $("span",$(this).parent()).show();
}); 
$(".code_listing .store a").mouseout(function(){
        $("span",$(this).parent()).hide();
});

//christmas giveaway banner
$(".code_listing .store a").mouseout(function(){
        $("span",$(this).parent()).hide();
});

$("#email","#christmas-giveaway").click(function(){
        return false;
});

$("#christmas-giveaway").click(function(){
        window.location = "/big-christmas-giveaway";
});



////////////////////////////////////////////////////////////////////////// More INFO ///////////////////////////////////////////////////////
$.fn.autoHeight = function(prop) {
        var temp = this.height();
        var result = this.height("auto").height();
        this.height(temp)
        return result;
};

//div#codes div.code_display a.more_info
$('div.more_info_container a.more_info').toggle(function(){
        var currentHeight;
        currentHeight = $(this).parent().prev().height();
        var newHeight = $(this).parent().prev().autoHeight();
        if( currentHeight < newHeight ){
                $(this).parent().prev().animate({height:''+newHeight+''});
                $(this).text(lessVar);
                //$(this).find('img').attr('src','public/images/js/red_arrow_up.jpg');
        }
},function(){
        $(this).parent().prev().animate({height: '4.5em'});
        //$(this).html("&darr;");
        $(this).text(moreVar);
        //$(this).find('img').attr('src','public/images/js/red_arrow_down.jpg');
});

//div#codes div.code_display p.description
$('p.shrunk_description').each(function(){
        var currentHeight;
        currentHeight = $(this).height();
        var autoHeight = $(this).autoHeight();
        if( autoHeight <= currentHeight ){
                $(this).height('auto');
                $(this).next().children().hide();
        }else{
                $(this).height('4.5em');
        }
});
////////////////////////////////////////////////////////////////////////// END More INFO ///////////////////////////////////////////////////////
	
	
});

	///////////////////// tabs

$(function () {
    var tabContainers = $('div.tabs > div');

    $('div.tabs ul.tabNavigation a').not('.tab_disabled').click(function () {
            tabContainers.hide().filter(this.hash).show();

            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');

            return false;
    }).filter(':first').click();

});

$(function(){
   $('.autocomplete_off').attr('autocomplete','off');
});

function jumpTo(list) {

	if (list.options[list.selectedIndex].value != "home") {
		location = list.options[list.selectedIndex].value
	}

}

function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}