var sDir = 5;
var tId;
var runDelay = 20;
var scrollVar;
var stillScroll;

function showMe(text, ev) {
var theDiv = document.getElementById('showMeDiv');
theDiv.scrollTop = 0;
theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
theDiv.innerHTML = text;
theDiv.style.visibility = 'visible';
theDiv.style.width = "250px";
var wid, hei, dWid, dHei;
if (window.innerWidth) {
wid = window.innerWidth;
hei = window.innerHeight;
}
else {
wid = document.body.clientWidth;
hei = document.body.clientHeight;
}
wid -= 15;
dWid = theDiv.clientWidth;
dHei = theDiv.clientHeight;
if (ev.clientX + dWid > wid)
theDiv.style.left = (parseInt(theDiv.style.left+document.documentElement.scrollTop) - dWid - 30) + "px";
if (ev.clientY + dHei > hei)
theDiv.style.top = (parseInt(theDiv.style.top+document.documentElement.scrollTop) - dHei) + "px";
}

function hideMe() {
var theDiv = document.getElementById('showMeDiv');
theDiv.style.visibility = 'hidden';
stillScroll = false;
if (tId)
clearTimeout(tId);
}

function moveMe(ev) {
var theDiv = document.getElementById('showMeDiv');
theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
var wid, hei, dWid, dHei;
if (window.innerWidth) {
wid = window.innerWidth;
hei = window.innerHeight;
}
else {
wid = document.body.clientWidth;
hei = document.body.clientHeight;
}
wid -= 15;
dWid = theDiv.clientWidth;
dHei = theDiv.clientHeight;
if (ev.clientX + dWid > wid)
theDiv.style.left = (parseInt(theDiv.style.left) - dWid - 30) + "px";
if (ev.clientY + dHei > hei)
theDiv.style.top = (parseInt(theDiv.style.top) - dHei) + "px";
}

function sizeMe(x) {
var theDiv = document.getElementById('showMeDiv');
if (x != '')
theDiv.style.width = x + 'px';
else
theDiv.style.width = '';
theDiv.style.height = '';
}

function scrollMe() {
scrollVar = 0;
stillScroll = true;
sDir = 5;
nextScrollStep();
var theDiv = document.getElementById('showMeDiv');
}

function nextScrollStep() {
var theDiv = document.getElementById('showMeDiv');
runDelay = 20;
theDiv.scrollTop = scrollVar;
scrollVar += sDir;
if (scrollVar <= 0) {
scrollVar = 0;
sDir = -sDir;
runDelay = 1500;
}
if (scrollVar >= theDiv.scrollHeight - parseInt(theDiv.style.height) +25 ) {
scrollVar = theDiv.scrollHeight - parseInt(theDiv.style.height) + 25;
sDir = -sDir;
runDelay = 1500;
}
if (stillScroll)
tId = setTimeout('nextScrollStep()', runDelay);
}

function getInfo(text_value){
new Ajax.Updater('showMeDiv','jax/return_img_text.php',{method:'post',postBody:'text_value='+text_value});
}

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

function make_focus(obj){
obj.focus();
}



/*standort*/

function standort(use_Gmap)
{
var arrayPageSize = getPageSize();
$('overlay_div').style.width = arrayPageSize[0]+'px';
$('overlay_div').style.height = arrayPageSize[1]+'px';
$('overlay_div').style.top = '0px';
$('overlay_div').style.left= '0px';
/*document.write('<script type="text/javascript" src="js/prototype.js"></script>');*/
/*$('showMeDiv').innerHTML='<script type="text/javascript" src="js/scripta/effects.js"></script>';*/
hideSelectBoxes();
hideFlash();
Element.show('overlay_div');
new Ajax.Updater('standort_div', 'jax/load_map.jax.php', {evalScripts:true, method:'post', postBody:'sid=&use_Gmap='+use_Gmap});
}

function closeStandort(use_Gmap,zoom_out_map)
{
if (use_Gmap==0)
{
Element.hide('map_img');
$('map_img').src=zoom_out_map;
}
Element.hide('standort_div');
Element.hide('overlay_div');
showSelectBoxes();
showFlash();
}

function change_map_display(use_Gmap)
{
if (use_Gmap=='0') standort(1);
else standort(0);
}

function map_zoom_in(has_Gmap,zoom_in_map)
{
if (has_Gmap==0) {Element.hide('map_img');$('map_img').src=zoom_in_map;}
else map.zoomIn();
}

function map_zoom_out(has_Gmap,zoom_out_map)
{
if (has_Gmap==0) {Element.hide('map_img');$('map_img').src=zoom_out_map;}
else map.zoomOut();
}

