//
//	Created by Luca Orio
//	Copyright (c) 2009 t-immagine. All rights reserved.
//	ver. 0.1
// 

//	reserved area

function checkCredentials()
{
	//	capture the return key
	$("#reservedAreaDiv").bind("keydown", function(e) {
		if (e.keyCode == 13) {
			if ( $("#username").val() == "" || $("#username").val() == "Inserisci il nome utente" || $("#password").val() == "" || $("#password").val() == "Inserisci la password" ) 
			{
				//	da perfezionare con ajax
				alert("inserire username e password");
			}
			else
			{
				postCredentials( $("#username").val(),  $("#password").val() );
			}
			return false;
		}
	});
	
	$("#buttonReservedArea").click(function()
	{

		if ( $("#username").val() == "" || $("#username").val() == "Inserisci il nome utente" || $("#password").val() == "" || $("#password").val() == "Inserisci la password" ) 
		{
			//	da perfezionare con ajax
			alert("inserire username e password");
		}
		else
		{
			postCredentials( $("#username").val(),  $("#password").val() );
		}
	});
	
}

function postCredentials(postUsername, postPassword)
{
	
	dataString = "username=" + postUsername + "&password=" + postPassword;

	$.post("include/reservedArea.php", dataString,
	function(responseString)
	{
		if ( responseString.credentialResponse == "ok"){ credentialOk(responseString.brandManual,responseString.graficheAI2010,responseString.brandImage); }
		else if ( responseString.credentialResponse == "ko"){ credentialKo(); }
	}, "json");
	
}

function credentialOk(url1,url2,url3)
{
	$('#formAreaRiservata').html("<br/><br/><a href='"+url1+"' style='font-size:12px;color:#cc0000'>Clicca qui per scaricare il brand manual di Sweet Years!</a><br/><br/><a href='"+url2+"' style='font-size:12px;color:#cc0000'>Clicca qui per scaricare le GRAFICHE AI 2010!</a><br/><br/><a href='"+url3+"' style='font-size:12px;color:#cc0000'>Clicca qui per scaricare il PDF di SweetYears - Brand Image !</a>");
}

function credentialKo()
{
	alert("username o password errati!");
}