var modificato = 0;
var condition_ser = 0;	

var index_ord="";//========use for check save order==============max 11_05_07
var index_ord_new="";//========use for check save order==============max 11_05_07
var index_con=""
var index_con_new="";
var index_logical="";
var index_logical_new="";
var text_con="";
var text_con_new="";
var text_note="";
var text_note_new="";
var text_query_desc="";//june 17-12-2007
var text_desc_query="";//june 17-12-2007


var length_con=0;
var condition_ser;
var paren_f="";
var paren_b="";
var paren_f_new="";
var paren_b_new="";
var chk_is=0;
var chk_insertcode=  new Array(); 
var nrow=0;
var inrow= new Array(5,4);
var formula_array=new Array("=","!=","<",">",">=","<=","CONCAT");
var formula_as2=0;

var row_pos = 0;

var old_valore="";


function add_field(FormName,tipo,tipocampo,x,check_view)//Send x to Changename <BOW> 13-12-2007
{

   	opener.modificato = 1;

theForm=document.forms[FormName].elements;

//alert("ddddddd=="+theForm.stringa.value);

var valori_k_node=theForm.stringa.value.split(";");
var valori=theForm.stringa.value.split("{;}");

//alert("valori=="+valori);

if(!check_view){

//##9480komcode##
var k_node_split=valori_k_node[valori_k_node.length-1].split("#");

if(k_node_split[k_node_split.length-1]!=""){
//alert(k_node_split[k_node_split.length-1]);
k_node="#"+k_node_split[k_node_split.length-1];
valori_k_node[1]=valori_k_node[1]+k_node;
} //end if
}
//##9480komcode end##


if(theForm.campo.value!="")
{
	if(tipo=="result")
	{
		var val = valori_k_node[1].replace("}","");
		if(valori_k_node[2])
			val = val+";"+valori_k_node[2];
			
			
	//	alert("val===="+val);
		
			opener.insertResult(valori[0],val,tipocampo,x);//Send x to Changename <BOW> 13-12-2007 // Send tipocampo to check type field 23-09-2008
		
			
		//if(valori[2])
		//	opener.addchiave(valori[2]);
		//var chiavi_collegate=opener.document.getElementById("chiavi_collegate");
		//chiavi_collegate.value=chiavi_collegate.value+";"+valori[0];
	}
	if(tipo=="order")
	{
		 var val2 = valori_k_node[1].replace("}","");
		if(valori_k_node[2])
			val2 = val2+";"+valori_k_node[2];
		opener.insertOrder(valori[0],val2,x);//Send x to Changename <BOW> 13-12-2007
	}
	if(tipo=="condition"){
	    var val1 = valori_k_node[1].replace("}","");
		if(valori_k_node[2])
			val1 = val1+";"+valori_k_node[2];
		opener.insertCondition(valori[0],val1,tipocampo,x);//Send x to Changename <BOW> 13-12-2007
	}
	if(tipo=="formPrivList") {
		var str = valori[0];
		str = str.split("@@");
		opener.insertResult(str[0], str[1]);
	}
}
}
//***********************june add view****01_08_2007********************
function add_field1(FormName,tipo,tipocampo,x)
{
	
	opener.modificato = 1;

theForm=document.forms[FormName].elements;
var valori_k_node=theForm.stringa.value.split(";");
var valori=theForm.stringa.value.split("{;}");
	//##9480komcode  june add 20-12-2007##
//var k_node_split=valori[valori.length-1].split("#");
var k_node_split=valori_k_node[valori_k_node.length-1].split("#");

if(k_node_split[k_node_split.length-1]!=""){
//alert(k_node_split[k_node_split.length-1]);
k_node="#"+k_node_split[k_node_split.length-1];
//valori[1]=valori[1]+k_node;
valori_k_node[1]=valori_k_node[1]+k_node;
} //end if

//##9480komcode end june add 20-12-2007##

	
if(theForm.campo.value!="")
{
	if(tipo=="result")
		//var val = valori[1];
		var val = valori_k_node[1].replace("}","");
		//if(valori[2])
		if(valori_k_node[2])
			val = val+";"+valori_k_node[2];
			
	//alert("val===="+val);
		opener.insertResult1(valori[0],val,x);

		
		//if(valori[2])
		//	opener.addchiave(valori[2]);
		//var chiavi_collegate=opener.document.getElementById("chiavi_collegate");
		//chiavi_collegate.value=chiavi_collegate.value+";"+valori[0];
	
//}
}
}
//******************************************************************



function addchiave(val)
{
	var chiavi_collegate=document.getElementById("chiavi_collegate");
	
	if(chiavi_collegate.value!="")
		chiavi_collegate.value = chiavi_collegate.value+";"
	
	chiavi_collegate.value=chiavi_collegate.value+val;
	//alert(chiavi_collegate.value);
}

function chiudi()
{
	if(modificato)
	//	return(confirm('ATTENZIONE: Uscendo senza salvare perderai tutte le modifiche.\nContinuare?'));
				return(confirm(text_09));

}
// JavaScript Document
/**************************************************************************************/
/* calling to submit this form when user choose table dropdown list */
/**************************************************************************************/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//************june switch select listbox between record with view***********
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////



//********* use in form view_query.php   june*******************//
function doSubmit_view(){
	document.queryform.query_desc.value = document.query.query_desc.value;
	document.queryform.submit();
}


//*********end use in form view_query.php *******************//



function doSubmit(name){
	//  document.queryform.query_desc.value = document.query.query_desc.value;
	 if(name.name=='view'){
 	//alert(name.name);
		window.document.queryform.record.value = 0;
		document.queryform.submit();
	}else if(name.name=='record'){
	 //alert(name.name);
		 window.document.queryform.view.value = 0;
		 document.queryform.submit();
		}	//alert(name.value);
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//********************************end june*********************************//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////**************************************************************************************/
/* check for existing table dropdown list */
/**************************************************************************************/
function isExistTable(){
	//if ((document.queryform.ID_Record.options[document.queryform.ID_Record.selectedIndex].value) == 0) 
		//return false;
	//else 
		return true;
}

function displayWarning(){
		if(document.queryform.ID_Record.options[document.queryform.ID_Record.selectedIndex].value == 0){
			alert(text_01);
			document.queryform.ID_Record.focus();
		}

}
/**************************************************************************************/
/* if existing table dropdownlist then insertResult otherwise alert */
/**************************************************************************************/
function doCreate_Result(field_pos,value){
	
	var existTable = isExistTable();
	
	if (existTable == true) {
		//removeOptionSelected("field[]");	//11 October 2005
		showOnlyNotDisplayList("field[]", 0); // 0 is result	11 October 2005

		if(TEMP_OPTION_VALUE[field_pos].length > 0){ 
			insertResult(value);
		}
	}

	else displayWarning();
}
/**************************************************************************************/
/* if existing table dropdownlist then insertCondition otherwise alert */
/**************************************************************************************/
function doCreate_Condition(){
	var existTable = isExistTable();

	if (existTable == true) insertCondition();
	else displayWarning();
}
/**************************************************************************************/
/* if existing table dropdownlist then insertOrder otherwise alert */
/**************************************************************************************/
function doCreate_Order(field_pos){
	var existTable = isExistTable();

	var selectlist = document.getElementsByName("field[]"); // order list that display on screen	
	var orderlist = document.getElementsByName("field2[]"); // order list that display on screen

	if (existTable == true) {
//	removeOptionSelected("field2[]");		11 October 2005
		showOnlyNotDisplayList("field2[]", 2); // 2 is order

		if(selectlist.length>0){
			insertOrder();
		}
	}
	else displayWarning();
}
/**************************************************************************************/
/* if existing table dropdownlist then deleteResult otherwise alert */
/**************************************************************************************/
function doDelete_Result(theForm,v){
	//alert(theForm.value)
	
	modificato=1;
	if(!v){
	re_vis()
	}
	if(v=="view"){
		//alert(v)
		deleteResult(theForm,v);
	}else{
		var accese_del = count_accessDel();//check vis for function check delete<bow>
		var doDel=check_delete(theForm,accese_del,v)//check delete<bow>
		if(doDel){
			deleteResult(theForm);
		}else{
			alert(text_30);
			//alert(text_30);
		}
	}
}
function doDelete_Result1(theForm,v){
	//alert(theForm.value)
	modificato=1;
//	if(!v){
//	re_vis()
//	}
//	var accese_del = count_accessDel();//check vis for function check delete<bow>
//	var doDel=check_delete(theForm,accese_del,v)//check delete<bow>
//	if(doDel){
		deleteResult(theForm);
//	}else{
//		alert(text_30);
//		//alert(text_30);
//	}
}
/**************************************************************************************/
/* if existing table dropdownlist then deleteCondition otherwise alert */
/**************************************************************************************/
function doDelete_Condition(theForm){
	modificato=1;
	deleteCondition(theForm);
	
}
/**************************************************************************************/
/* if existing table dropdownlist then deleteOrder otherwise alert */
/**************************************************************************************/
function doDelete_Order(theForm){
	
	modificato=1;
	deleteOrder(theForm);

}
/**************************************************************************************/
/* countElements is the function that count number of element in form with 1 parameter */
/* 1. position of form */
/**************************************************************************************/
function countElements(form){
	return document.forms[form].length;
}


function checkoperator(row,type)
{
	 //alert("row=="+row)
		var list;
		var operator;
		
		var testo = document.getElementById('text'+row);
		//alert("testo=="+testo)
		var valore_testo = testo.value;
		
		//alert("valore_testo=="+valore_testo)
		list = document.getElementById("op["+(row-1)+"]");
		//alert("list*******"+list.value)
		check = document.getElementById("type["+(row-1)+"]");
		//alert("check=="+check)
		if(check.checked==true)disabled="disabled";else disabled="";
		operator = list.options[list.selectedIndex].value;
		
		span = document.getElementById("SPAN"+row);
		
		//alert(span);
		if(operator == "><")
		{
			//tbody = document.getElementById("tcondition"); 
			//tbody.rows[row].cells[4].innerHTML="<div align=right>tra <input style='font-size:9px;' type='text' name='var["+(row-1)+"]' size=10 id='text"+row+"' "+disabled+" value='"+valore_testo+"'><br>e <input style='font-size:9px;' type='text' name='var_2["+(row-1)+"]'  size=10 id='text"+row+"_2' "+disabled+"></div>"; 
			if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
			//alert("Hear1")
			span.innerHTML="<div align=right>"+text_28+"<input style='font-size:9px;' type='text' name='var["+(row-1)+"]' size=10 id='text"+row+"' "+disabled+" value='"+valore_testo+"' onblur=\"doDate(this);setvalue_var("+(row-1)+",1);\"><br>"+text_29+" <input style='font-size:9px;' type='text' name='var_2["+(row-1)+"]'  size=10 id='text"+row+"_2' "+disabled+" onblur=\"doDate(this);setvalue_var("+(row-1)+",2);\"> <input type='hidden' id='text_name[]' name='text_name[]' value='"+row+"'><input type ='hidden' value='"+valore_testo+"' name='hid_var["+(row-1)+"]' id='hid_var["+(row-1)+"]'><input type ='hidden'  name='hid_var2["+(row-1)+"]' id='hid_var2["+(row-1)+"]'></div>";
			}else{
			//alert("Hear2")
			span.innerHTML="<div align=right>"+text_28+"<input style='font-size:9px;' type='text' name='var["+(row-1)+"]' size=10 id='text"+row+"' "+disabled+" value='"+valore_testo+"' onblur=\"setvalue_var("+(row-1)+",1);\"><br>"+text_29+" <input style='font-size:9px;' type='text' name='var_2["+(row-1)+"]' size=10 id='text"+row+"_2'"+disabled+" onblur=\"setvalue_var("+(row-1)+",2)\"> <input type='hidden' id='text_name[]' name='text_name[]' value='"+row+"'><input type ='hidden' value='"+valore_testo+"' name='hid_var["+(row-1)+"]' id='hid_var["+(row-1)+"]'><input type ='hidden' name='hid_var2["+(row-1)+"]' id='hid_var2["+(row-1)+"]'></div>"; 
			}
			
	var selectlist = document.getElementsByName("decode[]");
		var op_name = document.getElementsByName("op[]");
		
//****************edit 28_08_2007	***************
var row_con=row-1;

     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
				
		if(document.getElementById('op['+op_name[j].value+']').value!="IS"){
		
		   selectlist(j).value="0";
			//alert(row_con);
		    document.getElementById("type["+row_con+"]").style.visibility="visible";
		   
		}
		
	}	
//****************END edit 28_08_2007	***************			
		
/*######old##############        	
     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
				
		if(document.getElementById('op['+op_name[j].value+']').value!="IS"){
		    
		    selectlist(j).value="0";
		    document.getElementById("type["+j+"]").style.visibility='visible';
		   
		}
		
	}		
	*/
     var decode_no = document.getElementsByName("no_decode[]");
	for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		if(decode_no[j].value!=0){
			
			selectlist(j).value="1";
		}
		 
				 
		}
		
			//alert( tr_length("myCondition")-1);
		}
		//=======================add new conditons=====================================
		else if(operator == "IS")
		{
		//span.innerHTML= insCondi();
		var myCondi;

        myCondi = "<select id='text"+row+"' name='var["+(row-1)+"]'>" ;
       	myCondi = myCondi + "<option value=\"NULL\" selected>"+text_31+"</option>";
       	myCondi = myCondi + "<option value=\"NOT NULL\">"+text_32+"</option>";
        myCondi = myCondi + "</select>";
		 myCondi = myCondi + "<input type='hidden' id='text_name[]' name='text_name[]' value='"+row+"'><input type ='hidden' value='NULL' name='hid_var["+(row-1)+"]' id='hid_var["+(row-1)+"]'>"; 
        span.innerHTML= myCondi;
		 	
		//===========Use for check if select operator 'IS' =========max===
	var selectlist = document.getElementsByName("decode[]");
	var op_name = document.getElementsByName("op[]");
		
	//****************edit 28_08_2007	***************
var row_con=row-1;		

     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		if(document.getElementById('op['+op_name[j].value+']').value=="IS"){
			
		       selectlist(j).value="0";//june 06_09_2007
			//selectlist(j).value="1";old
		
		   document.getElementById("type["+row_con+"]").style.visibility="hidden";
		    }
	}	
//****************END edit 28_08_2007	***************			
		
		
 /*############old############3       	
     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
				
		if(document.getElementById('op['+op_name[j].value+']').value=="IS"){
		    
		    selectlist(j).value="1";
		    document.getElementById("type["+j+"]").style.visibility='hidden';
		   
		}
		
	}	
      */  	
   /*  for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		
		
		if(document.getElementById('op['+j+']').value=="IS"){
		    
		    selectlist(j).value="1";
		   
		}
		
	}*/
        		
        	    
        		
        
	
		}
		//=======================end =================================================
		
		else
		{
			//tbody = document.getElementById("tcondition");
			//tbody.rows[row].cells[4].innerHTML="<input type='text' name='var["+(row-1)+"]' size='15' id='text"+row+"' "+disabled+" value='"+valore_testo+"'>"; 
			if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
			//alert("Hear3")
			span.innerHTML="<input type='text' name='var["+(row-1)+"]' size='15' id='text"+row+"' "+disabled+" value='"+valore_testo+"' onblur=\"doDate(this);setvalue_var("+(row-1)+",1);\"> <input type='hidden' id='text_name[]' name='text_name[]' value='"+row+"'><input type ='hidden' value='"+valore_testo+"' name='hid_var["+(row-1)+"]' id='hid_var["+(row-1)+"]'>"; 
			}else{
			//alert("Hear4")
			span.innerHTML="<input type='text' name='var["+(row-1)+"]' size='15' id='text"+row+"' "+disabled+" value='"+valore_testo+"' onblur='setvalue_var("+(row-1)+",1);'> <input type='hidden' id='text_name[]' name='text_name[]' value='"+row+"'><input type ='hidden' value='"+valore_testo+"' name='hid_var["+(row-1)+"]' id='hid_var["+(row-1)+"]'>"; 
			}
			
			
			
	var selectlist = document.getElementsByName("decode[]");
	var op_name = document.getElementsByName("op[]");
		
//****************edit 28_08_2007	***************
var row_con=row-1;		
/*if(row==1){
	 row=3;
}*/

     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		
		if(document.getElementById('op['+op_name[j].value+']').value!="IS"){
		    selectlist(j).value="0";
			// alert(row_con);
		    document.getElementById("type["+row_con+"]").style.visibility="visible";
		   
		}
		
	}
//****************END edit 28_08_2007	***************		
		
 /*#####old##########       	
     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
				
		if(document.getElementById('op['+op_name[j].value+']').value!="IS"){
		    
		    selectlist(j).value="0";
		    document.getElementById("type["+j+"]").style.visibility='visible';
		   
		}
		
	}
	*/
	var decode_no = document.getElementsByName("no_decode[]");
	for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		if(decode_no[j].value!=0){
			
			selectlist(j).value="1";
		}
		 
				 
		}

	
		}
//re_condition(row)

}

/**************************************************************************************/
/* insertOperator is function that build dropdown list Operator by  */
/**************************************************************************************/
//Update 18-01-2008 Tu
function SelectOperaValue(ArrTextOp)
{	
	var ArrayValue=new Array();
	for(x in ArrTextOp)
	{
		var SplitValue=ArrTextOp[x].split("|");
		switch(SplitValue[1])
		{
			case "1":
				ArrayValue[x]="LIKE";
				break;
			case "2":
				ArrayValue[x]="><";
				break;
			case "3":
				ArrayValue[x]="!=";
				break;
			case "4":
				ArrayValue[x]="LIKEBEFORE";
				break;
			case "5":
				ArrayValue[x]="LIKEAFTER";
				break;
			case "6":
				ArrayValue[x]=">";
				break;
			case "7":
				ArrayValue[x]=">=";
				break;
			case "8":
				ArrayValue[x]="<";
				break;
			case "9":
				ArrayValue[x]="<=";
				break;
			case "10":
				ArrayValue[x]="=";
				break;
			case "11":
				ArrayValue[x]="IS";
				break;
			default:
				break;
		}
	}
	return ArrayValue;
}
function SplitArrOP(ArrTextOp)
{
	var ArrayOP=new Array();
	for(x in ArrTextOp)
	{
		var SplitFuncArr=ArrTextOp[x].split("|");
		ArrayOP[x]=SplitFuncArr[0];
	}
	return ArrayOP;
}
function insertOperator(ser,tipo,type){
		//alert(tipo);
		if(tipo==0){
  	var ArrTextOp=new Array(text_16+"|1",text_17+"|2",text_18+"|3",text_19+"|4",text_20+"|5",text_21+"|6",text_22+"|7",text_23+"|8",text_24+"|9",text_25+"|10",text_33+"|11");
		}else{//june edit 08-11-2008
			
	var ArrTextOp=new Array(text_16+"|1",text_18+"|3",text_19+"|4",text_20+"|5",text_21+"|6",text_22+"|7",text_23+"|8",text_24+"|9",text_25+"|10");//03-12-2008
		}
		ArrTextOp.sort();
		var ArrOpValue=SelectOperaValue(ArrTextOp);
		var ArrTextOp=SplitArrOP(ArrTextOp);
		//alert(ArrTextOp);alert(ArrOpValue);		
		
		var myOperator;
		var myEvent = "";
		
		if(tipo==0)
        	myOperator = "<input type='hidden' id='op[]' value='"+(ser-1)+"'><select name=op["+(ser-1)+"] onchange=\"checkoperator('"+ser+"','"+type+"');\" id=\"op["+(ser-1)+"]\">" ;
       	else
       		myOperator = "<input type='hidden' id='op[]' value='"+(ser-1)+"'><select name=op["+(ser-1)+"] id=\"mySelect\">";
					
        
				myOperator = myOperator + "<option value='"+ArrOpValue[0]+"'>" + ArrTextOp[0] + "</option>";
       	
        if(tipo==0)
				{
       		myOperator = myOperator + "<option value='"+ArrOpValue[1]+"'>" + ArrTextOp[1] + "</option>";
					myOperator = myOperator + "<option value='"+ArrOpValue[2]+"'>" + ArrTextOp[2] + "</option>";
				}
					
       	myOperator = myOperator + "<option value='"+ArrOpValue[3]+"'>" + ArrTextOp[3] + "</option>";
       	myOperator = myOperator + "<option value='"+ArrOpValue[4]+"'>" + ArrTextOp[4] + "</option>";
       	myOperator = myOperator + "<option value='"+ArrOpValue[5]+"'>" + ArrTextOp[5] + "</option>";
       	myOperator = myOperator + "<option value='"+ArrOpValue[6]+"'>" + ArrTextOp[6] + "</option>";
       	myOperator = myOperator + "<option value='"+ArrOpValue[7]+"'>" + ArrTextOp[7] + "</option>";       	
       	myOperator = myOperator + "<option value='"+ArrOpValue[8]+"'>" + ArrTextOp[8] + "</option>";
		 if(tipo==0)
				{//03-12-2008
       	myOperator = myOperator + "<option value='"+ArrOpValue[9]+"'>" + ArrTextOp[9] + "</option>";
				myOperator = myOperator + "<option value='"+ArrOpValue[10]+"'>" + ArrTextOp[10] + "</option>";
				}//03-12-2008
		//add new conditions----------------------------------------------------------------------------
		//myOperator = myOperator + "<option value=\"IS\">" + text_33 + "</option>";
		//end -------------------------------------------------------------------------------------------------
		
        myOperator = myOperator + "</select>";
        
        return myOperator;
   
}
//Update 18-01-2008
function insertOperator_formula(ser,tipo){

  
		var myOperator;
		var myEvent = "";
		
		if(tipo==0)
        	myOperator = "<input type='hidden' id='op[]' value='"+(ser-1)+"'><select name=op["+(ser-1)+"] onchange=\"checkoperator('"+ser+"','');\" disabled='disabled' style='background-color:#CCCCCC'>" ;
       	else
       		myOperator = "<input type='hidden' id='op[]' value='"+(ser-1)+"'><select name=op["+(ser-1)+"] disabled='disabled' style='background-color:#CCCCCC'>" ;
        myOperator = myOperator + "<option value=\"LIKE\">" + text_16 + "</option>";
       	
        if(tipo==0){
       		myOperator = myOperator + "<option value=\"><\">" + text_17 + "</option>";
			myOperator = myOperator + "<option value=\"IS\">" + text_33 + "</option>";
		}
			
			
       	myOperator = myOperator + "<option value=\"!=\">" + text_18 + "</option>";
       	myOperator = myOperator + "<option value=\"LIKEBEFORE\">" + text_19 + "</option>";
       	myOperator = myOperator + "<option value=\"LIKEAFTER\">" + text_20 + "</option>";
       	myOperator = myOperator + "<option value=\">\">" + text_21 + "</option>";
       	myOperator = myOperator + "<option value=\">=\">" + text_22 + "</option>";
       	myOperator = myOperator + "<option value=\"<\">" + text_23 + "</option>";
       	myOperator = myOperator + "<option value=\"<=\">" + text_24 + "</option>";
       	myOperator = myOperator + "<option value=\"=\">" + text_25 + "</option>";
		
		//add new conditions----------------------------------------------------------------------------
		//myOperator = myOperator + "<option value=\"IS\">" + text_33 + "</option>";
		//end -------------------------------------------------------------------------------------------------
		
        myOperator = myOperator + "</select>";
        
        return myOperator;
   
}
/**************************************************************************************/
/* insertLogical is function that build dropdown list Operator by  */
/**************************************************************************************/
function insertLogical(pos){
		var myOperator;

        //myOperator = "<select id='logic' name='logic[]' onChange='javascript: check_join_field(this);chk_select_logical_change();'>" ;
         myOperator = "<select id='logic["+pos+"]' name='logic[]' onChange='javascript:chk_select_logical_change();change_mstatus();'>" ;
      	//myOperator = myOperator + "<option value=\"\"></option>";
		//if(val=="AND"){
       		myOperator = myOperator + "<option value=\"AND\" selected>AND</option>";
       		myOperator = myOperator + "<option value=\"OR\">OR</option>";
		//}else{
//			myOperator = myOperator + "<option value=\"AND\">AND</option>";
//       		myOperator = myOperator + "<option value=\"OR\" selected>OR</option>";
//		}
        myOperator = myOperator + "</select>";

        return myOperator;
}
/**************************************************************************************/
/* insOrder is function that build dropdown list ORDER   */
/**************************************************************************************/
function insOrder(){
		var myOrder;

		myOrder = "<select name=ord[] onchange=\"chk_select_ord_change();\">";
		myOrder = myOrder + "<option value=\"ASC\">" + text_26 + "</option>";
		myOrder = myOrder + "<option value=\"DESC\">" + text_27 + "</option>";
		myOrder = myOrder + "</select>";

		return myOrder;
}
//***********************************june Grouping************************************************
function insOrder_Group(){
		var myGroup;

		myGroup = "<select id=gro[] name=gro[] onchange=\"chk_select_gro_change();\">";
		myGroup = myGroup + "<option value=\"None\">" + text_34 + "</option>";
		myGroup = myGroup + "<option value=\"Brief\">" + text_35 + "</option>";
		myGroup = myGroup + "<option value=\"Analitic\">" + text_36 + "</option>";
		myGroup = myGroup + "<option value=\"GroupBy\">" + text_81 + "</option>";
		myGroup = myGroup + "</select>";

		return myGroup;
	}
