/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2008 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 132 2008-05-23 16:05:17Z emartin24 $
 *
 */

var $j = jQuery.noConflict();

$j(document).ready(function(){

	$j('#loginFormLink').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$j.get('/user/loginform/', function(data){
			// create a modal dialog with the data
			$j(data).modal({
				close: false,
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});

	// preload images
	var img = ['button_denied.gif','button_enter.gif','login_form.gif'];
	$j(img).each(function () {
		var i = new Image();
		i.src = '/modal/img/' + this;
	});
});

var contact = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($j.browser.mozilla) {
			$j('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($j.browser.safari) {
			$j('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		var title = $j('#contact-container .contact-title').html();

		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$j('#contact-container .contact-content').animate({
						height: 260
					}, function () {
						$j('#contact-container .contact-title').html(title);
						$j('#contact-container form').fadeIn(200, function () {
						});
					});
				});
			});
		});
	},
	close: function (dialog) {
		$j('#contact-container .contact-message').fadeOut();
		$j('#contact-container form').fadeOut(200);
		$j('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$j.modal.close();
					});
				});
			});
		});
	}
};



function validateLoginForm(f){
	if(f.fldUserName.value == ''){
		alert('Моля, въведете потребителско име.');
		f.fldUserName.focus();
		return false;
	} else if(f.fldPassword.value == ''){
		alert('Моля, въведете парола.');
		f.fldPassword.focus();
		return false;
	}
	return true;
}
