
// 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; }

var states = {}
states.akt_tab = 1

// isIE  || isDOM || isOPERA
if( 1 ){ window.onresize = resizes; }

$(document).ready(function ()
{
	$('ul.tabs li').each(function ()
	{
		 $(this).click(function ()
		 {
			 states.akt_tab = $(this).attr('tab');
		 	 set_tabs() 
		 });
	});
	$('td.thumbs img').each(function ()
	{
		 $(this).click(function ()
		 {
			 var src = $(this).attr('src');
			 $('td.large_image img').attr('src', src);
		 });
		 $(this).css({'cursor':'pointer'})
	});
	set_tabs()
	resizes()
});

function set_tabs()
{
	$('ul.tabs li').each(function ()
	{
		 var indx = $(this).attr('tab');
		 if( indx == states.akt_tab )
		 {
			$(this).css({'background-color':'#57762f'})
		 }else{
		 	$(this).css({'background-color':'#46a122'})
		 }
		 $(this).css({'cursor':'pointer'})
	});
	$('div[tab]').each(function ()
	{
		var indx = $(this).attr('tab');
		if( indx == states.akt_tab )
		{
			$(this).css({'display':'block'})
		}else{
			$(this).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(obj_id, d)
{
	if( document.getElementById(obj_id) ) document.getElementById(obj_id).style.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;
		});
	}
};