function map_close(has_Gmap,zoom_out_map)
{
Element.hide('map_img');
if (has_Gmap==0) $('map_img').src=zoom_out_map;
}

function map_print()
{
var url_address='map_print.php';
popup = window.open( url_address, 'printpage', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=no,width=' + '708' + ', height=' + '900'  );
popup.focus();
}


/*--------------------------------------------------------------------------*/
/* overlay div */
function ___getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) {	// all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
return arrayPageSize;
};
/**
/ THIRD FUNCTION
* getPageScroll() by quirksmode.com
*
* @return Array Return an array with x,y page scroll values.
*/
function ___getPageScroll() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}
arrayPageScroll = new Array(xScroll,yScroll);
return arrayPageScroll;
};

function showSelectBoxes(){
var selects = document.getElementsByTagName("select");
for (i = 0; i != selects.length; i++) {
selects[i].style.visibility = "visible";
}
}
// ---------------------------------------------------

function hideSelectBoxes(){
var selects = document.getElementsByTagName("select");
for (i = 0; i != selects.length; i++) {
selects[i].style.visibility = "hidden";
}
}
// ---------------------------------------------------

function showFlash(){
var flashObjects = document.getElementsByTagName("object");
for (i = 0; i < flashObjects.length; i++) {
flashObjects[i].style.visibility = "visible";
}
var flashEmbeds = document.getElementsByTagName("embed");
for (i = 0; i < flashEmbeds.length; i++) {
flashEmbeds[i].style.visibility = "visible";
}
}
// ---------------------------------------------------

function hideFlash(){
var flashObjects = document.getElementsByTagName("object");
for (i = 0; i < flashObjects.length; i++) {
flashObjects[i].style.visibility = "hidden";
}
var flashEmbeds = document.getElementsByTagName("embed");
for (i = 0; i < flashEmbeds.length; i++) {
flashEmbeds[i].style.visibility = "hidden";
}
}

function isValidEmail(email, required) {
if (required==undefined) {   // if not specified, assume it's required
required=true;
}
if (email==null) {
if (required) {
return false;
}
return true;
}
if (email.length==0) {
if (required) {
return false;
}
return true;
}
if (! allValidChars(email)) {  // check to make sure all characters are valid
return false;
}
if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
return false;
} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
return false;
} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
return false;
} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
return false;
} else if (email.indexOf(".")+1 == email.length) {  // . must not be the last character
return false;
}
return true;
}

function allValidChars(email) {
var parsed = true;
var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
for (var i=0; i < email.length; i++) {
var letter = email.charAt(i).toLowerCase();
if (validchars.indexOf(letter) != -1)
continue;
parsed = false;
break;
}
return parsed;
}

function allValidUsernameChars(username){
var parsed = true;
var validchars = "abcdefghijklmnopqrstuvwxyz0123456789_";
for (var i=0; i < username.length; i++) {
var letter = username.charAt(i).toLowerCase();
if (validchars.indexOf(letter) != -1)
continue;
parsed = false;
break;
}
return parsed;
}



function toggle_news_box(){if ($("#news_box").css("display")=='none') $("#news_box").slideDown(500,function(){$('#news_arrow').attr('src','images/blue_arrow_up.gif')}); else $("#news_box").slideUp(500,function(){$('#news_arrow').attr('src','images/blue_arrow_down.gif')});}
function toggle_press_box(){if ($("#press_box").css("display")=='none') $("#press_box").slideDown(500,function(){$('#press_arrow').attr('src','images/blue_arrow_up.gif')}); else $("#press_box").slideUp(500,function(){$('#press_arrow').attr('src','images/blue_arrow_down.gif')});}
function toggle_login_box(){if ($("#login_box").css("display")=='none') $("#login_box").slideDown(500,function(){$('#login_arrow').attr('src','images/blue_arrow_up.gif')}); else $("#login_box").slideUp(500,function(){$('#login_arrow').attr('src','images/blue_arrow_down.gif')});}





var fixable_png_array = new Array();

function add_png_to_fix(div_id,class_nameFF)
{
fixable_png_array.push({'div_id':div_id,'class_name':class_nameFF});
}

function add_png_to_fix2(className)
{
if (!(/MSIE/.test(navigator.userAgent))) $('.'+className).attr('className',className+'_FF');
}

function png_fix()
{
if (!(/MSIE/.test(navigator.userAgent))){
for (i=0;i<fixable_png_array.length;i++) if ($('#'+fixable_png_array[i].div_id)) $('#'+fixable_png_array[i].div_id).attr('class',fixable_png_array[i].class_name);
}
}

