CodeCompany.FormFiller = Class.create({
	log: function(str) {
		if (!Object.isUndefined(site)) { site.log('FormFiller: '+str); }
	},
	initialize: function(options) {
			this.options = Object.extend({
			prefix: '',
			firstnamefield: 'Fornavn',
			lastnamefield:	'Efternavn',
			dayphonefield:	'Telefon1',
			emailfield:		'Email',
			shopfield:		'Butik',
			adress:			'Adresse',
			city:			'By',
			zipcode:		'postnummer'
		},options || {});
		console.log("Formfiller constructed with this prefix: "+this.options.prefix);
	}.bind(this),
	fillForm: function(data) {
		//Populate form. (validate?)
		//namefield
		namefield = this.options.prefix+this.options.firstnamefield;
		if($(namefield)!==null&&(data.firstName!==''&&data.firstName!=null)){
		$(namefield).value=data.firstName;
		};
		//lastname
		lastnamefield = this.options.prefix+this.options.lastnamefield;
		if($(lastnamefield)!==null&&(data.surName!==''&&data.surName!=null)){
		$(lastnamefield).value=data.surName;
		};
		//phone
		phonefield = this.options.prefix+this.options.dayphonefield;
		if($(phonefield)!==null&&(data.phoneMobile!==''&&data.phoneMobile!=null)){
		$(phonefield).value=data.phoneMobile;
		};
		//email
		mailfield = this.options.prefix+this.options.emailfield;
		if($(mailfield)!==null&&(data.email!==''&&data.email!=null)){
		$(mailfield).value=data.email;
		};
		//adress
		adressfield = this.options.prefix+this.options.adress;
		if($(adressfield)!==null&&(data.streetName!==''&&data.streetName!=null)){
		$(adressfield).value=data.streetName;
		};
		//city
		cityfield = this.options.prefix+this.options.city;
		if($(cityfield)!==null&&(data.city!==''&&data.city!=null)){
		$(cityfield).value=data.city;
		};
		//zipcode
		zipfield = this.options.prefix+this.options.zipcode;
		if($(zipfield)!==null&&(data.zipCode!==''&&data.zipCode!=null)){
		$(zipfield).value=data.zipCode;
		};
		},

	failedCallBack: function() {
		//Fail!
		//do nothing :)
	},
	render: function(){
	 console.log("Formfiller tries with servicetoken:" + servicetoken);
	 //Somehow the options is undefined when callback is reached after webservice-call.. do I need to bind THIS somehow? 
    dk.ide.webservice.EditMeService.GetUserDetails(servicetoken, this.fillForm, this.failedCallBack);
 //   var options = this.options;
   //Here we CAN get the options.. wtf? 
   // alert(this.options.prefix);
	}
});
