// JavaScript Document

var AJSprefix=0;

function ajax_request(div_aggiorna,script_server,anti_cache,div_wait,div_proxy,next_function){

var nc;
if (anti_cache=='true'){
script_server=script_server+'&ajax_nc='+nc;	
}
script_server=script_server+'&ajax=1';	
var d = AJS.getRequest(script_server)
d.addCallback(function(res_txt, req) { ajax_wait('normal',div_wait,'proxy',div_aggiorna); document.getElementById(div_aggiorna).innerHTML = res_txt;  AJS.evalScriptTags(res_txt); 
 eval(next_function); div_focus(div_aggiorna);
})
d.addErrback(function(res_txt, req) {  })
ajax_wait('wait',div_wait,div_proxy);
d.sendReq()


}
//--------------------------------------------------------------------------------------------------------------------------------------

function ajax_submit_form(script_server,form,div_wait,div_proxy,next_function,in_div){

var dest_divw=dest_div;
var dest_div="formAJS"+form;
var nformAJS="nformAJS"+form;
var nformAJSval="nformAJSval"+form;

if(AJS.getElement('ajax')) AJS.removeElement(AJS.getElement('ajax'));
AJS.ACN(AJS.getElement(form), AJS.INPUT({id : 'ajax' , name: "ajax" ,value: '1' ,type:"hidden"}));

if(AJS.getElement(nformAJS)) AJS.removeElement(AJS.getElement(nformAJS));
AJS.ACN(AJS.getElement(form), AJS.INPUT({id : nformAJS , name: "nformAJS" ,value: form ,type:"hidden"}));

if(in_div==null) {
AJS.ACN(AJS.getElement(form), AJS.INPUT({id : nformAJSval , name: "nformAJSval",value: "1",type:"hidden"}));}else{
AJS.ACN(AJS.getElement(form), AJS.INPUT({id : nformAJSval , name: "nformAJSval",value: in_div,type:"hidden"}));}

if(AJS.getElement(dest_div)) AJS.removeElement(AJS.getElement(dest_div));

AJS.ACN(AJS.getBody(), AJS.DIV({id: dest_div, style:"display:'none'"},''));


var form_contents = AJS.formContents(form);

AJS.removeElement(AJS.getElement(nformAJSval )); 


for (var propName in form_contents) {
    var value = form_contents[propName];
	value=value.replace(/€/gi, "&#8364;");
	//alert(value);
	form_contents[propName]=value;
}


//if (in_div){dest_div=in_div;}

var d = AJS.getRequest(script_server)
d.addCallback(function(res_txt, req) {ajax_wait('normal',div_wait,'proxy',dest_div); 
									  if (in_div){
										  if (res_txt.match(/<!--AJS_div-->/)) {dest_div=in_div; var v=1;}
										  }
									  document.getElementById(dest_div).innerHTML = res_txt; 
									  if (v==1) {div_focus(in_div);} 
									  AJS.evalScriptTags(res_txt);
									  eval(next_function); 
})
d.addErrback(function(res_txt, req) {  })
ajax_wait('wait',div_wait,div_proxy);
d.sendReq(form_contents)

}
//--------------------------------------------------------------------------------------------------------------------------------------

function ajax_graybox(caption,h,w,script_server,div_proxy,hide){
if(hide)GB_hide();
GB_showCenter(caption,'',w,h);
ajax_request('GB_frame',script_server,'true','GB_frame',div_proxy);
}
//--------------------------------------------------------------------------------------------------------------------------------------

function ajax_wait(stato,div,proxy,aggiornato){

var temp = new Array();
temp = div.split(',');

if(stato=='wait'){  

for(i=0; i < temp.length; i++) {
div=temp[i];
eval("ajax_"+div+"=document.getElementById(div).innerHTML;");
document.getElementById(div).innerHTML=document.getElementById(proxy).innerHTML;
}

}

if(stato != 'wait'){  

if(div!=aggiornato){
for(i=0; i < temp.length; i++) {
div=temp[i];	
document.getElementById(div).innerHTML = eval('ajax_'+div);}
}
}

}

//---------------------------------------------------------------------------------------------------------------------------------------
function vis_div(id,op)
{
document.getElementById(id).style.display = ''+op;
if(op=='') {div_focus(id);}
}
//---------------------------------------------------------------------------------------------------------------------------------------
function form_hide(formName,totStep)
{
var form;
for(i=2; i <= totStep; i++) {
form=formName+'_'+i+'_'+totStep;
AJS.hideElement(AJS.getElement(form));
}
}
//---------------------------------------------------------------------------------------------------------------------------------------
function css_error(url){
var l=document.createElement("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href",url+'form_error.css');
document.getElementsByTagName("head")[0].appendChild(l);
} 
//---------------------------------------------------------------------------------------------------------------------------------------
function form_show(formName,totStep,step)
{
var form;
for(i=1; i <= totStep; i++) {
form=formName+'_'+i+'_'+totStep;
AJS.hideElement(AJS.getElement(form));
}
document.getElementById(formName+'_'+step+'_'+totStep).style.display = '';
div_focus(formName+'_'+step+'_'+totStep);
}
//---------------------------------------------------------------------------------------------------------------------------------------

function div_focus(div)
{
if(AJS.getElement(div))	{
var pos_div = AJS.absolutePosition(AJS.$(div));
var pos_scroll=AJS.getScrollTop();
//var w=AJS.getWindowSize();
var margin=50;
//var x=pos_scroll-w.h;
if (pos_div.y<pos_scroll){
	window.scrollTo(0,(pos_div.y-margin));
	} 

}
}
//---------------------------------------------------------------------------------------------------------------------------------------

function add_error_class(lista_campi,err_form_dec){

var AJS_focus_error=AJS.getElementsByTagAndClassName(null, 'FormError');;

if(AJS_focus_error != undefined){
for (x=0; x<AJS_focus_error.length; x++)
{
AJS.removeClass(AJS.getElement(AJS_focus_error[x].id), 'FormError');
}}

for (x=0; x<lista_campi.length; x++)
{
AJS.addClass(AJS.getElement(lista_campi[x]), 'FormError');
}

AJS_focus_error=AJS.getElementsByTagAndClassName(null, 'FormError'); 
document.getElementById(AJS_focus_error[0].id).focus();

alert(err_form_dec);
}

//---------------------------------------------------------------------------------------------------------------------------------------
function gpval(id,act,val){

if(act=='get'){r=document.getElementById(id).value}
if(act=='put'){document.getElementById(id).value=val}
return r;
}
//---------------------------------------------------------------------------------------------------------------------------------------
function ajs_prefix(resp){
var aEls=document.getElementById(resp).getElementsByTagName("*");
AJSprefix=AJSprefix+1;
for (var iEl = 0; iEl < aEls.length; iEl++)
	{
		
			if (aEls[iEl].id) {document.getElementById(aEls[iEl].id).id=AJSprefix+'+'+aEls[iEl].id;}
	}

}