
// utilizzata da editor
// tipo: 0=pagina,1=email,3=allegati
function ApriLinkPagina(id,tipo,target) {
var urlTo="",sWinOption="";
sWinOption = "menubar=0,location=0,status=0,toolbar=0,scrollbars=1,resizable=1,directories=0,titlebar=1";
if (tipo==0) { //pagina
    urlTo = "naviga.php?p="+id;
    switch (target) {
        case 0:
            location.href = urlTo;
            return;
        case 1:
            open(urlTo,"",sWinOption);
            return;
        default:
            open(urlTo,"",sWinOption);
            return;
    }
}
if (tipo==1) { //email
    return;
}
if (tipo==3) { //allegati
    urlTo = "naviga.php?append="+id;
    switch (target) {
        case 0:
            location.href = urlTo;
            return;
        case 1:
            open(urlTo,"",sWinOption);
            return;
        default:
            open(urlTo,"",sWinOption);
            return;
    }
}
return;
}


function ConfermaElimina(sConfirm,idVal,idParam,sUrl) {
var s="";
if (sConfirm=="" || idVal=="")
	return(false);

if (confirm(sConfirm)) {
	s = sUrl + "?" + idParam + "=" + idVal;
	location.href = s;
	return(true);
}
return(false);
}

function ApriLink(strLink,strTarget) {
if (strLink=="")
    return(false);
if (strTarget=="")
    strTarget = "_blank";
window.open(strLink,strTarget);
return;
}

function setMargin(objSet,unita,iTop,iRight,iBottom,iLeft) { 
var margin;
if (unita=="")
    unita="px";
margin = iTop+unita+" "+iRight+unita+" "+iBottom+unita+" "+iLeft+unita+"";
objSet.style.margin = margin;
return;
}

function sleep(ms) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > ms){
      break;
    }
  }
}

function CheckData(strTest,blnInferioreNow) {
var reg_exp = /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/;
if (!reg_exp.test(strTest) || (strTest == "") || (strTest == "undefined") || (strTest == null)) 
    return(false)
//verifica se esiste
arrData = strTest.split("/");
iGiorno = arrData[0];
iMese = arrData[1]-1;
iAnno = arrData[2];
if (iGiorno>31 || iMese>11)
    return(false);
var dtmData = new Date(iAnno,iMese,iGiorno);
if (dtmData.getDate()!=iGiorno || dtmData.getMonth()!=iMese || dtmData.getFullYear()!=iAnno)
    return(false);
var dtmDataNow = new Date();
if (blnInferioreNow && dtmData>dtmDataNow) 
    return(false);
return(true);
}

function CheckEmail(strEmail){    
var er = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;    
if (strEmail=="" || !er.test(strEmail)) {
    return(false);    
    }
return(true);
}

function CheckUrl(strUrl){                                            
var er = /^http:\/\/(www\.)?[a-zA-Z0-9-]{3,}\.[a-zA-Z]{2,}(\/)?$/;    
if (!er.test(strUrl)) {
    return(false);    
    }
return(true);
}

function getBrowserId() { //restituisce un intero in un array corrispondente a un browser
// 0=errore 1=IE 2=Mozilla 3=Chrome 4=Safari 5=opera
var strBrowser="",s="",arrRet=new Array(),arrTemp=new Array(),er;
strBrowser = window.navigator.userAgent.toLowerCase();
strVersion = window.navigator.appVersion;
arrRet[0] = 0;
arrRet[1] = 0;
arrTemp = strVersion.split("(");
arrRet[1] = EliminaSpazi(arrTemp[0]);
s = "msie";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 1;
    return(arrRet); 
}
s = "firefox";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 2;
    return(arrRet);
}
s = "chrome";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 3;
    return(arrRet);
}
s = "safari";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 4;
    return(arrRet);
}
s = "opera";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 5;
    return(arrRet);
}
return(arrRet);
}

function EliminaSpazi(str) { //elimina spazi da una stringa
var ret="",er;
er = / /g;
ret = str.replace(er,'');
return(ret);
}

function CambiaStile(obj,css) { //cambia lo stile di un oggetto
if (obj=="" || obj=="undefined" || obj==null)
	return;
obj.className = css;
return;
}

