<!--
var p_koszt=0;
var p_prog=0;
function turn(e,name) {
  e.src=name;
 }

 
 
function change_note(note) {
 
 for(i=1;i<=5;i++)
  if(i<=note)
	 document.getElementById('note_'+i).src='http://www.koralland.eu/images/note_on.png';
	else
	 document.getElementById('note_'+i).src='http://www.koralland.eu/images/note_off.png';
 }
 
 
function note(product_id,user_note)  {
	  JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=note&product_id="+product_id+"&note="+user_note+"",
   success: function(status)
	  {
		 if(status==0)
		  {
			 alert("Wystąpił błąd! Ocena nie została uznana");
			}
		 else
		  {
			eval("var dane="+status);
			 document.getElementById('note').innerHTML=''+dane.rr+'/5 (głosów: '+dane.v+')';
			  document.getElementById('note_img').innerHTML='<img src="http://www.koralland.eu/images/GD/note.php?n='+dane.r+'">';
				document.getElementById('note_pool').innerHTML='Dziękujemy za oddanie głosu';
			}
		 
		}
 });
	
	
	}
	
	
function show_shopping_cart(update) {

//JQ('#shopping_cart4').hide();
JQ('#shopping_cart3').show();
if(update==false)
 {
	arrayPageSize=getPageSize();
	
	Element.setHeight('overlay', arrayPageSize[1]);
	
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
	//JQ('#shopping_cart1').fadeIn('slow');	
	
	JQ('#shopping_cart3').fadeIn('slow');	
	JQ('#shopping_cart2').fadeIn('slow');	
	}
	else
	 {
	 
	 JQ('#loading_cart').show();
	 }
	JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=shopping_cart",
   success: function(status)
	  {
		parse_cart(status);
		}
	
 });
		JQ('#loading_cart').hide();
		
	}