//*****************************************end june********************************
/**************************************************************************************/
/* insertOrderChoice is function that build dropdown list ORDER   */
/**************************************************************************************/
function insertOrderChoice(){
	var myChoice;
	var selectValue = new Array();
	var selectText = new Array();
	var orderValue = new Array();
	var orderText = new Array();

	var foundOrder = 0;
	var selectlist = document.getElementsByName("field[]"); // display only result that user choose
	var orderlist = document.getElementsByName("field2[]"); // order list that display on screen

	for(var i=0; i<selectlist.length; i++){
		selectValue[i] = selectlist[i].options[selectlist[i].selectedIndex].value;
		selectText[i] = selectlist[i].options[selectlist[i].selectedIndex].text;
	}
/*	11 October 2005
	for(var j=0; j<orderlist.length; j++){
		orderValue[j] = orderlist[j].options[orderlist[j].selectedIndex].value;
		orderText[j] = orderlist[j].options[orderlist[j].selectedIndex].text;
	}
*/
	myChoice = "<select name=\"field2[]\" >";
//	11 October 2005	
	for(var i=0; i<selectlist.length; i++){
		 myChoice = myChoice + " <option value=\"" + selectValue[i] + "\" >" + selectText[i] + "</option>";	
		foundOrder = 0;
	} // end for i

/*	11 October 2005
	for(var i=0; i<selectlist.length; i++){
		for(var j=0; j<orderlist.length; j++){
			if(selectValue[i] == orderValue[j]){	foundOrder = 1;	}
		} // end for j
		if(foundOrder != 1){ myChoice = myChoice + " <option value=\"" + selectValue[i] + "\" >" + selectText[i] + "</option>";	}
		foundOrder = 0;
	} // end for i
*/
	myChoice = myChoice + "</select>";
	
	return myChoice;
}
/**************************************************************************************/
/* tr_length is function that return number of <tr> minus 1 */
/**************************************************************************************/
function tr_length(table_name){
	return eval("document.getElementById('" + table_name + "').rows.length - 1");
}
/**************************************************************************************/
/* insertResult is function that append new row of table which have 2 columns and 3 elements*/
/* 1. field dropdown list; 2. checkbox  3. hidden*/
/**************************************************************************************/
function insertResult(name,value,type_result,xx){	//Send x to Changename <BOW> 13-12-2007
        //var va;
		//alert(value);
         //if(name=="check_formula_join"){
		//	  va=value;
		//	 }
		if(value.match("CONCAT")){//CONCAT 14-12-2007				
			value=set_value_insert(value);
		}//CONCAT 14-12-2007
		
		//alert(value);
			
		// start position is 0 then we pos = length of <tr> - 1
		var pos = tr_length("myResult");
		
				
		var x=document.getElementById('myResult').insertRow(pos)		// insert new row
		var y=document.getElementById('myResult').rows					// get attribute of row
		//var z=document.getElementById('myResult').insertRow(pos+2)		// insert new row

		
		var a=x.insertCell(0)			// assign position of cell 1 in new row
		var b=x.insertCell(1)			// assign position of cell 2 in new row
		var c=x.insertCell(2)			// assign position of cell 3 in new row
		//var d=x.insertCell(3)			// assign position of cell 4 in new row
	//	var e=x.insertCell(4)			// assign position of cell 4 in new row
		//var e=z.insertCell(3)			// assign position of cell 4 in new row


		x.bgColor="#FFFFFF"			// assign background color to TR
		//////////////////// Check Formula <BoW> ///////////////////////////
		//name_show=name
		tname=value
			tname=tname.replace(/#/g,"%chap%");//june  add new 25-12-2007
			tname=tname.replace(/&/g,"%alp%");			
			tname=tname.replace(/\+/g,"%plus%");
			name=name.replace(/\+/g," %plus% ");
			ID_query=document.getElementById("ID_query").value;
			var id=""
			var id_user=""

		
		var key_FOR=name.split("|");
		if(key_FOR[1]){
			
			name=key_FOR[0];
			a.innerHTML="<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','result','"+xx+"')\">"+name+"</a><input type='hidden' value=\""+value+"\" name='field[]'><input type='hidden' name='KFormula' value=\""+key_FOR[1]+"\"><input type='hidden' name='field_type[]' value=\"field_type##"+type_result+"\">";//Insert link for modify fields name <bow> 15-10-2007
			//Send field_type to check type of field <june> 23-09-2008
			//Send x to Changename <BOW> 13-12-2007
			//Insert link for modify fields name <bow> 15-10-2007  
			//alert(x)
		}else{

//a.innerHTML=insertChoice()			// insert fieldlist formula
			a.innerHTML="<a href=\"javascript:;\" id=\""+(pos)+"\" onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','result','"+xx+"')\">"+name+"</a><input type='hidden' value=\""+value+"\" name='field[]'><input type='hidden' name='field_type[]' value=\"field_type##"+type_result+"\">";	
			//a.innerHTML="<a href=\"changename.php?x="+xx+"&ID_query="+ID_query+"&id_user="+id_user+"&id_userselection="+id+"&from=result&p="+pos+"&name="+name+"&tname="+tname+"\" target=\"_blank\" id=\""+(pos)+"\">"+name_show+"</a><input type='hidden' value=\""+value+"\" name='field[]'><input type='hidden' name='field_type[]' value=\"field_type##"+type_result+"\">";
			//Send field_type to check type of field <june> 23-09-2008
			//Send x to Changename <BOW> 13-12-2007
			//Insert link for modify fields name <bow> 15-10-2007	
			//a.innerHTML="<a href=\"#\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+")\"><input type='text' name='name_f["+pos+"]' value='"+name+"' style='border:none;cursor:pointer;font-size:12px' readonly='true'></a><input type='hidden' name='field["+pos+"]' value='"+value+"'>";
		}
		////////////////End Check Formula <BoW> /////////////////////////

		//a.innerHTML=insertChoice()			// insert fieldlist
		//a.innerHTML=name+"<input type='hidden' name='field[]' value='"+value+"'>";			// insert fieldlist

		//b.innerHTML = "<input type='checkbox' id = 'd' name='d' value="  +  pos + "><input type='hidden' name='id[]' value='xx'>"		// insert checkbox
		//b.innerHTML = "<img src='immagini/vis.gif' onclick='toggle_vis(this,"+  pos +");' onmouseover=\"this.style.cursor='pointer'\"><input type='hidden' name='vis["+  pos +"]' value='1'>"
		b.innerHTML = "<input type='image' src='immagini/vis.gif' id=v["+pos+"] style='cursor:auto' onclick='toggle_vis(this,"+  pos +");return false;'><input type='hidden' name='vis["+  pos +"]' value=1>"
		c.innerHTML = "<input name='del' type='image' src='immagini/del.png' id="+pos+" style='cursor:auto' onClick=\"this.form.d.value="+pos+";doDelete_Result(this.form);return false;\"><input type='hidden' name='id[]' value='xx'>"		// insert checkbox
		//"<input name='del' type='image' src='immagini/del.png' id="+pos+" style='cursor:auto' onClick=\"this.form.d.value="+pos+";doDelete_Result(this.form,'view');return false;\"><input type='hidden' name='id[]' value='xx'>
		//c.innerHTML = "<img src='immagini/del.png' id="+pos+" style='cursor:auto' onClick='alert(this.form.d);'><input type='hidden' name='id[]' value='xx'>"
		
		//d.innerHTML = "<input type='image' src='immagini/down.gif' style='cursor:auto' onClick=\"moveRowDown("+(pos-1)+",'tresult');return false;\"><b>/</b><input type='image'  src='immagini/up.gif' style='cursor:auto' onClick=\"moveRowUp("+(pos-1)+",'tresult');return false;\">";
		
		//e.innerHTML = "<input type='image'  src='immagini/up.gif' style='cursor:auto' onClick=\"moveRowUp("+(pos-1)+",'tresult');return false;\">";
		//e.innerHTML = "<input type='button' name='delall' value='DeleteAll'>"

		a.align = "left"
		b.align = "center"
		c.align = "center"
		//d.align = "center"
	//	e.align = "center"
		y[pos+1].align = "left"			// left alignment for the last row
		
		//y[pos+2].align = "left"	
		 //<input type='button' name='delall' value='DeleteAll'>

		//accese_del++
		//doDelete_Result(this.form);
	DragDrop('myResult')   //Drag & Drop
	change_mstatus()
}
//*************************june create view* --01_08_2007*************
function insertResult1(name,value){//Ã£Â¹Â¡Ã?Â³Ã•Â·Ã•Ã¨Ã?Ã?Ã©Ã’Â§Ã£Ã?Ã?Ã¨ Ã¤Ã?Ã¨Ã¤Â´Ã©Ã?Ã’Â¨Ã’Â¡Â°Ã’Â¹Â¢Ã©Ã?Ã?Ã?Ã…

		// start position is 0 then we pos = length of <tr> - 1
		var pos = tr_length("myResult");
		
				
		var x=document.getElementById('myResult').insertRow(pos)		// insert new row
		var y=document.getElementById('myResult').rows					// get attribute of row
		//var z=document.getElementById('myResult').insertRow(pos+2)		// insert new row

		
		var a=x.insertCell(0)			// assign position of cell 1 in new row
		var b=x.insertCell(1)			// assign position of cell 2 in new row
		var c=x.insertCell(2)			// assign position of cell 3 in new row
	//	var d=x.insertCell(3)			// assign position of cell 3 in new row
	//	var d=x.insertCell(3)			// assign position of cell 4 in new row
		//var e=z.insertCell(3)			// assign position of cell 4 in new row
		c.style.display="none";

		x.bgColor="#FFFFFF"			// assign background color to TR

		//a.innerHTML=insertChoice()			// insert fieldlist
		//a.innerHTML=name+"<input type='hidden' name='field[]' value='"+value+"'>";			// insert fieldlist
			a.innerHTML="<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','view')\">"+name+"</a><input type='hidden' value='"+value+"' name='field[]'>";	//Insert link for modify fields name <bow> 15-10-2007	

		//b.innerHTML = "<input type='checkbox' id = 'd' name='d' value="  +  pos + "><input type='hidden' name='id[]' value='xx'>"		// insert checkbox
	//	b.innerHTML = "<img src='immagini/vis.gif' onclick='toggle_vis(this,"+  pos +");' onmouseover=\"this.style.cursor='pointer'\"><input type='hidden' name='vis["+  pos +"]' value='1'>"
		b.innerHTML = "<input name='del' type='image' src='immagini/del.png' id="+pos+" style='cursor:auto' onClick=\"this.form.d.value="+pos+";doDelete_Result(this.form,'view');return false;\"><input type='hidden' name='id[]' value='xx'>"		
		c.innerHTML ="&nbsp;"
		// insert checkbox
		//c.innerHTML ="<input type='image'  src='immagini/down.gif' style='cursor:auto' onClick=\"moveRowDown("+(pos-1)+",'tresult','view');return false;\"><b> / </b><input type='image'  src='immagini/up.gif' style='cursor:auto' onClick=\"moveRowUp("+(pos-1)+",'tresult','view');return false;\">";
	//	d.innerHTML ="<input type='image'  src='immagini/up.gif' style='cursor:auto' onClick=\"moveRowUp("+(pos-1)+",'tresult');return false;\">";
		//e.innerHTML = "<input type='button' name='delall' value='DeleteAll'>"

		a.align = "left"
		b.align = "center"
		c.align = "center"
	//	d.align = "center"
		//d.align = "center"
		y[pos+1].align = "left"			// left alignment for the last row
		
		//y[pos+2].align = "left"	
		 //<input type='button' name='delall' value='DeleteAll'>

	DragDrop('myResult','view')   //Drag & Drop
	change_mstatus()
}

//************************************************************

	function toggle_text(id)	
	{
		//alert(id)
		c_id=id.replace("text","");
		text = document.getElementById(id);
		var table = document.getElementById("myCondition");
		var rows = table.tBodies[0].rows;
		for (var i=1; i<(rows.length-1);i++) {
		rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML;
		}
		//text.value="";
		if(text.disabled==true)
		{
			text.disabled=false;
			
		}
		else
		{
			text.disabled=true;
			
		}
			
		text_2 = document.getElementById(id+"_2");
		
		
		if(text_2 != null)
		{
			if(text_2.disabled==true)
				text_2.disabled=false;
			else
				text_2.disabled=true;
		}
		
/////////////////// [Firefox]-->For checkbox in condition[BOW]///////////////////////		
//			if(document.getElementById("type["+(c_id-1)+"]").value==1)
//				document.getElementById("type["+(c_id-1)+"]").value=0
//			else
//				document.getElementById("type["+(c_id-1)+"]").value=1
/////////////////////////////////////////////////////////////////////////////////////
			change_mstatus()
		//alert(document.getElementById("type["+(c_id-1)+"]").innerHTML);
	}	
	
	function toggle_vis(img,id)	
	{
		var pos = tr_length("myResult");
		var accese = 0;
		var table = document.getElementById("myResult");
//		var array_img = table.getElementsByTagName("img"); 
//		//var array_img = document.getElementById("myResult");
		for (var i = 1; i < pos; i++)
		{ 
				//alert(document.getElementById("v["+i+"]").src)
				array_split = document.getElementById("v["+i+"]").src.split("/");
				if(array_split[array_split.length-1]=="vis.gif")
				{
					//alert(array_split[array_split.length-1]);
					accese++;
				}
		}
		accese_del= accese-1;
		//alert(accese_del)
		
			vis = document.getElementById("vis["+id+"]");
			//alert("vis["+id+"]")
			if(vis.value==1)
			{
				if(accese>1)
				{
					vis.value=0;
					img.src='immagini/novis.gif';
				}
				else
					//alert("ATTENZIONE: Devi visualizzare almeno un campo.");
					alert(text_30); //nong
			}
			else
			{
				vis.value=1;
				img.src='immagini/vis.gif';
			}

			
			change_mstatus()
	}		
	
/**************************************************************************************/
/* insertCondition is function that append new row of table which have 5 columns and 6 elements*/
/* 1. field dropdown list; 2. operator downdown list 3.textbox1  4. textbox2  5.checkbox  6. hidden*/
/**************************************************************************************/
function insertCondition(name,value,type,xx){//Send x to Changename <BOW> 13-12-2007

		var formula_as=0;
		var ass;
		var concat_value=0;
		var pos = tr_length("myCondition");
		if(value.match("CONCAT")){//CONCAT 14-12-2007				
			value=set_value_insert(value);
			concat_value=1
		}//CONCAT 14-12-2007
		//Check Name Operator TU
		var ValueAs=value.split("as");
		value=ValueAs[0];
		//Check Name Operator TU
		condition_ser++;
		for (x in formula_array)
		{
			ass=formula_array[x];
			if(value.match(ass)){		 	
				formula_as=1;
			}
		}
		//******june check changname "ssss as ggggg"  24-07-2008
			var new_value;
			if(ValueAs[1] && ValueAs.length>2){
				  for (i=1; i <= ValueAs.length-1; i++){
						if(i>1){
							new_value=new_value+"as"+ValueAs[i];
						}else{
							new_value=ValueAs[i];
						}
					
					}
					ValueAs[1]=new_value;
					value=ValueAs[0]+"as"+ValueAs[1];
			}
			else if(ValueAs[1]){
					value=ValueAs[0]+"as"+ValueAs[1];
					}
		//************end june check changname "ssss as ggggg"  24-07-2008
	//alert("after value==="+value);
		//Check Name Operator TU
		/*if(ValueAs[1]){//old
			value=ValueAs[0]+"as"+ValueAs[1];
			alert(value);
		}*/
		//Check Name Operator TU
			//value=\""..."\" CONCAT
		if(formula_as2==0){		 			 	
			if(formula_as==0){			 
				if(type >= 6 && type <= 9)
					format = "gg/mm/aaaa";
				else
					format = "";
				
				// start position is 0 then we pos = length of <tr> - 1		
				var pos = tr_length("myCondition");
		       	var x=document.getElementById('myCondition').insertRow(pos)		// insert new row
				var y=document.getElementById('myCondition').rows				// get attribute of row
				var z=document.getElementById('myCondition').rows[pos-1]		// get attribute of row		
			
		
				var a=x.insertCell(0)			// assign position of cell 1 in new row
				var b=x.insertCell(1)			// assign position of cell 2 in new row
		        var c=x.insertCell(2)			// assign position of cell 3 in new row
				var d=x.insertCell(3)			// assign position of cell 4 in new row
				var e=x.insertCell(4)			// assign position of cell 8 in new row
				var f=x.insertCell(5)			// assign position of cell 5 in new row
				var g=z.cells[6]
				var h=x.insertCell(6)			// assign position of cell 6 in new row
				var i=x.insertCell(7)			// assign position of cell 7 in new row
		
				x.bgColor="#FFFFFF"				// assign background color to TR
				
				
				//Contiene il primo campo per la parentesi
				a.innerHTML = "<input type='text' size='1' class='front_paren' id='p_front' name='front_paren["+(pos-1)+"]' value='' style='text-align:center;font-weight:bold; color:#FF0000; border:1px solid #C2C2C2' onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_front(event);'>";
				
				//Contiene la descrizione del campo passato dalla popup e un campo hidden con il nome vero del campo
				b.innerHTML ="<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','condition','"+xx+"')\">"+name+"</a><input type='hidden' value=\""+value+"\" name='field1[]'>";	//Insert link for modify fields name <bow> 15-10-2007  //Send x to Changename <BOW> 13-12-2007
				
				//Listbox con gli operatori
				// ----> insertOperator
				//c.innerHTML = "<span id='specific1' style='visibility:visible'>" + insertOperator(condition_ser,0,this) + "</span>";
				c.innerHTML = "<input type='hidden' id='no_decode[]' name='no_decode[]' value='0'><input type='hidden' name='decode[]' value=0 ><span id='specific1' style='visibility:visible'>" + insertOperator(pos,0,type) + "</span>";
				
				//var xx= document.getElementByName('op[0]').value;
				
				//Campo hidden decode che dice che la condizione non contiene una lista da decodificare
				//Checkbox che indica se la condizione Ã¨ fissa o no
				// ----> toggle_text
				//alert(c.innerHTML)
				
				//d.innerHTML="<input type='text' id='decode[]' name='decode[]' value=0><input type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\">";
				
				d.innerHTML="<input style='cursor:auto' value=1 type='checkbox' checked='checked' id='type["+(pos-1)+"]' name='type["+(pos-1)+"]' onclick=\"toggle_text('text"+pos+"')\">";
				
				//Campo di testo disabilitato per il valore da confrontare
//Update 18-01-2008 TU
		if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
		
					e.innerHTML = "<span id='SPAN"+pos+"' style='visibility:visible'>"+text_28+"<input id='text"+pos+"' style='font-size:9px;' disabled type='text' size='10' value=\""+format+"\" name=var["+(pos-1)+"] onblur=\"doDate(this);setvalue_var("+(pos-1)+",1);\"><br>"+text_29+"<input id='text"+pos+"_2' style='font-size:9px;' disabled type='text' size='10' value=\""+format+"\" name=var_2["+(pos-1)+"] onblur=\"doDate(this);setvalue_var("+(pos-1)+",2);\"><input type ='hidden' value="+pos+" name='text_name[]' id='text_name[]'><input type ='hidden' value='"+format+"' name='hid_var["+(pos-1)+"]' id='hid_var["+(pos-1)+"]'><input type ='hidden' value='"+format+"' name='hid_var2["+(pos-1)+"]' id='hid_var2["+(pos-1)+"]'></span>";
		}else{
			//alert("Hear")
				e.innerHTML = "<span id='SPAN"+pos+"' style='visibility:visible'>"+text_28+"<input id='text"+pos+"' style='font-size:9px;' disabled type='text' size='10' value=\""+format+"\" name=var["+(pos-1)+"] onblur=\"setvalue_var("+(pos-1)+",1);\"><br>"+text_29+"<input id='text"+pos+"_2' style='font-size:9px;' disabled type='text' size='10' value=\""+format+"\" name=var_2["+(pos-1)+"] onblur=\"setvalue_var("+(pos-1)+",2);\"><input type ='hidden' value="+pos+" name='text_name[]' id='text_name[]'><input type ='hidden' value='"+format+"' name='hid_var["+(pos-1)+"]' id='hid_var["+(pos-1)+"]'><input type ='hidden' value='"+format+"' name='hid_var2["+(pos-1)+"]' id='hid_var2["+(pos-1)+"]'> </span>";
	}
//Update 18-01-2008 TU
									
				//Contiene il secondo campo per la parentesi     <input type='hidden' name='text_name[]' value="+condition_ser+">"
				f.innerHTML = "<input type='text' size='1' class='back_paren' id='p_back' name='back_paren["+(pos-1)+"]' value='' style='text-align:center;font-weight:bold; color:#FF0000; border:1px solid #C2C2C2'  onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_back(event);'>";
		
				if(pos >= 2)
					g.innerHTML = insertLogical(pos-1)
				else
					h.innerHTML = "&nbsp;";
		
				//Croce per cancellare la condizione
				i.innerHTML = "<input name='del' type='image' src='immagini/del.png' id="  +  pos + " style='cursor:auto' onClick='this.form.d3.value=this.id; doDelete_Condition(this.form);return false;'><input type='hidden' name='id[]' value='xx'>"	// insert checkbox
		
				b.align = "left";
				c.align = "center";
				d.align = "center";
				e.align = "center";
				e.align = "center";
				g.align = "center";
		
				y[pos+1].align = "left";			// left alignment for the last row
				
				
			/*for(var j=0;j<tr_length("tcondition")-1;j++)
			{
				
				
				index_con_new = document.getElementById('op['+j+']').value;
					
				alert(index_con_new);
				
			}*/
			//alert(c.innerHTML);
			
			for(i=1;i<=pos;i++){
				re_condition(i)
			}

			
			}
			else{
			 if(type >= 6 && type <= 9)
					format = "gg/mm/aaaa";
				else
					format = "";
				
				// start position is 0 then we pos = length of <tr> - 1		
				var pos = tr_length("myCondition");
		       	var x=document.getElementById('myCondition').insertRow(pos)		// insert new row
				var y=document.getElementById('myCondition').rows				// get attribute of row
				var z=document.getElementById('myCondition').rows[pos-1]		// get attribute of row		
			
		
				var a=x.insertCell(0)			// assign position of cell 1 in new row
				var b=x.insertCell(1)			// assign position of cell 2 in new row
		        var c=x.insertCell(2)			// assign position of cell 3 in new row
				var d=x.insertCell(3)			// assign position of cell 4 in new row
				var e=x.insertCell(4)			// assign position of cell 8 in new row
				var f=x.insertCell(5)			// assign position of cell 5 in new row
				var g=z.cells[6]
				var h=x.insertCell(6)			// assign position of cell 6 in new row
				var i=x.insertCell(7)			// assign position of cell 7 in new row
		
				x.bgColor="#FFFFFF"	
				//Contiene il primo campo per la parentesi
				a.innerHTML = "<input type='text' size='1' class='front_paren' id='p_front' name='front_paren["+(pos-1)+"]' value='' style='text-align:center;font-weight:bold; color:#FF0000; border:1px solid #C2C2C2' onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_front(event);'>";
				
				//Contiene la descrizione del campo passato dalla popup e un campo hidden con il nome vero del campo
				//b.innerHTML ="<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','condition','"+xx+"')\">"+name+"</a><input type='hidden' name='field1[]' value=\""+value+"\">";	//Insert link for modify fields name <bow> 15-10-2007  //Send x to Changename <BOW> 13-12-2007
				b.innerHTML ="<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','condition','"+xx+"')\">"+name+"</a><input type='hidden' value=\""+value+"\" name='field1[]'>";
				
				//Listbox con gli operatori
				// ----> insertOperator
				//c.innerHTML = "<span id='specific1' style='visibility:visible'>" + insertOperator(condition_ser,0,this) + "</span>";
				if(concat_value==1)
			{
					c.innerHTML = "<input type='hidden' id='no_decode[]' name='no_decode[]' value='0'><input type='hidden' name='decode[]' value=0><span id='specific1' style='visibility:visible'>" + insertOperator(condition_ser,0,type) + "</span>";
						
			//d.innerHTML="<input style='cursor:auto'type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\" >";
			d.innerHTML="<input style='cursor:auto' value=1 type='checkbox' checked='checked' id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' onclick=\"toggle_text('text"+condition_ser+"')\">";
			
		//	e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px;cursor:auto' disabled type='text' name=var["+(condition_ser-1)+"] size='15' value = \""+format+"\"> <input type ='hidden' name='text_name[]' value="+condition_ser+" > </span>";
		if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
				e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'>"+text_28+"<input id='text"+condition_ser+"' style='font-size:9px;' disabled type='text' name=var["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"doDate(this);setvalue_var("+(condition_ser-1)+",1);\"><br>"+text_29+"<input id='text"+condition_ser+"_2' style='font-size:9px;' disabled type='text' name=var_2["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"doDate(this);setvalue_var("+(condition_ser-1)+",2);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+" ><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'><input type ='hidden' value='"+format+"' name='hid_var2["+(condition_ser-1)+"]' id='hid_var2["+(condition_ser-1)+"]'></span>";//june01-02-2008
				}else{
				e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'>"+text_28+"<input id='text"+condition_ser+"' style='font-size:9px;' disabled type='text' name=var["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"setvalue_var("+(condition_ser-1)+",1);\"><br>"+text_29+"<input id='text"+condition_ser+"_2' style='font-size:9px;' disabled type='text' name=var_2["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"setvalue_var("+(condition_ser-1)+",2);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+" ><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'><input type ='hidden' value='"+format+"' name='hid_var2["+(condition_ser-1)+"]' id='hid_var2["+(condition_ser-1)+"]'></span>";//june01-02-2008
				}
			}
			else
			{
			c.innerHTML = "<input type='hidden' id='no_decode[]' name='no_decode[]' value='0'><input type='hidden' name='decode[]' value=0><span id='specific1' style='visibility:visible'>" + insertOperator_formula(condition_ser,0) + "</span>";
			
			//var xx= document.getElementByName('op[0]').value;
			
			//Campo hidden decode che dice che la condizione non contiene una lista da decodificare
			//Checkbox che indica se la condizione Ã¨ fissa o no
			// ----> toggle_text
			
			
			//d.innerHTML="<input type='text' id='decode[]' name='decode[]' value=0><input type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\">";
			
			//d.innerHTML="<input type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\" disabled='disabled' style='background-color:#CCCCCC;cursor:auto'>";
			d.innerHTML="<input value=1 type='checkbox' checked='checked' id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' onclick=\"toggle_text('text"+condition_ser+"')\" disabled='disabled' style='background-color:#CCCCCC;cursor:auto'>";
			//Campo di testo disabilitato per il valore da confrontare
			//e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px' type='hidden' name=var["+(condition_ser-1)+"] size='15' value = '"+format+"' > <input type ='hidden' name='text_name[]' value="+condition_ser+" > </span>";
					if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
					
					e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px' disabled='disabled' style='background-color:#CCCCCC' type='text' name=var["+(condition_ser-1)+"] size='15' value = \""+format+"\" onblur=\"doDate(this);setvalue_var("+(condition_ser-1)+",1);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+"><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'></span>";
					}else{
					e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px' disabled='disabled' style='background-color:#CCCCCC' type='text' name=var["+(condition_ser-1)+"] size='15' value = \""+format+"\" onblur=\"setvalue_var("+(condition_ser-1)+",2);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+"><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'></span>";
					}
			}
									
				//Contiene il secondo campo per la parentesi     <input type='hidden' name='text_name[]' value="+condition_ser+">"
				f.innerHTML = "<input type='text' size='1' class='back_paren' id='p_back' name='back_paren["+(pos-1)+"]' value='' style='text-align:center;font-weight:bold; color:#FF0000; border:1px solid #C2C2C2'  onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_back(event);'>";
		
				if(pos >= 2)
					g.innerHTML = insertLogical(pos-1)
				else
					h.innerHTML = "&nbsp;";
		
				//Croce per cancellare la condizione
				i.innerHTML = "<input name='del' type='image' src='immagini/del.png' id="  +  pos + " style='cursor:auto' onClick='this.form.d3.value=this.id; doDelete_Condition(this.form);return false;'><input type='hidden' name='id[]' value='xx'>"			// insert checkbox
		
				b.align = "left";
				c.align = "center";
				d.align = "center";
				e.align = "center";
				e.align = "center";
				g.align = "center";
		
				y[pos+1].align = "left";			// left alignment for the last row
				
				
			/*for(var j=0;j<tr_length("tcondition")-1;j++)
			{
				
				
				index_con_new = document.getElementById('op['+j+']').value;
					
				alert(index_con_new);
				
			}*/
			}
			for(i=1;i<=pos;i++){
				re_condition(i)
			}
		}
	else{
		//Contiene il primo campo per la parentesi
		if(formula_as==1){
			 if(type >= 6 && type <= 9)
				format = "gg/mm/aaaa";
			else
				format = "";
			
			// start position is 0 then we pos = length of <tr> - 1		
			var pos = tr_length("myCondition");
	       	var x=document.getElementById('myCondition').insertRow(pos)		// insert new row
			var y=document.getElementById('myCondition').rows				// get attribute of row
			var z=document.getElementById('myCondition').rows[pos-1]		// get attribute of row		
		
	
			var a=x.insertCell(0)			// assign position of cell 1 in new row
			var b=x.insertCell(1)			// assign position of cell 2 in new row
	        var c=x.insertCell(2)			// assign position of cell 3 in new row
			var d=x.insertCell(3)			// assign position of cell 4 in new row
			var e=x.insertCell(4)			// assign position of cell 8 in new row
			var f=x.insertCell(5)			// assign position of cell 5 in new row
			var g=z.cells[6]
			var h=x.insertCell(6)			// assign position of cell 6 in new row
			var i=x.insertCell(7)			// assign position of cell 7 in new row
	
			x.bgColor="#FFFFFF"	
			a.innerHTML = "<input type='text' size='1' class='front_paren' id='p_front' name='front_paren["+(pos-1)+"]' value='' style='text-align:center;font-weight:bold; color:#FF0000; border:1px solid #C2C2C2' onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_front(event);'>";
			
			//Contiene la descrizione del campo passato dalla popup e un campo hidden con il nome vero del campo
			//b.innerHTML ="<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','condition')\">"+name+"</a><input type='hidden' name='field1[]' value=\""+value+"\">";	//Insert link for modify fields name <bow> 15-10-2007
			b.innerHTML ="<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','condition','"+xx+"')\">"+name+"</a><input type='hidden' value=\""+value+"\" name='field1[]'>";
			//Listbox con gli operatori
			// ----> insertOperator
			//c.innerHTML = "<span id='specific1' style='visibility:visible'>" + insertOperator(condition_ser,0,this) + "</span>";
			if(concat_value==1)
			{
					c.innerHTML = "<input type='hidden' id='no_decode[]' name='no_decode[]' value='0'><input type='hidden' name='decode[]' value=0><span id='specific1' style='visibility:visible'>" + insertOperator(condition_ser,0,type) + "</span>";
						
			d.innerHTML="<input style='cursor:auto' type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\" >";
			
			//e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px;cursor:auto' disabled type='text' name=var["+(condition_ser-1)+"] size='15' value = \""+format+"\"> <input type ='hidden' name='text_name[]' value="+condition_ser+" > </span>";
      		if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
	    		e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'>"+text_28+"<input id='text"+condition_ser+"' style='font-size:9px;' disabled type='text' name=var["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"doDate(this);setvalue_var("+(condition_ser-1)+",1);\"><br>"+text_29+"<input id='text"+condition_ser+"_2' style='font-size:9px;' disabled type='text' name=var_2["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"doDate(this);setvalue_var("+(condition_ser-1)+",2);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+" ><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'><input type ='hidden' value='"+format+"' name='hid_var2["+(condition_ser-1)+"]' id='hid_var2["+(condition_ser-1)+"]'></span>";//june01-02-2008
			}else{
				e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'>"+text_28+"<input id='text"+condition_ser+"' style='font-size:9px;' disabled type='text' name=var["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"setvalue_var("+(condition_ser-1)+",1);\"><br>"+text_29+"<input id='text"+condition_ser+"_2' style='font-size:9px;' disabled type='text' name=var_2["+(condition_ser-1)+"] size='10' value = \""+format+"\" onblur=\"setvalue_var("+(condition_ser-1)+",2);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+" ><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'><input type ='hidden' value='"+format+"' name='hid_var2["+(condition_ser-1)+"]' id='hid_var2["+(condition_ser-1)+"]'></span>";//june01-02-2008
			}
			}
			else
			{
			c.innerHTML = "<input type='hidden' id='no_decode[]' name='no_decode[]' value='0'><input type='hidden' name='decode[]' value=0><span id='specific1' style='visibility:visible'>" + insertOperator_formula(condition_ser,0) + "</span>";
			
			//var xx= document.getElementByName('op[0]').value;
			
			//Campo hidden decode che dice che la condizione non contiene una lista da decodificare
			//Checkbox che indica se la condizione Ã¨ fissa o no
			// ----> toggle_text
			
			
			//d.innerHTML="<input type='text' id='decode[]' name='decode[]' value=0><input type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\">";
			
			d.innerHTML="<input type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\" disabled='disabled' style='background-color:#CCCCCC;cursor:auto'>";
			
			//Campo di testo disabilitato per il valore da confrontare
			//e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px' type='hidden' name=var["+(condition_ser-1)+"] size='15' value = '"+format+"' > <input type ='hidden' name='text_name[]' value="+condition_ser+" > </span>";
		if(type >= 6 && type <= 9){//june format date in text box 18-09-2008
		  e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px' disabled='disabled' style='background-color:#CCCCCC' type='text' name=var["+(condition_ser-1)+"] size='15' value = \""+format+"\" onblur=\"doDate(this);setvalue_var("+(condition_ser-1)+",1);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+" disabled='disabled' style='background-color:#CCCCCC'><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'></span>";
		}else{
			e.innerHTML = "<span id='SPAN"+condition_ser+"' style='visibility:visible'><input id='text"+condition_ser+"' style='font-size:9px' disabled='disabled' style='background-color:#CCCCCC' type='text' name=var["+(condition_ser-1)+"] size='15' value = \""+format+"\" onblur=\"setvalue_var("+(condition_ser-1)+",1);\"> <input type ='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+" disabled='disabled' style='background-color:#CCCCCC'><input type ='hidden' value='"+format+"' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'></span>";
			}
		}
			//Contiene il secondo campo per la parentesi     <input type='hidden' name='text_name[]' value="+condition_ser+">"
			f.innerHTML = "<input type='text' size='1' class='back_paren' id='p_back' name='back_paren["+(pos-1)+"]' value='' style='text-align:center;font-weight:bold; color:#FF0000; border:1px solid #C2C2C2'  onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_back(event);'>";
	
			if(pos >= 2)
				g.innerHTML = insertLogical(pos-1)
			else
				h.innerHTML = "&nbsp;";
	
			//Croce per cancellare la condizione
			i.innerHTML = "<input name='del' type='image' src='immagini/del.png' id="  +  pos + " style='cursor:auto' onClick='this.form.d3.value=this.id; doDelete_Condition(this.form);return false;'><input type='hidden' name='id[]' value='xx'>"	// insert checkbox
	
			b.align = "left";
			c.align = "center";
			d.align = "center";
			e.align = "center";
			e.align = "center";
			g.align = "center";
	
			y[pos+1].align = "left";			// left alignment for the last row
			
			
		/*for(var j=0;j<tr_length("tcondition")-1;j++)
		{
			
			
			index_con_new = document.getElementById('op['+j+']').value;
				
			alert(index_con_new);
			
		}*/
			for(i=1;i<=pos;i++){
				re_condition(i)
			}
		
		}
		else
		{
		 	//alert("This field "+name+" has operator inappropriate to suit!!");
			alert(text_44+name+text_45);
		}
	}
	formula_as2=0;
		
