function ChangePassForm(){
	this.init = function(){
		disableButtons('passChange');
		$('#curPass').val('');$('#newPass').val('');
		$('#passChange input').keydown(function(){
			enableButtons('passChange');
			});
	}
	
	this.submit = function(){
		$('#error').html('<img src="/img/key.png"><ul class="steps"></ul><br class="clear"><p></p>');
		$('#error').hide();
		var valid = true;
		var valid2 = $('#newPass').notempty()& $('#newPass').val().length>5;
		
		valid = valid & valid2;
		addError(valid2, RB_Lang.PASSMIN6+'');
		if (!valid2) $('#newPass').markred();
		if (!valid){
			$('#error').slideDown();
		}else{
			var data = {old:$('#curPass').val(), changed:$('#newPass').val() };
			disableButtons('passChange');
			$.ajax({url:'/usr-changepass/', type: "POST", data:data, async:true, success: function(data){
				if (data==''){
					showGreenMes(RB_Lang.DATASAVED+'');
					var changed = $('#newPass').val();
					$('#newPass').val(''); $('#curPass').val(changed);
				}else{
					$('#error').html('<img src="/img/key.png"><ul class="steps"></ul><br class="clear"><p></p>');
					addError(false, RB_Lang.OLDPASSWRONG+'');
					$('#error').show('slow');
				}
				log(data);
			}});
			
		}
		return false;
	}
	
	this.cancel = function(){
		disableButtons('passChange');
		$('#curPass').val('');$('#newPass').val('');
	}
}

function PersForm(nick, sex, vor, nach, bd){
	this.nick = nick;
	this.sex = sex;
	this.vor = vor;
	this.nach = nach;
	var spl = bd.split('-')
	this.gd = spl[2];
	this.gm = spl[1];
	this.gy = spl[0];
	if (this.gd =='00') this.gd = 'TT';
	if (this.gy =='0000') this.gy = 'JJJJ';
	if (this.gm =='00') this.gm = 'MM';
	
	
	
	$('#persForm input').keydown(function(){
		enableButtons('persForm');
		});
	$('#persForm input').change(function(){
		enableButtons('persForm');
		});
	
	
	this.enableForm = function(){
		enableButtons('persForm');
	}
	
	this.submit = function(){
		$('#error').html('<img src="/img/key.png"><ul class="steps"></ul><br class="clear"><p></p>');
		$('#error').hide();
		var valid2 = $('#nick').notempty();
		var valid = valid2;
		addError(valid2, RB_Lang.NONICKERR+'');
		valid2 = $('#day').numeric(0, 31);
		valid2 = valid2 & $('#month').numeric(0, 12);
		valid2 = valid2 & $('#year').numeric(1950, 2000)
		addError(valid2, RB_Lang.NOBIRTHERR+'');
		valid = valid & valid2;
		if (!valid) {
			$('#error').show('slow');
		}else{
			this.nick = $('#nick').val();
			this.sex = $('input[name="sex"]:checked').val();
			this.vor = $('#name').val();
			this.nach = $('#surname').val();
			this.gd = $('#day').val();
			this.gy = $('#year').val();
			this.gm = $('#month').val();

			disableButtons('persForm');
			var data = {nick: this.nick, sex:this.sex, vor: this.vor, nach:this.nach, bd: this.gy+'-'+this.gm+'-'+this.gd};
			$.ajax({url:'/usr-changename/', type: "POST", data:data, async:true, success: function(data){
				showGreenMes(RB_Lang.DATASAVED+'');
				log(data);
			}});
		}
		return false;
	}
	
	this.clear = function(){
		$('#nick').val(this.nick);
		if (this.sex==1){
			$('input[name="sex"][value="1"]').attr('checked', 'checked');
		}else{
			$('input[name="sex"][value="0"]').attr('checked', 'checked');
		}
		$('#name').val(this.vor);
		$('#surname').val(this.nach);
		$('#day').val(this.gd);
		$('#year').val(this.gy);
		$('#month').val(this.gm);
		disableButtons('persForm');
		return false;
	}
	this.init = function(){
		customcontrols["wsex"].setHandler('persForm.enableForm()');
		customcontrols["msex"].setHandler('persForm.enableForm()');
		this.clear();
	}
	
}

function LocForm(plz, city, street, house, geolat, geolong, geoset){
	this.plz = plz;
	this.city = city;
	this.street = street;
	this.house = house;
	this.geolat = geolat;
	this.geolong = geolong;
	this.geoset = geoset;
	this.newlat = geolat;
	this.newlong = geolong;
	this.newgeoset = 0;
	this.initialized = false;
	
	
	this.init = function(){
		if (this.initialized) return false;
		$('#location input').keydown(function(){
			enableButtons('location');
			});
		$('#location input').change(function(){
			enableButtons('location');
			});
		this.map = new GMap('map');
		this.map.initMap();
		locForm.clear();
		this.initialized = true;
	}
	
	this.clear = function(){
		$('#plz').plzselect({plz:this.plz, city:this.city});
		$('#street').val(this.street);
		$('#house').val(this.house);
		if (this.geoset){
			this.map.addMarker('Ich', this.geolat, this.geolong, locForm.markerDrag);
		}
		disableButtons('location');
		return false;
	}
	
	this.submit = function(){
		$('#error').hide();
		var data = {plz:$('#plz').val(), city:$('#city').val(), street:$('#street').val(), house:$('#house').val(), 
				geoset:locForm.newgeoset,
				geolat:locForm.newlat, 
				geolong:locForm.newlong,
				cityname:$('#city option:selected').html()
				};
		disableButtons('location');
		$.ajax({url:'/usr-changegeo/', type: "POST", data:data, async:true, success: function(data){
			showGreenMes(RB_Lang.DATASAVED+'');
			log(data);
		}});
		return false;
	}
	
	this.markerDrag = function(point){
		locForm.newlat = point.y;
		locForm.newlong = point.x;
		locForm.newgeoset = 1;
		enableButtons('location');
	}
	
	this.coords = function(lat, lng){
		if (lat==0 && lng==0){
			//alert('');
		}else{
			locForm.map.setCenter(lat, lng);
			locForm.map.addMarker('Ich bin hier', lat, lng, locForm.markerDrag);
			locForm.newlat = lat;
			locForm.newlong = lng;
			locForm.newgeoset = 1;
			enableButtons('location');
		}
	}
	
	this.checkAddr = function(){
		Geocoder.lookup($('#plz').val(), $('#city option:selected').html(), $('#street').val(), $('#house').val(), locForm.coords);
		return false;
	}
	
}


