function supp_pop(field,fieldname,label,extra)
{
		var url = "/ibase/webitm/jsp/PorderPopHelp.jsp?field="+field+"&fieldname="+fieldname+"&label="+label+"&extra="+extra;
		var win = window.open( url, 'Supplier Code', 'toolbar=no,status=yes,resizable=no,scrollbars=yes,left=500,top=50,width=500,height=550');		
}

function callpop(x)
{
	document.getElementById("active").value=x;
	
	var temp=document.getElementById("supp_code").value;
	
	supp_pop('item_code','itmcode'+x,'Item Code',temp);
}

//this function is used to set the value in text field in wizard after selecting checkbox from pop help	
function selectCheckbox()
	{
		var supp_code="";
		var det="";
		var extra="";
		
		var otherField1 = "";
		var otherField2 = "";
		var otherField3 = "";
		
		var descr1 = "";
		var descr2 = "";
		var descr3 = "";
		
		var field = document.getElementById("erp").value;
		
		if(field=="supp_code")
		{		
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
					
					otherField1=otherField1+document.getElementById("DetailITCode."+ i +".otherField1").value;
					otherField2=otherField2+document.getElementById("DetailITCode."+ i +".otherField2").value;
					otherField3=otherField3+document.getElementById("DetailITCode."+ i +".otherField3").value;
					
					descr1=descr1+document.getElementById("DetailITCode."+ i +".descr1").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("xyz").value=supp_code;
				window.opener.document.getElementById("pqr").value=det;
				
				window.opener.document.getElementById("crterm").value=otherField1;
				window.opener.document.getElementById("prlist").value=otherField2;
				window.opener.document.getElementById("dlvterm").value=otherField3;
				
				window.opener.document.getElementById("crdescr").value=descr1;
				
				window.close();
			}
		}
		else if(field=="tran_code")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
					extra=extra+document.getElementById("DetailITCode."+ i +".otherField").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("trcode").value=supp_code;
				window.opener.document.getElementById("trdescr").value=det;
				window.opener.document.getElementById("trmode").value=extra;
				window.close();
			}
		}
		else if(field=="item_ser")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("itmser").value=supp_code;
				window.opener.document.getElementById("itmdescr").value=det;
				window.close();
			}
		}
		else if(field=="cr_term")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("crterm").value=supp_code;
				window.opener.document.getElementById("crdescr").value=det;
				window.close();
			}
		}
		else if(field=="dept_code")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("dcode").value=supp_code;
				window.opener.document.getElementById("ddescr").value=det;
				window.close();
			}
		}
		else if(field=="price_list")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("prlist").value=supp_code;
				window.opener.document.getElementById("prdescr").value=det;
				window.close();
			}
		}
		else if(field=="item_code")
		{
			
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(Wizard_SuppDetails.selectbox.length == undefined)
			{
				if (Wizard_SuppDetails.selectbox.checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ 1 +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ 1 +".fieldValue").value;
				}
			}
			
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				var s=window.opener.document.getElementById("active").value;
				
				window.opener.document.getElementById("itmcode"+s).value=supp_code;
				window.opener.document.getElementById("itmdescription"+s).value=det;
				
				window.opener.document.getElementById("main"+s).innerHTML=supp_code+" "+det;
				
				itmparntChange(window.opener.document.getElementById("itmcode"+s).value, "l");
				
				window.close();
			}
		}
		else if(field=="type")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("type").value=supp_code;
				window.opener.document.getElementById("typedescr").value=det;
				window.close();
			}
		}
		else if(field=="site_code")
		{
			for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
					//i=i+1;
				 if (Wizard_SuppDetails.selectbox[i-1].checked)
				{
					supp_code=supp_code+document.getElementById("DetailITCode."+ i +".fieldId").value;
					det=det+document.getElementById("DetailITCode."+ i +".fieldValue").value;
				}
			}
			
			if(supp_code=="")
			{
				alert('No Selection Made ! \nPlease Select the Code !');
			}
			else
			{
				window.opener.document.getElementById("site_code").value=supp_code;
				window.opener.document.getElementById("sitedescr").value=det;
				window.close();
			}
		}					
	}