DragDrop('myCondition')	   //Drag & Drop		
change_mstatus()
}

//==============================>max 11_05_07<===========================


function chk_select_con_change()
{
			
	var index_select_con="";
		
	
	index_con_new="";
	
	var op_name = document.getElementsByName("op[]");
		
        	
     for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		index_con_new = index_con_new + document.getElementById('op['+op_name[j].value+']').selectedIndex;
		
			
	}
		
	/*for(var j=0;j<tr_length("tcondition")-1;j++)
	{
		
		
		index_con_new = index_con_new + document.getElementById('op['+j+']').selectedIndex;
			
		//alert(document.getElementById('op[1]').selectedIndex);
		
	}*/
		
	
		
}
//=========================================================================

function load_indexs_select_con()
{
	
	var index_select_con="";
	var x=1;
	var tag_select;
	
	for(var j=0;j<tr_length("tcondition");j++)
	{
		
		//tag_select=document.getElementsByTagName('select');back_paren
		//alert(tag_select.name);
		
		index_con = index_con + document.getElementById('op['+j+']').selectedIndex;
		text_con=text_con + document.getElementById('text'+x).value;
		x++;
		
		
	}
	
	
	var f_paren = new Array();
	var b_paren = new Array();
	
	var front_paren = document.getElementsByName('front_paren[]');
	var back_paren = document.getElementsByName('back_paren[]');
	
		
	
	for(var i=0; i<front_paren.length; i++)
	{
		
		
		f_paren[i] = front_paren[i].value;
		b_paren[i] = back_paren[i].value;
		
		if(f_paren[i]=="") f_paren[i]="*";
		
		if(b_paren[i]=="") b_paren[i]="*";
		
		paren_f=paren_f + f_paren[i];
		paren_b=paren_b + b_paren[i];
			
		
	}
	
			
		
	index_con_new=index_con;
	load_indexs_select_logical();
	
}
//=========================================================================

function chk_paern_change()
{
	
	var f_paren_new = new Array();
	var b_paren_new = new Array();
	
	var front_paren = document.getElementsByName('front_paren[]');
	var back_paren = document.getElementsByName('back_paren[]');
			
	
	for(var i=0; i<front_paren.length; i++)
	{
		
		f_paren_new[i] = front_paren[i].value;
		b_paren_new[i] = back_paren[i].value;
		
		if(f_paren_new[i]=="") f_paren_new[i]="*";
		
		if(b_paren_new[i]=="") b_paren_new[i]="*";
		
		paren_f_new=paren_f_new + f_paren_new[i];
		paren_b_new=paren_b_new + b_paren_new[i];
			
		
	}
	
}//end function

function chk_select_logical_change()
{
	var delpos = new Array();
	var selectlist = document.getElementById('logic[]');
	var index_select="";
		
	//alert(selectlist.length)
	for(var i=0; i<selectlist.length; i++)
	{
		
		//delpos[i] = selectlist[i].options[selectlist[i].selectedIndex].value;
		delpos[i] = selectlist[i].selectedIndex;
		index_select=index_select + delpos[i];
		
	}
	
		
	
	index_logical_new=index_select;	
	//alert(index_logical_new);
}
//=========================================================================

function load_indexs_select_logical()
{
	var delpos = new Array();
	var selectlist = document.getElementsByName('logic[]');
	var index_select="";
	
	for(var i=0; i<selectlist.length; i++)
	{
		
		
		delpos[i] = selectlist[i].selectedIndex;
		index_select=index_select + delpos[i];
		index_logical=index_select;
		
		index_logical_new=index_logical;
	}	
	
	//alert(index_logical);
	
}

//=========================================================================