function ResizeIFrame(ifrmId) {
var browser,ifrm = document.getElementById(ifrmId);
browser = getBrowserId();
if(browser[0]!=2) { //iexplorer e nn ff 
  window.frames[ifrmId].window.scroll(0,0);
  var body = window.frames[ifrmId].document.body;
  if(body) {
	ifrm.style.height = (body.scrollHeight || body.offsetHeight) + 'px';
  }
}
else { //firefox
	ifrm.height = ifrm.contentDocument.body.scrollHeight + "px";
}
} //resize iframe

function AggiornaFrame(ifrmId,strUrl) {
var ifrm = document.getElementById(ifrmId);
ifrm.src = strUrl;
}

function getEstensioneFile(strPath,objFile) { //restituisce l'estensione di un file 
var obj,sFormato="",l=0,p=0;
if (strPath=="" || objFile=="")
	return(sFormato);
obj = document.getElementById(objFile);
if (obj=="undefined" || obj=="")
	return(sFormato);
if (obj.value!="") {
	l = strPath.length;
	p = strPath.lastIndexOf(".");
	sFormato = strPath.substring(p+1,l);
}
return(sFormato);   
}

function CheckCF(cf) {
var validi, i, s, set1, set2, setpari, setdisp;
if( cf == '' )  return(false);
cf = cf.toUpperCase();
if( cf.length != 16 )
	return(false);
validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for( i = 0; i < 16; i++ ){
	if( validi.indexOf( cf.charAt(i) ) == -1 )
		return(false);
}
set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
s = 0;
for( i = 1; i <= 13; i += 2 )
	s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
for( i = 0; i <= 14; i += 2 )
	s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
	return(false);
return(true);
}

function CheckPassword1(strPass,iMin,iMax) { //solo numeri e lettere,iMin=lung min,iMax=lung max
var er;
er = /[a-z0-9]$/;
if (strPass=="" || strPass=="undefined" || strPass=="null")
	return(false);
if (strPass.length<iMin || strPass.length>iMax)
	return(false);
if (!er.test(strPass))
	return(false);
return(true);
}

function ShowElement(objId,blnShow,sDisplay) {
if (blnShow) {
    document.getElementById(objId).style.display = sDisplay;
}
else {
    document.getElementById(objId).style.display = "none";    
}
return;
}

function SetClassName(obj,sClassName) {
if (obj=="" || obj==null)
    return;
obj.className = sClassName;	
return;
}

function boxAvviso(ms) { // il nome del box deve essere "divBoxAvviso"
var obj,code="document.getElementById('divBoxAvviso').style.display = 'none'";
setTimeout(code,ms);
return;
}

function SvuotaSelect(idSelect){
var obj;
obj = document.getElementById(idSelect);

for(i=obj.options.length-1;i>=0;i--)
     obj.remove(i);
     //obj.options[i]=null;
}


    
function ResizeIFrame(ifrmId) {
var browser,ifrm = document.getElementById(ifrmId);
browser = getBrowserId();
if(browser[0]!=2) { //iexplorer e nn ff 
  window.frames[ifrmId].window.scroll(0,0);
  var body = window.frames[ifrmId].document.body;
  if(body) {
    ifrm.style.height = (body.scrollHeight || body.offsetHeight) + 'px';
  }
}
else { //firefox
    ifrm.height = ifrm.contentDocument.body.scrollHeight + "px";
}
} //resize iframe

/*function getBrowserId() { //restituisce un intero in un array corrispondente a un browser
// 0=errore 1=IE 2=Mozilla 3=Chrome 4=Safari 5=opera
var strBrowser="",s="",arrRet=new Array(),arrTemp=new Array(),er;
strBrowser = window.navigator.userAgent.toLowerCase();
strVersion = window.navigator.appVersion;
arrRet[0] = 0;
arrRet[1] = 0;
arrTemp = strVersion.split("(");
arrRet[1] = EliminaSpazi(arrTemp[0]);
s = "msie";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 1;
    return(arrRet); 
}
s = "firefox";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 2;
    return(arrRet);
}
s = "chrome";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 3;
    return(arrRet);
}
s = "safari";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 4;
    return(arrRet);
}
s = "opera";
if (strBrowser.indexOf(s)!=-1)  {
    arrRet[0] = 5;
    return(arrRet);
}
return(arrRet);
}*/
