
// check browser version
var isNC	= (document.layers)?1:0;
var isNC4   = (isNC && parseInt(navigator.appVersion) < 6 ) ? 1 : 0;
var isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)?1:0;
var isIE	= (document.all && !isOPERA)?1:0;
var isDOM	= (document.getElementById && !isIE && !isOPERA)?1:0;
var isWIN	= (navigator.platform == 'Win32')?1:0;
var isMAC	= (navigator.platform == 'MacPPC')?1:0;
if(isNC){ isNC = 0; isDOM = 1; }

// isIE  || isDOM || isOPERA
if( 1 ){ window.onresize = resizes; }

$(document).ready(function ()
{
	resizes();
	$('#main_top').load('dates.php');
	setInterval(function(){ $('#main_top').load('dates.php') }, 30000);
	
	$('[select_files]').focus(function ()		//  = $('input[select_files]').click
	{
		jQuery.facebox('<iframe src="files.php?view=block&block=files&select_files_calback='+$(this).attr('select_files_calback')+'&calback_input='+$(this).attr('id')+'&'+$(this).attr('select_files')+'" style="width: 650px; height: 400px; border: 0px "></iframe>')
		// $('#facebox').css({top: '20px'});
		$('#facebox').draggable();
	});
	
	// file_attachments
	if( $('#file_attachments') )
	{
		$('#file_attachments').prepend('<button><b>+ fájl hozzáadása ...</b></button><br>').prepend('<h3>Csatolt fájlok:</h3>');
		$('#file_attachments').after('<div style="clear: both;">&nbsp;</div>')
		$('#file_attachments button').click(function ()
		{
			jQuery.facebox('<iframe src="files.php?view=block&block=files&select_files_calback=file_attachments" style="width: 650px; height: 400px; border: 0px "></iframe>')
			// $('#facebox').css({top: '20px'});
			$('#facebox').draggable();
			return false;
		});
		if( $('#file_attachments input').val() )
		{
			var file_attachments = $('#file_attachments input').val().split(',');
			for( var i in file_attachments ) if(file_attachments[i]) file_attachments_add_item( file_attachments[i] )
		}
		
		$('#file_attachments ul').sortable({
			update: function (e, ui) { file_attachments( '', 'sort' ) }
		});
	}
	theObjects = document.getElementsByTagName("object"); 
	for (var i = 0; i < theObjects.length; i++)
	{ 
		theObjects[i].outerHTML = theObjects[i].outerHTML; 
	}
	$('.arnyekolt').css({'background-color':'black'})
	$('.arnyekolt').dropShadow({
			left: 2,
			top: 3,
			blur: 4,
			opacity: .4,
			color: "black",
			swap: false 
			});
	
	$('.arnyekolt').each(function ()
	{
		$(this).hover(function ()
		{
			// $("<img/>").attr("src", this.src)
			tip_str = 'asasas'
			tip_str = '<img src=\''+$(this).parent().attr('href')+'\' />'
			 Tip(tip_str, DELAY, 300, LEFT, true, OFFSETY, -250, FADEIN, 200, FADEOUT, 150, BGCOLOR, '#FFFFFF', JUMPVERT, true, WIDTH, 800)
		}
		,function ()
		{
			 UnTip()
		})
		$(this).click(function ()
		{
			 return false;
		});
	});
	// scroll_to_main_top()
});

scroll_to_main_top = function ()
{
	var main_offset = $('#main').offset()
	$(document).scrollTo( main_offset.top, { duration:500, axis:'y' } );
}

function select_files_path( id, mod, path, input )
{
	var v = $('#'+input).val()
	if( v ) v = v+"\n"
	$('#'+input).val( v+path );
}

function select_a_file_path( id, mod, path, input )
{
	 $('#'+input).val(path);
	 jQuery(document).trigger('close.facebox');
}

function file_attachments( id, mod )
{
	switch( mod )
	{
		case 'add' : file_attachments_add_item( id ); break;
		case 'del' : file_attachments_del_item( id ); break;
	}
	var attached_ids = ''
	$('#file_attachments ul li[file_id]').each(function ()
	{
		 attached_ids += $(this).attr('file_id')+','
	});
	attached_ids = attached_ids.substring(0, attached_ids.length-1)
	$('#file_attachments input').val(attached_ids);
}
function file_attachments_add_item( id )
{
	if( !$('#file_attachments ul li[file_id="'+id+'"]').attr('file_id') )
	{
		$('#file_attachments ul').append('<li file_id="'+id+'"><span></span><br><a href="#" onclick="file_attachments(\''+id+'\',\'del\'); return false">töröl</a></li>');
		$('#file_attachments ul li[file_id="'+id+'"] span').load('files.php?view=block&block=file&id='+id);
	}else{
		alert('Korábban hozzáadva.');
	}
}
function file_attachments_del_item( id )
{
	$('#file_attachments ul li[file_id="'+id+'"]').remove();
}

// top menu
function tmenu_over(id)
{
	// var p = Position.positionedOffset($('tmenu_'+id));
	var p = $('#tmenu_'+id).offset();
	// var w = Element.getWidth($('tmenu_'+id));
	var w = $('#tmenu_'+id).width();
	$('#tmenu_child_'+id).css({
		display: 'block',
		position: 'absolute',
		'z-index': '1000',
		'white-space': 'nowrap',
		width: 'auto',
		top: p.top+22+'px',
		left: p.left-10+'px'
	});
	if( $('#tmenu_child_'+id).width() < w )
	{
		$('#tmenu_child_'+id).css({
			width: w+1+'px'
		});
	}
}
function tmenu_out(id)
{
	 $('#tmenu_child_'+id).css({
		display: 'none'
	});
}


