var footerblocked = 0;

$(document).ready(function(){
    if($("div[id*='gallery_']").length > 0){
        $(function(){
            $("div[id*='gallery_'] a").lightBox();
        });
    }
    
    if($("div[id*='map_']").length > 0){   
        setTimeout("setMap();",500);
    }
    
    emailAt();
    Check_Cookie();
    InitFloat(Events);
    
    if($("#sehit").length > 0){
        setTimeout('$("#sehit").slideDown("slow");', 1000);
    }
    
    if($.cookie("footerblocked") == null){
        if($("div[id='footerad']").length > 0){
            if($("#footeradtype").attr("value") == "timer"){
                fadDelay = $("#footeradtimer").attr("value");
                var fadTimer = setTimeout('$("#footerad").slideToggle("slow",function(){clearTimeout(' + fadTimer + ');});',fadDelay);
            }
            else{
                $(window).scroll(function(){
                    docheight = $(document).height();
                    
                    if(($(window).scrollTop() > docheight/6) && ($("#footerad").css("display") == "none")){
                        if(footerblocked == 0){
                            $("#footerad").slideToggle('slow');
                        }
                    }
                    else if(($(window).scrollTop() < docheight/6) && ($("#footerad").css("display") == "block")){
                        if(footerblocked == 0){
                            $("#footerad").hide();
                        }
                    }
                });
            }
        }
    }
});

function removeFooterAdd(){
    $.cookie("footerblocked","1");
    footerblocked = 1;
    $("#footerad").slideToggle('slow');
}

function askOffer(){
    FormState   = true;
    contactData = '';
    
    chaptcha = $("#offer_chaptcha").attr("value");
    
    if(chaptcha == ""){
        document.getElementById('offer_chaptcha_error').style.display = 'block';
        setTimeout("document.getElementById('offer_chaptcha_error').style.display = 'none'",1500);
    }
    else{
        for(x=0;x<=document.ajanlat.length-2;x++){
            TheValue = document.ajanlat.elements[x].value;
        
            if(TheValue.length == 0 || TheValue.charAt(0) == ' '){
                FormState = false;
            }
            contactData += '&data' + x + '=' + encodeURI(TheValue.split("+").join(plusEscape));
        }
        
        contactData += '&data5' + '=' + encodeURI(document.ajanlat.elements[5].value.split("+").join(plusEscape));
        
        URI = contactData.substr(1);
        
        Cookie = Get_Cookie('prodid');
        ProdidValue = Cookie.substr(1,Cookie.length)
        
        URI = URI + '&data6=' + ProdidValue;
        URI = URI + '&chaptcha=' + chaptcha;
        
        if(!CheckEmail(document.ajanlat.elements[4].value)){
            FormState = false;
        }
        
        if(!FormState){
        	obj = document.getElementById('offer_errordata').style
        	obj.display='block';
        	setTimeout("obj.display='none'",1500);
       	}
       	else{
        	document.getElementById('offer_wait').style.display = 'block';
            
            $.ajax({
                type: 'POST',
                data: "action=askoffer&" + URI,
                url: $("#ajanlat").attr("action"),
                success: function(data){
                    if(data == 'ok'){
                        $("#offer_wait").hide();
                        $("#cartinput").hide();
                        $("#cookie_list").hide();
                        $("#offer_thanx").show();
                    }
                    else if(data == 'chaptcha'){
                        $("#offer_wait").hide();
                        document.getElementById('offer_chaptcha_error').style.display = 'block';
                        setTimeout("document.getElementById('offer_chaptcha_error').style.display = 'none'",1500);
                    }
                    else{
                        alert('Hiba történt az űrlap elküldése közben! Az oldal újratöltődik...');
                        window.location.reload();
                    }
                }
            });
       	}
    }
}