function parse_cart(status) {

 eval("koszyk="+status);
 p_koszt=koszyk.p_koszt;
 p_prog=koszyk.p_prog;
		 if(koszyk.c>0)
		  {
			 html='';
			 html+='<br /><table cellspacing=0 style="margin:5px 5px 0 5px"><tr><th style="width:45px">ID</th><th style="width:60px">Foto</th><th style="width:160px;text-align:left">Nazwa produktu</th><th>Ilość</th><th width=55></th><th style="width:80px">Cena za 1 szt.</th><th width=32></th><th>WARTOŚĆ</th><th>Usuń</th><th width=5></th></tr></table><div style="text-align:left;overflow:auto;width:100%;height:163px"><table cellspacing=0  style="margin:0 0 0 5px">';
			 for(i=0;i<koszyk.c;i++) {
			 tekst='<tr class="prod_line"><td style="width:60px;text-align:center;">'+koszyk.p[i].pc+'</td><td style="width:50px"><img src="http://www.koralland.eu/images/foto.png"></td><td style="text-align:left;width:160px">'+koszyk.p[i].n+'</td><td><input type="text" style="text-align:right" size="4" value="'+koszyk.p[i].q+'" onkeyup="update_cart('+koszyk.p[i].id+',this.value,this,\''+(koszyk.code_type?koszyk.code_type:'0')+'\','+(koszyk.code_amount?koszyk.code_amount:'0')+')"  onchange="save_cart(\''+koszyk.p[i].code+'\',this.value)"></td><td style="width:55px"> szt. x</td><td style="width:70px;text-align:right;padding-right:7px;"><span id="cena_'+koszyk.p[i].id+'">'+koszyk.p[i].c+'</span> zł</td><td style="width:20px;text-align:center;">=</td><td style="width:60px;text-align:right;padding-right:7px;font-weight:bold"><span id="cost_'+koszyk.p[i].id+'">'+koszyk.p[i].kc+'</span> zł</td><td style="width:20px;text-align:center"><img src="http://www.koralland.eu/images/del.png" style="cursor:pointer" onClick="delete_product(\''+koszyk.p[i].code+'\')"></td></tr>';
		html+=tekst;
					   }
				 
				 html+='</table></div>';
				 html+='<img src="http://www.koralland.eu/images/hr.png"><br /><div style="padding-right:40px;text-align:right"><table align="right" width=100%><tr><td rowspan="2"  style="padding:15px;text-align:left;">Sposób przesyłki i płatności:<br /><input type="radio" name="przesylka" style="padding-right:15px;border:;background:;" '+(koszyk.prz_w==0?'checked':'')+' id="pobranie" onclick="update_shipping(0);" '+(koszyk.suma_p>=30?'':'disabled')+'><label for="pobranie"> Poczta Polska - polecony priorytet (za pobraniem) - min. 30 zł</label><br><input type="radio" style="padding-right:15px;border:;background:;"  '+(koszyk.prz_w==1?'checked':'')+'  name="przesylka" id="przelew"  onclick="update_shipping(1);"><label for="przelew"> Poczta Polska - polecony priorytet (przedpłata na konto)</label><br><input type="radio" style="padding-right:15px;border:;background:;"  '+(koszyk.prz_w==2?'checked':'')+'  name="przesylka" id="allpay" onclick="update_shipping(2);" ><label for="allpay"> Poczta Polska - polecony priorytet (płatności on-line)</label><br /><br />Kod promocyjny: <input type="text" id="code" size="20" value="'+(koszyk.prom_code?koszyk.prom_code:'')+'"> <input type="button" value="Zapisz" onclick=" save_code() "></td><td style="text-align:right;width:80px;height:20px;">koszt przesyłki</td><td style="text-align:right;width:70px;height:20px;"><span id="prz">'+koszyk.prz+'</span> zł</td></tr><tr><td style="text-align:right;width:80px;height:80px">'+(koszyk.code?'RABAT <br />':'')+'<b>RAZEM </b></td><td style="text-align:right;width:70px;font-weight:bold;height:100px">'+(koszyk.code?koszyk.code+'<br />':'')+'<span id="razem">'+koszyk.s+'</span> zł</td></tr></table></div><br clear="all"/><table cellpadding=5  width="560px"><tr><td style="text-align:left;vertical-align:middle"><a href="javascript:clear_shopping_cart()">wyczyść koszyk</a></td><td style="text-align:right"><img src="http://'+document.location.host+'/images/realizuj_zamowienie.png" onClick="document.location.href=\'http://'+document.location.host+'/zloz-zamowienie.html\'" style="cursor:pointer"></td></tr></table>';
			document.getElementById('cart').innerHTML=html;
			html='';
			tekst='';
			}
			else
			{
				document.getElementById('cart').innerHTML="<br /><br /><br /><br /><br /><br /><b>Brak produktów w koszyku</b>";
			
			}
}	
function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 
function update_cart(product_id,quantity,e,c_t,c_a)   {
 update_cart2(product_id,quantity,e,c_t,c_a);
 }
function update_cart2(product_id,quantity,e,c_t,c_a)  {
if(quantity=='') quantity=0;
 
 if(isInt(quantity))
  {
	 if(quantity<0) quantity=0;
	 
   cena=quantity*parseFloat(document.getElementById('cena_'+product_id).innerHTML.split(',').join('.'));
	 cena=Math.round(cena*100)/100;
    document.getElementById('cost_'+product_id).innerHTML=''+cena;
		document.getElementById('cost_'+product_id).innerHTML=document.getElementById('cost_'+product_id).innerHTML.split('.').join(',');
		
		il=koszyk.p.length;
		var suma=0;
		for(i=0;i<il;i++) {
		if(koszyk.p[i].id==product_id)
		koszyk.p[i].q=quantity;
			suma+=parseFloat(koszyk.p[i].q*koszyk.p[i].c.split(',').join('.'));
			}
			
			
			
			
			 if(c_t=="PERCENT")
			  {
				 suma=suma-(suma*parseInt(c_a))/100;
				}
			else if(c_t=="AMOUNT")
			 {
			 suma=suma-c_a;
			 }
			
			
			var prz=parseInt(p_koszt);
		if(suma>=p_prog)
		 prz=0.00;
		 
		 
		 
		 
		 document.getElementById('prz').innerHTML=prz;
		 document.getElementById('prz').innerHTML=document.getElementById('prz').innerHTML.split('.').join(',');
		 suma+=prz;
		 if(suma-prz<=30) {document.getElementById('pobranie').disabled=true;
		 if(document.getElementById('pobranie').checked==true) document.getElementById('pobranie').checked=false;
		 document.getElementById('przelew').checked=true;
		 }
		 else
		 document.getElementById('pobranie').disabled=false;
		 suma=Math.round(suma*100)/100;
		 document.getElementById('razem').innerHTML=''+suma;
		 document.getElementById('razem').innerHTML=document.getElementById('razem').innerHTML.split('.').join(',');
		 
	}
	else {
	 alert('To nie jest liczba!');
	 e.value='';
	 e.focus;
	 }
	 
	 

}
function save_cart(product_code,quantity)
 {
     JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=edit_product&code="+product_code+"&q="+quantity});
 }
