var Across = {

    NewLink : '',

    sendM : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=contacts.sendMessage&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#'+i).val(val);
				    });
				}
				else
				{

					Across.actualForm.reset();
					alert(data.message);
				}
			},
			"json"
		);
    },
    
    subscribeNewletter : function (thisFom)
    {
        Across.actualForm = thisFom;
        
        $.post("/", 
			'Func=contacts.subscribeNewsletter&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#'+i).val(val);
				    });
				}
				else
				{

					Across.actualForm.reset();
					alert(data.message);
				}
			},
			"json"
		);
    },

	
    sendRegistration : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.sendRegistration&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					var string = '<ul>';

					jQuery.each(data.items, function(i, val) {
						string += '<li><label for="'+i+'">'+val+'</label></li>';
				    });

					$('#reg-errors').html(string + '</ul>');
				}
				else
				{
					$('#content-right').html( data.message );
				}
			},
			"json"
		);
    },

    sendActivation : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.sendActivation&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					var string = '<ul>';

					jQuery.each(data.items, function(i, val) {
						string += '<li><label for="'+i+'">'+val+'</label></li>';
				    });

					$('#reg-errors').html(string + '</ul>');
				}
				else
				{
					$('#content-right').html( data.message );
				}
			},
			"json"
		);
    },

    doLogin : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.doLogin&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						$('#login-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#login-errors').html(string + '</ul>');
					}
				}
				else
				{
					Across.reloadWin(data.link);
				}
			},
			"json"
		);
    },

    doLostpass : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.doLostpass&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						$('#lostpass-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#lostpass-errors').html(string + '</ul>');
					}
				}
				else
				{
					$('#content-right').html( data.message );
				}
			},
			"json"
		);
    },	

	doPassChange : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.doPassChange&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						$('#passchange-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#passchange-errors').html(string + '</ul>');
					}
				}
				else
				{
					$('#content-right').html( data.message );
				}
			},
			"json"
		);
    },	
		
	doSelfEdit : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.doSelfEdit&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						$('#selfedit-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#selfedit-errors').html(string + '</ul>');
					}
				}
				else
				{
					$('#content-right').html( data.message );
				}
			},
			"json"
		);
    },	
		
	getGuestform : function ()
	{
		$.post("/", 
			'Func=guestbook.getGuestform', 
			function(data) {
				$('#guest-add').html(data);
			},
			"text"
		);
	},

	addGuest : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=guestbook.addGuest&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					if ( data.message )
					{
						$('#guest-errors').html('<p><strong>'+data.message+'</strong></p>');
					}
					else
					{
						var string = '<ul>';

						jQuery.each(data.items, function(i, val) {
							string += '<li><label for="'+i+'">'+val+'</label></li>';
						});


						$('#guest-errors').html(string + '</ul>');
					}
				}
				else
				{
					$('#form-content').html( data.message );
				}
			},
			"json"
		);
	},


	reloadWin : function (to)
	{
		if (to == false)
		{
			window.location = window.location.href;
		}
		else
		{
			window.location = to;
		}
	},

	clearField : function (item)
	{
		return true;
		$(item).attr('value', '');
	},

	back : function ()
	{
		history.go(-1);
	},
	
	getMap : function (address, title) 
	{
		var geocoder = new GClientGeocoder();

		geocoder.getLatLng(
			address,
			function(point)
			{
				if (!point) 
				{
				    $('#map_canvas').css('visibility', 'hidden');
				}
				else 
				{
					Across.ShowMap(point, address, title);
				}
		});
    },

	ShowMap : function (point, address, title)
	{
		var map = new GMap2(  document.getElementById('map_canvas') );

		map.setCenter(point, 13);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml('<strong>' + title + '</strong><br/> '+ address);

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

		$('#map_canvas').css('visibility', 'visible');
	}

};