//JavaScript Document

/// otwieranie okienka na srodki

function popUp(url, width, height) {
//	if(screen.height < height){
  //  	okienko = open(url,"displayWindow",'width=' + (width + 2) + ',height=' + screen.height + ',resizable=0,scrollbars=yes,menubar=no,top=0,left=0');
	//	okienko.moveTo(screen.width/2-width/2, 0)
//	}else{
   	okienko = open(url,"dsdsd",'width=' + (width - 10) + ',height=' + height + ',resizable=0,scrollbars=auto,menubar=no,top=0,left=0');		
		okienko.moveTo(screen.width/2-width/2, screen.height/2-height/2)
//	}//end if
	okienko.focus();
}//end OpenNewWind

function show(divID){
	if (document.getElementById(divID).style.display == 'inline'){
		document.getElementById(divID).style.display = 'none';
	}else{
		document.getElementById(divID).style.display = 'inline';
	}//end if
	return false;
}//end function

function show2(divID){

	//alert(document.getElementById("prev").innerHTML);
	
	if (document.getElementById('reklamacje').style.display == 'inline'){
		document.getElementById('reklamacje').style.display = 'none';
	}//end if
	
	
	
	var tt = document.getElementById("prev").innerHTML;
	
	if(document.getElementById("prev").innerHTML != divID){
	
	if (document.getElementById(tt).style.display == 'inline'){
		document.getElementById(tt).style.display = 'none';
	}//end if
	
	document.getElementById("prev").innerHTML = divID;	
	}//end if
	

	if (document.getElementById(divID).style.display == 'inline'){
		document.getElementById(divID).style.display = 'none';
	}else{
		document.getElementById(divID).style.display = 'inline';
	}//end if
	return false;
}//end function


function validate_rej(f){
	
	
	
	maska = /^[0-9a-z_.-]+@([0-9a-z-]+.)+[a-z]{2,4}$/;
	
	
	if(f.email) {
			
			if (f.email.value == ""){
		  		//alert ("Proszę podać adres e-mail.");
				document.getElementById("uwaga").innerHTML = "Proszę podać adres e-mail!"; 
		  		f.email.focus();
		  		return false;
		  	}else if (maska.test(f.email.value)==false) { 
				document.getElementById("uwaga").innerHTML = "Podaj poprawny adres e-mail!";
				f.email.focus();
		    	return false;
			}//end if

		}
		
		if (f.email_c.value == ""){

				document.getElementById("uwaga").innerHTML = "Proszę podać ponownie adres e-mail!"; 
		  		f.email_c.focus();
		  		return false;
		}else if (f.email.value!=f.email_c.value || f.email_c.value=='' )
			{
				//alert('Hasła są różne lub pole nie zawiera hasła.'); 
				document.getElementById("uwaga").innerHTML = "Podane adresy e-mail różnią się od siebie!";
				f.email_c.focus(); 
				return false;
			}

	
	
		if(!nrnip(f)){
			document.getElementById("uwaga").innerHTML = "Podany numer NIP jest błędny!";
			f.nip.focus(); 
			return false;
		}
	
	
	
	//dane do wysylki
		
		if(!f.firm.value.length) {
		    document.getElementById("uwaga").innerHTML = "Uzupełnij nazwę firmy";
			f.firm.focus()
			return false;
		}
		
		
		if(!f.firstname.value.length) {
		    document.getElementById("uwaga").innerHTML = "Uzupełnij imię";
			f.firstname.focus()
			return false;
		}
		
		if(!f.lastname.value.length) {
		    //alert('Uzupełnij nazwisko w danych do wysyłki');
			document.getElementById("uwaga").innerHTML = "Uzupełnij nazwisko";
			f.lastname.focus()
			return false;
		}
		if(!f.street.value.length) {
		    //alert('Uzupełnij ulice w danych do wysyłki');
			document.getElementById("uwaga").innerHTML = "Uzupełnij ulicę";
			f.street.focus()
			return false;
		}
		if(!f.city.value.length) {
		    //alert('Uzupełnij miasto w danych do wysyłki');
			document.getElementById("uwaga").innerHTML = "Uzupełnij miasto";
			f.city.focus()
			return false;
		}
		if(!f.zip.value.length) {
		    //alert('Uzupełnij kod pocztowy w danych do wysyłki');
			document.getElementById("uwaga").innerHTML = "Uzupełnij kod pocztowy";
			f.zip.focus()
			return false;
		}

		
		if(!blokuj()){
			document.getElementById("uwaga").innerHTML = "Proszę wybrać kartę";
			return false;
		}
		
		
		
		
		
		
		
		// akceptacja regulaminiu
		
		if (f.reg.checked) { 
			var chexok=1;
		}else{
			var chexok=0;
		}//end if

		if (chexok != 1) {
			document.getElementById("uwaga").innerHTML = "Proszę o zaznaczenie pola akceptacji!"; 
			f.reg.focus(); 
			return false; 
		}
		
	
		
		
		// akceptacja przetwarzania danych
		
		if (f.dane.checked) { 
			var chexok=1;
		}else{
			var chexok=0;
		}//end if

		if (chexok != 1) {
			document.getElementById("uwaga").innerHTML = "Proszę o zaznaczenie pola akceptacji!"; 
			f.dane.focus(); 
			return false; 
		}
		
		
		
		return true;
		
	
}//end validate_rej


