/* Copyright by Pineapple - www.pineapple.it                   */
/* Tutti i diritti riservati - Vietata la riproduzione e l'uso non autorizzato */

//GLOBAL
function act(imgName)
{
	if (document.images){ document[imgName].src = eval("j_s_" + imgName + ".src"); }
}

function inact(imgName)
{
	if (document.images) { document[imgName].src = eval("j_m_" + imgName + ".src"); }
}

function LTrim(value) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim(value) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim(value) {
	return LTrim(RTrim(value));
}

function validateMail(oggetto) {
        var s = oggetto.value;
        s = s.replace(/^\s*|\s*$/, "");
        if (s == "undefined" || s.length < 8) {
             alert("La lunghezza dell\'indirizzo EMAIL deve essere di almeno 8 caratteri");
             oggetto.focus();
             return false;
            }
        re = /\s+/
        if (re.test(s)) {
             alert("Gli spazi non sono ammessi all'interno dell\'indirizzo email.");
             oggetto.focus();
             return false;
            }
        re = /^[\w-][\w-]*((\.[\w-]+)+)*@([\w-]+\.)*([\w-]{2,}\.)+([a-zA-Z]{2,4})$/
        if (!re.test(s)) {
             alert("Indirizzo EMAIL non corretto.");
             oggetto.focus();
             return false;
            }
        re = /\.(a[c-gil-oq-uwz]|b[a-bd-jm-or-tvwyz]|c[acdf-ik-orsuvx-z]|d[ejkmoz]|e[ceghr-u]|f[i-kmorx]|g[abd-ilmnp-uwy]|h[kmnrtu]|i[delm-oq-t]|j[emop]|k[eg-imnprwyz]|l[a-cikr-vy]|m[acdghk-z]|n[ace-giloprtuz]|om|p[ae-hk-nrtwy]|qa|r[eouw]|s[a-eg-ort-vyz]|t[cdf-hjkm-prtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[admrw]|com|edu|net|org|mil|gov|biz|pro|aero|coop|info|name|museum|int)$/i
        if (!re.test(s)) {
             alert("Suffisso di dominio inesistente per l'email indicata.");
             oggetto.focus();
             return false;
            }
  return (true);
}

function validateDate(strValue) {
  var objRegExp = /^\d{2}(\-|\/|\.)\d{2}\1\d{4}$/
  var intDay;
  if(!objRegExp.test(strValue))
    return false; 
  else{
    var strSeparator = strValue.substring(2,3)
    var arrayDate = strValue.split(strSeparator);
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
	if (arrayDate[0].substr(0,1)=='0') { intDay = parseInt(arrayDate[0].substr(1,1)) } else { intDay = parseInt(arrayDate[0]); }
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true;
    }
    var intMonth = parseInt(arrayDate[1]);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true;
       }
  }
  return false;
}