function insertCode(name,value,select,xx,type){
		
		condition_ser++;
		
		//alert(xx);
		/*var idx=chk_insertcode.length;
		
		if(idx=="0"){
		chk_insertcode[idx]=condition_ser;
		idx++;
		
		}else{
			for(var m=0;m<idx;m++){
				chk_insertcode[idx]=condition_ser;
				
			}
			
		}*/
		
		
		// start position is 0 then we pos = length of <tr> - 1		
		var pos = tr_length("myCondition");

       	var x=document.getElementById('myCondition').insertRow(pos)		// insert new row
		var y=document.getElementById('myCondition').rows							// get attribute of row
		var z=document.getElementById('myCondition').rows(pos-1)				// get attribute of row

		var a=x.insertCell(0)			// assign position of cell 1 in new row
		var b=x.insertCell(1)			// assign position of cell 2 in new row
        var c=x.insertCell(2)			// assign position of cell 3 in new row
		var d=x.insertCell(3)			// assign position of cell 4 in new row
		var e=x.insertCell(4)			// assign position of cell 8 in new row
		var f=x.insertCell(5)			// assign position of cell 5 in new row
		var g=z.cells[6]
		var h=x.insertCell(6)			// assign position of cell 6 in new row
		var i=x.insertCell(7)			// assign position of cell 7 in new row
		//var l=x.insertCell(8)			// assign position of cell 8 in new row

		x.bgColor="#FFFFFF"				// assign background color to TR

		a.innerHTML = "<input type='text' size='1' class='front_paren' id='p_front' name='front_paren[]' value=''  style='font-size=12px; font-weight:bold; color:#FF0000; border:1px solid #C2C2C2' onFocus='add_border(this);' onBlur='remove_border(this);' onKeyPress='javascript: return add_front(event);'>";
//		b.innerHTML= name+"<input type='hidden' name='field1[]' value='"+value+"'>";			// insert fieldlist

		b.innerHTML ="<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','condition','"+xx+"')\">"+name+"</a><input type='hidden' name='field1[]' value='"+value+"'>";	//Insert link for modify fields name <bow> 15-10-2007 //Send x to Changename <BOW> 13-12-2007


		c.innerHTML = "<input type='hidden' id='no_decode[]' name='no_decode[]' value="+condition_ser+"><input type='hidden' name='decode[]' value=1><span id='specific1' style='visibility:visible'>" + insertOperator(condition_ser,1,type) + "</span>";			// insert operator
	
		d.innerHTML="<input type='checkbox' checked id='type["+(condition_ser-1)+"]' name='type["+(condition_ser-1)+"]' value=1 onclick=\"toggle_text('text"+condition_ser+"')\">";
		
				
		e.innerHTML = "<select id='text"+condition_ser+"' disabled name='var["+(condition_ser-1)+"]' style='width:150px;font-size:9px;'>"+select+"</select> <input type='hidden' id='text_name[]' name='text_name[]' value="+condition_ser+"><input type ='hidden' value='NULL' name='hid_var["+(condition_ser-1)+"]' id='hid_var["+(condition_ser-1)+"]'>";
		//e.innerHTML = "<span id='specific2' style='visibility:visible'>"+insert_select()+"</span>";
		
		f.innerHTML = "<input type='text' size='1' class='back_paren' id='p_back' name='back_paren[]' value='' style='font-size=12px; font-weight:bold; color:#FF0000; border:1px solid #C2C2C2' onKeyPress='javascript: return add_back(event);' onFocus='add_border(this);' onBlur='remove_border(this);'>";

		if(pos >= 2)
			g.innerHTML = insertLogical(pos-1)
		else
			h.innerHTML = "&nbsp;";

		//e.innerHTML = "<input type='checkbox' id = 'd1' name='d1' value="  +  pos + "><input type='hidden' name='id1[]' value='xx'>"	// insert checkbox
		i.innerHTML = "<input name='del' type='image' src='immagini/del.png' id="  +  pos + " style='cursor:auto' onClick='this.form.d3.value=this.id; doDelete_Condition(this.form);return false;'><input type='hidden' name='id[]' value='xx'>"		// insert checkbox
//		l.innerHTML = "<a href=\"#\" id='"+(pos-1)+"' onClick=\"moveRowDown(this.id,'tcondition')\"><img src='immagini/down.gif' border=0></a><a href=\"#\" id='"+(pos-1)+"' onClick=\"moveRowUp(this.id,'tcondition')\"><img src='immagini/up.gif' border=0></a>";

		b.align = "left"
		c.align = "center"
		d.align = "center"
		e.align = "center"
		g.align = "center"

		y[pos+1].align = "left"			// left alignment for the last row
		
DragDrop('myCondition')	 //Drag & Drop 		
change_mstatus()
			for(i=1;i<=pos;i++){
				re_condition(i)
			}
}


/**************************************************************************************/
/* insertOrder is function that append new row of table which have 4 columns and 5 elements*/
/* 1. order 2. field dropdown list; 3. orderby downdown list  4.checkbox  5. hidden*/
/**************************************************************************************/
function insertOrder(name,value,xx){//Send x to Changename <BOW> 13-12-2007
		// start position is 0 then we pos = length of <tr> - 1
		
		var pos = tr_length("myOrder");

       	var x=document.getElementById('myOrder').insertRow(pos)		// insert new row
		var y=document.getElementById('myOrder').rows							// get attribute of row
		
		var a=x.insertCell(0)			// assign position of cell 1 in new row
		var b=x.insertCell(1)			// assign position of cell 2 in new row
        var c=x.insertCell(2)			// assign position of cell 3 in new row
        var d=x.insertCell(3)			// assign position of cell 3 in new row
	//	var e=x.insertCell(4)			// assign position of cell 3 in new row----//june add
	//	var f=x.insertCell(5)			// assign position of cell 3 in new row----//june add

		x.bgColor="#FFFFFF"			// assign background color to TR

       	//a.innerHTML=insertOrderChoice()	// insert fieldlist
		//a.innerHTML=insertChoice2()	// insert fieldlist
		
		//a.innerHTML=name+"<input type='hidden' name='field2[]' value='"+value+"'>";			// insert fieldlist
		//alert(value);
		a.innerHTML="<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+value+"',"+pos+",'"+name+"','order','"+xx+"')\">"+ name +"</a><input type='hidden' value='"+value+"' name='field2[]'>";			//Insert link for modify fields name <bow> 15-10-2007 //Send x to Changename <BOW> 13-12-2007
		b.innerHTML = insOrder()			// insert orderby
		//c.innerHTML = "<input type='checkbox' id = 'd2' name='d2' value="  +  pos + ">"		// insert checkbox
		c.innerHTML = insOrder_Group()			// insert orderby ---//june add
		//c.innerHTML = "<input type='checkbox' id = 'd2' name='d2' value="  +  pos + ">"		// insert checkbox
	  d.innerHTML = "<input type='image' src='immagini/del.png' id="  +  pos + " style='cursor:auto' onClick='this.form.d2.value="  +  pos + "; doDelete_Order(this.form); return false;'>"	// insert checkbox
		//e.innerHTML = "<input type='image'  src='immagini/down.gif' style='cursor:auto' onClick=\"moveRowDown("+(pos-1)+",'torder');return false;\"><b>/</b><input type='image'  src='immagini/up.gif' style='cursor:auto' onClick=\"moveRowUp("+(pos-1)+",'torder');return false;\">";
	//	f.innerHTML = "<input type='image'  src='immagini/up.gif' style='cursor:auto' onClick=\"moveRowUp("+(pos-1)+",'torder');return false;\">";


		a.align = "left"
		b.align = "center"
	    c.align = "center"
		d.align = "center"
	//	e.align = "center"
	//	f.align = "center"
		y[pos+1].align = "left"			// left alignment for the last row
		
DragDrop('myOrder')	 //Drag & Drop 		
change_mstatus()
}

/**************************************************************************************/
/*deleteResult is the function that delete selected rows*/
/**************************************************************************************/
function deleteResult(theForm,v){

		var count = 0;
		var tr_before = 0	// 2 <tr> but start at 0 then 0,1;
		var pos = "";


		start=Number(theForm.d.value)-1;
		tbody = document.getElementById('tresult'); 
		
		for(k=start;k<tbody.rows.length-2;k++)
		{			
			moveRowDown(k,'tresult',v);
		}
		
		document.getElementById('myResult').deleteRow(tbody.rows.length-2);		// delete selected row
	
}

function DelResultByCheck(){
	var form = document.query;
	var countCheckbox = 0;

	for(i=0;i<form.elements.length;i++){
		var elm = form.elements[i];
		if(elm.type == 'checkbox'){
			//if(elm.checked){
				countCheckbox++;
			//}
		}
	}

	tbody = document.getElementById('tresult');
	var rCnt = tbody.rows.length-2;
	for(tum=1;tum<=countCheckbox;tum++){

		var chkRs = "";
		for(j=1;j<=rCnt;j++){
			var chk = 0;
			for(k=0;k<form.elements.length;k++){
				if(chkRs==""){
					var elm = form.elements[k];
					if(elm.type == 'checkbox'){
						chk++;
						//if(elm.checked){
							chkRs = chk - 1;
						//}
					}
				}
			}
		}
		//alert(chkRs);
		
		tbody = document.getElementById('tresult');
		var pos = chkRs; // ÂµÃ©Ã?Â§Ã Â»Ã…Ã•Ã¨Ã?Â¹ Â¨Âº..... pos = 1 Ã?Ã?Ã’Ã?Â¶Ã–Â§Ã¡Â¶Ã?Â·Ã•Ã¨ 2
		for(k=pos;k<tbody.rows.length-2;k++)
		{
			moveRowDown(k,'tresult');
		}
		document.getElementById('myResult').deleteRow(tbody.rows.length-2);
		
	} // for(tum=1;tum<=countCheckbox;tum++){


		if (tr_length("myResult")==1)
		{
		document.getElementById('myResultDel').deleteRow(0);

		}

/*
		tbody = document.getElementById('tresult');
		var pos = 0; // ÂµÃ©Ã?Â§Ã Â»Ã…Ã•Ã¨Ã?Â¹ Â¨Âº.....
		for(k=pos;k<tbody.rows.length-2;k++)
		{
			moveRowDown(k,'tresult');
		}
		document.getElementById('myResult').deleteRow(tbody.rows.length-2);
*/
change_mstatus()
}


/**************************************************************************************/
/*deleteCondition is the function that delete selected rows*/
/**************************************************************************************/
function deleteCondition(theForm)
{

		//var row = 0;
		var tr_before = 0	// 2 <tr> but start at 0 then 0,1;
		var count = 0;
		var pos = "";
		id_riga = Number(theForm.d3.value);
		tbody = document.getElementById('tcondition'); 
		start=id_riga-1;
//alert(tbody.rows.length-3);
		for(k=start;k<tbody.rows.length-3;k++)
		{
			rowNo = k+1; 
			rowBelow = rowNo + 1; 

			tbody = document.getElementById('tcondition'); 

			currentRowCells = tbody.rows[rowNo].cells; 
			currentCellContent = new Array(); 
			for(i=0;i<currentRowCells.length;i++)
			{ 
				currentCellContent[i] = currentRowCells[i].innerHTML; 
				
			} 
			
			
//			name_fparen=currentCellContent[0].substring(currentCellContent[0].indexOf("front_paren["),currentCellContent[0].indexOf("]"));
//			currentCellContent[0]=currentCellContent[0].replace(name_fparen,"front_paren["+(rowNo))
//			
//			alert(currentCellContent[0])
			
			belowRowCells = tbody.rows[rowBelow].cells; 
			belowCellContent = new Array(); 
			for(i=0;i<currentRowCells.length;i++)
			{ 
				belowCellContent[i] = belowRowCells[i].innerHTML; 
			} 
			
			
			name_fparen=belowCellContent[0].substring(belowCellContent[0].indexOf("front_paren["),belowCellContent[0].indexOf("]"));
			belowCellContent[0]=belowCellContent[0].replace(name_fparen,"front_paren["+(rowNo-1))
			
			//alert(belowCellContent[0])
			
			name_bparen=belowCellContent[5].substring(belowCellContent[5].indexOf("back_paren["),belowCellContent[5].indexOf("]"));
			belowCellContent[5]=belowCellContent[5].replace(name_bparen,"back_paren["+(rowNo-1))
			
			//alert(belowCellContent[5])
			re_condition(rowNo);

			for(i=0;i<currentRowCells.length;i++)
			{ 
				if(belowCellContent[i]!="&nbsp;")
				{
					tbody.rows[rowNo].cells[i].innerHTML = belowCellContent[i]; 
					tbody.rows[rowBelow].cells[i].innerHTML = currentCellContent[i]; 
				}
				
/*				if(i==3) {
					tbody.rows[rowNo].cells[i].innerHTML = currentCellContent[i]; 
					tbody.rows[rowBelow].cells[i].innerHTML = belowCellContent[i]; 
				}*/
				
				
			}
			
/////////////////// [Firefox]-->For checkbox in condition[BOW]///////////////////////			
			if(tbody.rows[rowNo].cells[3].innerHTML.match("value=\"0\" checked=\"checked\""))
				tbody.rows[rowNo].cells[3].innerHTML=tbody.rows[rowNo].cells[3].innerHTML.replace("value=\"0\" checked=\"checked\"","value=\"0\"")
			else if(tbody.rows[rowNo].cells[3].innerHTML.match("value=\"1\""))
				tbody.rows[rowNo].cells[3].innerHTML=tbody.rows[rowNo].cells[3].innerHTML.replace("value=\"1\"","value=\"1\" checked=\"checked\"")
/////////////////////////////////////////////////////////////////////////////////////				
		} 
		
		document.getElementById('myCondition').deleteRow(tbody.rows.length-2);
		
		
		
		//Aggiorno tutte le righe sotto a quella cancellata decrementando l'id
	var inputs = tbody.getElementsByTagName("input"); 	
		for (var i = 0; i < inputs.length; i++) { 
		
			var num_id = parseFloat(inputs[i].id); 
			if(num_id)
				if(num_id>start)
					inputs[i].id = num_id-1;
		}
		tbody.rows[tbody.rows.length-2].cells[6].innerHTML = "";
				
	//========================max 14_05_07=================	
	length_con=tr_length("tcondition")-1;
	pos=tr_length("tcondition")-1;
	if(length_con==0)
	condition_ser=0;
	change_mstatus()		
	for(i=1;i<=pos;i++){
		re_condition(i)
	}
	//==============end==========max 14_05_07==============
	}
/**************************************************************************************/
/*deleteOrder is the function that delete selected rows*/
/**************************************************************************************/
function deleteOrder(theForm){
	
		var count = 0;
		var tr_before = 0	// 2 <tr> but start at 0 then 0,1;
		var pos = "";
		
		/*var row = 0;
		var tr_before = 0	// 2 <tr> but start at 0 then 0,1;
		var count = 0;
		var pos = "";
		
		if(theForm.d2 && theForm.d2.length){  // in case that we have more than 1 checkbox
			count = theForm.d2.length;			// count number of checkbox
	
			for(i=count; i>=1; i--){					// loop from bottom to top
				if (eval("document.query.d2[" + (i-1) + "].checked") == true) pos = pos + (i+tr_before)  + ","  ;	// append checked position separate by comma (,)
			}
		}
		else if(theForm.d2){  // in case that we have only 1 checkbox
			if(document.query.d2.checked){
				pos = (tr_length("myOrder") - 1) + ",";  // pos = "2,";  // number of 3 <tr> before (0,1) delete record + position of first checkbox
			}
			else 	pos = "";
		}
	
		var myArray = pos.split(',');	 // split data into myArray

		// start loop for delete selected rows
		for(i=0; i < (myArray.length -1); i++)
			document.getElementById('myOrder').deleteRow(myArray[i]);		// delete selected row*/
			
		start=Number(theForm.d2.value)-1;
		tbody = document.getElementById('torder'); 
		
		for(k=start;k<tbody.rows.length-3;k++)
		{
			moveRowDown(k,'torder');
		}
		document.getElementById('myOrder').deleteRow(tbody.rows.length-2);		// delete selected row

		change_mstatus()			
}
/**************************************************************************************/
/* check data before sending data to next form */
/**************************************************************************************/
function isBlank(data){
	var result = true;

	for(var i = 0; i < data.length; i++){
		if(data.charAt(i) != " ") result = false;
	}
	return result;
}
/**************************************************************************************/
/* check data before sending data to next form */
/**************************************************************************************/
function checkSubmit(theForm){
	//alert(theForm);
	var existTable = isExistTable();
	var isBlank_SPECIFIC = false;
	var blank_Position = "";

	//var query_value = theForm.query_desc.value;
	var result = tr_length("myResult");
	if (!existTable){
		displayWarning();
		return false;
	}
	else if (result == 1){	
		//alert("Seleziona le informazioni da stampare!");
		alert(text_02);
		//theForm.btn_add_result.focus();
		return false;
	}	
	else if ((document.getElementsByName("field[]").length) == 0){	
		//alert("Seleziona le informazioni da stampare!");
		alert(text_02);
		//theForm.btn_add_result.focus();
		return false;
	}

	//uthai****************************************************
else if(!is_correct_parenthesis()){	// Ã Â¾Ã”Ã¨Ã?Ã Â¢Ã©Ã’Ã¤Â»
		return false;				// Ã Â¾Ã”Ã¨Ã?Ã Â¢Ã©Ã’Ã¤Â»
	}	
	//**********************************************************

/*	else if (isBlank(query_value)) {
		alert("Il nome del report non pu? rimanere in bianco!");
		theForm.query_desc.select();
		theForm.query_desc.focus();
		return false;
	} */
	else if(existTable){ // if all data are collected
//		theForm.query_desc.value = document.query.query_desc.value;
		theForm.ID_Record.value = document.queryform.ID_Record.options[document.queryform.ID_Record.selectedIndex].value;
		theForm.record_name.value = document.queryform.ID_Record.options[document.queryform.ID_Record.selectedIndex].text;
		return true;
	}
	else {
		displayWarning();
		return false;
	}
}

/**************************************************************************************/
/* check data before VIEW REPORT to next form */
/**************************************************************************************/
function checkView(theForm){
		if(checkSubmit(theForm))
		return true;
	else return false;
}
/**************************************************************************************/
/* check data before SAVE REPORT to next form */
/**************************************************************************************/

function checkSaveCrt(theForm){
	//var query_value = theForm.query_desc.value;
	var send_status = checkSubmit(theForm) ;
	
	//if((send_status) && (!isBlank(query_value))){ 
		if((send_status)){ 

		//modalvalue = window.showModalDialog("modaldia.php?query_desc="+query_value, "","dialogWidth:400px;'+'dialogHeight:250px;")
		//return modalvalue;
		
		
		return true;
	}
	//else if((send_status) && (isBlank(query_value))){
			else if((send_status)){

		//alert(text_04);
		//alert("ATTENZIONE: Inserisci un nome per il report.");
				alert(text_10);
				//alert(save);

		return false;
	}
	else {
		return false;
	}
}

function checkSave(theForm){

	//var query_value = theForm.query_desc.value;
	var send_status = checkSubmit(theForm) ;
	var old_desc = theForm.query_desc_old.value;
	//if((send_status) && (!isBlank(query_value))){ 
		if((send_status)){ 

		/*if(query_value != old_desc){
			confirmval = confirm(text_08);
		}*/
		if(confirmval==true){
			//modalval = window.showModalDialog("modaldia.php?query_desc="+query_value, "","dialogWidth:400px;'+'dialogHeight:250px;")				
		//	return modalval;
			return true;
		}
		else
			return confirmval;
	}
	//else if((send_status) && (isBlank(query_value))){
			else if((send_status)){

		alert(text_05);
		//alert("Il nome del report non puÃ² essere vuoto!");
		return false;
	}
	else {
		return false;
	}
}
/**************************************************************************************/
/* showCondition is function that  show and hide table myCondition */
/* 1. the name of span 2. flag */
/**************************************************************************************/
function showCondition(span_name, s_value) {
   var OP = s_value;

   var span1 = document.getElementById(span_name);

   if(OP == 0){
   span1.style.visibility = 'hidden';
   }
   else{
   span1.style.visibility = 'visible';
   }
};
/*********************************************************************************************/
// searching for used option element and ignored it, after then refresh option element
/*********************************************************************************************/
function showOnlyNotDisplayList(myField, field_pos){
	var optionValue = new Array();
	var optionText = new Array();
	var delpos = new Array();
	var found = new Array();
	var tempVal = new Array();
	var tempText = new Array();

	var selectlist = document.getElementsByName(myField);

	// loop checking for already choose selection list , add it into array delete position:delpos
	for(var i=0; i<selectlist.length; i++)	delpos[i] = selectlist[i].options[selectlist[i].selectedIndex].value;

	optionValue = OPTION_VALUE;	 // use temporary array
	optionText = OPTION_TEXT;	 // use temporary array

	k = 0;
	//*
	// search for delete position of element in delpos
	// if found then assign undefined value to array found
	// else assign old optionValue to array found
	//*
	for(j=0; j<delpos.length; j++){
		for(k=0;k<optionValue.length; k++){
			if(delpos[j] == optionValue[k]){	// found delete
				found[k] = "undefined";
			}
			else 	found[k] = optionValue[k];  // end if
		} // end for k
		optionValue = found;
	} // end for j
	//*
	// search undefined value in each array in optionValue if found ignore it!
	// if optionValue not equals to undefined then assign old value and old text to temporary array
	//*
	i = 0;
	for(m=0; m < optionValue.length ; m++){	
		if(optionValue[m] != 'undefined'){ 
			tempVal[i] = optionValue[m];
			tempText[i] = optionText[m];
			i++;
		}// end if
	}// end for

TEMP_OPTION_VALUE[field_pos] = tempVal;	// assign new array value 
TEMP_OPTION_TEXT[field_pos] = tempText;		// assign new array text
}
//*
// remove inside select list elements
//*
function removeOptionSelected(myField)
{
	var selectlist = document.getElementsByName(myField);
	var i;
	var show_item_value, list_member_value;

	for (i = selectlist.length - 1; i >=0 ; i--){ // for each selection list value
		show_item_value = selectlist[i].options[selectlist[i].selectedIndex].value; 
		for(j=selectlist[i].length -1; j >=0; j--){ // for each selected list value
			list_member_value = selectlist[i].options[j].value; 
			if(show_item_value != list_member_value){	selectlist[i].remove(j);	} // if show selection list value not equal to  value in selected list
		} // end for j
	} // end for i
}

//==============================>max 11_05_07<===========================


function chk_select_ord_change()
{
	var delpos = new Array();
	var selectlist = document.getElementsByName('ord[]');
	var index_select="";
		
	
	for(var i=0; i<selectlist.length; i++)
	{
		
		//delpos[i] = selectlist[i].options[selectlist[i].selectedIndex].value;
		delpos[i] = selectlist[i].selectedIndex;
		index_select=index_select + delpos[i];
		
	}
	
	//alert(document.getElementById('chk_save_ord')[0].selectedIndex);
	
	
	index_ord_new=index_select;		
}
//=========================================================================

function load_indexs_select_ord()
{
	var delpos = new Array();
	var selectlist = document.getElementsByName('ord[]');
	var index_select="";
	
	for(var i=0; i<selectlist.length; i++)
	{
		
		
		delpos[i] = selectlist[i].selectedIndex;
		index_select=index_select + delpos[i];
		index_ord=index_select;
		
		index_ord_new=index_ord;
	}	
	
}
//********************************june***Grouping***********************
function chk_select_gro_change()
{
	var delpos = new Array();
	var selectlist = document.getElementsByName('gro[]');
	
	var index_select="";
		
	
	for(var i=0; i<selectlist.length; i++)
	{
		
		//delpos[i] = selectlist[i].options[selectlist[i].selectedIndex].value;
		delpos[i] = selectlist[i].selectedIndex;
		index_select=index_select + delpos[i];
		
	}
	
	//alert(document.getElementById('chk_save_ord')[0].selectedIndex);
	
	
	index_ord_new=index_select;		
	
}

