
//------------------------------------------------------------------------------- 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'>";}
	  }	
   }
//---------------------------------------------------- DO AJAXA
function pokazPlansze(idimp)
{					 Tablica=new Array(F_MIEJSCA);
					for (i=0; i<=F_MIEJSCA; i++)
						{
								 Tablica[i]=new Array(F_RZEDY);
	 							
						}

					var los=(Math.floor(Math.random()*2000));
					var reszta="";					
					if(document.getElementById('inpKodRez')){
								reszta="&kod="+document.getElementById('inpKodRez').value;
					}	
					//alert (reszta);
					cel="main_cont";
					poststr="?wyb=ok&id_impreza="+idimp+reszta+"&los="+los;
					makePOSTRequest("php_ajax/plansz.php",poststr,2);
}


function  wyborImprezy(co){
					 Tablica=new Array(F_MIEJSCA);
					for (i=0; i<=F_MIEJSCA; i++)
						{
								 Tablica[i]=new Array(F_RZEDY);
	 	
						}
					var los=(Math.floor(Math.random()*2000));
					cel="main_cont";
					poststr="?wyb=ok&id_impreza="+co.value+"&los="+los;
					makePOSTRequest("php_ajax/plansz.php",poststr,2);
}
function filmInfo(idfilmu){
					var los=(Math.floor(Math.random()*2000));
					cel="container_desc";
					poststr="?wyb=ok&id_film="+idfilmu+"&los="+los;
					makePOSTRequest("phpajax/filminfo.php",poststr,2);

}
//------------------------------------------------------------------
//---------------------------------------------------------------------player
 function createPlayer(pId,imag,domain)
      {
        if(pId == 'undefined')
        {
          pId = 'movie';
	
        }
        var s1 = new SWFObject('swf/player.swf', 'ccvideo', '570', '321', '8');
        
	    s1.addParam('allowfullscreen',            'true');
		s1.addParam('wmode','transparent');
            s1.addVariable('width',                   '570');
	    s1.addVariable('skin',                   'swf/skins/stylish_slim.swf&lightcolor=#7bb634&controlbar=over');	
            s1.addVariable('height',                  '321');
            s1.addVariable('streamer',                'rtmp://'+domain+'/oflaDemo');
	    s1.addVariable('image',              		imag);
            s1.addVariable('file',                       pId);
            s1.addVariable('enablejs',                'true');
            s1.addVariable('javascriptid',            'ccvideo');
            s1.write('container');
      };

//--------------------------------------------------------------------------


function clearMiniG(){
	
	if(document.getElementById('art_minigrafa')){
		document.getElementById('art_minigrafa').className="art_minigrafa_trans";
		document.getElementById('art_minigrafa').innerHTML="<img src='images/inf.png'>";
	
	}	
	
}
//----------------------------------------------------------
function nextfoto(id_cont){

	eval('var szuk="foto_art_'+id_cont+'"');
	var spanik=document.getElementById(szuk);
	eval('cont_l_'+id_cont+'=cont_l_'+id_cont+'+1');
	eval('var lk=cont_l_'+id_cont);	
	eval('var lkmax=contmax_'+id_cont);
	if (lk>=lkmax){
		eval('cont_l_'+id_cont+'=0');
		lk=0;
	}	
			
	eval('var foto=cont_'+id_cont+'[lk]');	
	spanik.innerHTML= "<img src='admin/miniatury/"+foto+"' border='0'  style='margin-top:5px;width:150px;margin-bottom:5px;'>";

}
function prevfoto(id_cont){

	eval('var szuk="foto_art_'+id_cont+'"');
	var spanik=document.getElementById(szuk);
	eval('cont_l_'+id_cont+'=cont_l_'+id_cont+'-1');
	eval('var lk=cont_l_'+id_cont);	
	eval('var lkmax=contmax_'+id_cont);
	if (lk<0){
		eval('cont_l_'+id_cont+'=contmax_'+id_cont+'-1');
		eval('var lk=contmax_'+id_cont+'-1');
	}	
			
	eval('var foto=cont_'+id_cont+'[lk]');	
	spanik.innerHTML= "<img src='admin/miniatury/"+foto+"' border='0'  style='margin-top:5px;width:150px;margin-bottom:5px;'>";

}
//----------------------------------------------------------
//-----------------------------------------------------------------------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;

	}
}
//------------------------------------------------------------ sprawdzkom
function sprawdzkom(co,celzap){

//alert("ano1");	
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)){	//alert ("ano2");
					var los=(Math.floor(Math.random()*2000));
					TABF=f.action.split('?');
					zap=stwozZapytanie();
					poststr="?"+TABF[1]+encodeURI(zap)+los;
					cel=celzap;
					makePOSTRequest(TABF[0],poststr,2);
	}