//this function used to tick on only one checkbox at a time
function checkone(id)
{
    for (var i = 1;i<=Wizard_SuppDetails.selectbox.length; i++)
    {
        document.getElementById("DetailITCode."+ i +".selectbox").checked = false;
    }
    
    document.getElementById(id).checked = true;
}

//this function used to set checkbox tick when cliking on row in popup
function rowChecked(id)
{
		for (var i = 1;i<=Wizard_SuppDetails.selectbox.length; i++)
		{
			document.getElementById("DetailITCode."+ i +".selectbox").checked = false;
		}
		
		document.getElementById("DetailITCode."+ id +".selectbox").checked = true;
}

//this function used to set checkbox tick after reopen popup
function easy(tick)
{
	if(tick=="prlist")
	{
		for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
				 if (document.getElementById("DetailITCode."+ i +".fieldId").value==window.opener.document.getElementById(tick).value && document.getElementById("DetailITCode."+ i +".fieldValue").value==window.opener.document.getElementById("prdescr").value)
				{
					document.getElementById("DetailITCode."+ i +".selectbox").checked = true;
					break;
				}	
			}
	}
	else
	{
		for (var i = 1; i<=Wizard_SuppDetails.selectbox.length; i++)
			{
				 if (document.getElementById("DetailITCode."+ i +".fieldId").value==window.opener.document.getElementById(tick).value)
				{
					document.getElementById("DetailITCode."+ i +".selectbox").checked = true;
				}	
			}
			
		if(Wizard_SuppDetails.selectbox.length==undefined)  //this is for if only one checkbox
		{
				if (document.getElementById("DetailITCode."+ 1 +".fieldId").value==window.opener.document.getElementById(tick).value)
				{
					Wizard_SuppDetails.selectbox.checked = true;
				}
		}	
	}		
}

function sidebar()
{
	var x=document.getElementById("tabs").value;
	x++;
	//alert('Tabs='+x);
	document.getElementById("tabs").value=x;
	
	var a="<h3 onclick='run("+x+")' style='font-family: Arial Unicode MS, Arial, sans-serif;'>Product Set"+
				"<label id='main"+x+"' style='width:500px;background-color: transparent;'></label>"+
				
				
										
			"</h3>"+
			"<div style='padding: 0.8em 0.8em;' >"+
				"<div id='suppDtlDiv"+x+"' style='height: 180px; overflow: auto; margin-left: 0px; width:100%;'>"+
					"<table id='itemDtl' border='0' style='text-align: center;'>"+
						
						"<tr>"+
							"<td>"+
								"<strong>Item Parent :</strong>"+
							"<td>"+	
							"<td class='td_leftAlign'>"+
								"<div style='position:relative; width: 90%;'>"+
									"<input type='text' class='editInputClass' name='itmcode"+x+"' id='itmcode"+x+"' maxlength='10' ISCHANGED='false' readOnly = '1' style='width: 90%;'/>"+
									"<div style='width:3%; float: right;'>"+
										"<a href='javascript:callpop("+x+")' style='float: left;text-decoration: none;'>"+
											"<img src='/ibase/webitm/images/DD/popup1.png' style='margin-left: -5px;' title='Select Item Code'/>"+
										"</a>"+
									"</div>"+
								"</div>"+
							"</td>"+
							"<td colspan='2'>"+
								"<input type='text'  id='itmdescription"+x+"'  class='editDisplayClass' maxlength='0' ISCHANGED='false' readOnly = '1' style='margin-left: -9px;width: 200px'/>"+
								
							"</td>"+
							"<td colspan='2'>"+
								" <strong>Delivery Date:</strong> <input type='text' name='dlv_date"+x+"' onchange='dateChange("+x+")' "+
								"id='dlv_date"+x+"' class='editDisplayClass' maxlength='0' ISCHANGED='false' readOnly = '1' style='width: 200px;' />"+
							"</td>"+
						"<tr>"+	
							
							
					"</table>"+
				"</div>"+
			"</div>";
	//$( "#accordion" ).accordion();		
	$("#accordion").append(a);
	$( "#accordion" ).accordion('destroy').accordion();
	
	$("#accordion").accordion({ collapsible:true, active:false });
	
	//document.getElementById("accordion").style.visibility = "visible";
	$("#accordion").accordion('option', 'active' , x-1);
	
	$( "#dlv_date"+x+"").datepicker({ minDate: 0, changeMonth: true, changeYear: true, dateFormat : "d/m/y"});
	
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1;

	var yyyy = today.getYear() % 100;
	if(dd<10){dd='0'+dd}
	if(mm<10){mm='0'+mm}
	var today = dd+'/'+mm+'/'+yyyy;

	document.getElementById("dlv_date"+x+"").value=today;
	
	
}