function thisMovie(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return document.getElementById(movieName)
		return window[movieName]
	}else{
		return document[movieName]
	}
}

function resizes()
{
	var wh = $(window).height();
	$('#all').css({height:wh});
}

function setValue(id, val)
{
	document.getElementById(id).value = val;
}

function MM_openBrWindow(theURL,winName,features)
{
	window.open(theURL,winName,features);
	return false;
}

function setValIfVal(obj, val, new_val)
{
	if(obj.value == val) obj.value=new_val;
}

function tr_rollover(trobj, colorto, colorfrom)
{
	trobj.style.background = colorto
	trobj.onmouseout = function(){
	this.style.background = colorfrom
	}
}

function swap_display(id)
{
	s = document.getElementById(id).style;
	if(s.display == 'none') s.display = 'block';
	else  s.display = 'none';
}

function set_display(content_id, d)
{
	if( document.getElementById(content_id) ) document.getElementById(content_id).style.display = d;
}

function set_display_if(obj, if_obj, if_val)
{
	var d = ( $(if_obj).val() ==  if_val) ? 'block' : 'none';
	$(obj).css('display', d);
}

// ajax content -------------------------------------

var site_page_get_contents = function(page)
{
	advAJAX.tag_hideInInit = null;
	advAJAX.tag_showLoading = null;
	
	advAJAX.setDefaultParameters({
	    group: "prb_group",
	    onInitialization: function(obj) { obj.tag.style.visibility = ((obj.tag_hideInInit)?"hidden":"visible"); },
	    onLoading: function(obj) { if(obj.tag_showLoading){ obj.tag.innerHTML = '<div style="color: #999999; padding: 0px">Loading...</div>'; obj.tag.style.visibility = "visible"; } },
	    onComplete: function(obj) { if(obj.tag_showLoading){ obj.tag.innerHTML = ''; } },
	    onSuccess: function(obj) { obj.tag.innerHTML = obj.responseText; /* alert(obj.responseText) */ },
	    onError: function(obj) { obj.tag.innerHTML = obj.status; },
	    onFinalization: function(obj) { obj.tag.style.visibility = "visible"; }
	});
	advAJAX.get({
	    url: site_page_url_prefix +''+ page + '&ajax_site_content_box=right',
	    tag: document.getElementById('right'),
	    tag_hideInInit: false,
	    tag_showLoading: false
	});
	advAJAX.get({
	    url: site_page_url_prefix +''+ page + '&ajax_site_content_box=main',
	    tag: document.getElementById('main'),
	    tag_hideInInit: true,
	    tag_showLoading: true
	});
	document.right_flash.gotoFrame(2);
}
// ------------------------------------------------

function symple_form_validate(theForm, elements)
{
	for ( var i in elements )
	{
		if( elements[i] == 'mail_format' )
		{
			var email_addtess = theForm[i].value;
			if ( email_addtess.indexOf('@') == -1 || email_addtess.indexOf('.') == -1 || (email_addtess.length-email_addtess.lastIndexOf('.'))>4 || (email_addtess.length-email_addtess.lastIndexOf('.'))<2 || email_addtess.indexOf('.')==email_addtess.indexOf('@')+1 )
			{
				alert("Invalid e-mail format");
				return (false);
			}
		}
		else if( elements[i] == 'empty' )
		{
			if ( theForm[i].value == '' )
			{
				alert("Empty require data");
				return (false);
			}
		}
	}
	return true;
}

function copy_to_clipboard(obj)
{
	if (obj) window.clipboardData.setData('Text', obj.val());
} 

// head_menu 
function head_menu_over(id)
{
	// var p = Position.positionedOffset($('head_menu_'+id));
	var p = $('#head_menu_'+id).offset();
	// var w = Element.getWidth($('head_menu_'+id));
	var w = $('#head_menu_'+id).width();
	$('#head_menu_child_'+id).css({
		display: 'block',
		position: 'absolute',
		'z-index': '1000',
		'white-space': 'nowrap',
		// width: 'auto',
		top: p.top+25+'px',
		left: p.left-40+'px'
	});
	$('#head_menu_child_'+id+' li').css({
		clear: 'both'
	});
	if( $('#head_menu_child_'+id).width() < w )
	{
		$('#head_menu_child_'+id).css({
			width: w+1+'px'
		});
	}
}
function head_menu_out(id)
{
	 $('#head_menu_child_'+id).css({
		display: 'none'
	});
}

// $(window).height() returns wrong value in Opera 9.5.
var height_ = jQuery.fn.height;
jQuery.fn.height = function()
{
    if ( this[0] == window && jQuery.browser.opera && jQuery.browser.version >= 9.50)
        return window.innerHeight;
    else return height_.apply($(this[0]));
};

/*** uploader ***/

$(document).ready(function()
{	
	var fileMax = 10;
	$('.uploader_input').after('<div id="uploader_files_list" style="padding:5px;"></div>');
	$('.uploader_input').change(function()
	{
		uploader(this, fileMax);
	});
});

function uploader(obj, fm)
{
	if($('.uploader_input').size() > fm) {alert('Max files is '+fm); obj.value='';return true;}
	$(obj).hide();
	$(obj).parent().prepend('<input type="file"  name="file[]" />').find("input").change(function() {uploader(this, fm)});
	if( obj.value != '' )
	{
		$('#uploader_files_list').append('<div>'+obj.value+' <input type="button" class="remove" value="mégsem" /></div>').find("input").click(function()
		{
			$(this).parent().remove();
			$(obj).remove();
			return true;
		});
	}
};




