(function(){

/* -------------------------------------------------------------------------------------------------------- */
// Mootools implements
Element.implement({
	isChildOf: function(el) {
		var e = this;
		while (e && typeof(e.getParent) != "undefined" && e.tagName.toLowerCase() != "body") {
			if (e == el) {
				return true;
			}
			e = e.getParent();
		}
		return false;
	},
	
	isVisible: function(){
		var el = this.getParent();
	    while (el) {
	        if (el.getStyle("display") == "none" || el.getStyle("visibility") == "hidden") { return false; }
	        el = el.getParent();
	    }
	    return true;
	},
	
	ieFixLayerShow: function(){
		if (!Browser.Engine.trident4) {
			return;
		}
		var dim = this.getCoordinates();
		if (!this.iframeFx) {
			this.iframeFx = new IFrame({
				"id": this.id+"iframeFx",
				"src": "javascript:false;",
				"frameBorder": 0,
				"scrolling": "no",
				"styles": {
					"border": "0 none",
					"margin": 0,
					"padding": 0,
					"z-index": 998,
					"display": "none",
					"position": "absolute",
					"filter": "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)"
				}
			}).inject(this, "before");
		}
		//
		this.iframeFx.set("styles", {
			"visibility": "visible",
			"display": "block",
			"top": dim.top,
			"left": dim.left,
			"width": dim.width,
			"height": dim.height,
			"z-index": 998
		});
	},
	
	ieFixLayerHide: function(){
		if (!Browser.Engine.trident4) {
			return;
		}
		if (this.iframeFx) {
			this.iframeFx.set("styles", {
				"visibility": "hidden",
				"display": "none"
			});
		}
	},
	
	dragClone: function(){
		return this.clone().setStyles(this.getCoordinates()).setStyles({
			"opacity": 0.7, 
			"position": "absolute"
		}).store("el", this).inject(document.body);
	},
	
	swapClass: function(oldClass, newClass){
		this.removeClass(oldClass).addClass(newClass);
	}
});

// add more function to event
Event.implement({
	getCharCode: function(){
		return (typeof(this.event.charCode) != "undefined") ? this.event.charCode : this.event.keyCode;
	},
	
	getCharKey: function(){
		var code = this.getCharCode();
		return (code == 0) ? "" : String.fromCharCode(code);
	}
});


// String
String.implement({
	quoteStr: function(s1, s2){
		return this.substring(this.indexOf(s1) + s1.length, this.indexOf(s2));
	},
	
	isBlank: function(){
		return (this.trim() == "");
	},
	
	isEmails: function(){
		var re = new RegExp("[;,]");
	    var arr = this.split(re);
	    for (var i = 0; i < arr.length; i++) {
	        if (!arr[i].trim().isEmail()) {
				return false;
			}
	    }
	    return true;
	},
	
	isEmail: function(){
		var re = new RegExp("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]{2,4}$");
		return (this.search(re) != -1);
	},
	
	isImage: function(){
		var re = new RegExp("\\.(png|gif|bmp|jpg|jpeg|jpe)$", "i");
		return (this.search(re) != -1);
	},
	
	isCSV: function(){
		var re = new RegExp("\\.(csv)$", "i");
		return (this.search(re) != -1);
	},
	
	isPhone: function(){
		var re = new RegExp("^[ ()-.0-9]{3,}$");
		return (this.search(re) != -1);
	},
	
	isDate: function(format){
		var re = new RegExp("[.\/-]");
	    var arr = this.split(re);
	    if (arr.length != 3) {
			return false;
		}
	    var y = parseInt(arr[format.indexOf("y")]);
	    var m = parseInt(arr[format.indexOf("m")]);
	    var d = parseInt(arr[format.indexOf("d")]);
	    var date = new Date(y, m - 1, d);
	    return (y == date.getFullYear() && m == date.getMonth() + 1 && d == date.getDate());
	},
	
	compareDate: function(format, otherDate){
		var re = new RegExp("[.\/-]");
	    var a1 = this.split(re);
	    var y1 = parseInt(a1[format.indexOf("y")]);
	    var m1 = parseInt(a1[format.indexOf("m")]);
	    var iDate1 = parseInt(a1[format.indexOf("d")]);
	    if (otherDate) {
	        var a2 = otherDate.split(re);
	        var y2 = parseInt(a2[format.indexOf("y")]);
	        var m2 = parseInt(a2[format.indexOf("m")]);
	        var iDate2 = parseInt(a2[format.indexOf("d")]);
	    }
	    else {
	        var otherDate = new Date();
	        var y2 = otherDate.getFullYear();
	        var m2 = otherDate.getMonth() + 1;
	        var iDate2 = otherDate.getDate();
	    }
	    //
	    if (y2 > y1) { return 1; }
	    else if (y2 < y1) { return -1; }
	    else {
	        if (m2 > m1) { return 1; }
	        else if (m2 < m1) { return -1; }
	        else {
	            if (iDate2 > iDate1) { return 1; }
	            else if (iDate2 < iDate1) { return -1; }
	            else { return 0; }
	        }
	    }
	},
	
	isCreditCard: function(cardname){
		// Define the cards we support. You may add addtional card types.
	    // Name:      As in the selection box of the form - must be same as user's
	    // Length:    List of possible valid lengths of the card number for the card
	    // prefixes:  List of possible prefixes for the card
	    // checkdigit Boolean to say whether there is a check digit
	    var cards = new Array({
	        name: "Visa",
	        length: "13,16",
	        prefixes: "4",
	        checkdigit: true
	    }, {
	        name: "MasterCard",
	        length: "16",
	        prefixes: "51,52,53,54,55",
	        checkdigit: true
	    }, {
	        name: "DinersClub",
	        length: "14,16",
	        prefixes: "300,301,302,303,304,305,36,38,55",
	        checkdigit: true
	    }, {
	        name: "CarteBlanche",
	        length: "14",
	        prefixes: "300,301,302,303,304,305,36,38",
	        checkdigit: true
	    }, {
	        name: "AmEx",
	        length: "15",
	        prefixes: "34,37",
	        checkdigit: true
	    }, {
	        name: "Discover",
	        length: "16",
	        prefixes: "6011,650",
	        checkdigit: true
	    }, {
	        name: "JCB",
	        length: "15,16",
	        prefixes: "3,1800,2131",
	        checkdigit: true
	    }, {
	        name: "enRoute",
	        length: "15",
	        prefixes: "2014,2149",
	        checkdigit: true
	    }, {
	        name: "Solo",
	        length: "16,18,19",
	        prefixes: "6334, 6767",
	        checkdigit: true
	    }, {
	        name: "Switch",
	        length: "16,18,19",
	        prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
	        checkdigit: true
	    }, {
	        name: "Maestro",
	        length: "16,18",
	        prefixes: "5020,6",
	        checkdigit: true
	    }, {
	        name: "VisaElectron",
	        length: "16",
	        prefixes: "417500,4917,4913",
	        checkdigit: true
	    });
	    // Establish card type
		var cardnumber = this;
	    var cardType = -1;
	    for (var i = 0; i < cards.length; i++) {
	        // See if it is this card (ignoring the case of the string)
	        if (cardname.toLowerCase() == cards[i].name.toLowerCase()) {
	            cardType = i;
	            break;
	        }
	    }
	    // If card type not found, report an error
	    if (cardType == -1) { return false; }
	    // Ensure that the user has provided a credit card number
	    if (cardnumber.length == 0) { return false; }
	    // Now remove any spaces from the credit card number
	    var re1 = new RegExp("\\s", "g");
	    cardnumber = cardnumber.replace(re1, "");
	    // Check that the number is numeric
	    var cardNo = cardnumber;
	    var cardexp = new RegExp("^[0-9]{13,19}$");
	    if (!cardexp.exec(cardNo)) { return false; }
	    // Now check the modulus 10 check digit - if required
	    if (cards[cardType].checkdigit) {
	        var checksum = 0; // running checksum total
	        var mychar = ""; // next char to process
	        var j = 1; // takes value of 1 or 2
	        // Process each digit one by one starting at the right
	        var calc;
	        for (i = cardNo.length - 1; i >= 0; i--) {
	            // Extract the next digit and multiply by 1 or 2 on alternative digits.
	            calc = Number(cardNo.charAt(i)) * j;
	            // If the result is in two digits add 1 to the checksum total
	            if (calc > 9) {
	                checksum = checksum + 1;
	                calc = calc - 10;
	            }
	            // Add the units element to the checksum total
	            checksum = checksum + calc;
	            // Switch the value of j
	            if (j == 1) {
	                j = 2;
	            }
	            else {
	                j = 1;
	            }
	                        }
	        // All done - if checksum is divisible by 10, it is a valid modulus 10.
	        // If not, report an error.
	        if (checksum % 10 != 0) { return false; }
	    }
	    // The following are the card-specific checks we undertake.
	    var LengthValid = false;
	    var PrefixValid = false;
	    // We use these for holding the valid lengths and prefixes of a card type
	    var prefix = new Array();
	    var lengths = new Array();
	    // Load an array with the valid prefixes for this card
	    prefix = cards[cardType].prefixes.split(",");
	    // Now see if any of them match what we have in the card number
	    for (i = 0; i < prefix.length; i++) {
	        var exp = new RegExp("^" + prefix[i]);
	        if (exp.test(cardNo)) PrefixValid = true;
	    }
	    // If it isn't a valid prefix there's no point at looking at the length
	    if (!PrefixValid) { return false; }
	    // See if the length is valid for this card
	    lengths = cards[cardType].length.split(",");
	    for (j = 0; j < lengths.length; j++) {
	        if (cardNo.length == lengths[j]) LengthValid = true;
	    }
	    // See if all is OK by seeing if the length was valid. We only check the 
	    // length if all else was hunky dory.
	    if (!LengthValid) { return false; };
	    // The credit card is in the required format.
	    return true;
	}
});

function getRadioValue(form, radio) {
	if (typeof(form[radio]) == 'undefined') {
		return null;
	}
	for (var i = 0; i < form[radio].length; i++) {
		if (form[radio][i].checked) {
			return form[radio][i].value || i;
		}
	}
	return null;
}

function formatFilesize(size, round) {
	var iec = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
	var i = 0;
	var s = '';
	while ((size / 1024) > 1) {
		size = size / 1024;
		i++;
	}
	size = size.toString();
	if (size.indexOf('.') > 0) {
		s = size.substr(0, size.indexOf('.') + 3) + iec[i];
	} else {
		s = size + iec[i];
	}
	if (round) {
		s = Math.round(size) + iec[i];
	}
	return s;
}

function formatTimeFromSeconds(nSeconds) {
	var  hours = Math.floor(nSeconds / ( 60 * 60)); 
	nSeconds -= hours * ( 60 * 60);
	var mins = Math.floor(nSeconds / ( 60)); 
	nSeconds -= mins * (  60);
	if (hours < 10) {
		hours = '0' + hours;
	}
	if (mins<10) {
		mins = '0' + mins;
	}
	if (nSeconds < 10) {
		nSeconds = '0' + nSeconds;
	}
	return hours + ':' + mins + ':' + nSeconds;
}

/* -------------------------------------------------------------------------------------------------------- */

var IndexPage = new Class({
	// Implements: [Chain, Events, Options],
	// options: {},
	
	vars: {
		uploadInterval: Class.empty,
		numberOfReloadSent: 0,
		fromEmail: Class.empty,
		toEmailtoEmail: Class.empty,
		maxTotalFileSize: 50
	},
	
	initialize: function() {
		this.initForms();
		this.initControls();
	},

	initForms: function() {
		var _scope = this;
		var form1 = $('homeUpload');
		
		if (form1) {
			// custom file chooser
			form1.fileUploadContent.value = '';
			$(form1.file1).addEvent('change', function(){
				var files = this.value.split(/(\\|\/)/);
				this.getNext().value = files[files.length - 1];
			});
			
			// check account
			var fromInput = $(form1.from);
			if (fromInput) {
				fromInput.addEvents({
					'blur': function(e) {
						if (String(this.value).trim().isEmail()) {
							checkExistUser();
						}
					}
				});
			}
			
			// check form
			var submitBtn = form1.getElement('input[type=image]');
			if (submitBtn) {
				submitBtn.addEvent('click', function(e){
					// prevent default event
					e.stop();
					
					// start checking form
					if (String(form1.from.value).isBlank()) {
						alert(message.homeSenderEmail);
						form1.from.focus();
						return;
					}
					if (!String(form1.from.value).isEmail()) {
						alert(message.homeSenderWrongEmail);
						form1.from.focus();
						return;
					}
					if (String(form1.to.value).isBlank()) {
						alert(message.homeRecipientEmail);
						form1.to.focus();
						return;
					}
					if (!String(form1.to.value).isEmails()) {
						alert(message.homeRecipientWrongEmail);
						form1.to.focus();
						return;
					}
					if (String(form1.file1.value).isBlank()) {
						alert(message.homeFile);
						return;
					}
					
					// hide form
					this.disabled = 'disabled';
					this.setStyle('display', 'none');
					new Fx.Tween('homeUpload').start('height', '0');
					new Fx.Tween('homeUpload', {
						onComplete: function() {
							$('homeUpload').set('styles', {
								'margin': 0,
								'padding': 0,
								'position': 'relative'
							});
							new Fx.Tween('uploadStatusBar', {duration: 300}).start('height', '100');
							new Fx.Tween('homeUpload', {duration: 300}).start('opacity', '0', '1');
						}
					}).start('opacity', '0');
					
					// check & send
					checkExistUser(function() {
						form1.submit();
						startUploadProgress();
					});
				});
			}
			
			function startUploadProgress() {
				// Update progress
				_scope.vars.fromEmail = String(form1.to.value).trim();
				_scope.vars.toEmail = String(form1.from.value).trim();
				_scope.checkUploadStatus.periodical(2000, _scope);
			}
			
			function checkExistUser(callback) {
				new Request({
					'method': 'post',
					'url': 'check_upload.php',
					'data': 'email=' + fromInput.value.trim(),
					'onSuccess': function(responseText, responseXML) {
						if (responseText.trim() == '1') {
							window.location.href = 'login.php?email=' + fromInput.value.trim();
						} else {
							if (callback) {
								callback();
							}
						}
					},
					'onFailure': function() {
						//alert('Cannot make request!');
						checkExistUser();
					}
				}).send();
			}
		}
		
		window.uploadProgressStatus = function(status, totalSize, totalFilesUploaded ,uploadedSize, speed) {
			// if file size is too big, user must login
			if (typeof(_scope.vars.maxTotalFileSize) != 'undefined' && totalSize > 0 && (_scope.vars.maxTotalFileSize + 1 ) * 1024 * 1024 < totalSize) {
				window.location.href = '/login_request.php';
				return;
			}
			
			// update status
			if (status == 'Finished') {
				$('fileProgressBar').setStyle('width', '100%');
				$('percentComleted').set('html', message.uploadCompleted);
				$('estimateTimeRemaining').set('html', message.waitingConfirmation);
			} else {
				var percent = Math.ceil((uploadedSize / totalSize) * 100);		
				$('fileProgressBar').setStyle('width', percent + '%');
				$('percentComleted').set('html', message.uploading + ' ' + percent + '% (' + formatFilesize(uploadedSize) + ' / ' + formatFilesize(totalSize) + ')');
				var timeRemaining = '';
				if (speed > 0) {
					timeRemaining = Math.floor((totalSize - uploadedSize) / (speed * 1024));
					timeRemaining = '<br />' + message.estimateTime + ': ' + formatTimeFromSeconds(timeRemaining);
					$('estimateTimeRemaining').set('html', message.speed + ': '+ speed + 'KB/s' + timeRemaining);
				} else {
					$('estimateTimeRemaining').set('html', message.speed + ': ' + message.calculateTime);
				}
			}
		}
	},
	
	checkUploadStatus: function() {
		var _scope = this;
		var form1 = $('homeUpload');
		var storageServerUploader = form1.storageServerUploader.value;
		var tempSID = form1.tempSID.value;
		//var statusURL = '/getUploadStatusIframe.php?server=' + storageServerUploader + '&tmp_sid=' + tempSID;
		var statusURL = "/gateway/getUploadStatus.php"+"?tmp_sid="+tempSID;
		if (typeof(_scope.vars.fromEmail) != 'undefined' && _scope.vars.fromEmail.trim() != ''){
			statusURL += '&from=' + _scope.vars.fromEmail;
		}
		if (typeof(_scope.vars.toEmail) != 'undefined' && _scope.vars.toEmail.trim() != ''){
			statusURL += '&to=' + _scope.vars.toEmail;
		}
		statusURL = statusURL + '&NumberOfReloadSent=' + _scope.vars.numberOfReloadSent;
		_scope.vars.numberOfReloadSent++;
		
		window.homeUploadIframe.location.href = statusURL;
	},
	
	initControls: function() {
		$('homeAdvancedButton').getFirst().addEvent('click', function(e){
			e.stop();
			if (!this.hasClass('buttonClicked')) {
				this.addClass('buttonClicked').set('text', 'Hide options');
				new Fx.Tween('homeAdvancedTab', {duration:500}).start('height', '170px');
			} else {
				this.removeClass('buttonClicked').set('text', 'More options');
				new Fx.Tween('homeAdvancedTab', {duration:200}).start('height', '0');
			}
		});
	}
});

var LoginBox = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('loginBox');
		
		if (form1) {
			// custom file chooser
			$(form1.username).addEvents({
				'focus': function(){
					this.set('value', '');
				},
				'blur': function(){
					if (String(this.value).isBlank()) {
						this.set('value', label.loginBoxUsername);
					}
				}
			});
			$(form1.passwordText).addEvent('focus', function(){
				this.setStyle('display', 'none');
				this.getNext().setStyle('display', 'inline-block').focus();
			});
			$(form1.password).addEvent('blur', function(e){
				if (String(this.value).isBlank()) {
					this.set('value', '').setStyle('display', 'none');
					this.getPrevious().set('value', label.loginBoxPassword).setStyle('display', 'inline-block');
				}
			});
			
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.username.value).isBlank() || String(this.username.value).trim() == label.loginBoxUsername) {
					alert(message.loginBoxUsername);
					e.stop();
					return;
				}
				if (String(this.password.value).isBlank()) {
					alert(message.loginBoxPassword);
					e.stop();
					return;
				}
			});
		}
	}
});