function itmparntChange( itmcode, objName)
	{
		//alert('Recived'+itmcode);
		objName = "porderWiz";
		var temp="S001";
		
		var url = "/ibase/PorderTableServlet?ITEMCODE="+itmcode+"&OBJ_NAME="+objName;
		makeRequest( url, setColumnValues);
	}
	
function makeRequest( url, setColumnValues )
	{
		var sURL = unescape(window.location);
	
		if( ! isServerBusy )
		{
	  		isServerBusy = true;
			httpRequest.open("POST", url, false);
			httpRequest.onreadystatechange = function()
			{
				receiveResponse( setColumnValues );
			};
		
			httpRequest.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" );
			httpRequest.send( null );
		}
	}	
	
function receiveResponse( setColumnValues )
	{
		if (httpRequest.readyState == 4)
		{
			if(httpRequest.status == 200) 
			{
		  		processResponse( setColumnValues );
			}
			else 
			{
				alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
			}
		}
	}
	
function processResponse( setColumnValues )
	{
	    var returnStr = null;
		isProcessOn = false;
		
		if ( window.ActiveXObject )
		{   
			xmldoc = httpRequest.responseText;
			xmlHTTPResponse = xmldoc;
		}
		else
		{   
			try
			{
		  		var parser = new DOMParser();
		  		xmldoc = httpRequest.responseText;
			}
			catch(e)
			{
		   		alert("inside catch:"+e.message);
			}
		}

		setColumnValues( xmldoc );
		isServerBusy = false;
	}		
