// Set_Cookie
function Set_Cookie(name,value,expires,path,domain,secure) 
{ 
	/*expires = expires * 60 * 60 * 24 * 1000;
	var today = new Date();
	var expires_date = new Date( today.getTime() + (expires) );
    */
	var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
   
    document.cookie = cookieString; 
}

// toggle_elt 
function toggle_elt()
{
	Effect.toggle('contener_admin','blind')
	$('show_loggin').firstChild.src = ($('contener_admin').visible())? "../img/fleche-off.gif" : "../img/fleche-on.gif";
}

// ajax_failure
function ajax_failure(t)
{
	alert("Failure");
}

// ajax_exception
function ajax_exception(t, o)
{
	alert("onException #" + t.status + "# #" + o + "#");
}
// register
function register()
{
	var query = "login=" + escape($('login').value) + "&pwd=" + escape($('pwd').value);			
	new Ajax.Request("../login.php",
	{
		method       : 'post'
		,postBody    : query
		,onFailure   : ajax_failure
		,onException : ajax_exception
		,onComplete  : get_login
	});
	
}

// get_login
function get_login(t)
{
	var err = t.responseXML.getElementsByTagName("error")[0].firstChild.nodeValue; 
	if(isNaN(err))
	{
		alert(err);
		return;
	}
	
	var key = t.responseXML.getElementsByTagName("key")[0].firstChild.nodeValue;
	Set_Cookie("CARLIPA_ADMIN_UID", key);
	
	window.location.href = "../index.php?page=news";
	
}

// reset
function reset()
{
	Set_Cookie("CARLIPA_ADMIN_UID");
	window.location.reload();

}