function nrnip(f) {
  var nip = f.nip.value.replace(/[^0-9]/g,"");
  var suma = 0;
  if (nip.length==10 && nip!=0) {
    var wagi = new Array(6,5,7,2,3,4,5,6,7);
    for (var i=0;i<9;i++) suma += nip.charAt(i)*wagi[i];
    if ((suma%11)%10==nip.charAt(9)) {
      //alert("NIP poprawny");
      return true;
    }
  }
 // alert("NIP błędny, wpisz ponownie");
 // f.nip.value="";
  //f.nip.focus();
  return false;
}

function blokuj() {
  if (document.getElementById("k1").checked) return true;
  if (document.getElementById("k2").checked) return true;
  if (document.getElementById("k3").checked) return true;
  if (document.getElementById("k4").checked) return true;
  if (document.getElementById("k5").checked) return true;
  if (document.getElementById("k6").checked) return true;  
  return false;
}


function zamien() {
	
	var a_imie=document.getElementById("a_imie");
	var imie=document.getElementById("imie");
	if(a_imie.value != ''){
		imie.innerHTML="Witaj <strong><font style='color:#ff9d5b'>"+ a_imie.value +"</font></strong>,";
	}//end if
	
	var n_imie=document.getElementById("n_imie");
	var nadawca=document.getElementById("nadawca");
	if(n_imie.value != 'Anonim'){
		nadawca.innerHTML="<strong><font style='color:#ff9d5b'>"+ n_imie.value +"</font></strong> zostawił dla Ciebie kartkę:,";
	}//end if
	
	var wiadomosc=document.getElementById("wiadomosc");
	var wiadomosc_show=document.getElementById("wiadomosc_show");
	if(wiadomosc.value != ''){
		wiadomosc_show.innerHTML="&quot;"+ wiadomosc.value +"&quot;";
	}//end if
}//end zmien


function set_bg(val){
//	alert(val);
	document.getElementById("kartka_bg").className = val;
}//end sett_bg


function updateform() {
	
	var f_a_imie=document.getElementById("f_a_imie");
	var a_imie=document.getElementById("a_imie");
	a_imie.innerHTML = f_a_imie.value;
	
	var f_n_imie=document.getElementById("f_n_imie");
	var n_imie=document.getElementById("n_imie");
	n_imie.innerHTML = f_n_imie.value;
	
	
	//wiadomosc
	var f_text=document.getElementById("fText");
	var p_text=document.getElementById("wiadomosc");
	p_text.innerHTML = f_text.value;

}//end zmien




function show_anim(url, id){
	var so = new SWFObject(url, "Kartki Flash", "500", "420", "8", ""); so.addParam("menu", "false"); so.addVariable("id", id); so.write("animacja");
}//end show anim


function zaznacz(f) {
    f.focus();
    f.select();
}//end zaznacz 



function setoption(){
	
	if (document.getElementById("adres").checked){
		document.getElementById("a_mail").disabled = true;
		document.getElementById("a_mail").className = "disabled";
		document.getElementById("a_mail").value = "pole niedostępne przy wwbranej opcji";
		document.getElementById("w_adres").innerHTML = "";
		document.getElementById("submit").value = "utwórz kartkę";
	}else if (document.getElementById("wyslij").checked){
		//alert("wyslij");
		document.getElementById("a_mail").disabled = false;
		document.getElementById("a_mail").className = "";
		document.getElementById("a_mail").value = "";
		document.getElementById("w_adres").innerHTML = " *";
		document.getElementById("submit").value = "wyślij kartkę";
		
	}//end if
	
	//getDzwonki();
	
}

function setname(){
	if (document.getElementById("m").checked){
		document.getElementById("zostawil").innerHTML = "zostawił";
	}else if (document.getElementById("k").checked){
		//alert("wyslij");
		document.getElementById("zostawil").innerHTML = "zostawiła";
	}else{
		document.getElementById("zostawil").innerHTML = "zostawił";
	}//end if
}

function focus_input(id) {
	document.getElementById(id).focus();
}