function getPageSize(){
		
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}

	
function close_shopping_cart() {
	
	//new Effect.Appear('overlay', { duration: 0.5, from: 0.8, to: 0.0 });
	JQ('#overlay').fadeOut('slow');
//	new Effect.Appear('shopping_cart2', { duration: 0.5, from: 0.8, to: 0.0 });
	JQ('#shopping_cart2').fadeOut('slow');
	//new Effect.Appear('shopping_cart3', { duration: 0.5, from: 0.8, to: 0.0 });
//	JQ('#shopping_cart3').fadeOut('slow');
	//JQ.unblockUI();
	
	}
	
function add_product(code)	 {
	     JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=add_product&code="+code,
   success: function(data)
	  {
	    eval("var dane="+data);
		  if(dane.status)
			 {
		     JQ('#ProductMsg').empty().append(dane.msg).removeClass().toggleClass('done');
				 show_shopping_cart(false);
			 }
			 else
			 JQ('#ProductMsg').empty().append(dane.msg).removeClass().toggleClass('notdone');
		}
		
 }); 
	
	 }
function delete_product(code) {
	 if(confirm("Czy napewno chcesz usunąć ten produkt?"))
	JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=delete_product&code="+code,
   success: function(data)
	  {
	    eval("var dane="+data);
		  if(dane.status)
			 {
		   show_shopping_cart(true);
			 }
			 else
			 alert("Nie można usunąć produktu - powiadom administratora");
		}
		
 }); 
	
	
	
	
	}
function act(code,hello) {
JQ('#shopping_cart4').show();

	arrayPageSize=getPageSize();
	
	Element.setHeight('overlay', arrayPageSize[1]);

	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
	
	
	
	JQ('#shopping_cart2').fadeIn('slow');	
JQ('#shopping_cart3').hide();
//<iframe src="http://www.onet.pl" frameborder="0" style="width:587px;height:453px;background-color:;" width=587 height=453></iframe>
JQ('#shopping_cart4').show().empty().append('<div style="background-color:white;"><img src="http://www.koralland.eu/images/closelabel.png" style="padding: 5px; cursor: pointer;" onclick="close_shopping_cart()" align="right"><br clear="all"><iframe name="zamowienie" src="http://koralland.eu/index.php?X=order&action=pay&code='+code+'&auth='+hello+'&act=1" frameborder="0" style="width:587px;height:423px;"></iframe></div>');

}
function clear_shopping_cart() {
	 if(confirm("Czy napewno chcesz usunąć wszystkie produkty?"))
	JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=clear_shopping_cart",
   success: function(data)
	  {
	    eval("var dane="+data);
		  if(dane.status)
			 {
		   show_shopping_cart(true);
			 }
			 else
			 alert("Nie można wyczyścić koszyka - powiadom administratora");
		}
		
 }); 
	
	
	
	
	}
function realizuj_zamowienie() {
JQ('#shopping_cart3').hide();
JQ('#shopping_cart4').show().empty().append('<div style="background-color:white;"><img src="http://www.koralland.eu/images/closelabel.png" style="padding: 5px; cursor: pointer;" onclick="close_shopping_cart()" align="right"><br clear="all"><iframe name="zamowienie" src="http://www.koralland.eu/index.php?X=order" frameborder="0" style="width:587px;height:423px;"></iframe></div>');



}

function change_ctype(type) {
 
 if(type==1)
  {
	 JQ('#company_data').slideDown('slow');
	}
	else
	 JQ('#company_data').slideUp('slow');
 }
 
 

