/*
 * Wszystkie tlumaczenia do komunikatow znajduja sie w: 3line/application/i18n/$lang/registration.php
 */

var registration;

window.addEvent ("domready", function () {
	registration = new Registration();	
})

function init_messages (lang) {
	//ustaw opcje jezykowe, przekazuje format JSON
	registration.setLanguage(lang);
}

function init_focus () {
	$('registration').getElements('.input_text').each (function (item, i) {
		item.addEvent('focus', function () {
			this.setProperty('class', 'input_text_hover');
		})
		item.addEvent('blur', function () {
			this.setProperty('class', 'input_text');
		})		
	});
	
	registration.setSlide ();
}

var Registration = new Class ({
	overallOpacity: 0.7,
	interval: new Array (),
	

	
	initialize: function () {
		this.offert_first_open = true;
		this.slidingIn = false;
		this.slidingOut = false;
		this.value = 0;
		
		this.krs_val = 0;
		this.krs_slidingIn = false;
		this.krs_slidingOut = false;			
			
		this.overlay = new Overlay ({ /* from overlay.js */
			height: 1150, 
			cover_h: 2500
		})

	},
	
	openRegistration: function (action) {

		var dark_cover = $('dark_cover');

		this.overlay.show();
		this.overlay.showContent =  function () {
			request_showRegistration (this.overlay, action);
		}.bind(this);

	},
	
	closeRegistration: function () {
		this.overlay.hide();
	},
	
	init_slide: function (offert_maker,client_type) {
		this.edit = true;
		if (offert_maker) {
			if (!this.slidingIn) {
				this.slide_oferty.onStart = function(){
					this.slidingIn = true;
					this.slidingOut = false;
				}.bind(this);
				this.slide_oferty.onComplete = function(){
					this.slidingIn = false;
					if (client_type) {
						//jesli animacja wysuwania dodatowych opcji jest w toku to nic nie rob
						if (!this.krs_slidingIn) {
							this.slide_krs.onStart = function(){
								this.krs_slidingIn = true;
								this.krs_slidingOut = false;
							}.bind(this);
							this.slide_krs.onComplete = function(){
								this.krs_slidingIn = false;
							}.bind(this)
		
							//wysun dodatkowe opcje (krs, wysokosc kapitalu, spolka)
							this.slide_krs.cancel();
							this.slide_krs.slideIn();
		
							this.oferty_h = this.oferty_h + this.krs_h;
		
							//zwieksz wysokosc paneleu w ktorym znajduja sie dodatkowe opcje o wysokosc jaką posiada kontener dodatkowych opcji\
		
							$('oferty_cont').getParent().tween('height', this.oferty_h)
							//zwieksz wysokosci glownego bialego kontenera w ktorym jest panel rejestracji
		
							this.overlay.resize(this.krs_h)
							this.krs_val = 1;
						}
					}					
				}.bind(this)
				
				// wysun dodatkowe opcje jesli uzytkownik zaznaczy, ze chce robic oferty						
				this.slide_oferty.slideIn();
				//zwieksz wysokosci glownego bialego kontenera w ktorym jest panel rejestracji
				this.overlay.resize($('oferty_cont').getStyle('height').toInt())
				this.value = 1;
			}
		}		


		

	},
	
	setLanguage: function (lang) {
		this.lang = lang;	
	},
	
	setSlide: function () {
	/*
	 *  Przygoruj rozwijanie dodatkowych opcji ofert
	*/
		this.slide_oferty = new Fx.Slide('oferty_cont', {			
			duration: 1000,			
			transition: Fx.Transitions.Cubic.easeOut,
			link: 'cancel'
		})
		this.slide_oferty.hide();
		
		this.slide_krs = new Fx.Slide ('krs_cont',{
			duration: 1000,
			transition: Fx.Transitions.Cubic.easeOut,
			link: 'cancel'			
		})
		
		this.tween_oferty = new Fx.Tween ($('oferty_cont').getParent(), {
			duration: 250,
			transition: Fx.Transitions.Cubic.easeOut,
			link: 'cancel'	
		})
		
		this.tween_krs = new Fx.Tween ($('krs_cont').getParent(), {
			duration: 250,
			transition: Fx.Transitions.Cubic.easeOut,
			link: 'cancel'	
		})		
	
		
		this.slide_krs.hide();	
		this.oferty_h = $('oferty_cont').getStyle('height').toInt()	
		this.krs_h = $('krs_cont').getStyle('height').toInt()	

	},
	
	validate: function (value, id) {
		value = value.trim();
	
		switch (id) {		
			
			  /* LOGIN */
		      case "login" :
		         if (this.validate_login (value, 1)) {
					if (this.validate_login (value, 2)) {
		               this.showOk (id);
		               return true; 
					} else { 
		                this.showError (id, this.lang.login2);
		                return false;						
					}
				} else {
		            this.showError (id, this.lang.login1);
		            return false;  					
				}

		         break;
				 
			  /* HASLO */				 
		      case "pass":
		         if (value != "") {
		            if (!this.check_password (value)) {
		               messageError = "Hasło musi zawierać min 5, a max 64 znaki"; 
		               this.showError (id, this.lang.password1);
		               return false;
		            } else {
		               this.showOk (id);
		               return true;         
		            }
		         } else {
		            this.clearMessage (id);
		            return true;
		         }
		         break;		
				 
			 /* POTWIERDZENIE HASLA */
		      case "confirmPass":
		         value2 = document.getElementById("pass").value;
		         if (value != "" || value2 != "") {     
		            if (this.check_confirm_password (value)) {
		                              
		               if (value == value2) { //czy hasla pasuja do siebie  
		                  this.showOk (id);
		                  return true;
		               } else {
		                  this.showError (id, this.lang.confirm_password1);
		                  return false;
		               }
		            } else {
		               this.showError (id, this.lang.password1);
		               return false;          
		            }
		         } else {
		            this.clearMessage (id);
		            return true;
		         }
		         break;		
			
			/* IMIE I NAZWISKO */		 
		      case "name" :
	             if (this.check_name (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.name1);
	                return false;
		         }

		         break;			
			
			/* EMAIL */		 
		      case "email" :
	             if (this.check_email (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.email1);
	                return false;
		         }

		         break;					
			
			/* NAZWA FIRMY */		 
		      case "company" :
	             if (this.check_company (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.company1);
	                return false;
		         }

		         break;
			
			/* ULICA */ 
		      case "street" :
	             if (this.check_street (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.street1);
	                return false;
		         }

		         break;				 
		
			/* LOKAL */ 
		      case "lokal" :
	             if (this.check_lokal (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.lokal1);
	                return false;
		         }

		         break;
				 
			/* MIASTO */ 
		      case "miasto" :

		         if (this.check_miasto (value, 1)) {
		            if (this.check_miasto (value, 2)) {
		               this.showOk (id);
		               return true;
		            } else {
		               messageError = "Nazwa miejscowości może zawierać tylko znaki alfabetyczne"; 
		               this.showError (id, this.lang.miasto1);
		               return false;
		            }
		         } else {  
		            messageError = "Nazwa miejscowości musi zawierać min 2, a max 64 znaki"; 
		            this.showError (id, this.lang.miasto2);
		            return false;       
		         }

		         break;	
				 
			/* ZIP */ 
		      case "poczta" :
	             if (this.check_zip (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.zip1);
	                return false;
		         }

		         break;	
				 
			/* NIP */ 
		      case "nip" :
	             if (this.check_nip (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.nip1);
	                return false;
		         }

		         break;		
				 
			/* Telefon Firmowy */ 
		      case "phone1" :
	             if (this.check_phone (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.phone1);
	                return false;
		         }

		         break;		
				 
			/* Stanowisko */ 
		      case "job" :
	             if (this.check_position (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.position1);
	                return false;
		         }

		         break;					 			 			 				 				 					  		 		 			
				 
			/* Telefon 2 */ 
		      case "phone2" :
	             if (this.check_phone (value)) {
	                this.showOk (id);
	                return true;
	             } else {
	                this.showError (id, this.lang.phone1);
	                return false;
		         }

		         break;	
				 
				 
			/* NAZWA FIRMY */		 
		      case "company2" :
	             if (this.check_company (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.company1, true);
	                return false;
		         }

		         break;
			
			/* ULICA */ 
		      case "street2" :
	             if (this.check_street (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.street1, true);
	                return false;
		         }

		         break;				 
		
			/* LOKAL */ 
		      case "lokal2" :
	             if (this.check_lokal (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.lokal1, true);
	                return false;
		         }

		         break;
				 
			/* MIASTO */ 
		      case "miasto2" :

		         if (this.check_miasto (value, 1)) {
		            if (this.check_miasto (value, 2)) {
		               this.showOk (id, true);
		               return true;
		            } else {
		               messageError = "Nazwa miejscowości może zawierać tylko znaki alfabetyczne"; 
		               this.showError (id, this.lang.miasto1, true);
		               return false;
		            }
		         } else {  
		            messageError = "Nazwa miejscowości musi zawierać min 2, a max 64 znaki"; 
		            this.showError (id, this.lang.miasto2, true);
		            return false;       
		         }

		         break;	
				 
			/* ZIP */ 
		      case "poczta2" :
	             if (this.check_zip (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.zip1, true);
	                return false;
		         }

		         break;	
				 
			/* NIP */ 
		      case "nip2" :
	             if (this.check_nip (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.nip1, true);
	                return false;
		         }

		         break;		
				 
			/* Telefon Firmowy */ 
		      case "phone3" :
	             if (this.check_phone (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.phone1, true);
	                return false;
		         }

		         break;
				 
			/* REGON */ 
		      case "regon" :
	             if (this.check_regon (value)) {
	                this.showOk (id, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.regon1, true);
	                return false;
		         }

		         break;				 
				 
			/* KRS */ 
		      case "krs" :
	             if (this.check_krs (value)) {
	                this.showOk (id, true, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.krs1, true, true);
	                return false;
		         }

		         break;		
				 
			/* KAPITAL */ 
		      case "kapital" :
	             if (this.check_kapital (value)) {
	                this.showOk (id, true, true);
	                return true;
	             } else {
	                this.showError (id, this.lang.kapital1, true, true);
	                return false;
		         }

		         break;		
				 
			/* ORGAN REJESTRUJACY */ 
		      case "organ" :
	             if (this.check_organ (value)) {
	                this.showOk (id, true,true);
	                return true;
	             } else {
	                this.showError (id, this.lang.organ1, true, true);
	                return false;
		         }

		         break;		
				 
			/* LOGO FIRMY */ 
		      case "logo" :
	             if (this.check_logo (value)) {
	                this.showOk (id, true,true);
	                return true;
	             } else {
	                this.showError (id, this.lang.logo1, true, true);
	                return false;
		         }

		         break;	
				 				 					 				 				 		 				 					 
		}
	},
	
//--------------- FUNKCJE SPRAWDZAJACE --------------------//
//---------------------------------------------------------//
	validate_login: function (value, nrTestu) {
	// znaki od a-z oraz od A - Z wystepujace prznajmniej 3 razy, ale nie wiecej niz 32 razy
	   if (nrTestu == 1) { //na dlugosc ciagu
	      var regExp = /^(?:.){3,32}$/;
		  return regExp.test (value);
	   } else {
	   	  var res;
	      new Request.JSON ({
		  	url: 'user/check_login/',
			method: 'post',
			async: false,
			onComplete: function (r, response) {
				res = response;
			}
		  }).send ('&login='+encodeURI(value))

		  if (res == "0") {
		  	return true;
		  } else {
		  	return false;
		  }
	   }
	   
	},
	
	check_password: function (value) {
	// wszystkie znaki za wyjatkiem bialych znakow wystepujace przynajmniej 5 razy i nie wiecej niz 64
	   var regExp = /^(?:.){5,64}$/
	   return (regExp.test(value));
	},	
	
	check_confirm_password: function (value) {
	// wszystkie znaki za wyjatkiem bialy znakow wystepujace przynajmniej 5 razy i nie wiecej niz 64
	   var regExp = /^(?:.){5,64}$/
	   return (regExp.test(value));
	},	
	
	check_name: function (value) {
	   var regExp = /^[a-zA-ZąęóśłżźćńĄĘÓŚŁŻŹĆŃ]{2,30}\s+[a-zA-ZąęóśłżźćńĄĘÓŚŁŻŹĆŃ\-\s]+$/;
	   return (regExp.test(value));
	},	
	
	check_company: function (value) {
		// wszystkie znaki wystepujace przynajmniej 3 razy i nie wiecej niz 64		
	    var regExp = /^(?:.){3,32}$/;
 	    return regExp.test (value);
	},
	
	check_street: function (value) {
		// wszystkie znaki wystepujace przynajmniej 3 razy i nie wiecej niz 100		
	    var regExp = /^(?:.){3,32}$/;
 	    return regExp.test (value);
	},			
	
	check_lokal: function (value) {
	    var regExp = /^(?:.)+$/;
 	    return regExp.test (value);
	},		
	
	check_miasto: function (value, nrTestu) {
	   if (nrTestu == 1) { //na dlugosc ciagu
	      var regExp = /^(?:.){3,64}$/;
	   } else {
	      var regExp = /^[a-zA-ZąęóśłżźćńĄĘÓŚŁŻŹĆŃ\-\s]{3,64}$/; // kazda litera
	   }
	   return (regExp.test(value));		
	},
	
	check_zip: function (value) {
	   var regExp = /^[\w\-\\]{3,10}$/; //w formacie xx-xxx
	   return (regExp.test(value));
	},
	
	check_nip: function (value) {
	   var regExp = /^[\d]{10}$/; 
	   var regExp2 = /^\d{3}-\d{3}-\d{2}-\d{2}$/;
	   
	   return (regExp.test(value) || regExp2.test(value));		
	},
		
	check_phone: function (value) {
	   var regExp = /^(?:.)+$/;
	   return (regExp.test(value));
	},
	
	check_email: function (value) {
	   var regExp = /^(?:[ąęóśłżźćńĄĘÓŚŁŻŹĆŃ\-\w+]\.?)*[ąęóśłżźćńĄĘÓŚŁŻŹĆŃ\w+]@(?:.+\.)+\w+$/;
	   return (regExp.test(value));
	},	
	
	check_position: function (value) {
		//sprawdz czy jest nie puste
	    var regExp = /^(?:.)+$/;
 	    return regExp.test (value);
	},	
	
	check_krs: function (value) {
		//sprawdz czy ciag jest nie pusty	
	    var regExp = /^(?:.)+$/;
 	    return regExp.test (value);
	},			
	
	check_kapital: function (value) {
		//sprawdz czy ciag jest nie pusty	
	    var regExp = /^(?:.)+$/;
 	    return regExp.test (value);
	},			
	
	check_organ: function (value) {
		//sprawdz czy ciag jest nie pusty	
	    var regExp = /^(?:.)+$/;
 	    return regExp.test (value);
	},		
	
	check_regon: function (value) {
	   var regExp = /^[\d-\s]{7,20}$/; 
	   
	   return (regExp.test(value));		
	},	
	
	check_logo: function (value) {
		var regExp = /^.+\.(jpg|gif|png)$/;

	   return (regExp.test(value));				
	},
	
		
	//--------------- FUNKCJA SHOW NOK ------------------------//
	//---------------------------------------------------------//
	// Wyswietla blad, Kiedy uzytkownik wprwadzi bledne dane   //
	//---------------------------------------------------------//
	 showError: function  (id, message, oferty, krs) {
	/* Wyswietl komunikat o bledzie */
	   idError = id + "Error";
	   elementErr = document.getElementById (idError);
		
		
	   if (elementErr.className != 'error') {
	   	 this.overlay.resize (32)
		 
		 if (oferty) {
		 	this.oferty_h = this.oferty_h + 33
		 	this.tween_oferty.start('height', this.oferty_h);
		 }
	     if (krs) {
    	   	  this.krs_h = this.krs_h + 33
	        this.tween_krs.start('height', this.krs_h);		   	
	     }		 
	   }

	   elementErr.className = "error";
	   elementErr.style.height = elementErr.style.height;


	   this.interval[idError] =  setInterval("registration.slideOn('" + idError + "','" + message + "')", 5);


	/* zmien kolor obramowania pola input */
	   var element = document.getElementById (id);
	   element.style.borderColor = "#C80404";
	   
	/* Wyswietlamy czerwony znaczek NOK */
	   idImg = id + "Image";
	   
	   var elementImg = document.getElementById (idImg);
	   elementImg.innerHTML = '<img src="media/img/nok.gif" alt=""/>';
	   
	},


	//--------------- FUNKCJA SHOW OK -------------------------//
	//---------------------------------------------------------//
	// Po prawidlowym zweryfikowaniu danych funkcja wyswietla  //
	// znaczek OK oraz ustawia kolor obramowania na zielony    //
	//---------------------------------------------------------//
	 showOk: function (id, oferty, krs) {
	/* Wyswietl komunikat o bledzie */
	   idError = id + "Error";
	   var elementErr = document.getElementById (idError);
	   
	   elementErr.innerHTML = "";
	   this.interval[idError] =  setInterval("registration.slideOff('" + idError + "','" + message + "')", 5);
	
	/* Zmieniamy obramowanie na zielone */
	   var element = document.getElementById (id);
	   element.style.borderColor = "#00BB00";
	   
	/* Wyswietlamy zielony znaczek OK */
	   idImg = id + "Image";
	   var elementImg = document.getElementById (idImg);
	   elementImg.innerHTML = '<img src="media/img/ok.gif" alt=""/>';
	   
	   if (elementErr.className == 'error') {
	   	   this.overlay.resize(-32)
			
		   if (oferty) {
		   	  this.oferty_h = this.oferty_h - 33
		      this.tween_oferty.start('height', this.oferty_h);
		   }
		   if (krs) {
		   	  this.krs_h = this.krs_h - 33
		      this.tween_krs.start('height', this.krs_h);		   	
		   }
	   }
	},


	//--------------- FUNKCJA CLEAR MESSAGE -------------------//
	//---------------------------------------------------------//
	// W przypadku gdy pole nie jest wymagane funkcja ukrywa   //
	// informacje o bledzie lub o prawidlowych danych          //
	//---------------------------------------------------------//
	clearMessage: function  (id, oferty, krs) {
	   /* Wyswietl komunikat o bledzie */
	   idError = id + "Error";
	   var elementErr = document.getElementById (idError);
	   
	   elementErr.innerHTML = "";

	   this.interval[idError] =  setInterval("registration.slideOff('" + idError + "','" + message + "')", 5);
	
	/* Zmieniamy obramowanie na normalny kolor*/
	   var element = document.getElementById (id);
	   element.style.borderColor = "#CEC5BE";
	   
	/* Wyswietlamy zielony znaczek OK */
	   idImg = id + "Image";
	   var elementImg = document.getElementById (idImg);
	   elementImg.innerHTML = '';
	   
	   if (elementErr.className == 'error') {
	   	   this.overlay.resize(-32)
		  
		   if (oferty) {
		  	 this.oferty_h = this.oferty_h - 33
		  	 this.tween_oferty.start('height', this.oferty_h);
		   }
	       if (krs) {
		   	  this.krs_h = this.krs_h - 33
	          this.tween_krs.start('height', this.krs_h);		   	
	       }				   
	   }		   
	  
	},


	//------------ FUNKCJA SLIDE ON ---------------------------//
	//---------------------------------------------------------//
	// Funkcja animuje pojawienie sie ramki z informacja       //
	//---------------------------------------------------------//
	slideOn: function  (element, message) {
	   elementErr = document.getElementById (element);
	   h = elementErr.style.height;
	   var regExp = /\d*/;
	   h = h.match(regExp)
	  
	   if (h >= 20) {
	      elementErr.innerHTML = message;
	      clearInterval (this.interval[element]);
		  
	   } else {
	   h++;
	   h++;
	   h++;
	   elementErr.style.height = h + "px";
	   }
	},


	//------------ METODA SLIDE OFF ---------------------------//
	//----------------------------------------------------------//
	// Funkcja animuje ukrycie ramki z informacja               //
	//----------------------------------------------------------//
	slideOff: function (element) {
	   var elementErr = document.getElementById (element);
	   h = elementErr.style.height;
	   var regExp = /\d*/;
	   h = h.match(regExp)
	   h -= 3;

	   if (h < 0) {
	      h = 0;
	   }

	   elementErr.style.height = h + "px";
	   if (h <= 0) {
	   			   
	      elementErr.className = "hidden";
	      clearInterval (this.interval[element]);
	   }
	},
	
	check_oswiadczenie: function (value) {
		if (value.checked) {
			$('wyslij_btn').setProperty('class', 'button_en');	
			$('wyslij_btn').disabled = false;	
		} else {
			$('wyslij_btn').setProperty('class', 'button_dis');
			$('wyslij_btn').disabled = true;							
		}
	},
	
	czy_oferty: function (value) {
		

		if (this.offert_first_open && !this.edit) {
			this.offert_first_open = false;
			$('company2').value = $('company').value;
			$('street2').value = $('street').value;			
			$('lokal2').value = $('lokal').value;						
			$('miasto2').value = $('miasto').value;									
			$('poczta2').value = $('poczta').value;												
			$('nip2').value = $('nip').value;
			$('phone3').value = $('phone1').value;																																
			
			//---------- COMPANY NAME2 -------------//   
			var val = $("company2").value;
			if (val != '') {
				this.validate(val, "company2");
			}

			
			//---------- STREET2 -------------//   
			var val = $("street2").value;
			if (val != '') {
				this.validate(val, "street2");
			}
			
			//---------- LOKAL2 -------------//   
			var val = $("lokal2").value;
			if (val != '') {			
				this.validate(val, "lokal2")
			}
			
			//---------- MIASTO2 -------------//
			var val = $("miasto2").value;			   
			if (val != '') {
				this.validate(val, "miasto2");
			}
			
			//---------- POCZTA2 -------------//   
			var val = $("poczta2").value;
			if (val != '') {			
				this.validate(val, "poczta2");
			}
			
			//---------- NIP2 -------------//   
			var val = $("nip2").value;
			if (val != '') {			
				this.validate(val, "nip2")
			}
			
		    //---------- TELEFON3  -------------//   
		    var val = $("phone3").value;
 		    if (val != '') {		   
		   		this.validate (val, "phone3")
		    }
		}
	
		
		if (value != this.value) {
			this.value = value;
			if (value) {
				if (!this.slidingIn) {
					this.slide_oferty.onStart = function(){
						this.slidingIn = true;
						this.slidingOut = false;
					}.bind(this);
					this.slide_oferty.onComplete = function(){
						this.slidingIn = false;
					}.bind(this)
					
					// wysun dodatkowe opcje jesli uzytkownik zaznaczy, ze chce robic oferty						
					this.slide_oferty.slideIn();
					//zwieksz wysokosci glownego bialego kontenera w ktorym jest panel rejestracji
					this.overlay.resize($('oferty_cont').getStyle('height').toInt())
				}
			}
			else {

				if (!this.slidingOut) {
					this.slide_oferty.onStart = function(){
						this.slidingIn = false;
						this.slidingOut = true;
					}.bind(this);
					this.slide_oferty.onComplete = function(){
						this.slidingOut = false;
					}.bind(this)					
					
					// schow dodatkowe opcje jesli uzytkownik zaznaczy, ze nie chce robic ofert	
					this.slide_oferty.slideOut();
					//zmniejszy plynnnie wysokosc glonego bialego kontenera w ktorym miesci sie cala rejestraca, z powodu pozycjonowania absolutnego
					this.overlay.resize(-$('oferty_cont').getStyle('height').toInt())					
				}

			}
		}
	},
	
	
	czy_spolka: function (value) {

		if (value != this.krs_val) {
			this.krs_val = value
			if (value) {
				//jesli animacja wysuwania dodatowych opcji jest w toku to nic nie rob
				if (!this.krs_slidingIn) {
					this.slide_krs.onStart = function(){
						this.krs_slidingIn = true;
						this.krs_slidingOut = false;
					}.bind(this);
					this.slide_krs.onComplete = function(){
						this.krs_slidingIn = false;
					}.bind(this)
					
				//wysun dodatkowe opcje (krs, wysokosc kapitalu, spolka)
					this.slide_krs.slideIn();

					this.oferty_h = this.oferty_h + this.krs_h;

				//zwieksz wysokosc paneleu w ktorym znajduja sie dodatkowe opcje o wysokosc jaką posiada kontener dodatkowych opcji
					$('oferty_cont').getParent().tween('height', this.oferty_h)
				//zwieksz wysokosci glownego bialego kontenera w ktorym jest panel rejestracji
					this.overlay.resize(this.krs_h)
				}
			}
			else {
				//jesli animacja chowania jest uruchomiona to nie uruchamiaj drugi raz
				if (!this.slidingOut) {
					this.slide_krs.onStart = function(){
						this.krs_slidingIn = false;
						this.krs_slidingOut = true;
					}.bind(this);
					this.slide_krs.onComplete = function(){
						this.krs_slidingOut = false;
					}.bind(this)					

				//schowaj panel z opcjami krs, wysokosc kapitalu
					this.slide_krs.slideOut();	
				//zmniejsz plynnie wysokosc kontenera w ktorym jest panel z krs itp (poniewz pozycjonowanie absolutne trzeba recznie to robic			
					this.oferty_h = this.oferty_h - this.krs_h

					$('oferty_cont').getParent().tween('height',this.oferty_h)					
				//zmniejszy plynnnie wysokosc glonego bialego kontenera w ktorym miesci sie cala rejestraca, z powodu pozycjonowania absolutnego
					this.overlay.resize(-this.krs_h)					
				}

			}
		}
	},
	
	/*
	 *  Metody wywolywana po kliknieciu na przycisk "wyslij formularz". Sprawdzenie wszystkich pol w poszukiwaniu bledow
	 */
	validateAll: function (action) {
	   var validResult = true;
	  

	   //---------- LOGIN -------------//   
	   var login = $("login").value;
	   if (!this.validate (login, "login")) {
	       validResult = false;
	   }		
	   
	   //---------- HASLO -------------//   
	   var pass = $("pass").value;
	   if (!this.validate (pass, "pass")) {
	       validResult = false;
	   }		   
	   
	   //---------- CONFIRM HASLO -------------//   
	   var pass = $("confirmPass").value;
	   if (!this.validate (pass, "confirmPass")) {
	       validResult = false;
	   }		  	   
	  
	   //---------- NAME -------------//   
	   var val = $("name").value;
	   if (!this.validate (val, "name")) {
	       validResult = false;
	   }		  
	  
	   //---------- EMAIL -------------//   
	   var val = $("email").value;
	   if (!this.validate (val, "email")) {
	       validResult = false;
	   }	 

	   //---------- COMPANY NAME -------------//   
	   var val = $("company").value;
	   if (!this.validate (val, "company")) {
	       validResult = false;
	   }		   
	   
	   //---------- STREET -------------//   
	   var val = $("street").value;
	   if (!this.validate (val, "street")) {
	       validResult = false;
	   }		
	   
	   //---------- LOKAL -------------//   
	   var val = $("lokal").value;
	   if (!this.validate (val, "lokal")) {
	       validResult = false;
	   }		
	   
	   //---------- MIASTO -------------//   
	   var val = $("miasto").value;
	   if (!this.validate (val, "miasto")) {
	       validResult = false;
	   }	
	   
	   //---------- POCZTA -------------//   
	   var val = $("poczta").value;
	   if (!this.validate (val, "poczta")) {
	       validResult = false;
	   }			   		   	   	   

	   //---------- NIP -------------//   
	   var val = $("nip").value;
	   if (!this.validate (val, "nip")) {
	       validResult = false;
	   }			   		   	   	   	   

	   //---------- TELEFON -------------//   
	   var val = $("phone1").value;
	   if (!this.validate (val, "phone1")) {
	       validResult = false;
	   }			   		   	   	
	     	 
	   //---------- STANOWISKO -------------//   
	   var val = $("job").value;
	   if (!this.validate (val, "job")) {
	       validResult = false;
	   }
	   
	   //---------- TELEFON2 -------------//   
	   var val = $("phone2").value;
	   if (!this.validate (val, "phone2")) {
	       validResult = false;
	   }		   
		
		
		// jesli uzytkownik nie zaznaczyl ze chce robic oferty to nie waliduj tego	   
	    /*var radio1 = $('r1').checked
	   
		if (radio1) {
			//---------- COMPANY NAME2 -------------//   
			var val = $("company2").value;
			if (!this.validate(val, "company2")) {
				validResult = false;
			}
			
			//---------- STREET2 -------------//   
			var val = $("street2").value;
			if (!this.validate(val, "street2")) {
				validResult = false;
			}
			
			//---------- LOKAL2 -------------//   
			var val = $("lokal2").value;
			if (!this.validate(val, "lokal2")) {
				validResult = false;
			}
			
			//---------- MIASTO2 -------------//   
			var val = $("miasto2").value;
			if (!this.validate(val, "miasto2")) {
				validResult = false;
			}
			
			//---------- POCZTA2 -------------//   
			var val = $("poczta2").value;
			if (!this.validate(val, "poczta2")) {
				validResult = false;
			}
			
			//---------- NIP2 -------------//   
			var val = $("nip2").value;
			if (!this.validate(val, "nip2")) {
				validResult = false;
			}
			
		   //---------- TELEFON3  -------------//   
		   var val = $("phone3").value;
		   if (!this.validate (val, "phone3")) {
		       validResult = false;
		   }				
		}		
		
		// jesli uzytkownik nie zaznaczyl ze nalezy do spolki to nie waliduj  
	    var radio2 = $('r4').checked
	   
		if (radio1 && radio2) {
			//---------- COMPANY NAME2 -------------//   
			var val = $("krs").value;
			if (!this.validate(val, "krs")) {
				validResult = false;
			}
			
			//---------- STREET2 -------------//   
			var val = $("kapital").value;
			if (!this.validate(val, "kapital")) {
				validResult = false;
			}
			
			//---------- ORGAN REJESTRUJACY -------------//   
			var val = $("organ").value;
			if (!this.validate(val, "organ")) {
				validResult = false;
			}		
		}	*/		   		   	   	   	   

	    var send_action = (action == 1) ? 2 : 1;
	   
	   //wysij zadanie
	   if (validResult) {
		  
		  this.block_send_button ();
	   	  
		  $('cart_cover').setStyle('height', $('cart_cont').getStyle('height').toInt() - 2)

		  //if ((radio1 && !this.edit) || (radio1 && this.edit && $('logo').value != '')) {
		  //	document.rForm.submit();
		  //} else {
		  request_sendRegistration(this.overlay, send_action);
		  //}
	   }
	   return validResult;
		
	},
	
	block_send_button: function () {
   	   var button = $('wyslij_btn');		
 	   button.disabled = true;
	   button.setProperty ('class', 'button_dis');
	   button.setProperty ('value', this.lang.wysylanie);		
	},
	
	unblock_send_button: function () {
   	   var button = $('wyslij_btn');		
 	   button.disabled = false;
	   button.setProperty ('class', 'button_en');
	   button.setProperty ('value', this.lang.wyslij);			
	},
	
	//rejestracja
	finish_file_upload: function  (result) {
		if (result) {
			request_sendRegistration(this.overlay, 1);
		} else {
			message.showMessage('<div class="msg_error">' + this.lang.file_error1 + '</div>');
			this.unblock_send_button();
		}
	},	
	
	//edycja danych
	finish_file_upload2: function  (result) {
		if (result) {
			request_sendRegistration(this.overlay, 2);
		} else {
			message.showMessage('<div class="msg_error">' + this.lang.file_error1 + '</div>');
			this.unblock_send_button();
		}
	}	
	
})



