// JavaScript Document

function send(){

	var keyCode;
	
	if(window.event){
		keyCode = window.event.keyCode;
	}
	else if(variable){
		keyCode = variable.which;
	}
	
	if(keyCode == 13){
		document.login.submit();
	}

}

function show(div){
	
/*	document.getElementByID(div).style.display = 'visible';
	el = document.getElementById(div);
	var display = el.style.display ? '' : 'block';
	el.style.display = display;*/
	switch(div){
	
		case "personale":
		  document.getElementById('personale').style.display = 'block';
		  document.getElementById('professionista').style.display = 'none';
		  document.getElementById('societa').style.display = 'none';
		  
		  var divStyled = document.getElementById('reg_pers');
		  var divStyledOff_1 = document.getElementById('reg_pro');
		  var divStyledOff_2 = document.getElementById('reg_soc');
		  /*alert(divStyled.className);*/
		  divStyled.className='reg_persUp';
		  divStyledOff_1.className = 'reg_pro';
		  divStyledOff_2.className = 'reg_soc';
		  /*alert(divStyled.className);*/
		  /*document.getElementById('reg_pers').style.className = 'reg_persUp';
		  document.getElementById('reg_pro').style.className = 'reg_pro';
		  document.getElementById('reg_soc').style.className = 'reg_soc';*/
		break;   
		  
		case "professionista":
		  document.getElementById('personale').style.display = 'none';
		  document.getElementById('professionista').style.display = 'block';
		  document.getElementById('societa').style.display = 'none';
		  
		  var divStyled = document.getElementById('reg_pro');
		  var divStyledOff_1 = document.getElementById('reg_pers');
		  var divStyledOff_2 = document.getElementById('reg_soc');
		  
		  divStyled.className='reg_proUp';
		  divStyledOff_1.className = 'reg_pers';
		  divStyledOff_2.className = 'reg_soc';
		break;
		  
		case "societa":
		  document.getElementById('personale').style.display = 'none';
		  document.getElementById('professionista').style.display = 'none';
		  document.getElementById('societa').style.display = 'block';
		  
		  var divStyled = document.getElementById('reg_soc');
		  var divStyledOff_1 = document.getElementById('reg_pers');
		  var divStyledOff_2 = document.getElementById('reg_pro');
		  
		  divStyled.className='reg_socUp';
		  divStyledOff_1.className = 'reg_pers';
		  divStyledOff_2.className = 'reg_pro';
		break;
		  
	}
	
}

function numeri(campo){
	
	var chiffres = new RegExp("[.0-9]"); /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
	var verif;
	var points = 0;

	for(x = 0; x < campo.value.length; x++){
		
		verif = chiffres.test(campo.value.charAt(x));
		
		if(campo.value.charAt(x) == "."){
			points++;
		}
		
		if(points > 1){
			verif = false; 
			points = 1;
		}
		
		if(verif == false){
			campo.value = campo.value.substr(0,x) + campo.value.substr(x+1,campo.value.length-x+1);
			x--;
		}
		
	}

}

function lettere(campo){
	
	var chiffres = new RegExp("[a-zA-Z]"); /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
	var verif;
	var points = 0;

	for(x = 0; x < campo.value.length; x++){
		
		verif = chiffres.test(campo.value.charAt(x));
		
		if(campo.value.charAt(x) == "."){
			points++;
		}
		
		if(points > 1){
			verif = false; 
			points = 1;
		}
		
		if(verif == false){
			campo.value = campo.value.substr(0,x) + campo.value.substr(x+1,campo.value.length-x+1);
			x--;
		}
		
	}

}

function admTipologia(valore){
	
	var campoIVA = document.form.piva;
	switch(valore){
	
		case '1':
		//alert(valore);
		  campoIVA.value = 'disattivato per privati';
		  campoIVA.disabled = true;
		break; 
		
		case '2':
		//alert(valore);
		  campoIVA.value = '';
		  campoIVA.disabled = false;
		break; 
		
	}
}

