// ActionScript Document ----------

function modifica(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}


function filtraCluster(value, cluster_cliente, idOut, msg) {
	
	var url = "./ajax/ajax.php?" ;
	
	var ajaxObj = new ClassAJAX();
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	url += "&action=filtraCluster&valore=" + value + "&cluster_cliente=" + cluster_cliente;
	ajaxObj.runAJAX(url) ;
 	
	var html = "" ;
	var htmlOld = "" ;

	myInterval = window.setInterval(
	function() {
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		if (html != false) {
 
			if (htmlOld == html) {

				window.clearInterval(myInterval);
				var el = document.getElementById(idOut) ;
				el.innerHTML = html ;
				initTmpl() ;
			}
		}
	},100) ;
	
}




function displayDiv(idOut){
   document.getElementById(idOut).style.display="none" ;
}
function reloadPage(idOut){
   document.getElementById(idOut).style.display="none" ;
   location.href='index.php';
}
function submitForm(formName, idOut, msg) {
	
	var the_form = document.getElementById(formName);
	var action = null;
	var url = "./ajax/ajax.php?" ;
	var ext_errors = "" ;
	
	
	
	switch (formName) {
		
		case 'formLogin': 
			action = 'submitLogin'; 
		break ;
		
		case 'onChangeCluster': 
			action = 'onChangeCluster'; 
		break ;
		
		case 'formSearch':
			action = 'submitSearch';
		break ;
		
		case 'formRegistrazioneStep1':
			action = 'checkFormRegistrazioneStep1';		

			try {
				var code_err_1 = "" ;
				var code_err_2 = "" ;
				var ext_errors = "" ;
				if(document.formRegistrazioneStep1.dati_personali[0].checked == false){
					code_err_1 = 1 ;
					ext_errors = 1 ;
				}
				 
				if(document.formRegistrazioneStep1.condizioni_servizio[0].checked == false){
					code_err_2 = 1 ;
					ext_errors = 2
				}
				
				 
				if(code_err_1 == 1 && code_err_2 == 1) {
					ext_errors = 3 ;
				}
			}catch(e){}
	
		break ;
		
		case 'formRegistrazione':
			action = 'formRegistrazione';
		break ;
		
		default: 
			action = 'submitForm';
		break ;
	}
	
 	 
	var ajaxObj = new ClassAJAX();
		ajaxObj.setExecute(false) ;
		ajaxObj.setReturn(true) ;
		
		
		url += "&"+ajaxObj.getUrlParams(the_form) ;
		url += "&action="+action ;
		url += "&ext_errors="+ext_errors ;
		
		//alert(url);
		
		ajaxObj.runAJAX(url) ;
	 	
		var html = "" ;
		var htmlOld = "" ;
	


		myInterval = window.setInterval(
		function() {
			htmlOld = html ;
			html = ajaxObj.getHtml() ;
			if (html != false) {
	 
				if (htmlOld == html) {
	
					window.clearInterval(myInterval);


					if (html != "ok") {
						msg = html ;
					}
					 
					//alert(msg); 
					 
					switch (formName) {
						default :
						displayOutput(idOut, msg) ;
						break ; 
						
						case "formLogin": 
						displayOutputAndReload(idOut, msg) ;
						break;
						
						case "formRegistrazione" :
							document.getElementById(idOut).innerHTML = msg ;
							document.getElementById(idOut).style.display="" ;
							
							
							try{
								if(document.getElementById('esito').value==1){
									reloadPage('"+idOut+"');
									
								}
							}catch(e){}
							
						break ;
						
						case "formRegistrazioneStep1" :
							if(msg == "OK") { 
								eval("document."+formName+".submit() ;") ;
							 
							} else {
								document.getElementById(idOut).innerHTML = msg ;
								document.getElementById(idOut).style.display="" ;
								//centraBox(idOut) ;
							}
						break ;
						
						 
						
					}	
					
				}
	
			} 
			
		}
		,1) ;
	
	 
}