return false;
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------------SPRAWDZ MAIL

function sprawdzmail(co){

//alert("ano1");	
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)){	//alert ("ano2");
					//f.submit();
					//alert(f.action);
					var los=(Math.floor(Math.random()*2000));
					TABF=f.action.split('?');
					zap=stwozZapytanie();
					poststr="?"+TABF[1]+encodeURI(zap)+los;
					//alert(TABF[0]+poststr);
					cel="formZapytania";
					makePOSTRequest(TABF[0],poststr,2);
	}

return false;
}
//--------------------------------------------------- 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';
 }
//---------------------------------------------------------------------------------------
//-----------------------------------------------------------------ciasteczka
function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	  {
		  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		  x=x.replace(/^\s+|\s+$/g,"");
		  if (x==c_name)
		    {
		   	 return unescape(y);
		    }
	  }
}


function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value+"; path=/";
}

//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
function doors(idmodel){
					var los=(Math.floor(Math.random()*2000));
					cel="cont_door";
					
					//document.getElementById('cont_door_foto').innerHTML="";
					setCookie('model_drzwi',idmodel,1);
					
					poststr="?wyb=ok&idmodel="+idmodel+"&los="+los;
					makePOSTRequest("phpajax/doors.php",poststr,2);
					document.getElementById("drzwi_miniatury").innerHTML="";
					
					

}

function wlaczHistorie() { advHistory.create(setPage); }

function o(id) { return document.getElementById(id) }

function o1(id) { return o(id + "h") }

var oldPageName = null;
function setPage(pageName) {

            if (oldPageName !== null && oldPageName != "")
                        o1(oldPageName).className = "history";
            if (pageName != "")
                  o1(pageName).className = "hovered";
            oldPageName = pageName; 
            getAdv(pageName);
}

function opis(idmodel,nr){
					var los=(Math.floor(Math.random()*2000));
					
					cel="opis_drzwi";
					poststr="?wyb=ok&idmodel="+idmodel+"&nr="+nr+"&los="+los;
					makePOSTRequest("phpajax/opis.php",poststr,2);
					

}


function firstdoor(idmodel){
					var los=(Math.floor(Math.random()*2000));
					
					//alert('asdas');
					document.getElementById('cont_door_foto').innerHTML="";
					
					cel="cont_door_foto";
					poststr="?wyb=ok&idmodel="+idmodel+"&idtyp=&idkolor=&los="+los;
					makePOSTRequest("phpajax/doors_foto.php",poststr,2);
					

}



function doorsfototyp(idmodel,idtyp,idkolor){
					var los=(Math.floor(Math.random()*2000));
					cel="cont_door_foto";

					//setCookie('kolor_drzwi',idkolor,1);
					setCookie('typ_drzwi',idtyp,1);
					setCookie('model_drzwi',idmodel,1);

					poststr="?wyb=ok&idmodel="+idmodel+"&idtyp="+idtyp+"&idkolor="+idkolor+"&los="+los;
					makePOSTRequest("phpajax/doors_foto.php",poststr,2);

}

function doorsfotokolor(idmodel,idtyp,idkolor){
					var los=(Math.floor(Math.random()*2000));
					cel="cont_door_foto";

					setCookie('kolor_drzwi',idkolor,1);
					setCookie('model_drzwi',idmodel,1);
					//setCookie('typ_drzwi',idtyp,1)

					poststr="?wyb=ok&idmodel="+idmodel+"&idtyp="+idtyp+"&idkolor="+idkolor+"&los="+los;
					makePOSTRequest("phpajax/doors_foto.php",poststr,2);

}
//------------------------------------------------------------------------------- AJAX oscieznice
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'>";}
	  }	
   }
//-----------------------------------------------------------------ciasteczka
function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	  {
		  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		  x=x.replace(/^\s+|\s+$/g,"");
		  if (x==c_name)
		    {
		   	 return unescape(y);
		    }
	  }
}
//-----------------------------------------------------------------------------

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value+"; path=/";
}

