	var reactions = [];
	var tempReacitons = [];
	var metabolite = [];
	var currentSubstrate = [];
	var currentProduct = [];
	var sList="";
	var knockoutList = [];
	
	var currentSubstrateStoich = [];
	var currentProductStoich = [];
	
	var currentisReversible = 0;
	var currentReactionName = "";
	var SubstrateOrProduct = "";
	
	var isLineValidated = false;
	
	var newScriptReaction = "";
	
	var newKEGGReactionNum = 0;
	
	var scriptKeyword = "";
	var selectKeywordInScript = -1;
	
	var previousRName = '';
	var previousROfficialName = '';
	var previousEquation = '';
	
	var privX = 0;
	var privY = 0;
	
	var posX = 0;
	var posY = 0;
	
	var modelingGubun = 1; // 1: Wizard 2:Script 3:KEGG
	
	function addMetabolite()
	{
		if (event.keyCode != 13) return;
		var idx = byId("metaboliteIdx").value;
		var name = byId("metaboliteName").value;
		var moname = byId("moName").value;
		if(moname == "") moname = name;
		var compartment = byId("compartment").value;
		var charge = byId("charge").value;
		
		if(idx != "")
			cmdMetabolite(name, moname, compartment, charge, 'updateCompound', idx);
		else{
			if(isExistCompound(name)){
				alert("Compound name is duplicated");
				return;
			}
			cmdMetabolite(name, moname, compartment, charge, 'saveCompound');
		}
	}
	
	function saveMetabolite()
	{
		var idx = byId("metaboliteIdx").value;
		var name = byId("metaboliteName").value;
		var moname = byId("moName").value;
		if(moname == "") moname = name;
		var compartment = byId("compartment").value;
		var charge = byId("charge").value;
		if(idx != "")
			cmdMetabolite(name, moname, compartment, charge, 'updateCompound', idx);
		else{
			if(isExistCompound(name)){
				alert("Compound name is duplicated");
				return;
			}
			cmdMetabolite(name, moname, compartment, charge, 'saveCompound');
		}
	}
	
	function cmdMetabolite(name, moname, compartment, charge, command, idx)
	{
    	//Start command for metabolite
		var sendData = "cmd="+command;
		sendData = sendData + "&pid="+projectIdx;
	  	sendData = sendData + "&name="+name;
	   	sendData = sendData + "&oname="+moname;
	   	sendData = sendData + "&compartment="+compartment;
	   	sendData = sendData + "&charge="+charge;
	   	var getPost = "POST";                
	   	var urlFileAppl = "ModelingServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();           
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                
	            if (xmlHttp.status == 200) {
	            	if(xmlHttp.responseText == 'success')
	            	{
	            		if(command == 'saveCompound')
	            			metabolite.push(name+"<T>"+moname+"<T>"+compartment+"<T>"+charge);
						if(command == 'updateCompound')
							metabolite[idx] = name+"<T>"+moname+"<T>"+compartment+"<T>"+charge;
						if(command == 'deleteCompound')
							metabolite.splice(idx, 1);

						cleareCompoundInput();
						printMetabolitList();
	            	}else if(xmlHttp.responseText == 'exist')
	            	{
	            		alert("Compound Name is already exist in DB\n Please enter another name");
	            	}
	            } else {
	                exceptionControl(xmlHttp);            
	                alertMessage("Code: 3001");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
	   
	  	//End of command for metabolite
	}
	
	function getMetaboliteList()
	{
	
		if(projectIdx == 0) return;
    	//Start getMetaboliteList
		var sendData = "cmd=getCompoundList";
	  	sendData = sendData + "&pid="+projectIdx;
	   	var getPost = "POST";                
	   	var urlFileAppl = "ModelingServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();           
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                
	            if (xmlHttp.status == 200) {               
	            	if(xmlHttp.responseText != 'failed')
	            	{
	            		removelAllArray(metabolite);
	            		var colSplit = xmlHttp.responseText.split("<N>");
	            		for(var i=0; i<colSplit.length-1; i++)
	            		{
	            			metabolite.push(colSplit[i]);
	            		}
	            		printMetabolitList();
	            	}
	            } else {
	                exceptionControl(xmlHttp);            
	                alertMessage("Code: 3002");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
	  	//End of getMetaboliteList
	}
	
		
	//function cmdReaciton(command, idx, name, oname, substrate, product, reversible, subsystem, ecnumber, genename, genes, equation, system)
	function cmdReaciton(command, idx, name, oname, substrate, product, reversible, subsystem, ecnumber, genename, genes, system, nName)
	{
		var sendData = "cmd="+command;
		sendData = sendData + "&pid="+projectIdx;
		sendData = sendData + "&name="+name;
		if(command != 'deleteReaction'){
			sendData = sendData + "&nName="+nName;
			sendData = sendData + "&oname="+oname;
			sendData = sendData + "&ecnumber="+ecnumber;
			sendData = sendData + "&genename="+genename;
			sendData = sendData + "&genes="+genes;
			sendData = sendData + "&reversible="+reversible;
			sendData = sendData + "&subsystem="+subsystem;
			sendData = sendData + "&system="+system;
			sendData = sendData + "&substrate="+substrate;
			sendData = sendData + "&product="+product;
			//sendData = sendData + "&equation='"+makeEquation(substrate, product, reversible)+"'";
		}
		var getPost = "POST";                
	   	var urlFileAppl = "ModelingServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();           
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                
	            if (xmlHttp.status == 200) {               
	            	if(xmlHttp.responseText == 'success')
	            	{
	            		if(command == 'saveReaction')
	            		{
	            			var str = name+"<T>"+oname+"<T>"+substrate+"<T>"+product+"<T>"+reversible+"<T>"+subsystem+"<T>"+ecnumber+"<T>"+genename+"<T>"+genes+"<T>"+system;
	            			
	            			reactions.push(str);
	            		}
						if(command == 'updateReaction')
						{
							reactions[idx] = nName+"<T>"+oname+"<T>"+substrate+"<T>"+product+"<T>"+reversible+"<T>"+subsystem+"<T>"+ecnumber+"<T>"+genename+"<T>"+genes+"<T>"+system;
						}
						if(command == 'deleteReaction'){
							reactions.splice(idx, 1);
						}
						if(byId("ModelingPane2").style.visibility == 'visible')
				  			printReactionList();
				  		else if(byId("ReactionsPane").style.visibility == 'visible')
				  			getPathwayInformation(previousPathwayName,previousCategory);
				  		//newReaction();
	            	}else if(xmlHttp.responseText == 'exist')
	            	{
	            		alert("Reaction Name is already exist in DB\n Please enter another name");
	            	}
	            } else {
	                exceptionControl(xmlHttp);            
	                alertMessage("Code: 3003");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
	}
	
	function getReactionList()
	{	
		if(projectIdx == 0) return;
    	//Start getMetaboliteList
		var sendData = "cmd=getReactionList";
	  	sendData = sendData + "&pid="+projectIdx;
	   	var getPost = "POST";                
	   	var urlFileAppl = "ModelingServlet";
	   	var trueFalse = isTrueOrFalse;
	   	if (window.ActiveXObject) {	 // IE
			trueFalse = false;
		}
		
	   	var xmlHttp = newXMLHttpRequest();           
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                
	            if (xmlHttp.status == 200) {               
	            	if(xmlHttp.responseText != 'failed')
	            	{
	            		removelAllArray(reactions);
	            		var colSplit = xmlHttp.responseText.split("<N>");
	            		for(var i=0; i<colSplit.length-1; i++)
	            		{
	            			reactions.push(colSplit[i]);
	            		}
	            		printReactionList();
	            	}
	            } else {
	                exceptionControl(xmlHttp);            
	                alertMessage("Code: 3004");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
	  	//End of getMetaboliteList
	}
	
	
	
	function printMetabolitList()
	{

		var mTable = byId("newcompoundsTableBody");
		deleteRowFromTable(mTable);
				
		for(var i=0; i<metabolite.length; i++)
		{
			var colSplit = metabolite[i].split("<T>");
			
			var newRow = document.createElement("tr");
			
			var newCell = [];
			for(var k=0; k<5; k++){
				newCell.push(document.createElement("td"));
			}
			newCell[0].innerHTML = i+1;
			newCell[1].innerHTML = colSplit[0];
			newCell[2].innerHTML = colSplit[1];
			newCell[3].innerHTML = colSplit[2]+" Charge="+colSplit[3];
			newCell[4].innerHTML = "<a href='javascript:editMetabolite("+i+")'>[Edit]</a><a href='javascript:deleteMetabolite("+i+");'>[Del]</a>";
			newCell[4].width = "60px";
			for(var k=0; k<5; k++){
				newRow.appendChild(newCell[k]);
			}
			if((i % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((i % 2) == 1) newRow.bgColor = "#eeeeee";
			
			mTable.appendChild(newRow);
		}
	}
	
	function editMetabolite(idx)
	{
		var colSplit = metabolite[idx].split("<T>");
		//byId("saveButton").onClick = "modifyMetabolite("+idx");";
		byId("metaboliteIdx").value = idx;
		byId("metaboliteName").value = colSplit[0];
		byId("metaboliteName").disabled = true;
		byId("moName").value = colSplit[1];
		byId("compartment").value = colSplit[2];
		byId("charge").value = colSplit[3];
		
		openAddCompoundDialog();
	}
		
	
	function modifyMetabolite(idx)
	{
		
		var name = byId("metaboliteName").value;
		var moname = byId("moName").value;
		if(moname == "") moname = name;
		var compartment = byId("compartment").value;
		var charge = byId("charge").value;

		cmdMetabolite(name, moname, compartment, charge, "updateCompound", idx);
	}
	
	function cleareCompoundInput()
	{
		byId("metaboliteIdx").value = "";
		byId("metaboliteName").value = "";
		byId("metaboliteName").disabled = false;
		byId("moName").value = "";
		byId("compartment").selectedIndex = 0;
		byId("charge").value = "1.0";
	}
	
	function deleteMetabolite(idx)
	{
		var colSplit = metabolite[idx].split("<T>");
		cmdMetabolite(colSplit[0], colSplit[1], colSplit[2], colSplit[3], "deleteCompound", idx);
	}
	
	function deleteRowFromTable(rTableBody)
  	{
  		for(var i=rTableBody.rows.length-1; i>=0; i--)
	  		rTableBody.deleteRow(i);
  	}
  	
  	function addCompoundToReaction(name, gubun)
  	{
		if(gubun == 'substrate') 
		{
			currentSubstrate.push(name);
			currentSubstrateStoich.push(1);
		}
		if(gubun == 'product') 
		{
			currentProduct.push(name);
			currentProductStoich.push(1);
		}
  		printEquation();
  	}
  	
  	function printEquation()
  	{
  		var equation = "";
  		for(var i=0; i<currentSubstrate.length; i++)
		{
			if(i==0) equation = currentSubstrate[i];
			else equation = equation + " + " + currentSubstrate[i];
		}
		equation = equation + " --> " 
		for(var i=0; i<currentProduct.length; i++)
		{
			if(i==0) equation = equation + currentProduct[i];
			else equation = equation + " + " + currentProduct[i];
		}
		//alert(equation);
		showSubsrateListForEdit();
		showProductListForEdit();
  	}
  	
  	function showSubsrateListForEdit()
  	{
  		var mTable = byId("currentSubstrateListBody");
		deleteRowFromTable(mTable);

		var newRow = document.createElement("tr");	
		var newCell = document.createElement("td");
		newCell.innerHTML = "";
				
		for(var i=0; i<currentSubstrate.length; i++)
		{
			if(i!=0) newCell.innerHTML = newCell.innerHTML + " + ";
			newCell.innerHTML = newCell.innerHTML +"<input type=text size=2 id=sub"+i+" value='"+currentSubstrateStoich[i]+"' onchange='chageSubstrateStoich("+i+");'>";
			newCell.innerHTML = newCell.innerHTML +currentSubstrate[i]+"<input type=button value='x' onclick='deleteCompoundOfReaction("+i+", \"s\");'>";
		}
		newRow.appendChild(newCell);
		mTable.appendChild(newRow);
  	}
  	
  	function showProductListForEdit()
  	{
  		var mTable = byId("currentProductListBody");
		deleteRowFromTable(mTable);
				
		var newRow = document.createElement("tr");	
		var newCell = document.createElement("td");
		newCell.innerHTML = "";

		for(var i=0; i<currentProduct.length; i++)
		{
			if(i!=0) newCell.innerHTML = newCell.innerHTML + " + ";
			newCell.innerHTML = newCell.innerHTML+"<input type=text size=1 id=pro"+i+" value='"+currentProductStoich[i]+"' onchange='chageProductStoich("+i+");'>";
			newCell.innerHTML = newCell.innerHTML+currentProduct[i]+"<input type=button value='x' onclick='deleteCompoundOfReaction("+i+", \"p\");'>";
		}
		newRow.appendChild(newCell);
		mTable.appendChild(newRow);
  	}
  	
  	function deleteCompoundOfReaction(idx, gubun)
  	{
  		if(gubun == 'p')
  		{
  			currentProduct.splice(idx, 1);
  			currentProductStoich.splice(idx, 1);
  			showProductListForEdit();
  		}else if(gubun == 's')
  		{
  			currentSubstrate.splice(idx, 1);
  			currentSubstrateStoich.splice(idx, 1);
  			showSubsrateListForEdit();
  		}
  	}
  	
  	function chageSubstrateStoich(idx)
  	{
  		currentSubstrateStoich[idx] = byId("sub"+idx).value;
  	}

  	function chageProductStoich(idx)
  	{
  		currentProductStoich[idx] = byId("pro"+idx).value;
  	}
  	
  	function addReaction()
  	{
  		var idx = byId('reactionIdx').value;
  		var name = byId('reactionName').value;
  		var oname = byId('reactionOName').value;
  		var ecnumber = byId("ecnumber").value;
  		var genename = byId("genename").value;
  		var genes = byId("genes").value;
  		var reversible = byId('isreversible').value;
  		var system = byId('category').value;
  		var subsystem = byId("selecPathway").value;
  		var substrate = "";
  		var product = "";
  		if(name == '')
  		{
  			alert("There is no reaction's name\n You must enter the name");
  			return;
  		}
  		if(oname == '')
  		{
  			oname = name;
  		}
  		if(subsystem == '')
  		{
  			alert("There is no pathway\n You must select a pathway or create new pathway");
  			return;
  		}
  		
  		
  		
  		if(currentSubstrate.length == 0 || currentProduct.length == 0)
  		{
  			alert("Reaction must have substrates and products"); 
  			return;
  		}
  		for(var i=0; i<currentSubstrate.length; i++)
  		{
  			if(i > 0) substrate = substrate +"<P>";
  			substrate = substrate+currentSubstrateStoich[i]+"<D>"+currentSubstrate[i];  			
  		}
  		for(var i=0; i<currentProduct.length; i++)
  		{
  			if(i > 0) product = product +"<P>";
  			product = product+currentProductStoich[i]+"<D>"+currentProduct[i];
  		}
  		//alert(substrate+" "+product);
  		var equation = makeEquation(substrate, product, reversible);
  		if(idx != ""){
  			var colSplit = reactions[idx].split("<T>");
  			var nName = name;
  			name = colSplit[0];
  			cmdReaciton("updateReaction", idx, name, oname, substrate, product, reversible, subsystem, ecnumber, genename, genes, system, nName)
  		}else{
  			if(isExistReaction(name)){
				alert("Reaction name is duplicated");
				return;
			}
  			cmdReaciton("saveReaction", -1, name, oname, substrate, product, reversible, subsystem, ecnumber, genename, genes, system, name)
  		}
  	}
  	
  	function newReaction()
  	{
  		removelAllArray(currentProduct);
  		removelAllArray(currentProductStoich);
  		removelAllArray(currentSubstrate);
  		removelAllArray(currentSubstrateStoich);
  		
  		byId("reactionIdx").value = '';
  		byId('reactionName').value = '';
  		byId('reactionOName').value = '';
  		byId("selecPathway").selectedIndex = 0;
  		byId("ecnumber").value = '';
  		byId("genename").value = '';
  		byId("genes").value = '';
  		byId('isreversible').selectedIndex = 0;
  		
  		byId("SubstrateSearchKey").value = "";
  		byId("ProductSearchKey").value = "";
		
		deleteRowFromTable(byId("currentProductListBody"));
		deleteRowFromTable(byId("currentSubstrateListBody"));
  	}
  	
  	function printReactionList()
  	{
  		var mTable = byId("newreactionsTableBody");
			deleteRowFromTable(mTable);
			
  		for(var i=0; i<reactions.length; i++)
  		{
  			var newRow = document.createElement("tr");
  			//alert(reactions[i]);
  			var colSplit = reactions[i].split("<T>");
  			
 			var newCell = [];
			for(var k=0; k<6; k++){
				newCell.push(document.createElement("td"));
			}
			newCell[0].innerHTML = i+1;
			newCell[1].innerHTML = "<div id='RName"+i+"' style='cursor:hand;' onClick='readyToChangeRName(\""+i+"\");'>"+colSplit[0]+ "</div>";
			newCell[2].innerHTML = "<div id='ROName"+i+"' style='cursor:hand;' onClick='readyToChangeROfiicialName(\""+i+"\");'>"+colSplit[1]+ "</div>";
				
			var substrates = colSplit[2].split("<P>");
			var products = colSplit[3].split("<P>");

			newCell[3].innerHTML = "<div id='Equation"+i+"' style='cursor:hand;' onClick='readyToChangeEquation(\""+i+"\");'>"+makeEquation(colSplit[2], colSplit[3], colSplit[4])+ "</div>";
			newCell[4].innerHTML = colSplit[5];
			newCell[5].innerHTML = "[<a href='#' onClick='editReaction("+i+");'>Edit</a>][<a href='javascript:deleteReaction("+i+");'>Del</a>]";
  			newCell[5].width = "60px";
			for(var k=0; k<6; k++){
					newRow.appendChild(newCell[k]);
			}
			if((i % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((i % 2) == 1) newRow.bgColor = "#eeeeee";
			
			mTable.appendChild(newRow);
  		}
  	}
  	
  	function makeEquation(substrate, product, reversible)
  	{
  	    
  		var substrates = substrate.split("<P>");
  		var products = product.split("<P>");
  		var equation = "";
		for(var s=0; s<substrates.length; s++)
		{
			var cols = substrates[s].split("<D>");
			if(cols[0] == '1') cols[0] = '';
			if(s==0) equation = cols[0]+" " + cols[1];
			else
				equation = equation + " + " + cols[0]+" " + cols[1];
		}
		if(reversible == 'true')
			equation = equation + " <==> ";
		else
			equation = equation + " --> ";
		
		for(var s=0; s<products.length; s++)
		{
			var cols = products[s].split("<D>");
			if(cols[0] == '1') cols[0] = '';
			if(s==0) equation = equation + cols[0]+" " + cols[1];
			else
				equation = equation + " + " + cols[0]+" " + cols[1];
		}
		//alert(equation);
		return equation;
  	}
  	
  	function editReaction(idx)
  	{
		showModelingByWizard();
		showAddReactionDialog();
  		
  		var colSplit = reactions[idx].split("<T>");
  		byId('category').value = colSplit[9];
  		selectPathwayForCategory("selecPathway",byId("category").value);
  		
  		byId("reactionIdx").value = idx;
		byId('reactionName').value = colSplit[0];
  		byId('reactionOName').value = colSplit[1];
  		byId("selecPathway").value = colSplit[5];
  		byId("ecnumber").value = colSplit[6];
  		byId("genename").value = colSplit[7];
  		byId("genes").value = colSplit[8];
  		byId('isreversible').value = colSplit[4];
  		
		removelAllArray(currentSubstrate);
		removelAllArray(currentSubstrateStoich);
		removelAllArray(currentProduct);
		removelAllArray(currentProductStoich);
		
		var substrates = colSplit[2].split("<P>");
		var products = colSplit[3].split("<P>");
		
		for(var s=0; s<substrates.length; s++)
		{
			var cols = substrates[s].split("<D>");
			currentSubstrate.push(cols[1]);
			currentSubstrateStoich.push(cols[0]);
		}
		for(var s=0; s<products.length; s++)
		{
			var cols = products[s].split("<D>");
			currentProduct.push(cols[1]);
			currentProductStoich.push(cols[0]);
		}
		
		showSubsrateListForEdit();
		showProductListForEdit();
		//showNewPathwayForm();
  	}
  	
  	function deleteReaction(idx)
  	{
  		var colSplit = reactions[idx].split("<T>");
		cmdReaciton("deleteReaction", idx, colSplit[0]);
  	}
  	
  	function removelAllArray(arr)
  	{
  		for(var i=arr.length-1; i>=0; i--)
  			arr.pop();
  	}
  	
  	function showNewReactionInput(isShow)
  	{
  		if(isShow == 'hide')
  		{
  			if(modelingGubun != 1){
	  			byId("newReacitonInput").style.visibility = 'hidden';
	  			byId("newReacitonInput").style.display = 'none';
  			}
  			newReaction();
  		}else{
  			byId("newReactionDialog").style.height = '520px';
  			byId("newReacitonInput").style.visibility = 'visible';
  			byId("newReacitonInput").style.display = 'inline';
  		}
  	}
  	
  	function showNewScriptInput(isShow)
  	{
  		if(isShow == 'hide')
  		{
  			byId("newScriptInput").style.visibility = 'hidden';
  			byId("newScriptInput").style.display = 'none';
  			//clearNewPathwayForm();
  		}else{
  			hideCompoundList();
  			
  			byId("newReactionDialog").style.height = '600px';
  			byId("newReactionDialog").style.width = '635px';
  			byId("newScriptInput").style.visibility = 'visible';
  			byId("newScriptInput").style.display = 'inline';
  		}
  	}
  	
  	function showNewKEGGInput(isShow)
  	{
  		if(isShow == 'hide')
  		{
  			byId("newInputFromKegg").style.visibility = 'hidden';
  			byId("newInputFromKegg").style.display = 'none';
  			//clearNewPathwayForm();
  		}else{
  			hideCompoundList();
  			showNewScriptInput('show');
  			byId("newReactionDialog").style.height = '600px';
  			byId("newReactionDialog").style.width = '635px';
  			byId("newInputFromKegg").style.visibility = 'visible';
  			byId("newInputFromKegg").style.display = 'inline';
  		}
  	}
  	
  	function searchCompoundKeyword(gubun)
	{
		var partialKey = "";
	  	if(gubun == 'substrate')
	  		partialKey = byId("SubstrateSearchKey").value;	
	  	else if(gubun == 'product')
  			partialKey = byId("ProductSearchKey").value;

		if(event.keyCode == 13)
		{
			directAddCompound(partialKey, gubun);
		}else{
		  	
			var sendData = "action=searchCompoundKeyword";
			sendData = sendData + "&pid="+projectIdx;
		  	sendData = sendData + "&keyword="+partialKey;
		   	
		   	var getPost = "POST";                      
		   	var urlFileAppl = "AnalysisServlet";
		   	var trueFalse = isTrueOrFalse;                       
		
		   	var xmlHttp = newXMLHttpRequest();
		  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
		    xmlHttp.onreadystatechange = function() {    
		        if (xmlHttp.readyState == 4) {              
		            if (xmlHttp.status == 200) {             
		            	//printPathwayList(xmlHttp);
		            	printCompoundKeywordList(xmlHttp, gubun);
		            } else {
		                exceptionControl(xmlHttp);          
		                alert("Code: 3005");
		            }
		        }
		    }
		    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
		    xmlHttp.setRequestHeader("Content-Type", conType);
		    xmlHttp.send(sendData);
		  	//End
	  	}
  	}
  	
  	function searchDirectCompoundKeyword(gubun)
	{
		var partialKey = "";
	  	if(gubun == 'substrate')
	  		partialKey = byId("SubstrateSearchKey").value;	
	  	else if(gubun == 'product')
 			partialKey = byId("ProductSearchKey").value;

		if(event.keyCode == 13)	directAddCompound(partialKey, gubun);
		else {
		  	if(partialKey.length < 2) return;	
	
		  	searchCompoundKeyword(gubun);
	  	}
  	}
  	
  	function directAddCompound(keyword, gubun)
  	{
  		var sendData = "action=getCompound";
		sendData = sendData + "&pid="+projectIdx;
	  	sendData = sendData + "&keyword="+keyword;
	   	
	   	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {             
	            	if(xmlHttp.responseText == "failed")
	            	{
	            		cmdMetabolite(keyword, keyword, "Cytosol", "1.0", "saveCompound");
	            	}
	            	addCompoundToReaction(keyword, gubun)
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("Code: 3005");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function showCompoundList()
  	{
  		byId("compoundList").style.visibility = "visible";
  		byId("compoundList").style.display = "inline";
  	}
  	function hideCompoundList()
  	{
  		deleteRowFromTable(byId("compoundListBody"));
  		byId("compoundList").style.visibility = "hidden";
  		byId("compoundList").style.display = "none";
  	}
  	
  	function printCompoundKeywordList(xmlHttp, gubun)
  	{
  		showCompoundList();
  		var xmlData = xmlHttp.responseXML;
  		var mNodes = xmlData.getElementsByTagName("mname");
	  	var mNames = xmlData.getElementsByTagName("moname");
	  	//var mDescs = xmlData.getElementsByTagName("mdescription");
	  	
	  	var keywordBody = byId("compoundListBody");
	  	deleteRowFromTable(keywordBody);
	  	
	  	for(var k=0; k<mNodes.length; k++)
	  	{
	  		
	  		var name = mNodes[k].childNodes[0].nodeValue;
	  		var officialname = mNames[k].childNodes[0].nodeValue;
	  		//var description = mDescs[k].childNodes[0].nodeValue;
	  		var newRow = document.createElement("tr");
	  		var newCell1 = document.createElement("td");
	  		var newCell2 = document.createElement("td");
	  		var newCell3 = document.createElement("td");
	  		//var newCell4 = document.createElement("td");
	  		var newCell5 = document.createElement("td");

			newCell1.width = '20px';
	  		newCell2.width = '100px';
	  		newCell3.width = '360px';
	  		//newCell4.width = '300px';
	  		newCell5.width = '50px';
	  		
			newRow.id = name;
	  		newCell1.innerHTML = k+1;
	  		newCell2.innerHTML = name;
	  		newCell3.innerHTML = officialname;
	  		//newCell4.innerHTML = description;
	  		if(gubun == 'substrate')
	  		{
	  			if(isExistSubstrate(name))
	  				newCell5.innerHTML = "<input type=checkbox checked id=candidateChk"+k+" onClick='addOrDelCompoundFromReaction(\""+k+"\",\""+name+"\", \"substrate\");'>";
	  			else
	  				newCell5.innerHTML = "<input type=checkbox id=candidateChk"+k+" onClick='addOrDelCompoundFromReaction(\""+k+"\",\""+name+"\", \"substrate\");'>";
	  		}else if(gubun == 'product')
	  		{
	  			if(isExistProduct(name))
	  				newCell5.innerHTML = "<input type=checkbox checked id=candidateChk"+k+" onClick='addOrDelCompoundFromReaction(\""+k+"\",\""+name+"\", \"product\");'>";
	  			else
	  				newCell5.innerHTML = "<input type=checkbox id=candidateChk"+k+" onClick='addOrDelCompoundFromReaction(\""+k+"\",\""+name+"\", \"product\");'>";
	  		}
	  		newRow.appendChild(newCell1);
	  		newRow.appendChild(newCell2);
	  		newRow.appendChild(newCell3);
	  		///newRow.appendChild(newCell4);
	  		newRow.appendChild(newCell5);
	  		
	  		if((k % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((k % 2) == 1) newRow.bgColor = "#eeeeee";
			
	  		keywordBody.appendChild(newRow);
	  	}
  	}
  	
  	function isExistCompound(name)
  	{
  		for(var i=0; i<metabolite.length; i++)
  		{ 
  			var colSplit = metabolite[i].split("<T>");
  			if(colSplit[0].toLocaleUpperCase() == name.toLocaleUpperCase()) return true;
  		}
  		return false;
  	}
  	
  	function isExistReaction(name)
  	{
  		for(var i=0; i<reactions.length; i++)
  		{ 
  			var colSplit = reactions[i].split("<T>");
  			if(colSplit[0].toLocaleUpperCase() == name.toLocaleUpperCase()) return true;
  		}
  		return false;
  	}
  	
  	function isExistSubstrate(name)
  	{
  		for(var i=0; i<currentSubstrate.length; i++)
  		{ 
  			if(name == currentSubstrate[i]) return true;
  		}
  		return false;
  	}
  	
  	function isExistProduct(name)
  	{
  		for(var i=0; i<currentProduct.length; i++)
  		{ 
  			if(name == currentProduct[i]) return true;
  		}
  		return false;
  	}
  	
  	function deleteCompoundFromReaction(name, gubun)
  	{
  		if(gubun == 'substrate'){
  			for(var i=0; i<currentSubstrate.length; i++)
	  		{ 
	  			if(name == currentSubstrate[i])
	  			{
	  				currentSubstrate.splice(i, 1);
	  				currentSubstrateStoich.splice(i, 1);
	  			}
	  		}
  		}else if(gubun == 'product'){
  			for(var i=0; i<currentProduct.length; i++)
	  		{ 
	  			if(name == currentProduct[i])
	  			{
	  				currentProduct.splice(i, 1);
	  				currentProductStoich.splice(i, 1);
	  			}
	  		}
  		}
  		printEquation();
  	}
  	
  	function addOrDelCompoundFromReaction(idx, name, gubun)
  	{
  		if(byId("candidateChk"+idx).checked)
  		{
  			addCompoundToReaction(name, gubun);
  		}else{
  			deleteCompoundFromReaction(name, gubun)
  		}
  	}
  	
  	function showModelingCompoundList()
  	{
  		closeAddReactionDialog();
  		closeAddKnockoutDialog()
  		
  		byId("ListOfReactionMenu1").style.backgroundColor = "#ffffff";
  		byId("ListOfCompoundMenu1").style.backgroundColor = "#FDDC76";
		byId("ListOfKnockoutMenu1").style.backgroundColor = "#ffffff";

  		byId("modelingReactionList").style.visibility = "hidden";
  		byId("modelingReactionList").style.display = "none";
  		
  		byId("modelingCompoundList").style.visibility = "visible";
  		byId("modelingCompoundList").style.display = "inline";

  		byId("modelingKnockoutList").style.visibility = "hidden";
  		byId("modelingKnockoutList").style.display = "none";
  		
  		getMetaboliteList();
  	}
  	
  	function showModelingReactionList()
  	{ 
  	   
  	   if(byId("projectName").value=="")
  	   {
  	    deleteRowFromTable(byId("newcompoundsTableBody"));
			deleteRowFromTable(byId("newreactionsTableBody"));
			deleteRowFromTable(byId("newknockoutTableBody"));
  		}
  	   else
  	   {
  	   getReactionList();
  	   }
  		closeAddCompoundDialog();
  		closeAddKnockoutDialog()
  		
  		byId("ListOfReactionMenu1").style.backgroundColor = "#FDDC76";
  		byId("ListOfCompoundMenu1").style.backgroundColor = "#ffffff";
		byId("ListOfKnockoutMenu1").style.backgroundColor = "#ffffff";

  		byId("modelingReactionList").style.visibility = "visible";
  		byId("modelingReactionList").style.display = "inline";
  		
  		byId("modelingCompoundList").style.visibility = "hidden";
  		byId("modelingCompoundList").style.display = "none";

  		byId("modelingKnockoutList").style.visibility = "hidden";
  		byId("modelingKnockoutList").style.display = "none";
  		
  		
  	}
  	
  	function showModelingKnockoutList()
  	{
  	      if(byId("projectName").value=="")
  	   {
  	    deleteRowFromTable(byId("newcompoundsTableBody"));
			deleteRowFromTable(byId("newreactionsTableBody"));
			deleteRowFromTable(byId("newknockoutTableBody"));
  		}
  	   else
  	   {
  	   getKnockoutList();
  	   }
  		closeAddCompoundDialog();
  		closeAddReactionDialog();
  		
  		byId("ListOfReactionMenu1").style.backgroundColor = "#ffffff";
  		byId("ListOfCompoundMenu1").style.backgroundColor = "#ffffff";
		byId("ListOfKnockoutMenu1").style.backgroundColor = "#FDDC76";

  		byId("modelingKnockoutList").style.visibility = "visible";
  		byId("modelingKnockoutList").style.display = "inline";

  		byId("modelingReactionList").style.visibility = "hidden";
  		byId("modelingReactionList").style.display = "none";
  		
  		byId("modelingCompoundList").style.visibility = "hidden";
  		byId("modelingCompoundList").style.display = "none";
  		
  		
  	}
  	
  	function getPathwayForModeling()
  	{
  		var cat = byId("category").value;
  	   // alert(cat);
  		if(cat=="all")
  		{
  		selectPathwayAll('pathwayForResult')
  		}
  		else
  		{
  		selectPathwayForCategory('selecPathway', cat);
  		}
  	}
  	//Implemented By Ganesh
  
  	function selectPathwayForCategory(comboName, category)
  	{
  	  
  	   if(category=="all")
  	   {
  	     byId("graphica").disabled=true;
  	     var sendData = "";
  		if(category == 'Select Category') 
  		{
  		return;
  		}
  		//if(category == 'user')	
  		//{
  		  //  if(userid=="guest")
  		   // {
  		     //alert("Please Login!");
  		   // }
  		    //else 
  		   // {
  		    //sendData = "cmd=pathwayListOfProject";
  			//sendData = sendData + "&pid="+projectIdx+"&userid="+userid;
  		   // }
  			
  		//}
  		
  		//else {
  		
  			sendData = "cmd=pathwayListAll";
  			sendData = sendData +"&pid="+projectIdx;
  			//sendData = sendData + "&system="+byId("pathwayForResult").value;
  		//}
  		var getPost = "POST";                      
    	var urlFileAppl = "PathwayServlet";
    	var trueFalse = isTrueOrFalse;                      
    	var xmlHttp = newXMLHttpRequest();            
   		xmlHttp.open(getPost, urlFileAppl, trueFalse);
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                 
	            if (xmlHttp.status == 200) {
	            	var xmlData = xmlHttp.responseText;
	            	printPathwayListForCategoryToCombo(xmlData, comboName);
	            } else {
	                exceptionControl(xmlHttp);          
                	alertMessage("CODE: 3006");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	   }
  	   else
  	   {
  		var sendData = "";
  	 
  		
  		if(category == 'user')	{
  		  if(userid=="guest")
  		  {
  		    alert("Please Login!")
  		  }
  		  else if((userid != 'guest')&&(userid !=null))
  		  {
  		 
  			sendData = "cmd=pathwayListOfUser";
  			sendData = sendData + "&pid="+projectIdx+"&userid="+userid;
  		
  		  }
  		}
  		else {
  			sendData = "cmd=pathwayList";
  			sendData = sendData + "&system="+category;
  		}
  		byId("graphica").disabled=false;
  		var getPost = "POST";                      
    	var urlFileAppl = "PathwayServlet";
    	var trueFalse = isTrueOrFalse;                      
    	var xmlHttp = newXMLHttpRequest();            
   		xmlHttp.open(getPost, urlFileAppl, trueFalse);
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                 
	            if (xmlHttp.status == 200) {
	            	var xmlData = xmlHttp.responseText;
	            	printPathwayListForCategoryToCombo(xmlData, comboName);
	            } else {
	                exceptionControl(xmlHttp);          
                	alertMessage("CODE: 3006");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	  
	    xmlHttp.send(sendData);
	    }
  	}
  	
  	function selectPathwayAll(comboName)
  	{
 
  		var sendData = "";
		sendData = "cmd=pathwayListAll";
		sendData = sendData + "&pid="+projectIdx;
  		
    	var getPost = "POST";                      
    	var urlFileAppl = "PathwayServlet";
    	var trueFalse = isTrueOrFalse;                      

    	var xmlHttp = newXMLHttpRequest();            
   		xmlHttp.open(getPost, urlFileAppl, trueFalse);
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                 
	            if (xmlHttp.status == 200) {                
	            	var xmlData = xmlHttp.responseText;
	            	printPathwayListForCategoryToCombo(xmlData, comboName);
	            } else {
	                exceptionControl(xmlHttp);          
                	alertMessage("CODE: 3007");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function printPathwayListForCategoryToCombo(xmlData, comboName)
    {
    	//var xmlData = xmlHttp.responseText;
    	
    	var colsplit = xmlData.split("<T>");
       
    		var newOption1 = document.createElement("option");
    		
   		var pathwayCombo = byId(comboName);
   		for(var i=pathwayCombo.options.length-1; i>=0; i--)
   			pathwayCombo.remove(i);
   			
    	//alert(selectedPathwayName);
    	
    	for(var i=0; i<colsplit.length; i++)
    	{
    		
    		//alert(colsplit[i]);
    	 var newOption = document.createElement("option");
    	
    		//  newOption.selected = true;
    		
    		
    		newOption.value = colsplit[i];
    		newOption.innerHTML = colsplit[i];    		
    		pathwayCombo.appendChild(newOption);
    		
    	}
    	newOption.SelectedIndex=0;
  		if(comboName == "pathwayForCompareCombo")
  		{
  		 readyToGetReactionWithAnalysisCompare();
  		 }
  		if(comboName == "pathwayForResult")
  		{
  		  
  		readyToGetReactionWithAnalysisResult();
  		}
  		if(comboName == "selecPathway"){
  			if(selectedPathwayName != '')
  			{
  			    
  				byId("selecPathway").value = selectedPathwayName;
                  				
  			}
  		}
    }
    
    function addReactionByEquationLine()
  	{
  		var script = byId("reactionScriptLine").value;
  		if(script == '') return;
  		equationValidation(script);
  	}
  	
  	function equationValidation(script)
  	{
  	    
  		var i = script.indexOf('+',i+1);
  		
  		while(i > 0)
  		{
  			k = i;
  			script = script.substring(0, i) + "#" +script.substring(i+1, script.length);
  			
  			i = script.indexOf('+', i+1);
  			if(i==k) break;
  		}
  		
  		var sendData = "cmd=validationLine";
  		sendData = sendData +"&script="+script;
  		sendData = sendData + "&userid="+userid;
    	sendData = sendData + "&pid="+projectIdx;
    	var getPost = "POST";                      
    	var urlFileAppl = "ScriptServlet";
    	var trueFalse = isTrueOrFalse;                      
		//alert(sendData);
    	var xmlHttp = newXMLHttpRequest();            
   		xmlHttp.open(getPost, urlFileAppl, trueFalse);
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                 
	            if (xmlHttp.status == 200) {
	            	printValidationResult(xmlHttp);
	            } else {
	                exceptionControl(xmlHttp);          
                	alertMessage("Code: 3010");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function printValidationResult(xmlHttp)
  	{
  		var colSplit = xmlHttp.responseText.split("<N>");
  		byId("validationResult").innerHTML="";
  		newScriptReaction = "";
  		if(colSplit[0] == 'failed')
  		{
  			//byId("validationResult").value = "Not validated\n";
  			newScriptReaction = "";
  			byId("validationResult").innerHTML="<B> The reaction format is Invalid!"+" Please check the"+ "<a href='#' onClick='rules()'> validation rules.</a></B>";
  		}else if(colSplit[0] == 'success')
  		{
  			//byId("validationResult").value = "Validated\n";
			newScriptReaction = colSplit[2];
			saveNewReaction();
			byId("validationResult").innerHTML = byId("validationResult").innerHTML + colSplit[1];
  		}
		
  	}
  	
  	function saveNewReaction()
  	{
  		var colSplit = newScriptReaction.split("<T>");
  		var name = colSplit[0];
  		var oname = colSplit[1];
  		var substrate = colSplit[2];
  		var product = colSplit[3];
  		var reversible = colSplit[4];
  		var ecnumber = colSplit[6];
  		var genename = colSplit[7];
  		var genes = colSplit[8];
  		//var system = colSplit[9];
  		//var subsystem = colSplit[5];
  		var system = byId('category').value;
  		var subsystem = byId("selecPathway").value;
  		//alert(newScriptReaction);
  		if(isExistReaction(name)){
				alert("Reaction name is duplicated");
				return;
		}
		
  		saveNewCompound(substrate);
  		//alert(substrate);
  		saveNewCompound(product);
  		//alert(product);
  		cmdReaciton("saveReaction", -1, name, oname, substrate, product, reversible, subsystem, ecnumber, genename, genes, system, name)
  		newSriptReaction();
  		cleareKEGGInput();
  	}
  	
  	function saveNewCompound(compound)
  	{
  		var colSplit = compound.split("<P>");
  		for(var i=0; i<colSplit.length;i++)
  		{
  			//alert(colSplit[i]);
  			cols = colSplit[i].split("<D>");
	  		if(cols[2] == 'N')
	  		{
	  			var name = cols[1];
	  			var moname = cols[1];
	  			var compartment = "Cytosol";
	  			var charge = "1.0";
	  			cmdMetabolite(name, moname, compartment, charge, "saveCompound", -1)
	  		}
  		}
  	}
  	
  	function newSriptReaction()
  	{
  		byId("reactionScriptLine").value = '';
  		//byId("newScriptReactionName").value = '';
  		byId("validationResult").innerHTML = '';
  		//byId("saveNewReactionBtn").disabled = true;
  		if(modelingGubun ==3) showNewScriptInput('hide');
  	}
  	
  	function startReactionListOfEnzyme()
  	{
  		if (event.keyCode != 13) return;
  		getReactionListOfEnzyme();
  	}
  	
  	function getReactionListOfEnzyme()
  	{
  		var enzymeId = byId("keggecnumber").value;
  		var mTable = byId("keggReactionList");
  		deleteRowFromTable(byId("keggReactionList"));
  		var newRow = document.createElement("tr");
  		var newCell = document.createElement("td");
  		
  		newCell.colspan = "5";
  		newCell.innerHTML = "Loading....<img src='images/indicator.gif'>";
  		newRow.appendChild(newCell);
  		mTable.appendChild(newRow);
  		/*	
  		for(var i=0; i<enzymeId.length; i++)
  		{
  			var c = enzymeId.substring(i,i+1);
  			if((c < 48 && c >57) && c != 46)
  			{
  				alert(enzymeId+" is not EC Number\n Ex) 1.1.2.1");
  				return;
  			}
  		}
  		*/
  		//Search option multiplize
  		var conditionGubun = byId("searchGubun").value;
  		var exactmatch = byId("exactmatch").checked;

  		var org = byId("organismList").value;
  		var sendData = "action=getReactionListOfEnzyme";
  		sendData = sendData +"&enzymeId="+enzymeId;
  		sendData = sendData + "&organism="+org;
    	sendData = sendData + "&conditionGubun="+conditionGubun;
    	sendData = sendData + "&exactmatch="+exactmatch;
    	var getPost = "POST";                      
    	var urlFileAppl = "KEGGServlet";
    	var trueFalse = isTrueOrFalse;                      

    	var xmlHttp = newXMLHttpRequest();            
   		xmlHttp.open(getPost, urlFileAppl, trueFalse);
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                 
	            if (xmlHttp.status == 200) {
	            	printReactionOfEnzyme(xmlHttp);
	            } else {
	                exceptionControl(xmlHttp);          
                	alertMessage("Code: 3011");
                	byId("keggecnumber").value = "";
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function printReactionOfEnzyme(xmlHttp)
  	{
  		if(xmlHttp.responseText == 'failed' || xmlHttp.responseText == '') {
  			alert("No reaction");
  			byId("keggecnumber").value = "";
			deleteRowFromTable(byId("keggReactionList"));
  			return;
  		}
  		tempReacitons = xmlHttp.responseText.split("<N>");
  		
  		var mTable = byId("keggReactionList");
			deleteRowFromTable(mTable);
			
  		for(var i=0; i<tempReacitons.length; i++)
  		{
  			var newRow = document.createElement("tr");
  			//alert(tempReacitons[i]);
  			var colSplit = tempReacitons[i].split("<T>");
  			
 			var newCell = [];
			for(var k=0; k<5; k++){
				newCell.push(document.createElement("td"));
			}
			newCell[0].innerHTML = colSplit[0];
			newCell[1].innerHTML = colSplit[1];
			
			equation = colSplit[2];
			
			if(tempReacitons.length > 0)
				//equation = dataCleansing(equation);
			   // alert(equation);
			//var regex = new RegExp("(",'g');
			//replace(/^\s*|\s*$/g,'');
		   equation=equation.replace(/\(/g,"");
		     equation=equation.replace(/\)/g,"");
		      equation=equation.replace(/\[/g,"");
		     
		   // equation=equation.replaceAll(")","");
	  		
			newCell[2].innerHTML = equation;
			newCell[3].innerHTML = colSplit[3];
			
				newCell[4].innerHTML = "<input type='radio' id='selecReaction' name='selecReaction' value='"+i+"' onClick='changeSelecReaction("+i+");'>";
  		
  				//newCell[4].innerHTML = "<input type='radio' id='selecReaction' name='selecReaction' value='"+i+"' onClick='changeSelecReaction("+i+");'>";
			for(var k=0; k<5; k++){
					newRow.appendChild(newCell[k]);
			}
			if((i % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((i % 2) == 1) newRow.bgColor = "#eeeeee";
			
			mTable.appendChild(newRow);
			tempReacitons[i] = colSplit[0]+"<T>"+colSplit[1]+"<T>"+equation+"<T>"+colSplit[3];
  		}
  		byId("keggecnumber").value = "";
  	}
  	
  	function dataCleansing(equation)
  	{
  		equation = equation.substring(4);
  		//alert(equation);
  		var idx = equation.indexOf('[');
  		if(idx > 0)
  			equation = equation.substring(0,idx);
  		idx = equation.indexOf('(');
  		if(idx > 0)
  		{
	  		var eidx = equation.indexOf(')');
  			equation = equation.substring(0,idx) + equation.substring(eidx+1);
  		}  		
  		return equation;  		
  	}
  	 function showList() {
     
       }

      function remLink() {
      if (window.sList && window.sList.open && !window.sList.closed)
      window.sList.opener = null;
       }
  	
  	
  	function saveReactionOfKegg()
  	{
  		//showNewScriptInput();
  		var now = new Date();
  	     var seconds = now.getSeconds();
         var ran="nag"+seconds;
  		var colSplit = tempReacitons[newKEGGReactionNum].split("<T>");
  		//alert(colSplit[0]+","+colSplit[2]);
  		// sList = window.open("stocklist.html", "list", 'resizable=1,width=480,height=250,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes');
  		 //sList.document.getElementById("yahoo").value=colSplit[2];
  		byId("reactionScriptLine").value = colSplit[2];
  		byId("newScriptReactionName").value = colSplit[0];
  	}
  	function call()
  	{
  	   alert("I got activated");
  	}
  	function changeSelecReaction(idx)
  	{
  		newKEGGReactionNum = idx;
  		byId("siva").disabled=false;
  	}
  	
  	function cleareKEGGInput()
  	{
  		var mTable = byId("keggReactionList");
			deleteRowFromTable(mTable);
  	}
  	
  	
  	
  	function reacyToGetCandidateKeyword()
  	{
  		//get candiate keyword start with given works
  		
  		//if key is direction key down or up navigae to the candidate keyword table
  		var key = event.keyCode;
		var scriptKeywordTable = byId("scriptkeywordListBody");
  		if(key == 38)
  		{
  			if(selectKeywordInScript != -1){
	  			if((selectKeywordInScript % 2) == 0) 
	  				scriptKeywordTable.rows[selectKeywordInScript].style.backgroundColor = "#FFFFFF";
				if((selectKeywordInScript % 2) == 1)
	  				scriptKeywordTable.rows[selectKeywordInScript].style.backgroundColor = "#eeeeee";
			}			
  			selectKeywordInScript--;
  			if(selectKeywordInScript != -1){
	  			scriptKeywordTable.rows[selectKeywordInScript].style.backgroundColor = "#CBFF75";
  			}
  		}else if(key == 40)
  		{
  			if(selectKeywordInScript != -1){
	  			if((selectKeywordInScript % 2) == 0) 
	  				scriptKeywordTable.rows[selectKeywordInScript].style.backgroundColor = "#FFFFFF";
				if((selectKeywordInScript % 2) == 1)
	  				scriptKeywordTable.rows[selectKeywordInScript].style.backgroundColor = "#eeeeee";
			}			
  			selectKeywordInScript++;
  			if(selectKeywordInScript <= byId("scriptkeywordListBody").rows.length){
	  			scriptKeywordTable.rows[selectKeywordInScript].style.backgroundColor = "#CBFF75";
  			}
  		}else{
			if(key==8 && scriptKeyword.length > 0) //backspace
				scriptKeyword = scriptKeyword.substring(0,scriptKeyword.length-1);
				
			if(key == 13) {//Enter
				var scriptvalue = byId("reactionScriptLine").value;
				scriptvalue = scriptvalue.substring(0, scriptvalue.length-scriptKeyword.length);
				scriptvalue = scriptvalue + byId("scriptkey"+selectKeywordInScript).value + " ";
				
				byId("reactionScriptLine").value = scriptvalue;
				deleteRowFromTable(byId("scriptkeywordListBody"));
				showOrhideScriptKeywordDiv('show');
				scriptKeyword = "";
				selectKeywordInScript = -1;
			}
			
			if((key >= 65 && key <= 90)||(key >= 97 && key <= 122) || (key>=48 && key <=57)) //Character or number
				scriptKeyword = scriptKeyword + String.fromCharCode(event.keyCode);
			if(key == 32) {// Space
				scriptKeyword = '';
	  			deleteRowFromTable(byId("scriptkeywordListBody"));
	  			showOrhideScriptKeywordDiv('hide');
	  		}
			
			//alert(key+","+scriptKeyword);
			if(scriptKeyword.length >= 2)
			{
				selectKeywordInScript = -1;
			 	getCandidateKeyword(scriptKeyword);
			}
		}
  	}
  	
  	function getCandidateKeyword(keyword)
  	{
		var partialKey = keyword;
	  	
	  	var sendData = "action=searchKeywordStartWith";
		sendData = sendData + "&pid="+projectIdx;
	  	sendData = sendData + "&keyword="+partialKey;
	   	
	   	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {             
	            	//printPathwayList(xmlHttp);
	            	printScriptKeywordList(xmlHttp);
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("Code: 3012");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function printScriptKeywordList(xmlHttp)
  	{
  		var xmlData = xmlHttp.responseXML;
  		var mNodes = xmlData.getElementsByTagName("mname");
	  	var mNames = xmlData.getElementsByTagName("moname");
	  	
	  	var keywordBody = byId("scriptkeywordListBody");
	  	deleteRowFromTable(keywordBody);
	  	
	  	showOrhideScriptKeywordDiv('show');
	  	
	  	for(var k=0; k<mNodes.length; k++)
	  	{
	  		
	  		var name = mNodes[k].childNodes[0].nodeValue;
	  		var officialname = mNames[k].childNodes[0].nodeValue;
	  		var newRow = document.createElement("tr");
	  		var newCell1 = document.createElement("td");
	  		var newCell2 = document.createElement("td");

			newCell1.width = '80px';
	  		newCell2.width = '300px';
	  		
			newRow.id = name;
	  		newCell1.innerHTML = "<input type='hidden' id='scriptkey"+k+"' value='"+name+"'>"+name;
	  		newCell2.innerHTML = officialname;
	  		newRow.appendChild(newCell1);
	  		newRow.appendChild(newCell2);
	  		
	  		if((k % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((k % 2) == 1) newRow.bgColor = "#eeeeee";
			
	  		keywordBody.appendChild(newRow);
	  	}
  	}
  	function showOrhideScriptKeywordDiv(gubun)
  	{
  		if(gubun == 'show')
  		{
  			byId("scriptkeywordListDiv").style.visibility = 'visible';
  			byId("scriptkeywordListDiv").style.display = 'inline';  			
  		}else{
  			byId("scriptkeywordListDiv").style.visibility = 'hidden';
  			byId("scriptkeywordListDiv").style.display = 'none';  			
		}  			
  	}
  	
  	function readyToChangeRName(idx)
  	{
  		//alert("Ready To Change "+idx);
  		var nameDiv = byId("RName"+idx);
  		previousRName = nameDiv.innerHTML;
  		nameDiv.innerHTML = "<input type='text' size=10 id='nRName"+idx+"' value='"+previousRName+"' onBlur='cancelChangeRName(\""+idx+"\");' onKeypress='changeRName(\""+idx+"\");'>";
  		byId("nRName"+idx).focus();
  		nameDiv.onclick = "";
  	}
  	
  	function cancelChangeRName(idx)
  	{
  		var nameDiv = byId("RName"+idx);
  		nameDiv.innerHTML = previousRName;
  		nameDiv.onclick = function(){readyToChangeRName(idx);};
  	}
  	
  	function changeRName(idx)
  	{
  		if(event.keyCode == 13){
	  		var newName = byId("nRName"+idx).value;
	  		if(newName != previousRName){
		  		var colSplit = reactions[idx].split("<T>");
		  		reactions[idx] = newName+"<T>"+colSplit[1]+"<T>"+colSplit[2]+"<T>"+colSplit[3]+"<T>"+colSplit[4]+"<T>"+colSplit[5]+"<T>"+colSplit[6]+"<T>"+colSplit[7]+"<T>"+colSplit[8]+"<T>"+colSplit[9]
		  		cmdReaciton("updateReaction", idx, previousRName, colSplit[1], colSplit[2], colSplit[3], colSplit[4], colSplit[5], colSplit[6], colSplit[7], colSplit[8], colSplit[9], newName);
	  			previousRName = '';
	  		}else{
	  			cancelChangeRName(idx);
	  		}
  		}
  	}
  	
  	function readyToChangeROfiicialName(idx)
  	{
  		//alert("Ready To Change "+idx);
  		var nameDiv = byId("ROName"+idx);
  		previousROfficialName = nameDiv.innerHTML;
  		nameDiv.innerHTML = "<input type='text' size=10 id='nROName"+idx+"' value='"+previousROfficialName+"' onBlur='cancelChangeROfiicialName(\""+idx+"\");' onKeypress='changeROfiicialName(\""+idx+"\");'>";
  		byId("nROName"+idx).focus();
  		nameDiv.onclick = "";
  	}
  	
  	function cancelChangeROfiicialName(idx)
  	{
  		var nameDiv = byId("ROName"+idx);
  		nameDiv.innerHTML = previousROfficialName;
  		nameDiv.onclick = function(){readyToChangeROfiicialName(idx);};
  	}
  	
  	function changeROfiicialName(idx)
  	{
  		if(event.keyCode == 13){
	  		var newName = byId("nROName"+idx).value;
	  		if(newName != previousROfficialName){
		  		var colSplit = reactions[idx].split("<T>");
		  		reactions[idx] = colSplit[0]+"<T>"+newName+"<T>"+colSplit[2]+"<T>"+colSplit[3]+"<T>"+colSplit[4]+"<T>"+colSplit[5]+"<T>"+colSplit[6]+"<T>"+colSplit[7]+"<T>"+colSplit[8]+"<T>"+colSplit[9]
		  		cmdReaciton("updateReaction", idx, colSplit[0], newName, colSplit[2], colSplit[3], colSplit[4], colSplit[5], colSplit[6], colSplit[7], colSplit[8], colSplit[9], colSplit[0]);
		  		previousROfficialName = '';
	  		}else{
	  			cancelChangeROfiicialName(idx);
	  		}
  		}
  	}
  	
  	function readyToChangeEquation(idx)
  	{
  		//alert("Ready To Change "+idx);
  		var nameDiv = byId("Equation"+idx);
  		previousEquation = nameDiv.innerHTML;
  		nameDiv.innerHTML = "<input type='text' size=40 id='nEquation"+idx+"' value='"+previousEquation+"' onBlur='cancelChangeEquation(\""+idx+"\");' onKeypress='changeEquation(\""+idx+"\");'>";
  		byId("nEquation"+idx).focus();
  		nameDiv.onclick = "";
  	}
  	
  	function cancelChangeEquation(idx)
  	{
  		var nameDiv = byId("Equation"+idx);
  		nameDiv.innerHTML = previousEquation;
  		nameDiv.onclick = function(){readyToChangeEquation(idx);};
  	}
  	
  	function changeEquation(idx)
  	{
  		if(event.keyCode == 13){
	  		var newName = byId("nEquation"+idx).value;
	  		//alert(newName);
	  		if(newName != previousEquation){
	  			changeEquationDirect(newName, idx);
	  		}else{
	  			cancelChangeEquation(idx);
	  		}
  		}
  	}
  	
  	function changeEquationDirect(script, idx)
  	{
  		var i = script.indexOf('+',i+1);
  		while(i > 0)
  		{
  			k = i;
  			script = script.substring(0, i) + "#" +script.substring(i+1, script.length);
  			i = script.indexOf('+', i+1);
  			if(i==k) break;
  		}
  		
  		var sendData = "cmd=validationLine";
  		sendData = sendData +"&script="+script;
  		sendData = sendData + "&userid="+userid;
    	sendData = sendData + "&pid="+projectIdx;
    	var getPost = "POST";                      
    	var urlFileAppl = "ScriptServlet";
    	var trueFalse = isTrueOrFalse;                      

    	var xmlHttp = newXMLHttpRequest();            
   		xmlHttp.open(getPost, urlFileAppl, trueFalse);
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {                 
	            if (xmlHttp.status == 200) {
	            	changeEquationComplete(xmlHttp, idx);
	            } else {
	                exceptionControl(xmlHttp);          
                	alertMessage("Code: 3013");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}

  	function changeEquationComplete(xmlHttp, idx)
  	{
  		var result = xmlHttp.responseText;
  		//alert(result);
		var colSplit = result.split("<N>");
		var temp = '';
 		if(colSplit[0] == 'failed')
 		{
 			alert("Not validated");
 			cancelChangeEquation();
 		}else if(colSplit[0] == 'success')
 		{
		temp = colSplit[2];
 						
  		colSplit = reactions[idx].split("<T>");
  		var newEquation = temp.split("<T>");
  		//alert(newEquation[2]+"    "+newEquation[3]);
  		reactions[idx] = colSplit[0]+"<T>"+colSplit[1]+"<T>"+newEquation[2]+"<T>"+newEquation[3]+"<T>"+colSplit[4]+"<T>"+colSplit[5]+"<T>"+colSplit[6]+"<T>"+colSplit[7]+"<T>"+colSplit[8]+"<T>"+colSplit[9]
  		saveNewCompound(newEquation[2]);
  		saveNewCompound(newEquation[3]);
  		cmdReaciton("updateReaction", idx, colSplit[0], colSplit[1], newEquation[2], newEquation[3], colSplit[4], colSplit[5], colSplit[6], colSplit[7], colSplit[8], colSplit[9], colSplit[0]);
  		previousEquation = '';
 		}
	}
	
  	function openAddReactionDialog()
  	{
          byId("validationResult").value="";
  		if(byId("addReactionSelect").value != "0")
  		{
  			showAddReactionDialog();
  			if(selectedCategory != '')
			{
				//alert(selectedCategory);
				var tempCategory = '';
				if(selectedCategory == 'Central') tempCategory = 'Central Metabolism';
				if(selectedCategory == 'Amino Acid') tempCategory = 'Amino Acid Metabolism';
				if(selectedCategory == 'Carbohydrate') tempCategory = 'Carbohydrate Metabolism';
				if(selectedCategory == 'Energy') tempCategory = 'Energy Metabolism';
				if(selectedCategory == 'Lipid') tempCategory = 'Lipid Metabolism';
				if(selectedCategory == 'Cofactor/Vitamins') tempCategory = 'Metabolism of Cofactors and Vitamins';
				if(selectedCategory == 'ETC') tempCategory = 'ETC';
				byId("category").value = tempCategory;
			}
  			selectPathwayForCategory("selecPathway",byId("category").value);
  			var idx = byId("addReactionSelect").value;
  			if(idx == "1") showModelingByWizard();
  			if(idx == "2") showModelingByScript();
  			if(idx == "3") showModelingFromKegg();
  		}
  	}
  	
  	function showAddReactionDialog()
  	{
 	  	byId("newReactionDialog").style.visibility = "visible";
  		byId("newReacitonInput").style.visibility = "visible";
  		byId("newPathwayInputForm").style.visibility = "visible";
  		byId("newScriptInput").style.visibility = "visible";
  		byId("newInputFromKegg").style.visibility = "visible";
  		showCompoundList();
  	}
  	
  	function closeAddReactionDialog()
  	{
  		byId("newReactionDialog").style.visibility = "hidden";
  		byId("newReacitonInput").style.visibility = "hidden";
  		byId("newPathwayInputForm").style.visibility = "hidden";
  		
  		byId("newScriptInput").style.visibility = "hidden";
  		byId("newInputFromKegg").style.visibility = "hidden";

  		hideCompoundList();
  	}
  	
  	function openAddKnockoutDialog()
  	{
  	    var keywordBody = byId("candidateKnockTableBody");
	  	deleteRowFromTable(keywordBody);
  		byId("knockoutsearchKey").value="";
  		//geneknockout();
  		byId("newKnockoutDialog").style.visibility = "visible";
  		byId("newKnockoutDialog").style.display = "inline";
  		byId("newKnockoutInput").style.visibility = "visible";
  		
  		selectPathwayAll("knockoutPathwayListCombo");
  	}
  	
  	function closeAddKnockoutDialog()
  	{
  		byId("newKnockoutDialog").style.visibility = "hidden";
  		byId("newKnockoutDialog").style.display = "none";
  		byId("newKnockoutInput").style.visibility = "hidden";
  	}
  	
  	function openAddCompoundDialog()
  	{
  		byId('newCompoundDialog').style.visibility = "visible";
  		byId('newCompoundDialog').style.display = "inline";
  	}
  	
  	function closeAddCompoundDialog()
  	{
  		byId('newCompoundDialog').style.visibility = "hidden";
  		byId('newCompoundDialog').style.display = "none";
  	}
  	
  	
  	function moveStartCompoundInput()
  	{
  		privX = event.x;
  		privY = event.y;
  		posX = byId("newCompoundDialog").style.left;
  		posY = byId("newCompoundDialog").style.top;
  		posX = posX.substring(0, posX.length-2);
  		posY = posY.substring(0, posY.length-2);
  	}
  	
  	function movingCompoundInput()
  	{
  		var moveX = privX - event.x;
  		var moveY = privY - event.y;
  		var destY = (new Number(posY) - new Number(moveY));
  		var destX = (new Number(posX) - new Number(moveX));
  		if(destX <-250) destX = -250;
  		if(destY <0) destY = 0;
  		//if(destX >winWidth-300) destX = windWidth-300;
  		//if(destY >winHeight-300) destY = winHeight-300;
  		 
  		byId("newCompoundDialog").style.top = destY+"px";
  		byId("newCompoundDialog").style.left = destX+"px";
  	}
  	
  	function moveStartReactionInput()
  	{
  		privX = event.x;
  		privY = event.y;
  		posX = byId("newReactionDialog").style.left;
  		posY = byId("newReactionDialog").style.top;
  		posX = posX.substring(0, posX.length-2);
  		posY = posY.substring(0, posY.length-2);
  	}
  	
  	function movingReactionInput()
  	{
  		var moveX = privX - event.x;
  		var moveY = privY - event.y;
  		var destY = (new Number(posY) - new Number(moveY));
  		var destX = (new Number(posX) - new Number(moveX));
  		if(destX <-500) destX = -500;
  		if(destY <150) destY = 150;
  		//if(destX >winWidth-650) destX = winWidth-650;
  		//if(destY >winHeight-300) destY = winHeight-300;
  		
  		byId("newReactionDialog").style.top = destY+"px";
  		byId("newReactionDialog").style.left = destX+"px";
  	}
  	
  	function moveReactionForm(direction)
  	{
  		posX = byId("newReactionDialog").style.left;
  		posY = byId("newReactionDialog").style.top;
  		posX = posX.substring(0, posX.length-2);
  		posY = posY.substring(0, posY.length-2);
  		
  		var destY = posY;
  		var destX = posX;
  		
  		if(direction == 'up'){
  			destY = (new Number(posY) - 100);
  		}
  		if(direction == 'down'){
  			destY = (new Number(posY) + 100);  		
  		}
  		if(direction == 'left'){
  			destX = (new Number(posX) - 100);  		
  		}
  		if(direction == 'right'){
  			destX = (new Number(posX) + 100);  		
  		}

  		if(destX <-500) destX = -500;
  		if(destY <150) destY = 150;
  		//if(destX >winWidth-650) destX = winWidth-650;
  		//if(destY >winHeight-300) destY = winHeight-300;
  		
  		byId("newReactionDialog").style.top = destY+"px";
  		byId("newReactionDialog").style.left = destX+"px";
  	}
  	
  	function moveCompoundForm(direction)
  	{
  		posX = byId("newCompoundDialog").style.left;
  		posY = byId("newCompoundDialog").style.top;
  		posX = posX.substring(0, posX.length-2);
  		posY = posY.substring(0, posY.length-2);
  		
  		var destY = posY;
  		var destX = posX;
  		
  		if(direction == 'up'){
  			destY = (new Number(posY) - 100);
  		}
  		if(direction == 'down'){
  			destY = (new Number(posY) + 100);  		
  		}
  		if(direction == 'left'){
  			destX = (new Number(posX) - 100);  		
  		}
  		if(direction == 'right'){
  			destX = (new Number(posX) + 100);  		
  		}

  		if(destX <-250) destX = -250;
  		if(destY <150) destY = 150;
  		//if(destX >winWidth-300) destX = winWidth-300;
  		//if(destY >winHeight-300) destY = winHeight-300;
  		
  		byId("newCompoundDialog").style.top = destY+"px";
  		byId("newCompoundDialog").style.left = destX+"px";
  	}
  	
  	function moveKnockoutForm(direction)
  	{
  		posX = byId("newKnockoutDialog").style.left;
  		posY = byId("newKnockoutDialog").style.top;
  		posX = posX.substring(0, posX.length-2);
  		posY = posY.substring(0, posY.length-2);
  		
  		var destY = posY;
  		var destX = posX;
  		
  		if(direction == 'up'){
  			destY = (new Number(posY) - 100);
  		}
  		if(direction == 'down'){
  			destY = (new Number(posY) + 100);  		
  		}
  		if(direction == 'left'){
  			destX = (new Number(posX) - 100);  		
  		}
  		if(direction == 'right'){
  			destX = (new Number(posX) + 100);  		
  		}

  		if(destX <-470) destX = -470;
  		if(destY <150) destY = 150;
  		//if(destX >winWidth-650) destX = winWidth-650;
  		//if(destY >winHeight-300) destY = winHeight-300;
  		
  		byId("newKnockoutDialog").style.top = destY+"px";
  		byId("newKnockoutDialog").style.left = destX+"px";
  	}
  	
  	function moveStartKnocoutInput()
  	{
  		privX = event.x;
  		privY = event.y;
  		posX = byId("newKnockoutDialog").style.left;
  		posY = byId("newKnockoutDialog").style.top;
  		posX = posX.substring(0, posX.length-2);
  		posY = posY.substring(0, posY.length-2);
  	}
  	
  	function movingKnocoutInput()
  	{
  	 	
  		var moveX = privX - event.x;
  		var moveY = privY - event.y;
  		var destY = (new Number(posY) - new Number(moveY));
  		var destX = (new Number(posX) - new Number(moveX));
  		if(destX <-470) destX = -470;
  		if(destY <150) destY = 150;
  		//if(destX >winWidth-650) destX = winWidth-650;
  		//if(destY >winHeight-300) destY = winHeight-300;
  		
  		byId("newKnockoutDialog").style.top = destY+"px";
  		byId("newKnockoutDialog").style.left = destX+"px";
  	}
  	
function showModelingByWizard()
{
	//showModeling();
	modelingGubun = 1;

	showNewKEGGInput("hide");
	showNewScriptInput("hide");
	showNewReactionInput("show");
}

function showModelingByScript()
{
	//showModeling();
	modelingGubun = 2;
	
	showNewKEGGInput("hide");
	showNewScriptInput("show");
	showNewReactionInput("hide");
}

function showModelingFromKegg()
{
	//showModeling();
	modelingGubun = 3;
	
	showNewScriptInput("hide");
	showNewReactionInput("hide");
	showNewKEGGInput("show");
}
//Implemented By Ganesh Based on Reviewer Requirementss
    function geneknockout()
    {
    var a=0;
    var b=0;
    var c=0;
     if(byId("gk").checked==true)
     {
        a=1;
     }
     if(byId("ridk").checked==true)
     {
        b=1;
     }
     if(byId("rnk").checked==true)
     {
        c=1;
     }
     
    var keywordBody = byId("candidateKnockTableBody");
	  	deleteRowFromTable(keywordBody);
	  	var newRow = document.createElement("tr");
  		var newCell = document.createElement("td");
  		newCell.innerHTML = "Loading......<img src='images/indicator.gif'>";
  		newRow.appendChild(newCell);
  		keywordBody.appendChild(newRow);
		
	  	var sendData = "action=geneknockout";
	  	var partialKey = "";
  		partialKey = byId("knockoutsearchKey").value;
	  
	  	//if(partialKey.length < 2 && byId("knockoutPathwayListCombo").value == 'All')
	  	if(partialKey.length < 2)
  			return;
      
	  //	sendData = sendData + "&category=Genetic"
	  	sendData = sendData + "&keyword="+partialKey;
	  	//sendData = sendData + "&pathway="+byId("knockoutPathwayListCombo").value;
	  	sendData=sendData+"&pid="+projectIdx+"&a="+a+"&b="+b+"&c="+c;
	  	//alert(sendData);
	  	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {             
	            	printKnockoutKeywordList1(xmlHttp);
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("CODE: 3014");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    	
	    xmlHttp.send(sendData);
	  	//End
	  
    }

	function searchKeywordOfKnockout()
	{
	   
		var keywordBody = byId("candidateKnockTableBody");
	  	deleteRowFromTable(keywordBody);
	  	var newRow = document.createElement("tr");
  		var newCell = document.createElement("td");
  		newCell.innerHTML = "Loading......<img src='images/indicator.gif'>";
  		newRow.appendChild(newCell);
  		keywordBody.appendChild(newRow);
		
	  	var sendData = "action=searchKeyword";
	  	var partialKey = "";
  		partialKey = byId("knockoutsearchKey").value;
	  
	  	//if(partialKey.length < 2 && byId("knockoutPathwayListCombo").value == 'All')
	  	if(partialKey.length < 2)
  			return;

	  	sendData = sendData + "&category=Genetic"
	  	sendData = sendData + "&keyword="+partialKey;
	  	sendData = sendData + "&pathway="+byId("knockoutPathwayListCombo").value;
	  	sendData=sendData+"&pid="+projectIdx;
	  	//alert(sendData);
	  	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = isTrueOrFalse;                       
	
	   	var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {             
	            	printKnockoutKeywordList(xmlHttp);
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("CODE: 3014");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    	
	    xmlHttp.send(sendData);
	  	//End
	  
  	}
  	function printKnockoutKeywordList1(xmlHttp)
  	{
  	 var xmlData = xmlHttp.responseXML;
  		var rNodes = xmlData.getElementsByTagName("rname");
	  	var rGubun = xmlData.getElementsByTagName("rgubun");
	  	var rNames = xmlData.getElementsByTagName("roname");
	  	var rDescs = xmlData.getElementsByTagName("rgenename");
	  	var rgenes = xmlData.getElementsByTagName("rgenes");
	  	var rsub = xmlData.getElementsByTagName("rsub");
	  	var rcount = xmlData.getElementsByTagName("rcount");
	  	var co=rcount[0].childNodes[0].nodeValue;
	     
	  	
	  	var keywordBody = byId("candidateKnockTableBody");
	  	var i=0;
	  	for(i=keywordBody.rows.length-1; i>=0; i--)
	  		keywordBody.deleteRow(i);
	  	var k = 0;
	  	for(i=0; i<rNodes.length; i++)
	  	{
	  		var name = rNodes[i].childNodes[0].nodeValue;
	  		var gubun = rGubun[i].childNodes[0].nodeValue;
	  		var officialname = rNames[i].childNodes[0].nodeValue;
	  		var description = rDescs[i].childNodes[0].nodeValue;
	  		var genes=rgenes[i].childNodes[0].nodeValue;
	  		var subsystem=rsub[i].childNodes[0].nodeValue;
	  		var newRow = document.createElement("tr");
	  		var newCell1 = document.createElement("td");
	  		var newCell2 = document.createElement("td");
	  		var newCell3 = document.createElement("td");
			var newCell4 = document.createElement("td");
			var newCell5 = document.createElement("td");
			var newCell6 = document.createElement("td");
			var newCell7 = document.createElement("td");
	  		newCell1.width = '20px';
	  		newCell2.width = '80px';
	  	    newCell3.width = '150px';
	  		newCell4.width = '130px';
	  		newCell5.width = '250px';
	  		newCell6.width = '200px';
	  		newCell7.width = '50px';
	  		
	  		
			newRow.id = name;
			newCell1.innerHTML = i+1;
	  		var val=i;
	  		newCell2.innerHTML = genes;
	  		newCell3.innerHTML = name;
	  		newCell4.innerHTML = description;
	  		newCell5.innerHTML = officialname
	  		newCell6.innerHTML =subsystem;
	  		
	  		if(isExistKnockout(name))
	  			newCell7.innerHTML = "<input type=checkbox id='candidate"+i+"' checked onClick='addOrDelknockout1(\""+val+"\",\""+name+"\", \""+gubun+"\");'>";
	  		else
	  			newCell7.innerHTML = "<input type=checkbox id='candidate"+i+"' onClick='addOrDelknockout1(\""+val+"\",\""+name+"\", \""+gubun+"\");'>";
	  		
	  		newRow.appendChild(newCell1);
	  		newRow.appendChild(newCell2);
	  		newRow.appendChild(newCell3);
	  		newRow.appendChild(newCell4);
	  		newRow.appendChild(newCell5);
	  		newRow.appendChild(newCell6);
	  		newRow.appendChild(newCell7);
	  		
	  		
	  		if((k % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((k % 2) == 1) newRow.bgColor = "#eeeeee";
	  		
	  		keywordBody.appendChild(newRow);
	  		k++;
	  		//byId("searchConditionResultPane").style.visibility = "visible";
	  	}
  	 
  	
  	}
  	function printKnockoutKeywordList(xmlHttp)
  	{
  		var xmlData = xmlHttp.responseXML;
  		var rNodes = xmlData.getElementsByTagName("rname");
	  	var rGubun = xmlData.getElementsByTagName("rgubun");
	  	var rNames = xmlData.getElementsByTagName("roname");
	  	var rDescs = xmlData.getElementsByTagName("rdescription");
	  	
	  	
	  	var keywordBody = byId("candidateKnockTableBody");
	  	var i=0;
	  	for(i=keywordBody.rows.length-1; i>=0; i--)
	  		keywordBody.deleteRow(i);
	  	var k = 0;
	  	for(i=0; i<rNodes.length; i++)
	  	{
	  		var name = rNodes[i].childNodes[0].nodeValue;
	  		var gubun = rGubun[i].childNodes[0].nodeValue;
	  		var officialname = rNames[i].childNodes[0].nodeValue;
	  		var description = rDescs[i].childNodes[0].nodeValue;
	  		var newRow = document.createElement("tr");
	  		var newCell1 = document.createElement("td");
	  		var newCell2 = document.createElement("td");
	  		var newCell3 = document.createElement("td");
			var newCell4 = document.createElement("td");
			var newCell5 = document.createElement("td");
	  		newCell1.width = '20px';
	  		newCell2.width = '80px';
	  		newCell3.width = '250px';
	  		newCell4.width = '300px';
	  		newCell5.width = '50px';
	  		
			newRow.id = name;
			newCell1.innerHTML = i+1;
	  		newCell2.innerHTML = name;
	  		newCell3.innerHTML = officialname;
	  		newCell4.innerHTML = description;
	  		if(isExistKnockout(name))
	  			newCell5.innerHTML = "<input type=checkbox id='candidate"+k+"' checked onClick='addOrDelknockout(\""+k+"\",\""+name+"\", \""+gubun+"\");'>";
	  		else
	  			newCell5.innerHTML = "<input type=checkbox id='candidate"+k+"' onClick='addOrDelknockout(\""+k+"\",\""+name+"\", \""+gubun+"\");'>";
	  		
	  		newRow.appendChild(newCell1);
	  		newRow.appendChild(newCell2);
	  		newRow.appendChild(newCell3);
	  		newRow.appendChild(newCell4);
	  		newRow.appendChild(newCell5);
	  		
	  		if((k % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((k % 2) == 1) newRow.bgColor = "#eeeeee";
	  		
	  		keywordBody.appendChild(newRow);
	  		k++;
	  		//byId("searchConditionResultPane").style.visibility = "visible";
	  	}
  	}
  	
  	function addOrDelknockout1(idx, cname, gubun)
  	{
  		
  		if(idx < 0)
  		{
  		 return;
  		 }
  		if(byId("candidate"+idx).checked)
  		{
  		    
  			saveKnockout(cname);
  		}else
  		{
  		  
  			deleteKnockout(cname);
  		}
  	}
  	function addOrDelknockout(idx, cname, gubun)
  	{
  		
  		if(idx < 0)
  		{
  		 return;
  		 }
  		if(byId("candidateChk"+idx).checked)
  		{
  		   
  			saveKnockout(cname);
  		}else
  		{
  		  
  			deleteKnockout(cname);
  		}
  	}
  	
  	function isExistKnockout(name)
  	{
  		for(var i=0; i<knockoutList.length; i++)
  		{ 
  			var colSplit = knockoutList[i].split("<T>");
  			if(colSplit[0] == name) return true;
  		}
  		return false;
  	}
  	
  	function getKnockoutList()
  	{
  		var conditionBody = byId("newknockoutTableBody");
	  	deleteRowFromTable(conditionBody);

	  	var newRow = document.createElement("tr");
  		var newCell = document.createElement("td");
  		newCell.innerHTML = "Loading......<img src='images/indicator.gif'>";
  		newRow.appendChild(newCell);
  		conditionBody.appendChild(newRow);
  		
  		
  		var sendData = "action=getKnockout";
  		sendData = sendData + "&pid="+projectIdx;
  		
	   	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = true;                       
		var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {
	            	//alert("complete");
	            	knockoutList = xmlHttp.responseText.split("<N>");
	            	printKnockoutList();  
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("CODE: 3015");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function getKnockoutListForPathway()
  	{
  		var sendData = "action=getKnockout";
  		sendData = sendData + "&pid="+projectIdx;
  		
	   	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = true;                       
		var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {
	            	knockoutList = xmlHttp.responseText.split("<N>");
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("CODE: 3033");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function printKnockoutList()
  	{
  		var mTable = byId("newknockoutTableBody");
			deleteRowFromTable(mTable);
			
  		for(var i=0; i<knockoutList.length-1; i++)
  		{
  			var newRow = document.createElement("tr");
  			
  			var colSplit = knockoutList[i].split("<T>");
  			
 			var newCell = [];
			for(var k=0; k<6; k++){
				newCell.push(document.createElement("td"));
			}
			newCell[0].innerHTML = i+1;
			newCell[1].innerHTML = colSplit[0];
			newCell[2].innerHTML = colSplit[1];
			newCell[3].innerHTML = colSplit[2];
			newCell[4].innerHTML = colSplit[3];
			newCell[5].innerHTML = "[<a href='javascript:deleteKnockoutFromList("+i+");'>Del</a>]";
  			newCell[5].width = "60px";
			for(var k=0; k<6; k++){
					newRow.appendChild(newCell[k]);
			}
			if((i % 2) == 0) newRow.bgColor = "#FFFFFF";
			if((i % 2) == 1) newRow.bgColor = "#eeeeee";
			
			mTable.appendChild(newRow);
  		}
  	}
  	
  	function saveKnockout(cname)
  	{
  		var sendData = "action=saveKnockout";
  		sendData = sendData + "&pid="+projectIdx+"&cname="+cname;
  		
	   	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = isTrueOrFalse;                       
		//alert(sendData);
	   	var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {
	            		if(byId("ModelingPane2").style.visibility == 'visible')
				  			getKnockoutList();
				  		else if(byId("ReactionsPane").style.visibility == 'visible'){
				  			getKnockoutListForPathway();
				  			getPathwayInformation(previousPathwayName,previousCategory);
				  		}
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("CODE: 3016");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function deleteKnockoutFromList(idx)
  	{
  		deleteKnockout(getKnockoutName(idx));
  	}
  	
  	function deleteKnockout(name)
  	{
  		var sendData = "action=deleteKnockout";
  		sendData = sendData + "&pid="+projectIdx+"&cname="+name;
  		
	   	var getPost = "POST";                      
	   	var urlFileAppl = "AnalysisServlet";
	   	var trueFalse = isTrueOrFalse;                       
		var xmlHttp = newXMLHttpRequest();
	  		xmlHttp.open(getPost, urlFileAppl, trueFalse); 
	    xmlHttp.onreadystatechange = function() {    
	        if (xmlHttp.readyState == 4) {              
	            if (xmlHttp.status == 200) {
	            	//knockoutList.splice(idx,1);
			  		if(byId("ModelingPane2").style.visibility == 'visible')
			  			getKnockoutList();
			  		else if(byId("ReactionsPane").style.visibility == 'visible'){
			  			getKnockoutListForPathway();
			  			getPathwayInformation(previousPathwayName,previousCategory);
			  		}
	            } else {
	                exceptionControl(xmlHttp);          
	                alert("CODE: 3017");
	            }
	        }
	    }
	    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	    xmlHttp.setRequestHeader("Content-Type", conType);
	    xmlHttp.send(sendData);
  	}
  	
  	function getKnockoutName(idx)
  	{
   		var colSplit = knockoutList[idx].split("<T>");
   		return colSplit[0];
  	}
  	
  	function clearScript()
  	{
  		byId("reactionScriptLine").value = "";
  	}
  	function changeStrainDescription()
  	{
  		byId('projectSaveBtn').disabled = false;
  	}