var RegisterPage = new Class({
	// Implements: [Chain, Events, Options],
	// options: {},
	initialize: function() {
		this.initForms();
	},

	initForms: function() {
		var form1 = $('registerForm');

		if (form1) {
			if (!String(form1.prePlan.value).isBlank()) {
			var selectedIndex = 0;
				switch (form1.prePlan.value.trim().toLowerCase()) {
					case 'free':
						selectedIndex = 1;
					break;
					case 'sy':
						selectedIndex = 2;
					break;
					case 'pm':
						selectedIndex = 3;
					break;
					case 'py':
						selectedIndex = 4;
					break;
					case 'bm':
						selectedIndex = 5;
					break;
					case 'by':
						selectedIndex = 6;
					break;
					case 'cm':
						selectedIndex = 7;
					break;
					case 'cy':
						selectedIndex = 8;
					break;
				}
				form1.solution.selectedIndex = selectedIndex;
			}
			
			form1.addEvent('submit', function(e){
				if (this.solution.selectedIndex == 0) {
					alert(message.registerHostplan);
					e.stop();
					return;
				}
				if (String(this.FullName.value).isBlank()) {
					alert(message.registerFullName);
					e.stop();
					return;
				}
				if (String(this.Email.value).isBlank()) {
					alert(message.registerEmail);
					e.stop();
					return;
				}
				if (!String(this.Email.value).isEmail()) {
					alert(message.registerWrongEmail);
					e.stop();
					return;
				}
				if (String(this.Password.value).isBlank()) {
					alert(message.registerPassword);
					e.stop();
					return;
				}
				if (String(this.Password2.value).isBlank()) {
					alert(message.registerPassword2);
					e.stop();
					return;
				}
				if (this.Password2.value != this.Password.value) {
					alert(message.registerConfirmPW);
					e.stop();
					return;
				}
				if (!this.agree.checked) {
					alert(message.registerAgree);
					e.stop();
					return;
				}
			});
		}
	}
});

