//var j = jQuery.noConflict();
re = new RegExp(/^http:\/\/([^\/]+\/)/);
var HTTP_ROOT = re.exec(window.location)[0]+"";
var SITE_ROOT = HTTP_ROOT;
var aIdx = -1; 
var tabIdx = -1; 
var xIdx = -1; 


Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

$(function(){

    $("div#paramsearch div.item div.input input").each(function() {
        var id = $("div#paramsearch div.item div.input input").index(this);
        switch(id) {
            case 0:
                if($(this).val() != "Zenekarok, előadók" && $(this).val() != "Bands, artists")
                    $(this).css("color", "#333");
                break;
            case 1:
                if($(this).val() != "Helyszínek" && $(this).val() != "Places")
                    $(this).css("color", "#333");
                break;
            case 2:
                if($(this).val() != "Események" && $(this).val() != "Events")
                    $(this).css("color", "#333");
                break;
        }
    });

    $("div#paramsearch div.item div.input input").click(function() {
        var id = $("div#paramsearch div.item div.input input").index(this);
        switch(id) {
            case 0:
                if($(this).val() == "Zenekarok, előadók")
                    $(this).val("").css("color", "#333");
                break;
            case 1:
                if($(this).val() == "Helyszínek")
                    $(this).val("").css("color", "#333");
                break;
            case 2:
                if($(this).val() == "Események")
                    $(this).val("").css("color", "#333");
                break;
        }
    }).blur(function() {
        var id = $("div#paramsearch div.item div.input input").index(this);
        switch(id) {
            case 0:
                if($(this).val() == "")
                    $(this).val("Zenekarok, előadók").css("color", "#CCC");
                break;
            case 1:
                if($(this).val() == "")
                    $(this).val("Helyszínek").css("color", "#CCC");
                break;
            case 2:
                if($(this).val() == "")
                    $(this).val("Események").css("color", "#CCC");
                break;
        }
    });
    
    $("div#paramsearch div.item div.button").click(function() {
        var id = $("div#paramsearch div.item div.button").index(this);
        switch(id) {
            case 0:
                if($(this).prev().children().val() != "Zenekarok, előadók" && $(this).prev().children().val() != "")
                    unHackBack('kereses/zenekarok/', SITE_ROOT+'kereses/zenekarok/'+urlencode($(this).prev().children().val())+'/');
                break;
            case 1:
                if($(this).prev().children().val() != "Helyszínek" && $(this).prev().children().val() != "")
                    unHackBack('kereses/helyszinek/', SITE_ROOT+'kereses/helyszinek/'+urlencode($(this).prev().children().val())+'/');
                break;
            case 2:
                if($(this).prev().children().val() != "Események" && $(this).prev().children().val() != "")
                    window.location.href = SITE_ROOT+'kereses/esemenyek/'+urlencode($(this).prev().children().val())+'/';
                break;
        }
    })
    
     $("div#globalsearch div.button").click(function() {
            if($(this).prev().children().val() != "")
			unHackBack('kereses/minden/', SITE_ROOT+'kereses/minden/'+urlencode($(this).prev().children().val())+'/');
    })

    /** menu rollovers *
    $(".topmenu_item .middle").each(function() {
        if($(".topmenu_item .middle").index(this) == 2) {
            if($(this).children("a").attr("class") != "active") {
                $(this).hover(function() { $(this).children("a").css("color", "#ff9933") }, function() { $(this).children("a").css("color", "#999999") });
            }
        }  else 
            $(this).hover(function() { $(this).children(".rollover").show().next() }, function() { $(this).children(".rollover").hide() });
    });*/
    
    /** rss icon rollover **/ 
    $(".rss a img").hover(function() {
        $(this).attr("src", SITE_ROOT+"/assets/images/rss_rollover.gif") }, function() { $(this).attr("src", SITE_ROOT+"/assets/images/rss.gif")     
    });
    
    /** sitemap icon rollover **/
    $(".sitemap a img").hover(function() {
        $(this).attr("src", SITE_ROOT+"/assets/images/sitemap_rollover.gif") }, function() { $(this).attr("src", SITE_ROOT+"/assets/images/sitemap.gif")     
    });
    
    /** weekselector rollover **/
    $("ul#weekselectors li").hover(function() { $(this).css("background", "url('/assets/images/week_active.jpg') no-repeat scroll 4px 5px") }, function() { $(this).css("background", "url('/assets/images/week.jpg') no-repeat scroll 5px 5px") });
    
    /** naptar click **/
    
    $(".month a").click(function() {
        if($(this).attr("id") == "nprev")
            $.get(SITE_ROOT+"/mainscreen/getnaptar/"+(parseInt($("input[name=currentmonth]").val())-1)+"/", function(re) { $("#naptar").html(re);naptar(); });
        else
            $.get(SITE_ROOT+"/mainscreen/getnaptar/"+(parseInt($("input[name=currentmonth]").val())+1)+"/", function(re) { $("#naptar").html(re);naptar(); });
    });

    //--
 function removeByElement(array,element)
 {
    for(var i=0; i<array.length;i++ )
     { 
        if(array[i]==element)
            array.splice(i,1); 
      } 
     return array;
  }

    $(".searchfilter ul li").click(function() {
    	var types=new Array('','szovegben','kommentekben','archivumban');
        var idx = $(".searchfilter ul li").index(this);
        var prev=$("input[name=searchtypes]").val().split("|");
        var filter=new Array;
        if(idx > 0) {
            if($(this).attr("class") == "selected") {
               filter=removeByElement(prev,types[idx]);
   
            } else {
               filter=prev;
               filter.push(types[idx]);
            }
            window.location.href = SITE_ROOT+'kereses/minden/'+$("input[name=gsearch]").val()+'/'+filter.join("|")+'/';
        } 
    });
    
    /** mufajok **/
    
    $(".mufajok table tr td a").click(function() {
        if($(this).attr("class") == "selected") {
            $(this).removeClass("selected");
            /*$("input[name=mufajok_value]").val($("input[name=mufajok_value]").val().replace($(this).attr("id") + ",", ""));*/
            ai = $.inArray($(this).attr("id"), mufajf);
            mufajf.remove(ai);
        } else {
            $(this).addClass("selected");
            mufajf.push($(this).attr("id"));
            /*$("input[name=mufajok_value]").val($("input[name=mufajok_value]").val() + $(this).attr("id") + ",");*/
        }
    }/*, function() {
        $(this).removeClass("selected");
        $("input[name=mufajok_value]").val($("input[name=mufajok_value]").val().replace($(this).attr("id") + ",", ""));
    }*/);
    
    
    
    
    
    $(".esemeny_table tr").mouseover(function() {
            $(this).addClass("gray");
            $(this).find("td.listen_active").css("background-image","url(/assets/images/listen_icon_gray.gif)");
            $(this).find("td.name").css("background-image","none");
    }).mouseout(function(){
    	    $(this).removeClass("gray");
    		$(this).find("td.name").css("background-image","url(/assets/images/column_topbg.gif)");
    		$(this).find("td.listen_active").css("background-image","url(/assets/images/listen_icon.gif)");
    });
    
    $(".esemeny_table td.date").mouseover(function() {
            $(this).find("a").addClass("orange");
    }).mouseout(function(){
    	    $(this).find("a").removeClass("orange");
    });
    

    
    //--
    
    $(".cikkemail").hover(function() { $(this).css("background", "url('/assets/images/level_aktiv.gif') no-repeat scroll 0 2px") }, function() { $(this).css("background", "url('/assets/images/level.gif') no-repeat scroll 0 2px") });
    
    $(".cikkprint").hover(function() { $(this).css("background", "url('/assets/images/nyomtato_aktiv.gif') no-repeat") }, function() { $(this).css("background", "url('/assets/images/nyomtato.gif') no-repeat") }); 
    
    /*$("#filtercontrol a").click(function() {
        var idx = $("#filtercontrol a").index(this);
        if(idx==0) {
            $("#zenekarok_content .abc").show();
            $("#zenekarok_content .mufajok").hide();
            //$(this).closest("div").removeClass().addClass("mufajbutton");
            
            $(this).removeClass().addClass("wbutton_active");
            $(this).next().removeClass().addClass("wbutton");
           
        } else {
            $("#zenekarok_content .abc").hide();
            $("#zenekarok_content .mufajok").show();
            $(this).removeClass().addClass("wbutton_active");
            $(this).prev().removeClass().addClass("wbutton");
        }    
    });
    
    $("#filtercontrol a[rel=c]").click(function() {
        var idx = $("#filtercontrol a[rel=c]").index(this);
        if(idx==0) {
            $("#helyek_content .abc").show();
            $("#helyek_content .kerulet").hide();
            $(this).removeClass().addClass("wbutton_active");
            $(this).next().removeClass().addClass("wbutton");
        } else {
            $("#helyek_content .abc").hide();
            $("#helyek_content .kerulet").show();
            $(this).removeClass().addClass("wbutton_active");
            $(this).prev().removeClass().addClass("wbutton");
        }
        
        tabIdx = idx;    
    });*/
    
    /*$("#esemenyek_filtercontrol a").click(function() {
        var idx = $("#esemenyek_filtercontrol a").index(this);
        if(idx==1) {
            $("#esemenyek_content .abc").show();
            $("#esemenyek_content .idopontok").hide();
            $(this).removeClass().addClass("wbutton_active");
            $(this).prev().removeClass().addClass("wbutton");
        }
        
        xIdx = idx;    
    });*/
    
    $(".esemeny_table td.name .bottom").toggle(function() {
        $(this).parent().parent().next().show();
        if($(this).next().children().children().attr("src")==SITE_ROOT+"/assets/images/right_arrow.gif")
        $(this).next().children().children().attr("src", SITE_ROOT+"/assets/images/down_arrow.gif");
        else
        $(this).next().children().children().attr("src", SITE_ROOT+"/assets/images/down_arrow_gray.gif");
    }, function() {
        $(this).parent().parent().next().hide();
        if($(this).next().children().children().attr("src")==SITE_ROOT+"/assets/images/down_arrow.gif")
        $(this).next().children().children().attr("src", SITE_ROOT+"/assets/images/right_arrow.gif");     
        else
        $(this).next().children().children().attr("src", SITE_ROOT+"/assets/images/right_arrow_gray.gif");  
    });
    
    $(".esemeny_table td.name .arrow").toggle(function() {
        $(this).parent().parent().next().show();
        if($(this).children().children().attr("src")==SITE_ROOT+"/assets/images/right_arrow.gif")
        $(this).children().children().attr("src", SITE_ROOT+"/assets/images/down_arrow.gif");
        else 
        $(this).children().children().attr("src", SITE_ROOT+"/assets/images/down_arrow_gray.gif");
    }, function() {
        $(this).parent().parent().next().hide();
        if($(this).children().children().attr("src")==SITE_ROOT+"/assets/images/down_arrow.gif")
        $(this).children().children().attr("src", SITE_ROOT+"/assets/images/right_arrow.gif");     
        else
        $(this).children().children().attr("src", SITE_ROOT+"/assets/images/right_arrow_gray.gif");  
    });
    
    /*var switchconcert_ki = false;
    $(".zenekar a").each(function() {
        if($(this).attr("rel") == "1") {
            switchconcert_ki = true;
        }
    });
    if(!switchconcert_ki) {
        $("#switchconcert").parent().hide();
    }*/
    
    $("#switchconcert").click(function() {
        /*$(this).text("Mind");
        $(".zenekar a").each(function() {
            if($(this).attr("rel") == "0") {
                $(this).hide();    
            } 
        });*/
        if($(this).text()=="Koncertezők" || $(this).text()=="with actual concerts") {
            window.location.href = window.location.href.replace(/mind/i, '');
        } else {
            window.location.href = window.location.href+'mind';
        }
    //}, function() {
        /*$(this).text("Koncertezők");
        $(".zenekar a").each(function() {
            if($(this).attr("rel") == "0") {
                $(this).show();    
            } 
        });*/
    });
    /*
    var switchplaces_ki = false;
    $(".helyszin a").each(function() {
        if($(this).attr("rel") == "1") {
            switchplaces_ki = true;
        }
    });
    if(!switchplaces_ki) {
        $("#switchplaces").parent().hide();
    }
     */
    $("#switchplaces").click(function() {
        if($(this).text()=="Koncertezők" || $(this).text()=="with actual concerts") {
            window.location.href = window.location.href.replace(/mind/i, '');
        } else {
            window.location.href = window.location.href+'mind';
        }
        /*$(this).text("Mind");
        $(".helyszin a").each(function() {
            if($(this).attr("rel") == "0") {
                $(this).hide();    
            } 
        });
    }, function() {
        $(this).text("Koncertezők");
        $(".helyszin a").each(function() {
            if($(this).attr("rel") == "0") {
                $(this).show();    
            } 
        });*/
    });
    
    $("#tcontrol h3").click(function() {
        var idx = $("#tcontrol h3").index(this);
        if(idx == 0) {
            $(".helyek_reszletes").hide();
            $(".zenekar_reszletes").show();
            $(this).next().css("color", "#999");
            $(this).css("color", "#333");
        } else {
            $(".zenekar_reszletes").hide();
            $(".helyek_reszletes").show();
            $(this).prev().css("color", "#999");
            $(this).css("color", "#333");
            setGmap();
        }
    });
    showPlace();
    showBand();
    buttonHover();  
    buttonHoverTop();
    xButtonHover();
    naptar();        
});

