/*
*************************************
  Created by Laszlo Bejczi 2006
  Send me a mail if u could use this code. Anyway its free to reuse.
  fikusz01 at gmail dot com
*************************************
*/

/* window.size crossbrowser sulotion */

window.size = function() {
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth) {
		//strict mode
		if(!(document.documentElement.clientWidth == 0)) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		} else {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

/* window.size crossbrowser sulotion END */

function ajax_div_bezarasa() {
    // ha volt tavoli parancs statuszlekerdezes timer azt toroljuk
    $('#ajax_div_inner').fadeOut('fast',function(){
        var ni = document.getElementById('site_wrapper');
        ni.removeChild(ni.lastChild);
        ni.removeChild(ni.lastChild);
    });
}

function ajax_div_keszitese(szelesseg, magassag) {
    var ni = document.getElementById('site_wrapper');
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id','ajax_div');
    ni.appendChild(newdiv);
    $('#ajax_div').click(function() {
        ajax_div_bezarasa();
    });
    newdiv = document.createElement('div');
    newdiv.setAttribute('id','ajax_div_inner');
    ni.appendChild(newdiv);
    var x = ((window.size().width / 2) - (szelesseg / 2));
    var y = ((window.size().height / 2) - (magassag / 2));
    $('#ajax_div_inner').css({'width':szelesseg+'px', 'height':magassag+'px', 'position':'fixed', 'top':y+'px', 'left':x+'px'});
}

function ajax_div_megjelenitese(http_url,w,h) {
    if ( http_url != '' ) {
        ajax_div_keszitese(w,h);
        $("#ajax_div_inner").load(http_url,'',function(){
            $('#ajax_div_inner').fadeIn({duration:500});
        });
    }
}

function ajax_div_megjelenitese_jScrollPane(http_url,w,h) {
    if ( http_url != '' ) {
        ajax_div_keszitese(w,h);
        $("#ajax_div_inner").load(http_url,'',function(){
            $('#ajax_div_inner').fadeIn('slow', function() {
                $('#pane2').jScrollPane({showArrows:false});
            });
        });
    }
}

function hirlevel_getEmailValue(email_id) {
    var email = document.getElementById(email_id);
    if ( email ) {
        var email_val = email.value;
        if ( email_val != '' ) {
            return email_val;
        } else return '';
    } else return '';
}

function hirlevel_sendFormWithAjax(form_id) {
    $('#ajax_div_inner').fadeOut('fast', function() {
        var data = $("#"+form_id).serialize();
        $.post(__prefix__+"/ajax/hirlevel-feliratkozas", data, function(result) {
            $('#ajax_div_inner').html(result);
            $('#ajax_div_inner').fadeIn('fast');
        });
    });
    return false;
}

function hirlevel_nev_bekerese(email_id) {
    var email_val = hirlevel_getEmailValue(email_id);
    if ( email_val != '' ) {
        ajax_div_megjelenitese(__prefix__+'/ajax/hirlevel-nev-megadasa',580,250);
    } else alert('Nem adott meg e-mail címet!');
}

function showInClearbox(url,title,w,h) {
    CB_Open('href='+url+',,title='+title+',,width='+w+',,height='+h);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function bookmarksite(title, url){
    if (document.all) window.external.AddFavorite(url, title);
    else if (window.sidebar) window.sidebar.addPanel(title, url, "");
}

function go(url) {
    window.location = url;
}

function Confirm(msg, hova) {
    var response = window.confirm(msg);
    if (response) { go(hova); }
}

function ConfirmOnly(msg) {
    return window.confirm(msg);
}

function ajax_tartalom(url,div_id) {
    if ( $(div_id) == null ) {
        alert("HTML ID ('"+div_id+"') for AJAX updater is not found!");
    } else {
        $(div_id).fadeOut('slow',function(){
            $(div_id).load(url,'',function(){$(div_id).fadeIn({duration:500});});
        });
        //$(div_id).html($(div_id).html() + '<div style="padding-top:10px;text-align:center;width:100%"><img src="' + __prefix__ + '/templates/pictures/ajax/ajax-loader.gif" alt="..." /></div>');
    }
    return false;
}

function openWindow(url) {
    var windowwidth = 880;
    var windowheight = 700;
    var left = 100;
    var top  = 100;
    window.open(url,'Nyomtatás','width='+windowwidth+',height='+windowheight+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes,screenX='+left+',screenY='+top);
}