var ContactPage = new Class({
	// Implements: [Chain, Events, Options],
	// options: {},
	initialize: function() {
		this.initForms();
	},

	initForms: function() {
		var form1 = $('contactForm');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.FullName.value).isBlank()) {
					alert(message.contactFullName);
					e.stop();
					return;
				}
				if (String(this.Email.value).isBlank()) {
					alert(message.contactEmail);
					e.stop();
					return;
				}
				if (!String(this.Email.value).isEmail()) {
					alert(message.contactWrongEmail);
					e.stop();
					return;
				}
				if (String(this.message.value).isBlank()) {
					alert(message.contactMessage);
					e.stop();
					return;
				}
			});
		}
	}
});

var HelpPage = new Class({
	// Implements: [Chain, Events, Options],
	// options: {},
	initialize: function() {
		this.initSlide();
	},

	initSlide: function() {
		$$('.faq').each(function(ul){
			var togglers = ul.getElements('h4');
			var contents = ul.getElements('div');
			new Fx.Accordion(togglers, contents, {
				show: -1,
				opacity: false,
				alwaysHide: true,
				onActive: function(el){
					el.addClass("active");
				},
				onBackground: function(el){
					el.removeClass("active");
				}
			});
		});
	}
});

var SendFilesPage = new Class({
	// Implements: [Chain, Events, Options],
	options: {
		uploader: Class.empty,
		flashEnabled: false
	},
	
	vars: {
		uploadInterval: Class.empty,
		numberOfReloadSent: 0,
		fromEmail: Class.empty,
		toEmailtoEmail: Class.empty,
		maxTotalFileSize: 50,
		exceededMaxSize: false
	},
	
	initialize: function() {
		this.initFancy();
		this.initForms();
		this.initControls();
	},
	
	initFancy: function() {
		var _scope = this;
		var form1 = $('sendFiles');
		
		if (typeof(FancyUpload2) == 'undefined' || !form1) {
			this.options.uploader = {};
			this.options.uploader.size = 0;
			return;
		}
		
		this.options.uploader = new FancyUpload2($('uploadStatus'), $('fileList'), {
			verbose: false,
			url: form1.flashUploadURL.value,
			path: 'flash/swf/Swiff.Uploader.swf',
			target: $('chooseFile').getFirst(),
			//fileListMax: Number(form1.maxFileAllow.value),
			fileListSizeMax: Number(form1.maxTotalFileSize.value) * 1024 * 1024,
			onLoad: function() {
				$('plainUploadPanel').setStyle('display', 'none');
				$('flashUploadPanel').setStyle('display', 'block');
				_scope.options.flashEnabled = true;
			},
			
			onSelectSuccess: function() {
				$('uploadStatus').setStyle('display', 'block');
			},
			
			onSelectFail: function(files) {
				$('uploadStatus').setStyle('display', 'none');
				files.each(function(file) {
					new Element('li', {
						'class': 'validation-error',
						html: file.validationErrorMessage || file.validationError,
						title: MooTools.lang.get('FancyUpload', 'removeTitle'),
						events: {
							click: function() {
								this.destroy();
							}
						}
					}).inject(this.list, 'top');
					
					if (file.validationError == 'fileListSizeMax' || file.validationError == 'fileListMax') {
						_scope.vars.exceededMaxSize = true;
					}
				}, this);
			},
			
			onFileSuccess: function(file, response) {
			},
			
			onComplete: function() {
				form1.fileUploaded.value = true;
				form1.submit();
			},
			
			onFail: function(error) {
				$('flashUploadPanel').setStyle('display', 'none');
				$('plainUploadPanel').setStyle('display', 'block');
				switch (error) {
					case 'hidden': // works after enabling the movie and clicking refresh
						alert('To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).');
						break;
					case 'blocked': // This no *full* fail, it works after the user clicks the button
						alert('To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).');
						break;
					case 'empty': // Oh oh, wrong path
						//alert('A required file was not found, please be patient and we fix this.');
						break;
					case 'flash': // no flash 9+ :(
						alert('To enable the embedded uploader, install the latest Adobe Flash plugin.');
						break;
				}
			}
			
		});
	},
	
	initForms: function() {
		var _scope = this;
		var form1 = $('sendFiles');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.to.value).isBlank()) {
					alert(message.homeRecipientEmail);
					e.stop();
					return;
				}
				/*
				if (!String(this.to.value).isEmails()) {
					alert(message.homeRecipientWrongEmail);
					e.stop();
					return;
				}*/
				if (_scope.options.uploader.size == 0 &&
					form1.file1.value.trim() == '' &&
					form1.file2.value.trim() == '' &&
					form1.file3.value.trim() == '' &&
					form1.file4.value.trim() == '' &&
					form1.file5.value.trim() == '' &&
					form1.file6.value.trim() == ''
					) {
					alert(message.sendFiles);
					e.stop();
					return;
				}
				
				if (form1.fileUploaded.value == 'false') {
					// start upload
					if (_scope.options.uploader != Class.empty && _scope.options.flashEnabled != false) {
						e.stop();
						if (_scope.vars.exceededMaxSize == true) {
							window.location = '/members/upgrade.php';
							return;
						}
						$('fileList').setStyle('display', 'none');
						$('sendFileButtons').setStyle('display', 'none');
						$('chooseFile').setStyles({
							'opacity': 0.01,
							'position': 'absolute',
							'top': 0,
							'left': 0							
						});
						if (typeof(form1.to) != 'undefined') {
							form1.to.readOnly = 'readonly';
						}
						if (typeof(form1.subject) != 'undefined') {
							form1.subject.readOnly = 'readonly';
						}
						if (typeof(form1.message) != 'undefined') {
							form1.message.readOnly = 'readonly';
						}
						if (typeof(form1.copy) != 'undefined') {
							form1.copy.disabled = 'disabled';
						}
						_scope.options.uploader.start();
					} else {
						// redirect target
						form1.target = 'memberUploadIframe';
						
						// Show progress bar
						new Fx.Tween('sendFiles').start('height', '0');
						new Fx.Tween('sendFiles', {
							onComplete: function() {
								$('sendFiles').set('styles', {
									'margin': 0,
									'padding': 0,
									'position': 'relative'
								});
								new Fx.Tween('uploadStatusBar', {duration: 300}).start('height', '100');
								new Fx.Tween('sendFiles', {duration: 300}).start('opacity', '0', '1');
							}
						}).start('opacity', '0');
						
						// Update progress
						//_scope.vars.fromEmail = String(this.to.value).trim();
						_scope.vars.toEmail = String(this.from.value).trim();
						_scope.vars.maxTotalFileSize = Number(form1.maxTotalFileSize.value.trim());
						_scope.checkUploadStatus.periodical(2000, _scope);
					}
				}
			});
		}
	},
	
	checkUploadStatus: function() {
		var _scope = this;
		var form1 = $('sendFiles');
		var storageServerUploader = form1.storageServerUploader.value;
		var tempSID = form1.tempSID.value;
		//var statusURL = '/getUploadStatusIframe.php?server=' + storageServerUploader + '&tmp_sid=' + tempSID;
		var statusURL = "/gateway/getUploadStatus.php"+"?tmp_sid="+tempSID;
		if (typeof(_scope.vars.fromEmail) != 'undefined' && _scope.vars.fromEmail.trim() != ''){
			statusURL += '&from=' + _scope.vars.fromEmail;
		}
		if (typeof(_scope.vars.toEmail) != 'undefined' && _scope.vars.toEmail.trim() != ''){
			statusURL += '&to=' + _scope.vars.toEmail;
		}
		statusURL = statusURL + '&NumberOfReloadSent=' + _scope.vars.numberOfReloadSent;
		_scope.vars.numberOfReloadSent++;
		
		new Request.JSON({
			url: statusURL,
			method: 'get',
			onSuccess:  function(progress) {
				// if file size is too big, user must upgrade
				if (typeof(_scope.vars.maxTotalFileSize) != 'undefined' && progress.totalSize > 0 && (_scope.vars.maxTotalFileSize + 1 ) * 1024 * 1024 < progress.totalSize) {
					window.location.href = '/upgrade.php';
					return;
				}
				
				// update status
				if (progress.status == 'Finished') {
					$('fileProgressBar').setStyle('width', '100%');
					$('percentComleted').set('html', message.uploadCompleted);
					$('estimateTimeRemaining').set('html', message.waitingConfirmation);
				} else {
					var percent = Math.ceil((progress.uploadedSize / progress.totalSize) * 100);		
					$('fileProgressBar').setStyle('width', percent + '%');
					$('percentComleted').set('html', message.uploading + ' ' + percent + '% (' + formatFilesize(progress.uploadedSize) + ' / ' + formatFilesize(progress.totalSize) + ')');
					var timeRemaining = '';
					if (progress.Speed > 0) {
						timeRemaining = Math.floor((progress.totalSize - progress.uploadedSize) / (progress.Speed * 1024));
						timeRemaining = '<br />' + message.estimateTime + ': ' + formatTimeFromSeconds(timeRemaining);
					} else {
						timeRemaining = message.calculateTime;
					}
					$('estimateTimeRemaining').set('html', message.speed + ': '+ progress.Speed + 'KB/s' + timeRemaining);
				}
			}
		}).send();
	},
	
	initControls: function() {
		if ($('toggleOptions')) {
			$('toggleOptions').getFirst().addEvent('click', function(e){
				e.stop();
				if (!this.hasClass('buttonClicked')) {
					this.addClass('buttonClicked').set('text', 'Hide options');
					new Fx.Tween('moreOptions', {duration:500}).start('height', '130px');
				} else {
					this.removeClass('buttonClicked').set('text', 'More options');
					new Fx.Tween('moreOptions', {duration:200}).start('height', '0');
				}
			});
		}
		
		if ($('importAddress')) {
			$('importAddress').addEvent('click', function(e){
				e.stop();
				var URLStr = 'popup_addressbook.php';
				window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+650+',height='+500+',left='+10+', top='+100+',screenX='+100+',screenY='+100+'');
			});
		}
	}
});

