//controllo sul formato del prezzo: accetta . o vorgole e ne esce con punti per mysql
function controllaPrezzo(inValue){
	if ((inValue == "")||(inValue == "0,00")){
	    return "0.00";
   }else{
		var outPrezzo = inValue.replace(",",".");
        if(isNaN(outPrezzo)){
		    outPrezzo = "0.00";
		    //alert("Attenzione! Inserire un valore numerico.");
		    return "KO";
		  }else{
				return outPrezzo;
		  }  
	} 
}

//aprire una finestra centrata nello schermo
function apriFinestra(url, myname, w, h, prop, res) {
 	var winl = (screen.width - w) / 2;
 	var wint = (screen.height - h) / 2;
 	winprops = "scrollbars="+prop+",height="+h+",width="+w+",top="+wint+",left="+winl+",resizable="+res+",status=yes";
	var win;
 	win = window.open(url, myname, winprops);
 if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//apre finestra centrata con la foto grande
function apriZoom(theURL,winName,width,height,features) { //v3.1
    var window_width = width;
    var window_height = height;
    var newfeatures= features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;
    newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + '');
    newWindow.focus();
}

//es onClick= apriFinestra('fotoGrandi.php','".urlencode(DIR_V_DT_IMG)."','".$aDati2[0]['file_4']."','fotoGrande',720,500,1,'yes')


function closeFin(){
	if(confirm("chiudo la finestra?")){
		this.close();
	}
}

function controllaVariante(){
	F=eval(document.selezione);
	ok=true;
	var jId=F.IDvar;
	var jQnt=F.qnt;
	if(ok){
		if((jId.value==0)||(jId.value=='')){
			alert(EId);
			ok=false;
			jId.focus();}}
	if(ok){
		if(isNaN(jQnt.value)||(parseInt(jQnt.value)==0)){
			alert(Eqnt);
			ok=false;
			jQnt.focus();}}	
	if(ok){
		F.submit();
	}		
					
}

//entra una stringa nel supposto formato 000_000 el ne controllo la forma (se non return false) e 
//se tutto ok ne restituisco il numero di pezzi di cui è composta
function CTRLstringa(inStringa){
	var myRegExp=/^[0-9_]+$/;
	if(inStringa==""){
		return true;
	}
	if(myRegExp.test(inStringa)==false){
		return false;
	}
	return true;	
}




function controllaCombinato(){
	F=eval(document.selezione);
	ok=true;
	var jQnt=F.qnt;
	if(ok){
		if(isNaN(jQnt.value)||(parseInt(jQnt.value)==0)){
			alert(Eqnt);
			ok=false;
			jQnt.focus();}}	
	if(ok){
	for(i=0; i < F.elements.length; i++){
		var tmpName=F.elements[i].name;
		tmpArray=tmpName.split('_');
		if(tmpArray[0]=="tessuti"){	
			var massimo=F.elements[(i + 1)].value;
			var jCol=F.elements[(i + 2)].value;
			var jFan=F.elements[(i + 3)].value;
			if(!CTRLstringa(jCol)){
				alert(EStrCol);
				ok=false;
				break;
			}else{
				var aSplitC=jCol.split('_');
				var contoCol=0;
				for(k=0;k < aSplitC.length; k++){
					if(aSplitC[k].length > 0){
						contoCol++;
					}
				}
			}
			if(!CTRLstringa(jFan)){
				alert(EStrFan);
				ok=false;
				break;
			}else{
				var aSplitF=jFan.split('_');
				var contoFan=0;
				for(k=0;k < aSplitF.length; k++){
					if(aSplitF[k].length > 0){
						contoFan++;
					}
				}
			}
			if(contoFan + contoCol != massimo){
				alert(EComb);
				ok=false;
				break;
			}			
		}}
	}//end if ok		
	
	if(ok){
		F.submit();
	}		
}


//CTRLstringa("014_002");