function forceLogout(idOut, msg) {
	
	var action = null;
	var ajaxObj = new ClassAJAX();
	
	ajaxObj.setMethod("POST") ;	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	 	
	ajaxObj.runAJAX('./ajax/ajax.php?action=submitLogout') ;
	
	var html = "" ;
	var htmlOld = "" ;
		
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);
				if (html != "ok") {
					msg = html ;
				}
				
				displayOutputAndReload(idOut, msg) ;
						
			}
			
		} 
	} 
	,1);
}


function displayOutput(idOut, msg) {

	var elem = document.getElementById(idOut) ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	
	//setTimeout(function(){
		elem.style.display="none" ;
	//}, 2000);	
}


function displayOutputAndReload(idOut, msg) {

	var elem = document.getElementById(idOut) ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	
	//setTimeout(function(){
		elem.style.display="none" ;
		location.reload();
	//}, 2000);
}

/*function submitForm(formName, idOut, msg) {
	
	var the_form = document.getElementById(formName);
	var action = null;
	var ajaxObj = new ClassAJAX();
	ajaxObj.setMethod("POST") ;	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.setLoading(false) ;	
	
	switch (formName) {
		//case 'formRegistrazione': action = 'submitForm'; break;
		
		
		default: action = 'submitForm';
	}*/
	/*alert("html non "+ ajaxObj.getUrlParams(the_form));
	alert(the_form.elements.length);*/
/*	ajaxObj.runAJAX('./ajax/ajax.php?'+ajaxObj.getUrlParams(the_form)) ;
	//alert("html non e false");
	var html = "" ;
	var htmlOld = "" ;
		
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);
				if (html != "ok") {
					msg = html ;
					switch (formName) {
						default :
						//displayOutput(idOut, msg) ;
						creaDiv(idOut,msg) ;
						break ; 
						
						case "formLogin": 
						//displayOutputAndReload(idOut, msg) ;
						creaDiv(idOut,msg) ;
						break;
						
					}
					
				}
				else {
					eval ("document."+formName+".submit();") ;	*/
						 	
				 /* var elem = document.getElementById(idOut) ;
				  
				  switch (action) {
				  	
				  	default :
					  	
						elem.style.display="" ;
						elem.innerHTML = msg ;
						alert('ciao');*/
						/*alert(document.getElementById("formRegistrazione").action.value);
						eval ("document."+formName+".action.value='?';");*/
						/*alert(document.getElementById("formRegistrazione").action.value);
						//document.formRegistrazione.write("action='?'")
						document.formRegistrazione.submit();
				   	break;	
					
			*/	
	/*		}		
			}
		} 
	} 
	,1);

}*/

Sleep = function ZZzzzZZzzzzzzZZZz(naptime){
  naptime = naptime * 1000;
  var sleeping = true;
  var now = new Date();
  var alarm;
  var startingMSeconds = now.getTime();
  //alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
  while(sleeping){
     alarm = new Date();
     alarmMSeconds = alarm.getTime();
     if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
  }      
  alert("Wakeup!");
}

function test() {
	return false;	
}

/*

function displayOutputAndPost(idOut, msg) {

	var elem = document.forms[0].value ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	
	setTimeout(function(){
		elem.style.display="none" ;
		
	}, 20);
	document.formRegistrazione.submit();
	
	
}*/

function creaDiv(a,msg){

		var elem = document.getElementById(a);
		
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		
		//var l =( (myWidth - elem.style.width.substr(0,elem.style.width.length - 2)) / 2 ) - (elem.style.width.substr(0,elem.style.width.length - 2) / 2) ;
		var l = (myWidth - elem.style.width.substr(0,elem.style.width.length - 2)) / 2 ;
		var t = scrOfY + ((myHeight - elem.style.height.substr(0,elem.style.height.length - 2)) / 2) ;
			
		elem.style.top = t +'px';
		elem.style.left = l +'px';

		elem.innerHTML = msg ;
		elem.style.display = '' ;
		
		//setTimeout(function(){
			elem.style.display="none" ;
		//	}, 
		//2000);
		
		}
		
