var mouseX,mouseY;

jQuery(document).ready(function(){
   $().mousemove(function(e){
      mouseX = e.pageX;
      mouseY = e.pageY;
   }); 
})

function sendData()
{	
	$("#mail_info").html("<div style='padding:5px;color:gray;'><img src='gfx/loading.gif' style='float:left;margin-right:10px;'/>wysyłanie...<div>");
//alert(document.getElementById('f_tresc').value);
	$.post("ajax/sendMail.php", { 
					mail_imie: document.getElementById('imie').value, 
//					mail_firma: document.getElementById('firma').value, 
//		            mail_nazwisko: document.getElementById('nazwisko').value, 
//		            mail_ulica: document.getElementById('ulica').value, 
//		            mail_miejscowosc: document.getElementById('miejscowosc').value,
//		            mail_kod_pocztowy: document.getElementById('kod_pocztowy').value,
		            mail_email: document.getElementById('email_form').value, 
		            mail_telefon: document.getElementById('telefon').value,
		            mail_temat: document.getElementById('temat').value,
		            mail_tresc: document.getElementById('f_tresc').value },
			  function(data){
//		            	alert(data);
				if (data=="ERROR")
				{
					$("#mail_info").html("<div style='padding:5px'>Proszę wypełnić wszystkie pola wymagane.<div>");
					
				}
				if (data=="OK")
			    {
					$("#mail_info").html("<div style='padding:5px'>Dziękujemy, wiadomość została wysłana!</div>");
//					document.getElementById('firma').value="";
					document.getElementById('imie').value="";
//					document.getElementById('nazwisko').value="";
//					document.getElementById('miejscowosc').value="";
//					document.getElementById('kod_pocztowy').value="";
					document.getElementById('email_form').value="";
					document.getElementById('telefon').value="";
					document.getElementById('temat').value="";
//					document.getElementById('ulica').value="";
					document.getElementById('f_tresc').value=""; 
			    }
				//else 
				//	alert(data);
			  });
}

function sendDataProduktForm()
{	
	$("#mail_info").html("<div style='padding:5px;color:gray;'><img src='gfx/loading.gif' style='float:left;margin-right:10px;'/>wysyłanie...<div>");
	$.post("ajax/sendMailProduktForm.php", { 
					mail_imie: document.getElementById('imie').value, 
		            mail_nazwisko: '',//document.getElementById('nazwisko').value,
		            mail_produkt: document.getElementById('produkt').value, 
		            mail_telefon: document.getElementById('telefon').value,
		            mail_email: document.getElementById('email_form').value, 
		            mail_tresc: document.getElementById('f_tresc').value },
			  function(data){
//		            	alert(data);
				if (data=="ERROR")
				{
					$("#mail_info").html("<div style='padding:5px'>Proszę wypełnić wszystkie pola wymagane.<div>");
					
				}
				if (data=="OK")
			    {
					$("#mail_info").html("<div style='padding:5px'>Dziękujemy, wiadomość została wysłana!</div>");
					document.getElementById('imie').value="";
					document.getElementById('telefon').value="";
					document.getElementById('email_form').value="";
					document.getElementById('f_tresc').value=""; 
			    }

			  });
}

function sendDataRegisterForm()
{
	$("#register_info").html("<div style='padding:5px;color:gray;'><img src='gfx/loading.gif' style='float:left;margin-right:10px;'/>wysyłanie...<div>");
	$.post("ajax/registerUser.php", { 
		knt_podmiotGospodarczy: document.getElementById('knt_podmiotGospodarczy').value,	
		knt_osoba: document.getElementById('knt_osoba').value, 
		knt_adres: document.getElementById('knt_adres').value, 
		knt_kodPocztowy: document.getElementById('knt_kodPocztowy').value, 
		knt_poczta: document.getElementById('knt_poczta').value, 
		knt_miasto: document.getElementById('knt_miasto').value, 
		knt_nazwa: document.getElementById('knt_nazwa').value, 
		knt_nazwa2: document.getElementById('knt_nazwa2').value, 
		knt_nip: document.getElementById('knt_nip').value, 
		knt_telefon: document.getElementById('knt_telefon').value, 
		knt_email: document.getElementById('knt_email').value, 
		knt_www: document.getElementById('knt_www').value, 
		knt_faks: document.getElementById('knt_faks').value, 
		knt_login: document.getElementById('knt_login').value, 
		knt_haslo: document.getElementById('knt_haslo').value, 
		knt_haslo2: document.getElementById('knt_haslo2').value} , 
		function(data){
        	if (data!="OK")
        		$("#register_info").html("<div style='padding:5px;color:red;'>"+data+"<div>");
        	else
        		location.href="sklep-rejestruj-potwierdzenie.html";
		}
		);

}


function comparerAdd(id)
{	
	$.ajax({
		  url: 'ajax/porownywarka.php?action=add&twr_id='+id,
		  success: function(data) {
		    history.go(0);
		  }
		});
}

