/**
 * Concact Engine.
 * @auth Sławomir {uGhost} Furgala
 * @mail sfurgala@browserside.pl
 * @version 1.0
 * @require jQuery
 */

	var Contact_impl = function () {
		var obj = this;
		
		this.sending = false;
		
		/**
		 * Initialization method.
		 */
		this.init = function () {
            
		};
		
		/**
		 * Send method - using to send an email.
		 */
		this.send = function () {
			var validation = null;
			
			if (obj.name == "" || obj.mail == "" || obj.phone == "" || obj.www == "" || obj.question == "") {
				validation = false;
				window.alert('Uzupełnij wszystkie pola formularza!');
			} else {
				validation = true;
			}
			
			if (this.sending == false && validation == true) {
				$('#indicator').fadeIn(1000); //showing indicator
				this.sending = true;
				
				$.post('./mail.html', 
					{
						name: obj.name, 
						firm_name: obj.firm_name,
						mail: obj.mail,
						phone: obj.phone,
						www: obj.www,
						budget: obj.budget,
						question: obj.question
					},
					function (data) {
						$('#indicator').fadeOut(1000);
						if (data == 'true') {
							window.alert('Twoje zapytanie zostało wysłane.');
							window.location.href = './index.html';
						} else {
							window.alert('Wystąpił problem z wysłaniem zpaytania.\nSprawdź połączenie z siecią.');
						}
					}
				);
				
			}
		};
		
		/**
		 * Clear method - usead to clear form.
		 */
		this.clear = function () {
			obj.name = null;
			obj.firm_name = null;
			obj.mail = null;
			obj.phone = null;
			obj.www = null;
			obj.budget = null;
			obj.question = null;
		};
		
		//getters and setters
		//#name
		this.__defineGetter__("name", function () { return $('#contact_name').val(); });
		this.__defineSetter__("name", function (value) { return $('#contact_name').val(value); });
		//#firm_name
		this.__defineGetter__("firm_name", function () { return $('#contact_firm_name').val(); });
		this.__defineSetter__("firm_name", function (value) { return $('#contact_firm_name').val(value); });
		//#mail
		this.__defineGetter__("mail", function () { return $('#contact_mail').val(); });
		this.__defineSetter__("mail", function (value) { return $('#contact_mail').val(value); });
		//#phone
		this.__defineGetter__("phone", function () { return $('#contact_phone').val(); });
		this.__defineSetter__("phone", function (value) { return $('#contact_phone').val(value); });
		//#www
		this.__defineGetter__("www", function () { return $('#contact_www').val(); });
		this.__defineSetter__("www", function (value) { return $('#contact_www').val(value); });
		//#budget
		this.__defineGetter__("budget", function () { return $('#contact_budget').val(); });
		this.__defineSetter__("budget", function (value) { return $('#contact_budget').val(value); });
		//#question
		this.__defineGetter__("question", function () { return $('#contact_question').val(); });
		this.__defineSetter__("question", function (value) { return $('#contact_question').val(value); });
		
		return this;
	};
	
	if ($ != undefined) {
        var Contact = new Contact_impl;
            Contact.init();
           
        $(window).bind("load",function(){
            $('#budgetAmount').text('100PLN +');
            $('#slider').slider({min: 100, max : 3500, slide : function (e, o) { $('#budgetAmount').text(o.value + 'PLN +'); }, change : function (e, o) { Contact.budget = o.value; }});
        });
	
	}
	