function setColumnValues( retVal )
	{
		var xmldoc = null;
		var count = 0;
		
		//alert("retVal["+retVal+"]");
		retVal = retVal.replace(/(\r\n|\n|\r)/g, '');
		
		xmldoc = loadXMLString(retVal);
		
		if( xmldoc.nodeType != 9 )
		{
			return true;
		}
		
		var x = xmldoc.getElementsByTagName("tr");
		
		//var len=x.length;
		//alert("Lenght="+len);
		
		if (x.length > 0)
			appendSizesRow();
		
		var sizesValue = new Array();
		
		var tr = "";
		
		var t=window.opener.document.getElementById("active").value;    /*t variable for current tab check box id */
		var temp = "";
		for (var i = 0; i < x.length; i++) 
	    {
	    	if (x[i].nodeName != null && x[i].nodeName != undefined)
	    	{
	    		var y = x[i].childNodes;
	    		
	    		/*alert("1 = ["+ x[i].childNodes[0].childNodes[0].nodeValue +"]");
	    		alert("2 = ["+ x[i].childNodes[1].childNodes[0].nodeValue +"]");*/
	    		
	    		
	    		if (x[i].childNodes[0] != undefined)
				{
	    			 tr = tr + "<tr style='text-align: center;'>";
					
		    		for (var j = 0; j < y.length; j++)
		    		{
		    			if (y[j].nodeName != null && y[j].nodeName != undefined)
		    			{
		    				if (y[j].childNodes[0] != undefined)
		    				{
		    					if (y[j].childNodes[0].nodeValue == 'X')
		    					{
		    					
		    						tr = tr + "<td>"+ y[j].childNodes[0].nodeValue +"</td>";
		    					}
		    					else if (j == 0)
		    					{
		    						tr = tr + "<td>"+ y[j].childNodes[0].nodeValue +"</td>";
		    					
		    					}
		    					else if (j == 1)
		    					{
		    						tr = tr + "<td>"+ y[j].childNodes[0].nodeValue +"</td>";
		    					}
		    					else
		    					{
									var rate=xmldoc.getElementsByTagName("rate");
									var price = "";
									
		    						//tr = tr + "<td><input type='text' placeholder='"+y[j].childNodes[0].nodeValue+"' title='Price="+rate[0].childNodes[0].nodeValue+"' onkeypress='return isNumberKey(event)' class='editInputClass' style='width: 60px;text-align: right;' id='Detail2."+t+"."+y[j].childNodes[0].nodeValue+"."+count+"'/></td>";
		    						
		    						var fld = window.opener.document.getElementById("fld").value;
		    						var dte = window.opener.document.getElementById("dlv_date"+t+"").value;
		    						fld++;
		    						window.opener.document.getElementById("fld").value = fld;
		    						tr = tr + "<input type='hidden'    id='Detail2."+fld+".selectbox'  name='Detail2."+fld+".selectbox'  checked='false' value='false' />";
									tr = tr + "<input type='hidden'    id='Detail2."+fld+".item_code'  name='Detail2."+fld+".item_code'  value='"+y[j].childNodes[0].nodeValue+"' class='editInputClass' style='width: 60px;text-align: right;' />";
									tr = tr + "<input type='hidden'    value='"+dte+"' id='Detail2."+fld+".dlv_date'  name='Detail2."+fld+".dlv_date' class='editInputClass' style='width: 60px;text-align: right;'/>";
									tr = tr + "<input type='hidden'    value='"+dte+"' id='Detail2."+fld+".dlv_date'  name='Detail2."+fld+".dlv_date' class='editInputClass' style='width: 60px;text-align: right;'/>";
									tr = tr + "<td><input type='text'  id='Detail2."+fld+".quantity'   name='Detail2."+fld+".quantity'   title='"+y[j].childNodes[0].nodeValue+"' onkeypress='return isNumberKey(event)'  ISCHANGED='true' class='editInputClass' style='width: 60px;text-align: right;' /></td>";
									temp = temp + fld +",";
		    						count++;
		    						
								}
		    					
		    					
		    				}
		    			}
		    			
		    		}
					
		    		tr = tr + "</tr>";
		    		
				}
				
				
	    	}
	    }
	    
		tr = tr + "<input type='hidden'    value='"+temp+"' id='dlv_date_temp"+t+"'  name='dlv_date"+t+"' class='editInputClass' style='width: 60px;text-align: right;'/>";	
	    //alert("tr RECIVED="+tr);
	 
	    var x=window.opener.document.getElementById("tabs").value;
	    var y=window.opener.document.getElementById("active").value;
	    
	    var pSet = xmldoc.getElementsByTagName("SET");
	    //alert(pSet.length);
	    
	    var pSetVal = "";
	    
	    for (var k = 0; k < pSet.length; k++) 
		{
				//alert(pSet[k]);
				if (pSet[k].nodeName != null && pSet[k].nodeName != undefined)
				{
					pSetVal = pSetVal + "<th>"+pSet[k].childNodes[0].nodeValue+"</th>";
				}
		}
	    
	    var a = "<table class='tableClass' id='itemDtl"+y+"' width='100%' style='text-align: left;'>" +
			"<thead><tr class='thClass' style='text-align:center;'>"+
			pSetVal
			+"</tr></thead>" +
			"<tbody class='table-body'>" +
			"</tbody>" +
			"</table>";
			
			/*
			window.opener.document.getElementById("itemDtlDiv").innerHTML = a;
			window.opener.document.getElementById("ttt").innerHTML = tr;
			$('#itemDtlDiv tbody', window.opener.document).append(tr);  */
			
			
			//alert("active="+y);
			//alert("X="+x);
			
			$('#itemDtl'+y, window.opener.document).remove();
			$('#suppDtlDiv'+y, window.opener.document).append(a);
			$('#itemDtl'+y+' tbody', window.opener.document).append(tr);
			
	}
	
function loadXMLString(txt)
	{
		if (window.DOMParser)
	  	{
	  		parser=new DOMParser();
	  		xmlDoc=parser.parseFromString(txt,"text/xml");
	  	}
		else 
		{
	  		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  		xmlDoc.async=false;
	  		xmlDoc.loadXML(txt);
	  	}
		
		return xmlDoc;
	}	

