	function autoFill(id){		
		$(id).attr('def_val', $(id).val());
		if ($(id).attr('def_val') !== undefined)
		{
			$(id).val($(id).attr('def_val')).focus(function(){
				if($(this).val()==$(id).attr('def_val')){
					$(this).val('');
				}
			}).blur(function(){
				if($(this).val()==''){
					$(this).val($(id).attr('def_val'));
				}
			});
		}
	}
	
	function anim_partnerzy(repos)
	{
		if (repos == true)
		{
			$("#partnerzy").css('right', -1100);
		}
		
		czas = parseInt(15000*(1100-parseInt($("#partnerzy").css('right')))/1100);
        $("#partnerzy").animate({right: 1100}, czas, "linear", function(){
			anim_partnerzy(true);
		}, false, false);
			
	}
	
	$(function() {
		autoFill($("#search_phrase"));
		autoFill($("#newsletter_mail"));
		
		anim_partnerzy(true);
		
		$("#partnerzy_c").hover(function(){
			$("#partnerzy").stop(true, false);
		}, function(){
			anim_partnerzy(false);
		});
		
	
		$('#rotate_01').cycle({ 
		    fx:      'scrollLeft', 
		    speed:    1200, 
		    timeout:  11000 
		});
		
		//$("ul#subpage_menu li ul").visible();
		
		$("ul#subpage_menu li ul").parent().children('a').click(function(){
			$(this).parent().children('ul').slideToggle('fast');
			return false;
		})
        
	});
	
	function CreateXMLHttp () {

		if (typeof XMLHttpRequest != "undefined")
			return new XMLHttpRequest();
		else {
			if (window.ActiveXObject) {
				var Versions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
				for (var i = 0;i<Versions.length;i++) {
					try {
						var XmlHttp = new ActiveXObject(Versions[i]);
						return XmlHttp;
					} catch (oError) {}
				}
			}
		}
		
		throw new Error ("Zmien przegladarke!");

	}
	
	function SendEmail () {


		var XMLHTTP = CreateXMLHttp ();
		XMLHTTP.open("POST","ajax/sendemail",true);
		XMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		XMLHTTP.onreadystatechange = function () {
			if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) {
				window.alert(XMLHTTP.responseText);
				document.getElementById('newsletter_mail').value='';
			}
		}

		XMLHTTP.send('email='+encodeURIComponent(document.getElementById('newsletter_mail').value));
	}
	
	function SendMessage () {


		var XMLHTTP = CreateXMLHttp ();
		XMLHTTP.open("POST","ajax/sendmessage",true);
		XMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		XMLHTTP.onreadystatechange = function () {
			if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) {
				window.alert(XMLHTTP.responseText);
			}
		}

		XMLHTTP.send('name='+encodeURIComponent(document.getElementById('name').value)+'&surname='+encodeURIComponent(document.getElementById('surname').value)+'&city='+encodeURIComponent(document.getElementById('city').value)+'&email='+encodeURIComponent(document.getElementById('email').value)+'&subject='+encodeURIComponent(document.getElementById('subject').value)+'&body='+encodeURIComponent(document.getElementById('body').value));
	}
	
	function SendProcedure () {
	
		var XMLHTTP = CreateXMLHttp ();
		XMLHTTP.open("POST","ajax/sendprocedure",true);
		XMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		XMLHTTP.onreadystatechange = function () {
			if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) {
				window.alert(XMLHTTP.responseText);
			}
		}
		
		if (document.getElementById('forma1').checked==true)
			var forma = 1;
		else
			var forma = 0;
		
		if (document.getElementById('vat1').checked==true)
			var vat = 1;
		else
			var vat = 0;
		
		XMLHTTP.send('name='+encodeURIComponent(document.getElementById('name').value)+'&surname='+encodeURIComponent(document.getElementById('surname').value)+'&tel='+encodeURIComponent(document.getElementById('tel').value)+'&email='+encodeURIComponent(document.getElementById('email').value)+'&forma='+encodeURIComponent(forma)+'&vat='+encodeURIComponent(vat)+'&firm_name='+encodeURIComponent(document.getElementById('firm_name').value)+'&firm_zip='+encodeURIComponent(document.getElementById('firm_zip').value)+'&firm_city='+encodeURIComponent(document.getElementById('firm_city').value)+'&firm_street='+encodeURIComponent(document.getElementById('firm_street').value)+'&firm_house='+encodeURIComponent(document.getElementById('firm_house').value)+'&vat_name='+encodeURIComponent(document.getElementById('vat_name').value)+'&vat_zip='+encodeURIComponent(document.getElementById('vat_zip').value)+'&vat_city='+encodeURIComponent(document.getElementById('vat_city').value)+'&vat_street='+encodeURIComponent(document.getElementById('vat_street').value)+'&vat_house='+encodeURIComponent(document.getElementById('vat_house').value)+'&vat_nip='+encodeURIComponent(document.getElementById('vat_nip').value)+'&count='+encodeURIComponent(document.getElementById('count').value));
	
	}
	