//------------------------------------------------------------------------------- AJAX
var http_request = false;
var cel="";
var filter="";

   function makePOSTRequest(url, parameters,fk) {
      http_request = false;
	  
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      if(fk==1){
	     http_request.onreadystatechange = alertContents;
      }else{
		 http_request.onreadystatechange = alertContentsRead;
      }
	  
	  http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			
            document.getElementById('myspan').innerHTML = result;            
			
		 } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function alertContentsRead() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//alert(cel);			
			var  ok=document.getElementById(cel);
			if (cel!="msg_cont")
			{
				ok.innerHTML=result;
			}else{
				

			}
            document.getElementById('myspan').innerHTML ="wykonano"; //result;            
         } else {
            alert('There was a problem with the request.');
         }
      }else{
		var  ok=document.getElementById(cel);
			if (cel!="msg_cont")
			{
			ok.innerHTML="<img src='images/load0.gif' width='147px'>";}
	  }	
   }
//--------------------------------------------------------
//-----------------------------------------------------------------------test formularza
testFormularza={
		
	rodzajePol:{
		niepuste:
		[/.+/,'Proszę wypełnić pole'],
		email:
		[/^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/,'Proszę podać prawidłowy adres e-mail'],
		dataa:[/^.[0-9]{3}-.[0-9]{1}-.[0-9]{1}$/,"data ma być podana w formacie RRRR-MM-DD"],
		dataczas:[/^.[0-9]{3}-.[0-9]{1}-.[0-9]{1} .[0-9]{1}:.[0-9]{1}:.[0-9]{1}$/,"poprawny format RRRR-MM-DD HH:MM:SS"],

		liczba:[/^\d+(\.\d+)?$/,"należy podać liczbe"]
	},

	testuj:function(f){
	
		var i,rodz,E;
		//alert(f.elements);

	    	for(i=0;i<f.elements.length;i++){
      
		  E=f.elements[i];
		  if(rodz=this.rodzajePol[E.getAttribute('rodzajpola')])
			
			if(!rodz[0].test(E.value)){
								 							  
				E.focus();
				E.select();
				if (znacznik=document.getElementById('blad1')){
				
					znacznik.parentNode.removeChild(znacznik)
					znacznik = document.createElement('error');
					znacznik.setAttribute('id', 'blad1');
					znacznik.setAttribute('color', 'red');
					
					znacznik.appendChild(document.createTextNode('▼▼▼▼▼▼▼▼'));										
					   E.parentNode.insertBefore(znacznik, E);
	 
					 znacznik.className="mini_blad";
				}else{ 
					znacznik = document.createElement('error');
					znacznik.setAttribute('id', 'blad1');
					znacznik.setAttribute('color', 'red');
					znacznik.appendChild(document.createTextNode('▼▼▼▼▼▼▼'));

					 E.parentNode.insertBefore(znacznik, E);
					 znacznik.className="mini_blad";
					
				}


				  alert('"'+E.value+'" nie jest prawidłową wartością'+' tego pola '+E.name+' formularza!\n'+(E.getAttribute('komunikat')||rodz[1]));
				 return false;
			}
		}     
	return true;

	}
}
//----------------------------------------------------SPRAWDZANIE----------------------------------------
function sprawdznews(co){

	var f=document.getElementById(co);

		function stwozZapytanie(){
			 
			 zap="&";
			  for(i=0;i<f.elements.length;i++){
				  E=f.elements[i].name;
				  V=f.elements[i].value;
				  zap+=E+"="+V+"&";
		
			  }
			  return zap;
		  }
	
					 
		if(testFormularza.testuj(f)){	
						var los=(Math.floor(Math.random()*2000));
						TABF=f.action.split('?');
						zap=stwozZapytanie();
						poststr="?"+TABF[1]+encodeURI(zap)+los;
						cel="newsLBody";
						makePOSTRequest(TABF[0],poststr,2);
		}

	return false;
}
//----------------------------------------------------FUNKJE
function pokazN3Form(){
	ustawopIn('formZapytania',0);
}
//-------------------------------------------------------PKAZ BSK
function pokazN3(){
		//liczba losowa
		var los=(Math.floor(Math.random()*2000));
		//okreslenie id diva gdzie sie to wyswietli
		cel="newsLBody";
		poststr=encodeURI("los=")+los;
		makePOSTRequest("includes/formularz_news.php",poststr,2);	
	
}
//--------------------------------------------------- OKNA FORMULARZY-----------------------------------
var alfastart=0;

function ustawop(indent,value)
{
	if(value == 0) {
		document.getElementById(indent).style.display = 'none';
	} else {
		document.getElementById(indent).style.display = 'block';
	}

	document.getElementById(indent).style.opacity = (value / 100);
	document.getElementById(indent).style.MozOpacity = (value / 100);
	document.getElementById(indent).style.KhtmlOpacity = (value / 100);
	document.getElementById(indent).style.filter = "alpha(opacity=" + value + ")";
  	value=value-10;	
	if(value+10>0){
   		setTimeout("ustawop('"+indent+"',"+value+")",20);
	}
}

function ustawopIn(indent,value)
{
	if(value == 0) {
		document.getElementById(indent).style.display = 'none';
	} else {
		document.getElementById(indent).style.display = 'block';
	}

	document.getElementById(indent).style.opacity = (value / 100);
	document.getElementById(indent).style.MozOpacity = (value / 100);
	document.getElementById(indent).style.KhtmlOpacity = (value / 100);
	document.getElementById(indent).style.filter = "alpha(opacity=" + value + ")";
  	value=value+10;	
	if(value-10<100){
  		 setTimeout("ustawopIn('"+indent+"',"+value+")",20);
	}
}
function ustawopZero(indent,value)
{
	if(value == 0) {
		document.getElementById(indent).style.display = 'none';
	} else {
		document.getElementById(indent).style.display = 'block';
	}

	document.getElementById(indent).style.opacity = (value / 100);
	document.getElementById(indent).style.MozOpacity = (value / 100);
	document.getElementById(indent).style.KhtmlOpacity = (value / 100);
	document.getElementById(indent).style.filter = "alpha(opacity=" + value + ")";
   	
	
}	
	
function ukryj(indent) {
	  document.getElementById(indent).style.display='none';
}
//---------------------------------------------------------------------

