﻿if(typeof com == "undefined") var com = new Object();
if(typeof com.parkside == "undefined") com.parkside = new Object();
if(typeof com.parkside.customer_area == "undefined") com.parkside.customer_area = new Object();

// Constructor
com.parkside.customer_area.login_window = function() {
	
}

/// Static variables
// com.parkside.customer_area.login_window.static_variable = "value";

/// Static methods
// com.parkside.customer_area.login_window.static_method = function() {} ;
com.parkside.customer_area.login_window.global_init = function() {
	$("a.customer-login-link").click( com.parkside.customer_area.login_window.show );
	$(".customer-login-window a#customer_login_link").click( com.parkside.customer_area.login_window.hide );
	$(".customer-login-window input.customer-login-button").click( com.parkside.customer_area.login_window.ajax_login_rq );
	$(".customer-login-window input.customer-login-button").hover( function() { $(this).addClass("customer-login-button-hover"); }, function() { $(this).removeClass("customer-login-button-hover"); } );	
	$(".customer-login-window input.customer-login-button").focus( function() { $(this).blur(); } );
	$(".customer-login-window").click( function(){ return false; } );
	$("body #mainwrapper").prepend($(".customer-login-window"));
	$(".customer-login-window").parent().remove(".customer-login-window");
};

com.parkside.customer_area.login_window.show = function() {
	$(".customer-login-window #customer_login_error").html("").css("display", "none");
	$(".customer-login-window").css("opacity", 0.0).css("display", "block").animate({opacity: 1.0}, 500);
	$(".customer-login-window input[type='text']").focus( com.parkside.customer_area.login_window.text_focus );
	$(".customer-login-window input[type='text']").blur( com.parkside.customer_area.login_window.text_blur );
	$(".customer-login-window input[type='password']").focus( com.parkside.customer_area.login_window.text_focus );
	$(".customer-login-window input[type='password']").blur( com.parkside.customer_area.login_window.text_blur );
	$(".customer-login-window #lost_password_link").click( function() { document.location.href = $(this).attr("href"); return false; } );
	$(document).click( com.parkside.customer_area.login_window.hide );
	return false;
};

com.parkside.customer_area.login_window.hide = function( jqevent ) {
	$(".customer-login-window #customer_login_error").html("").css("display", "none");
	$(".customer-login-window").css("display", "none");
	$(document).unbind( "click", com.parkside.customer_area.login_window.hide )
};

com.parkside.customer_area.login_window.text_focus = function( jq_event ) {
	$(".customer-login-window #customer_login_error").html("").css("display", "none");
	if ( $(this).attr("name") == "dummy_password" ) {
		$(this).css("display", "none");
		$("input[name='password']").css("display", "inline").focus();
	} else	if ($(this).val() == $(this).attr("title")) {
		$(this).val("");
	}
}

com.parkside.customer_area.login_window.text_blur = function( jq_event ) {
	if ($(this).val() == "" ) {
		if ( $(this).attr("name") == "password" ) {
			$(this).css("display", "none");
			$("input[name='dummy_password']").css("display", "inline").val($("input[name='dummy_password']").attr("title"));
		} else {
			$(this).val($(this).attr("title"));
		}
	}
}

com.parkside.customer_area.login_window.ajax_login_rq = function() {
	try {
		$(".customer-login-window #customer_login_error").html("").css("display", "none");
		$.post("ajax.customer-login.htm", $("#login_form").serialize(), com.parkside.customer_area.login_window.ajax_login_rs );
	} catch (ex) {
		console.log ( ex );		
	}
	return false;
}

com.parkside.customer_area.login_window.ajax_login_rs = function( cfc_result ) {
	try {
		cfc_result = $.parseJSON( cfc_result );
		
		if ( cfc_result.ERROR ) {
			$(".customer-login-window #customer_login_error").html(cfc_result.MESSAGE).css("display", "block");
		} else {
			document.location.href = "customer-profile." + cfc_result.LANG + ".htm";
		}
	} catch (ex) {
		console.log ( ex );		
	}
}


/// Class members
com.parkside.customer_area.login_window.prototype = {
	/// class variables
	// variable: value,
	
	/// class methods
	// method: function() {}
}

$(document).ready( com.parkside.customer_area.login_window.global_init );
