var orderVisit = 0;
function gotBlur(obj) 
{
	if((oldVal != obj.value) || (obj.ISCHANGED == "true"))
	{
		obj.ISCHANGED = "true"; 
	}
}

function gotFocus(column)
{
	objCur=column.name; 
	oldVal=column.value; 
}

function addSupply()
{
	//alert("So in js........."); 

	var srNo = 1;
	var selectedItemHtml = "";
	var saleOrder = "";
	var lineNo = "";
	var itemCode = "";
	var siteCode = "";
	var qtyReqd = "";
	var lotNo = "";
	var lotSl = "";
	var locCode = "";
	var tranSer = "";
	var tranId = "";
	var refLineNo = "";
	var supply = "";
	var availableSupply = "";
	var allocQty = "";
	var totalAllocQty=0;
	//alert("maxId["+maxId+"]");
	var itemCnt =0;
	var tempdbID=0;
	var tempdbIDArray = new Array();
	for( dbID = 1; dbID <= maxId; dbID++)
	{
		//alert("dbID["+dbID+"]");
		if(( document.getElementById("Detail4."+dbID+".selectbox")!=null && document.getElementById("Detail4."+dbID+".selectbox").checked ) &&  (  document.getElementById("Detail4." +dbID+".tran_ser") != null && document.getElementById("Detail4." +dbID+".tran_ser").value == "Stock" ))
		//if( document.getElementById("Detail4."+dbID+".selectbox")!=null && document.getElementById("Detail4."+dbID+".selectbox").checked)	
		{
			//alert("inside if-------------dbID["+dbID+"]-----");
			// tempdbID = dbID ;
			tempdbIDArray[tempdbIDArray.length]  =  dbID;
			
			itemCnt++;
			allocQty=0;
			saleOrder = document.getElementById("Detail4." +dbID+".sale_order").value;
			lineNo = document.getElementById("Detail4." +dbID+".line_no").value;
			itemCode = document.getElementById("Detail4." +dbID+".item_code").value ;
			qtyReqd = document.getElementById("Detail4." +dbID+".qty_reqd").value ;
			siteCode = document.getElementById("Detail4." +dbID+".site_code").value;
			lotNo =  document.getElementById("Detail4." +dbID+".lot_no").value;
			lotSl =  document.getElementById("Detail4." +dbID+".lot_sl").value;
			locCode =  document.getElementById("Detail4." +dbID+".loc_code").value;
			tranSer =  document.getElementById("Detail4." +dbID+".tran_ser").value;
			tranId =  document.getElementById("Detail4." +dbID+".tran_id").value;
			refLineNo =  document.getElementById("Detail4." +dbID+".ref_line_no").value;
			supply =  document.getElementById("Detail4." +dbID+".supply").value;
			//availableSupply =  document.getElementById("sample_item." + dbID+ ".available_supply").value;
			allocQty =  document.getElementById("Detail4." +dbID+".alloc_qty").value;

			//alert("test new availableSupply ["+availableSupply+"]===[supply]["+supply+"]---allocQty["+allocQty+"]");
			availableSupply = eval(supply) - eval(allocQty);
			
			//alert("test after availableSupply ["+availableSupply+"]allocQty["+allocQty+"]");
			//alert("supply["+supply+"]allocQty["+allocQty+"]availableSupply["+availableSupply+"]saleOrder["+saleOrder+"]");

			if(saleOrder == "" && lineNo == "")
			{
				//alert("Please select a sale order ");
				return false;
			}

			if( tranSer == "Stock" && itemCode != "" && allocQty == 0 )
			{
				//alert("Please enter a quantity for allocation ");
				return false;
			}

			if(( eval(allocQty) > eval(supply) )  &&  tranSer == "Stock" )
			{
				//alert("Quantity to be allocated is greater than supply quantity. Please enter less quantity to be allocated.");
				return false;
			}

			//srNo=dbID;

			selectedItemHtml = selectedItemHtml + 
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".sale_order' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".sale_order' value='" + saleOrder + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".line_no' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".line_no' value='" + lineNo + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".item_code' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".item_code' value='" + itemCode + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".qty_reqd' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".qty_reqd' value='" + qtyReqd + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".site_code' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".site_code' value='" + siteCode + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".lot_no' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".lot_no' value='" + lotNo + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".lot_sl' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".lot_sl' value='" + lotSl + "'></INPUT>" +
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".loc_code' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".loc_code' value='" + locCode + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".tran_ser' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".tran_ser' value='" + tranSer + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".tran_id' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".tran_id' value='" + tranId + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".ref_line_no' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".ref_line_no' value='" + refLineNo + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".supply' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".supply' value='" + supply + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".available_supply' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".available_supply' value='" + availableSupply + "'></INPUT>"+
			"<INPUT TYPE='hidden' name='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".alloc_qty' id='Detail4." +saleOrder+"."+lineNo+"."+dbID+ ".alloc_qty' value='" + allocQty + "'></INPUT>";

			// srNo = srNo + 1;
		}
	}
	//quantity validation
	{ //start


		//alert("quantity validation");
		var value = "";
		var tr = document.getElementsByTagName("tr");
		//var count = tr.length - 1 ;
		var count = 1000;
		var j=1;
		var qtyReqdFlag = false;
		var singleQtyReqd =0;		//alert("count["+count+"]");
		//alert("value["+value+"]")
		for(i = 1; i < count; i++)
		{  
			//if( document.getElementById("Detail4."+i+".sale_order") != null )
			if(	document.getElementById("Detail4."+i+".selectbox")!=null  &&  document.getElementById("Detail4."+i+".selectbox").checked )	
			{
				if( qtyReqdFlag == false)
				{
					qtyReqdFlag = true;
					singleQtyReqd = document.getElementById("Detail4."+i+".qty_reqd").value;
				}
				//alert("i["+i+"]");
				value = document.getElementById("tr."+i);
				//alert("value["+value+"]");
				var singleAllocQty = document.getElementById("Detail4."+i+".alloc_qty").value;
				totalAllocQty = eval(totalAllocQty)  +  eval(singleAllocQty) ;
			}
		}
		alert("singleQtyReqd["+singleQtyReqd+"]totalAllocQty["+totalAllocQty+"]::");

		totalAllocQty = Math.round(totalAllocQty*1000000)/1000000 ;
		
	} //end

	//alert("selectedItemHtml["+selectedItemHtml+"]");

	if( selectedItemHtml == "" )
	{
		alert("No Selection Made ! \nPlease Select an sale order !");
	}
	else if(  totalAllocQty != singleQtyReqd )
	{
		alert("Quantity required is mismatch with quantity allocated...!");
	}
	else	
	{
		//alert("displayItem opener called ---itemCnt["+itemCnt+"]tempdbID["+tempdbID+"]tempdbIDArray["+tempdbIDArray+"]["+selectedItemHtml+"]");

		for( var updDivCtr = 0;  updDivCtr <= tempdbIDArray.length - 1 ;  updDivCtr++ )
		{
			var tempdbID2 = tempdbIDArray[updDivCtr];
			//alert("updDivCtr["+updDivCtr+"]::tempdbID2["+tempdbID2+"]");
			window.opener.displayItem( selectedItemHtml, tempdbID2  );    // itemCnt
		}
		window.close();
	}



}