function SendFloat(){
    IsFilled = true;
    FormElements = document.beuszo.elements.length;
    
    chaptcha = $("#chaptcha").attr("value");
    
    if(chaptcha == ""){
        document.getElementById('float_errordata').style.display = 'block';
        setTimeout("document.getElementById('float_errordata').style.display = 'none'",1500);
    }
    else{
        for(x=0;x<=FormElements-1;x++){
            TheName = document.beuszo.elements[x].name;
            TheValue = document.beuszo.elements[x].value;
            TheType = document.beuszo.elements[x].type;
            
            if(TheType == 'text' && !CheckDataField(TheValue)){
                IsFilled = false;
            }
        }
        
        if(IsFilled){
            IsEmails = true;
 			
             for(x=0;x<=FormElements-1;x++){
                TheName = document.beuszo.elements[x].name;
                TheValue = document.beuszo.elements[x].value;
                TheType = document.beuszo.elements[x].type;
                    
                if(TheType == 'text' && TheName/TheName == 1){
                    if(!CheckEmail(TheValue)){
                        IsEmails = false;
                    }
                }
            }
            
            if(IsEmails){
                URI = '';
        			
                for(x=0;x<=FormElements-1;x++){
                    TheType = document.beuszo.elements[x].type;
                    TheName = document.beuszo.elements[x].name;
                    TheValue = document.beuszo.elements[x].value;
                        
                    if(TheType == 'select-one'){
                        Selected = document.beuszo.elements[x].selectedIndex;
                        SelectedValue = document.beuszo.elements[x].item(Selected).text;
                        URI = URI + '&' + TheName + '=' + encodeURI(SelectedValue.split("+").join(plusEscape));
                    }
                        
                    if(TheType == 'checkbox'){
                        if(document.beuszo.elements[x].checked){
                            URI = URI + '&' + TheName + '=' + '1';
                        }
                        else{
                            URI = URI + '&' + TheName + '=' + '0';
                        }
                    }
                        
                    if(TheType == 'text' || TheType == 'hidden'){
                        URI = URI + '&' + TheName + '=' + encodeURI(TheValue.split("+").join(plusEscape));
                    }
                }
                    
                URI = URI.substr(1);
                document.getElementById('float_wait').style.display = 'block';
                    
                $.ajax({
                    type: 'POST',
                    data: "action=sendfloat&" + URI,
                    url: $("#beuszo").attr("action"),
                    success: function(data){
                        if(data == 'ok'){
                            $("#float_wait").hide();
                            $("#floatinput").hide();
                            $("#floatsent").show();    
				            setCookieFloatSent('FloatSent','','1');
                        }
                        else if(data == 'chaptcha'){
                            $("#float_wait").hide();
                            document.getElementById('chaptcha_error').style.display = 'block';
                            setTimeout("document.getElementById('chaptcha_error').style.display = 'none'",1500);
                        }
                        else{
                            alert('Hiba történt az űrlap elküldése közben! Az oldal újratöltődik...');
                            window.location.reload();
                        }
                    }
                });
           }
           else{
                document.getElementById('float_errordata').style.display = 'block';
                setTimeout("document.getElementById('float_errordata').style.display = 'none'",1500);
           }
        }
        else{
            document.getElementById('float_errordata').style.display = 'block';
            setTimeout("document.getElementById('float_errordata').style.display = 'none'",1500);
        }
    }
}

function offerPrint(){
    FormState = true;
    contactData = '';
    for(x=0;x<=document.ajanlat.length-2;x++){
        TheValue = document.ajanlat.elements[x].value;
        
        if(TheValue.length == 0 || TheValue.charAt(0) == ' '){
            FormState = false;
        }
            
        contactData += encodeURIComponent(TheValue) + '},{';
    }
    
    contactData = '{' + contactData + document.ajanlat.elements[5].value + '}';
    
    if(!CheckEmail(document.ajanlat.elements[4].value)){
        FormState = false;
    }
    
    if(!FormState){
		obj = document.getElementById('print_errordata').style
		obj.display='block';
		setTimeout("obj.display='none'",1500);
	}
	else{
		Cookie = Get_Cookie('prodid');
		URI = $("#ajanlat").attr("action") + 'index.php?print=' + encodeURI(Cookie) + '&contactdata=' + encodeURI(contactData);
		newwindow=window.open(URI,'','scrollbars=1,menubar=1,height=500,width=800,top=150,left=150,resizable=yes');
	}
}

function createMarker(point,mtext){
    var marker = new GMarker(point);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(mtext);
    });
    
    return marker;
}
function sendSeHelp(){
    var semail    = $("#seemail").attr("value");
    var sekeyword = encodeURIComponent($("#sekeyword").attr("value"));
    
    if(semail != "" && sekeyword != ""){
        $("#sendse").attr("disabled",true);
        
        $.ajax({
            type: 'POST',
            data: "action=sehelp&mail=" + semail + "&sekeyword=" + sekeyword ,
            url: $("#seaction").attr("value"),
            success: function(data){
                if(data == "ok"){
                    alert("Hamarosan küldjük a választ!");
                    $.cookie("sehitword",null);
                    $("#sehit").slideUp("slow");
                }
                else{
                    alert(data);
                    $("#sendse").attr("disabled",false);
                }
            }
        });
    }
    else{
        if(semail == ""){
            $("#seemail").css("border","1px solid #ff0000");
            setTimeout('$("#seemail").css("border","1px solid #cfcfcf");',250);
        }
        if(sekeyword == ""){
            $("#sekeyword").css("border","1px solid #ff0000");
            setTimeout('$("#sekeyword").css("border","1px solid #cfcfcf");',250);
        }
    }
}
function sendFooter(){
    url = $("#footeradform").attr("action");
    
    data0 = encodeURI($("#fromdomain").attr("value")).replace(/\+/g,'%2B');
    data1 = encodeURI($("#footerad1").attr("value")).replace(/\+/g,'%2B');
    data2 = encodeURI($("#footerad2").attr("value")).replace(/\+/g,'%2B');
    data3 = encodeURI($("#targetmail").attr("value")).replace(/\+/g,'%2B');
    
    $.ajax({
        type: 'POST',
        url : url,
        data: {"data0":data0,"data1":data1,"data2":data2,"data3":data3},
        success: function(data){
            if(data == "ok"){
                $("#footerad").hide();
            }
        }
    });
    
    return false;
}
function closeHelp(){
    $.cookie("sehitword",null);
    $("#sehit").slideUp("slow");
}