function validateCF(cf)
{
	CF = cf.value.toString();
	CF = CF.toUpperCase();

	var valori = new Array("A","0","B","1","C","2","D","3","E","4","F","5","G","6","H","7","I","8","J","9","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var pari = new Array(0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);
	var dispari = new Array(1,1,0,0,5,5,7,7,9,9,13,13,15,15,17,17,19,19,21,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23);
	var resto = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
	var somma = 0;

	for (i=0;i<15;i=i+2) {             
		for (j=0;j<36;j++) {
			if (CF.substr(i,1) == valori[j]) {
				somma = somma + dispari[j];
			}
		}   
	}	

	for (i=1;i<15;i=i+2) {             
		for (j=0;j<36;j++) {
			if (CF.substr(i,1) == valori[j]) {
				somma = somma + pari[j];
			}
		}   
	}	
	
	somma = somma % 26;

	if (CF.substr(15,1) == resto[somma]) {
		return true;
	} else {
		alert('Codice Fiscale errato');
		cf.focus();
		return false;
	}
}

function checkBuyForm(mForm)
{
	if (mForm.nome.value == '') { alert('Il campo nome è vuoto.'); mForm.nome.focus(); return; }
	if (mForm.cognome.value == '') { alert('Il campo cognome è vuoto.'); mForm.cognome.focus(); return; }
	if (mForm.luogonasc.value == '') { alert('Il campo luogo di nascita è vuoto.'); mForm.luogonasc.focus(); return; }	
	if (mForm.provincianasc.value == '') { alert('Il campo provincia di nascita è vuoto.'); mForm.provincianasc.focus(); return; }	
	if (!validateDate(mForm.datanasc.value)) { alert('Riepire il campo Data di Nascita con un valore gg/mm/aaaa'); mForm.datanasc.focus(); return; }	
	if (mForm.nazionalita.value == '') { alert('Il campo nazionalità è vuoto.'); mForm.nazionalita.focus(); return; }			
	if (mForm.indirizzo.value == '') { alert('Il campo indirizzo è vuoto.'); mForm.indirizzo.focus(); return; }		
	if (mForm.cap.value == '') { alert('Il campo CAP è vuoto.'); mForm.cap.focus(); return; }			
	if (mForm.citta.value == '') { alert('Il campo comune è vuoto.'); mForm.citta.focus(); return; }		
	if (mForm.provincia.value == '') { alert('Selezionare la provincia di residenza.'); mForm.provincia.focus(); return; }	
	if (!validateCF(mForm.codicefiscale)) { return; }
	if (mForm.telefono.value == '') { alert('Il campo telefono è vuoto.'); mForm.telefono.focus(); return; }			
		
	if (!validateMail(mForm.email)) { return; }
	if (!mForm.clausolecontratto.checked) { alert('Attenzione\nLa mancata preva visione del regolamento e la sua mancata accettazione non permetteno l\'acquisto della carta Cilento PerTe'); return; }	
	if (!mForm.liberatoria.checked) { alert('Attenzione\nLa mancata accettazione della liberatoria per il trattamento dei dati in rispetto della n.196\\2003\ncomporta l\'impossibilita\' per Pineapple s.n.c. di registrare e mantenere i dati provenienti dal presente modulo elettronico.'); return; }
	
	mForm.submit();
}

function modBuy(mForm)
{
	mForm.action = "acquista_cilento_perte.asp";
	mForm.sop.value = "mod";
	mForm.submit();
}

function checkCPTSupport(mForm)
{
	if (mForm.nome.value == '') { alert('Il campo nome è vuoto'); mForm.nome.focus(); return; }
	if (mForm.cognome.value == '') { alert('Il campo cognome è vuoto'); mForm.cognome.focus(); return; }
	if (!validateMail(mForm.email)) { return; }
	if (mForm.messaggio.value == '') { alert('Scrivi un messaggio nell\'apposito campo di testo'); mForm.messaggio.focus(); return; }	
	mForm.submit();
}

function checkCPTConvenzione(mForm)
{
	if (mForm.nome_azienda.value == '') { alert('Inserisci il nome della tua azienda'); mForm.nome_azienda.focus(); return; }
	if (mForm.nome.value == '') { alert('Il campo nome è vuoto'); mForm.nome.focus(); return; }
	if (mForm.cognome.value == '') { alert('Il campo cognome è vuoto'); mForm.cognome.focus(); return; }
	if (mForm.telefono.value == '') { alert('Il campo telefono è vuoto'); mForm.telefono.focus(); return; }	
	if (!validateMail(mForm.email)) { return; }
	if (mForm.messaggio.value == '') { alert('Scrivi un messaggio nell\'apposito campo di testo'); mForm.messaggio.focus(); return; }	
	mForm.submit();
}

function checkLogin(tForm) {
	if (!validateMail(tForm.login)) { alert('Nome Utente errato'); tForm.login.focus(); return; }	
												
	tForm.submit();
}

function checkAmicoForm(mForm)
{
	if (mForm.tuonome.value == '') { alert('Scrivi il tuo nome'); mForm.tuonome.focus(); return; }
	if (mForm.amico.value == '') { alert('Scrivi il nome del tuo amico'); mForm.amico.focus(); return; }
	if (!validateMail(mForm.emailamico)) { return; }
	mForm.submit();
}


function chiudiFoto()
{
	var obj=document.getElementById('foto_preview');
	obj.style.visibility='hidden';
	obj.style.display="none"; 		
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		fldP.style.visibility="visible"; 
		fldP = document.getElementById('prodotto');
		fldP.style.visibility="visible"; 		
		fldP = document.getElementById('feedback');
		fldP.style.visibility="visible"; 			
	}	
	document.fotop.src = '/img/caricamento.gif';
	hideMask();
}