function finishAction( value )
{  
	//alert("call finishAction");

	document.getElementById("action").value = value;

	//alert("call MRPWizardSaveSample");

	var samplItem = [];
	var method = "post";
	var path="/ibase/webitm/jsp/MRPWizardSaveSample.jsp";



	//alert("test........"); 

	var srNo = 1;
	var selectedSampleItem = "";
	var saleOrder = "";
	var lineNo = "";
	var itemCode = "";
	var siteCode = "";
	var qtyReqd = "";
	var lotNo = "";
	var lotSl = "";
	var locCode = "";
	var tranSer = "";
	var tranId = "";
	var refLineNo = "";
	var supply = "";
	var availableSupply = "";
	var allocQty = "";
	var maxId = 5;
	var div1 = "";
	//alert("maxId["+maxId+"]");
	var itemCnt =0;
	var itemCodeDescr="";
	var finishArray = new Array();
	var flagforSO = false;
	var finishArrayKey="";

	var itemCodeHdr="";
	var parentItem="";
	
	for( var dbIDOut = 1; dbIDOut <= maxId; dbIDOut++)
	{
		//alert("first for ckeck so------------");
		if(document.getElementById("Detail2."+dbIDOut+".selectbox")!=null && document.getElementById("Detail2."+dbIDOut+".selectbox").checked )
		{
			finishArrayKey="";
			saleOrder = document.getElementById("Detail2."+dbIDOut+".sale_order").value.trim();
			lineNo = document.getElementById("Detail2."+dbIDOut+".line_no").value.trim();
			itemCodeHdr = document.getElementById("Detail2."+dbIDOut+".item_code").value.trim();

			//alert("@@@@@@@@@@@@ div["+div1+"]["+saleOrder+"]["+lineNo+"]itemCodeHdr["+itemCodeHdr+"]");
			
			finishArrayKey = saleOrder+""+lineNo;
			index = finishArray.indexOf(finishArrayKey);

			//alert("finishArrayKey["+finishArrayKey+"]::::::::finishArray["+finishArray+"]");
			if(  index == null || index == "" || index < 0 ||  index == -1  ) 
			{
				//alert("addd.........");
				flagforSO = false;
				finishArray[finishArrayKey.length] = finishArrayKey;
			}
			else
			{
				flagforSO = true;
			}

			//alert("flagforSO["+flagforSO+"]");
			if( flagforSO == false )
			{
				for(var dbID = 1; dbID <= maxId; dbID++)
				{	
					alert("inside second for -----------");

					alert(document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".sale_order"));

					if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".sale_order") != null)
					{
						//alert("@@@@@@@@ inside second  if for div...........");
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".sale_order") != null)
						{
							saleOrder = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".sale_order").value;
							alert("saleOrder::::"+saleOrder);
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".line_no") != null)
						{
							lineNo = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".line_no").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code") != null)
						{
							itemCode = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code").value;
						}

						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code_descr") != null)
						{
							itemCodeDescr = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code_descr").value;
						}

						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".site_code") != null)
						{				
							siteCode = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".site_code").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".qty_reqd") != null)
						{
							qtyReqd = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".qty_reqd").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_no") != null)
						{
							lotNo = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_no").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_sl") != null)
						{
							lotSl = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_sl").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".loc_code") != null)
						{
							locCode = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".loc_code").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_ser") != null)
						{
							tranSer = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_ser").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_id") != null)
						{
							tranId = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_id").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".ref_line_no") != null)
						{
							refLineNo = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".ref_line_no").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".supply") != null)
						{	
							supply = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".supply").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".available_supply") != null)
						{
							availableSupply = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".available_supply").value;
						}
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".alloc_qty") != null)
						{
							allocQty = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".alloc_qty").value;
						}
						
						if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".parent_item") != null)
						{
							parentItem = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".parent_item").value;
						}

						//alert("div1:dbID["+dbID+"]["+dbIDOut+"]["+saleOrder+"]["+lineNo+"]["+qtyReqd+"]["+siteCode+"]["+itemCode+"]["+lotNo+"]["+lotSl+"]["+locCode+"]["+tranSer+"]["+tranId+"]["+refLineNo+"]["+allocQty+"]");

						// alert("for item code ["+itemCode+"]itemCodeHdr["+itemCodeHdr+"]parentItem["+parentItem+"]");
						
						/*
						if( itemCode!= null && itemCodeHdr != null &&  itemCode.trim() ==  itemCodeHdr.trim() )
						{
							//itemCode = itemCode;
							alert("1");
						}
						else if( parentItem != null && itemCodeHdr != null &&  parentItem.trim() ==  itemCodeHdr.trim() )
						{
							itemCode =  parentItem;
							alert("2");
						}
						 */
						
						//alert("for allocation item code ["+itemCode+"]");
						
						//selectedSampleItem = selectedSampleItem +div1;
						selectedSampleItem = selectedSampleItem + "<Detail4  domID='" + dbID + "'>" +	
						"<sale_order>" + saleOrder + "</sale_order><line_no>" + lineNo + "</line_no><qty_reqd>" + qtyReqd + "</qty_reqd>" +
						"<site_code>" + siteCode + "</site_code><item_code>" + itemCode + "</item_code>" +
						"<item_code_descr>" + itemCodeDescr + "</item_code_descr>" +
						"<lot_no>" + lotNo + "</lot_no>" +
						"<lot_sl>" + lotSl + "</lot_sl><loc_code>" + locCode + "</loc_code><tran_ser>" + tranSer + "</tran_ser>" +
						"<tran_id>" + tranId + "</tran_id><ref_line_no>" + refLineNo + "</ref_line_no>" +
						"<supply>" + supply + "</supply><available_supply>" + availableSupply + "</available_supply><alloc_qty>" + allocQty + "</alloc_qty>" +
						"</Detail4>";

						//	alert("selectedSampleItem inside"+saleOrder+"."+lineNo+"."+dbID+"["+selectedSampleItem+"]");
					}


				}
			}
			//	alert("selectedSampleItem outside"+saleOrder+"."+lineNo+"."+dbID+"["+selectedSampleItem+"]");
		}
	}