function appendSizesRow()
{
		
		$("#itemDtl").remove();
		
		$("#itemDtlDiv").append(
				
			"<table class='tableClass' id='itemDtl' width='100%' style='text-align: left;'>" +
			
			"<thead><tr class='thClass'><th style='width:10%'><input type='checkbox' id='chkSizeDtl'></th><th>Item_Code</th><th>Description</th></tr></thead>" +
			
			"<tbody class='table-body fadeInDown'>" +
			
			"</tbody>" +
			
			"</table>"
		);
} 

function chkSizes(event, id)
	{
		if (event.target.type !== 'checkbox') 
		{
			if ( document.getElementById("chkid"+id).checked )
			{
				document.getElementById("chkid"+id).checked = false;
			}
			else
			{
				document.getElementById("chkid"+id).checked = true;
			}
		}
		
		sizeValues();
	}	

function checkAll()
{
	var id=document.getElementById("active").value;
	
	//alert("Active Tab="+id);
	
	if(document.getElementById("chkSizeDtl"+id).checked)
	{
		for (var i = 0;i<=document.getElementById("hide"+id).value; i++)
		{
			document.getElementById("chkid."+id+"."+i+"").checked = true
		}
	}
	else
	{
		for (var i = 0;i<=document.getElementById("hide"+id).value; i++)
		{
			document.getElementById("chkid."+id+"."+i+"").checked = false
		}
	}
	
}

function run(x)
{
	//alert("Active tab"+x);
	document.getElementById("active").value=x;
}

function isNumberKey(evt)
{
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
            {
				  alert('Enter only numeric value');
                  return false;
            }      
			else
			{
				return true;
			}	
}

function makexml()
{
	var tot=document.getElementById("fld").value;
	
	/*var supp_code=document.getElementById("supp_code").value;
	var purc_order=document.getElementById("purc_order").value;
	var ord_date=document.getElementById("ord_date").value;
	var dept_code=document.getElementById("dept_code").value;
	var item_ser=document.getElementById("item_ser").value;*/
	
	var data="<DATA>";
	var quan="";
	var code="";
	
	for(var i=1;i<=tot; i++)
	{
		if(document.getElementById("enter"+i) == undefined)
		{
			continue;
		}	
		
		else if(document.getElementById("enter"+i).value != "")
		{
			var quan=document.getElementById("enter"+i).value;
			var code=document.getElementById("enter"+i).title;
				
				data=data+"<record>"+
								"<quantity>"+quan+"</quantity>"+
								"<code>"+code+"</code>"+
								/*"<supp_code>"+supp_code+"</supp_code>"+
								"<purc_order>"+purc_order+"</purc_order>"+
								"<ord_date>"+ord_date+"</ord_date>"+
								"<dept_code>"+dept_code+"</dept_code>"+
								"<item_ser>"+item_ser+"</item_ser>"+*/
						  "</record>";
		}				  
		        
	}	
	
	data=data+"</DATA>";
	
	//alert(data);
	
	 var element = $( "input[name^='Detail2.0.']" );
		
		var DOMeles = element.get();
		
		var xmlString = "<?xml version = \"1.0\"?><Root><header><editFlag></editFlag></header>" +
				"<Detail1 domID='1' selected = 'N'>";
		
		for (var i = 0; i < DOMeles.length; i++)
		{
			if ( DOMeles[i] != null )
			{
				xmlString = xmlString + "<" + DOMeles[i].getAttribute('id') + ">" +
								"<![CDATA[" + DOMeles[i].getAttribute('value') + "]]>" +
								"</" + DOMeles[i].getAttribute('id') + ">";
			}
		}
		
	xmlString = xmlString + "</Detail1>" + data +"</Root>";
		
	alert(xmlString);
		
	document.getElementById("NEXT_FORM_VAL").value=xmlString;
	
	document.getElementById("porderWizFormII").action = "/ibase/PorderForm2Servlet";
	document.getElementById("porderWizFormII").submit();
}


/*function setCheckedTrue()
{
	//alert('ok');
	var tot=document.getElementById("fld").value;
	
	for(var i=1;i<=tot; i++)
	{
		if(document.getElementById("Detail2."+i+".quantity") == undefined)
		{
			continue;
		}	
		
		else if(document.getElementById("Detail2."+i+".quantity").value != "")
		{
			document.getElementById("Detail2."+i+".selectbox").checked = true;
			document.getElementById("Detail2."+i+".selectbox").value = true;
		}				  
	}
			
}*/