function showMask() {
	var myWidth = 0, myHeight = 0, myScroll = 0, scrollTop = 0, obj;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	    myScroll = document.body.offsetHeight;
	    scrollTop = document.body.scrollTop;	    
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	    myScroll = document.documentElement.scrollHeight;	
	    scrollTop = document.documentElement.scrollTop;	    	        
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	    myScroll = document.body.scrollHeight;	
	    scrollTop = document.body.scrollTop;	    	    
	  }
	  
	obj = document.getElementById("mask");
	obj.style.width=myWidth.toString() + 'px'; 
	if (myScroll > myHeight)
		obj.style.height=myScroll.toString() + 'px';	
	else
		obj.style.height=myHeight;	
	obj.style.visibility="visible"; 
	obj.style.display="block"; 	
}

function hideMask() {
	var obj;
	obj = document.getElementById("mask");
	obj.style.visibility="hidden"; 
	obj.style.display="none"; 		
}

function mostraFoto(num)
{
	if (document.contactForm) {
		var fldP = document.getElementById('provincia');
		fldP.style.visibility="hidden"; 
		fldP = document.getElementById('prodotto');
		fldP.style.visibility="hidden";
		fldP = document.getElementById('feedback');
		fldP.style.visibility="hidden"; 							
	}
	
	showMask();
	
	document.fotop.src = '/public/pic/big_'+num+'.png';
	
	var myWidth = 0, myHeight = 0, myScroll = 0, scrollTop = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	    myScroll = document.body.offsetHeight;
	    scrollTop = document.body.scrollTop;	  
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	    myScroll = document.documentElement.scrollHeight;	
	    scrollTop = document.documentElement.scrollTop;	    	        
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	    myScroll = document.body.scrollHeight;	
	    scrollTop = document.body.scrollTop;	    	    
	  }
	

	var obj = document.getElementById('foto_preview');
	obj.style.left = ((myWidth - 520) / 2).toString() + 'px'; 
	obj.style.top = (scrollTop + 100).toString() + 'px';
	obj.style.visibility="visible"; 
	obj.style.display="block"; 	
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "cursor:pointer;"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML  
    }
    
    return;
}

function checkIE() {
    if ((version >= 5.5) && (version < 7)) 
    {
    var obj = document.getElementById('checker');
    if (obj) setTimeout("showChecker()", 3000);
    }
}

function showChecker() {
    var obj = document.getElementById("checker");
    if (obj) {
    	obj.innerHTML = "<b>Il browser che stai utilizzando (IE " + version +") non supporta molte nuove funzionalit&agrave; che sono invece messe a disposizione da programmi quali Internet Explorer 7 o Mozilla Firefox 3.<br><br>" + 
    	                "<a href='http://windowsupdate.microsoft.com/' class='menu-link'>Clicca qui per aggiornare la tua copia di Internet Explorer alla versione 7.0 o 8.0</a></b><br>"+
    	                "<div style='width:100%;text-align:right;'>[<a href='javascript:void(0)' onclick='hideChecker();' class='menu-link'>chiudi</a>]</div>";
    	obj.style.display = "block";
    }
}

function hideChecker() {
    var obj = document.getElementById("checker");
    if (obj) obj.style.display = "none";
}

function updateCPTpay(iord, sord, metodo) {
	xmlhttp.open("GET","/include/updateCPTPay.asp?i=" + iord + "&o=" + sord + "&m=" + metodo + "&" + Math.random(), true);
	xmlhttp.onreadystatechange=function() 
	{
	if (xmlhttp.readyState==4) {
		var getResponse =  trim(xmlhttp.responseText);
		return getResponse;
	}
	}
	xmlhttp.send(null)	
	
}

