/**
 * @author Gumfi
 */

var vTunerRequest = new Class({
	Implements:Options,
	
	// Some options for the application class
	options: {
		blowfishURL: 'http://www.loewe.de/de/',
		vTunerURL: 'http://loewe.vtuner.com/setupapp/Loewe/asp/AuthLogin/RegLoginUpdateSync.asp',
		vTunerSignIn: 'http://loewe.vtuner.com/setupapp/loewe/asp/AuthLogin/signin.asp?Lngy=',
		vTunerLogIn: 'http://loewe.vtuner.com/setupapp/loewe/asp/AuthLogin/AuthCreate.asp?',
		vTunerParams: {
			lngy: 'lngy=',
			emailAddress: 'sEmailAddress=',
			password: 'sPassword='
		},
		userData: {
			emailAddress: false,
			password: false,
			deviceName: false,
			userLang: false,
			userCode: false
		}
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.userData = this.options.userData;
		this.blowfishURL = this.options.blowfishURL;
		this.vTunerURL = this.options.vTunerURL;
		this.vTunerSignIn = this.options.vTunerSignIn;
		this.vTunerLogIn = this.options.vTunerLogIn;
		this.vTunerParams = this.options.vTunerParams;
	},
	
	encryptUserData: function() {
		var getEncryptData = new Request({
			url: this.blowfishURL,
			method: 'post',
			async: 0
		}).send('type=768&function=vTuner&vTuner=encryptData&tx_bmloesupport_pi1[vTunerData]='+this.requestType);
		
		return getEncryptData.response.text;
	},
	
	vTunerLogin: function(listContainer) {
		//alert(this.vTunerSignIn+this.userData.userCode);
		
		var vTunerCookieFrame = new Element('iframe', {
			src: this.vTunerSignIn+this.userData.userCode,
			styles: {
				width: 1,
				height: 1,
				display: 'none'
			},
			id: 'vTunerCookieWrite'
		});
		vTunerCookieFrame.inject(listContainer);
		vTunerCookieFrame.fireEvent('load');
		
	},
	
	openVTunerRadio: function() {
		this.vTunerLoginParams = this.vTunerParams.lngy+this.userData.userCode+'&'+this.vTunerParams.emailAddress+this.userData.emailAddress+'&'+this.vTunerParams.password+this.userData.password;
		//alert(this.vTunerLogIn+this.vTunerLoginParams);
		window.open(this.vTunerLogIn+this.vTunerLoginParams, '_blank');
	},
	
	addDevice: function(macAddress, listContainer) {
		this.requestType = 'add';
		this.requestParam = '?reginfo='+macAddress+'|'+this.userData.emailAddress+'|'+this.userData.password+'|'+this.userData.deviceName+'|'+this.userData.userLang+'|'+this.userData.userCode+'|'+this.requestType
		alert(this.vTunerURL+this.requestParam);
		var vTunerRegFrame = new Element('iframe', {
			src: this.vTunerURL+this.requestParam,
			styles: {
				width: 1,
				height: 1,
				display: 'none'
			}
		});
		vTunerRegFrame.inject(listContainer);
		vTunerRegFrame.fireEvent('load');
	},
	
	changeDevice: function(macAddress, listContainer) {
		this.requestType = 'change';
		this.requestParam = '?reginfo='+macAddress+'|'+this.userData.emailAddress+'|'+this.userData.password+'|'+this.userData.deviceName+'|'+this.userData.userLang+'|'+this.userData.userCode+'|'+this.requestType
		//alert(this.vTunerURL+this.requestParam);
		var vTunerRegFrame = new Element('iframe', {
			src: this.vTunerURL+this.requestParam,
			styles: {
				width: 1,
				height: 1,
				display: 'none'
			}
		});
		vTunerRegFrame.inject(listContainer);
		vTunerRegFrame.fireEvent('load');
	},
	
	deleteDevice: function(macAddress, listContainer) {
		this.requestType = 'delete';
		this.requestParam = '?reginfo='+macAddress+'|'+this.userData.emailAddress+'|'+this.userData.password+'|'+this.userData.deviceName+'|'+this.userData.userLang+'|'+this.userData.userCode+'|'+this.requestType
		alert(this.vTunerURL+this.requestParam);
		var vTunerRegFrame = new Element('iframe', {
			src: this.vTunerURL+this.requestParam,
			styles: {
				width: 1,
				height: 1,
				display: 'none'
			}
		});
		vTunerRegFrame.inject(listContainer);
		vTunerRegFrame.fireEvent('load');
	}
	
});