function controlloSpedizione(valore){
	
	if(valore == "contrassegno"){
		
		document.getElementById('plus').innerHTML="contrassegno + <b>&euro; 5,00</b>";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#FF9900; color:#FFFFFF;'>Per il pagamento in Contrassegno sono accettati solo i contanti</p>";
		
	} else if(valore == "in sede") {
	
		document.getElementById('plus').innerHTML="presso sede - <b>&euro; 8,00</b>";
		document.getElementById('info').innerHTML="&nbsp;";
	
	} else {
		
		document.getElementById('plus').innerHTML="";
		document.getElementById('info').innerHTML="&nbsp;";
		
	}
	
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    // Format a number with grouped thousands
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/
    // +       version: 809.2411
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     

    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}// }}}

function controlloSpedizione2(tipo, costo){
	
	if(tipo == "contrassegno"){
		
		var tot = costo - 9 + 14;
		var jstot = number_format(tot, '2', ',', '.');
		var jstotSender = number_format(tot, '2', '.', '');
		
		//document.getElementById('plus').innerHTML="contrassegno + <b>&euro; 5,00</b>";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#EFEFEF;'><b>Note: </b><br />- Sono stati aggiunti &euro; 5,00 per spese<br />- Per il pagamento in Contrassegno sono accettati <u>solo contanti</u>.</p>";
		document.getElementById('totale').innerHTML="Totale <strong style='font-size:14px;'>&euro; " + jstot + "</strong>";
		
		// campi calcolo valore
		document.cassa.totale.value=jstotSender;	
		document.cassa.totaleLoyalty.value=jstotSender;
		
	} else if(tipo == "in sede") {
		
		var tot = costo - 9;
		var jstot = number_format(tot, '2', ',', '.');
		var jstotSender = number_format(tot, '2', '.', '');
		
		//document.getElementById('plus').innerHTML="presso sede - <b>&euro; 8,00</b>";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#EFEFEF;'><b>Note: </b><br />- Sono stati detratti i &euro; 9,00 di spese di spedizione</p>";
		document.getElementById('totale').innerHTML="Totale <strong style='font-size:14px;'>&euro; " + jstot + "</strong>";
		
		// campi calcolo valore
		document.cassa.totale.value=jstotSender;	
		document.cassa.totaleLoyalty.value=jstotSender;
	
	} else {
			
		var tot = costo;
		var jstot = number_format(tot, '2', ',', '.');
		var jstotSender = number_format(tot, '2', '.', '');
		
		//document.getElementById('plus').innerHTML="";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#EFEFEF;'><b>Note: </b><br />- Le coordinate le verrano fornite tramite l'e-mail di conferma</p>";
		document.getElementById('totale').innerHTML="Totale <strong style='font-size:14px;'>&euro; " + jstot + "</strong>";
		
		// campi calcolo valore
		document.cassa.totale.value=jstotSender;	
		document.cassa.totaleLoyalty.value=jstotSender;
		document.cassa.totale.value=jstotSender;
		
	}
	
}