var EditProfile = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('editProfile');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.FullName.value).isBlank()) {
					alert(message.profileFullName);
					e.stop();
					return;
				}
				if (String(this.Email.value).isBlank()) {
					alert(message.profileEmail);
					e.stop();
					return;
				}
				if (!String(this.Email.value).isEmail()) {
					alert(message.profileWrongEmail);
					e.stop();
					return;
				}
			});
		}
	}
});

var ChangePassword = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('changePassword');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.OldPassword.value).isBlank()) {
					alert(message.changeOldPassword);
					e.stop();
					return;
				}
				if (String(this.Pass1.value).isBlank()) {
					alert(message.changePass1);
					e.stop();
					return;
				}
				if (String(this.Pass2.value).isBlank()) {
					alert(message.changePass2);
					e.stop();
					return;
				}
				if (String(this.Pass2.value) != String(this.Pass1.value)) {
					alert(message.changeMissPass);
					e.stop();
					return;
				}
			});
		}
	}
});

var DropBox = new Class({
	initialize: function() {
		this.initForms();
		this.initControls();
	},
	
	initForms: function() {
		var form1 = $('dropBoxForm');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				//
			});
		}
	},
	
	initControls: function() {
		
	}
});

var Storage = new Class({
	initialize: function() {
		this.initControls();
	},
	
	initForms: function() {
		
	},
	
	initControls: function() {
		var _scope = this;
		var form = $('storagePage');
		var ID = 0;
		var ParentFolderID = form.ParentFolderID.value;
		var IsShared = form.IsShared.value;
		
		var divContainer = new Element('div', {
			'class' : 'storageForms'
		}).inject(form.getParent(), 'after');
		
		// add new folder
		$('newFolder').addEvent('click', function(e){
			e.stop();
			divContainer.setStyle('display', 'block').set('text', message.storageLoading);
			new Request.HTML({
				'method': 'get',
				'url': 'ajaxEditFolder.php',
				'data': 'FolderID=' + ID + '&ParentFolderID=' + ParentFolderID + '&IsShared=' + IsShared,
				'onSuccess': function(responseTree, responseElements, responseHTML, responseJavaScript) {
					divContainer.set('html', responseHTML);
					divContainer.getElement('form').addEvent('submit', function(evt){
						evt.stop();
						var FolderID = this.FolderID.value;
						var FolderName = this.FolderName.value;
						if (FolderName.isBlank()) {
							alert(message.storageFolder);
							return;
						}
						new Request.HTML({
							'method': 'get',
							'url': 'ajaxEditFolder.php',
							'data': 'task=update&FolderID=' + ID + '&FolderName=' + FolderName + '&ParentFolderID=' + ParentFolderID + '&IsShared=' + IsShared,
							'onSuccess': function(rTree, rElements, rHTML, rJavaScript) {
								if (rHTML.trim() == 'OK') {
									//alert(message.storageFolderSaved);
									window.location.href = window.location.href;
								} else {
									alert(rHTML)
								}
							},
							'onFailure': function() {
								alert('Cannot make request!');
							}
						}).send();
						divContainer.set('text', message.storageUpdating);
					});
				},
				'onFailure': function() {
					alert('Cannot make request!');
				}
			}).send();
		});

		// download selected
		$('downloadItems').addEvent('click', function(e){
			e.stop();
			if (_scope.getSelectedFiles() + _scope.getSelectedFolders() == 0) {
				alert(message.storageDownload);
				return;
			}
			$('storageList').set('action', 'download.php').submit();
		});
		
		// delete selected
		$('deleteItems').addEvent('click', function(e){
			e.stop();
			if (_scope.getSelectedFiles() + _scope.getSelectedFolders() == 0) {
				alert(message.storageDelete);
				return;
			}
			if (confirm(message.storageConfirmDelete)) {
				$('storageList').task.value = 'delete';
				$('storageList').set('action', 'storage.php').submit();
			}
		});
		
		// show share file / folder
		$('showShared').addEvent('click', function(e){
			e.stop();
			if (_scope.getSelectedFiles() + _scope.getSelectedFolders() == 0) {
				alert(message.storageShared);
				return;
			}
			new Request.HTML({
				'method': 'get',
				'url': 'ajaxSharedBox.php',
				'data': '',
				'onSuccess': function(responseTree, responseElements, responseHTML, responseJavaScript) {
					divContainer.set('html', responseHTML);
					divContainer.getElement('form').addEvent('submit', function(evt){
						evt.stop();
						var NewFolder = this.NewFolder.value;
						var NewFolderID = this.ParentFolderID.options[this.ParentFolderID.selectedIndex].value;
						var copy = getRadioValue(this, 'copy');
						$('storageList').task.value = 'moveToShared';
						$('storageList').set('action', 'storage.php?NewFolderID=' + NewFolderID + '&NewFolder=' + NewFolder + '&IsShared=' + IsShared + '&copy=' + copy).submit();
					});
				},
				'onFailure': function() {
					alert('Cannot make request!');
				}
			}).send();
			divContainer.setStyle('display', 'block').set('text', message.storageLoading);
		});
		
		// move files/folders
		$('showMove').addEvent('click', function(e){
			e.stop();
			if (_scope.getSelectedFiles() + _scope.getSelectedFolders() == 0) {
				alert(message.storageMove);
				return;
			}
			new Request.HTML({
				'method': 'get',
				'url': 'ajaxMoveFolder.php',
				'data': 'CurrentFolderID=' + ParentFolderID + "&IsShared=" + IsShared,
				'onSuccess': function(responseTree, responseElements, responseHTML, responseJavaScript) {
					divContainer.set('html', responseHTML);
					divContainer.getElement('form').addEvent('submit', function(evt){
						evt.stop();
						var NewFolderID = this.ParentFolderID.options[this.ParentFolderID.selectedIndex].value;
						var NewFolder = this.NewFolder.value;
						$('storageList').task.value = 'move';
						$('storageList').set('action', 'storage.php?NewFolderID=' + NewFolderID + '&NewFolder=' + NewFolder + '&IsShared=' + IsShared).submit();
					});
				},
				'onFailure': function() {
					alert('Cannot make request!');
				}
			}).send();
			divContainer.setStyle('display', 'block').set('text', message.storageLoading);
		});
		
		// send 
		$('showSend').addEvent('click', function(e){
			e.stop();
			if (_scope.getSelectedFiles() == 0) {
				alert(message.storageSend);
				return;
			}
			$('storageList').set('action', 'storageSend.php').submit();
		});
		
		// edit folder 
		$$('a.editFolder').each(function(el){
			el.addEvent('click', function(e){
				e.stop();
				divContainer.setStyle('display', 'block').set('text', message.storageLoading);
				var ID = this.rel;
				new Request.HTML({
					'method': 'get',
					'url': 'ajaxEditFolder.php',
					'data': 'FolderID=' + ID + '&ParentFolderID=' + ParentFolderID + '&IsShared=' + IsShared,
					'onSuccess': function(responseTree, responseElements, responseHTML, responseJavaScript) {
						divContainer.set('html', responseHTML);
						divContainer.getElement('form').addEvent('submit', function(evt){
							evt.stop();
							var FolderID = this.FolderID.value;
							var FolderName = this.FolderName.value;
							if (FolderName.isBlank()) {
								alert(message.storageFolder);
								return;
							}
							new Request.HTML({
								'method': 'get',
								'url': 'ajaxEditFolder.php',
								'data': 'task=update&FolderID=' + ID + '&FolderName=' + FolderName + '&ParentFolderID=' + ParentFolderID + '&IsShared=' + IsShared,
								'onSuccess': function(rTree, rElements, rHTML, rJavaScript) {
									if (rHTML.trim() == 'OK') {
										//alert(message.storageFolderSaved);
										window.location.href = window.location.href;
									} else {
										alert(rHTML)
									}
								},
								'onFailure': function() {
									alert('Cannot make request!');
								}
							}).send();
							divContainer.set('text', message.storageUpdating);
						});
					},
					'onFailure': function() {
						alert('Cannot make request!');
					}
				}).send();
			});
		});
	},
	
	getSelectedFiles: function() {
		return $('storageList').getElements('input[name^=FileIDs]:checked').length;
	},
	
	getSelectedFolders: function() {
		return $('storageList').getElements('input[name^=FolderIDs]:checked').length;
	}
});

