function chiamaCalendario(nome){
  var ogg = document.getElementById(nome);
  popcal('Seleziona', nome, ogg.value);
}	

function popcal(vCaption, vField, vDate){
	window.open('../calendario/calendario.asp?caption=' + escape(vCaption) + '&field=' + vField + '&date=' + vDate, 'Calendario', 'resizable=no,scrollbars=no,width=300,height=320');
}

function solonumeri(nome){
	var newElements = document.getElementsByName(nome);
	//if (isNaN(newElements[0].value)){ //scommentandola la funzione accetta anche .
		var dato = newElements[0].value;
		var totex = dato.length;
		var ultimo = dato.substring(totex, totex - 1);
		if ( ultimo != '-' && ultimo != '.' && isNaN(ultimo) ){
			newElements[0].value = dato.substring(totex - 1, 0);
		}else{
		  var controllo = dato.split('.');	
		  if (controllo.length >2){
		    newElements[0].value = dato.substring(totex - 1, 0);
		  }
		}	//}
}

function getElementPosition(obj)
{
  var t = 0;
  var l = 0;
  if (obj.offsetParent){
    while (obj.offsetParent){
      t += obj.offsetTop;
      l += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }else if (obj.y && obj.x){
    t += obj.y;
    l += obj.x;
  }
  return {left : l, top : t};
}

function getElementSize(obj)
{
  var w = obj.offsetWidth;
  var h = obj.offsetHeight;
  return {width : w, height : h};
}	

function typb(){
	var out = '';
	var nome = navigator.appName;
	if (nome == 'Microsoft Internet Explorer'){
		out = 'MIE';
	}else if (nome == 'Netscape'){
		out = 'NET';
	}
	return out;
}
strScrivi = '';
strScrivi1 = '';

function paginaCorrente(){
  var ogg = document.getElementById('frmAccessoPagina');
  ogg.value = window.location.href;
}

function accesso(){
  var oggFrm = document.getElementById('frmAccesso');
  var oggL = document.getElementById('login');
  var oggP = document.getElementById('password');
  if (oggL.value == '' || oggP.value == ''){
    alert('Inserire Login e Password per accedere.');
  }else{
    oggFrm.submit();
  }
}

function doSubmit(frm){
  document.getElementById(frm).submit();
}

//aggiunge una voce in elenco alle pagine che hanno
//degli elenchi (esempio : titoli)
//oggetto = l'hidden nella pagina che impsota la aggiunta a true
function aggiungiVoceElenco(oggetto, form){
  document.getElementById(oggetto).value = 'true';
  doSubmit(form);
}

//imposta la pagina per aprire la riga selezionata
//con l oggetto di modifica
//oggettoid = oggetto dove scrivere id
//valoreid = valore id della riga
//form = nome della form
//oggettoflag = oggetto hidden dove mettere true per modifica
function modificaVoceElenco(oggettoId, valoreId, form, oggettoFlag){
    document.getElementById(oggettoId).value = valoreId;
    document.getElementById(oggettoFlag).value = 'true';
    doSubmit(form);
}

//salva l'aggiunta di una nuova voce in elenco
//form = id della form
//percorso = percorso completo di id da dare all'action della form
//valore da dare all'oggetto caso per poi salvare
function salvaNuovaVoceEleneco(form, percorso, caso){
    document.getElementById(form).action = percorso;
    document.getElementById('caso').value = caso;
    doSubmit(form);
}

//salva la modifica di una nuova voce in elenco
//form = id della form
//percorso = percorso completo di id da dare all'action della form
//valore da dare all'oggetto caso per poi salvare
//idmodifica = valore id da modificare
//oggettoId = oggetto hidden dove metter il valore id
function salvaModificaVoceElenco(form, percorso, caso, idmodifica, oggettoId){
  document.getElementById(form).action = percorso;
  document.getElementById('caso').value = caso;
  document.getElementById(oggettoId).value = idmodifica;
  doSubmit(form);
}

function eliminaVoceElenco(idcancella, oggettoid, form, percorso, caso){
  if (confirm('Confermi la cancellazione ?')){
    document.getElementById(oggettoid).value = idcancella;
    document.getElementById(form).action = percorso;
    document.getElementById('caso').value = caso;
    doSubmit(form);
  }
}

//sposta le voci in elenco
//form = id della form
//tipo = 0(giù), 1(su)
//idriga = valore id della riga
//percorso = percorso per la form
//oggettoid = hidden dove salvare l'id
//caso = caso per la pgina successiva
function spostaVociElenco(form, tipo, idriga, oggettoid, percorso, caso){
  document.getElementById(oggettoid).value = idriga;
  document.getElementById(form).action = percorso;
  document.getElementById('caso').value = caso;
  document.getElementById('tipoSpostamento').value = tipo;
  doSubmit(form);
}

function acquisto(pwdAzienda, codiceProdotto, descrProdotto, credito, valoreProdotto, Pos, tipo, c, frmName, importo, brand){
  //transazione = wsTransazione(idazienda, idrv, idcausale, idprodotto, descrProdotto)
  var importoPerConferma = valoreProdotto;
  if (importo > 0){
    importoPerConferma = importo;
}
  if (parseFloat(credito.replace(',','.')) >= parseFloat(importoPerConferma.replace(',','.'))){
    if (confirm('Confermi l\'acquisto di : ' + brand + ' ' + descrProdotto + '?\nImporto: ' + importoPerConferma + ' €')){
      window.open('../transazioni/transazioni_web.asp?w=true&frmName=' + frmName + '&p=' + pwdAzienda + '&cod=' + codiceProdotto + '&i=' + importo + '&l=' + Pos + '&c=' + c + '&t=' + tipo,'acquisto','width=300, height=600, toolbars=yes, resizable=yes, scrollbars=yes');
    }
  }else{
    alert('Il credito a disposizione non è sufficiente per effettuare l\'operazione.');
  }
}

function operazioniPos(pwdAzienda, Pos, tipo){
  window.open('../transazioni/transazioni_web.asp?w=true&p=' + pwdAzienda + '&l=' + Pos + '&t=' + tipo,'acquisto','width=800, height=600, toolbars=yes, resizable=yes, scrollbars=yes');
}


function UCase(StringToUpperCase) { 
    return StringToUpperCase.toUpperCase(); 
}


function cambiaActionForm(idForm,action) { 
    document.getElementById(idForm).action = action; 
}


function verificaPopup(){
  var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
  if (mine == null || typeof (mine) == "undefined" || typeof (mine.closed) == "undefined"){
  }else{    
    alert('I popup del browser sono disabilitati: il sito potrebbe non essere visualizzato correttamente.\n\nSi consiglia di autorizzare i popup per questo sito.')
  }
  mine.close()
}

function checkEmail(str) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(str) == false) {
      //alert('Invalid Email Address');
      return false;
   }
}


