// Funzioni x i Cookie


//#>Leggi
function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{ begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}


//#>Crea
function setCookie(NameOfCookie, value, expiredays)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; path=/";
}


//#>Elimina
function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}


//Funzione che cambia la visubilita di un'id

function expandCollapse(targetId){
if (document.getElementById){
divId = document.getElementById(targetId );
if (divId.style.display == "none"){
divId.style.display = "block";
} else {
divId.style.display = "none";
}
}
}




/************************************************************************************************************
	Conferma l'eliminazione
************************************************************************************************************/	
/*
function canc()
  {
  	return confirm("Sei sicuro di voler effettuare questa operazione?");
  }
  	function ins_image(obj) {
	document.isn.imageup.value = obj;
 }
*/
/************************************************************************************************************
	Resize text area con jquery
************************************************************************************************************/	

jQuery.fn.resizehandle = function() {
  return this.each(function() {
    var me = jQuery(this);
    me.after(
      jQuery('<div class="resizehandle"></div>')
      .bind('mousedown', function(e) {
        var h = me.height();
        var y = e.clientY;
        var moveHandler = function(e) {
          me
          .height(Math.max(20, e.clientY + h - y));
        };
        var upHandler = function(e) {
          jQuery('html')
          .unbind('mousemove',moveHandler)
          .unbind('mouseup',upHandler);
        };
        jQuery('html')
        .bind('mousemove', moveHandler)
        .bind('mouseup', upHandler);
      })
    );
  });
}


$(document).ready(function(){
  $(".resizebleTextarea")
  .resizehandle();
});


/************************************************************************************************************
	Risoluzione video browser
************************************************************************************************************/	

if(getCookie("resolution")==null) setCookie("resolution",window.screen.height + 'x' + window.screen.width);


/************************************************************************************************************
	Assistente	
************************************************************************************************************/	
function selectOptionByValue(ID,val)
{
	var els=document.getElementById(ID);
	for (var i=0;domNode=els[i];i++)
	{
		if (domNode.value==val) break;
	}
		if (domNode) domNode.selected=true;
}

/************************************************************************************************************
	Dialog di conferma
************************************************************************************************************/	

function canc(element) {
	$.prompt('Sei sicuro di voler effettuare questa operazione?',
		{
			buttons:{OK: element.href, Annulla: ''}, 
			callback:function callback(v){if(v) location.href = v;}
		}
	)
	return false;
}



/************************************************************************************************************
	Pop up centrato
************************************************************************************************************/	

function centralpopup(lnk, wight, height) 
{
   if(wight == null)
   		var w = 800;
   else
   		var w = wight;
   
   if(height == null)
 	  var h = 600;
   else
   	  var h = height;
   
   
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open(lnk,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l+",scrollbars=1");
 }
 