function comparerRemove(id)
{	
	$.ajax({
		  url: 'ajax/porownywarka.php?action=del&twr_id='+id,
		  success: function(data) {
		    history.go(0);
		  }
		});
}


///////////////////// cart
function cartAdd(id)
{	
	l = Math.floor((screen.width - 400)/2);
	t = Math.floor((screen.height - 90)/2);
	document.getElementById("cartAddedInfo").style.visibility = "visible";
	document.getElementById("cartAddedInfo").style.left = (l)+"px";
	document.getElementById("cartAddedInfo").style.top = (t)+"px";
//	alert('x');
	$.ajax({
		  url: 'ajax/koszyk.php?action=add&twr_id='+id,
		  success: function(data) {
		
			setTimeout("history.go(0);", 1000);
		    
		  }
		});
}

function cartChange(id,am)
{	
	$.ajax({
		  url: 'ajax/koszyk.php?action=change&twr_id='+id+'&ilosc='+am,
		  success: function(data) {
		    history.go(0);
		  }
		});
}

function cartRemove(id)
{	
	$.ajax({
		  url: 'ajax/koszyk.php?action=del&twr_id='+id,
		  success: function(data) {
		    history.go(0);
		  }
		});
}
function clearSearchForm()
{
	document.getElementById('symbol').value='';
	document.getElementById('nazwa').value='';
	document.getElementById('opis').value='';
	document.getElementById('grupa').value='';
	document.getElementById('fraza').value='';
}

function switchSearchForm(v)
{
	if (v==0)
	{
		document.getElementById('produkty').style.display="block";
		document.getElementById('inne').style.display="none";
		
	}
	else
	{
		document.getElementById('produkty').style.display="none";
		document.getElementById('inne').style.display="block";
	}
	//alert(v);
}


function changeFontSize(val, css_area){
	
	if (css_area=='page_content_products')
		css_area='karta_produktu_kontener';
	else
		css_area=css_area;
	
	if (val=="3"){
		$('#'+css_area).css('font-size','16px');
		$('#'+css_area).css('line-height','19px');
	}
	else if (val=="2"){
		$('#'+css_area).css('font-size','14px');
		$('#'+css_area).css('line-height','17px');
	}
	else{
		$('#'+css_area).css('font-size','12px');
		$('#'+css_area).css('line-height','15px');
	}
	
}


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function hideDiv(name)
{
	document.getElementById(name).style.visibility = "hidden";
}

function showComparer()
{
	l = Math.floor((screen.width - 900)/2);
	document.getElementById("comparerWindow").style.visibility = "visible";
	document.getElementById("comparerWindow").style.left = l+"px";
	document.getElementById('comparerWindow').innerHTML=
		"<div class='right' style='height:48px;'><a href=\"javascript:hideDiv('comparerWindow');\">[x]</a></div>"+
		"<iframe width='900' height='450' frameborder='0' src='ajax/porownywarka.php?action=show'>"+		
		"Brak możliwosci prezentacji produktow</iframe>";
}

function enlarge(img)
{
//	alert(img);
//	document.getElementById('picturePreview').style.left
	l = Math.floor((screen.width - 650)/2);
	document.getElementById("big_picture").style.visibility = "visible";
	document.getElementById("big_picture").style.left = l+"px";
//	document.getElementById('big_picture').innerHTML="<div style='cursor:pointer;background-color:#FFFFFF;text-align: center'><img src='"+img+"' onclick='javascript:hideDiv(\"big_picture\")'></div>";
	document.getElementById('big_picture').innerHTML="<div style=\"float: right;\"><img onclick='javascript:hideDiv(\"big_picture\")' src=\"images/lightbox-btn-close.gif\"></div><div style='cursor:pointer;background-color:#FFFFFF;text-align: center'><img src='"+img+"' ></div>";
}


function registerFormChangeMode(mode)
{
	document.getElementById('knt_podmiotGospodarczy').value=mode;
	if (mode==0)
	{
		document.getElementById("line_knt_nazwa").style.display = "none";
		document.getElementById("line_knt_nazwa2").style.display = "none";
		document.getElementById("line_knt_nip").style.display = "none";
	}
	else
	{
		document.getElementById("line_knt_nazwa").style.display = "block";
		document.getElementById("line_knt_nazwa2").style.display = "block";
		document.getElementById("line_knt_nip").style.display = "block";
	}
}


function saveRating(twrId,val)
{	
	$.ajax({
		  url: 'ajax/saveRating.php?twr='+twrId+'&val='+val,
		  success: function(data) {
//		alert(data);
//		    history.go(0);
		  }
		});
}

function SetCookie(cookieName,cookieValue,nDays) {
	 var today = new Date();
	 var expire = new Date();
	 if (nDays==null || nDays==0) nDays=1;
	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = cookieName+"="+escape(cookieValue)
	                 + ";expires="+expire.toGMTString();
	}


function GetCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