//	alert("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ for save selectedSampleItem["+selectedSampleItem+"]@@@@@@@@@@@@@@@@@@@@@");
	var saleOrderArray = new Array();
	var finishArrayKey = "";
	var index2 = "";
	var flagSO="";
	var deSelectedFlag =  false;
	var selectedFlag =  false;
	var issError = false;
	var sourceSupply="";
	for( var dbIDOut2 = 1; dbIDOut2 <= maxId; dbIDOut2++)
	{
		
		saleOrder="";
	
		//alert("first for ckeck for selection------------");
		if(document.getElementById("Detail2."+dbIDOut2+".sale_order") != null )
		{
			//alert("chk for so[ "+ dbIDOut2 +"]SO["+document.getElementById("Detail2."+dbIDOut2+".sale_order").value+"]");
			saleOrder = document.getElementById("Detail2."+dbIDOut2+".sale_order").value.trim();
			
			index2 = saleOrderArray.indexOf(saleOrder);
			//alert("index2["+index2+"]");
			if(  index2 == null || index2 == "" || index2 < 0 ||  index2 == -1  ) 
			{
				flagSO = false;
				saleOrderArray[saleOrderArray.length] = saleOrder;
			}
			else
			{
				flagSO = true;
			}
			
			//alert("flagSO["+flagSO+"]");
			if( flagSO == false  && saleOrder != null )
			{
				
				 selectedFlag == false;
				 deSelectedFlag == false; 
				 
				for( var dbIDIn2 = 1; dbIDIn2 <= maxId; dbIDIn2++)
				{
					sourceSupply = "";
					if( document.getElementById("Detail2."+dbIDIn2+".source_supply") != null)
					{
						sourceSupply = document.getElementById("Detail2."+dbIDIn2+".source_supply").value.trim();
					}
					else
					{
						sourceSupply = "";
					}
					
					//alert("sale order["+document.getElementById("Detail2."+dbIDIn2+".sale_order").value+"]:sourceSupply["+sourceSupply+"]");
					
					if(  document.getElementById("Detail2."+dbIDIn2+".sale_order") != null && saleOrder == document.getElementById("Detail2."+dbIDIn2+".sale_order").value.trim()  && ("S" == sourceSupply || "PS" == sourceSupply || "SP" == sourceSupply ) )
					{
						
						//alert("getStock....");
						if( document.getElementById("Detail2."+dbIDIn2+".selectbox").checked == true )
					    {
							selectedFlag = true;
					    }
						else
						{
							deSelectedFlag = true;	
						}
						//alert( "inside for ["+dbIDIn2+"] selectedFlag["+selectedFlag+"]:::deSelectedFlag["+deSelectedFlag+"]");
					}
				}
				
				//alert("@@@@@@@@@ out side :::::selectedFlag["+selectedFlag+"]:::deSelectedFlag["+deSelectedFlag+"]");
				if( selectedFlag == true && deSelectedFlag == true )
				{
					issError = true;
					//alert(" please select all stock record of "+saleOrder+" for allocation...");
				}
			}
		}

	}

		//samplItem["SALE_ORDER"] = saleOrder;
		//samplItem["LINE_NO"] = lineNo;
		//samplItem["QTY_REQD"] = qtyReqd;
		//samplItem["div_data"] = div1;
		//alert("call MRPWizardSaveSample["+selectedSampleItem+"]");
	//alert("issError["+issError+"]");
	if( issError == false)
	{
		samplItem["SAVE_SAMPLE_DATA"] = "<Root>" + selectedSampleItem + "</Root>";
		post_to_url(path, samplItem, method);
	}
	else
	{
		alert(" please select all stock record of selected saleOrder for allocation...");
		return false;
	}
		//alert("end finishAction");
	}



	function setActionVal( value )
	{  

		document.getElementById("action").value = value;
	}
	/*Added By Shahu Mali on 10-01-13 */
	function checkDate(field ,flag)
	{   
		// alert("checkDate>>"+field.value);
		var currDateVal = new Date();
		//   alert(" currDate==>"+currDateVal);
		//var fieldValue = field.value.trim().split('/');
		var fieldValue = field.value.split('/');
		var firstDate=new Date();
		var eventDate = new Date(firstDate.setFullYear(currDateVal.getFullYear().toString().substring(0,2)+fieldValue[2],(fieldValue[1] - 1 ),fieldValue[0]));
		// alert(" eventDate==>"+eventDate);
		var finishButton = document.getElementById("ActFinish");  
		var nextButton = document.getElementById("ActNext"); 
		if(eventDate - currDateVal > 0)
		{

			if(flag==1)
			{	
				alert("ERROR::CANNOT CREATE FUTURE EVENT ");
				finishButton.style.disabled = false;
				return true;
			}
			else if(flag==2)
			{
				alert("ERROR::CANNOT CREATE FUTURE EVENT ");
				nextButton.style.disabled="disabled";
				return true;
			}	
		}
		else
		{
			return false;
		}

	}
	function setCheckedPlace( obj, dbID )
	{
		//alert(" inside check method obj= ["+obj+"] dbID=["+dbID+"]");	
		//alert("obj.value:"+obj.value);
		if( obj.value == 'false' )
		{
			obj.value ='true';
			//orderVisit = orderVisit + 1;
			//obj1 = document.getElementById("Detail2."+dbID+".order_of_visit");
			//obj1.value = orderVisit;
		}
		else 
		{
			obj.value = 'false';
			/*if ( dbID == orderVisit )
		{
			orderVisit = orderVisit - 1;
		}
		obj1 = document.getElementById("Detail2."+dbID+".order_of_visit");*/
			obj1.value = "";
		}
	}
	function setCheckedCustomers(obj,dbId)
	{
		if( obj.value == 'false' )
		{
			obj.value ='true';
		}
		else 
		{
			obj.value = 'false';
			document.getElementById("itemCodes"+dbId).innerHTML = "";
			document.getElementById("teamCodes"+dbId).innerHTML = "";
			document.getElementById("Detail3."+dbId+".order_booked").value = "0";
			document.getElementById("Detail3."+dbId+".meet_summ").value = "";
			document.getElementById("Detail3."+dbId+".oth_participant").value = "";
			document.getElementById("Detail3."+dbId+".remarks").value = "";

		}

	}

	var repeatLocCnt = 0;
	function setRepeatLocChecked( dbId )
	{

		if ( document.getElementById( "Detail2."+dbId+".selectbox").checked == true )
		{
			repeatLocCnt = repeatLocCnt + 1;
			div = document.getElementById("repeatPlacesDiv");
			div.innerHTML = div.innerHTML + "<table id='travelTable2' class ='tableClass_rep' WIDTH='85%' CELLPADDING='1' CELLSPACING='1' ><tr>"+ displayRepeatPlace( dbId )+"</tr></table>" ;
		}
		else
		{
			alert("Place is not selected.");
		}
	}


	function setDrVisit( obj )
	{
		if( obj.value == "Y" ) 
		{
		}
	}
	function setChemVisit( obj )
	{
		if( obj.value == "Y" ) 
		{
		}
	}

	function validatePlace(formNo)
	{}

	function countChecked()
	{
		var chkCount = 0;
		var count = 0;
		count = document.customer_deact_data.elements.length;

		action = document.getElementById("action").value;
		if( action != "previous" )
		{
			for(i = 0; i < count; i++)
			{
				if(document.customer_deact_data.elements[i].type == 'checkbox')
				{
					if(document.customer_deact_data.elements[i].checked == true)
					{chkCount = chkCount + 1;}
				}
			}

			if(chkCount == 0 )
			{
				alert("No Selection Made ! \nPlease select a record !");
				return false;
			}
		}
	}

	function setChecked(obj)
	{
		if( obj.value == 'false' )
		{
			obj.value ='true';
		}
		else 
		{
			obj.value = 'false';
		}

	}

	function selectAlltr()
	{
		//alert("selectAlltr");
		var value = "";
		var tr = document.getElementsByTagName("tr");
		//var count = tr.length - 1 ;

		var count = 1000;
		var j=1;
		//alert("count["+count+"]");
		//alert("value["+value+"]")
		for(i = 1; i < count; i++)
		{  


			if( soursSupply = document.getElementById("Detail4."+i+".source_supply") != null )
			{
				//alert("i["+i+"]");
				value = document.getElementById("tr."+i);
				//alert("value["+value+"]");
				var soursSupply = document.getElementById("Detail4."+i+".source_supply").value;
				var tranSer = document.getElementById("Detail4."+i+".tran_ser").value;

				//alert("soursSupply["+soursSupply+"]");
				if( soursSupply.trim() == "S" || ( tranSer != null && tranSer.trim() == "Stock" ) )
				{
					value.className = "Stock";
				}
				else if( soursSupply.trim() == "P" )
				{
					value.className = "Planned";
					document.getElementById("Detail4."+i+".selectbox").disabled = true ;
					document.getElementById("Detail4."+i+".selectbox").checked = true ;
				}
				else if( soursSupply.trim() == "W" )
				{
					value.className = "WIP";
					document.getElementById("Detail4."+i+".selectbox").disabled = true ;
					document.getElementById("Detail4."+i+".selectbox").checked = true ;
				}

			}

		}
	}


	function selectAllbox()
	{
		var value = "";
		var tr = document.getElementsByTagName("tr");
		var count = tr.length - 1 ;
		//alert("count["+count+"]");
		value = document.getElementById("Detail2.selectAllbox").checked;
		//alert("value["+value+"]")
		for(i = 1; i < count; i++)
		{  
			document.getElementById("Detail2."+i+".selectbox").checked = value;
		}
	}

	function deselectbox()
	{
		//alert("deselectbox called"+ document.getElementById("Detail2.selectAllbox").checked);
		document.getElementById("Detail2.selectAllbox").checked = false;
		//alert("called"+ document.getElementById("Detail2.selectAllbox").checked);
	}

	function validateCust(formNo)
	{
		disableButtons(formNo);
		var chkCount = 0;
		var count = 0;
		count = document.Wizard_Customer.elements.length;

		action = document.getElementById("action").value;
		if( action != "previous"  )
		{
			for(i = 0; i < count; i++)
			{
				if(document.Wizard_Customer.elements[i].type == 'checkbox')
				{
					if(document.Wizard_Customer.elements[i].checked == true)
					{chkCount = chkCount + 1;}
				}
			}
		}

	}
	function validateDoctor(formNo)
	{
		disableButtons(formNo);
		var chkCount = 0;
		var count = 0;
		count = document.Wizard_Customer.elements.length;

		action = document.getElementById("action").value;
		if( action != "previous"  )
		{
			for(i = 0; i < count; i++)
			{
				if(document.Wizard_Customer.elements[i].type == 'checkbox')
				{
					if(document.Wizard_Customer.elements[i].checked == true)
					{chkCount = chkCount + 1;}
				}
			}
			var drVisit;
			var isNonFW;
			if ( document.getElementById("CustomerSelected.1.is_non_fw") != null )
			{
				isNonFW =document.getElementById("CustomerSelected.1.is_non_fw").value;
			}
			if ( document.getElementById("CustomerSelected.1.dr_visit") != null )
			{
				drVisit =document.getElementById("CustomerSelected.1.dr_visit").value;
			}

			if(chkCount == 0 && drVisit =='Y')
			{
				enableButtons(formNo);
				alert("No Selection Made ! \nPlease select a Doctor visited !");         
				return false;
			}
			else if(chkCount == 0 && isNonFW =='Y')
			{
				enableButtons(formNo);
				alert("No Selection Made ! \nPlease select the record!");
				return false;
			}
		}
	}
	function validateChemist(formNo)
	{
		disableButtons(formNo);
		var chkCount = 0;
		var count = 0;
		count = document.Wizard_Customer.elements.length;

		action = document.getElementById("action").value;
		if( action != "previous"  )
		{
			for(i = 0; i < count; i++)
			{
				if(document.Wizard_Customer.elements[i].type == 'checkbox')
				{
					if(document.Wizard_Customer.elements[i].checked == true)
					{chkCount = chkCount + 1;}
				}
			}
			var chemVisit;
			var isNonFW;
			if ( document.getElementById("CustomerSelected.1.is_non_fw") != null )
			{
				isNonFW =document.getElementById("CustomerSelected.1.is_non_fw").value;
			}
			if ( document.getElementById("CustomerSelected.1.chem_visit") != null )
			{
				chemVisit =document.getElementById("CustomerSelected.1.chem_visit").value;
			}
			if(chkCount == 0 && chemVisit =='Y')
			{
				enableButtons(formNo);
				alert("No Selection Made ! \nPlease select a Chemist visited !");
				return false;
			}
			else if(chkCount == 0 && isNonFW =='Y')
			{
				enableButtons(formNo);
				alert("No Selection Made ! \nPlease select the record!");
				return false;
			}
		}
	}

	var DomId = 0;
	var MAXITEMID = 80;

	function callItemJSP( dbID, strgCode, salesPers )
	{
		DomId = dbID;
		var selectedItem = "";
		var eventDate = "";

		document.getElementById("Detail4."+dbID+".selectbox").checked = true;
		document.getElementById("Detail4."+dbID+".selectbox").value = true;

		if ( document.getElementById("Detail4."+dbID+".event_date") != null )
		{
			eventDate =document.getElementById("Detail4."+dbID+".event_date").value;
		}

		if(MAXITEMID > 0)
		{
			for ( i = 1; i <= MAXITEMID; i++ )
			{
				var pitch = "";
				var qty = "";
				var itemCode = "";
				var salesPrdGrp = "";
				if ( document.getElementById("Detail5." + strgCode + i +".briefed_descr") != null )
				{ 
					pitch = document.getElementById("Detail5." + strgCode + i +".briefed_descr").value;
				}	
				if ( document.getElementById("Detail5." + strgCode + i +".quantity") != null )
				{ 
					qty = document.getElementById("Detail5." + strgCode + i +".quantity").value;
				}
				if ( document.getElementById("Detail5." + strgCode + i +".item_code") != null )
				{ 
					itemCode = document.getElementById("Detail5." + strgCode + i +".item_code").value;
				}
				if ( document.getElementById("Detail5." + strgCode + i +".sales_prod_grp") != null )
				{ 
					salesPrdGrp = document.getElementById("Detail5." + strgCode + i +".sales_prod_grp").value;
				}
				if ( ! ( itemCode == "" && salesPrdGrp == "" ) )
				{
					selectedItem = selectedItem + "<strg_item domID='" + i + "'><item_code>" + itemCode + "</item_code><sales_prod_grp>" + salesPrdGrp + "</sales_prod_grp><briefed_descr>" + pitch + "</briefed_descr><quantity>" + qty + "</quantity></strg_item>";

				}

			}

		}

		//var url = '/ibase/webitm/jsp/ITMWizardItems.jsp?SALES_PERS='+salesPers+'&amp;STRG_CODE='+strgCode+'&amp;SELECTED_ITEM=<Root>'+ selectedItem+'</Root>' ;
		var url = '/ibase/webitm/jsp/ITMWizardItems.jsp?SALES_PERS='+salesPers+'&STRG_CODE='+strgCode+'&EVENT_DATE='+eventDate+'&SELECTED_ITEM=<Root>'+ selectedItem+'</Root>' ;
		var win = window.open( url, 'Items', 'toolbar=no,status=YES,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );
	}
	
	function displayItem( updDetail4Div, maxId )
	{
		DomId = maxId
		//alert("DomId["+DomId+"]::::maxId["+maxId+"]");
		//MAXITEMID = maxId;
		var div1 = document.getElementById("sample_item"+DomId);  // DomId
		//alert("div1:DomId["+DomId+"]["+div1+"]");
		//alert("updDetail4Div["+updDetail4Div+"]");
		div1.innerHTML = updDetail4Div;
	}

	var domIDTeam = 0;
	var MAXTEAMID = 80;
	function callTeamJSP( dbID, strgCode, salesPers )
	{
		domIDTeam = dbID;
		var selectedTeam = "";
		var sprsCode ="";
		//Gulzar on 18/06/12
		var workWith = "";

		if ( document.getElementById("Detail1."+dbID+".visited_with_display") != null )
		{
			workWith =document.getElementById("Detail1."+dbID+".visited_with_display").value;
		}
		else if ( document.getElementById("Detail4."+dbID+".visited_with_display") != null )
		{
			workWith =document.getElementById("Detail4."+dbID+".visited_with_display").value;
		}
		//End Gulzar 18/06/12

		if(MAXTEAMID > 0)
		{
			for ( i = 1; i <= MAXTEAMID; i++ )
			{
				if ( document.getElementById("Detail6." + strgCode + i +".sales_pers") != null )
				{ 
					sprsCode = sprsCode + document.getElementById("Detail6." + strgCode + i +".sales_pers").value + ",";
				}

			}
			selectedTeam = sprsCode.substring(0, sprsCode.length-1);
		}
		var url = '/ibase/webitm/jsp/ITMWizardTeam.jsp?SALES_PERS='+salesPers+'&STRG_CODE='+strgCode+'&WORK_WITH='+workWith+'&SELECTED_TEAM='+selectedTeam;
		var win = window.open( url, 'Team', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );
	}
	function Open(dbID) {
		var spCodeWW= document.getElementById('Detail1.'+dbID+'.sales_pers').value;
		if (spCodeWW == null || spCodeWW == "" )
		{
			document.getElementById('fieldactivity_descr' + dbID).style.display = "none";
			alert("No Sales Person Selected");
		}
		else
		{	
			document.getElementById('list_worked_with' + dbID).style.display = "block";
			document.getElementById('view_worked_with' + dbID).innerHTML="<a href=\"javascript:Close('" + dbID + "');\">Close...</a>";
		}
	}

	function Close(dbID) {
		document.getElementById('list_worked_with' + dbID).style.display = "none";
		document.getElementById('view_worked_with' + dbID).innerHTML="<a href=\"javascript:Open('" + dbID + "');\">View Worked With List</a>";
	} 
	function displayWorkedWith( sprsCode, spName, spDisp )
	{
		if (document.getElementById("Detail1..activity_code") != null)
		{
			document.getElementById("list_worked_with").innerHTML = spDisp;

			var manager = spDisp.substring( spDisp.indexOf("(") + 1, spDisp.lastIndexOf(")") );
			document.getElementById("Detail1..visited_with_display").value = manager;

			document.getElementById("list_worked_with").style.display = "block";
		}
	}


	function displayTeam(selectedTeam, maxTeamId )
	{
		//MAXTEAMID = maxTeamId;
		var divTeam = document.getElementById("teamCodes" + domIDTeam);
		divTeam.innerHTML = selectedTeam;
	}
	function deSelectedTeam(selectedTeam, strgCode )
	{
		//MAXTEAMID = maxTeamId;
		var divTeam = document.getElementById("teamCodes" + domIDTeam);
		divTeam.innerHTML = selectedTeam;

		var deselectDomID;

		var count = 0;
		if(MAXTEAMID > 0)
		{
			for ( i = 1; i <= MAXTEAMID; i++ )
			{
				if ( document.getElementById("Detail4." + i +".strg_code") != null && document.getElementById("Detail4." + i +".strg_code").value == strgCode )
				{
					if ( document.getElementById("Detail4." + i +".deselect_team") != null )
					{
						document.getElementById("Detail4." + i +".deselect_team").value = "Y";
					}
				}
			}
		}
	}
//	-------------------------------------------Changed By Vidhya on 08/12/09 [WS89NOV642 | function change for Work team issue] End

	function callActivityTypeJSP( dbID, salesPers )
	{
		var selectedActCode = document.getElementById("Detail1."+dbID+".activity_code").value;
		//Changed By Vidhya on 28/10/09[WS89NOV617 | MOZILLA COMPATIBILITY] Start
		//var url = '/ibase/webitm/jsp/ITMWizardActitvityCode.jsp?SALES_PERS='+salesPers+'&amp;SELECTED_ACT_CODE='+selectedActCode;
		var url = '/ibase/webitm/jsp/ITMWizardActitvityCode.jsp?SALES_PERS='+salesPers+'&SELECTED_ACT_CODE='+selectedActCode;
		var win = window.open( url, 'ActivityCode', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );

	}
	function displayActCode( actCode, actDescr )
	{
		if (document.getElementById("Detail1..activity_code") != null)
		{
			document.getElementById("Detail1..activity_code").value = actCode;
			document.getElementById("Detail1..activity_descr").value = actDescr;
		}
		else
		{
			document.getElementById("Detail1.1.activity_code").value = actCode;
			document.getElementById("Detail1.1.activity_descr").value = actDescr;	
		}

		//Changed by Dipak on 31/12/12 to disable and enable fnish button based on activity type : START
		var finishButton = document.getElementById("ActFinish");  
		var nextButton = document.getElementById("ActNext");  
		if(actCode != null && (actCode == "CL" || actCode == "SL"  || actCode == "TL" || actCode == "PL" || actCode == "BD" || actCode == "HL" || actCode == "SD" || actCode == "OH" || actCode == "CO" || actCode == "ED"))
		{
			if (finishButton != null && nextButton != null )
			{
				// alert("inside if");  	
				finishButton.disabled = false;
				nextButton.disabled = true;
			}

		}
		else
		{
			if (finishButton != null && nextButton != null )
			{

				finishButton.disabled = true;
				nextButton.disabled = false;
			}

		}
		//Changed by Dipak on 31/12/12 to disable and enable fnish button based on activity type : START
	}


	function callSalesPersListJSP( dbID, loginId )
	{
		var url = '/ibase/webitm/jsp/ITMWizardSalesPersList.jsp?LOGIN_ID='+loginId;
		var win = window.open( url, 'SalesPerson', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );

	}
	function displaySalesPerson( salesPers, spName )
	{
		if (document.getElementById("Detail1..sales_pers") != null)
		{
			document.getElementById("Detail1..sales_pers").value = salesPers;
			document.getElementById("Detail1..sp_name").value = spName;
		}
		else
		{
			document.getElementById("Detail1.1.sales_pers").value = salesPers;
			document.getElementById("Detail1.1.sp_name").value = spName;	
		}
	}


	var offsetxpoint = -60 //Customize x offset of tooltip
	var offsetypoint = 20 //Customize y offset of tooltip
	var ie=document.all
	var ns6=document.getElementById && !document.all
	var enabletip=false
	if (ie||ns6)
		var tipobj = document.getElementById("itemsToolTip");
	var dataEle

	function ietruebody(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

	function ddrivetip(thetext, thecolor ){

		if (ns6||ie){
			tipobj = document.getElementById("itemsToolTip");
			if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
			if (typeof thecolor!="undefined" && thecolor!="" && tipobj != null ) 
				
				tipobj.style.backgroundColor=thecolor

			dataEle = document.getElementById(thetext);
			if( dataEle != null)
			   {
				tipobj.innerHTML = dataEle.innerHTML;
			   }
			if( (  dataEle != null ) && ( dataEle.innerHTML.indexOf("</font>") > 60 || dataEle.innerHTML.indexOf("</FONT>") > 55 ))
				enabletip=true
				return false
		}
	}

	function positiontip(e){
		if (enabletip){
			var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
			var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//			Find out how close the mouse is to the corner of the window
			var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
					var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

							var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//									if the horizontal distance isn't enough to accomodate the width of the context menu
									if (rightedge<tipobj.offsetWidth)
//										move the horizontal position of the menu to the left by it's width
										tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
												else if (curX<leftedge)
													tipobj.style.left="5px"
														else
//															position the horizontal position of the menu where the mouse is positioned
															tipobj.style.left=curX+offsetxpoint+"px"

//															same concept with the vertical position
															if (bottomedge<tipobj.offsetHeight)
																tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
																		else
																			tipobj.style.top=curY+offsetypoint+"px"
																			tipobj.style.visibility="visible"
		}
	}

	function hideddrivetip(){
		if (ns6||ie){
			if( dataEle != null )
			{
				dataEle.style.display = "none";
			}
			enabletip=false
			if( tipobj != null )
			{
			tipobj.style.visibility="hidden"
				tipobj.style.left="-1000px"
					tipobj.style.backgroundColor=''
						tipobj.style.width=''
			}
		}
	}

	document.onmousemove=positiontip

//	------------------------------------------------------------------------------------------------------------------

	function isNumberKey(e)
	{
		//alert("isNumberKey called...");
		var unicode = e.charCode ? e.charCode : e.keyCode;
		if ((unicode == 8) || (unicode == 9) || (unicode > 47 && unicode < 58)
			|| (unicode == 37) || (unicode == 46) || (unicode == 39)
			|| (unicode == 115) || (unicode == 121) || (unicode == 117)) {
		return true;
	} 
	else 
	{
		window.alert("This field accepts only Numbers");
		return false;
	}
	}
	
	function numbersonly(myfield, e, dec)
	{
		var key;
		var keychar;

		if ( window.event )
		{
			key = window.event.keyCode;
		}
		else
		{
			return true;
		}

		if( key >= 48 && key <= 57 )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	function goToPage(objName)
	{
		var url =  "E12WizardPage.jsp?OBJ_NAME="+objName;
		window.location.href = url;
	}
//	Changed By Vidhya on 09/12/09[WS89NOV643 | to alert when transaction is saved] END

//	added by rakesh kumar on 22/11/12 to set the order of visit
	function setOrderOfVisit( obj, dbID, formNo )
	{
		if( obj.value == 'false' )
		{
			orderVisit = orderVisit + 1;
			obj1 = document.getElementById("Detail"+formNo+"."+dbID+".order_of_visit");
			obj1.value = orderVisit;
		}
		else 
		{
			if ( dbID == orderVisit )
			{
				orderVisit = orderVisit - 1;
			}
			obj1 = document.getElementById("Detail"+formNo+"."+dbID+".order_of_visit");
			obj1.value = "";
		}
	}

//	ended by rakesh kumar

//	Added By Shahu Mali on 16-MAY-2013 [WS3BFRA007].START

	function callSalesPersJSP( dbID )
	{
		//alert("dbID==>"+dbID);  
		var url = '/ibase/webitm/jsp/ITMWizardAdminSalesPersList.jsp?';
		var win = window.open( url, 'SalesPerson', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );

	}

	function callSupplyItemJSP1( dbID , saleOrder , lineNo , qtyReqd )
	{
		//alert("test callSupplyItemJSP ");
	}

	var DomId = 0;
	var MAXITEMID = 100;
	function callSupplyItemJSP( dbID , saleOrder , lineNo , qtyReqd )
	{
		//alert("calling callSupplyItemJSP");
		DomId = dbID;
		var selectedItem = "";
		var eventDate = "";
		var selectedSampleItem = "";
		var itemCodeDet2="";
		var siteCodeDet2="";
		document.getElementById("Detail2."+dbID+".selectbox").checked = true;
		document.getElementById("Detail2."+dbID+".selectbox").value = true;

		var keyArray = new Array();
		var valueArray = new Array();

		var saleOrder2="";
		var lineNo2="";


		var saleOrderDet2 = "";
		var lineNoDet2 = "";
		var itemCodeDescr1 = "";


		itemCodeDet2 = document.getElementById("Detail2."+dbID+".item_code").value.trim().trim();
		siteCodeDet2 = document.getElementById("Detail2."+dbID+".site_code").value.trim().trim();

		saleOrderDet2 = document.getElementById("Detail2."+dbID+".sale_order").value.trim();
		lineNoDet2 = document.getElementById("Detail2."+dbID+".line_no").value.trim();
		itemCodeDescr1 = document.getElementById("Detail2."+dbID+".item_code_descr").value;

		//alert("MAXITEMID["+MAXITEMID+"]dbID["+dbID+"]");

		if(MAXITEMID > 0)
		{
			//var domID = 1;

			//alert("inside max");


//			for( var dbIDout=1; dbIDout <= MAXITEMID; dbIDout++ )
			{
//				saleOrder2="";
				saleOrder2 = saleOrderDet2;
				lineNo2 = lineNoDet2;
//				lineNo2="";
//				if( document.getElementById("Detail2."+dbIDout+".sale_order") != null )
//				{
//					saleOrder2 = document.getElementById("Detail2."+dbIDout+".sale_order").value.trim();
//				}
//				if( document.getElementById("Detail2."+dbIDout+".line_no") != null )
//				{
//					lineNo2 = document.getElementById("Detail2."+dbIDout+".line_no").value.trim();
//				}

				/*	if( document.getElementById("Detail2."+dbIDout+".site_code") != null )
			{
				siteCode1 = document.getElementById("Detail2."+dbIDout+".site_code").value.trim();
			}
			if( document.getElementById("Detail2."+dbIDout+".item_code") != null )
			{
				itemCode1 = document.getElementById("Detail2."+dbIDout+".item_code").value.trim();
			}
			if( document.getElementById("Detail2."+dbIDout+".item_code_descr") != null )
			{
				itemCodeDescr = document.getElementById("Detail2."+dbIDout+".item_code_descr").value.trim();
			}
				 */	//alert("@@@@@dbIDout["+dbIDout+"]saleOrder2["+saleOrder2+"]lineNo2["+lineNo2+"]");			
				for ( i = 1; i <= MAXITEMID; i++ )
				{
					var siteCode = "";
					var itemCode = "";
					var lotNo = "";
					var lotSl = "";
					var locCode = "";
					var tranSer = "";
					var tranId = "";
					var refLineNo = "";
					var supply=0;
					var allocQty=0;
					var availableSupply=0;
					var index="";
					var tempQty = 0;
					var parentItem="";
					//alert("@@@@@977111saleOrder2["+saleOrder2+"."+lineNo2+"."+i+".");
					//alert("test977:[Detail4."+saleOrder2+"."+lineNo2+"."+i+".site_code]");
					//alert("test977:"+ document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".site_code"));
					siteCode="";
					itemCode="";
					allocQty=0;
					parentItem="";
					//alert("i["+i+"]"+ document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".site_code"));
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".site_code") != null )
					{
						siteCode =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".site_code").value.trim();
						//	alert("test555555"+saleOrder2+"]lineNo2["+lineNo2+"]site code["+siteCode+"]");
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".item_code") != null )
					{

						itemCode =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".item_code").value.trim();
						//alert("@@@@@@itemCode["+itemCode+"]");
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".lot_no") != null )
					{
						lotNo =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".lot_no").value.trim();
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".lot_sl") != null )
					{
						lotSl =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".lot_sl").value.trim();
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".loc_code") != null )
					{
						locCode =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".loc_code").value.trim();
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".tran_ser") != null )
					{
						tranSer =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".tran_ser").value.trim();
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".tran_id") != null )
					{
						tranId =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".tran_id").value.trim();
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".ref_line_no") != null )
					{
						refLineNo =document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".ref_line_no").value.trim();
					}
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".alloc_qty") != null )
					{
						allocQty = document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".alloc_qty").value;
					}  //parent_item
					if ( document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".parent_item") != null )
					{
						parentItem = document.getElementById("Detail4."+saleOrder2+"."+lineNo2+"."+i+".parent_item").value;
						
					}
					
					//alert("outside itemCode["+itemCode+"]["+itemCodeDet2+"]site code["+siteCode+"]["+siteCodeDet2+"]")
					//alert("outside itemCode["+itemCode+"]["+itemCodeDet2+"]site code["+siteCode+"]["+siteCodeDet2+"]")

					if (( itemCode != null && siteCode != null  &&  tranSer != null  &&  lotNo != null && lotSl != null  && locCode != null ) && ( itemCode != "" && siteCode != "" && lotNo != "" && lotSl != "" && locCode != "" ) && ( ( itemCode == itemCodeDet2 || parentItem == itemCodeDet2 ) &&  siteCode == siteCodeDet2 ))
					{
						//alert("["+i+"]itemCode["+itemCode+"]["+itemCodeDet2+"]site code["+siteCode+"]["+siteCodeDet2+"]parentItem["+parentItem+"]")
						//alert("["+i+"]itemCode["+itemCode+"]["+siteCode+"]["+tranSer+"]["+lotNo+"]["+lotSl+"]");
						tempQty = 0;
						var key = siteCode+"@"+itemCode+"@"+lotNo+"@"+lotSl+"@"+locCode+"@"+tranSer+"@"+tranId+"@"+refLineNo;
						//var key = siteCode+"@"+itemCode+"@"+lotNo+"@"+lotSl+"@"+locCode+"@"+tranSer;
						var tempQty = 0;
						//alert("key["+i+"]["+key+"]");

						if(allocQty==null || allocQty =="")
						{
							allocQty=0;
						}
						//for (ctr=0;ctr<keyArray.length;ctr++)
						//{
						//alert("@@@@@@@@@@@@@@@@@[key["+key+"]");
						//alert("@@@@@@@@@@@@@@@@@["+i+"]keyArray["+keyArray+"]");
						//alert("@@@@@@@@@@@@@@@@@@@["+i+"]valueArray["+valueArray+"]");

						//alert("@@@@@@@@@@@@@@@@@@@[index["+index+"]");
						index = keyArray.indexOf(key);
						//}
						//alert("index["+index+"]key["+key+"]");
						if(( index != 0 ) && ( index == null || index == "" || index < 0 ||  index == -1  ))
						{
							//alert("add-key["+key+"]["+index+"]:allocQty["+allocQty+"]");
							keyArray[keyArray.length] =  key;
							valueArray[valueArray.length] =  allocQty;
						}
						else
						{

							tempQty = valueArray[index];
							if( tempQty== null || tempQty =="" || tempQty== NaN || tempQty== "NaN" )
							{
								tempQty = 0;
							}
							if( allocQty > 0)
							{	
								//alert("modify-key["+key+"]:tempQty["+tempQty+"]:allocQty["+allocQty+"]");
								valueArray[index] =  (+tempQty) + (+allocQty);
								//alert("increment valueArray[index]["+index+"]["+valueArray[index]+"]");
							}	
						}

					}

					//siteCode1 = siteCode;
					//itemCode1 = itemCode;
					//itemCodeDescr1 = "";

				}
			}

			//alert("array cycle complete............")
			//alert("@@@@@@@@@@@@@@@@@final keyArray["+keyArray+"]");
			//alert("@@@@@@@@@@@@@@@@@@@final valueArray["+valueArray+"]");

			selectedSampleItem = selectedSampleItem + "<CommonDetail >" +	
			"<sale_order>" + saleOrderDet2 + "</sale_order><line_no>" + lineNoDet2 + "</line_no>" +
			"<site_code>"+siteCodeDet2 + "</site_code><item_code>"+ itemCodeDet2 + "</item_code>" +
			"<item_code_descr>" + itemCodeDescr1 + "</item_code_descr></CommonDetail>";


			///////////
			for ( i = 1; i <= MAXITEMID; i++ )
			{
				//alert("inside for i["+i+"]");
				var siteCode = "";
				var itemCode = "";
				var itemCodeDescr = "";
				var lotNo = "";
				var lotSl = "";
				var locCode = "";
				var tranSer = "";
				var tranId = "";
				var refLineNo = "";
				var supply=0;
				var allocQty=0;
				var availableSupply=0;
				var sourceSupply="";
				var plannedQty="";
				var unit="";
				siteCode="";
				itemCode="";
				//alert(document.getElementById("Detail4.sample_item"+i+".site_code").value);
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".site_code") != null )
				{
					siteCode =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".site_code").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".item_code") != null )
				{
					itemCode =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".item_code").value.trim();
					//alert("itemCode["+itemCode+"]");
				}

				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".item_code_descr") != null )
				{
					itemCodeDescr =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".item_code_descr").value;
					//alert("itemCodeDescr["+itemCodeDescr+"]");
				}

				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".lot_no") != null )
				{
					lotNo =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".lot_no").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".lot_sl") != null )
				{
					lotSl =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".lot_sl").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".loc_code") != null )
				{
					locCode =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".loc_code").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".tran_ser") != null )
				{
					tranSer =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".tran_ser").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".tran_id") != null )
				{
					tranId =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".tran_id").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".ref_line_no") != null )
				{
					refLineNo =document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".ref_line_no").value.trim();
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".supply") != null )
				{
					supply = document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".supply").value;
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".alloc_qty") != null )
				{
					allocQty = document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".alloc_qty").value;
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".source_supply") != null )
				{
					sourceSupply = document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".source_supply").value;
					//alert("sourceSupply["+sourceSupply+"]");
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".unit") != null )
				{
					unit = document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".unit").value;
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".planned_quantity") != null )
				{
					plannedQty = document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".planned_quantity").value;
				}
				if ( document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".parent_item") != null )
				{
					parentItem = document.getElementById("Detail4."+saleOrder+"."+lineNo+"."+i+".parent_item").value;
					//alert("parentItem"+parentItem);
				}
				
				//alert("itemCodeDet2["+itemCodeDet2+"]itemCode["+itemCode+"]parentItem["+parentItem+"]")

				//if ( (! ( itemCode == "" && siteCode == "" )) && ( itemCode == itemCodeDet2 &&  siteCode == siteCodeDet2 ))

				if(  itemCode != "" && siteCode != "" &&  itemCode.trim().length > 0 && siteCode.trim().length > 0 &&( ( itemCode.trim() == itemCodeDet2.trim() || parentItem.trim() == itemCodeDet2.trim() ) &&  siteCode.trim() == siteCodeDet2.trim() ))  
				{
					var key2 = "";
					var index2="";
					var tempQty2=0;
					//alert("@@test inside");
					//alert("supply["+supply+"]");
					//alert("availableSupply["+availableSupply+"]");
					//alert("allocQty["+allocQty+"]");
					if( allocQty.trim().length==0 )
					{
						allocQty=0;
					}
					if( plannedQty.trim().length==0 )
					{
						plannedQty=0;
					}
					if( supply.trim().length==0 )
					{
						supply=0;
					}
					key2 = siteCode+"@"+itemCode+"@"+lotNo+"@"+lotSl+"@"+locCode+"@"+tranSer+"@"+tranId+"@"+refLineNo;
					//var key2 = siteCode+"@"+itemCode+"@"+lotNo+"@"+lotSl+"@"+locCode+"@"+tranSer;
					//alert("@@@@@@@@@@@@@@@@@--- key2["+key2+"]");
					index2 = keyArray.indexOf(key2) ;
					//alert("@@@@@@@@@@@@@@@@@@@----- valueArray["+valueArray+"]index2["+index2+"]");
					tempQty2 = valueArray[index2];
					//alert("@@@@@@@@@@@@@@@@@--- tempQty2["+tempQty2+"]index2["+index2+"]");
					
					//alert("key2["+key2+"]index2["+index2+"]tempQty2["+tempQty2+"]");
					//alert("supply["+supply+"]tempQty2["+tempQty2+"]");
					//if(tempQty2 != null || tempQty2 != undefined ||  tempQty2 != "undefined" || tempQty2 == NaN || tempQty2 == "NaN")
					if( ( index2 != 0 ) && ( index2 == null || index2 == "" || index2 < 0 ||  index2 == -1  ) )
					{
						tempQty2 = 0;
						//alert("tempQty2["+tempQty2+"]");
					}
					availableSupply = supply - tempQty2;

					//alert("key2["+key2+"]:::tempQty2["+tempQty2+"]:availableSupply["+availableSupply+"]");  //Detail4.sample_item."+dbID+"."+i+".

					
					
					//alert("itemCode["+itemCode+"]itemCodeDescr["+itemCodeDescr+"]");
					selectedSampleItem = selectedSampleItem + "<Detail4  domID='" + i + "'>" +	
					"<sale_order>" + saleOrder + "</sale_order><line_no>" + lineNo + "</line_no><qty_reqd>" + qtyReqd + "</qty_reqd>" +
					"<site_code>" + siteCode + "</site_code><item_code>" + itemCode + "</item_code>" +
					"<item_code_descr>" + itemCodeDescr + "</item_code_descr>" +
					"<lot_no>" + lotNo + "</lot_no>" +
					"<lot_sl>" + lotSl + "</lot_sl><loc_code>" + locCode + "</loc_code><tran_ser>" + tranSer + "</tran_ser>" +
					"<tran_id>" + tranId + "</tran_id><ref_line_no>" + refLineNo + "</ref_line_no>" +
					"<supply>" + supply + "</supply><available_supply>" + availableSupply + "</available_supply><alloc_qty>" + allocQty + "</alloc_qty>" +
					"<source_supply>" + sourceSupply + "</source_supply><unit>" + unit + "</unit><planned_quantity>" + plannedQty + "</planned_quantity></Detail4>";
					//domID++;


				}

			}


			//alert("selectedSampleItem["+selectedSampleItem+"]");
			/*
		for ( i = 1; i <= MAXITEMID; i++ )
		{
			var siteCode = "";
			var itemCode = "";
			var lotNo = "";
			var lotSl = "";
			var locCode = "";
			var tranSer = "";
			var TranId = "";
			var lineNo = "";


			if ( document.getElementById("Detail4."+i+".site_code") != null )
			{
				siteCode =document.getElementById("Detail4."+i+".site_code").value;
			}
			if ( document.getElementById("Detail4."+i+".item_code") != null )
			{
				itemCode =document.getElementById("Detail4."+i+".item_code").value;
			}
			if ( document.getElementById("Detail4."+i+".lot_no") != null )
			{
				lotNo =document.getElementById("Detail4."+i+".lot_no").value;
			}
			if ( document.getElementById("Detail4."+i+".lot_sl") != null )
			{
				lotSl =document.getElementById("Detail4."+i+".lot_sl").value;
			}
			if ( document.getElementById("Detail4."+i+".loc_code") != null )
			{
				locCode =document.getElementById("Detail4."+i+".loc_code").value;
			}
			if ( document.getElementById("Detail4."+i+".tran_ser") != null )
			{
				tranSer =document.getElementById("Detail4."+i+".tran_ser").value;
			}
			if ( document.getElementById("Detail4."+i+".tran_id") != null )
			{
				TranId =document.getElementById("Detail4."+i+".tran_id").value;
			}
			if ( document.getElementById("Detail4."+i+".line_no") != null )
			{
				lineNo =document.getElementById("Detail4."+i+".line_no").value;
			}


			if ( ! ( itemCode == "" && salesPrdGrp == "" ) )
			{
				selectedItem = selectedItem + "<strg_item domID='" + i + "'>" +
							"<site_code>" + siteCode + "</site_code><item_code>" + itemCode + "</item_code><lot_no>" + lotNo + "</lot_no>" +
							"<lot_sl>" + lotSl + "</lot_sl><loc_code>" + locCode + "</loc_code><tran_ser>" + tranSer + "</tran_ser><tran_id>" + tranId + "</tran_id><line_no>" + lineNo + "</line_no>" +
							"</strg_item>";

			}

		}
			 */	
		}
		
		var win = window.open( '', 'Items', 'toolbar=no,status=YES,resizable=yes,scrollbars=yes,left=0,top=0,width=1300,height=876,fullscreen=yes' );



		var samplItem = [];
		var method = "post";
		var path="/ibase/webitm/jsp/MRPWizardSampleItems.jsp";
		samplItem["SALE_ORDER"] = saleOrder;
		samplItem["LINE_NO"] = lineNo;
		samplItem["QTY_REQD"] = qtyReqd;
		// samplItem["SELECTED_ITEM"] = "<Root>" + selectedItem + "</Root>";
		samplItem["SELECTED_SAMPLE_ITEMS"] = "<Root>" + selectedSampleItem + "</Root>";
		post_to_url(path, samplItem, method);

	}
