/*PREPARAZIONE ACQUISTO */

function fillData(idIns, typeIns){
	var modulo=document.forms[0];  
	modulo.idIns.value=idIns;
	modulo.typeIns.value=typeIns;
	if (idIns==''){
		setCheckedGuaranteesPrint();
	}else{
		setCheckedGuarantees(idIns);
	}
			 
} 

function setCheckedGuarantees(idIns){
	var modulo=document.forms[0];
	var guaList=""; 
	for(var i=0;i<modulo.elements.length;i++){
		var chkGua=modulo.elements[i]; 
		if(chkGua.type=="checkbox"){
			if(chkGua.name.indexOf("g_"+idIns+"_")>=0 && chkGua.checked){
				guaList+=chkGua.value+"#";
			}
		}
	}
	if(guaList!="") { guaList=guaList.substr(0, (guaList.length)-1); }
	modulo.guaranteesList.value=guaList;
}

function setCheckedGuaranteesPrint(){
	var modulo=document.forms[0];
	var guaList=""; 
	for(var i=0;i<modulo.elements.length;i++){
		var chkGua=modulo.elements[i]; 
		if(chkGua.type=="checkbox"){
			if(chkGua.name.indexOf("g_")>=0 && chkGua.checked){
				guaList+=chkGua.value+"#";
			}
		}
	}
	if(guaList!="") { guaList=guaList.substr(0, (guaList.length)-1); }
	modulo.guaranteesList.value=guaList;
}

function apri_mod(URL){
	var w = open(URL,"model","scrollbars=1,resizable=1,width=725,height=650, status=0");
	w.focus();
}

function apri_prov(url){
	var w = open(url,"prov","scrollbars=auto,resizable=1,width=675,height=300, status=1");
	w.focus();
}

function generalPopUp(url){	
	var win = open(url,"dettagli","scrollbars=1,resizable=1,width=650,height=500, status=0");
	win.focus();
}

function apriPrint(url,idIns,typeIns,urlSave){	
	var modulo=document.forms[0];
	modulo.target="prev";
	modulo.action=url; 
	fillData(idIns, typeIns)
	var w = open('',"prev","scrollbars=1,resizable=1,width=650,height=500, status=0");
	modulo.submit()
	modulo.action=urlSave; 
	modulo.target="";
	w.focus();
}

function apri_help(url){
  var w = open(url,"help","scrollbars=1,resizable=1,width=650,height=430, status=0");
  w.focus();
}

function trim(str){
	if(typeof(str)!='boolean' && typeof(str)!='number')
		return str.replace(/\s+$|^\s+/g,""); 
	else return str;
}

function ismoney(mioval){
   var s= mioval.value;
   var conta_punti=0;
   var conta_virgola=0;
   var miobool = false;

   for (var i = 0; i<s.length;i++){
	   var c=s.charAt(i);
	   if (c == ","){
		conta_punti = conta_punti + 1;
	   }else if (c == "."){
		   conta_virgola = conta_virgola + 1;
		   alert("Il punto non è ammesso come separatore di cifre.Usare la virgola");
		   mioval.focus();
		   mioval.select();
		   return false;
		   break;
	   }
	}
	if (conta_virgola == 0){
		if ((conta_punti == 1) || (conta_punti == 0)){
			for (var i = 0; i<s.length; i++){
				var c=s.charAt(i);
				if (!((c >= "0") && (c <= "9") || (c == ","))){
					alert("Inserire un valore numerico: decimale separato da una virgola oppure un valore intero.");
					mioval.focus();
					mioval.select();
					return false;
					break;
				}
			}                       
		}
	}
 return true;
}

function isLetter(c){ 
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c){ return ((c >= "0") && (c <= "9"))	}

function isEmail(email){
		var email_format = /^[^@]+@[^@]+\.[a-z]{2,}$/i;
		var ok=true;
		if (email.search(email_format) == -1 || email.search(' ') != -1)
			ok=false;
		return ok; 
}

function isEmpty(inputStr){ 
	if ( (trim(inputStr)=="") || inputStr==null) { return true; }
	return false;
}

function isnumber (s){
		var i;
		for (i=0;i<s.length;i++){
		  var c=s.charAt(i);
		  if (!((c >= "0") && (c <= "9"))){
			 return false;
		   }
		}
		return true;
}

function containValidChar(s){
	var i;
	for (i=0;i<s.length;i++){
		var c=s.charAt(i);
		if (isDigit(c) || (c=='@') || (c=='.') || (c=='_') || (c=='-') || (c=='+') ) {
			return false;
		}
	}
	return true;
}


function apriPopUp(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function bookmark_us(url, title){



        if (window.sidebar) // firefox

            window.sidebar.addPanel(title, url, "");

        else if(window.opera && window.print){ // opera

            var elem = document.createElement('a');

            elem.setAttribute('href',url);

            elem.setAttribute('title',title);

            elem.setAttribute('rel','sidebar');

            elem.click();

        }

        else if(document.all)// ie

            window.external.AddFavorite(url, title);

        }