function checkForm(idOut) { 
	
	var sw = 0 ;
	var msg = "" ;
 
 	if (document.formRegistrazione.XACCESS01.value =='' ) {
		sw = 1 ;
		msg += "<li>Manca Username.</li>" ;
	}
	if (document.formRegistrazione.XACCESS02.value == '') {
		sw = 1 ;
		msg += "<li>Manca Password.</li>" ;
	}
	if(document.formRegistrazione.XUT04.value == '') {
		sw = 1 ;
		msg += "<li>Manca Nome</li>" ;
	}
 	if (document.formRegistrazione.XUT05.value == '') {
		sw = 1 ;
		msg += "<li>Manca Cognome.</li>" ;
	}	
 	if (document.formRegistrazione.XUT07.value == '') {
		sw = 1 ;
		msg += "<li>Manca l'indirizzo\'.</li>" ;
	}	
 	if (document.formRegistrazione.XUT18.value == '') {
		sw = 1 ;
		msg += "<li>Manca la nazione.</li>" ;
	}
 	if (document.formRegistrazione.XUT09.value == '') {
		sw = 1 ;
		msg += "<li>Manca la regione.</li>" ;
	}	
 	if (document.formRegistrazione.XUT10.value == '') {
		sw = 1 ;
		msg += "<li>Manca la provincia</li>" ;
	}	
 	if (document.formRegistrazione.XUT11.value == '') {
		sw = 1 ;
		msg += "<li>Manca la Localit&aacute;</li>" ;
	}
 	if (document.formRegistrazione.XUT12.value == '') {
		sw = 1 ;
		msg += "<li>Manca il telefono.</li>" ;
	}	
 	
	//controllo email valida 
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(document.formRegistrazione.XUT14.value) || (document.formRegistrazione.XUT14.value == "") || (document.formRegistrazione.XUT14.value == "undefined")|| (document.formRegistrazione.XUT14.value == "0")) {
	sw = 1 ;
	msg += "<li>Email non corretta o mancante.</li>" ;
	}
	
					
	/* result */
	if (sw == 1) {
		
		a=document.getElementById('pippo');
		
		a.innerHTML = 	"<div style=\"background-color:#ff0000;text-align:left;font-size:12px; width:300px;color:#ffffff;border:3px solid #b81010;margin:3px;padding:3px;\" id=\"prova\">" + 
						"<strong style=\"color:#000000;font-size:14px;\">Attenzione:</strong><br><ul style=\"list-style:none; margin:1px; padding:2px;\">" + msg + "</ul>" + 
						"<a href=\"javascript:;\" onclick=\"document.getElementById('"+idOut+"').style.display='none';\" style=\"color:#ffffff;\">chiudi finestra</a></div>" ;
		a.style.display='inline' ; 
		 
		return false ;
	} else {
		return true ;	
	}
}

function checkFormStep2(idOut) { 
	
	var sw = 0 ;
	var msg = "" ;
 
 	if (document.formRegistrazione.XCLI16.value =='' ) {
		sw = 1 ;
		msg += "<li>Manca Dominio.</li>" ;
	}
	if (document.formRegistrazione.CLI01.value == '') {
		sw = 1 ;
		msg += "<li>Manca Settore.</li>" ;
	}
	if(document.formRegistrazione.XCLI17.value == '') {
		sw = 1 ;
		msg += "<li>Manca Titolo</li>" ;
	}
					
	/* result */
	if (sw == 1) {
		
		a=document.getElementById('pippo');
		
		a.innerHTML = 	"<div style=\"background-color:#ff0000;text-align:left;font-size:12px; width:300px;color:#ffffff;border:3px solid #b81010;margin:3px;padding:3px;\" id=\"prova\">" + 
						"<strong style=\"color:#000000;font-size:14px;\">Attenzione:</strong><br><ul style=\"list-style:none; margin:1px; padding:2px;\">" + msg + "</ul>" + 
						"<a href=\"javascript:;\" onclick=\"document.getElementById('"+idOut+"').style.display='none';\" style=\"color:#ffffff;\">chiudi finestra</a></div>" ;
		a.style.display='inline' ; 
		 
		return false ;
	} else {
		return true ;	
	}
}