//	New Function added by Gulzar to display sample item and stock quantity on 28/MAY/13 : END
	/* Added by Amit D on 27-May-13 Start */
	function callTemplateJSP(obj)
	{       
		var url = '/ibase/webitm/jsp/ITMWizardTemplate.jsp';
		var win = window.open( url, 'Template', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );
	}
	function displayTemplate( templateId )
	{

		if (document.getElementById("Detail1..template_id") != null)
		{
			document.getElementById("Detail1..template_id").value = templateId;
		}
		else
		{
			document.getElementById("Detail1.1.template_id").value = templateId;
		}
	}

	function callItemSeriesJSP(obj)
	{       
		var url = '/ibase/webitm/jsp/ITMWizardItemSeries.jsp';
		var win = window.open( url, 'Template', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=500,height=406' );
	}
	function displayItemSeries( itemSer ,  itemSerDescr)
	{

		if (document.getElementById("Detail1..item_ser") != null)
		{
			document.getElementById("Detail1..item_ser").value = itemSer;


		}
		else
		{
			document.getElementById("Detail1.1.item_ser").value = itemSer;

		}
	}
	function performNextAction( action )
	{  
		document.getElementById("action").value = action;
		var flag=0; 	
		if(action == "next")
		{ 
			flag=1;
			return true;
		}
	}

	function post_to_url(path, params, method) {
		method = method || "post"; // Set method to post by default if not specified.

		// The rest of this code assumes you are not using a library.
		// It can be made less wordy if you use one.
		var form = document.createElement("form");
		form.setAttribute("method", method);
		form.setAttribute("action", path);
		form.target = 'Items';

		for(var key in params) {
			if(params.hasOwnProperty(key)) {
				var hiddenField = document.createElement("input");
				hiddenField.setAttribute("type", "hidden");
				hiddenField.setAttribute("name", key);
				hiddenField.setAttribute("value", params[key]);

				form.appendChild(hiddenField);
			}
		}

		document.body.appendChild(form);
		form.submit();
	}
	/* Added by Amit D on 27-May-13 END*/ 

//	New Function added by Gulzar to display period code and station code pophelp : START
	var fieldName = "";
	function callPeriodCodeJSP( dbID, periodCode, periodFieldName )
	{

		fieldName = periodFieldName;
		var selectedPeriod = document.getElementById("Detail1."+dbID+"."+periodFieldName).value;
		var url = '/ibase/webitm/jsp/ITMWizardPeriodCode.jsp?PERIOD_CODE='+periodCode+'&SELECTED_PERIOD_CODE='+selectedPeriod;
		var win = window.open( url, 'PeriodCode', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=600,height=406' );

	}

	var currStationField = "";
	var currDbID = "";
	function callStationCodeJSP( dbID, selStanDescrFldName, selStationName, stanHq1Name, stanHq2Name )
	{
		currStationField = selStanDescrFldName;
		currDbID = dbID;
		var selStationDescr = "";
		var selStationCode = "";
		var stationCode1 = "";
		var stationCode1 = "";
		if(document.getElementById("Detail1."+dbID+"."+selStanDescrFldName) != null)
		{
			selStationDescr = document.getElementById("Detail1."+dbID+"."+selStanDescrFldName).value;
		}
		if(document.getElementById("Detail1."+dbID+"."+selStationName) != null)
		{
			selStationCode = document.getElementById("Detail1."+dbID+"."+selStationName).value;
		}
		if(document.getElementById("Detail1."+dbID+"."+stanHq1Name) != null)
		{
			stationCode1 = document.getElementById("Detail1."+dbID+"."+stanHq1Name).value;
		}
		if(document.getElementById("Detail1."+dbID+"."+stanHq2Name) != null)
		{
			stationCode2 = document.getElementById("Detail1."+dbID+"."+stanHq2Name).value;
		}

		var url = '/ibase/webitm/jsp/ITMWizardStationCode.jsp?STATION_DESCR='+selStationDescr+'&SELECTED_STATION_CODE='+selStationCode+'&STATION_CODE_OTH_1='+stationCode1+'&STATION_CODE_OTH_2='+stationCode2;
		var win = window.open( url, 'StationCode', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=100,top=50,width=600,height=406' );

	}


	function disableButtons(formNo)
	{
		//alert("formNo =["+formNo+"]");
		if (formNo == '1')
		{
			//document.Wizard_activity.next.disabled = true;
			if(document.Wizard_activity.ActNext != null && document.Wizard_activity.ActNext != 'undefined')
			{
				document.Wizard_activity.ActNext.disabled = true;
			}
			if(document.Wizard_activity.ActFinish != null && document.Wizard_activity.ActFinish != 'undefined')
			{
				document.Wizard_activity.ActFinish.disabled = true;
			}

			if(document.Wizard_activity.Cancel != null && document.Wizard_activity.Cancel != 'undefined')
			{
				document.Wizard_activity.Cancel.disabled = true;
			}
			if(document.Wizard_activity.Next != null && document.Wizard_activity.Next != 'undefined')
			{
				document.Wizard_activity.Next.disabled = true;
			}
		}
		else if (formNo == '2')
		{
			if(document.Wizard_Travel != null && document.Wizard_Travel !='undefined')
			{
				if(document.Wizard_Travel.Cancel != null)
				{
					document.Wizard_Travel.Cancel.disabled = true;
				}
				if(document.Wizard_Travel.Next != null)
				{
					document.Wizard_Travel.Next.disabled = true;
				}
			}
			if(document.Wizard_Sprs != null && document.Wizard_Sprs !='undefined')
			{
				if(document.Wizard_Sprs.Cancel != null)
				{
					document.Wizard_Sprs.Cancel.disabled = true;
				}
				if(document.Wizard_Sprs.Next != null)
				{
					document.Wizard_Sprs.Next.disabled = true;
				}
			}
		}
		/*	if (formNo == '3')
	{
		if(document.Wizard_Customer.Previous != null)
		{
			document.Wizard_Customer.Previous.disabled = true;
		}
		if(document.Wizard_Customer.Next != null)
		{
			document.Wizard_Customer.Next.disabled = true;
		}
	}
		 */	
	}
	function enableButtons(formNo)
	{
		//alert("formNo =["+formNo+"]");
		if (formNo == '1')
		{

			var activityType = "";
			if(document.getElementById( "Detail"+formNo+".activity_type") != null)  //..
			{
				activityType = document.getElementById( "Detail"+formNo+"..activity_type").value;
			}
			else
			{
				if(document.getElementById("Detail"+formNo+".1.activity_type") != null)
				{
					activityType = document.getElementById("Detail"+formNo+".1.activity_type").value;
				}
			}
			//alert("activityType =["+activityType+"]");
			if(activityType =="LEAVE" || activityType =="NFW" )
			{
				if(document.Wizard_activity.ActNext != null && document.Wizard_activity.ActNext != 'undefined')
				{
					document.Wizard_activity.ActNext.disabled = true;
				}
				if(document.Wizard_activity.ActFinish != null && document.Wizard_activity.ActFinish != 'undefined')
				{
					document.Wizard_activity.ActFinish.disabled = false;
				}

				if(document.Wizard_activity.Cancel != null && document.Wizard_activity.Cancel != 'undefined')
				{
					document.Wizard_activity.Cancel.disabled = false;
				}
				if(document.Wizard_activity.Next != null && document.Wizard_activity.Next != 'undefined')
				{
					document.Wizard_activity.Next.disabled = true;
				}
			}
			else
			{
				if(document.Wizard_activity.ActNext != null && document.Wizard_activity.ActNext != 'undefined')
				{
					document.Wizard_activity.ActNext.disabled = false;
				}
				if(document.Wizard_activity.ActFinish != null && document.Wizard_activity.ActFinish != 'undefined')
				{
					document.Wizard_activity.ActFinish.disabled = true;
				}

				if(document.Wizard_activity.Cancel != null && document.Wizard_activity.Cancel != 'undefined')
				{
					document.Wizard_activity.Cancel.disabled = false;
				}
				if(document.Wizard_activity.Next != null && document.Wizard_activity.Next != 'undefined')
				{
					document.Wizard_activity.Next.disabled = false;
				}
			}
		}
		else if (formNo == '2')
		{
			//alert(""+document.Wizard_Travel.Cancel);
			if(document.Wizard_Travel != null && document.Wizard_Travel !='undefined')
			{
				if(document.Wizard_Travel.Cancel != null)
				{
					document.Wizard_Travel.Cancel.disabled = false;
				}
				if(document.Wizard_Travel.Next != null)
				{
					document.Wizard_Travel.Next.disabled = false;
				}
			}
			if(document.Wizard_Sprs != null && document.Wizard_Sprs !='undefined')
			{
				if(document.Wizard_Sprs.Cancel != null)
				{
					document.Wizard_Sprs.Cancel.disabled = false;
				}
				if(document.Wizard_Sprs.Next != null)
				{
					document.Wizard_Sprs.Next.disabled = false;
				}
			}
		}
		/*	if (formNo == '3')
	{
		//alert(""+document.Wizard_Travel.Cancel);
		if(document.Wizard_Customer.Previous != null)
		{
			document.Wizard_Customer.Previous.disabled = false;
		}
		if(document.Wizard_Customer.Next != null)
		{
			document.Wizard_Customer.Next.disabled = false;
		}
	}
		 */
	}
	function validateActivity(formNo)
	{
		disableButtons(formNo);
		var value = document.getElementById("action").value;

		var flag=0; 	
		if(value =="next")
		{ 
			flag=1;
			var returnVal = checkDate(document.getElementById("Detail1..event_date"),flag);
			if(returnVal== true)
			{
				enableButtons(formNo);
				return false;
			}

		}
		else if(value=="finish")
		{
			flag=2;
			var returnValue = checkDate(document.getElementById("Detail1..event_date"),flag);
			if(returnValue== true)
			{
				enableButtons(formNo);
				return false;
			}
		}
	}
	function vlidateSprs(formNo)
	{
		disableButtons(formNo);
		var chkCount = 0;
		var count = 0;
		count = document.Wizard_Sprs.elements.length;


		action = document.getElementById("action").value;
		if( action != "previous" )
		{

			for(i = 0; i < count; i++)
			{

				if(document.Wizard_Sprs.elements[i].type == 'checkbox')
				{
					if(document.Wizard_Sprs.elements[i].checked == true)
					{
						chkCount = chkCount + 1;
					}
				}
			}

			if(chkCount == 0 )
			{
				alert("No Selection Made ! \nPlease select a Subordinate !");

				for(i = 0; i < count; i++)
				{
					if(document.Wizard_Sprs.elements[i].type == 'submit' || document.Wizard_Sprs.elements[i].type == 'button')
					{
						var value = document.Wizard_Sprs.elements[i].value;
						var buttonDisabledId = document.getElementById("button."+value);
						if(buttonDisabledId != null && document.getElementById("button."+value).disabled == true)
						{
							document.getElementById("button."+value).disabled = false;
						}
					}
				}
				enableButtons(formNo);
				return false;
			}
		}
	}
//Added by chandrashekar
/*function callRumMrpExportJSP( value )
{  
		//alert("callRumMrpExportJSP")
		document.getElementById("action").value = value;

		var samplItem = [];
		var method = "post";
		var path="/ibase/webitm/jsp/RunMrpExportExcel.jsp";
		var issError = false;

		var srNo = 1;
		var selectedSampleItem = "";
		var saleOrder = "";
		var lineNo = "";
		var itemCode = "";
		var siteCode = "";
		var qtyReqd = "";
		var lotNo = "";
		var lotSl = "";
		var locCode = "";
		var tranSer = "";
		var tranId = "";
		var refLineNo = "";
		var supply = "";
		var availableSupply = "";
		var allocQty = "";
		var maxId = 1000;
		var div1 = "";
		
		var itemCnt =0;
		var itemCodeDescr="";
		var finishArray = new Array();
		var flagforSO = false;
		var finishArrayKey="";

		var itemCodeHdr="";
		var parentItem="";
		var unit="";
		var plannedQuantity="";
		var sourceSupply="";
		var dateFrom="";
		var dateTo="";
		var siteCodeFrom="";
		var siteCodeTo="";
		
		for( var dbIDOut = 1; dbIDOut <= maxId; dbIDOut++)
		{
			
			if(document.getElementById("Detail2."+dbIDOut+".selectbox")!=null && document.getElementById("Detail2."+dbIDOut+".selectbox").checked )
			{	
				saleOrder = document.getElementById("Detail2."+dbIDOut+".sale_order").value.trim();
				lineNo = document.getElementById("Detail2."+dbIDOut+".line_no").value.trim();
				itemCodeHdr = document.getElementById("Detail2."+dbIDOut+".item_code").value.trim();
				
					for(var dbID = 1; dbID <= maxId; dbID++)
					{	
						
						if( document.getElementById("Detail2"+"."+dbID+".qty_reqd") != null)
						{
							qtyReqd = document.getElementById("Detail2"+"."+dbID+".qty_reqd").value;
						}
						if( document.getElementById("Detail2.dateFr_argdata") != null)
						{
							dateFrom = document.getElementById("Detail2.dateFr_argdata").value;							
						}
						if( document.getElementById("Detail2.dateTo_argdata") != null)
						{
							dateTo = document.getElementById("Detail2.dateTo_argdata").value;							
						}
						if( document.getElementById("Detail2.siteCodeFr_argdata") != null)
						{
							siteCodeFrom = document.getElementById("Detail2.siteCodeFr_argdata").value;							
						}
						if( document.getElementById("Detail2.siteCodeTo_argdata") != null)
						{
							siteCodeTo = document.getElementById("Detail2.siteCodeTo_argdata").value;							
						}

											
						
						var divid= document.getElementById("sample_item"+dbID);						  
						if( divid != null)
						{ 
							
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".sale_order") != null)
							{
								saleOrder = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".sale_order").value;
								
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".line_no") != null)
							{
								lineNo = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".line_no").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code") != null)
							{
								itemCode = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code").value;
							}

							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code_descr") != null)
							{
								itemCodeDescr = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".item_code_descr").value;
							}

							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".site_code") != null)
							{				
								siteCode = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".site_code").value;
							}
							if( document.getElementById("Detail2"+"."+dbID+".qty_reqd") != null)
							{
								qtyReqd = document.getElementById("Detail2"+"."+dbID+".qty_reqd").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_no") != null)
							{
								lotNo = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_no").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_sl") != null)
							{
								lotSl = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".lot_sl").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".loc_code") != null)
							{
								locCode = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".loc_code").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_ser") != null)
							{
								tranSer = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_ser").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_id") != null)
							{
								tranId = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".tran_id").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".ref_line_no") != null)
							{
								refLineNo = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".ref_line_no").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".supply") != null)
							{	
								supply = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".supply").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".available_supply") != null)
							{
								availableSupply = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".available_supply").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".alloc_qty") != null)
							{
								allocQty = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".alloc_qty").value;
							}
							
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".parent_item") != null)
							{
								parentItem = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".parent_item").value;
							}						
							
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".unit") != null)
							{
								unit = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".unit").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".planned_quantity") != null)
							{
								plannedQuantity = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".planned_quantity").value;
							}
							if( document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".source_supply") != null)
							{
								sourceSupply = document.getElementById("Detail4"+"."+saleOrder+"."+lineNo+"."+dbID+".source_supply").value;
							}
								
							selectedSampleItem = selectedSampleItem + "<Detail4  domID='" + dbID + "'>" +	
							"<sale_order>" + saleOrder + "</sale_order><line_no>" + lineNo + "</line_no><qty_reqd>" + qtyReqd + "</qty_reqd>" +
							"<site_code>" + siteCode + "</site_code><item_code>" + itemCode + "</item_code>" +
							"<item_code_descr>" + itemCodeDescr + "</item_code_descr>" +
							"<lot_no>" + lotNo + "</lot_no><parent_item>" + parentItem + "</parent_item>" +
							"<lot_sl>" + lotSl + "</lot_sl><loc_code>" + locCode + "</loc_code><tran_ser>" + tranSer + "</tran_ser>" +
							"<tran_id>" + tranId + "</tran_id><ref_line_no>" + refLineNo + "</ref_line_no>" +
							"<supply>" + supply + "</supply><alloc_qty>" + allocQty + "</alloc_qty>" +
							"<unit>" + unit + "</unit><planned_quantity>" + plannedQuantity + "</planned_quantity><source_supply>" + sourceSupply + "</source_supply>" +
							"<site_code__from>" + siteCodeFrom + "</site_code__from><site_code__to>" + siteCodeTo + "</site_code__to><date_from>" + dateFrom + "</date_from>" +
							"<date_to>" + dateTo + "</date_to>" +
							"</Detail4>";
							//alert("selectedSampleItem::"+selectedSampleItem);

						}

						

					}
				
			}
		}
		
		if( issError == false)
		{	
			samplItem["SAVE_SAMPLE_DATA"] = "<Root>" + selectedSampleItem + "</Root>";
			post_to_url2(path, samplItem, method);
		}
		else
		{
			alert(" please select all stock record of selected saleOrder for allocation...");
			return false;
		}
			
 }
	function post_to_url2(path, params, method) {
		method = method || "post"; // Set method to post by default if not specified.

		
		var form = document.createElement("form");
		form.setAttribute("method", method);
		form.setAttribute("action", path);
		form.target = 'Items';

		for(var key in params) {
			if(params.hasOwnProperty(key)) {
				var hiddenField = document.createElement("input");
				hiddenField.setAttribute("type", "hidden");
				hiddenField.setAttribute("name", key);
				hiddenField.setAttribute("value", params[key]);

				form.appendChild(hiddenField);
			}
		}

		document.body.appendChild(form);
		form.submit();
	}*/