function FsForm(firma, addr, sid){
	this.firma = firma;
	this.addr = addr;
	this.sid = sid;

	this.submit = function(){
		disableButtons('fsform');
		var data = {fsid:$('#fsid').val()};
		$.ajax({url:'/usr-changeschool/', type: "POST", data:data, async:true, success: function(data){
			showGreenMes(RB_Lang.DATASAVED+'');
			log(data);
		}});
		return false;
	}
	
	this.search = function(){
		regFSSearch();
		return false;
	}
	
	this.enableForm = function(){
		enableButtons('fsform');
	}
	
	this.delSchool = function(){
		regFSClear();
		enableButtons('fsform');
		return false;
	}
	
	this.clear = function(){
		disableButtons('fsform');
		if (fsForm.sid==0){
			$('#fahrschule').slideUp();
		}else{
			$('#fahrschule').slideDown();
			$('#fahrschule h1').html(fsForm.firma);
			$('#fahrschule .adresse').html(fsForm.addr);
		}
		$('#fsid').val(fsForm.sid);
		return false;
	}
}

function PassForm(){
	this.init = function(){
		//disableButtons('passform');
		$('#passform a[name="save"]').attr('class', 'submitbtndis');
		$('#mail').keydown(this.enable);
	}
	
	this.enable = function(){
		$('#passform a[name="save"]').attr('class', 'submitbtn');
	}
	
	this.submit = function(){
		if ($('#passform a[name="save"]').attr('class')=='submitbtndis') return false;
		$('#error p').hide();
		$('.greenmes').hide();
		var data = {mail:$('#mail').val()};
		$.ajax({url:'/user-restorepass/', type: "POST", data:data, async:true, success: function(data){
			if (data=='1'){
				$('#error').html('<p>'+RB_Lang.SAMEMAILERR+'</p>');
				$('#error').slideDown();
			}else{
				$('.greenmes').html('<p>'+RB_Lang.PASSRESTSENT+'</p>');
				$('.greenmes').slideDown();
			}
			log(data);
		}});
		$('#passform a[name="save"]').attr('class', 'submitbtndis');
		return false;
		
	}
}


function OrderForm(present, vor, nach, street, house, plz, cityid, email){
	this.vor = vor;
	this.nach = nach;
	this.street = street;
	this.house = house;
	this.plz = plz;
	this.cityid = cityid;
	this.city = '';
	this.present = present;
	this.email = email;
	
	this.submit = function(){
		
		this.vor = $('#name').val();
		this.nach = $('#surname').val();
		this.street = $('#street').val();
		this.house = $('#house').val();
		this.plz = $('#plz').val();
		this.house = $('#house').val();
		this.cityid = $('#city_id').val();
		this.city = $('#city_id option:selected').html();
		this.email = $('#email').val();
		
		$('#error').html('<img src="/img/key.png"><ul class="steps"></ul><br class="clear"><p></p>');
		$('#error').hide();
		var valid2 = $('#name').notempty() & $('#surname').notempty();
		addError(valid2, RB_Lang.NONAMEERR+'');
		
		var valid = valid2;
		valid2 = $('#street').notempty();
		valid2 = $('#house').notempty() & valid2;
		valid2 = $('#plz').notempty() & valid2;
		if (this.cityid==0) $('#plz').markred();
		valid2 = valid2& (this.cityid>0);
		addError(valid2, RB_Lang.NOADDRERR+'');
		valid = valid & valid2;
		
		valid2 = $('#email').isEmail();
		addError(valid2, RB_Lang.ENTERMAIL);
		valid = valid & valid2;
		if (!valid) {
			$('#error').show('slow');
		}else{
			var data = {present:this.present, email:this.email, vor: this.vor, nach:this.nach, street: this.street, house:this.house, plz: this.plz, city:this.city, city_id:this.cityid};
			$.ajax({url:'/order-premium/', type: "POST", data:data, async:true, success: function(data){
				document.location = '/order-done/'+data;
			}});
		}
		return false;
	}
	
	this.init = function(){
		$('#plz').plzselect({plz:this.plz, city:this.cityid, cityId:'city_id', inputClass:'ortselect'});
		$('#name').val(this.vor);
		$('#surname').val(this.nach);
		$('#street').val(this.street);
		$('#house').val(this.house);
		$('#email').val(this.email);
	}
	
}

