
function openWindow(url, w, h,name) {
        var Win = window.open(url,name,'width=' + w + ',height=' + h + ',resizable=1,scrollbars=yes,menubar=no' )
}
function Launch(url)
{
	openWindow(url,720,480,'padi');
}
function show_hide(ggg)
{

var val;
   val=document.getElementById(ggg);
   if(val.style.display=='none') val.style.display='';
   else val.style.display='none';


}
function hide(ggg)
{

var val=false;
   val=document.getElementById(ggg);
if(!val) alert(ggg);
   val.style.display='none';
}
function show(ggg)
{

var val;
   val=document.getElementById(ggg);
   val.style.display='';


}

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 eraseCookie(name) {
	createCookie(name,"",-1);
}
function wspin_get_skaly(select)
{
	var id=select.value;
	try
  {
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
  {
     if(xmlHttp.readyState==4)
     {
			select.form.id_rejon.value=id;
	 		document.getElementById('skaly_div').innerHTML=xmlHttp.responseText;
	 		document.getElementById('skaly_tr').style.display='';

     }
  }
  	xmlHttp.open("GET","modules/Wspin/ajax.php?id_rejon="+id+"",true);

    xmlHttp.send(null);


}
function wspin_nowy_rejon(input)
{
	try
  {
    xmlHttp=new XMLHttpRequest();
  xmlHttp.overrideMimeType('text/xml');
  }
  catch (e)
  {
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
  {
  
  	if (xmlHttp.readyState == 4) {
	if (xmlHttp.status == 200) {
	
		var xml=xmlHttp.responseXML;
		var root=xml.documentElement;
		var id;
		if(document.all) id=root.childNodes[1].text;
		else id=root.childNodes[1].firstChild.nodeValue;

		var text;
		if(document.all) text=root.childNodes[3].text;
		else text=root.childNodes[3].firstChild.nodeValue;
		input.form.id_rejon.style.display='none';	
		input.form.id_rejon.value=id;

	 	document.getElementById('skaly_div').innerHTML=text;
	 	document.getElementById('skaly_tr').style.display='';
	}
	}
	
   }
  	
	var url = "modules/Wspin/ajax.php";
	var params = "nowy_rejon="+input.value+"";
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
//  	xmlHttp.open("GET","modules/Wspin/ajax.php?nowy_rejon="+input.value+"",true);

    xmlHttp.send(params);


return false;
}
function wspin_nowa_skala(input)
{
	try
  {
    xmlHttp=new XMLHttpRequest();
  xmlHttp.overrideMimeType('text/xml');
  }
  catch (e)
  {
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
  {
  
  	if (xmlHttp.readyState == 4) {
	if (xmlHttp.status == 200) {
	
		var xml=xmlHttp.responseXML;
		var root=xml.documentElement;
		var id=0;
		if(document.all) id=root.childNodes[1].text;
		else id=root.childNodes[1].firstChild.nodeValue;

		if(input.form.skala) input.form.skala.style.display='none';	
		input.form.id_skala.value=id;

	 	document.getElementById('wycena_tr').style.display='';
	}
	}
	
   }
  	
	var url = "modules/Wspin/ajax.php";
	var params = "nowa_skala="+input.value+"&id_rejon="+input.form.id_rejon.value+"";
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.send(params);
return false;

}
function show_kalend(dtyp)
{
var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php',onSuccess: function(txt){
		
		$('kalendarz_content').set('html',txt);
//		showw('content_middle');
		$$('.dzien2').addEvents( { 'click': function(e) {
			show_day_big(this,e);
		}
		});
		$$('.wyjazd_dive_button ').addEvents( { 
		'mouseenter': function(e) {
			show_day(this,1);
		},
		'click':function(e) {
			e.stopPropagation();
		},


		'mouseleave': function(e){
			$$('.kalend_opis_short').each(function(a) { alert('a');a.getParent().getParent().set('class','dzien2');a.destroy();});
		}
		});
		$$('.wyjazd_priv_button').addEvents( { 
		'mouseenter': function(e) {
			show_day(this,0);
		},
		'click':function(e) {
			e.stopPropagation();
		},


		'mouseleave': function(e){
			$$('.kalend_opis_short').each(function(a) {   a.getParent().getParent().set('class','dzien2'); a.destroy();});
		}
		});


	}
	}).send('action=get_kalend&dtyp='+dtyp);
}
function show_day(div,divepoint)
{
	var dzien=div.getParent().id;

	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
	var day=new Element('div',{'class':'kalend_opis_short','style':''});
	day.set('html',txt);
	//div.getParent().set('class','dzien4');
	div.getParent().set('style','z-index:150;');
	day.addEvent('click',function(e) {e.stopPropagation(); } );
	day.inject(div);
	}
	}).send('action=get_dzien&dzien='+dzien+'&divepoint='+divepoint);

}
function close_day()
{
	$('show_day').setStyle('display','none');
}
function close_dzien_big()
{
	var el=$('show_day_big');
		var myEffect = new Fx.Morph(el, {duration: '300', transition: Fx.Transitions.Sine.easeOut});
		 myEffect.start({
			 'top':[0,350],
			 'left':[0,350],
			 'width':[703,84],
			 'height':[528,84],
			 'display':'none'

			 });

}
function show_day_big(div,e)
{
	var dzien=div.id;

	$('show_day').setStyle('display','none');
	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php',onSuccess: function(txt){
		$('show_day_big').set('html',txt);
		var size=div.getCoordinates('miesiac');
		$('show_day_big').setStyle('display','');
		var el=$('show_day_big');
		var myEffect = new Fx.Morph(el, {duration: '300', transition: Fx.Transitions.Sine.easeOut});
		 
		 myEffect.start({
			 'top':[size.top,0],
			 'left':[size.left,0],
			 'width':[94,698],
			 'height':[94,528]
			 });
//		el.set('tween', {duration: 'long'});
//		el.tween('top', '0px');
//		el.tween('left', '0px');

//		alert(size.x+' y'+size.y)
	}
	}).send('action=get_dzien_big&dzien='+dzien);

}
function add_kalend(e,div)
{

	$('show_day').setStyle('display','none');
	e.stopPropagation();
	var dzien=div.getParent().id;
	var el=$('add_kalend');

	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		$('add_kalend').set('html',txt);
	}
	}).send('action=add_kalend&dzien='+dzien);

		var size=div.getCoordinates('miesiac');
		el.setStyles({'top':size.top,'left':size.left,'width':'50px',height:'50px'});
		
		var myEffect = new Fx.Morph(el, {duration: '300', transition: Fx.Transitions.Sine.easeOut});
		 myEffect.start({
			 'top':[size.top,size.top-100],
			 'left':[size.left,size.left-100],
			 'width':[50,300],
			 'height':[50,337]
			 }); 
		el.setStyle('display','');

}