function checkPromoCode(codex) {
	xmlhttp.open("GET","/include/checkPromoCode.asp?c=" + codex + "&" + Math.random(), true);
	xmlhttp.onreadystatechange=function() 
	{
	if (xmlhttp.readyState==4) {
		var getResponse =  trim(xmlhttp.responseText);
		var myCheck = getResponse.split('|');
		if (myCheck.length > 1) {
				if (myCheck[0] == '0') {
					var obj = document.getElementById("codemessage");
					if (obj) obj.innerHTML = '<b>Il Codice &egrave; valido, congratulazioni!</b>';
					obj = document.getElementById("coderesponse");
										
					if (myCheck[1] == 'E') {
						if (obj) {
							obj.innerHTML = '<br><b>Il Codice Rivenditore &egrave; assegnato a: ' +  myCheck[2] + '</b>';					
							obj.style.display = 'block';	
						}
					}
				
					if (myCheck[1] == 'S') {
						if (obj) {
							obj.innerHTML = '<br><b>Il Codice inserito ti offre uno <span class=\"rosso\">sconto di &euro; ' +  myCheck[2] + '</span> sull\'acquisto della carta Cilento PerTe! Approfittane subito...</b>';					
							obj.style.display = 'block';	
						}
					}
					
					//Sconto percentuale
					if (myCheck[1] == 'C') {
						if (obj) {
							obj.innerHTML = '<br><b>Il Codice inserito ti offre uno <span class=\"rosso\">sconto del ' +  myCheck[2] + '</span> sull\'acquisto della carta Cilento PerTe! Approfittane subito...</b>';					
							obj.style.display = 'block';	
						}
					}
					
					if (myCheck[1] == 'P') {
						if (obj) {
							obj.innerHTML = '<br><b>Il Codice Promoter &egrave; assegnato a: ' +  myCheck[2] + '</b>';					
							obj.style.display = 'block';	
						}
					}				
										
				}
		} else {
				if (myCheck[0] == '-2') {
					var obj = document.getElementById("codemessage");
					if (obj) obj.innerHTML = '<b>Per effettuare la verifica, digita il Codice!</b>';				
				} else if (myCheck[0] == '-9') {
					var obj = document.getElementById("codemessage");
					if (obj) obj.innerHTML = '<b>Spiacenti, ma il codice non &egrave; valido!</b>';						
				} else if (myCheck[0] == '-3') {
					var obj = document.getElementById("codemessage");
					if (obj) obj.innerHTML = '<b>Spiacenti, ma il codice non &egrave; pi&ugrave; valido!</b>';						
				}
				
					var obj = document.getElementById("coderesponse");
					if (obj) obj.style.display = 'none';					
		}
		

		return getResponse;
	}
	}
	xmlhttp.send(null)	
}


function showCPTBox(num) {
	var obj;
	for (i=1;i<5;i++) {
	obj = document.getElementById("box"+i);
	obj.style.display = "none";
	}
	obj = document.getElementById("box"+num);
	obj.style.display = "block";	
	
	if (num!=1) {
		obj = document.getElementById("pagaonline");
		obj.style.display = "none";
	} else {
		obj = document.getElementById("pagaonline");
		obj.style.display = "block";
	}
	
}

function checkChangePWD(tForm) {
	var obj = document.getElementById("change_pwd_err");
		
	if (trim(tForm.nuova_password.value) == '') { 
		if (obj) {
			obj.innerHTML = "Errore. Digita la nuova password nella casella di testo!";
			obj.style.display = "block";
			tForm.nuova_password.focus();
			return;
		}
	} 
	else if (tForm.nuova_password.value.length  < 8) { 
			if (obj) {
				obj.innerHTML = "Errore. Digitare una password di almeno 8 caratteri!";
				obj.style.display = "block";
				tForm.nuova_password.focus();
				return;
			}	
	}
	else if (tForm.nuova_password.value != tForm.ripeti_password.value) { 
			if (obj) {
				obj.innerHTML = "Errore. Le password non coincidono!";
				obj.style.display = "block";
				tForm.nuova_password.focus();
				return;
			}
	}
	
	tForm.cambia_pwd.disabled = true;
		
	xmlhttp.open("GET","/include/modificaPasswordUtente.asp?np=" + tForm.nuova_password.value + "&rp=" + tForm.ripeti_password.value + "&" + Math.random(), true);
	xmlhttp.onreadystatechange=function() 
	{
	if (xmlhttp.readyState==4) {
		var getResponse =  trim(xmlhttp.responseText);
		if (getResponse == "0") {

			var resp_obj = document.getElementById("responseBox");
			if (resp_obj) {
				resp_obj.style.visibility = "visible";
				resp_obj.innerHTML = '<img src="/img/button_ok.png" width=48 height=48><br><br><b>Complimenti!<br>L\'operazione di modifica password &egrave; stata effettuato correttamente.</b><br><br><form style="margin:0px;"><input type="button" class="tbut" name="close" value="chiudi" onclick="closeResponse();"></form>';
			}		
				
			tForm.cambia_pwd.disabled = false;			
			tForm.nuova_password.value = "";
			tForm.ripeti_password.value = "";		
		}
		else if (getResponse == "-1") {
			if (obj) {
				obj.innerHTML = "Errore. Si &egrave; verificato un errire inatteso. Riprovare!";
				obj.style.display = "block";
				tForm.nuova_password.focus();
				tForm.cambia_pwd.disabled = false;
				return;
			}
		}
		else if (getResponse == "-2") {
			if (obj) {
				obj.innerHTML = "Errore. Password non corrette!";
				obj.style.display = "block";
				tForm.nuova_password.focus();
				tForm.cambia_pwd.disabled = false;				
				return;
			}
		}
		else if (getResponse == "-3") {
			if (obj) {
				obj.innerHTML = "Errore. Utente non abilitato a questa operazione!";
				obj.style.display = "block";
				tForm.nuova_password.focus();
				tForm.cambia_pwd.disabled = false;				
				return;
			}
		}		
		
	}
	}
	xmlhttp.send(null)	
		
}

