// JavaScript Document
// Scripted by A.M. Bettoni

/*************FUNZIONI DOM********************/

function prendiElementoDaId(id_elemento) {
 var elemento;
 if(document.getElementById)
  elemento = document.getElementById(id_elemento);
 else
  elemento = document.all[id_elemento];
 return elemento;
}

function selezionaLog(id) {
  if (!document.getElementById) return;
  selDiv = document.getElementById(id);
	selDiv.style.fontWeight = "Bold";
}
function deselezionaLog(id) {
  if (!document.getElementById) return;
  selDiv = document.getElementById(id);
		selDiv.style.fontWeight = "Normal";
}

function passaFile(id,valore) {  
var elem=prendiElementoDaId(id);
elem.value=valore;
} 

/*************************************/

/********OPERAZIONI SU STRINGHE*****************/
function cambia(str) {
var strVoid = " n.d. ";
if (str != "") {
str2 = str.replace(/'/g,"''");
} else {
str2 = strVoid;
} 
return str2
}


function estraiPath(str) { 
indice = str.indexOf("/")
strOut = str.substring(str,indice)
}


/***********************************/

/***************CONFERME*********************/

function confermaeliminasistema() {
	stringa="\n\rEliminare il sistema selezionato?\n\rATTENZIONE:\n\rQuesta azione non potrà essere annullata!";
	stringa+="\n\rVerranno eliminati anche tutti i prodotti appartenenti a questa categoria di sistemi...\n\r";
if (confirm(stringa)) {
return true;
	} else {
return false;
	}
}

function eliminaUtente(quale) {
if (confirm("Eliminare il cliente selezionato?")) 	{
strUrl = "_del_utente.asp?id=" + quale;
document.location.replace(strUrl);
}  else {
return false
}  
}

function conferma() {
if (confirm("Procedere con la cancellazione definitiva?"))
 {
return true;
	}  else {
return false;
	}
}

function confermaElimina(){
if (confirm("Eliminare il record selezionato?"))
 {
return true;
	}  else {
return false;
	}
}

function confermastr(str) {
if (confirm(str))
 {
return true;
	}  else {
return false;
	}
}

function sicuro(aux) { 
var str = "Eliminare " + aux + " ?";
return confirm(str);
}
/******************************************/

/*************POP-UP UPLOADS****************/

function chiudiericarica () { 
if (parent.opener){ 
parent.opener.location.reload(); 
self.close();
} else { 
self.close();
} 
} 

function identifica(id_elemento) {
 var elemento;
 if(document.getElementById)
  elemento = document.getElementById(id_elemento);
 else
  elemento = document.all[id_elemento];
 return elemento;
}

function insertFoto() { 
larg=640; 
alt=480; 
toptop=(screen.height/2)-(alt/2); 
leftleft=300;//(screen.width/2)-(larg/2); 
window.open('/_comingsoon/Insimage.asp','dragndropWin','top='+toptop+',left='+leftleft+',width='+larg+',height='+alt+',scrollbars=yes,status=no,location=no,toolbar=no'); 
} 

function caricaFoto() {  
var urlToPop='/_comingsoon/_upload_immagine.asp';
larg=640; 
alt=270; 
toptop=(screen.height/2)-(alt/2); 
leftleft=(screen.width/2)-(larg/2); 
window.open(urlToPop,'uploadImgWin','top='+toptop+',left='+leftleft+',scrollbars=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no');
} 

function popFileAce() { 
file = "/fileace/fileace.asp"
larg=900;
alt=700;
toptop=(screen.height/2)-(alt/2)
leftleft=(screen.width/2)-(larg/2); 
window.open(file,'FileAceWindow','top='+toptop+',left='+leftleft+',scrollbars=yes,resizable=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no'); 
}

function uploadImmagineEditor() {  
var urlToPop='/admin/_upload_immagine.asp';
larg=640; 
alt=270; 
toptop=(screen.height/2)-(alt/2); 
leftleft=(screen.width/2)-(larg/2); 
window.open(urlToPop,'uploadImgWin','top='+toptop+',left='+leftleft+',scrollbars=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no');
} 

function uploadImmagine(id) { 
if ((id=='')||(id=='undefined')) {
alert('Errore nei parametri ID');
return
	} 
var urlToPop='/admin/listino/_upload_immagine_techdata.asp?return='+id;
larg=640; 
alt=270; 
toptop=(screen.height/2)-(alt/2); 
leftleft=(screen.width/2)-(larg/2); 
window.open(urlToPop,'uploadImgWin','top='+toptop+',left='+leftleft+',scrollbars=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no');
} 

function uploadFile(rtrn) {  
if ((rtrn=='')||(!rtrn)) {  
alert('ERRORE PARAMETRI MANCANTI')
return
} 
var urlToPop='/admin/listino/_upload_file.asp?return='+rtrn;
larg=640; 
alt=270; 
toptop=(screen.height/2)-(alt/2); 
leftleft=(screen.width/2)-(larg/2); 
window.open(urlToPop,'uploadFileWin','top='+toptop+',left='+leftleft+',scrollbars=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no');
} 

/*********************************************/

/**************POP-UP FILEMANAGER*************/

function popFileManager() { 
  window.open('/_filemanager/default.asp','FMwindow','scrollbars=yes,resizable=yes,width=790,height=590')
}

function popFileAce(flag) { 
file = "/fileace/fileace.asp"
larg=900;
alt=700;
toptop=(screen.height/2)-(alt/2)
leftleft=(screen.width/2)-(larg/2); 
window.open(file,'FileAceWindow','top='+toptop+',left='+leftleft+',scrollbars=yes,resizable=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no'); 
}

function uploadFileAce() { 
larg=500; 
alt=120; 
toptop=(screen.height/2)-(alt/2); 
leftleft=(screen.width/2)-(larg/2); 
window.open('/_APP/_upload_fileace.asp','uploadFileAceWin','top='+toptop+',left='+leftleft+',scrollbars=no,width='+larg+',height='+alt+',status=no,location=no,toolbar=no'); 
}


function pfilemanager() { 
file = "/_filemanager/default.asp"
larg=770;
alt=550;
toptop=(screen.height/2)-(alt/2)
leftleft=(screen.width/2)-(larg/2); 
window.open(file,'FMWindow','top='+toptop+',left='+leftleft+',scrollbars=yes,resizable=yes,width='+larg+',height='+alt+',status=no,location=no,toolbar=no'); 
}

function apriFM() { 
  window.open('/_filemanager/default.asp','FMwindow','scrollbars=yes,resizable=yes,width=790,height=590')
}

/*******************************************************/

/***************CONTROLLI SU INPUT**************/

function checkAdminLogin() {
if (document.adminlogin.pwd.value != "") {
return true
} else {
alert('Inserite una password valida!!');
document.adminlogin.pwd.value='';
document.adminlogin.pwd.focus();
return false
}
}

function checkLogin() {
missinginfo = "";
if (document.loginform.pwd.value == "") {
missinginfo += "\n\rDOVETE INSERIRE UNA PASSWORD!\n\r";
alert(missinginfo);
return false
} else {
return true
}
}

function checkAggiungiCategoria() {
	var stringa=document.aggiungicategorie.categoria.value
if (stringa!="") 	{
document.aggiungicategorie.categoria.value=stringa.replace(/'/g,"''");
return true
}  else {
alert('\n\rInserire un nome per la nuova categoria!\n\r')
return false
}  
}

function checkFileUpload(aux) {
var el=prendiElementoDaId(aux)
if (el.value == '') {
alert('Selezionate un file!');
return false;
	}  else {
return true;
	}
}