function trim(stringa){    
  while (stringa.substring(0,1) == ' '){
	  stringa = stringa.substring(1, stringa.length);
	}
	while (stringa.substring(stringa.length-1, stringa.length) == ' '){
	  stringa = stringa.substring(0,stringa.length-1);
	}
	return stringa;
}

function doRadio(idValore, oggetto){
  var ogg = document.getElementById(oggetto + idValore);
  ogg.checked = true;
}

function verificaPassword(valore, oggetto){
  var chrLettera = 0;
  //chrLettera = valore.charCodeAt(valore.length-1);
  var errore = false;
  for (i=0; i<valore.length;i++ ){
    chrLettera = valore.charCodeAt(i);
    if (chrLettera< 48 || (chrLettera > 57 && chrLettera < 65) || (chrLettera > 90 && chrLettera < 97) || chrLettera > 122){
      errore = true;
    }
  }
  if (errore){    
    document.getElementById('pwdErrore1').innerHTML = "<font color=Red>E\' stato inserito un carattere non valido.</font>";
    document.getElementById('passaControllo').value = 'false';
  }else{
    document.getElementById('pwdErrore1').innerHTML = "<font color=Green>Caratteri validi.</font>";
    document.getElementById('passaControllo').value = 'true';
  }
}

function prelievoMrt(pwdAzienda, Pos, c, importo, m, frmName) {
    var tipo = 'n';
    //transazione = wsTransazione(idazienda, idrv, idcausale, idprodotto, descrProdotto)
    //transazioni.asp?v=090722&l=10808884&p=69804&m=C001194894813948&i=500&t=np&c=5267427740116555&stamp=091008082308
    //var valoreProdotto = importo;
    window.open('../transazioni/transazioni_web.asp?w=true&frmName=' + frmName + '&p=' + pwdAzienda + '&i=' + parseFloat(importo*100) + '&l=' + Pos + '&c=' + c + '&t=' + tipo + '&m=' + m, 'acquistoMrt', 'width=300, height=600, toolbars=yes, resizable=yes, scrollbars=yes');
}
