function demotSave(_id) {
	if (_id>0) {
		demotSaveAll(_id); 
	} else {
		Show_full('alert_box');
		$('alert_txt').innerHTML = "Nie jestes zalogowany:<br/> Jeśli Twój demot wygra- nie będziesz mógł wgrać następnego zdjęcia.<br/><br/><input onclick=\"demotSaveAll(-1);\" type=\"button\" class=\"btn_send\" style=\"width:180px;\" value=\"zapisz anonimowo!\" /><br/>lub<br/><input onclick=\"location.href='/login';\" type=\"button\" class=\"btn_send\" style=\"width:180px;\" value=\"zaloguj/zarejestruj!\" /><br/>"; 
	}
}
function clearTable(_table) { 
	for (i = _table.rows.length-1; i >= 0; i--)
		_table.deleteRow(i);
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
	}

function demotSaveAll(_user_id) {
	var text_1 = $('demot_text_1').value; 
	var text_2 = $('demot_text_2').value; 
	if ((text_1=="")){
		Show_full('alert_box');
		$('alert_txt').innerHTML = "Musisz wypełnić pierwsze pole!"; 
		return;
	}	
	if ((text_1=="......")){
		Show_full('alert_box');
		$('alert_txt').innerHTML = "Musisz wypełnić pierwsze pole!"; 
		return;
	}	 
	if ((text_2=="......"))
		text_2="";
	new Ajax.Request('./act/demot.act.php', {
		method: 'post',
		parameters: {'act': 'saveDemot', 'user_id': _user_id, 'text_1': text_1, 'text_2': text_2 },
		onCreate: function() {
			Show_full('alert_box');
			$('alert_txt').innerHTML = "Trwa wysyłanie danych ...";  
		},
		onSuccess: function(transport)  {	
			if (trim(transport.responseText) >0) {
				$('demot_text_1').value="......";
				$('demot_text_2').value="......";
				$('alert_txt').innerHTML = "Zapisano! Co teraz?<br/><div align=\"left\" style=\"padding-left:10px;\"><ul><li><a href=\"/showd-"+trim(transport.responseText)+".html\">pokaż mojego demota!</a></li><li><a href=\"/oceniaj\">oceniaj konkursowe demoty!</a></li></ul></div>";	
			//	$('trigg').submit();
				
				
			} else { 
				$('alert_txt').innerHTML = "Błąd: "+transport.responseText; 
			};  
		},
		onFailure: function() { 
			$('alert_txt').innerHTML = "Wysyłanie... (błąd)";  
		} 	
	});
	return true; 		
	
}

function delMessage(_id) {
	
	new Ajax.Request('./act/user.act.php', {
		method: 'post',
		parameters: {'act': 'delMessage', 'mid': _id },
		onCreate: function() {
			Show_full('alert_box');
			$('alert_txt').innerHTML = "Trwa wysyłanie danych ...";  
		},
		onSuccess: function(transport)  {	
			if (trim(transport.responseText) =="ok") {
				Hide('alert_box');
				Hide('msg_'+_id);
			} else { 
				$('alert_txt').innerHTML = "Błąd: "+transport.responseText; 
			};  
		},
		onFailure: function() { 
			$('alert_txt').innerHTML = "Wysyłanie... (błąd)";  
		} 	
	});
	return true; 		
}

function changeMenu(_tab) {
  var nclass= "menu_bg_"+_tab;
 $('menu_tb').className=nclass;
}
function loadImages() {
	var myImage = new Image;
	myImage.src = "img/btn_0_1.jpg";
	var myImage = new Image;
	myImage.src = "img/btn_1_1.jpg";
	var myImage = new Image;
	myImage.src = "img/btn_2_1.jpg";
	var myImage = new Image;
	myImage.src = "img/btn_3_1.jpg";
	var myImage = new Image;
	myImage.src = "img/btn_4_1.jpg";
	var myImage = new Image;
	myImage.src = "img/btn_5_1.jpg";
}

function changePFotoID(){
	var fid=$('p_foto').value;
	new Ajax.Request('./act/user.act.php', {
		method: 'post',
		parameters: {'act': 'pfoto', 'fid': fid },
		onCreate: function() {
			Show_full('alert_box');
			$('alert_txt').innerHTML = "Trwa wysyłanie danych ...";  
		},
		onSuccess: function(transport)  {	
			if (trim(transport.responseText) =="ok") {
				$('alert_txt').innerHTML = "Zmieniłem"; 
				
			} else { 
				$('alert_txt').innerHTML = "Błąd: "+transport.responseText; 
			};  
		},
		onFailure: function() { 
			$('alert_txt').innerHTML = "Wysyłanie... (błąd)";  
		} 	
	});
	return true; 		
	
}

function sprawdz_konto(formularz)
{
  for (i = 0; i < formularz.length; i++)
  {
    var pole = formularz.elements[i];
    if ((pole.type == "text" || pole.type == "text" || pole.type == "text" || pole.type == "text") && pole.value == "")
    {
      alert("Proszę wypełnić wszystkie pola!");
      return false;
    }
  }
  return true;
}


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function ShowOrHide(div) {
var d = $(div);
if (document.getElementById(div).className.indexOf("hide") != -1) {
Element.removeClassName( d, "hide" );
Element.addClassName( d, "show" );
} else
{
Element.removeClassName( d, "show" );
Element.addClassName( d, "hide" );
}
}



/* Komunikat błędu - AJAX */ 
function ajaxErrorMessage(msg) 
{
	var mm = 'Nie udało się odebrać odpowiedzi z serwera. Prosimy o kontakt z administratorem, '; 
	if (msg != '') 
		mm += 'przekazując mu następujący komunikat: '+msg; 
	else 
		mm += 'opisując mu przy jakiej czynności ten błąd się pojawił'; 
	alert(mm); 
}