var UserList = new Class({
	initialize: function() {
		this.initForms();
		this.initControls();
	},
	
	initForms: function() {
		var form1 = $('userList');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (!confirm(message.deleteAllUsers)) {
					e.stop();
				}
			});
		}
	},
	
	initControls: function() {
		
	}
});

var AddEditUser = new Class({
	initialize: function() {
		this.initForms();
		this.initControls();
	},
	
	initForms: function() {
		var form1 = $('addEditUser');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.FullName.value).isBlank()) {
					alert(message.editUserFullName);
					e.stop();
					return;
				}
				if (String(this.Email.value).isBlank()) {
					alert(message.editUserEmail);
					e.stop();
					return;
				}
				if (!String(this.Email.value).isEmail()) {
					alert(message.editUserWrongEmail);
					e.stop();
					return;
				}
				if (String(this.Password.value).isBlank()) {
					alert(message.editUserPassword);
					e.stop();
					return;
				}
				if (String(this.MaxStorage.value).isBlank()) {
					alert(message.editUserMaxStorage);
					e.stop();
					return;
				}
				if (isNaN(this.MaxStorage.value.trim())) {
					alert(message.editUserMaxStorageNumber);
					e.stop();
					return;
				}
				if (String(this.MaxSendPerMonth.value).isBlank()) {
					alert(message.editUserMaxSend);
					e.stop();
					return;
				}
				if (isNaN(this.MaxSendPerMonth.value.trim())) {
					alert(message.editUserMaxSendNumber);
					e.stop();
					return;
				}
			});
		}
	},
	
	initControls: function() {
		
	}
});