function load_indexs_select_gro()
{
	var delpos = new Array();
	var selectlist = document.getElementsByName('gro[]');
	var index_select="";
	
	for(var i=0; i<selectlist.length; i++)
	{
		
		
		delpos[i] = selectlist[i].selectedIndex;
		index_select=index_select + delpos[i];
		index_ord=index_select;
		
		index_ord_new=index_ord;
	}	
	
}

//**********************************end june*****************************

//=========================================================================

function validate(form,type,filetype)
{		
  	if(form.query_desc!=null)
  	form.query_desc.value=document.desc.query_desc.value;	
  //  form.query_txt.value=document.add_query.query_txt.value;
//	form.query_desc.value=document.add_query.query_desc.value;
  	if (type==0)
 		form.todo.value="ViewReport";
 	else if (type==1)
 		form.todo.value="CreateChart";
 	else if (type==2)
 		form.todo.value="SaveReport";
 	else if (type==3){
 		form.todo.value="SaveAs";
 		form.fileType.value=filetype;
	}else if (type==4){	
		form.todo.value="SaveView";//june
		//	alert(form.todo.value);
	}
	else if (type==5){	
			form.todo.value="ViewQuery";//june
		//	alert(form.todo.value);
	}	
	else if (type==6){	
			form.todo.value="SaveQuery";//june
			//alert(form.todo.value);
	}	


		
	var result = tr_length("myResult");

	//if (result == 1)//old
	if (result == 1 && type!=6 && type!=5)//june query 12-02-2008
 	{//	alert("ATTENZIONE: Scegli le informazioni da stampare.");
	alert(text_11);
	
	
	}else if(form.query_desc.value=="" && type==2){
	
 	//	alert("ATTENZIONE: Inserisci un nome per il report.");
	alert(text_10);
	
    }//****************june add**************
	else if(form.query_desc.value=="" && type==4 ){
	
 	//	alert("ATTENZIONE: Inserisci un nome per il report.");
	alert(text_37);
	
	}//****************end june add**************
	//****************june query12-02-2008**************
	else if(form.query_desc.value=="" && type==6 ){
	
 	alert(text_82);
	//alert(text_37);
//	alert("you want save Query");
	
	}//****************june query12-02-2008**************

 	else if (type!=6 && type!=5)//june query 12-02-2008
	{
	//==========================max=========================
		
		chk_paern_change();//check  parentheses change
		
		
		
		length_con=tr_length("tcondition")-1;
				
		var x=1;			
		
			//=========max=========
		var name_text=document.getElementsByName('text_name[]');
		
		
		for(var j=0;j<length_con;j++)
		{
			//alert(name_text[j].value)
			text_con_new=text_con_new+document.getElementById('text'+name_text[j].value).value;
			
		}
		
  //=========================================================
		function chk_length()
		{
			
		var row_re=tr_length("tresult")
		var row_co=tr_length("tcondition")
		var row_or=tr_length("torder")
		 
		
		
		//============================use for check report's note===============================
			text_note_new=document.getElementById('note').value;
			text_query_desc=document.getElementById('query_name_report').value;//june edit 17-12-2007
		
		//======================================================================================
		
		
		//if((rows_result == row_re) && (rows_condition == row_co) && (rows_order == row_or) && (index_ord==index_ord_new) && (index_con==index_con_new) && (index_logical==index_logical_new) && (text_con==text_con_new) && (text_note==text_note_new) && (paren_f==paren_f_new) && (paren_b==paren_b_new))
		if((rows_result == row_re) && (rows_condition == row_co) && (rows_order == row_or) && (index_ord==index_ord_new) && (index_con==index_con_new) && (index_logical==index_logical_new) && (text_con==text_con_new) && (text_note==text_note_new) && (paren_f==paren_f_new) && (paren_b==paren_b_new) && (text_query_desc==text_desc_query))//june edit 17-12-2007

		{
			
			if(type==4){
			form.chk_save.value="Save_view";
			}else{
			form.chk_save.value="Save";
			}
		}
		else
		{
			//alert(save1);
			if(type==4){
			form.chk_save.value="Save_view1";
			}else{
			form.chk_save.value="Save1";
			}
		}
				
		}//end function
	
		
		
	//=============================================================
	if (type != "0") chk_length();			
 		//form.submit();
 		is_correct_parenthesis(form);
		
	}	
	else{//june query 12-02-2008
	
	 if(document.getElementById('query_txt').value=="" ){
	alert(text_83);
	}else if(document.getElementById('query_txt').value.replace(" ","")=="SELECT" || document.getElementById('query_txt').value.replace(" ","")=="select"){
   alert(text_84);
      
  //}else if((document.getElementById('query_txt').value.split("*")).length>1){ //16-02-2009
 
 //  alert(text_85);
   
 }else{
	
	var txtQuery=document.getElementById('query_txt').value;
	var q_split=txtQuery.split(" ");
	
//	alert(q_split[0]);
	
	var block_list=Array("UPDATE","INSERT","DELETE","CREATE","ALTER","ANALYZE","BACKUP","CACHE","CHANGE","CHECK","CHECKSUM","COMMIT","DESCRIBE","DO","DROP","EXPLAIN","FLUSH","GRANT","HANDLER","JOIN","KILL","LOAD","OPTIMIZE","PURGE","RENAME","REPAIR","REPLACE","RESET","RESTORE","REVOKE","ROLLBACK","SAVEPOINT","SET","SHOW","START","STOP","TRUNCATE","UNION","UNLOCK","USE","LIMIT");
	
	var c;
	q_split[0]=q_split[0].replace(" ","");
	for(c=0;c<=block_list.length;c++){
		//alert(block_list[c]);
		var check_query=q_split[0].indexOf(block_list[c]);
		
		if((q_split[0]=="SELECT" || q_split[0]=="select") && (txtQuery!="SELECT" || txtQuery!="select")&&(!txtQuery.match(" LIMIT "))){
			//alert(q_split[0]);
			//alert("55555555555555");	
			if (type == "6"){ chk_length1();}
			form.submit();
			break;
			
			}//****
				
		else if((check_query!="" && q_split[0]!="SELECT" || q_split[0]!="select" || txtQuery=="SELECT" || txtQuery=="select")&&(!txtQuery.match(" LIMIT "))){
			check_have_block_list="YES";
			alert(text_86+q_split[0]);
			break;
			
			}//end if
			//**********************june add check block  insert "LIMIT" 22-07-2008**************************
		else if((check_query!="" && q_split[0]=="SELECT" || q_split[0]=="select" || txtQuery=="SELECT" || txtQuery=="select")&&(txtQuery.match(" LIMIT "))){
			check_have_block_list="YES";
			alert(text_86+" LIMIT");
			break;
			
			}//end if
	//**********************END june add check block  insert "LIMIT"  **************************					
	        
			
	}//end for
	
	}//end if
	
	
	function chk_length1()
		{
			
		var row_re=tr_length("tresult")
		var row_co=tr_length("tcondition")
		var row_or=tr_length("torder")
		 
		
		
		//============================use for check report's note===============================
			text_note_new=document.getElementById('note').value;
			text_query_desc=document.getElementById('query_name_report').value;//june edit 17-12-2007
		    text_create_query1=document.getElementById('query_txt').value;
		//======================================================================================
		
		
		//if((rows_result == row_re) && (rows_condition == row_co) && (rows_order == row_or) && (index_ord==index_ord_new) && (index_con==index_con_new) && (index_logical==index_logical_new) && (text_con==text_con_new) && (text_note==text_note_new) && (paren_f==paren_f_new) && (paren_b==paren_b_new))
		if( (text_note==text_note_new)&&(text_query_desc==text_desc_query) && (text_create_query1==text_create_query))//june edit 17-12-2007

		{
						
			form.chk_save.value="Save";
			
		}
		else
		{
			//alert(save1);
			
			form.chk_save.value="Save1";
			
		}
				
		}//end function
	
	//if (type == "6") chk_length1();
				
 		//form.submit();
 		//is_correct_parenthesis(form);
		}
  }  
 //**************************max add new********Use in main_document.php*******************
function open_treeview_document( x, tipo , id ,view_query)
{
	/*if(tipo=='formula')
		var stree = window.open("formula.php?x="+x+"&tipo=result&ID_Record="+id+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
	else if(tipo=='formula_condition')
		var stree = window.open("formula.php?x="+x+"&tipo=condition&ID_Record="+id+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
	else*/
	var stree = window.open("treeview_document.php?x="+x+"&tipo="+tipo+"&ID_Record="+id+"&tabella="+id+"&view_query="+view_query, "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes")
		
}
//**************************end max add new***************************