function closeResponse() {
	var obj = document.getElementById("responseBox");
	if (obj) {
		obj.innerHTML = '';
		obj.style.visibility = "hidden";
	}
}

function resetPWDErr() {
	var obj = document.getElementById("change_pwd_err");
	if (obj) {
		obj.innerHTML = "";
		obj.style.display = "none";	
	}
}


function evaluatePosition(leftPos)
{
	if (document.body.clientWidth > 900) {
		var calibra = parseInt((document.body.clientWidth - 900) / 2);
		var posizione = leftPos + calibra;
		return posizione;
	}
	else
	{
		return leftPos;
	}
}

function setPositionMarker()
{
	var newPos = evaluatePosition(657);
	var obj=document.getElementById('head_b3_home');
	if (obj) {
		obj.style.left = newPos+'px';
		obj.style.visibility = 'visible';
	}

	
	newPos = evaluatePosition(159);
	obj=document.getElementById('dis-liberatoria');
	if (obj) obj.style.left = newPos+'px';	
	
	newPos = evaluatePosition(600);
	obj=document.getElementById('sms_box');
	if (obj) {
		obj.style.left = newPos+'px';
		obj.style.visibility = 'visible';
	}	
}

function showIndirizzo(n)
{
	var obj = document.getElementById("indirizzo-sped");
	
	if (n==0) 
		if (obj) obj.style.display = "none";

	if (n==1) 
		if (obj) obj.style.display = "block";		
	
}

function showLib()
{
	var obj = document.getElementById("dis-liberatoria");
	obj.style.visibility = 'visible';
	obj.style.display = 'block';
}

function hideLib()
{
	var obj = document.getElementById("dis-liberatoria");
	obj.style.visibility = 'hidden';
	obj.style.display = 'none';
}

function checkMail(tForm) {
	if (!validateMail(tForm.nlmail)) { return; }
	tForm.submit();
}


function showMail(n)
{
	if (n==0) location.href='mailto:info@cilentoperte.it';
}


var t, yTop, smsBoxOpened;
yTop = -292;
smsBoxOpened = false;

function vSMS(n) {
	//if(!smsBoxOpened) getSMSPanel();
	if ((yTop < 62 && !smsBoxOpened) || (yTop > -292 && smsBoxOpened)) { t = setTimeout("sms_docking_move()", n); } else { stopSMS(); }
}

function hideSMS() {
	var obj = document.getElementById("sms_box");
	if (obj) {
		yTop = -292;
		obj.style.top = yTop + 'px';
		smsBoxOpened = false;
		if (smsBoxOpened) { document.dockfrex.src = "/img/dock_su.png"; } else { document.dockfrex.src = "/img/dock_giu.png"; }				
	}
}

function stopSMS() {
	clearTimeout(t);
	smsBoxOpened =  smsBoxOpened ? false : true;
	if (smsBoxOpened) { document.dockfrex.src = "/img/dock_su.png"; } else { document.dockfrex.src = "/img/dock_giu.png"; }		
}

function sms_docking_move() {
	var obj = document.getElementById("sms_box");
	if (obj) {
		if (smsBoxOpened) { yTop = yTop - 3 } else { yTop = yTop + 3 }
		obj.style.top = yTop+'px';
	}
	vSMS(.7);
}

function sendSMS(tForm) {
	tForm.invia_sms.disabled = true;
	
	xmlhttp.open("GET","/include/SMSgatewayCPT.asp?p=" + tForm.prefix.value + "&n=" + tForm.number.value + "&t=" + tForm.msg.value  + "&" + Math.random(), true);
	xmlhttp.onreadystatechange=function() 
	{
	if (xmlhttp.readyState==4) {
		var getResponse =  trim(xmlhttp.responseText);
		clearSMS(getResponse);
	}
	}
	xmlhttp.send(null)	
}

