/* -------------------------------------------------------------------------------------------------------------*/
/* ---------------------------------------------- FORMS ACTION--------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

function ConfirmDelete(Message, Url)
{
	if (window.confirm(Message))
	{
		document.location = Url;
	}
    
    return;
}

function findFormIndex (nomeform)
{
	for (i = 0; i < document.forms.length; i++)
	{
		if (document.forms[i].name == nomeform)
		{ break; }
	}
	return i;
}

function PostForm(FormName)
{
    var indexFormToCheck = findFormIndex(FormName);
	var formToCheck = document.forms[indexFormToCheck];
	formToCheck.submit();
    return;
}

function ConfirmAndPost(Message, Url, Form)
{
    if(Message != '')
    {
        if (window.confirm(Message))
        {
            Form.method = "post";
            Form.action = Url;
            Form.submit();
        }
    }else
    {
        Form.method = "post";
        Form.action = Url;
        Form.submit();
    }
    
    return;
}

function cleandefaultvalues(param) {
	if(param != null)
	{
		if(param.value == 'email' || param.value == 'name' || param.value == 'nome' || param.value == 'search')
		{
			param.value = '';
		}
	}
	return true;
}

/*
//////////////////////////////////////////////////////////////////////////// COOKIES
//////////////////////////////////////////////////////////////////////////// COOKIES
//////////////////////////////////////////////////////////////////////////// COOKIES
*/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*
//////////////////////////////////////////////////////////////////////////// TOOLBAR STATE
//////////////////////////////////////////////////////////////////////////// TOOLBAR STATE
//////////////////////////////////////////////////////////////////////////// TOOLBAR STATE
*/

function restore_toolbar_state()
{ 
  var state_cookie = readCookie('editor_toolbar');
  var editorbox = document.getElementById('toolsWrapper');
  if(state_cookie && editorbox)
  {
    var preferences = state_cookie.split('x');

    editorbox.style.left = preferences[0]+'px';
    editorbox.style.top = preferences[1]+'px';
  }
}

function save_toolbar_state()
{
  var position = Position.cumulativeOffset($('toolsWrapper'));
  var preferences = new Array();
  preferences[0] = position[0];
  preferences[1] = position[1];
  
  createCookie('editor_toolbar', preferences.join('x'), 7);
}