//------------------------------------------------------------------oscieznice
function oscieznice(idmodel){
	var los=(Math.floor(Math.random()*2000));
	cel="container_oscieznice";
	setCookie('model_oscieznice',idmodel,1);
	poststr="?wyb=ok&idmodel="+idmodel+"&los="+los;
	makePOSTRequest("phpajax/osc.php",poststr,2);
}

function oscieznicekolor(idmodel,cont,idkolor){
	var los=(Math.floor(Math.random()*2000));
	cel=cont;
	setCookie('kolor_oscieznice',idkolor,1);
	poststr="?wyb=ok&idkolor="+idkolor+"&los="+los;
	makePOSTRequest("phpajax/osckolor.php",poststr,2);

}

function opis_osc(idmodel,nr){
	var los=(Math.floor(Math.random()*2000));
	cel="oscieznice_opis";
	poststr="?wyb=ok&idmodel="+idmodel+"&nr="+nr+"&los="+los;
	makePOSTRequest("phpajax/oscopis.php",poststr,2);
					

}
//---------------------------------------------------------------podswietlanie
var selected_osc=1;

function poswietl_zazn(co,nr)
{	
	selected_osc=nr;
	co.className='opis_przycisk'+nr+'_over';
	for (i=1;i<4;i++){

		if(nr!=i){
			document.getElementById('opis_przycisk'+i).className='opis_przycisk'+i;
		}	
	}

}

function podswietl_p(co,nr){
	
	co.className='opis_przycisk'+nr+'_over';
}

function normal_p(co,nr){

	if(selected_osc!=nr) co.className='opis_przycisk'+nr;
}
//-------------------------------------------------------------------------------
var selected_doors=1;

function poswietl_zazn2(co,nr)
{	
	selected_doors=nr;
	co.className='opis_door_przycisk'+nr+'_over';
	for (i=1;i<4;i++){

		if(nr!=i){
			document.getElementById('opis_door_przycisk'+i).className='opis_door_przycisk'+i;
		}	
	}

}

function podswietl_p2(co,nr){
	
	co.className='opis_door_przycisk'+nr+'_over';
}

function normal_p2(co,nr){

	if(selected_doors!=nr) co.className='opis_door_przycisk'+nr;
}
//------------------------------------------------------------------
//-------------------------dystrybutorzy
function wojewodztwo(idwoj){

	var los=(Math.floor(Math.random()*2000));
	cel="opis_wojewodztwa";
	poststr="?wyb=ok&id_woj="+idwoj+"&los="+los;
	makePOSTRequest("phpajax/woj.php",poststr,2);
				
}
function aps(idaps){

	var los=(Math.floor(Math.random()*2000));
	cel="opis_aps";
	poststr="?wyb=ok&id_aps="+idaps+"&los="+los;
	makePOSTRequest("phpajax/aps.php",poststr,2);
				
}

//------------------------------------------------------------------przesuwne
function przesuwne(idmodel){
	var los=(Math.floor(Math.random()*2000));
	cel="container_przesuwne";
	setCookie('model_przesuwne',idmodel,1);
	poststr="?wyb=ok&idmodel="+idmodel+"&los="+los;
	makePOSTRequest("phpajax/przesuw.php",poststr,2);
}

function przesuwnekolor(idmodel,cont,idkolor){
	var los=(Math.floor(Math.random()*2000));
	cel=cont;
	setCookie('kolor_przesuwne',idkolor,1);
	poststr="?wyb=ok&idkolor="+idkolor+"&los="+los;
	makePOSTRequest("phpajax/przesuwnekolor.php",poststr,2);

}

function opis_przesuwne(idmodel,nr){
	var los=(Math.floor(Math.random()*2000));
	cel="przesuwne_opis";
	poststr="?wyb=ok&idmodel="+idmodel+"&nr="+nr+"&los="+los;
	makePOSTRequest("phpajax/przesuwneopis.php",poststr,2);
					

}
//---------------------------------------------------------------podswietlanie
var selected_przesuwne=1;

function poswietl_zaznSS(co,nr)
{	
	selected_przesuwne=nr;
	co.className='opis_przycisk'+nr+'_over';
	for (i=1;i<4;i++){

		if(nr!=i){
			document.getElementById('opis_przycisk'+i).className='opis_przycisk'+i;
		}	
	}

}

function podswietl_pSS(co,nr){
	
	co.className='opis_przycisk'+nr+'_over';
}

function normal_pSS(co,nr){

	if(selected_przesuwne!=nr) co.className='opis_przycisk'+nr;
}