function  close_add_kalend() { $('add_kalend').setStyle('display','none'); }

function save_wyjazd()
{
	if((!$('id_miejsca').value)  && 	(!$('miejsce_text').value) ) { 	alert('Wybierz miejsce'); return false;	}

	var id_cat=$('id_cat')?($('id_cat').checked?1:0):0;
	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		var data=$($('data').value);
		var tt=data.get('html');
		var tmpp='';
		if(id_cat) tmpp='<div class="wyjazd_dive_button"><img src="images/page/wyjazd_dive_button.png"/></div>';
		 else tmpp='<div class="wyjazd_priv_button"><img src="images/page/wyjazd_priv_button.png"/></div>';
		data.set('html',tt+tmpp);

 		if($$('.wyjazd_dive_button').length > 0)//only triggered if 'mb' class found on page
		{

		$$('.wyjazd_dive_button ').addEvents( { 
		'mouseenter': function(e) {

			if($$('.kalend_opis_short').length>0) {
				$$('.kalend_opis_short').each(function(a) { a.destroy();});
			}
			show_day(this,1);
		},
		'mouseleave': function(e) {
			if($$('.kalend_opis_short').length>0) {
				$$('.kalend_opis_short').each(function(a) { a.destroy();});
			}
		},

		'click':function(e) {
			e.stopPropagation();
		}


		});
		}
 		if($$('.wyjazd_priv_button').length > 0)//only triggered if 'mb' class found on page
		{
		$$('.wyjazd_priv_button').addEvents( { 
		'mouseenter': function(e) {
			if($$('.kalend_opis_short').length>0) {
				$$('.kalend_opis_short').each(function(a) { a.destroy();});
			}
			show_day(this,0);
		},
		'mouseleave': function(e) {
			if($$('.kalend_opis_short').length>0) {
				$$('.kalend_opis_short').each(function(a) { a.destroy();});
			}
		},

		'click':function(e) {
			e.stopPropagation();
		}


		});
		
		}


		$('add_kalend').set('html',txt);
		$('add_kalend').setStyle('display','none');
//		alert($('data'));
//		$($('data').value).addopt('<div class="wyjazd_priv_button"><img src="images/page/wyjazd_priv_button.png"/></div>')

	}
	}).send('action=save_wyjazd&data='+$('data').value+'&czas='+$('czas').value+'&opis='+$('opis').value+'&miejsce='+$('miejsce_text').value+'&id_miejsca='+$('id_miejsca').value+'&id_cat='+id_cat);

}
function save_wyjazd_panel(id)
{
	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){

	}
	}).send('action=save_wyjazd&data='+$('data_'+id).value+'&czas='+$('czas_'+id).value+'&opis='+$('opis_'+id).value+'&id_miejsca='+$('id_miejsca_'+id).value+'');
}
function get_ankieta(id)
{
	
	var req = new Request({method: 'get', url: 'modules/Ankieta/ajax.php', evalScripts:true, onSuccess: function(txt){
		$('ankieta').set('html',txt);
	}
	}).send('action=get_ankieta&id_ankieta='+id);
}
function ankieta_submit(id)
{
	
	var ank_form=$('ankieta_form');
	var id_odp=0;
	for ( i =0; i< ank_form.ankieta_value.length;i++)
	{
		if(ank_form.ankieta_value[i].checked) { id_odp=ank_form.ankieta_value[i].value ; break;}

	}
	if(!id_odp) { alert('Nie podaleś żadnej odpowiedzi.'); return false; }
	createCookie('ankieta_'+id,1,5) ;
	
	


	var req = new Request({method: 'get', url: 'modules/Ankieta/ajax.php', evalScripts:true, onSuccess: function(txt){
		$('ankieta').set('html',txt);
	}
	}).send('action=ankieta_submit&id_ankieta='+id+'&id_odp='+id_odp);
}