function change_tab(from,to){

JQ("#tab"+from).hide();

JQ("#tab"+to).show();

  
 }
 
function save_dane() {
JQ('#MB_wait').fadeIn('slow');
type=(document.getElementById('type_company').checked?0:1);
if(type==1) //firma
 {
		company_name=encodeURIComponent(document.getElementById('customer_company').value);
		company_NIP=encodeURIComponent(document.getElementById('customer_NIP').value);
 
 }
 
 customer_name=encodeURIComponent(document.getElementById('customer_name').value);
 customer_surname=encodeURIComponent(document.getElementById('customer_surname').value);
 address_street=encodeURIComponent(document.getElementById('address_street').value);
 address_no=encodeURIComponent(document.getElementById('address_no').value);
 address_app=encodeURIComponent(document.getElementById('address_app').value);
 address_zipcode=encodeURIComponent(document.getElementById('address_zipcode').value);
 address_city=encodeURIComponent(document.getElementById('address_city').value);
 address_voiv=encodeURIComponent(document.getElementById('address_voiv').value);
 
 
 
 JQ.getJSON('ajax/customer.php?action=save_data&type='+type+(type==1?'&company_name='+company_name+'&company_NIP='+company_NIP:'')+'&customer_name='+customer_name+'&customer_surname='+customer_surname+'&address_street='+address_street+'&address_no='+address_no+'&address_app='+address_app+'&address_zipcode='+address_zipcode+'&address_city='+address_city+'&address_voiv='+address_voiv,function(dane)
  {
	
	if(dane.status==0)
		{
		JQ('#MB_alert_text').empty().append(dane.msg);
		
		JQ('#MB_alert').show();
		JQ('#MB_wait').hide();
		}
	else if(dane.status==-1)
		{
		
		
		JQ('#MB_crash').show();
		JQ('#MB_wait').hide();
		}
	
	else
		{
	
		JQ('#MB_ok').show();
		JQ('#MB_wait').hide();
		}
	});
 
} 


function change_password() {

JQ('#MB_wait').fadeIn('slow');
		old_pass=encodeURIComponent(document.getElementById('old_pass').value);
		new_pass1=encodeURIComponent(document.getElementById('new_pass1').value);
		new_pass2=encodeURIComponent(document.getElementById('new_pass2').value);
 JQ.ajax({
   type: "POST",
   url: "ajax/customer.php?action=change_password",
   data: "old_pass="+old_pass+"&new_pass1="+new_pass1+"&new_pass2="+new_pass2,
   success: function(msg){
	 eval("dane="+msg);
    
	if(dane.status==0)
		{
		JQ('#MB_alert_text').empty().append(dane.msg);
		
		JQ('#MB_alert').show();
		JQ('#MB_wait').hide();
		}
	else if(dane.status==-1)
		{
		
		
		JQ('#MB_crash').show();
		JQ('#MB_wait').hide();
		}
	
	else
		{
	
		JQ('#MB_ok').show();
		JQ('#MB_wait').hide();
		}
	}
   });
 }

 
 
 
 
function change_email() {

JQ('#MB_wait').fadeIn('slow');
		old_mail=encodeURIComponent(document.getElementById('old_mail').value);
		new_mail=document.getElementById('new_mail').value;
		pass=encodeURIComponent(document.getElementById('pass').value);
 JQ.ajax({
   type: "POST",
   url: "ajax/customer.php?action=change_email",
   data: "old_mail="+old_mail+"&new_mail="+new_mail+"&pass="+pass,
   success: function(msg){
	 eval("dane="+msg);
    
	if(dane.status==0)
		{
		JQ('#MB_alert_text').empty().append(dane.msg);
		
		JQ('#MB_alert').show();
		JQ('#MB_wait').hide();
		}
	else if(dane.status==-1)
		{
		
		
		JQ('#MB_crash').show();
		JQ('#MB_wait').hide();
		}
	
	else
		{
	
		JQ('#MB_ok_mail').show();
		JQ('#MB_wait').hide();
		}
	}
   });
 }