//**************************june add new***************************
function open_treeview1( x, tipo , id ,view_query) //june edit view_query---------01_08_2007
{
	if(tipo=='formula')
		var stree = window.open("formula.php?loopback_unset=unset&x="+x+"&tipo=result&ID_Record="+id+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
	else if(tipo=='formula_condition')
		var stree = window.open("formula.php?loopback_unset=unset&x="+x+"&tipo=condition&ID_Record="+id+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
	else
		    var stree = window.open("treeview.php?loopback_unset=unset&x="+x+"&tipo="+tipo+"&ID_Record="+id+"&tabella="+id+"&view_query="+view_query, "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") //june edit view_query---------01_08_2007
		
}
//**************************end june add new***************************

function open_treeview( x, tipo , id,view )
{//alert(view);
view=view.replace(/~singview~/gi,"'");
view=view.replace(/~douview~/gi,'"');
if(tipo=='formula')
			if(view!=""){//june add check view 
			var stree = window.open("formula.php?loopback_unset=unset&x="+x+"&tipo=result&view="+view+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
			}else{
			var stree = window.open("formula.php?loopback_unset=unset&x="+x+"&tipo=result&ID_Record="+id+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
		}
	else if(tipo=='formula_condition')
			if(view!=""){//june add check view 
			var stree = window.open("formula.php?loopback_unset=unset&x="+x+"&tipo=condition&view="+view+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
				}else{
			var stree = window.open("formula.php?loopback_unset=unset&x="+x+"&tipo=condition&ID_Record="+id+"&sess=unset", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
		}
	else
	/////////////////////////////////////june/////////////////////////////////
		if(view!=""){//june add check view 
//	alert(view);
		var stree = window.open("treeview.php?loopback_unset=unset&x="+x+"&tipo="+tipo+"&view="+view+"&tabella="+id, "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
			}else{
			//	alert(id);
		var stree = window.open("treeview.php?loopback_unset=unset&x="+x+"&tipo="+tipo+"&ID_Record="+id+"&tabella="+id, "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") 
			}
			//////////////////////end june////////////////////////////////
			
}
// assign all data to stringa 
// extract only first data (x;y;z = x = data[0])  and assign to campo
//set_valore('Address Id_new;store2.address_id;1:create_date&&store_id&store_id')
function open_excel(x,grouping){
			//window.open("report_xls.php?x="+x+"&start="+xlstart+"&end="+xlend+"&per="+perpage,"resizable=1,toolbar=no,status=yes,location=no,menubar=no,width=500,height=600,scrollbars=yes") ?x=$_REQUEST[x]&todo=SaveAs&grouping=$_REQUEST[grouping]&fileType=xls\"
			var stree = window.open("report.php?x="+x+"&todo=SaveAs&grouping="+grouping+"&fileType=xls", "treeView","resizable=1,toolbar=no,status=yes,location=no,menubar=no,scrollbars=yes") 
}

function set_valore(valore)
{

	var valori=valore.split("{;}");
	var campo=document.getElementById("campo");
	//alert(valore+";"+valori[1]);
	document.getElementById("stringa").value=valore;
	
	campo.value=valori[0]; // Â¡Ã?Â³Ã• treeview Ã Â»Ã§Â¹ÂªÃ—Ã¨Ã?Â¢Ã?Â§ field

}

function moveRowUp(theCell,tbodyID,v) { 
	
rowNo =Number(theCell)+1; 
rowBelow = rowNo - 1; 

tbody = document.getElementById(tbodyID); 

currentRowCells = tbody.rows[rowNo].cells; 
currentCellContent = new Array(); 
	for(i=0;i<currentRowCells.length;i++) { 
	currentCellContent[i] = currentRowCells[i].innerHTML;
//======================Rename vis[] 25-09-2007 <bow>======================
		if(currentCellContent[0]!= null){
			for(var numr=rowNo;numr>=1;numr--){
				var replacestr1="="+rowNo
				var replacestr2="="+rowBelow
				var replacestr3=","+rowNo
				var replacestr4=","+rowBelow
				var newstr=currentCellContent[0].replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				currentCellContent[0]=newstr
			}
		}  

		if(currentCellContent[1]!= null){
			for(var numr=rowNo;numr>=1;numr--){
//				var replace_v1="v["+(rowNo)+"]"
//				var replace_v2="v["+(rowBelow)+"]"
				var replacestr1="vis["+(rowNo)+"]"
				var replacestr2="vis["+(rowBelow)+"]"
				var replacestr3="toggle_vis(this,"+rowNo+")"
				var replacestr4="toggle_vis(this,"+rowBelow+")"
				var newstr=currentCellContent[1].replace(replacestr1,replacestr2)
//				newstr=newstr.replace(replace_v1,replace_v2)
				newstr=newstr.replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				currentCellContent[1]=newstr
			}
		
		}
//==================End Rename vis[] 25-09-2007 ======================
	
	}

belowRowCells = tbody.rows[rowBelow].cells; 
belowCellContent = new Array(); 
	for(i=0;i<currentRowCells.length;i++) { 
	belowCellContent[i] = belowRowCells[i].innerHTML; 
//======================Rename vis[] 25-09-2007 <bow>======================
		if(belowCellContent[0]!= null){
			for(var numr=rowNo;numr>=1;numr--){
				var replacestr1="="+numr
				var replacestr2="="+rowNo
				var replacestr3=","+numr
				var replacestr4=","+rowNo
				var newstr=belowCellContent[0].replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				belowCellContent[0]=newstr
			}
		}  


		if(belowCellContent[1]!= null){
			for(var numr=rowNo;numr>=1;numr--){
//				var replace_v1="v["+(numr)+"]"
//				var replace_v2="v["+(rowNo)+"]"
				var replacestr1="vis["+(numr)+"]"
				var replacestr2="vis["+(rowNo)+"]"
				var replacestr3="toggle_vis(this,"+numr+")"
				var replacestr4="toggle_vis(this,"+rowNo+")"
				var newstr=belowCellContent[1].replace(replacestr1,replacestr2)
//				newstr=newstr.replace(replace_v1,replace_v2)
				newstr=newstr.replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				belowCellContent[1]=newstr
			}
		}
//==================End Rename vis[] 25-09-2007 ======================

	}

	for(i=0;i<currentRowCells.length-2;i++) { 
		
		if(rowBelow!=0)
		{
				
			tbody.rows[rowNo].cells[i].innerHTML = belowCellContent[i]; 
			tbody.rows[rowBelow].cells[i].innerHTML = currentCellContent[i]; 
				
				if(tbodyID=='tcondition' && i==6) {
					tbody.rows[rowNo].cells[i].innerHTML = currentCellContent[i]; 
					tbody.rows[rowBelow].cells[i].innerHTML = belowCellContent[i]; 
				}
		}
	}
	/*var vis1 = document.getElementById("vis["+rowNo+"]");
	var vis2 = document.getElementById("vis["+rowBelow+"]");
	var vis3 = vis1.value;
	vis1.value = vis2.value;
	vis2.value = vis3;*/
	if(!v){
	re_vis();
	}
	change_mstatus()
}

function export_field(from,to,x)//Send x to Changename <BOW> 13-12-2007
{
	var condi;
	var testo;
	if(to=="tcondition")
	//	testo = "ATTENZIONE: Verranno aggiunti tutti i campi in stampa alle condizioni.\nProseguo?";
			testo = text_12;

	else if(to=="torder")
	//	testo = "ATTENZIONE: Verranno aggiunti tutti i campi in stampa all\'ordinamento.\nProseguo?";
			//////////////////// Check Formula <BoW> //////////////////////
//						if(document.getElementById('KFormula')){
//							condi=1;
//							alert("Can't export Formula field!!!");
//						}
//						else
							testo = text_13;
			///////////////// End Check Formula <BoW> ////////////////////////

//if(condi!=1){//For Check Formula <BoW>
	if(confirm(testo))
	{
		
		//prendo i due oggetti
		tBodyfrom = document.getElementById(from); 
		tBodyto = document.getElementById(to); 
		//e copio tutte le righe da una tabella all'altra

		for(j=1;j<tBodyfrom.rows.length-1;j++)	
		{
			currentRowCells = tBodyfrom.rows[j].cells; 
			currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				
				
				nome=stringa.substring(stringa.indexOf( "\">")+2,stringa.indexOf( "</", 0 ));			
				//alert("FROM=="+stringa);
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );
				
				valore=stringa.substring(pos1,pos2);
//		alert("valore=="+valore);
				//########june add type for check date 23-09-2008#############
			    pos3=stringa.indexOf( "field_type##", 0 )+12;
			   	pos4=stringa.indexOf( " name=field_type[]", 0 );
				field_type=stringa.substring(pos3,pos4);
				//alert(field_type);
				//########june add type for check date 23-09-2008#############
					var aa = stringa.substr((stringa.length-7),7);
					
					//alert(stringa.length);
					//alert(stringa);
					//alert(aa);
				/*				
				function Left(str, n){
						if (n <= 0)
							return "";
						else if (n > String(str).length)
							return str;
						else
							return String(str).substring(0,n);
					}
					function Right(str, n){
						if (n <= 0)
						   return "";
						else if (n > String(str).length)
						   return str;
						else {
						   var iLen = String(str).length;
						   return String(str).substring(iLen, iLen - n);
						}
				}
			
				*/
				
				
				
				 if(valore.match(">\"")){
					valore=valore.replace(">\"","");
					valore=valore.replace("\"","");
				}								
				else if(valore.match("\"")){
					 pos1=stringa.indexOf( "value=", 0 )+7;
					 pos2=stringa.indexOf( "\" name", 0);
					 valore=stringa.substring(pos1,pos2);
				}	
				
													
				if(stringa.match("KFormula"))
					formula_as2=1;
				else
					formula_as2=0;
				if(to=="tcondition")
						insertCondition(nome,valore,field_type,x);//Send x to Changename <BOW> 13-12-2007 
				else if(to=="torder"){
					if(formula_as2==0){
						
						insertOrder(nome,valore,x);//Send x to Changename <BOW> 13-12-2007
					}else{
						//alert("The formula field cannot insert to order!!");
						alert(text_43);
					}
				}
		
		}
	//}
}
	
	
	
}

function moveRowDown(theCell,tbodyID,v) {
rowNo = Number(theCell)+1; 
rowBelow = rowNo + 1; 

tbody = document.getElementById(tbodyID); 

currentRowCells = tbody.rows[rowNo].cells; 
currentCellContent = new Array(); 
	for(i=0;i<currentRowCells.length;i++) { 
	currentCellContent[i] = currentRowCells[i].innerHTML;
//======================Rename vis[] 25-09-2007 <bow>======================
		if(currentCellContent[0]!= null){
			for(var numr=1;numr<=rowNo;numr++){
				var replacestr1="="+numr
				var replacestr2="="+rowBelow
				var replacestr3=","+numr
				var replacestr4=","+rowBelow
				var newstr=currentCellContent[0].replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				currentCellContent[0]=newstr
			}
		}  


		if(currentCellContent[1]!= null){
			
				for(var numr=1;numr<=rowNo;numr++){
//					var replace_v1="v["+(numr)+"]"
//					var replace_v2="v["+(rowBelow)+"]"
					var replacestr1="vis["+(numr)+"]"
					var replacestr2="vis["+(rowBelow)+"]"
					var replacestr3="toggle_vis(this,"+numr+")"
					var replacestr4="toggle_vis(this,"+rowBelow+")"
					var newstr=currentCellContent[1].replace(replacestr1,replacestr2)
//					newstr=newstr.replace(replace_v1,replace_v2)
					newstr=newstr.replace(replacestr1,replacestr2)
					newstr=newstr.replace(replacestr1,replacestr2)
					newstr=newstr.replace(replacestr3,replacestr4)
					currentCellContent[1]=newstr
				}
				
		}
//==================End Rename vis[] 25-09-2007 ======================

	} 

belowRowCells = tbody.rows[rowBelow].cells; 
belowCellContent = new Array(); 
	for(i=0;i<currentRowCells.length;i++) { 
	belowCellContent[i] = belowRowCells[i].innerHTML; 
//======================Rename vis[] 25-09-2007 <bow>======================	
		if(belowCellContent[0]!= null){
			for(var numr=1;numr<=rowNo;numr++){
				var replacestr1="="+(numr+1)
				var replacestr2="="+rowNo
				var replacestr3=","+(numr+1)
				var replacestr4=","+rowNo
				var newstr=belowCellContent[0].replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				belowCellContent[0]=newstr
			}
		}  


	if(belowCellContent[1]!= null){
			for(var numr=1;numr<=rowNo;numr++){
//				var replace_v1="v["+(numr+1)+"]"
//				var replace_v2="v["+(rowNo)+"]"
				var replacestr1="vis["+(numr+1)+"]"
				var replacestr2="vis["+(rowNo)+"]"
				var replacestr3="toggle_vis(this,"+(numr+1)+")"
				var replacestr4="toggle_vis(this,"+rowNo+")"
				var newstr=belowCellContent[1].replace(replacestr1,replacestr2)
//				newstr=newstr.replace(replace_v1,replace_v2)
				newstr=newstr.replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr1,replacestr2)
				newstr=newstr.replace(replacestr3,replacestr4)
				belowCellContent[1]=newstr
			}
			
		}
//==================End Rename vis[] 25-09-2007 ======================

	} 

	for(i=0;i<currentRowCells.length-2;i++) { 
		
		//if(i==0 && belowCellContent[i]!="&nbsp;")
		if(belowCellContent[i]!="&nbsp;")
		{
			tbody.rows[rowNo].cells[i].innerHTML = belowCellContent[i]; 
			tbody.rows[rowBelow].cells[i].innerHTML = currentCellContent[i]; 

			if(tbodyID=='tcondition' && i==6) {
				tbody.rows[rowNo].cells[i].innerHTML = currentCellContent[i]; 
				tbody.rows[rowBelow].cells[i].innerHTML = belowCellContent[i]; 
			}

		}
	}

	/*var vis1 = document.getElementById("vis["+rowNo+"]");
	var vis2 = document.getElementById("vis["+rowBelow+"]");
	var vis3 = vis1.value;
	vis1.value = vis2.value;
	vis2.value = vis3;*/
	if(!v){
	re_vis()
	}
	change_mstatus()
} 

function IsBlank(theForm){
	if(theForm.ID_query.options[theForm.ID_query.selectedIndex].value == 0) return true;
	else return false;
	}
	
function checkShow(theForm){
	var prompt = text_prompt;
	if (IsBlank(theForm)){
	  alert(prompt);
	  return false }
	else return true;
	}

function confirmDelete(theForm){
	 var prompt = text_prompt ;
	if (IsBlank(theForm)){
	alert(prompt); 
	return false;}
	else if (confirm(prompt)) return true; 
	 else 
	 return false;
	 }
//*******************************************************************************************************//
// START VARIABLE CONDITION CHECK
//  @author Uthai ShiangJan 2006-01-30
//*******************************************************************************************************//
function check_join_for_edit(){
	var DEFAULT_DATA = "#135791113#";
	var data = "";
	var max_length =	document.getElementsByName("logic[]").length;

	for(var i=0; i < max_length; i++){

		if(max_length == 1){		// if you have only one logic combo box
			data = document.all.logic.value;
		} 
		else{
			data = document.all.logic[i].value;
		}	// end if

		 if(data == ""){	// if logic box is selected to blank
			if(document.all.specific1[i]){
				document.all.specific1[i].style.visibility = "visible";
			}
			if(document.all.specific2[i]){ 
				document.all.specific2[i].style.visibility = "hidden";
				document.getElementsByName("var[]")[i].value = DEFAULT_DATA;
			}
			if(document.all.specific1[i+1]){ 
				document.all.specific1[i+1].style.visibility = "hidden";
			}
			if(document.all.specific2[i+1]){ 
				document.all.specific2[i+1].style.visibility = "hidden";
				document.getElementsByName("var[]")[i+1].value = DEFAULT_DATA;
			}
			i++;	// skip next logic box because we can not set logic box to blank closely
		}
		else if(data != ""){
			if(document.all.specific1[i]){
				document.all.specific1[i].style.visibility = "visible";
			}
			if((document.all.specific2[i]) && (document.getElementsByName("var[]")[i].value == DEFAULT_DATA)){ 
				document.all.specific2[i].style.visibility = "visible";
				document.getElementsByName("var[]")[i].value = "";
			}
			if(document.all.specific1[i+1]){ 
				document.all.specific1[i+1].style.visibility = "visible";
			}
			if((document.all.specific2[i+1]) && (document.getElementsByName("var[]")[i+1].value ==DEFAULT_DATA)){ 
				document.all.specific2[i+1].style.visibility = "visible";
				document.getElementsByName("var[]")[i+1].value = "";
			} // end if
		} // end else if
	} // end for
}
function check_join_field(obj){
	var DEFAULT_DATA = "#135791113#";
	var data = "";
	var max_length =	document.getElementsByName("logic[]").length;

	for(var i=0; i < max_length; i++){
		if((i+1) < max_length){	 // if logic position + 1 is less than total of logic
			data = document.all.logic[i].value;
			data1 = document.all.logic[i+1].value ;
		
			if((data == "") && (data1 == "")){
				//alert("You can not set this logic to blanks ");
				alert(text_14);
				obj.selectedIndex = 1;
				break;
			} // end if
		}// end if
		else if(max_length == 1){		// if you have only one logic combo box
			data = document.all.logic.value;
		} 
		else{
			data = document.all.logic[i].value;
		}	// end if
/*
		if((data == "") && (document.getElementsByName("var[]")[i].value)){	// if logic box is selected to blank
			//alert("case1");
			if(document.all.specific1[i]){
				document.all.specific1[i].style.visibility = "visible";
			}
			if((document.all.specific2[i]) && (document.getElementsByName("var[]")[i].value == DEFAULT_DATA)){ 
				document.all.specific2[i].style.visibility = "visible";
				document.getElementsByName("var[]")[i].value = "";
			}
			if(document.all.specific1[i+1]){ 
				document.all.specific1[i+1].style.visibility = "visible";
			}
			if((document.all.specific2[i+1]) && (document.getElementsByName("var[]")[i+1].value ==DEFAULT_DATA)){ 
				document.all.specific2[i+1].style.visibility = "visible";
				document.getElementsByName("var[]")[i+1].value = "";
			} // end if
		}
		*/
		if(data == ""){	// if logic box is selected to blank
			if(document.all.specific1[i]){
				document.all.specific1[i].style.visibility = "visible";
			}
			if(document.all.specific2[i]){ 
				document.all.specific2[i].style.visibility = "hidden";
				document.getElementsByName("var[]")[i].value = DEFAULT_DATA;
			}
			if(document.all.specific1[i+1]){ 
				document.all.specific1[i+1].style.visibility = "hidden";
			}
			if(document.all.specific2[i+1]){ 
				document.all.specific2[i+1].style.visibility = "hidden";
				document.getElementsByName("var[]")[i+1].value = DEFAULT_DATA;
			}
			i++;	// skip next logic box because we can not set logic box to blank closely
		}
		else if(data != ""){
			if(document.all.specific1[i]){
				document.all.specific1[i].style.visibility = "visible";
			}
			if((document.all.specific2[i]) && (document.getElementsByName("var[]")[i].value == DEFAULT_DATA)){ 
				document.all.specific2[i].style.visibility = "visible";
				document.getElementsByName("var[]")[i].value = "";
			}
			if(document.all.specific1[i+1]){ 
				document.all.specific1[i+1].style.visibility = "visible";
			}
			if((document.all.specific2[i+1]) && (document.getElementsByName("var[]")[i+1].value ==DEFAULT_DATA)){ 
				document.all.specific2[i+1].style.visibility = "visible";
				document.getElementsByName("var[]")[i+1].value = "";
			} // end if
			
		} // end else if
	} // end for
} // end function
//*******************************************************************************************************//
// END VARIABLE CONDITION CHECK
//  @author Uthai ShiangJan 2006-01-30
//*******************************************************************************************************//
//*******************************************************************************************************//
// START PARENTHESIS CHECK
//  @author Uthai ShiangJan 2006-01-20
//*******************************************************************************************************//
//function add_front(e){
//	var key = window.event ? e.keyCode : e.which;
//	var keychar = String.fromCharCode(key);
//	if(keychar=="(")
//		return true
//	else
//		return false;
//}
//function add_back(e){
//	var key = window.event ? e.keyCode : e.which;
//	var keychar = String.fromCharCode(key);
//	if(keychar==")")
//		return true
//	else
//		return false;
//}
function add_front(e){//Use e.keyCode for Firefox because it cannot use e.which [BOW]
	var key = window.event ? e.keyCode : e.which;
	var k_code = e.keyCode;
	var keychar = String.fromCharCode(key);
		if(k_code==37 || k_code==39 || k_code==8 || k_code==46 || keychar=="("){
			return true
		}else{
			return false;
		}
}
function add_back(e){
	var key = window.event ? e.keyCode : e.which;
	var k_code = e.keyCode;
	var keychar = String.fromCharCode(key);
	if(k_code==37 || k_code==39 || k_code==8 || k_code==46 || keychar==")")
		return true
	else
		return false;
}
function add_border(object)
{
	object.style.border="2px solid #FF0000";
}

function remove_border(object)
{
	if(object.value.length>0)
	object.style.border="1px solid #FFFFFF";
	else
	object.style.border="1px solid #C2C2C2";
}

/**
 * Add back parenthesis when double click to front parenthesis input
 *
 * @author Uthai ShiangJan
 */
function add_front_parenthesis(obj){
/*	if(obj.value.length < 3){
		obj.value = obj.value + "(";
	}else{
		alert(text_06);
	}*/
}
/**
 * Add back parenthesis when double click to back parenthesis input
 *
 * @author Uthai ShiangJan
 */
function add_back_parenthesis(obj){
/*	if(obj.value.length < 3){
		obj.value = obj.value + ")";
	}else{
		alert(text_06);
	}*/
}

/**
 * Prepare parenthesis
 *
 * @author Uthai ShiangJan
 */
/*function prepare_parenthesis(){
	var parenthesis = new Array();
	var count = 0;
	var front = "";
	var back1 = "";
	
	if(!document.all.p_front) return true; // by tudtoo
	if(document.all.p_front.length > 0) 
		var maxlength = document.all.p_front.length; 
	else 
		var maxlength = 1;
	
	if(maxlength == 1){
		front = document.all.p_front.value;
		if(front != ""){
			for(var j=0; j < front.length; j++){
				parenthesis[count] = front.charAt(j);
				count++;
			} // end for
		} // end if
		back1 = document.all.p_back.value;
		if(back1 != ""){
			for(var j=0; j < back1.length; j++){
				parenthesis[count] = back1.charAt(j);
				count++;
			} // end for
		} // end if
	}
	else{
		for(var i=0; i < maxlength; i++){
			if(document.all.p_front[i].value != "" ){
				front = document.all.p_front[i].value;
				if(front != ""){ 
					for(var j=0; j < front.length; j++){
						parenthesis[count] = front.charAt(j);
						count++;
					} // end for
				} // end if
			} // end if
			if(document.all.p_back[i].value != "" ){
				back1 = document.all.p_back[i].value;
				if(back1 != ""){ 
					for(var k=0; k < back1.length; k++){
						parenthesis[count] = back1.charAt(k);
						count++;
					} // end for
				} // end fi
			} // end if
			front = "";  back1 = "";
		} // end for
	}	
	return parenthesis;
	
}*/
/**
 * Prepare parenthesis [Modify for use in IE and Firefox]
 *
 */
// function prepare_parenthesis(){
//	var parenthesis = new Array();
//	var count = 0;
//	var front = "";
//	var back1 = "";
//	if(!document.getElementById("p_front")) return true;
//	if(document.getElementById("p_front").length > 0) 
//		var maxlength = document.getElementById("p_front").length; 
//	else 
//		var maxlength = 1;
//	
//	if(maxlength == 1){
//		front = document.getElementById("p_front").value;
//		if(front != ""){
//			for(var j=0; j < front.length; j++){
//				parenthesis[count] = front.charAt(j);
//				count++;
//			} // end for
//		} // end if
//		back1 = document.getElementById("p_back").value;
//		alert("1-back1="+back1)
//		if(back1 != ""){
//			for(var j=0; j < back1.length; j++){
//				parenthesis[count] = back1.charAt(j);
//				count++;
//			} // end for
//		} // end if
//	}
//	else{
//		for(var i=0; i < maxlength; i++){
//			if(document.getElementById("p_front")[i].value != "" ){
//				front = document.getElementById("p_front")[i].value;
//				if(front != ""){ 
//					for(var j=0; j < front.length; j++){
//						parenthesis[count] = front.charAt(j);
//						count++;
//					} // end for
//				} // end if
//			} // end if
//			if(document.getElementById("p_back")[i].value != "" ){
//				back1 = document.getElementById("p_back")[i].value;
//				if(back1 != ""){ 
//					for(var k=0; k < back1.length; k++){
//						parenthesis[count] = back1.charAt(k);
//						count++;
//					} // end for
//				} // end fi
//			} // end if
//			front = "";  back1 = "";
//		} // end for
//	}	
//	return parenthesis;
//	
//}

function prepare_parenthesis(){
	var parenthesis = new Array();
	var count = 0;
	var front = new Array();
	var back1 = new Array();
	var err=0
	//alert(tr_length("myCondition"))
	if(!document.getElementById("p_front")){
		return true;
	}else{
		
		var pos = tr_length("myCondition");
		
		for(i=0;i<(pos-1);i++){
			//alert("paren=="+document.getElementById("front_paren["+i+"]").value);
			if(document.getElementById("front_paren["+i+"]").value=="("){
				front[front.length]=i
			}
			if(document.getElementById("back_paren["+i+"]").value==")"){
				back1[back1.length]=i
			}
		}
		//return parenthesis;
		if(front.length!=back1.length){
			//alert(text_07);
			return false;
		}else{
			for(i=0;i<front.length;i++){
				if(front[i]>back1[i]){
					err++
				}
			}
			if(err>0){
				//alert(text_07);
				return false;
			}else{
				return true;
			}
		}
	}
}
/**
 * Check for matching Front and Back Parenthesis
 *
 * @author Uthai ShiangJan
 */
function is_valid_parenthesis(data,form){
	var result = new Array();

//	for(var i=0; i < data.length; i++){
//		if(data[i] == "("){  result.push("(") }
//		else if(result.length == 0){ alert(text_07); return false;	}
//		else if(data[i] == ")"){ var c = result.pop();}
//	}
	
	
	
	if(data){	// if match
				
		form.submit();
	}
	else{
		alert(text_07);
		return false;
		
	}
	//alert(text_07);
	//return false;

	
}

/**
 * Check prepare parenthesis into array and send it to function check_parenthesis();
 *
 * @author Uthai ShiangJan
 */
function is_correct_parenthesis(form){
	   
	var parenthesis = new Array();
//prepare_parenthesis();
	parenthesis = prepare_parenthesis();
    
	return is_valid_parenthesis(parenthesis,form);
}

//*******************************************************************************************************//
// END PARENTHESIS CHECK
//  @author Uthai ShiangJan 2006-01-20
//*******************************************************************************************************//
//By Jeeranan 26-01-2006
function showVisibility(obj)
{
 	 var theForm = obj.value;
	 //indexgraph,bar
	 if(theForm==5){ //polygon bar shape
	 	 	document.all.polygon.style.visibility = "visible";
		    document.all.polygonangle.style.visibility = "visible";
	}
	else if(theForm=="StarShape"){
			document.all.star.style.visibility = "visible";
	}
	//line
	else if(theForm==8){ //multi symbol line chart
		document.all.symbol.style.visibility = "visible";
	}
	else if(theForm==9){ //multi line chart
		document.all.dashline.style.visibility = "visible";
	}
	else if(theForm=="PolygonShape"){
		document.all.polygonline.style.visibility = "visible";
	}
	//pie
	else if((theForm==11)||(theForm==12)||(theForm==13)){ //inner radious , explode
		document.all.inner.style.visibility = "visible";
		document.all.explode.style.visibility = "visible";
	}
	else if(theForm==3){ //3D dept
		document.all.dept.style.visibility = "visible";
	}
}

function advanceCheck(obj)
{
	if(obj.value=='false'){
	 	document.getElementById('advance_chart').style.display='block';
		obj.value=true;	
	}
	else{
		 	document.getElementById('advance_chart').style.display='none';
			obj.value=false;	
	}
}

function SaveAs(tipo,form)
{
	
	 	form.fileType.value=tipo;
	
		form.todo.value="SaveAs";
	
	return true;
}
//end
function row_color(row,action)
{
	row.style.cursor='pointer';
	if(action == "on")
		row.bgColor = '#F1F4F9';
	if(action == "off")
		row.bgColor = '#FFFFFF';
	//if(action == "click")
		//alert('click');
}

//==========================================================
//To remove the "Click here to activate this " message on Internet Explorer:
//==========================================================
function write_object(embedded_object)
{
	document.write(embedded_object);
	document.write('\n');
}
//==========================================================

////////////////function check delete bow 26-09-2007 <bow>////////////////////
function check_delete(id,accese_del,v){
	
	var id_del=id.d.value
if(!v){
	var delvis=document.getElementById("vis["+id_del+"]");
	var rowdel = document.getElementById('tresult'); 
	//alert(delvis.value)	
	if(delvis.value!=""){
		if((rowdel.rows.length-2)==1){
			return true;
		}else{
			if((delvis.value==1) & (accese_del==1))
				return false;
			else{
				return true;
			}
		}
	}else{ return true;}
}else{ return true;}
}

/////////////end function check delete bow 26-09-2007 <bow>////////////////////

////////////////function count vis.gif bow 26-09-2007 <bow>////////////////////
function count_accessDel(){
	var pos = tr_length("myResult");
	var rowdel = document.getElementById('tresult'); 
	var del_img = rowdel.getElementsByTagName("img"); 
	var acdel=1;
	for (var i = 1; i < pos; i++)
		{ 
				//alert(document.getElementById("v["+i+"]").src)
				array_split = document.getElementById("v["+i+"]").src.split("/");
				if(array_split[array_split.length-1]=="vis.gif")
				{
					//alert(array_split[array_split.length-1]);
					acdel++;
				}
		}
	return acdel-1;
}
////////////end function count vis.gif bow 26-09-2007 <bow>////////////////////


	
//////////////////////////////////////////////////  NEW FUNCTIONS FOR MODIFY FIELDS NAME 15-10-2007 <BOW> ////////////////////////////////////////////////////////////////
function CN_openWindow(tname,p,name,from,xx,id,id_user) { //open opoup window for modify fields name <bow> 15-10-2007
																									//Send x to Changename <BOW> 13-12-2007
			tname=tname.replace(/#/g,"%chap%");//june  add new 25-12-2007
		//alert("2"+tname);			
			tname=tname.replace(/&/g,"%alp%");			
			tname=tname.replace(/\+/g,"%plus%");
			name=name.replace(/\+/g," %plus% ");
			ID_query=document.getElementById("ID_query").value;
			//alert(ID_query);
			//window.open("changename.php?x="+xx+"&ID_query="+ID_query+"&id_user="+id_user+"&id_userselection="+id+"&from="+from+"&p="+p+"&name="+name+"&tname="+tname+"")
			window.open("changename.php?x="+xx+"&ID_query="+ID_query+"&id_user="+id_user+"&id_userselection="+id+"&from="+from+"&p="+p+"&name="+name+"&tname="+tname+"","ChangeName","status=no,scrollbars=no,width=320,height=170").focus(); 
			/////////////////////
		 //from=window.open("changename.php?x="+xx+"&ID_query="+ID_query+"&id_user="+id_user+"&id_userselection="+id+"&from="+from+"&p="+p+"&name="+name+"&tname="+tname+"","ChangeName","").focus(); 
			/////////////////////
			
			
			//Send x to Changename <BOW> 13-12-2007
			//window.open("changename.php?ID_query="+ID_query+"&from="+from+"&p="+p+"&name="+name+"&tname="+tname+"","ChangeName","status=no,location=no,scrollbars=no,width=320,height=170,toolbar=no,menubar=no,resizable,alwaysRaised,dependent,titlebar=no").focus();
}

function new_formula_fields(from,pos,name,newname,xx,id_user,id_result)//01-12-2008
{
	tBodyfrom =opener.document.getElementById("myResult"); 
	tBodyOrder =opener.document.getElementById("myOrder"); 
	tBodyCondi =opener.document.getElementById("myCondition"); 
	
	if(from=="result")
	{				currentRowCells = tBodyfrom.rows[pos].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				nome=newname;
				pos1=stringa.indexOf( "value=", 0 )+7;
				pos2=stringa.indexOf( "\" name", 0);

				valore=stringa.substring(pos1,pos2);
				valore1=valore.split(" | ");
				valore=valore1[0];
				name1=name.split(" | ");
				name=name1[0];
				//alert(newname+"   "+pos);		
				//if(valore==name){
					newval=valore.split(" as ");
					newvalore=newval[0]+" as "+newname+" | "+valore1[1];
					//alert(newvalore);
				//}//DOUNOPS1.DOFCCCA-DOUNOPS1.DOFCCOA as poio | DOUNOPS1.DOFCCCA;1:DOFCCCA&-DOUNOPS1.DOFCCOA;1:DOFCCCA&
				opener.document.getElementById("myResult").rows[pos].cells[0].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+newvalore+"',"+pos+",'"+newname+"','result','"+xx+"','"+id_user+"','"+id_result+"')\">"+newname+"</a><input type='hidden' name='field[]' value=\""+newvalore+"\"><input type='hidden' name='KFormula' >";//01-12-2008
		}
		
		
	else if(from=="condition")
	{
//				alert(tBodyCondi.rows.length-1);
				currentRowCells = tBodyCondi.rows[pos].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[1].innerHTML.replace(" ","");
				
				nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
//				alert("nome=="+nome);
				if(nome==name){
						nome=newname;
				}
				pos1=stringa.indexOf( "value=", 0 )+7;
				pos2=stringa.indexOf( "\" name", 0);

				valore=stringa.substring(pos1,pos2);
				valore1=valore.split(" | ");
				valore=valore1[0];
				name1=name.split(" | ");
				name=name1[0];
						
				//if(valore==name){
					newval=valore.split(" as ");
					newvalore=newval[0]+" as "+newname+" | "+valore1[1];
				// } 
				  
					opener.document.getElementById("myCondition").rows[pos].cells[1].innerHTML = "<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+newvalore+"',"+pos+",'"+newname+"','condition','"+xx+"','"+id_user+"','"+id_result+"')\">"+newname+"</a><input type='hidden' name='field1[]' value=\""+newvalore+"\">";	//01-12-2008	
				
		}
}

function new_fields_as(from,pos,name,newname,xx,id_user,id_result)//01-12-2008
{
	tBodyfrom =opener.document.getElementById("myResult"); 
	tBodyOrder =opener.document.getElementById("myOrder"); 
	tBodyCondi =opener.document.getElementById("myCondition"); 
	var crow=1
	if(from=="result")
	{
		for(j=1;j<tBodyfrom.rows.length-1;j++)	
		{
			if(tBodyfrom.rows[j].cells[0].innerHTML.match("',"+pos+",'")){
				crow=j
				//alert(crow)
				}
		}

				currentRowCells = tBodyfrom.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				//alert(stringa);
				nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				//alert("nome="+nome)
				if(nome==name){nome=newname;}
				//alert("newnome="+nome)
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );
				//alert(pos1);
				
				valore=stringa.substring(pos1,pos2);
				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					//alert(valore)
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
						//alert(old_valore)
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
						pos2=stringa.indexOf( "\" name", 0);
						valore=stringa.substring(pos1,pos2);
						valore1=valore.indexOf(") as ",0);
						valore2=valore.substring(0,valore1);
						valore=valore2;
				}
				//alert(valore);
				if(valore.match("CONCAT"))
					valore=valore+") as "+nome+old_valore;
				else
					valore="("+valore+") as "+nome+old_valore;
					
					//valore3=valore.replace(/\\' \\'/g,"\' \'")
					//alert(valore);
				opener.document.getElementById("myResult").rows[crow].cells[0].innerHTML = "<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore+"',"+pos+",'"+nome+"','result','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input value=\""+valore+"\" type='hidden' name='field[]'>";	//01-12-2008	
	}
	else if(from=="order")
	{
		for(j=1;j<tBodyOrder.rows.length-1;j++)	
		{
			if(tBodyOrder.rows[j].cells[0].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}

				currentRowCells = tBodyOrder.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				
				if(stringa.match("<DIV")){
					nome=stringa.substring(stringa.indexOf( ":;\">")+4,stringa.indexOf( "</", 0 ));
				}else{
					nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				}
				//alert(stringa);
				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );

				valore=stringa.substring(pos1,pos2);
				
				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
				if(stringa.match("<DIV")){
					valore=valore+" as "+nome;
				}else{
					if(valore.match("CONCAT"))
						valore=valore+") as "+nome+old_valore;
					else
						valore="("+valore+") as "+nome+old_valore;
				}
                //valore="("+valore+") as "+nome;
				//alert(valore);
				if(!opener.document.getElementById("myOrder").rows[crow].cells[0].innerHTML.match("<DIV")){
				opener.document.getElementById("myOrder").rows[crow].cells[0].innerHTML = "<a href=\"javascript:;\" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore+"',"+pos+",'"+nome+"','order','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field2[]' value=\""+valore+"\">";//01-12-2008	
				}else{
				opener.document.getElementById("myOrder").rows[crow].cells[0].innerHTML = "<div style='border:solid;border-width:thin;border-color:#FF0000'><a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore+"',"+pos+",'"+nome+"','order','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field2[]' value=\""+valore+"\"></div>";//01-12-2008	
				}
	}
	else if(from=="condition")
	{
		for(j=1;j<tBodyCondi.rows.length-1;j++)	
		{
			if(tBodyCondi.rows[j].cells[1].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}

				currentRowCells = tBodyCondi.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[1].innerHTML.replace(" ","");
				
				if(stringa.match("<DIV")){
					nome=stringa.substring(stringa.indexOf( ":;\">")+4,stringa.indexOf( "</", 0 ));
				}else{
					nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				}

				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );
				
				valore=stringa.substring(pos1,pos2);
				
				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
					
				if(stringa.match("<DIV")){					
					valore=valore+" as "+nome;
				}else{
					if(valore.match("CONCAT"))
						valore=valore+") as "+nome+old_valore;
					else
						valore="("+valore+") as "+nome+old_valore;
				}
				//alert(valore)
				if(!opener.document.getElementById("myCondition").rows[crow].cells[1].innerHTML.match("<DIV")){
					opener.document.getElementById("myCondition").rows[crow].cells[1].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore+"',"+pos+",'"+nome+"','condition','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field1[]' value=\""+valore+"\">";	//01-12-2008
				}else{
					opener.document.getElementById("myCondition").rows[crow].cells[1].innerHTML = "<div style='border:solid;border-width:thin;border-color:#FF0000'><a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore+"',"+pos+",'"+nome+"','condition','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field1[]' value=\""+valore+"\"></div>";	//01-12-2008	
				}
					
					
					
					
	}else if(from=="view")
	{
		for(j=1;j<tBodyfrom.rows.length-1;j++)	
		{
			if(tBodyfrom.rows[j].cells[0].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}
				currentRowCells = tBodyfrom.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );

				valore=stringa.substring(pos1,pos2);

				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
				
				if(valore.match("CONCAT"))
					valore=valore+") as "+nome+old_valore;
				else
					valore="("+valore+") as "+nome+old_valore;
					
					opener.document.getElementById("myResult").rows[crow].cells[0].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore+"',"+pos+",'"+nome+"','view','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field[]' value=\""+valore+"\">";	//01-12-2008	
				
				change_mstatus();
	}
}

function new_fields(from,pos,name,newname,xx,id_user,id_result)//01-12-2008
{
	tBodyfrom =opener.document.getElementById("myResult"); 
	tBodyOrder =opener.document.getElementById("myOrder"); 
	tBodyCondi =opener.document.getElementById("myCondition"); 
	
	if(from=="result")
	{
		for(j=1;j<tBodyfrom.rows.length-1;j++)	
		{
			if(tBodyfrom.rows[j].cells[0].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}

				currentRowCells = tBodyfrom.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				//alert(stringa)
				nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );

				valore=stringa.substring(pos1,pos2);
				//alert(valore)
				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
				if(valore.match("CONCAT"))
					valore=valore+") as "+nome+old_valore;
				else
					valore="("+valore+") as "+nome+old_valore;
					
					
					//alert(valore)
					
					valore2=valore.replace(/' '/g,"\\' \\'")
					
					//alert(valore2)
					opener.document.getElementById("myResult").rows[crow].cells[0].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore2+"',"+pos+",'"+nome+"','result','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field[]' value=\""+valore+"\">";//01-12-2008	
	}
	else if(from=="order")
	{
		for(j=1;j<tBodyOrder.rows.length-1;j++)	
		{
			if(tBodyOrder.rows[j].cells[0].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}

				currentRowCells = tBodyOrder.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML.replace(" ","");
				//alert(stringa)
				if(stringa.match("<DIV")){
					nome=stringa.substring(stringa.indexOf( ":;\">")+4,stringa.indexOf( "</", 0 ));
				}else{
					nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				}
				
				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );

				valore=stringa.substring(pos1,pos2);
				
				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
				if(stringa.match("<DIV")){
					valore=valore+" as "+nome;
				}else{
					if(valore.match("CONCAT"))
						valore=valore+") as "+nome+old_valore;
					else
						valore="("+valore+") as "+nome+old_valore;
				}
				//alert(valore);
				valore2=valore.replace(/' '/g,"\\' \\'")
                //valore="("+valore+") as "+nome;
				if(!opener.document.getElementById("myOrder").rows[crow].cells[0].innerHTML.match("<DIV")){
				opener.document.getElementById("myOrder").rows[crow].cells[0].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore2+"',"+pos+",'"+nome+"','order','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field2[]' value=\""+valore+"\">";//01-12-2008	
				}else{
				opener.document.getElementById("myOrder").rows[crow].cells[0].innerHTML = "<div style='border:solid;border-width:thin;border-color:#FF0000'><a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore2+"',"+pos+",'"+nome+"','order','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field2[]' value=\""+valore+"\"></div>";//01-12-2008	
				}
	}
	else if(from=="condition")
	{
		for(j=1;j<tBodyCondi.rows.length-1;j++)	
		{
			if(tBodyCondi.rows[j].cells[1].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}

				currentRowCells = tBodyCondi.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[1].innerHTML.replace(" ","");
				//alert(stringa)
				if(stringa.match("<DIV")){
					nome=stringa.substring(stringa.indexOf( ":;\">")+4,stringa.indexOf( "</", 0 ));
				}else{
					nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				}

				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );
				
				valore=stringa.substring(pos1,pos2);

				
				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
					
				if(stringa.match("<DIV")){
					valore=valore+" as "+nome;
				}else{
						if(valore.match("CONCAT")){
						valore=valore+") as "+nome+old_valore;
					}else{
					//	valore="("+valore+") as "+nome+old_valore;	//old
					//june edit chang name (((ANANAGR1.ANANPLU))) as qqqqqqqqq *******24-07-2008
						if(valore.indexOf(")")!=-1 && valore.indexOf("(")!=-1){
						 valore=valore+" as "+nome+old_valore;	
						}else{
						valore="("+valore+") as "+nome+old_valore;	
						}
					// end june edit chang name (((ANANAGR1.ANANPLU))) as qqqqqqqqq *******24-07-2008
					}
				}
				valore2=valore.replace(/' '/g,"\\' \\'")
				//alert(valore2)
				if(!opener.document.getElementById("myCondition").rows[crow].cells[1].innerHTML.match("<DIV")){
					opener.document.getElementById("myCondition").rows[crow].cells[1].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore2+"',"+pos+",'"+nome+"','condition','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field1[]' value=\""+valore+"\">";//01-12-2008	
				}else{
					opener.document.getElementById("myCondition").rows[crow].cells[1].innerHTML = "<div style='border:solid;border-width:thin;border-color:#FF0000'><a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore2+"',"+pos+",'"+nome+"','condition','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field1[]' value=\""+valore+"\"></div>";//01-12-2008	
				}
					
					
					
					
	}else if(from=="view")
	{
		for(j=1;j<tBodyfrom.rows.length-1;j++)	
		{
			if(tBodyfrom.rows[j].cells[0].innerHTML.match("',"+pos+",'")){
				crow=j
				}
		}
				currentRowCells = tBodyfrom.rows[crow].cells; 
				currentCellContent = new Array(); 
	
				stringa=currentRowCells[0].innerHTML;
				nome=stringa.substring(stringa.indexOf( ">")+1,stringa.indexOf( "</", 0 ));
				if(nome==name){nome=newname;}
				pos1=stringa.indexOf( "value=", 0 )+6;
				pos2=stringa.indexOf( " name", 0 );

				valore=stringa.substring(pos1,pos2);

				if(valore.match("\""))
				{
					pos1=stringa.indexOf( "value=", 0 )+7;
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
				}
				if(valore.match(" as "))
				{
					if(valore.match("CONCAT")){
						pos1=stringa.indexOf( "value=", 0 )+7;
						old_valore=valore.substring(valore.indexOf("|"));
					}else{
						pos1=stringa.indexOf( "value=", 0 )+8;
					}
					pos2=stringa.indexOf( "\" name", 0);
					valore=stringa.substring(pos1,pos2);
					valore1=valore.indexOf(") as ",0);
					valore2=valore.substring(0,valore1);
					valore=valore2;
				}
				if(valore.match("CONCAT"))
					valore=valore+") as "+nome+old_valore;
				else
					valore="("+valore+") as "+nome+old_valore;
					
					valore2=valore.replace(/' '/g,"\\' \\'")
					opener.document.getElementById("myResult").rows[crow].cells[0].innerHTML = "<a href=\"javascript:; \" id='"+(pos)+"' onDblClick=\"CN_openWindow('"+valore2+"',"+pos+",'"+nome+"','view','"+xx+"','"+id_user+"','"+id_result+"')\">"+nome+"</a><input type='hidden' name='field[]' value=\""+valore+"\">";//01-12-2008	
					
			change_mstatus();
	}
}

/////////////////////////////////////////////////////  END FUNCTIONS FOR MODIFY FIELDS NAME 15-10-2007 //////////////////////////////////////////////////////////////////

	function set_submit()
	{	
		//alert(row_pos);
		
		if(row_pos>0)
			document.getElementById("check_submit").value="submit";
		else
			document.getElementById("check_submit").value="";
	}
	
 ///////////////////////////////////////////////////////////////Drag & Drop///////////////////////////////////////////////////////////////////////////
function DragDrop(table,table1){
if(table1){
		var tablename=table1
}else{
		var tablename=table
}
//alert(tablename)
var table = document.getElementById(table);
var tableDnD = new TableDnD();
var t_row=1;
var cbox = new Array()
tableDnD.findDropTargetRow = function(y) {
    var rows = this.table.tBodies[0].rows;
    for (var i=1; i<(rows.length-1); i++) {
		//if(document.getElementsByName("front_paren["+(i-1)+"]")=="\("){
        var row = rows[i];
        var rowY    = this.getPosition(row).y;
        var rowHeight = parseInt(row.offsetHeight)/2;
		if (row.offsetHeight == 0) {
			rowY = this.getPosition(row.firstChild).y;
			rowHeight = parseInt(row.firstChild.offsetHeight)/2;
		}
		t_row=i;
		
        if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
			
            return row;
        }
    }
	
    return null;
}
tableDnD.onDrop = function(table, row) {
    var rows = this.table.tBodies[0].rows;
	var new_value="";
		for (var i=1; i<(rows.length-1);i++) {
			
			if(tablename=="myCondition"){
				//if(cbox[i-1])
				//alert((i-1)+"   "+cbox[i-1])
				
/////////////////////////BOW-28-11/2008/////////////////////////////	
re_condition(i);
///*rename cell[2]*/
//	//rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(/> </g,">")
//	tag_op=rows[i].cells[2].innerHTML.split(">");
//	//alert(rows[i].cells[2].innerHTML)
//	name_op=tag_op[4].substring(tag_op[4].indexOf("op["),tag_op[4].indexOf("]"));
//	//alert(name_op)
//	rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(name_op,"op["+(i-1))
//	rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(name_op,"op["+(i-1))
//	check_name=tag_op[4].substring(tag_op[4].indexOf("checkoperator('"),tag_op[4].indexOf("',"));
//	rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(check_name,"checkoperator('"+(i))
///*rename cell[4]*/
//	tag_span=rows[i].cells[4].innerHTML.split(">");
//	name_span=tag_span[0].substring(tag_span[0].indexOf("id=SPAN"),tag_span[0].indexOf("id=SPAN")+9);
//	name_span=name_span.replace(" ","")
//	rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_span,"id=SPAN"+(i))
//	/*rename textfield in cell[4]*/
//	//alert(tag_span[1])
//	name_text=tag_span[1].substring(tag_span[1].indexOf("id=text"),tag_span[1].indexOf("id=text")+9);
//	name_text=name_text.replace(" ","")
//	rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_text,"id=text"+(i))
//	//alert(name_text)
//	//alert(rows[i].cells[4].innerHTML)
////////////////////////////////////////////////////////////////////
//				  if(i<rows.length-2){
//						if(rows[i].cells[6].innerHTML== "&nbsp;" || rows[i].cells[6].innerHTML=="")
//							rows[i].cells[6].innerHTML=insertLogical(i)
//				  }else{
//					rows[i].cells[6].innerHTML= "&nbsp;";
//				  }
////				  
//					
//				  if(rows[i].cells[4].innerHTML.match("disabled") && !rows[i].cells[3].innerHTML.match("CHECKED")){
//				  		rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace(">"," CHECKED >")
//				  }
//				 if(rows[i].cells[7].innerHTML.match("deldis.png")){
//						rows[i].cells[7].innerHTML="<IMG style=\"CURSOaR: auto\" src=\"immagini/deldis.png\">"
//				 }else{
//					  rows[i].cells[7].innerHTML="<input name='del' type='image' src='immagini/del.png' id="  +  i + " style='cursor:auto' onClick='this.form.d3.value=this.id; doDelete_Condition(this.form);return false;'><input type='hidden' name='id[]' value='xx'>"
//				 }
//				 if(rows[i].cells[4].innerHTML.match("NULL")){
//					new_value=document.getElementById("text"+i).value
//				 }
//				 /////checkbox
//				 name_cb=rows[i].cells[3].innerHTML.substring(rows[i].cells[3].innerHTML.indexOf("type["),rows[i].cells[3].innerHTML.indexOf("]"));	
//				 rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("id="+name_cb,"id=type["+(i-1))
//				 rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("name="+name_cb,"name=type["+(i-1))
//				 /////
//				 //alert("3"+rows[i].cells[3].innerHTML)
//				 name_var=rows[i].cells[4].innerHTML.substring(rows[i].cells[4].innerHTML.indexOf("var["),rows[i].cells[4].innerHTML.indexOf("]"));	
//				 rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_var,"var["+(i-1))
//				 //alert("4"+rows[i].cells[4].innerHTML)
//				 name_fparen=rows[i].cells[0].innerHTML.substring(rows[i].cells[0].innerHTML.indexOf("front_paren["),rows[i].cells[0].innerHTML.indexOf("]"));
//				// alert(name_fparen)
//				 //alert(rows[i].cells[0].innerHTML)
//				 rows[i].cells[0].innerHTML=rows[i].cells[0].innerHTML.replace(name_fparen,"front_paren["+(i-1))
//				// alert(rows[i].cells[0].innerHTML)
//				 name_bparen=rows[i].cells[5].innerHTML.substring(rows[i].cells[5].innerHTML.indexOf("back_paren["),rows[i].cells[5].innerHTML.indexOf("]"));
//				 rows[i].cells[5].innerHTML=rows[i].cells[5].innerHTML.replace(name_bparen,"back_paren["+(i-1))
//				 if(new_value=="NOT NULL"){
//					  rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("<option value=\"NULL\" selected=\"selected\">NULL</option><option value=\"NOT NULL\">NOT NULL</option>","<option value=\"NULL\">NULL</option><option value=\"NOT NULL\" selected=\"selected\">NOT NULL</option>")
//					  //alert(rows[i].cells[4].innerHTML)
//				 }else if(new_value=="NULL"){
//				 		rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("<option value=\"NULL\">NULL</option><option value=\"NOT NULL\" selected=\"selected\">NOT NULL</option>","<option value=\"NULL\" selected=\"selected\">NULL</option><option value=\"NOT NULL\">NOT NULL</option>")
//				 }
////				 alert(name_var)

//////////////////////////////////////////////////////////////////////////////////////////
			  }
			  if(tablename=="myResult"){
				  
				   if(rows[i].cells[2].innerHTML.match("deldis.png")){
						rows[i].cells[2].innerHTML="<IMG style=\"CURSOR: auto\" src=\"immagini/deldis.png\">"
				 	}else{
					rows[i].cells[2].innerHTML="<input name='del' type='image' src='immagini/del.png' id="+i+" style='cursor:auto' onClick=\"this.form.d.value="+i+";doDelete_Result(this.form);return false;\"><input type='hidden' name='id[]' value='xx'>"
					}
					//alert(rows[i].cells[3].innerHTML)
					//tpos3=rows[i].cells[3].innerHTML.substring(rows[i].cells[3].innerHTML.indexOf( "(")+1,rows[i].cells[3].innerHTML.indexOf( ","));
					//alert(tpos3)
					//rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("("+tpos3,"("+(i-1))
					//rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("("+tpos3,"("+(i-1))
					//alert(rows[i].cells[3].innerHTML)
			  }
			  if(tablename=="view"){
				  if(rows[i].cells[1].innerHTML.match("deldis.png")){
						rows[i].cells[1].innerHTML="<IMG style=\"CURSOR: auto\" src=\"immagini/deldis.png\">"
				 	}else{
						rows[i].cells[1].innerHTML= "<input name='del' type='image' src='immagini/del.png' id="  +  i + " style='cursor:auto' onClick=\"this.form.d.value="  +  i + ";doDelete_Result(this.form,'view');return false;\"><input type='hidden' name='id[]' value='xx'>"
					}
					//alert(rows[i].cells[2].innerHTML)
					//tpos3=rows[i].cells[2].innerHTML.substring(rows[i].cells[2].innerHTML.indexOf( "(")+1,rows[i].cells[2].innerHTML.indexOf( ","));
					//alert(tpos3)
					//rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace("("+tpos3,"("+(i-1))
				//	rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace("("+tpos3,"("+(i-1))
					//alert(rows[i].cells[2].innerHTML)
			  }

			  if(tablename=="myOrder"){
				  if(rows[i].cells[3].innerHTML.match("deldis.png")){
						rows[i].cells[3].innerHTML="<IMG style=\"CURSOR: auto\" src=\"immagini/deldis.png\">"
				 	}else{
						rows[i].cells[3].innerHTML= "<input type='image' src='immagini/del.png' id="  +  i + " style='cursor:auto' onClick='this.form.d2.value="  +  i + "; doDelete_Order(this.form); return false;'>"
					}
					//alert(rows[i].cells[4].innerHTML)
					//tpos3=rows[i].cells[4].innerHTML.substring(rows[i].cells[4].innerHTML.indexOf( "(")+1,rows[i].cells[4].innerHTML.indexOf( ","));
					//alert(tpos3)
					//rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("("+tpos3,"("+(i-1))
					//rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("("+tpos3,"("+(i-1))
					//alert(rows[i].cells[3].innerHTML)
					
			  }
		}
		
	
}

tableDnD.init(table);	

}

var currenttable = null;

document.onmousemove =function(ev){
    if (currenttable && currenttable.dragObject) {
        ev   = ev || window.event;
        var mousePos = currenttable.mouseCoords(ev);
        var y = mousePos.y - currenttable.mouseOffset.y;
        if (y != currenttable.oldY) {
			
			change_mstatus()
			
            var movingDown = y > currenttable.oldY;
            currenttable.oldY = y;
            currenttable.dragObject.style.backgroundColor = "#eee";
            var currentRow = currenttable.findDropTargetRow(y);
            if (currentRow) {
                if (movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow.nextSibling);
                } else if (! movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow);
                }
            }
        }

        return false;
    }
}

document.onmouseup   = function(ev){
    if (currenttable && currenttable.dragObject) {
        var droppedRow = currenttable.dragObject;
        droppedRow.style.backgroundColor = 'transparent';
        currenttable.dragObject   = null;
        currenttable.onDrop(currenttable.table, droppedRow);
        currenttable = null; // let go of the table too
    }
}


function getEventSource(evt) {
    if (window.event) {
        evt = window.event; // For IE
        return evt.srcElement;
    } else {
        return evt.target; // For Firefox
    }
}

function TableDnD() {
    this.dragObject = null;
    this.mouseOffset = null;
    this.table = null;
    this.oldY = 0;

    this.init = function(table) {
        this.table = table;
        var rows = table.tBodies[0].rows; //getElementsByTagName("tr")
        for (var i=0; i<rows.length; i++) {
			var nodrag = rows[i].getAttribute("NoDrag")
			if (nodrag == null || nodrag == "undefined") { //There is no NoDnD attribute on rows I want to drag
				this.makeDraggable(rows[i]);
			}
        }
    }

    this.onDrop = function(table, droppedRow) {
        //alert(droppedRow)
    }

    this.getPosition = function(e){
        var left = 0;
        var top  = 0;
		if (e.offsetHeight == 0) {
			e = e.firstChild; // a table cell
		}

        while (e.offsetParent){
            left += e.offsetLeft;
            top  += e.offsetTop;
            e     = e.offsetParent;
        }

        left += e.offsetLeft;
        top  += e.offsetTop;

        return {x:left, y:top};
    }

	/** Get the mouse coordinates from the event (allowing for browser differences) */
    this.mouseCoords = function(ev){
        if(ev.pageX || ev.pageY){
            return {x:ev.pageX, y:ev.pageY};
        }
        return {
            x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            y:ev.clientY + document.body.scrollTop  - document.body.clientTop
        };
    }

	/** Given a target element and a mouse event, get the mouse offset from that element.
		To do this we need the element's position and the mouse position */
    this.getMouseOffset = function(target, ev){
        ev = ev || window.event;

        var docPos    = this.getPosition(target);
        var mousePos  = this.mouseCoords(ev);
        return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
    }

	/** Take an item and add an onmousedown method so that we can make it draggable */
    this.makeDraggable = function(item) {
        if(!item) return;
        var self = this; // Keep the context of the TableDnd inside the function
        item.onmousedown = function(ev) {
		
            // Need to check to see if we are an input or not, if we are an input, then
            // return true to allow normal processing
            var target = getEventSource(ev);
            if (target.tagName == 'INPUT' || target.tagName == 'SELECT') return true;
            currenttable = self;
            self.dragObject  = this;
            self.mouseOffset = self.getMouseOffset(this, ev);
            return false;
        }
        item.style.cursor = "move";
    }

    /** We're only worried about the y position really, because we can only move rows up and down */
    this.findDropTargetRow = function(y) {
        var rows = this.table.tBodies[0].rows;
		for (var i=0; i<rows.length; i++) {
			var row = rows[i];
			//alert(row)
			// John Tarr added to ignore rows that I've added the NoDnD attribute to (Header rows)
			var nodrop = row.getAttribute("NoDrop");
			if (nodrop == null || nodrop == "undefined") {  //There is no NoDnD attribute on rows I want to drag
				var rowY    = this.getPosition(row).y;
				var rowHeight = parseInt(row.offsetHeight)/2;
				if (row.offsetHeight == 0) {
					rowY = this.getPosition(row.firstChild).y;
					rowHeight = parseInt(row.firstChild.offsetHeight)/2;
				}
				// Because we always have to insert before, we need to offset the height a bit
				if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {

					// that's the row we're over
					return row;
				}
			}
		}
		return null;
	}
}

function re_vis(){
	rows=document.getElementById("myResult").rows
			for(i=1;i<rows.length-1;i++){
					//alert(rows[i].cells[1].innerHTML)
										tpos3=rows[i].cells[1].innerHTML.substring(rows[i].cells[1].innerHTML.indexOf("v["),rows[i].cells[1].innerHTML.indexOf( "] "));
					rows[i].cells[1].innerHTML=rows[i].cells[1].innerHTML.replace(tpos3,"v["+i)

					tpos=rows[i].cells[1].innerHTML.substring(rows[i].cells[1].innerHTML.indexOf( "(this,"),rows[i].cells[1].innerHTML.indexOf( ");"));
					
					//alert(tpos)
					rows[i].cells[1].innerHTML=rows[i].cells[1].innerHTML.replace(tpos,"(this,"+i)
					tpos2=rows[i].cells[1].innerHTML.substring(rows[i].cells[1].innerHTML.indexOf("vis["),rows[i].cells[1].innerHTML.indexOf( "]>"));
					rows[i].cells[1].innerHTML=rows[i].cells[1].innerHTML.replace(tpos2,"vis["+i)
					//rows[i].cells[1].innerHTML=rows[i].cells[1].innerHTML.replace(tpos2,"vis["+i)
//					tpos3=rows[i].cells[3].innerHTML.substring(rows[i].cells[3].innerHTML.indexOf( "id="),rows[i].cells[3].innerHTML.indexOf( " onc"));
//					rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace(tpos3,"id="+(i-1))
					//rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("this.id",(i-1))
//					alert(rows[i].cells[3].innerHTML)
		}
}

 ///////////////////////////////////////////////////////////////Drag & Drop///////////////////////////////////////////////////////////////////////////
//CONCAT
function split_value(value)
{
	var newvalue;
	var value_new;
	newvalue=value.split(" ) ");
	//alert(newvalue);
	value_new=newvalue[0]+") "+newvalue[1];
	value_new=value_new.replace(" )",")");
	return value_new;												
}
function set_value_insert(value)
{
	//alert(value)
	var new_value_insert;
	value=value.replace(/\\'/g,"'");
	value=value.replace(/'/g,"\\'");
	value=value.split("|")
	var as_value_first=value[0].split("as");
	as_value_first[0]=as_value_first[0].replace(")","");
	as_value_first[0]=as_value_first[0]+") as"+as_value_first[1]+"|"+value[1];
	new_value_insert=split_value(as_value_first[0]);
	return new_value_insert;
}
//END CONCAT
function closeWindow(){
  //alert("This window will Close, After Click !!!");
  window.close();
  setTimeout("alert('This window will Close, After Click !!!')",1000);  
  window.close();
}

//############################### START KOM ###################################

                         // var elementName="";
                         // function  setElement(ele){
						 //	alert(document.getElementById(ele.name).value);
						 //	elementName=ele.name;
                         // }//end function
						 
						 function Strim(str){
                          if(!str || typeof str != 'string')
                          return null;
                          return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
                         } //end function

                         function insertToBody(a) {
							//alert(a);
							 opener.modificato = 1;

							 var fieldq=a.split("{;}");//12-01-2009	
    						 var elementName="query_txt";
							 //alert(document.getElementById("stringa").value);
							 //alert(opener.document.getElementById(elementName).value);
							 			  var tag_new=fieldq[1].split(";");//12-01-2009		 
                                          var tag=tag_new[0];//12-01-2009	
						                  var myField;  
										  var chkq;
                                          if (elementName != "query_txt" ){
											  return false;
                                          }//end if
                                         myField = opener.document.getElementById(elementName);
										 
										 chkq=Strim(myField.value);
										 var ltag=tag.split(".");
										 var cusfield=Strim(tag).substr(0,7);
										 if((ltag.length)==2 && (cusfield!="(SELECT") && (cusfield!="(select")){
										//alert(cusfield);
										 ltag[0]=ltag[0].substr(0,(ltag[0].length-1));
										 tag=ltag[0]+"."+ltag[1];
										 }//end if
										 //alert(chkq)
										
										 if(chkq=="SELECT"){ 
										       tag=tag;
										 }else if(myField.value==""){
											  
											 if((ltag.length)==2){
											 
											   tag="SELECT "+tag;
											 }else{
												  
											   tag=" "+tag; 
												 
												 
											 } //end if
											
										
										}else if((ltag.length)==1){
									var fq=myField.value.substr(myField.value.length-5,myField.value.length);
								//	alert(fq);
									/*
													     if(fq=="FROM "){
														  tag=tag;	
														 }else{
														  tag=","+tag;	
														 }//end if
				        		   */
						   
						   if(fq=="FROM " || fq=="from "){
                                     tag=tag;
                             }else if(fq=="HERE " || fq=="here "){
                                     tag=tag;
                             }else if(fq=="R BY " || fq=="r by "){
                                    tag=tag;
							}else if(fq=="P BY " || fq=="p by "){
                                    tag=tag;		
                             }else{
                                   //tag=", "+tag;
								   tag=" "+tag;
                           }//end if
						   
						   
						   
						   
						   
						 //  tag=tag;	
										 }else{
											 
											 
											 
									 var fq=myField.value.substr(myField.value.length-5,myField.value.length);
									//alert(fq);
									/*
													     if(fq=="FROM "){
														  tag=tag;	
														 }else{
														  tag=","+tag;	
														 }//end if
						   */
						   
						   if(fq=="FROM " || fq=="from "){
                                     tag=tag;
                             }else if(fq=="HERE " || fq=="here "){
                                     tag=tag;
                             }else if(fq=="R BY " || fq=="r by "){
                                    tag=tag;
							}else if(fq=="P BY " || fq=="p by "){
                                    tag=tag;		
                           }else{
                                   //tag=", "+tag;
								   tag=" "+tag;
                           }//end if
		 
											 
											 
											 
											//  tag=", "+tag;	 
										 } //end if
										 
										 
							 
										 
										 if (opener.document.selection) {
											// alert(tag);
										  //myField.focus();
                                         // sel = opener.document.selection.createRange();
                                         // sel.text = tag;
                                         // myField.focus();
										 myField.value+=tag;
										  
                                         } else if (myField.selectionStart || myField.selectionStart == '0') {
                                           
										  var startPos  = myField.selectionStart;
                                           var endPos    = myField.selectionEnd;
                                           var cursorPos = endPos;
										   
			                             myField.value = myField.value.substring(0, startPos)
                                               + tag
                                               + myField.value.substring(endPos, myField.value.length);
                                          cursorPos += tag.length;
                                          myField.focus();
                                          myField.selectionStart = cursorPos;
                                          myField.selectionEnd = cursorPos;
										  
                                         } else {
											
                                          myField.value += tag;
                                          myField.focus();
                                         }//end if
								 opener.document.getElementById("m_status").value="1";
                        } //end function 
						
				  
					 //############################### END KOM ###################################
					 
					 
function change_mstatus(){
	if(document.getElementById("m_status"))
		document.getElementById("m_status").value="1";
	else
		opener.document.getElementById("m_status").value="1";
}

//###########################june check date 18-09-2008########################
//Author : chadawan kaewplung
//#############################################################################
function doDate( el )
{
//	alert(el.value);
	
var s = el.value;
var d, m, y;
var erString = text_88;
var len = s.length;
var date_format;//15-12-2008
//alert("LEN=="+len);
if (10 == len){
d = s.substring(0,2);
m = s.substring(3,5);
y = s.substring(6,10);
} else if (8 == len) {
d = s.substring(0,2);
m = s.substring(2,4);
y = s.substring(4,8);
} else if (6 == len) {
d = s.substring(0,2);
m = s.substring(2,4);
y = '20' + s.substring(4,6);
}


date_format=d+"/"+m+"/"+y;//15-12-2008
//alert(date_for)
	


if ((checkDate(y,m,d)&& el.value==date_format) || (el.value=="gg/mm/aaaa")){//15-12-2008
//el.value = d + ' ' + monthNames[m-1] + ' ' + y;
//el.value = d + ' ' + m + ' ' + y;
erString = '';

//////////////////////////////for DragDrop /////////////////////////////////////////////////
document.onmousemove =function(ev){
    if (currenttable && currenttable.dragObject) {
        ev   = ev || window.event;
        var mousePos = currenttable.mouseCoords(ev);
        var y = mousePos.y - currenttable.mouseOffset.y;
        if (y != currenttable.oldY) {
			
			change_mstatus()
			
            var movingDown = y > currenttable.oldY;
            currenttable.oldY = y;
            currenttable.dragObject.style.backgroundColor = "#eee";
            var currentRow = currenttable.findDropTargetRow(y);
            if (currentRow) {
                if (movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow.nextSibling);
                } else if (! movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow);
                }
            }
        }

        return false;
    }
}

document.onmouseup   = function(ev){
    if (currenttable && currenttable.dragObject) {
        var droppedRow = currenttable.dragObject;
        droppedRow.style.backgroundColor = 'transparent';
        currenttable.dragObject   = null;
        currenttable.onDrop(currenttable.table, droppedRow);
        currenttable = null; // let go of the table too
    }
}

////////////////////////end DragDrop//////////////////////////////////////////////////////
//el.style.border="1px solid gray";
//el.style.border="1px solid gray";
}else{
if(len!=0){
	if (el.focus){ el.focus();
	}	

el.document.onmousemove=null;
el.document.onmouseup=null;
alert(erString);	

//document.onmousedown=null ;
//document.onmousedown=" ";
//return false;

}else{
	//s.value="gg/mm/aaaa";
//	alert(s);
//alert("444444");

document.onmousemove =function(ev){
    if (currenttable && currenttable.dragObject) {
        ev   = ev || window.event;
        var mousePos = currenttable.mouseCoords(ev);
        var y = mousePos.y - currenttable.mouseOffset.y;
        if (y != currenttable.oldY) {
			
			change_mstatus()
			
            var movingDown = y > currenttable.oldY;
            currenttable.oldY = y;
            currenttable.dragObject.style.backgroundColor = "#eee";
            var currentRow = currenttable.findDropTargetRow(y);
            if (currentRow) {
                if (movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow.nextSibling);
                } else if (! movingDown && currenttable.dragObject != currentRow) {
                    currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow);
                }
            }
        }

        return false;
    }
}

document.onmouseup   = function(ev){
    if (currenttable && currenttable.dragObject) {
        var droppedRow = currenttable.dragObject;
        droppedRow.style.backgroundColor = 'transparent';
        currenttable.dragObject   = null;
        currenttable.onDrop(currenttable.table, droppedRow);
        currenttable = null; // let go of the table too
    }
}

////////////////////////end DragDrop//////////////////////////////////////////////////////
	}
/*if(object.value.length>0)
	object.style.border="1px solid #FFFFFF";
	else
	object.style.border="1px solid #C2C2C2";*/
//return true;

//el.value = '';
}
//if (document.getElementById){
//if(erString!=""){

