function open_window(file, width, height)
{
	var left = (screen.width - width) / 2;

	var top = (screen.height - height + 20) / 2;

	var Win =  window.open(file, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left);
	Win.resizeTo(width, height);
	Win.focus();
}

function js_ZapytajCzyNapewno(pytanie){
	var r=confirm(pytanie);
	if (r==true){
		return true;
	}
	return false;
}

function data_urodzin_z_pesela(pesel){
	var data = [''];
	var year = '';
	var month = '';
	var e = document.getElementById('data_urodzenia');
	if( parseInt(pesel.charAt(0)) == 0 ) {
		switch(true){
			case ( parseInt(pesel.charAt(2).toString()+pesel.charAt(3).toString()) >= 20 &&  parseInt(pesel.charAt(2).toString() + pesel.charAt(3).toString()) <= 32 ):
				month = parseInt(pesel.charAt(2).toString()+pesel.charAt(3).toString()) - 20;
				year = parseInt(pesel.charAt(2)+pesel.charAt(3)) - month ;
				data.push(year.toString()+pesel.charAt(0)+pesel.charAt(1)); // rok
				data.push('-');
				data.push((month.toString().length == 1) ? '0'+month.toString() : month.toString() ); // miesiac
				data.push('-');
				data.push(pesel.charAt(4).toString()+pesel.charAt(5).toString() ); // dzien
				break;				
		}
	}else{
		data.push('19'+pesel.charAt(0)+pesel.charAt(1)); // rok
		data.push('-');
		data.push(pesel.charAt(2)+pesel.charAt(3)); // miesiac
		data.push('-');
		data.push(pesel.charAt(4)+pesel.charAt(5)); // miesiac
	}
	if( data.join('').toString().length == 10 ){
		e.value = data.join('');
	}else{
		e.value = "";
	}
}

function open_file_in_window(file, width, height)
{
	var left = (screen.width - width) / 2;

	var top = (screen.height - height + 20) / 2;

	var Win =  window.open(file, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left);
	Win.resizeTo(width, height);
	Win.focus();
}

function checkmail(value){
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var returnval=emailfilter.test(value);
	if (returnval==false){
		alert("Prosze podac poprawny email");
		//document.getElementById('emial').select();
	}
	return returnval;
}	

function checkFileType(FileID,fileTypes){
	if (eval("document.getElementById('"+FileID+"').value != ''")){
		val = eval("document.getElementById('"+FileID+"').value;");
		val = val.toLowerCase();
		reg= eval("/"+fileTypes+"/");
		if(!reg.test(val)){
			alert('proszę wskazac plik '+fileTypes);
			eval("document.getElementById('"+FileID+"').value = '';");
			eval("document.getElementById('"+FileID+"').select();");	
		}
	}
}
	
function open_window(text, params) {  
		var Win = window.open('',"displayWindow",'width=' +  params["width"] + ',height=' +  params["height"] + ',resizable=0,scrollbars=no, menubar=no,statusbar=0, left='+200+', top='+100,true );
		var head ='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>' +  params["title"] + '</title></head><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">';
		var fott ='</body></html>';
		Win.document.open();
		Win.document.write(head+text+fott);
		Win.document.close();
		Win.resizeTo(params["width"], params["height"]);
		Win.focus();
}


function addToFavorite()
{ 
	if (window.sidebar)  
		window.sidebar.addPanel(document.title,location.href,''); 
	if (document.all)
		window.external.AddFavorite(location.href,document.title);
}
function printCurentWindow(){
	if (!window.print){
		alert("Musisz miec NS4.x lub IE5,\naby uzyc przycisku drukowania!");
		return;
	}
	window.print();
}
function open_foto (foto,descr,width,height){
	prop = new Array();
	prop['width'] = width;
	if (descr != ''){ height = parseInt(height) + 150; }else{ height = parseInt(height) + 100;}
	prop['height'] = height;
	prop['title'] = 'foto: '+width+'/'+height;
	var text = new String;
	text = '<a style="cursor:pointer;" onclick="window.close();"><img src="'+foto+'" alt="image" title="'+descr+'" border="0" /></a><br />'+descr;
	text += '<script language="javascript" type="text/javascript">window.onBlur="window.close();"</script>';
	open_window(text, prop);
	
}
function CreateEditor(file,prop)
{
	var oFCKeditor = new FCKeditor(file) ;
	oFCKeditor.BasePath = '../plugins/FCKeditor/';
	oFCKeditor.Width = '100%' ;
	oFCKeditor.Height = prop['height'] ;
	oFCKeditor.ToolbarSet = prop['toolTyp'];
	oFCKeditor.Config["ToolbarLocation"] = "Out:"+prop['toolID'];
	oFCKeditor.ReplaceTextarea() ;
}

function js_PrepareSave(DataText0)
{
	if ( typeof( FCKeditorAPI ) != 'undefined' ){
		if ( DataText0 != ''){
			var oEditor = FCKeditorAPI.GetInstance(DataText0) ;
			document.getElementById(DataText0).value = oEditor.GetXHTML() ;
		}
	}
} 

function onMouseEvents(e,val,kierunek){
	if(kierunek == 1)
	{
		if (e.value == val) e.value = "";		
	}
	else if (kierunek == 0)
	{
		if (e.value == "") e.value = val;
	}	
}