function testPassword(passwd) {
		var intScore   = 0;
		var strVerdict = '<span style="color:#cc0000;font-weight:bold;">za krótkie</span>';
		
		if (passwd.length<6) 
			return strVerdict;
		else if (passwd.length<8)	
			intScore = (intScore+6)
		else if (passwd.length<16)
			intScore = (intScore+12)
		else if (passwd.length>15) 
			intScore = (intScore+18)
	
		if (passwd.match(/[a-z]/))
				intScore = (intScore+1)
		if (passwd.match(/[A-Z]/))  
			intScore = (intScore+5)
		if (passwd.match(/\d+/)) 
			intScore = (intScore+5)
	  if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) 
			intScore = (intScore+5)
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))
			intScore = (intScore+5)
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
			intScore = (intScore+5)
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  
			intScore = (intScore+2)
		if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) 
			intScore = (intScore+2)
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
			intScore = (intScore+2)
		if(intScore < 16)
		   strVerdict = '<span style="color:#cc0000;font-weight:bold;">bardzo słabe</span>';
		else if (intScore < 25)
		   strVerdict = '<span style="color:#cc0000;font-weight:bold;">słabe</span>';
		else if ( intScore < 35)
		   strVerdict = '<span style="color:#cccc00;font-weight:bold;">średnie</span>';
		else if (intScore < 45)
		   strVerdict = '<span style="color:#00aa00;font-weight:bold;">mocne</span>';
		else
		   strVerdict = '<span style="color:#00aa00;font-weight:bold;">bardzo mocne</span>';
	
	return strVerdict;
	
	
}

 

function update_shipping(way) {
var prz_w=document.getElementById('prz').innerHTML;
var razem_w=document.getElementById('razem').innerHTML;
JQ('#prz').empty().append('---');
JQ('#razem').empty().append('---');
JQ.getJSON('http://'+document.location.host+'/ajax/product.php?action=set_shipping&way='+way,function(dane) {
	if(dane.status==0)
	 {
	 JQ('#prz').empty().append(prz_w);
	JQ('#razem').empty().append(razem_w);
	 alert(dane.msg);
		return 0;
	 }
	 p_koszt=dane.p_koszt;
 p_prog=dane.p_prog;
	JQ('#prz').empty().append(dane.p);
	JQ('#razem').empty().append(dane.s);
	
});

}
 
 
function save_code() {

var code=document.getElementById('code').value;

 JQ.ajax({
   type: "GET",
   url: "http://"+document.location.host+"/ajax/product.php",
   data: "action=save_code&code="+code,
   success: function(status)
	  {
	
		parse_cart(status);
		}
	
 });
}
function random() {
 		
		
	JQ.getJSON('http://'+document.location.host+'/ajax/product.php?action=random',function(dane) {
		
	if(dane.status==0)
	 {
	 
	 alert(dane.msg);
		return 0;
	 }
	
	 
	 var html='<div class="img" style="text-align:center;"><a href="http://www.koralland.eu/'+dane.product_link+'"><img src="http://www.koralland.eu/zdjecia/miniatury/'+dane.foto+'" style="border:0px" /></a></div><a href="http://www.koralland.eu/'+dane.product_link+'" class="name" style="font-family:Trebuchet MS;font-size:11px;font-weight:400;color:#000000;">'+dane.product+'</span></a>	<br />'+(dane.product_prom_cost==0?'':'<s style="color:black;font-size:10px;color:#000000;">'+dane.product_cost+' zł</s><br />')+'<span class="cost" style="color:red;font-size:12px;color:#FF0000;">'+(dane.product_prom_cost==0?dane.product_cost:dane.product_prom_cost)+' zł</span><br /><br /><div style="text-align:right"><a href="http://www.koralland.eu/'+dane.product_link+'">Zobacz produkt</a>';
	//
	  var ua = window.navigator.userAgent
	 var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )
      {
      
   
        JQ('#random').empty().append(html);
        
       
        }
        else
        {
        	JQ("#random").animate( {opacity: 0}, 1000 );
			     JQ("#random").queue(function () {
        JQ('#random').empty().append(html);
        
        JQ(this).dequeue();
				JQ("#random").animate( {opacity: 1}, 1000 );
		});
		
		}
     
//
     
	window.setTimeout("random()",30000);
});
	
	
}
 //-->
