Anastasis.SerenaUtils=function(){}

/**
 * Stampa il contenuto del div 'cosa' (di default 'content') con i css passati
 */
Anastasis.SerenaUtils.print=function(cosa)
{
	if(!cosa) cosa="content";
	var divToPrint=document.getElementById(cosa);
	if(!divToPrint)
	{
		alert("[Anastasis.Utils.print]\nImpossibile stampare il contenuto di "+cosa);
		return;
	}

	var header="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>" +
	  "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='it' lang='it'>" +
	  "<head>" +
	  "<title>Anteprima di stampa</title>"+
	  "<link href='/"+anastasis.servletContext+"/app/Template/metaAmbiente/common.css' rel='stylesheet' type='text/css' />"+
	  "<link href='/"+anastasis.servletContext+"/app/Template/metaAmbiente/print.css' rel='stylesheet' type='text/css' />"+
	  "</head>";

  	header+="<body id='home'>" +
	  	    "<div id='wrap'><div id='main'><div id='da_stampare'><div id='"+cosa+"'>";
	w=window.open("","STAMPA","toolbar=no,menubar=no,personalbar=no,width=800,height=600,resizable=yes,scrollbars=yes,modal=yes,dependable=yes");
	w.document.write(header);
	w.document.write(divToPrint.innerHTML);
	w.document.write("</div></div></div></div></body></html>");
	w.document.close();
	w.print();
}


/**
 * Stampa il contenuto del div 'cosa' (di default 'content') con i css passati
 */
Anastasis.SerenaUtils.getDataDiOggi=function()
{
	var theMonth = new Date().getMonth()+1;
	return new Date().getDate()+"/"+theMonth+"/"+new Date().getFullYear();
}

Anastasis.SerenaUtils.getInputInfo=function(input,info)
{
	var rep="";
	if(document.getElementById("info_"+input.id))
	{
		var infostring=document.getElementById("info_"+input.id).value;
		var reg=new RegExp(info+'=(.*?)(\\||$)');
		var tmp=infostring.match(reg);
		if(tmp) rep=tmp[1];
	}
	if(!rep && document.getElementById(info+"_"+input.id))
	{
		rep=document.getElementById(info+"_"+input.id).value;
	}
	return rep;
}

Anastasis.SerenaUtils.popupMessage=function(title,text,onclose,onopen,width,height,draggable)
{
	$dialog=$('<div title="'+title+'">'+text+"</div>");

	if(!width) width=300;
	if(!height) height=200;

	$dialog.dialog({
			bgiframe: true,
			autoOpen: true,
			width: width,
			height: height,
			modal: true,
			draggable: draggable,
			closeOnEscape: false,
			open: function(event, ui) { if(typeof(onopen)=="function") onopen($dialog); },
			close: function() { if(typeof(onclose)=="function") onclose($dialog); else $(this).remove(); },
			buttons: {
						'Ok': function() {$(this).dialog('close');}
					 }
		});


	return false;
}

Anastasis.SerenaUtils.postFilter=function(url,info)
{
	$form=$("<form>");
	$form.attr("action",url);
	$form.attr("method","POST");
	
	var categorie=info.split("@cat@");
	for(var i=0;i<categorie.length;i++)
	{
		var valori=categorie[i].split("@val@");
		
		var name=valori[0];
		if(name.match(".")) 
		{		
			name=name.split(".");
			name=name[name.length-1];
		}

		var $type=$("<input>");		
		$type.attr("name",name+"type");
		$type.attr("value","and");
		$form.append($type);
		
		for(var h=1;h<valori.length;h++)
		{
			var $input=$("<input>");
			$input.attr("name","KEY_"+name);
			$input.attr("value",valori[h] ? valori[h] : "null");
			$form.append($input);
		}
	}
	
	$("body").append($form);
	$form.submit();
}