//document.getElementById(erID).innerHTML = erString;
//}
//}
/*if (erString){
if (el.focus) el.focus();
alert(erString);
}*/
}

function checkDate(y, m, d)
{
m = '' + (m-1);
var checkDate = new Date(y,m,d);
return ( checkDate.getMonth() == m
&& checkDate.getFullYear() == y);
}

//######################end check date##########################################
function re_condition(i){
	var new_value="";
	var rows=document.getElementById("myCondition").rows
	//for (var i=1; i<(rows.length-1);i++) {
/////////////////////////BOW-28-11/2008/////////////////////////////				
/*rename cell[2]*/
		//rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(/> </g,">")
		//alert(rows[i].cells[2].innerHTML)
		tag_op=rows[i].cells[2].innerHTML.split(">");
		//alert(rows[i].cells[2].innerHTML)
		name_op=tag_op[4].substring(tag_op[4].indexOf("op["),tag_op[4].indexOf("]"));
		//alert(name_op)
		rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(name_op,"op["+(i-1))
		rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(name_op,"op["+(i-1))
		check_name=tag_op[4].substring(tag_op[4].indexOf("checkoperator('"),tag_op[4].indexOf("',"));
		//alert(check_name)
		if(rows[i].cells[2].innerHTML.match("checkoperator")){
		rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(check_name,"checkoperator('"+(i))
		}
		/*revalue op[] in cell[2]*/
			value_op=tag_op[3]
			//value_op=value_op.replace(" ","")
			rows[i].cells[2].innerHTML=rows[i].cells[2].innerHTML.replace(value_op,"<INPUT id=op[] type=hidden value="+(i-1))
			//alert(rows[i].cells[2].innerHTML)
/*rename cell[4]*/
		tag_span=rows[i].cells[4].innerHTML.split(">");
		if(rows[i].cells[4].innerHTML.match("id=SPAN")){
		
		name_span=tag_span[0].substring(tag_span[0].indexOf("id=SPAN"),tag_span[0].indexOf("id=SPAN")+9);
		name_span=name_span.replace(" ","")
		//alert(name_span)
		rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_span,"id=SPAN"+(i))
		}
		/*rename textfield in cell[4]*/
			//alert(tag_span[1])
			for(tag=0;tag<tag_span.length;tag++){
				if(tag_span[tag].match("id=text")){
					tag_cut=tag_span[tag];
					break;
				}
			}
			name_text=tag_cut.substring(tag_cut.indexOf("id=text"),tag_cut.indexOf("id=text")+9);
			name_text=name_text.replace(" ","")
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_text,"id=text"+(i))
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_text,"id=text"+(i))
		//alert(tag_span[3])
		for(tag=0;tag<tag_span.length;tag++){
				if(tag_span[tag].match("var_2")){
					tag_cut=tag_span[tag];
					break;
				}
			}
		if(tag_cut.match("var_2")){
			var_name=tag_cut.substring(tag_cut.indexOf("var_2["),tag_cut.indexOf("]"));	
			//alert(var_name)
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(var_name,"var_2["+(i-1))
//			setvar2=tag_cut.substring(tag_cut.indexOf("setvalue_var("),tag_cut.indexOf(","));
//			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(setvar2,"setvalue_var("+(i-1))
		}
		for(tag=0;tag<tag_span.length;tag++){
			if(tag_span[tag].match("hid_var2")){
				tag_cut=tag_span[tag];
				break;
			}
		}
		if(rows[i].cells[4].innerHTML.match("hid_var2")){
			hidvar2_name=tag_cut.substring(tag_cut.indexOf("hid_var2["),tag_cut.indexOf("]"));	
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(hidvar2_name,"hid_var2["+(i-1))
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(hidvar2_name,"hid_var2["+(i-1))
			//alert(rows[i].cells[4].innerHTML)
		}
		for(tag=0;tag<tag_span.length;tag++){
			if(tag_span[tag].match("hid_var")){
				tag_cut=tag_span[tag];
				break;
			}
		}
		if(rows[i].cells[4].innerHTML.match("hid_var")){
			hidvar_name=tag_cut.substring(tag_cut.indexOf("hid_var["),tag_cut.indexOf("]"));
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(hidvar_name,"hid_var["+(i-1))
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(hidvar_name,"hid_var["+(i-1))
		}
		if(rows[i].cells[4].innerHTML.match("setvalue_var")){
			setvar=rows[i].cells[4].innerHTML.substring(rows[i].cells[4].innerHTML.indexOf("setvalue_var("),rows[i].cells[4].innerHTML.indexOf(","));
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(setvar,"setvalue_var("+(i-1))
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(setvar,"setvalue_var("+(i-1))
		}
		
		
		for(tag=0;tag<tag_span.length;tag++){
				if(tag_span[tag].match("text_name")){
					tag_cut2=tag_span[tag];
					break;
				}
			}
		//if(tag_span[4].match("text_name")){
			txtname_value=tag_cut2.substring(tag_cut2.indexOf("value="),tag_cut2.indexOf("value=")+8);	
			txtname_value=txtname_value.replace(" ","")
			//alert("INPUT id=text_name[] type=hidden "+txtname_value)
			rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("INPUT id=text_name[] type=hidden "+txtname_value,"INPUT id=text_name[] type=hidden value="+i)
			
		//}
		//alert(rows[i].cells[4].innerHTML)