var AddressBook =  new Class({
	initialize: function() {
		this.initControls();
	},
	
	initForms: function() {
		
	},
	
	initControls: function() {
		var form = $('addressBook');
		$$('input[type=button]').each(function(el){
			el.addEvent('click', function(e){
				e.stop();
				if (this.value.indexOf('Search') != -1) {
					if (String(form.search.value).isBlank()) {
						alert(message.addressSearch);
						return;
					}
					form.submit();
				} else if (this.value.indexOf('Send') != -1) {
					form.task.value='send';
					form.submit();
				} else if (this.value.indexOf('Delete') != -1) {
					if (confirm(message.addressDeleteAll)) {
						form.task.value='delete';
						form.submit();
					}
				}
			});
		});
	}
});

var AddEditContact = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('addEditContact');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.FullName.value).isBlank()) {
					alert(message.editContactFullName);
					e.stop();
					return;
				}
				if (String(this.Email.value).isBlank()) {
					alert(message.editContactEmail);
					e.stop();
					return;
				}
				if (!String(this.Email.value).isEmail()) {
					alert(message.editContactWrongEmail);
					e.stop();
					return;
				}
			});
		}
	}
});

var ImportCSV = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('importCVS');
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.csvfile.value).isBlank()) {
					alert(message.csvFile);
					e.stop();
					return;
				}
				if (!String(this.csvfile.value).isCSV()) {
					alert(message.csvWrongFile);
					e.stop();
					return;
				}
			});
		}
		
		var form2 = $('cvsList');
		if (form2) {
			// check form
			form2.getElements('input[type=button]').each(function(el){
				el.addEvent('click', function(e){
					e.stop();
					if (this.value.indexOf('Import') != -1) {
						if (getRadioValue(form2, 'ContactIDs[]') == null) {
							alert(message.cvsListNoSelect);
							return;
						}
						form2.task.value = 'save';
						form2.submit();
					}  else if (this.value.indexOf('Delete') != -1) {
						if (confirm(message.cvsListDeleteAll)) {
							form2.task.value = 'delete';
							form2.submit();
						}
					}
				});
			});
		}
		
		var form3 = $('importContact');
		if (form3) {
			// check form
			form3.addEvent('submit', function(e){
				if (String(this.Login.value).isBlank()) {
					alert(message.importLogin);
					e.stop();
					return;
				}
				if (String(this.Password.value).isBlank()) {
					alert(message.importPassword);
					e.stop();
					return;
				}
			});
		}
	}
});

