var xmlhttp;

function pokazNewsa(liczba)
{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax.php";
	url=url+"?nid="+liczba;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("NEWS_DIV").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return null;
}

function pokazBiznes(liczba)
{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax.php";
	url=url+"?bid="+liczba;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged2;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function stateChanged2()
{
	if (xmlhttp.readyState==4)
	{
		parent.document.getElementById("BIZNES_STRONA").innerHTML=xmlhttp.responseText;
	}
}

function wyslijEmailSTRONA_GLOWNA()
{
	nadawca = document.form1.mail_strona_glowna.value;
	tresc = document.form1.tresc_strona_glowna.value;
	odbiorca = document.form1.home_reciver.value;
	
	if(odbiorca == "")
		odbiorca = ADRES_EMAIL_POLNET;
		
	//alert("nadawca -> " + nadawca + "\ntresc -> " + tresc + "\nodbiorca -> " + odbiorca);
	
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax.php";
	url=url+"?email="+nadawca+"&wiadomosc="+tresc+"&src=home&rec="+odbiorca;
	url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=stateChanged3;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function wyslijEmailPOLNET_CONTACT()
{
	nadawca = document.form4.mail_polnet_contact.value;
	tresc = document.form4.tresc_polnet_contact.value;
	
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax.php";
	url=url+"?email="+nadawca+"&wiadomosc="+tresc+"&src=polnet_contact";
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged4;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function wyslijEmailBIZNES_CONTACT()
{
	nadawca = document.form3.mail_biznes_contact.value;
	tresc = document.form3.tresc_biznes_contact.value;
	odbiorca = document.form3.odbiorca.value;
	
	//alert("nadawca -> " + nadawca + "\ntresc -> " + tresc + "\nodbiorca -> " + odbiorca);
	
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax.php";
	url=url+"?email="+nadawca+"&wiadomosc="+tresc+"&src=biznes_contact&rec="+odbiorca;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged5;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function wyswietlFirme(liczba)
{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax_fade.php";
	url=url+"?num="+liczba;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged7;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged3()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("EMAIL_STRONA_GLOWNA").innerHTML=xmlhttp.responseText;
	}
}

function stateChanged4()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("EMAIL_POLNET_CONTACT").innerHTML=xmlhttp.responseText;
	}
}

function stateChanged5()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("EMAIL_BIZNES_CONTACT").innerHTML=xmlhttp.responseText;
	}
}



function zapiszFormularz()
{
	for(i=0; i < document.form5.zgloszenie.length; i++)
	{
		if(document.form5.zgloszenie[i].checked)
			zgloszenie = document.form5.zgloszenie[i].value;
	}
	
	typ_czlonkostwa = document.form5.typ_czlonkostwa.value;
	nazwa = document.form5.nazwa.value; 
	kontakt = document.form5.kontakt.value; 
	kontakt_telefon = document.form5.kontakt_telefon.value; 
	kontakt_email = document.form5.kontakt_email.value; 
	adres = document.form5.adres.value; 
	telefon = document.form5.telefon.value; 
	email = document.form5.email.value;
	fax = document.form5.fax.value; 
	strona_www = document.form5.strona_www.value; 
	
	if(nazwa == "" || nazwa == " " || kontakt == "" || kontakt == " " || kontakt_telefon == "" || kontakt_telefon == " " || adres == "" || adres == " " || telefon == "" || telefon == " " || email == "" || email == " ")
	{
		alert("Niekompletne dane.\nProsze uzupelnic wszystkie pola z gwiazdka *");
	}
	else
	{
		xmlhttp=GetXmlHttpObject();
		
		if (xmlhttp==null)
		{
		  alert ("Browser does not support HTTP Request");
		  return;
		}
		
		var url="ajax_rejestracja.php";
		url=url+"?zgloszenie="+zgloszenie;
		url=url+"&typ_czlonkostwa="+typ_czlonkostwa;
		url=url+"&nazwa="+nazwa;
		url=url+"&kontakt="+kontakt;
		url=url+"&kontakt_telefon="+kontakt_telefon;
		url=url+"&kontakt_email="+kontakt_email;
		url=url+"&adres="+adres;
		url=url+"&telefon="+telefon;
		url=url+"&email="+email;
		url=url+"&fax="+fax;
		url=url+"&strona_www="+strona_www;
		
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=stateChanged6;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}

}
function stateChanged6()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("potwierdzenie").innerHTML=xmlhttp.responseText;
	}
}

function stateChanged7()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("fade1").innerHTML=xmlhttp.responseText;
	}
}

function zaloguj(user, password)
{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax_login.php";
	url=url+"?user="+user+"&pass="+password;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged9;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged9()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("box_logowanie").innerHTML=xmlhttp.responseText;
	}
}

function wyloguj()
{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	}
	
	var url="ajax_logout.php";
	url=url+"?sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged9;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