function update_wyjazd(id)
{
	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
	$('mod_wyjazd_'+id).setStyle('display','none');
	}
	}).send('action=update_wyjazd&data='+$('data_'+id).value+'&czas='+$('czas_'+id).value+'&opis='+$('opis_'+id).value+'&id_miejsca='+$('id_miejsca_'+id).value+'&miejsce='+$('miejsce_'+id).value+'&id_wyjazd='+id);

}
function mod_gall(id)
{
	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		$('mod_gall').set('html',txt);
		showw('mod_gall');

/*
	var swiffy = new FancyUpload2($('fancy-status'), $('fancy-list'), {
		url: $('form-demo').action,
		fieldName: 'photoupload',
		path: 'flash/Swiff.Uploader.swf',
		limitSize: 2 * 1024 * 1024, // 2Mb
		limitFiles: 30, 
		onLoad: function() {
			$('fancy-status').removeClass('hide');
			$('fancy-fallback').destroy();
		},
		// The changed parts!
		debug: true, // enable logs, uses console.log
		target: 'fancy-browse' // the element for the overlay (Flash 10 only)
	});
 
	var filter = {'Obrazki (*.jpg, *.jpeg )': '*.jpg; *.jpeg;'};
		swiffy.options.typeFilter = filter;

	$('fancy-browse').addEvent('click', function() {
		swiffy.browse();
		return false;
	});
 
 
	$('fancy-clear').addEvent('click', function() {
		swiffy.removeFile();
		return false;
	});
 
	$('fancy-upload').addEvent('click', function() {
		swiffy.upload();
		return false;
	});
 
*/



		if($$('.mb').length > 0)//only triggered if 'mb' class found on page
		 {
		 var initMultiBox = new multiBox('mb', {
			 descClassName: 'multiBoxDesc',//the class name of the description divs
			 path: './Files/',//path to mp3 and flv players
			 useOverlay: true,//use a semi-transparent background. default: false;
			 maxWidth: 600,//max width (set to false to disable)
			 maxHeight: 400,//max height (set to false to disable)
			 addDownload: false,//do you want the files to be downloadable?
			 pathToDownloadScript: './Scripts/forceDownload.asp',//if above is true, specify download script
			 addRollover: true,//add rollover fade to each multibox link
			 addOverlayIcon: false,//adds overlay icons to images within multibox links
			 addChain: true,//cycle through all images fading them out then in
			 recalcTop: true//subtract the height of controls panel from top position
 		});
		 };


	}
	}).send('action=mod_gall&id_gall='+id);

}
function del_gall_foto(id_foto,obj)
{
	var ask=confirm('Jestes pewien że chcesz usunąć to zdjęcie?');
	if(ask)
	{
	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		if(txt) obj.getParent().getParent().destroy();
	}
	}).send('action=del_gall_foto&id_foto='+id_foto);
	}

}
function del_wyjazd(id,img)
{
var ask=confirm('Jestes pewien?');
if(ask)
{

	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		if(txt) img.getParent().getParent().destroy();
	}
	}).send('action=del_wyjazd&id='+id);
}
}
function del_miejsce(id,img)
{
var ask=confirm('Jestes pewien?');
if(ask)
{

	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		if(txt) img.getParent().getParent().destroy();
	}
	}).send('action=del_miejsce&id='+id);
}
}
function del_galeria(id,img)
{
var ask=confirm('Jestes pewien?');
if(ask)
{

	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		if(txt) img.getParent().getParent().destroy();
	}
	}).send('action=del_galleria&id='+id);
}
}
function del_koment(img,id)
{
var ask=confirm('Jestes pewien?');
if(ask)
{

	var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
		if(txt) img.getParent().getParent().getParent().getParent().destroy();
	}
	}).send('action=del_koment&id='+id);
}
}