var CheckoutForm = new Class({
	initialize: function() {
		this.initForms();
		this.initControls();
	},
	
	initForms: function() {
		var form1 = $('checkoutForm');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.CardNumber.value).isBlank()) {
					alert(message.checkoutCardNumber);
					e.stop();
					return;
				}
				if (String(this.CCV.value).isBlank()) {
					alert(message.checkoutCCV);
					e.stop();
					return;
				}
				if (String(this.FirstName.value).isBlank()) {
					alert(message.checkoutFirstName);
					e.stop();
					return;
				}
				if (String(this.LastName.value).isBlank()) {
					alert(message.checkoutLastName);
					e.stop();
					return;
				}
			});
		}
	},
	
	initControls: function() {
		$('CCVInput').addEvents({
			'mouseover': function(){
				var objCoord = this.getCoordinates();
				$('ccvn').set('styles', {
					'top': objCoord.top - 100,
					'left': objCoord.left + objCoord.width + 10
				});
			},
			'focus': function(){
				var objCoord = this.getCoordinates();
				$('ccvn').set('styles', {
					'top': objCoord.top - 100,
					'left': objCoord.left + objCoord.width + 10
				});
			},
			'mouseout': function(){
				$('ccvn').set('styles', {
					'top': -500,
					'left': -500
				});
			},
			'blur': function(){
				$('ccvn').set('styles', {
					'top': -500,
					'left': -500
				});
			}
		});
	}
});