/* Sprawdzanie poprawności adresu e-mail */ 
function checkEMail(adres) {
	if (adres != "") {
		var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
		var wynik = re.test(adres);
		if (wynik == true) {
			return true;
		}
		if (wynik == false) {
			return false;
		}
	}
}

function primoClearTable(_table) { 
	for (i = _table.rows.length-1; i >= 0; i--)
		_table.deleteRow(i);
}; 

/* Sprawdzenie poprawności kodu pocztowego */ 
function checkPostCode(kod)
{
//  var regex = /^[0-9]{2}\-[0-9]{3}$/;
  var regex = /^[0-9]{5}$/;
  return regex.test(kod);
}

/* Sprawdzenie poprawności wprowadzenia liczby całkowitej */ 
function checkIntNumber(liczba)
{
  var regex = /^[\-]{0,1}[0-9]{1,8}$/;
  return regex.test(liczba);
}


/* Sprawdzenie poprawności wprowadzenia liczby zmiennoprzecinkowej */ 
function checkRealNumber(liczba)
{
  var regex = /^[\-]{0,1}[0-9]{1,8}[.]{0,1}[0-9]{0,6}$/;
  return regex.test(liczba);
}

/* Sprawdzenie poprawności godziny */ 
function checkHour(godz)
{
  var regex = /^[0-9]{2}\:[0-9]{2}$/;
  return regex.test(godz);
}

function changeSpecialChars(txt)
{
  var arg = txt.replace(/</g,'&lt;');
  arg = arg.replace(/>/g,'&gt;');
  return arg; 
}

function hl2Item(item,action) {
	color='#AEAEAE';
	if (action==0) 
		color='#EBEBEB';
	item.style.background=color;
}

function hlOn() {
	this.style.background='#f3f3f3';
}

function hlOff() {
	this.style.background='#ffffff';
}

function changeOrder(form,item) {
	if (document.getElementById(form).order.value==item-1)
		iSort=(parseInt(document.getElementById(form).sort.value)+1)%2;
	else
		iSort = 0;
	document.getElementById(form).order.value=item-1;
	document.getElementById(form).sort.value=iSort;
	document.getElementById(form).submit();
}


function popup(v,t,e,p){
	if(!document.createElement) return;
	p=document.getElementById('popup');
	if(!p){
		p=document.createElement('div');
		p.id='popup';
		p.style.zIndex=100;
		if(document.all&&!window.opera)
		    p.style.position='absolute';
		else
		    p.style.position='fixed';
		p.style.padding='1px';
		p.style.border='1px solid #000000';
		p.style.backgroundColor='#ffffff';
		p.style.MozOpacity='0.9';
		p.style.align='left';

	}
	p.move=function(e){
		e=e||event;
		p.style.left=e.clientX+5+"px";
		if(document.all&&!window.opera)
		    p.style.top=e.clientY+document.body.scrollTop+20+"px";
		else
		    p.style.top=e.clientY+20+"px";
	}
	p.hide=function(x){
		if(x=document.getElementById('popup')) document.body.removeChild(x)
	}
	p.move(e);
	p.innerHTML=t;
	document.body.appendChild(p);
	p.onmousedown=p.hide;
	v.onmouseout=p.hide;
}

function popup_l(v,t,e,p){
	if(!document.createElement) return;
	p=document.getElementById('popup');
	if(!p){
		p=document.createElement('div');
		p.id='popup';
		p.style.zIndex=100;
		if(document.all&&!window.opera)
		    p.style.position='absolute';
		else
		    p.style.position='fixed';
		p.style.padding='1px';
		p.style.border='1px solid #000000';
		p.style.backgroundColor='#ffffff';
		p.style.MozOpacity='0.9';
		p.style.align='left';

	}
	p.move=function(e){
		e=e||event;
		p.style.left=e.clientX-100+"px";
		if(document.all&&!window.opera)
		    p.style.top=e.clientY+document.body.scrollTop+20+"px";
		else
		    p.style.top=e.clientY+20+"px";
	}
	p.hide=function(x){
		if(x=document.getElementById('popup')) document.body.removeChild(x)
	}
	p.move(e);
	p.innerHTML=t;
	document.body.appendChild(p);
	p.onmousedown=p.hide;
	v.onmouseout=p.hide;
}

function ShowOrHide(div) {
var d = $(div);
if (document.getElementById(div).className.indexOf("hide") != -1) {
Element.removeClassName( d, "hide" );
Element.addClassName( d, "show" );
} else
{
Element.removeClassName( d, "show" );
Element.addClassName( d, "hide" );
}
}

function isNumeric(input) {
   var fine = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < input.length && IsNumber == true; i++) 
      { 
      Char = input.charAt(i); 
      if (fine.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function getElementById(id) {
    if (document.all) {
	return document.getElementById(id);
    }
    for (i=0;i<document.forms.length;i++) {
	if (document.forms[i].elements[id]) {return document.forms[i].elements[id]; }
    }
    return null;
}


function Show(div) {
	var d = $(div);
	Element.removeClassName( d, "hide" );
	Element.addClassName( d, "show" );

	setTimeout("Hide('"+div+"')", 1000);
	}
function Show_full(div) {
	var d = $(div);
	Element.removeClassName( d, "hide" );
	Element.addClassName( d, "show" );
	}

function Hide(div) {
var d = $(div);
Element.removeClassName( d, "show" );
Element.addClassName( d, "hide" );
}


