	function _geb (id)
	{
		if (!document.getElementById (id))
		return false;
		else
		return document.getElementById (id);
	}

	function Otworz(w,s,nazwa)
	{
		Nowe=null;
		if (Nowe!=null) { Nowe.close(); Nowe=null; }
		Nowe=window.open("" , "","toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,status=no,directories=no,resizable=no,height="+w+",width="+s);
		Nowe.document.write("<HTML><HEAD><title></title></HEAD><BODY  topMargin='0' marginheight='0' marginwidth='0' scrolling='NO' bottommargin='0' leftmargin='0' rightmargin='0'><center><img src='"+ nazwa +"' onclick='window.close()' style='cursor: pointer; border: 1px solid black;' ></center>");
		Nowe.document.write("</BODY></HTML>");
		Nowe.focus();
		Nowe.document.close();
	}

	function check_email(email)
	{

 			//niedozwolone znaki
   			invalid = " /:,;";
		    for(i=0; i < invalid.length; i++) {
		      bad = invalid.charAt(i);
		      if (email.indexOf (bad, 0) != -1) { return false }
		    }

		    //at dwa razy
		    if (email.lastIndexOf("@")!=email.indexOf("@"))
		     return false;

		    //at na pierwszym miejscu lub brak
		    at = email.indexOf("@", 0);
		    if( (at == -1) || (at == 0) )
		     return false;

		    at_str = email.substring((at+1),email.length);

		    //jezeli brak
		    if (at_str=="")
		     return false;

		    //dot na pierwszy miejscu lub brak
		    dot = at_str.indexOf(".", 0);
		    if( (dot == -1) || (dot == 0) )
		     return false;

		    if ((at_str.lastIndexOf(".")+1)==at_str.length)
		     return false;

		    return true;
	}

	function sprawdzFormZam(element)
	{

		for (i=0;i<document.forms[1].elements.length;i++)
		{
			if (document.forms[1].elements[i].name.toString()=="im_i_naz")
			if (document.forms[1].elements[i].value == "")
			{
				alert('Uzupelnij brakujace pola w formularzu typu: Imie i Nazwisko');
				return false;
			}


			if (document.forms[1].elements[i].name.toString()=="email")
			{
				if (document.forms[1].elements[i].value == "")
				{
					alert('Uzupelnij brakujace pola w formularzu typu: Email');
					return false;
				}

				if (!check_email(document.forms[1].elements[i].value))
				{
					alert('Blad danych w polu E-mail');
					return false;
				}
			}


		}
	}

	function sprawdzTA(element)
	{
		if (element.tresc.value.length>2500)
		element.tresc.value = element.tresc.value.substring(0,2500);
	}
	
	function ShowForm()
	{
		if (_geb('ShowForm').style.display == 'none')
		{
			_geb('ShowForm').style.display = 'block';
			_geb('ShowFormLink').innerHTML = 'Ukryj formularz';
		}	
		else
		{
			_geb('ShowForm').style.display = 'none'
			_geb('ShowFormLink').innerHTML = 'Kup / Zapytaj o produkt';
		}	
		
	}
	
	function SendForm()
	{
		advAJAX.submit(document.getElementById('SendForm'),
		{
		    url : 'index.php',
		    parameters : {
	      	"action" :"send_form"
        },
	    onSuccess : function(obj) { eval(obj.responseText); },
    	onError : function(obj) { alert("Error: " + obj.status); },
       	mimeType: 'text/plain'
		});
	}