function centraBox(box) {  
	//var elem = eval("document.getElementById('"+box+"') ;") ;
	var elem = document.getElementById(box) ;	 			
	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}	
	
	 
	 
	 
	var l = (myWidth - elem.clientWidth - 2) / 2 ;
	var t = scrOfY + ((myHeight - elem.clientHeight - 2) / 2) ;
	
 	elem.style.height = elem.clientHeight ;
	elem.style.width = elem.clientWidth ;
			
	elem.style.top = t+"px" ;
	elem.style.left = l+"px" ;
	
	
}

/**
 * drag.js:
 *
 * Adapted from "JavaScript: The Definitive Guide, Fourth Edition".
 *
 * beginDrag() is designed to be called from an onmousedown event handler.
 * elementToDrag may be the element that received the mousedown event, or it
 * may be some containing element.  event must be the Event object for the
 * mousedown event.  This implementation works with both the DOM Level 2
 * event model and the IE Event model.
 **/
function beginDrag(elementToDrag, event) {
    // Compute the distance between the upper-left corner of the element
    // and the mouse click. The moveHandler function below needs these values.
    var deltaX = event.clientX - parseInt(elementToDrag.style.left);
    var deltaY = event.clientY - parseInt(elementToDrag.style.top);

    // Register the event handlers that will respond to the mousemove events
    // and the mouseup event that follow this mousedown event.  
    if (document.addEventListener) {  // DOM Level 2 Event Model
	// Register capturing event handlers
        document.addEventListener("mousemove", moveHandler, true);
	document.addEventListener("mouseup", upHandler, true);
    }
    else if (document.attachEvent) {  // IE 5+ Event Model
	// In the IE Event model, we can't capture events, so these handlers
	// are triggered when only if the event bubbles up to them.
	// This assumes that there aren't any intervening elements that
	// handle the events and stop them from bubbling.
	document.attachEvent("onmousemove", moveHandler);
	document.attachEvent("onmouseup", upHandler);
    }

    // We've handled this event.  Don't let anybody else see it.  
    if (event.stopPropagation) event.stopPropagation();   // DOM Level 2
    else event.cancelBubble = true;                       // IE

    // Now prevent any default action.
    if (event.preventDefault) event.preventDefault();     // DOM Level 2
    else event.returnValue = false;                       // IE

    /**
     * This is the handler that captures mousemove events when an element
     * is being dragged.  It is responsible for moving the element.
     **/
    function moveHandler(e) {
	if (!e) e = window.event;  // IE event model

        // Move the element to the current mouse position, adjusted as
	// necessary by the offset of the initial mouse click.
	elementToDrag.style.left = (e.clientX - deltaX) + "px";
	elementToDrag.style.top = (e.clientY - deltaY) + "px";

	// And don't let anyone else see this event.
	if (e.stopPropagation) e.stopPropagation();       // DOM Level 2
	else e.cancelBubble = true;                       // IE

        // Now prevent any default action.
        if (e.preventDefault) e.preventDefault();     // DOM Level 2
        else e.returnValue = false;                       // IE
    }

    /**
     * This is the handler that captures the final mouseup event that
     * occurs at the end of a drag.
     **/
    function upHandler(e) {
	if (!e) e = window.event;  // IE event model

	// Unregister the capturing event handlers.
	if (document.removeEventListener) {    // DOM Event Model
	    document.removeEventListener("mouseup", upHandler, true);
	    document.removeEventListener("mousemove", moveHandler, true);
	}
	else if (document.detachEvent) {       // IE 5+ Event Model
	    document.detachEvent("onmouseup", upHandler);
	    document.detachEvent("onmousemove", moveHandler);
	}

	// And don't let the event propagate any further.
	if (e.stopPropagation) e.stopPropagation();       // DOM Level 2
	else e.cancelBubble = true;                       // IE
    }
}