function controlloSpedizione3(tipo, costo){
	
	if(tipo == "contrassegno"){
		
		var tot = costo - 9 + 14;
		var jstot = number_format(tot, '2', ',', '.');
		var jstotSender = number_format(tot, '2', '.', '');
		
		//document.getElementById('plus').innerHTML="contrassegno + <b>&euro; 5,00</b>";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#EFEFEF;'><b>Note: </b><br />- <font color='#FF0000'>Non è possibile attualmente acquistare con questa modalità</font></p>";
		document.getElementById('totale').innerHTML="Totale <strong style='font-size:14px;'>&euro; " + jstot + "</strong>";
		document.getElementById('payLink').innerHTML="E' possibile acquistare <u>solo con ritiro in sede</u>";
		
		// campi calcolo valore
		document.cassa.totale.value=jstotSender;	
		document.cassa.totaleLoyalty.value=jstotSender;
		
	} else if(tipo == "in sede") {
		
		var tot = costo - 9;
		var jstot = number_format(tot, '2', ',', '.');
		var jstotSender = number_format(tot, '2', '.', '');
		
		//document.getElementById('plus').innerHTML="presso sede - <b>&euro; 8,00</b>";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#EFEFEF;'><b>Note: </b><br />- Sono stati detratti gli &euro; 8,00 di spese di spedizione</p>";
		document.getElementById('totale').innerHTML="Totale <strong style='font-size:14px;'>&euro; " + jstot + "</strong>";
		document.getElementById('payLink').innerHTML="<a href='javascript:document.cassa.submit()'><strong>concludi acquisto</strong></a> <img src='img/icone/prosegui.png' align='absmiddle' />";
		
		// campi calcolo valore
		document.cassa.totale.value=jstotSender;	
		document.cassa.totaleLoyalty.value=jstotSender;
	
	} else {
			
		var tot = costo;
		var jstot = number_format(tot, '2', ',', '.');
		var jstotSender = number_format(tot, '2', '.', '');
		
		//document.getElementById('plus').innerHTML="";
		document.getElementById('info').innerHTML="<p style='padding:5px; background:#EFEFEF;'><b>Note: </b><br />- <font color='#FF0000'>Non è possibile attualmente acquistare con questa modalità</font></p>";
		document.getElementById('totale').innerHTML="Totale <strong style='font-size:14px;'>&euro; " + jstot + "</strong>";
		document.getElementById('payLink').innerHTML="E' possibile acquistare <u>solo con ritiro in sede</u>";
		
		// campi calcolo valore
		document.cassa.totale.value=jstotSender;	
		document.cassa.totaleLoyalty.value=jstotSender;
		document.cassa.totale.value=jstotSender;
		
	}
	
}

function controlloStato(form){
	var linkList=form;
	//alert(linkList);
	if(linkList=="4"){
		
		document.statoAcquisti.reason.style.display='block';
		document.statoAcquisti.reasonButton.style.display='block';
		
	} else {
		
		document.statoAcquisti.submit();
		
	}
}

function upInfo(content){
	var newdiv = document.createElement('div');
	//var divIdName = 'div'+arguments[0];
	var divIdName = 'divInfo';
	// add-on
	//var left = (screen.width/2) - "500"/2;
	//var top = "220";
	
	newdiv.setAttribute('id',divIdName);
	newdiv.style.width = "auto";
	newdiv.style.height = "auto";
	//newdiv.style.left = 0;//(screen.width/2) - "500"/2;//left;
	//newdiv.style.top = 10;
	newdiv.style.position = "absolute";
	newdiv.style.background = "#EFEFEF";
	newdiv.style.border = "1px solid #034E75";
	//newdiv.innerHTML = '<p style="padding:5px;">this is div number '+arguments[0]+'</p>';
	newdiv.innerHTML = content;
	
	/*var lnk = document.createElement('a');
	if(lnk.addEventListener){
	lnk.addEventListener('click', (function(i){
			 return function(){
				   document.body.removeChild(i)}
			 })(newdiv), false);
	} else
		if(lnk.attachEvent){
		lnk.attachEvent('onclick', (function(i){
				 return function(){
					   document.body.removeChild(i)}
				 })(newdiv));
		}else{
		lnk.onclick = (function(i){
				 return function(){
					   document.body.removeChild(i)}
				 })(newdiv);
	};
	lnk.href = '#';
	lnk.appendChild(document.createTextNode("chiudi"));
	newdiv.appendChild(lnk);*/
	
	document.body.appendChild(newdiv);
}

function popUpRoy(){
	
	var width="600", height="350";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var stile = 'status=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	
	var msgWindow = window.open("royDetails.php", "Royalty", stile);
	
}