function setCheckedTrue()
{
	var tot=document.getElementById("fld").value;
	var count=0;
	
	for(var i=1;i<=tot; i++)
	{
		if(document.getElementById("Detail2."+i+".quantity") == undefined)
		{
			continue;
		}	
		
		else if(document.getElementById("Detail2."+i+".quantity").value != "")
		{
			document.getElementById("Detail2."+i+".selectbox").checked = true;
			document.getElementById("Detail2."+i+".selectbox").value = true;
		}
		
		else
		{
			count++;
		}				  
	}
	
	if(count==tot)
	{
		alert("Please enter at least 1 quantity...");
		return false;
	}
	
}


function dateChange(x)
{
	
	
	var element = $( "input[name^='dlv_date"+x+"']" );
		
		var DOMeles = element.get();
		
		var dateStr = document.getElementById("dlv_date"+x+"").value;
		//alert(dateStr);
		for (var i = 0; i < DOMeles.length; i++)
		{
			if ( DOMeles[i] != null )
			{
				var str = DOMeles[i].getAttribute('id');
				var nam = DOMeles[i].getAttribute('name');
				//alert("str  ["+str);
				//alert("name  ["+nam);
				var pax = "dlv_date_temp"+x+"";
				if(str == pax )
				{
					var tempVal = document.getElementById(pax).value;
					//alert(tempVal);
					
					var tempValStr = tempVal.split(",");
					for (var j = 0; j < tempValStr.length; j++)
					{
							//alert(tempValStr[j]);
							
							if(tempValStr[j] != "")
							{
								document.getElementById("Detail2."+tempValStr[j]+".dlv_date").value = dateStr
								//alert( document.getElementById("Detail2."+x+".dlv_date").value);
							}
					}
				}
				
			}
		}
		
		
	//alert( document.getElementById("dlv_date"+x+"").value);
	//document.getElementById("Detail2."+x+".dlv_date").value = document.getElementById("dlv_date"+x+"").value;
	//alert( document.getElementById("Detail2."+x+".dlv_date").value);
}

function changeAmount(x)
{
	var quantity=document.getElementById("Detail3."+x+".quantity").value;
	var rate=document.getElementById("Detail3."+x+".rate").value;
	
	var amount=quantity * rate;
	
	document.getElementById("Detail3."+x+".tot_amt").value=amount;
}

function form2Pre() 
{	
    	var element = $( "input[name^='Detail2.0.']" );
		
		var DOMeles = element.get();
		
		var xmlString = "<?xml version = \"1.0\"?><Root><header><editFlag></editFlag></header>" +
				"<Detail1 domID='1' selected = 'N'>";
		
		for (var i = 0; i < DOMeles.length; i++)
		{
			if ( DOMeles[i] != null )
			{
				xmlString = xmlString + "<" + DOMeles[i].getAttribute('id') + ">" +
								"<![CDATA[" + DOMeles[i].getAttribute('value') + "]]>" +
								"</" + DOMeles[i].getAttribute('id') + ">";
			}
		}
		
		xmlString = xmlString + "</Detail1></Root>";
		//alert(xmlString);
		document.getElementById("PRE_FORM_VAL").value = xmlString;
		
		setActionVal( "previous" );

		document.getElementById("porderWizFormII").action = "/ibase/PorderForm2Servlet";
		document.getElementById("porderWizFormII").submit();
}

function validate()
{
	if(document.getElementById("xyz").value == "")
	{
		alert("Please Select Supplier Code...!");
		return false;
	}
	
	else if(document.getElementById("itmser").value == "")
	{
		alert("Please Select Item Series...!");
		return false;
	}
	
	else if(document.getElementById("type").value == "")
	{
		alert("Please Select Purchase Order Type...!");
		return false;
	}
	
	else if(document.getElementById("trcode").value == "")
	{
		alert("Please Select Transporter Code...!");
		return false;
	}
	
	else if(document.getElementById("exch_rate").value == "")
	{
		alert("Please Enter Exchange Rate...!");
		return false;
	}
	
	else if(document.getElementById("dcode").value == "")
	{
		alert("Please Select Department Code...!");
		return false;
	}
	
}