function metodiPagamento(){
	
	
	if(document.getElementById('metodoPagamento').style.display==''){
		document.getElementById('metodoPagamento').style.display='none';		
	}else{
		document.getElementById('metodoPagamento').style.display='';	
	}
	
}

function popup(url_pagina,w,h,sw_scroll) {

	
	  /*w = 500;
	  h = 400;*/
	  l = (screen.width - w) / 2;
	  t = (screen.height - h) / 2;
	
	  wnd = window.open(url_pagina,"","fullscreen=0,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+sw_scroll+", resizable=no, width="+w+", height="+h+", left="+l+", top="+t);
	  wnd.focus();		

}


function switchTmpl(codiceTmpl,msg) {
	
		
	var ajaxObj = null ; 
	var html = null ;
	var htmlOld = null ;
	var myInterval = null ;
	
	ajaxObj = new ClassAJAX();	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.setLoading(false) ;
	//alert(codiceTmpl);
	ajaxObj.runAJAX('./ajax/ajax.php?action=switchTmpl&codiceTmpl='+codiceTmpl) ;
	
	var html = "" ;
	var htmlOld = "" ;
		
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);

				/************************************************
				cambio immagine del tmpl
				************************************************/
				var el = document.getElementById('idDivScreenshot') ;
				el.innerHTML = html ;
				aliasShow(codiceTmpl) ;
			}
		}
	},1)
}


function aliasShow(codiceTmpl) {
	
	/************************************************
	mostro gli alias
	************************************************/
	var ajaxObj1 = null ; 
	var html1 = null ;
	var htmlOld1 = null ;
	var myInterval1 = null ;
	
	ajaxObj1 = new ClassAJAX();	
	ajaxObj1.setExecute(false) ;
	ajaxObj1.setReturn(true) ;
	ajaxObj1.setLoading(false) ;
	ajaxObj1.runAJAX('./ajax/ajax.php?action=listTmplAlias&codiceTmpl='+codiceTmpl) ;
	
	var html1 = "" ;
	var htmlOld1 = "" ;
		
	myInterval1 = window.setInterval(
	function() { 
		
		htmlOld1 = html1 ;
		html1 = ajaxObj1.getHtml() ;
		
		if (html1 != false) {
			
			if (htmlOld1 == html1) {
				
				window.clearInterval(myInterval1);

				var el1 = document.getElementById('idDivAlias') ;
				el1.innerHTML = html1 ;									
				 
			}
			
		}
	} 
	,1) ;
		
}
	
 


function selectAliasTmpl(codTmpl,codiceAlias) {
	
	var allAliasBox ;
	var ids ;

	var codiceAliasJs = 'atmpl_' + codiceAlias ;
	
	
	
	/*var currAlias = document.getElementById(codiceAliasJs) ;
	currAlias.style.border='3px solid #CC3399' ; 
	
	
	/*********************************************************
	aggiorno campo alias tmpl in CLITMPL
	*********************************************************/
	var ajaxObj = null ; 
	var html = null ;
	var htmlOld = null ;
	var myInterval = null ;
	
	ajaxObj = new ClassAJAX();	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.setLoading(false) ;
	//alert('./ajax/ajax.php?action=switchTmplImg&codiceAlias='+codiceAlias+'&codiceTmpl='+codTmpl);
	//ajaxObj.runAJAX('./ajax/ajax.php?action=switchTmplImg&codiceAlias='+codiceAlias+'&codiceTmpl='+codTmpl) ;
	ajaxObj.runAJAX('./ajax/ajax.php?action=switchTmpl&codiceAlias='+codiceAlias+'&codiceTmpl='+codTmpl) ;
	
	var html = "" ;
	var htmlOld = "" ;
		
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);

				 var el1 = document.getElementById('idDivScreenshot') ;
				 el1.innerHTML = html ;
				 
			}
							
		}
	} 
	,1) ;
	
}