////////////////////////////////////////////////////////////////////

			if(i<rows.length-2){
				 if(rows[i].cells[6].innerHTML== "&nbsp;" || rows[i].cells[6].innerHTML=="")
							rows[i].cells[6].innerHTML=insertLogical(i)
				  }else{
					rows[i].cells[6].innerHTML= "&nbsp;";
				  }
//				  
					
				  if(rows[i].cells[4].innerHTML.match("disabled") && !rows[i].cells[3].innerHTML.match("CHECKED")){
				  		rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace(">"," CHECKED >")
				  }
				 if(rows[i].cells[7].innerHTML.match("deldis.png")){
						rows[i].cells[7].innerHTML="<IMG style=\"CURSOaR: auto\" src=\"immagini/deldis.png\">"
				 }else{
					  rows[i].cells[7].innerHTML="<input name='del' type='image' src='immagini/del.png' id="  +  i + " style='cursor:auto' onClick='this.form.d3.value=this.id; doDelete_Condition(this.form);return false;'><input type='hidden' name='id[]' value='xx'>"
				 }
//				 if(rows[i].cells[4].innerHTML.match("NULL")){
//					new_value=document.getElementById("text"+i).value
//				 }
				 /////checkbox
				 name_cb=rows[i].cells[3].innerHTML.substring(rows[i].cells[3].innerHTML.indexOf("type["),rows[i].cells[3].innerHTML.indexOf("]"));	
				 rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("id="+name_cb,"id=type["+(i-1))
				 rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace("name="+name_cb,"name=type["+(i-1))
				 tag_toggle=rows[i].cells[3].innerHTML.substring(rows[i].cells[3].innerHTML.indexOf("toggle_text('text"),rows[i].cells[3].innerHTML.indexOf("')"));
				 rows[i].cells[3].innerHTML=rows[i].cells[3].innerHTML.replace(tag_toggle,"toggle_text('text"+(i))
				 /////
				 //alert("3"+rows[i].cells[3].innerHTML)
				 name_var=rows[i].cells[4].innerHTML.substring(rows[i].cells[4].innerHTML.indexOf("var["),rows[i].cells[4].innerHTML.indexOf("]"));	
				 rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace(name_var,"var["+(i-1))
																								   
				 //alert("4"+rows[i].cells[4].innerHTML)
				 name_fparen=rows[i].cells[0].innerHTML.substring(rows[i].cells[0].innerHTML.indexOf("front_paren["),rows[i].cells[0].innerHTML.indexOf("]"));
				// alert(name_fparen)
				 //alert(rows[i].cells[0].innerHTML)
				 rows[i].cells[0].innerHTML=rows[i].cells[0].innerHTML.replace(name_fparen,"front_paren["+(i-1))
				// alert(rows[i].cells[0].innerHTML)
				 name_bparen=rows[i].cells[5].innerHTML.substring(rows[i].cells[5].innerHTML.indexOf("back_paren["),rows[i].cells[5].innerHTML.indexOf("]"));
				 rows[i].cells[5].innerHTML=rows[i].cells[5].innerHTML.replace(name_bparen,"back_paren["+(i-1))
				 if(new_value=="NOT NULL"){
					  rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("<option value=\"NULL\" selected=\"selected\">NULL</option><option value=\"NOT NULL\">NOT NULL</option>","<option value=\"NULL\">NULL</option><option value=\"NOT NULL\" selected=\"selected\">NOT NULL</option>")
					  //alert(rows[i].cells[4].innerHTML)
				 }else if(new_value=="NULL"){
				 		rows[i].cells[4].innerHTML=rows[i].cells[4].innerHTML.replace("<option value=\"NULL\">NULL</option><option value=\"NOT NULL\" selected=\"selected\">NOT NULL</option>","<option value=\"NULL\" selected=\"selected\">NULL</option><option value=\"NOT NULL\">NOT NULL</option>")
				 }

	//}
}

function setvalue_var(pos,n){
	if(n==1){
	var var_value=document.getElementById("var["+pos+"]").value
	document.getElementById("hid_var["+pos+"]").value=var_value
	}else{
	var var2_value=document.getElementById("var_2["+pos+"]").value
	document.getElementById("hid_var2["+pos+"]").value=var2_value
	}
	//alert(document.getElementById("hid_var["+pos+"]").value)
}