var SendStorage = new Class({
	initialize: function() {
		this.initForms();
		this.initControls();
	},
	
	initForms: function() {
		var form1 = $('sendStorage');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.to.value).isBlank()) {
					alert(message.sendStorageEmails);
					e.stop();
					return;
				}
				if (!String(this.to.value).isEmails()) {
					alert(message.sendStorageWrongEmails);
					e.stop();
					return;
				}
			});
		}
	},
	
	initControls: function() {
		$$('a.removeSendStorage').each(function(el){
			el.addEvent('click', function(e){
				e.stop();
				var table = this.getParent().getParent().getParent().getParent();
				if (confirm(message.sendStorageRemove)) {
					this.getParent().getParent().destroy();
				}
				
				//
				table.getElements('tr').each(function(tr, i){
					if (i > 1 && i%2 == 0) {
						tr.addClass('zebra');
					} else {
						tr.removeClass('zebra');
					}
				});
				
				//
				if ($$('a.removeSendStorage').length == 0) {
					window.location = '/members/storage.php';
				}
			});
		});
		
		$('importAddress').addEvent('click', function(e){
			e.stop();
			var URLStr = 'popup_addressbook.php';
			window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+650+',height='+500+',left='+10+', top='+100+',screenX='+100+',screenY='+100+'');
		});
	}
});

var GetPass = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('getPass');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.Email.value).isBlank()) {
					alert(message.getPassEmail);
					e.stop();
					return;
				}
				if (!String(this.Email.value).isEmail()) {
					alert(message.getPassWrongEmail);
					e.stop();
					return;
				}
			});
		}
	}
});

var Unsubcribe = new Class({
	initialize: function() {
		this.initForms();
	},
	
	initForms: function() {
		var form1 = $('unsubscribeForm');
		
		if (form1) {
			// check form
			form1.addEvent('submit', function(e){
				if (String(this.youremail.value).isBlank()) {
					alert(message.getPassEmail);
					e.stop();
					return;
				}
				if (!String(this.youremail.value).isEmail()) {
					alert(message.getPassWrongEmail);
					e.stop();
					return;
				}
				if (!confirm(message.unsubscribe)) {
					e.stop();
					return;
				}
			});
		}
	}
});

var CommonComponents = new Class({
	initialize: function() {
		this.initControls();
	},
	
	initControls: function() {
		// init checkboxes
		var allCheckboxes = $$('input[name*=IDs]');
		if ($('checkAll') && allCheckboxes.length > 0) {
			allCheckboxes.each(function(el){
				el.addEvent('click', function(e){
					if ($(el.form).getElements('input[name*=IDs]:checked').length == allCheckboxes.length) {
						$('checkAll').checked = 'checked';
					} else {
						$('checkAll').checked = false;
					}
				});
			});
			$('checkAll').addEvent('click', function(e){
				var val = this.checked ? 'checked' : false;
				allCheckboxes.each(function(el){
					el.checked = val;
				});
			});
		}
		
		// input number only
		$$('input.number').each(function(el){
			el.addEvent("keypress", function(e){
	            var evt = new Event(e);
				var key = evt.getCharKey();
	            var re = new RegExp('[0-9.]');
	            if (key != "" && !re.test(key)) {
					evt.stop();
				}
				if (key == '.' && this.value.indexOf('.') != -1) {
					evt.stop();
				}
	        });
		});
		
		// color pickers
		$$('input.picker').each(function(el, index){
			var span = new Element('span', {
				'class': 'bgd1 icon colorPicker'
			}).inject(el, 'after');
			new MooRainbow(span, {
				'id': String('MooRainbow_' + index),
				'startColor': [58, 142, 246],
				'imgPath': '/images/',
				'onChange': function(color, scope) {
					scope.element.getPrevious().value = color.hex;
				}
			});
		});
	}
});

function PageTrigger() {
	if (typeof(message) == 'undefined') {
		alert('Missing language file during deployment. Please check again!');
		return;
	}
	if ($('homeUpload')) {
		new IndexPage();
	}
	if ($('loginBox')) {
		new LoginBox();
	}
	if ($('registerForm')) {
		new RegisterPage();
	}
	if ($('contactForm')) {
		new ContactPage();
	}
	if ($('sendFiles')) {
		new SendFilesPage();
	}
	if ($('editProfile')) {
		new EditProfile();
	}
	if ($('changePassword')) {
		new ChangePassword();
	}
	if ($('helpPage')) {
		new HelpPage();
	}
	if ($('dropBoxForm')) {
		new DropBox();
	}
	if ($('storagePage')) {
		new Storage();
	}
	if ($('userList')) {
		new UserList();
	}
	if ($('addEditUser')) {
		new AddEditUser();
	}
	if ($('addressBook')) {
		new AddressBook();
	}
	if ($('addEditContact')) {
		new AddEditContact();
	}
	if ($('importCVS') || $('cvsList') || $('importContact')) {
		new ImportCSV();
	}
	if ($('checkoutForm')) {
		new CheckoutForm();
	}
	if ($('sendStorage')) {
		new SendStorage();
	}
	if ($('getPass')) {
		new GetPass();
	}
	if ($('unsubscribeForm')) {
		new Unsubcribe();
	}
	// 
	new CommonComponents();
}

window.addEvent('domready', PageTrigger);
})();