function inputCode(code) {
			var action = null;
			var ajaxObj = new ClassAJAX();
			
			ajaxObj.setMethod("POST") ;	
			ajaxObj.setExecute(false) ;
			ajaxObj.setReturn(true) ;
			 
			var url = './ajax/ajax.php?action=inputCode&code='+code ;	 	 
			ajaxObj.runAJAX(url) ; 	
			 
			
			var html = "" ;
			var htmlOld = "" ;
				
			myInterval = window.setInterval(
			function() { 
				
				htmlOld = html ;
				html = ajaxObj.getHtml() ;
				
				if (html != false) {
					
					if (htmlOld == html) {
						
						window.clearInterval(myInterval);
						elem = document.getElementById('inputCode_div') ;
						elem.innerHTML = html ;
						elem.style.display='' ; 
						
						if( typeof( window.innerWidth ) == 'number' ) {
							//Non-IE
							myWidth = window.innerWidth;
							myHeight = window.innerHeight;
						} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
							//IE 6+ in 'standards compliant mode'
							myWidth = document.documentElement.clientWidth;
							myHeight = document.documentElement.clientHeight;
						} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
							//IE 4 compatible
							myWidth = document.body.clientWidth;
							myHeight = document.body.clientHeight;
						}
						
						
						var scrOfX = 0, scrOfY = 0;
						if( typeof( window.pageYOffset ) == 'number' ) {
							//Netscape compliant
							scrOfY = window.pageYOffset;
							scrOfX = window.pageXOffset;
						} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
							//DOM compliant
							scrOfY = document.body.scrollTop;
							scrOfX = document.body.scrollLeft;
						} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
							//IE6 standards compliant mode
							scrOfY = document.documentElement.scrollTop;
							scrOfX = document.documentElement.scrollLeft;
						}
						
						//var l =( (myWidth - elem.style.width.substr(0,elem.style.width.length - 2)) / 2 ) - (elem.style.width.substr(0,elem.style.width.length - 2) / 2) ;
						var l = (myWidth - elem.style.width.substr(0,elem.style.width.length - 2)) / 2 ;
						var t = scrOfY + ((myHeight - elem.style.height.substr(0,elem.style.height.length - 2)) / 2) ;
							
						elem.style.top = t +'px';
						elem.style.left = l +'px';
						
								
					}
					
				} 
			} 
			,1);
		}
		
		function releaseCode() {
			var code = document.getElementById('codiceConv').value ;
			var CONV_ID = document.getElementById('CONV_ID').value ;
			var action = null;
			var ajaxObj = new ClassAJAX();
			
			ajaxObj.setMethod("POST") ;	
			ajaxObj.setExecute(false) ;
			ajaxObj.setReturn(true) ;
			 
			var url = './ajax/ajax.php?action=checkCode&CONV_ID='+CONV_ID+'&code='+code ;	 	 
			ajaxObj.runAJAX(url) ; 	
			 
			
			var html = "" ;
			var htmlOld = "" ;
				
			myInterval = window.setInterval(
			function() { 
				
				htmlOld = html ;
				html = ajaxObj.getHtml() ;
				
				if (html != false) {
					
					if (htmlOld == html) {
						
						window.clearInterval(myInterval);
						if(html == "OK") {
							window.opener.document.formRegistrazione.XREG10.value=CONV_ID ;
							self.close();
						} else {
							alert('Il codice non e presente.') ;	
						}		
					}
					
				} 
			} 
			,1);
			
			
		}						