function set_title_box_content(main_title,sub_title){$('#title_box_main_title').attr('innerHTML',main_title);$('#title_box_subtitle').attr('innerHTML',sub_title);}

/* font resizer */
var selected_font_size='small';
function change_font_size(index)
{
$('#'+selected_font_size+'_font').attr('src',($('#'+selected_font_size+'_font').attr('src')).replace("icon.","icon_inactive."));
var num;
if (index==1) {content_size=11;menu_size=12;footer_size=11;selected_font_size='small';}
if (index==2) {content_size=15;menu_size=13;footer_size=13;selected_font_size='middle';}
if (index==3) {content_size=20;menu_size=15;footer_size=15;selected_font_size='big';}

$('#'+selected_font_size+'_font').attr('src',($('#'+selected_font_size+'_font').attr('src')).replace("icon_inactive.","icon."));

var $mainText = $('div.middle_content');
$mainText.css('font-size', content_size + 'px');
var $mainText = $('td.menu_bg_over');
$mainText.css('font-size', menu_size + 'px');
var $mainText = $('td.menu_bg');
$mainText.css('font-size', menu_size + 'px');
var $mainText = $('a.big_menu_link');
$mainText.css('font-size', menu_size + 'px');
var $mainText = $('a.right_menu');
$mainText.css('font-size', footer_size + 'px');
var $mainText = $('div.footer_navi');
$mainText.css('font-size', footer_size + 'px');
var $mainText = $('div.footer');
$mainText.css('font-size', footer_size + 'px');
var $mainText = $('#title_box_main_title');
$mainText.css('font-size', menu_size-4 + 'px');
var $mainText = $('#title_box_subtitle');
$mainText.css('font-size', menu_size+2 + 'px');
var $mainText = $('a.right_menu');
$mainText.css('font-size', menu_size + 'px');
var $mainText = $('td.white_box');
$mainText.css('font-size', content_size + 'px');
var $mainText = $('.hot_ref_title > a');
$mainText.css('font-size', content_size + 'px');
var $mainText = $('.hot_ref_title');
$mainText.css('font-size', content_size + 'px');
var $mainText = $('.default_title > a');
$mainText.css('font-size', content_size + 'px');
var $mainText = $('.default_title');
$mainText.css('font-size', content_size + 'px');
}


function verifyPassPresse(doc_id,pass,file,zip){
$('#press_debug').load('jax/load_presse_pass.jax.php', { 'doc_id':doc_id, 'file':file, 'zip':zip, 'pass':pass});
}

function load_map(map_type)
{
var arrayPageSize = ___getPageSize();

$('#overlay_div').css({
width:	arrayPageSize[0],
height:	arrayPageSize[1]
});
// Get page scroll
var arrPageScroll = ___getPageScroll();
// Calculate top and left offset for the jquery-lightbox div object and show it
$('#map_jax_target').css({
top:	arrPageScroll[1] + (arrayPageSize[3] / 10)
});

hideSelectBoxes();
hideFlash();
$('#overlay_div').show();
$('#map_jax_target').load('jax/load_map.jax.php', {'map_type':map_type});
$('#map_jax_target').show();
}

function hide_map()
{
$('#map_jax_target').hide();
$('#overlay_div').hide();
showSelectBoxes();
showFlash();
}