function getSMSPanel() {
	xmlhttp.open("GET","/include/getSMSPanel.asp?&" + Math.random(), true);
	xmlhttp.onreadystatechange=function() 
	{
	if (xmlhttp.readyState==4) {
		var getResponse =  trim(xmlhttp.responseText);
		var obj = document.getElementById("sms_panel");
		if (obj) obj.innerHTML = getResponse;
	}
	}
	xmlhttp.send(null)	
}

function clearSMS(n) {
		var obj = document.getElementById("sms_panel");
		if (obj) {
			if (n == "0") obj.innerHTML = '<br><br><form method="post" action="" name="smsForm" style="margin:0px;"><table border="0" width="190"><tr>' +
			                              '<td colspan="2" align="right"><a href="javascript:void(0)" onclick="hideSMS();"><img src="/img/x_close.png" border="0" alt="Nascondi"></a></td>' +
										  '</tr><tr><td class="tab_head" colspan="2"><b>SMS inviato!</b></td></tr></table>' +
										  '<br><br><img src="/img/button_ok.png" width=48 height=48><br><br><b>Il messaggio &egrave; stato<br>correttamente recapitato al destinatario!<br><br>Il tuo credito &egrave<br>stato scalato di un sms.</b><br><br><form style="margin:0px;"><input type="button" class="tbut" name="new_sms" value="crea nuovo sms" onclick="getSMSPanel();"></form>';
										  
			if (n == "-1") obj.innerHTML = '<br><br><form method="post" action="" name="smsForm" style="margin:0px;"><table border="0" width="190"><tr>' +
			                              '<td colspan="2" align="right"><a href="javascript:void(0)" onclick="hideSMS();"><img src="/img/x_close.png" border="0" alt="Nascondi"></a></td>' +
										  '</tr><tr><td class="tab_head" colspan="2"><b>SMS non inviato!</b></td></tr></table>' +
										  '<br><br><img src="/img/ko.png" width=48 height=48><br><br><b>Attenzione!<br>Il messaggio non &egrave; stato<br>recapitato al destinatario!<br><br>Il tuo credito &egrave rimasto invariato.</b><br><br><form style="margin:0px;"><input type="button" class="tbut" name="new_sms" value="riprova" onclick="getSMSPanel();"></form>';										  
		}	
}

function smsContaCar(smsForm)  {
	conta = 160 - smsForm.msg.value.length;
	var obj = document.getElementById("sms_limit");
	if (obj) obj.innerHTML = conta;	
	if (conta < 0)  {
	    	smsForm.msg.value = smsForm.msg.value.substr(0, 160);
	    	if (obj) obj.innerHTML = "0";
      }
  }

window.onresize = setPositionMarker;

   var savedTarget=null;     
   var orgCursor=null;    
   var dragOK=false;                   
   var dragXoffset=0;                               
   var boxDrag; 
   var frexDx, frexSx;
    
   
 function moveHandler(e){      
 	if (e == null) { e = window.event }       
 	if (e.button<=1&&dragOK&&(e.clientX-dragXoffset)>0){         
 		savedTarget.style.left=e.clientX-dragXoffset+'px';                
 		return false;      
 	}		
 	return;
 }   
 		
function cleanup(e) {      
	document.onmousemove=null;      
	document.onmouseup=null;    
	document.onclick=null;  
	dragOK=false; 
 	frexDx.style.visibility = "hidden";
 	frexSx.style.visibility = "hidden"; 
}  
 		
function dragHandler(e){    
	chargeObject();
 	var htype='-moz-grabbing';      
 	if (e == null) { e = window.event; htype='move';}      
 	 var target = e.target != null ? e.target : e.srcElement;      
     if (target.name == "dockfrex") {  
 	 	savedTarget=boxDrag;                
 	 	dragOK=true;         
 	 	if (boxDrag) {
 	 		frexDx.style.visibility = "visible";
 	 		frexSx.style.visibility = "visible";
	 	 	dragXoffset=e.clientX - parseInt(boxDrag.style.left);           
	 	 	document.onmousemove=moveHandler;         
	 	 	document.onmouseup=cleanup;    
 	 	}   
 	 } 
 	 return;   
}
 
 function chargeObject() {
 	if (!boxDrag) boxDrag = document.getElementById("sms_box"); 
 	if (!frexSx) frexSx = document.getElementById("sxsms"); 
 	if (!frexDx) frexDx = document.getElementById("dxsms"); 
 }
 
 document.onmousedown=dragHandler;