function save_pass(a)


{	var butt=	new Element('input',{'id':'butt_pass','type':'button','value':'Zmień hasło'});
		
		butt.addEvent('click',function() {  

			if($('pass_1').value==$('pass_2').value) 
			{
				var req = new Request({method: 'get', url: 'modules/DivePoint/ajax.php', evalScripts:true, onSuccess: function(txt){
					$('pass_1').destroy();
					$('pass_2').destroy();
					$('butt_pass').destroy();
				}
				}).send('action=save_pass&pass='+$('pass_1').value);
	
			}
			else 
			{
				alert('Hasła nie są identyczne');
			}

		} );

	$('zmiana_pass').adopt(
		new Element('input',{'id':'pass_1','type':'password'}),
		new Element('input',{'id':'pass_2','type':'password'}),
		butt
		); 

}

window.addEvent('domready', function(){
 if($$('.mb').length > 0)//only triggered if 'mb' class found on page
 {
 var initMultiBox = new multiBox('mb', {
 descClassName: 'multiBoxDesc',//the class name of the description divs
 useOverlay: false,
 path: './Files/',//path to mp3 and flv players
 maxWidth: 600,//max width (set to false to disable)
 maxHeight: 400,//max height (set to false to disable)
 addDownload: false,//do you want the files to be downloadable?
 pathToDownloadScript: './Scripts/forceDownload.asp',//if above is true, specify download script
 addRollover: true,//add rollover fade to each multibox link
 addOverlayIcon: false,//adds overlay icons to images within multibox links
 addChain: true,//cycle through all images fading them out then in
 recalcTop: true//subtract the height of controls panel from top position
 });
 };
 if($$('.page_log').length > 0)//only triggered if 'mb' class found on page
 {
	$$('.page_log').addEvents({ 
		'mouseenter':function (e) {  this.set('tween',{duration: 200 }); this.tween('height','100');  },
		'mouseleave':function (e) {  this.tween('height','20');   }
	
	});
 }



});


function show_popup(url,width,height,timeout)
{
var div=new Element('div',{'style':'overflow:hidden;position:fixed;z-index:30;top:300px;height:5000px;width:587px;left:50%;margin-left:-'+width/2+'px'});

new Request({url:url,method:'post',onSuccess:function(txt) {
var myDrag;
div.set('html',txt);
var close=new Element('div',{'style':'position:absolute;right:0px;background-image:url(images/page/close.png);width:24px;height:24px;cursor:pointer;'}).inject(div,'top');
close.addEvent('click',function(){ div.destroy();} );
var move=new Element('div',{'style':'position:absolute;right:30px;background-image:url(images/page/move.png);width:24px;height:24px;cursor:pointer;'}).inject(div,'top');
move.addEvent('mousedown',function() { $(document.body).setStyle('cursor','-moz-grabbing');  myDrag=new Drag.Move(div); } );
move.addEvent('mouseup',function() {  $(document.body).setStyle('cursor','auto');  myDrag.detach(); } );
close.inject(div);
move.inject(div);


}}).send();
div.inject($(document.body),'top');
div.addEvent('koniec',function(){ this.destroy();} );
var left= div.getCoordinates().left;
left=left+(width/2);
div.setStyle('left',left+'px');
//if(timeout) div.fireEvent('koniec','',timeout);
}