function naptar() {
	
	re = new RegExp(/^.*?\/mufajok\/(.*?)\//);
	var mufajokr = re.exec(window.location);
	var mufaj_url='';
	if(mufajokr) mufaj_url='mufajok/'+mufajokr[1]+'/';

    $("div#naptar div.naptar div.wrap table tr td").click(function() {
        if($("input[name=currentday]").val()==$(this).text()) {
        	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        	else window.location.href = SITE_ROOT;
        }
        else {
        if($.trim($(this).text()) != ""){
        window.location.href = SITE_ROOT+'kereses/datum/nap/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'-'+$(this).text()+'/'+mufaj_url;
        }
        }
    });
    $("div#naptar div.naptar div.wrap table tr td[class!=active]").hover(function() {
        $(this).css("background-color", "#FFF");
    }, function() {
        $(this).css("background-color", "transparent");
    });

    $(".nap a").click(function() {
        switch($.trim($(this).text().toUpperCase())) {
            case "H":
            if($("input[name=currentdow]").val()=="1") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else {
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/1/'+mufaj_url;}
                break;
            case "K":
            if($("input[name=currentdow]").val()=="2") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/2/'+mufaj_url;         
                break;
            case "SZ":
            if($("input[name=currentdow]").val()=="3") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/3/'+mufaj_url;
                break;
            case "CS":
            if($("input[name=currentdow]").val()=="4") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/4/'+mufaj_url;
                break;
            case "P":
            if($("input[name=currentdow]").val()=="5") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/5/'+mufaj_url;
                break;
            case "SZO":
            if($("input[name=currentdow]").val()=="6") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/6/'+mufaj_url;
                break;
            case "V":
            if($("input[name=currentdow]").val()=="7") {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/napok/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/7/'+mufaj_url;
                break;
        }
    });
    
    $("ul#weekselectors li").click(function() {
        var idx = $("ul#weekselectors li").index(this);
        $(".naptar .wrap table tr").each(function(i) {
            if(i == idx) {
                /*$(this).children("td").each(function() {
                    if($(this).children("div").css("display") == "none") {
                        $(this).children("div").show();
                    } else { 
                        $(this).children("div").hide();
                    }
                });*/
                if($("input[name=currentweek]").val()==(i+1)) {
            	if(mufajokr) window.location.href = SITE_ROOT+'kereses/'+mufaj_url;
        		else window.location.href = SITE_ROOT;
            }
            	else
                window.location.href = SITE_ROOT+'kereses/datum/het/'+$("input[name=currentyear]").val()+"-"+$("input[name=currentmonth]").val()+'/'+(i+1)+'/'+mufaj_url;
            }        
        }); 
    });
    
    $(".month a").click(function() {
        if($(this).attr("id") == "nprev")
            $.get(SITE_ROOT+"/mainscreen/getnaptar/"+(parseInt($("input[name=currentmonth]").val())-1)+"/"+mufaj_url, function(re) { $("#naptar").html(re);naptar(); });
        else
            $.get(SITE_ROOT+"/mainscreen/getnaptar/"+(parseInt($("input[name=currentmonth]").val())+1)+"/"+mufaj_url, function(re) { $("#naptar").html(re);naptar(); });
    });
}

function showBand() {
    
        buttonHover();
        $(".zrplusztab div").hide();
        /*$(".zrplusztab div:eq(0)").show();
        $(".zrcontent span[rel=c]").eq(0).prev().removeClass().addClass("buttonleft_active");
        $(".zrcontent span[rel=c]").eq(0).next().removeClass().addClass("buttonright_active");
        $(".zrcontent span[rel=c]").eq(0).removeClass().addClass("buttoncenter_active");*/
        
        aIdx = -1;
        $(".zrcontent a[rel=c]").click(function() {
            var idx = $(".zrcontent a[rel=c]").index(this);
            $(".zrplusztab div").hide();
            $(".zrplusztab div").eq(idx).show();
            
            $(this).removeClass().addClass("wbutton_active");
                
            if(aIdx>-1) $(".zrcontent a[rel=c]").eq(aIdx).removeClass().addClass("wbutton");
                
                aIdx = idx;
            
        });
        /*$(".zenekarkepek a").hide().lightBox({
            imageLoading:SITE_ROOT+'/assets/images/lightbox-ico-loading.gif',
            imageBtnPrev:SITE_ROOT+'/assets/images/lightbox-btn-prev.gif',
            imageBtnNext:SITE_ROOT+'/assets/images/lightbox-btn-next.gif',            
            imageBtnClose:SITE_ROOT+'/assets/images/lightbox-btn-close.gif',
            imageBlank:SITE_ROOT+'/assets/images/lightbox-blank.gif'
        });*/
        $(".zenekarkepek a:eq(0)").show();
}

function showPlace() {
    
            buttonHover();
            $(".placeplusztab div").hide();
            /*$(".placeplusztab div:eq(0)").show();
            $(".hcontent span[rel=c]").eq(0).prev().removeClass().addClass("buttonleft_active");
            $(".hcontent span[rel=c]").eq(0).next().removeClass().addClass("buttonright_active");
            $(".hcontent span[rel=c]").eq(0).removeClass().addClass("buttoncenter_active");*/
            
            aIdx = -1;
            $(".hcontent a[rel=c]").click(function() {
                var idx = $(".hcontent a[rel=c]").index(this);
                $(".placeplusztab div").hide();
                $(".placeplusztab div").eq(idx).show();
                
                $(this).removeClass().addClass("wbutton_active");
                
                if(aIdx>-1) $(".hcontent a[rel=c]").eq(aIdx).removeClass().addClass("wbutton");
                
                aIdx = idx;
                
            });
        /*$(".helyekkepek a").hide().lightBox({
            imageLoading:SITE_ROOT+'/assets/images/lightbox-ico-loading.gif',
            imageBtnPrev:SITE_ROOT+'/assets/images/lightbox-btn-prev.gif',
            imageBtnNext:SITE_ROOT+'/assets/images/lightbox-btn-next.gif',            
            imageBtnClose:SITE_ROOT+'/assets/images/lightbox-btn-close.gif',
            imageBlank:SITE_ROOT+'/assets/images/lightbox-blank.gif'
        });*/ 
        $(".helyekkepek a:eq(0)").show();
        //initialize(pid);
}

function buttonHover() {
    
    
}

function xButtonHover() {
    
    $("#esemenyek_filtercontrol span[rel=c]").hover(function() {
        $(this).prev().removeClass().addClass("xbuttonleft_active");
        $(this).removeClass().addClass("xbuttoncenter_active"); 
        $(this).next().removeClass().addClass("xbuttonright_active"); 
    }, function() {
        var idx = $("#esemenyek_filtercontrol span[rel=c]").index(this);
        if(idx != xIdx) {
            $(this).prev().removeClass().addClass("buttonleft");
            $(this).removeClass().addClass("buttoncenter");
            $(this).next().removeClass().addClass("buttonright");
        }
    });
}

function buttonHoverTop() {
    
    
}

function load() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("gmap"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        
        GEvent.addListener(map, "load()", function() {
            $("div[dir=ltr]").hide();
            alert("loaded");
        });
    }
}

function urlencode( str ) {	
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
   for (s in histogram) {
        replace=histogram[s];
        ret = replacer(s, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

/* GMAP CODES */
    
var map = null;
var geocoder = null;

function initialize(pid) {
    if(GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("gmap"));
        map.setCenter(new GLatLng(47.499344, 19.058876), 13);
        geocoder = new GClientGeocoder();
        
        loadMarks(pid);    
    }
}

function createMarker(point) {
    var marker = new GMarker(point);
    return marker;
}

function showAddress(address) {
    if(geocoder) {
        geocoder.getLatLng(
            address,
            function(point) {
                if(!point) {
                    //alert(address + " not found");
                } else {
                    map.setCenter(point, 15);
                    map.addOverlay(createMarker(point));
                    //marker.openInfoWindowHtml(address);
                    GEvent.addListener(map, "click", function() {
                        window.open("http://maps.google.com/maps?f=q&source=s_q&hl=hu&geocode=&q="+urlencode(address));    
                    });
                }
            }
        );
    }
}

function loadMarks(pid) {
    $.getJSON(SITE_ROOT+"/helyszinek/gmarks/"+pid+"/",
        function(data) {
            $.each(data.address, function(i, item) {
                showAddress(item);
            });            
        }
    );
}

function sendEnter(evt, code) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        eval(code);
        return true;
    } else {
        return false;
    }
} 

function mufajFilter(page) {
    if(mufajf.length > 0) {
        var lstr = mufajf.join("|");
        if(page=='zenekarok')
        window.location.href=SITE_ROOT+'zenekarok/mufaj/'+lstr+'/';
        else 
        window.location.href=SITE_ROOT+'helyszinek/stilus/'+lstr+'/';
    } else {
        $("#nomufaj").show();
    }
}


function MM_openBrWindow() { /*blank function*/ }

function hackBackCikk(rovatid, url) {
    $.get(SITE_ROOT+"/cikkek/setvissza/"+rovatid+"/");
    window.location.href = url;
}

function unHackBackCikk(rovatid, url) {
    $.get(SITE_ROOT+"/cikkek/unsetvissza/"+rovatid+"/");
    window.location.href = url;
}

function hackBack(type, url) {
    $.get(SITE_ROOT+"/"+type+"/setvissza/");
    window.location.href = url;
}

function unHackBack(type, url) {
    $.get(SITE_ROOT+"/"+type+"/unsetvissza/");
    window.location.href = url;
}

function keresFilter() {
    $.post(SITE_ROOT+"kereses/setfilter/", { filter:$('input[name=searchtypes]').val() });
    keresSubmit();
}

function keresSubmit() {
    if($('input[name=search]').val() != "") {
        $("#searchform").submit();
    } else {
        $('input[name=search]').focus();
    }
}