function printPage(print_page){
popup = window.open( print_page, 'print', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=' + '708' + ', height=' + '900'  );
}

function change_lang(lang)
{
$('#press_debug').load('jax/change_lang.jax.php', { 'lang':lang });
}

var selected_tooltip_height=0;
var tooltip_status=0;
function toggle_tooltip()
{
if (tooltip_status==0)
{
if (selected_tooltip_height==0) selected_tooltip_height = $('#tooltip_container').height();
$('#tooltip_container').css({top: 280-selected_tooltip_height });
$('#tooltip_table').css({display:'none', visibility:'visible'});
$('#tooltip_table').show('slide', {direction:'down'}, 300,function(){tooltip_status=1;$('#tooltip_arrow').show('slide', {direction:'up'},200);});
}
else
{
$('#tooltip_arrow').hide('slide', {direction:'up'},300,function(){tooltip_status=0;$('#tooltip_table').hide('slide', {direction:'down'},300);});
}
}

function toggle_upload_box()
{
if ($("#upload_box").css("display")=='none')
{
$('#upload_box').load('jax/perl_upload.jax.php',{'upload_cat_id':s_upload_cat_id, 'member_id':s_member_id, 'owner_username':s_owner_username}, function(){$("#upload_box").slideDown(500,function(){$('#upload_arrow').attr('src','images/blue_arrow_up.gif')}); });
}
else $("#upload_box").slideUp(500,function(){$('#upload_arrow').attr('src','images/blue_arrow_down.gif')});
}

function toggle_event_description(id){if ($("#event_description_"+id).css("display")=='none') $("#event_description_"+id).slideDown(500,function(){$('#little_arrow_'+id).attr('src','images/little_arrow_up.gif')}); else $("#event_description_"+id).slideUp(500,function(){$('#little_arrow_'+id).attr('src','images/little_arrow_down.gif')});}

function toggle_event_op_box(op_nr)
{
if ($('#event_op_'+op_nr).css('display')!='none') {$('#event_op_box').slideUp('slow',function(){$('.event_op').hide();});return}
if ($('#event_op_box').css('display')!='none') $('#event_op_box').slideUp('slow',function(){$('.event_op').hide();$('#event_op_'+op_nr).show();$('#event_op_box').slideDown('slow')} );
else {$('.event_op').hide();$('#event_op_'+op_nr).show();$('#event_op_box').slideDown('slow');}
}
function setCookie(name, value, expiredays, path, domain, secure) {

if (expiredays) {

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

var expires = exdate.toGMTString();

}

document.cookie = name + "=" + escape(value) +

((expiredays) ? "; expires=" + expires : "") +

((path) ? "; path=" + path : "") +

((domain) ? "; domain=" + domain : "") +

((secure) ? "; secure" : "");

}

function getCookie(name) {

var cookie = " " + document.cookie;

var search = " " + name + "=";

var setStr = null;

var offset = 0;

var end = 0;

if (cookie.length > 0) {

offset = cookie.indexOf(search);

if (offset != -1) {

offset += search.length;

end = cookie.indexOf(";", offset)

if (end == -1) {

end = cookie.length;

}

setStr = unescape(cookie.substring(offset, end));

}

}

return setStr;

}

function load_members_subcat(cat_id,actual_cat,reload)
{
$('#subcat_container').load('jax/load_member_subcat_list.jax.php', { 'cat_id':cat_id, 'actual_cat':actual_cat, 'reload':reload });
}

function del_file(file_id)
{
$.ajax({
type: "POST",
url: "jax/del_file.jax.php",
data: {'id':file_id},
success: function(msg){
window.location.href=window.location.href;
}
});
}

function reloadPage()
{
window.location.href=window.location.href;
}


function sendEventRegister(id)
{
	alert($('#events_reg_form').serialize());
	//$('#status_text_'+id).load('jax/register2event.jax.php', { 'event_id':id, 'company':$('#company').val(), 'address':$('#address').val(), 'name':$('#name').val(), 'phone':$('#phone').val(), 'email':$('#email').val() });
}

/* load pass from cache, so the user has not to enter the same pass more times in this session */
var events_pass_cache=new Array();

function handleEventsDownload(id,type,file)
{
	if (typeof events_pass_cache[id] == 'undefined') jPrompt(lang_password_text, '', lang_password, function(r) { eventsPasswordDownload(id,type,r,file);	});
	else eventsPasswordDownload(id,type,'OK',file)
}

function eventsPasswordDownload(id,type,pass,file)
{
	$.ajax({
		type: "POST",
		url: "jax/events_pass_check.jax.php",
		data: {'id':id, 'pass':pass, 'type':type, 'file':file},
		success: function(msg){
			msg = jQuery.trim(msg); 
			if (msg!='') 
			{
				events_pass_cache[id]=1;
				window.location.href='util/file.php?f='+msg;
			}
			else jAlert(lang_incorrect_password_text, lang_incorrect_password);
		}
	});
}

function toggle_events_gallery(event_id)
{
	if ($("#events_gallery_"+event_id).css("display")=='none')
	{
		//$("#events_gallery_"+event_id).find("img.short_news").each(function(){$(this).asynchImageLoader({ effect: "fadeIn", speed: 1000 });});
		
		$("#events_inner_gallery_"+event_id).load('jax/load_events_images.jax.php', { 'ev_id':event_id}, function(){
			$("#events_gallery_"+event_id).slideDown();	
		});
	}
	else $("#events_gallery_"+event_id).slideUp();
}

function checkbox_click(t)
{
	check_events_price();	
	if (t.checked) $('#events_checked').val(Number($('#events_checked').val())+1); 
	else $('#events_checked').val($('#events_checked').val()-1);
}
function check_events_price()
{
	var total_price=0;
	$('.reg_checkbox').each(function(index, element) {
		if (element.checked) total_price = total_price+parseInt($(element).attr('price'));
	});	
	//alert(total_price);
	if (total_price==0) {$('#money_agree_text').hide(); $('#free_agree_text').show();}
	else {$('#free_agree_text').hide(); $('#money_agree_text').show();}
}
	
