// Use this js to get all values from each grid used. Just Copy a Section and paste 
//below for each new grid 

function GetValueFromGrid(){
//---------------------------------------
//Get final values from the General & Details Section
// Then transfer data tothe Database
//---------------------------------------

  	var str = ""
  	var Valn = new Array;  
	var Qty = "";

	if (validateArea()){

		Qty=document.getElementById("hDetail").value;
		Valn = Qty.split("|");
  
  	    var p = document.getElementById("RType").value;
		alert(p);
		if (p == 1){var radioValue = "Company";}
		if (p == 2){var radioValue = "Government Agencies";}
		if (p == 3){var radioValue = "Manifest";}
		if (p == 4){var radioValue = "Brokers";}
		
//------------------------------------- Start General Section ----------------------------------------
	  //Get data from the General Section of the Application
	  	str = str + "<?xml version=" + "\"1.0\"" + "?>" + "\n";
		//alert(str);
		str = str + "<REGISTRATION>" + "\n";
	//alert(document.getElementById("URCcheif").value);
		str = str + "\t" + "<DECOMPANY>" + "\n";
		str = str + "\t\t" + "<URCtype>" + escape(radioValue) + "</URCtype>"  + "\n";
		str = str + "\t\t" + "<URCgovagen>" + escape(document.getElementById("GovAgen").value) + "</URCgovagen>"  + "\n";	
		str = str + "\t\t" + "<URCacmode>" + escape(document.getElementById("ACMode").value) + "</URCacmode>"  + "\n";	
		str = str + "\t\t" + "<URCchief>" + escape(document.getElementById("URCcheif").value) + "</URCchief>"  + "\n";
		str = str + "\t\t" + "<URCnrn>" + escape(document.getElementById("URCnrn").value) + "</URCnrn>"  + "\n";
		str = str + "\t\t" + "<URCcomp>" + escape(document.getElementById("URCcomp").value) +  "</URCcomp>"  + "\n";
		str = str + "\t\t" + "<URCvat>" + escape(document.getElementById("URCvat").value) +  "</URCvat>"  + "\n";
		str = str + "\t\t" + "<URCadd1>" + escape(document.getElementById("URCadd1").value) +  "</URCadd1>"  + "\n";
		str = str + "\t\t" + "<URCadd2>" + escape(document.getElementById("URCadd2").value) +  "</URCadd2>"  + "\n";
		str = str + "\t\t" + "<URCcountry>" + escape(document.getElementById("URCcountry").value) +  "</URCcountry>"  + "\n";	
		str = str + "\t\t" + "<URCtel>" + escape(document.getElementById("URCtel").value) +  "</URCtel>"  + "\n";
		str = str + "\t\t" + "<URCemail>" + escape(document.getElementById("URCemail").value) +  "</URCemail>"  + "\n";
		str = str + "\t\t" + "<URCfax>" + escape(document.getElementById("URCfax").value) +  "</URCfax>"  + "\n";
		str = str + "\t\t" + "<URCcategory>" + escape(document.getElementById("URCcategory").value) +  "</URCcategory>"  + "\n";
		str = str + "\t\t" + "<URCloca>" + escape(document.getElementById("URCloca").checked) +  "</URCloca>"  + "\n";
		str = str + "\t\t" + "<URCloca2>" + escape(document.getElementById("URCloca2").checked) +  "</URCloca2>"  + "\n";
		str = str + "\t\t" + "<URCloca3>" + escape(document.getElementById("URCloca3").checked) +  "</URCloca3>"  + "\n";
								
		str = str + "\t" + "</DECOMPANY>" + "\n";
		


//------------------------------------- End Section ----------------------------------------


//------------------------------------- Start Grid-1 Sections ----------------------------------------
			
		//Collect data from Grid1 Details Table  
		gdObj = document.getElementById("Grid");
				
		for (i=1; i < gdObj.rows.length; i++) {
		//for (i=1; i < document.all.Grid.rows.length; i++) {
			//Get current row
			myrow = gdObj.getElementsByTagName("tr")[i];
			str = str + "\t" + "<ITEMS>" + "\n";
			for (j=0; j <  myrow.cells.length; j++) { 
			//for (j=0; j < document.all.Grid.rows[i].cells.length; j++) { 
				//Get current cell
				mycel = myrow.cells[j];				
				if(j==0){
					var bn, ValIT;
					bn = Valn[i-1];
					valIT = bn.split("^");
					
					//alert(valIT.length);
				}
				
				switch (j){
					case 0:
						str = str + "\t\t" + "<URuserAddress1>" + valIT[0] + "</URuserAddress1>"  + "\n";
	 					str = str + "\t\t" + "<URuserAddress2>" + valIT[1] + "</URuserAddress2>"  + "\n";
						str = str + "\t\t" + "<URCOO>" + valIT[2] + "</URCOO>"  + "\n";
						str = str + "\t\t" + "<URuserpwd2>" + valIT[3] + "</URuserpwd2>"  + "\n";
						//str = str + "\t\t" + "<URtele>" + valIT[4] + "</URtele>"  + "\n";
						str = str + "\t\t" + "<URemail>" + valIT[4] + "</URemail>"  + "\n";
						break;
					case 1:
						str = str + "\t\t" + "<URregnum>" + mycel.childNodes[0].data + "</URregnum>"  + "\n";
						break;			
					case 2:
						str = str + "\t\t" + "<URtele>" + mycel.childNodes[0].data + "</URtele>"  + "\n";																
						break;			
					case 3:
						str = str + "\t\t" + "<URuserfname>" + mycel.childNodes[0].data + "</URuserfname>"  + "\n";	
						break;			
					case 4:
						str = str + "\t\t" + "<URusermid>" + mycel.childNodes[0].data + "</URusermid>"  + "\n";	
						break;			
					case 5:	
						str = str + "\t\t" + "<URuserlname>" + mycel.childNodes[0].data + "</URuserlname>"  + "\n";
						break;			
					case 6:
						str = str + "\t\t" + "<URlogname>" + mycel.childNodes[0].data + "</URlogname>"  + "\n";
						break;			
					case 7:
						str = str + "\t\t" + "<URuserpwd1>" + mycel.childNodes[0].data + "</URuserpwd1>"  + "\n";						
						break;	
				}		
			}
			str = str + "\t" + "</ITEMS>"  + "\n";
		}			
	str = str + "</REGISTRATION>";
	
	//alert(str);
	document.getElementById("hxml").value = str;
	
	document.form1.action = '../../DB/InsertRegistration.php';
    document.form1.submit();
   } 	
 
 return;
}

function validateArea(){
//------------------------------------
//Validate General Section for errors
//------------------------------------
//ACMode

		//if (parseInt(document.getElementById("CLIENT_COMP").selectedIndex) == -1){ 
		//	alert("A valid warehouse from which goods will be removed must be specified.");
		//	return false; 
		//}

		if (document.getElementById("URCcheif").value == ""){ 
			alert("Owner/Agent is Required.");
			document.getElementById("URCcheif").select();
			document.getElementById("URCcheif").focus();
			return false; 
		}

		if (document.getElementById("URCnrn").value == "" && document.getElementById("URCvat").value == ""){ 
			alert("National Registration # or VAT Registration # must be specified.");
			document.getElementById("URCnrn").select();
			document.getElementById("URCnrn").focus();			
			return false; 
		}

		if (document.getElementById("URCcomp").value == ""){ 
			alert("Company Name is Required.");
			document.getElementById("URCcomp").select();
			document.getElementById("URCcomp").focus();	
			return false; 
		}						
	
		if (document.getElementById("URCadd1").value == ""){ 
			alert("Company address1 must be specified.");
			document.getElementById("URCadd1").select();
			document.getElementById("URCadd1").focus();	
			return false; 
		}

		if (document.getElementById("URCadd2").value == ""){ 
			alert("Company address2 must be specified.");
			document.getElementById("URCadd2").select();
			document.getElementById("URCadd2").focus();	
			return false; 
		}
	
		if (document.getElementById("URCcountry").value == ""){ 
			alert("Country of business must be specified.");
			document.getElementById("URCcountry").select();
			document.getElementById("URCcountry").focus();				
			return false; 
		}

		if (document.getElementById("URCtel").value == ""){ 
			alert("Telephone # must be specified.");
			document.getElementById("URCtel").select();
			document.getElementById("URCtel").focus();				
			return false; 
		}

		if (document.getElementById("URCemail").value == ""){ 
			alert("An Email account must be specified.");
			document.getElementById("URCemail").select();
			document.getElementById("URCemail").focus();				
			return false; 
		}

		if (document.getElementById("URCcategory").value == ""){ 
			alert("Category/Line Of business must be specified.");
			document.getElementById("URCcategory").select();
			document.getElementById("URCcategory").focus();				
			return false; 
		}

		if (!document.form1.URCloca.checked && !document.form1.URCloca2.checked && !document.form1.URCloca3.checked ){ 
			alert("A request to one of the locations provided must be specified.");
			document.form1.URCloca.select();
			document.form1.URCloca.focus();
			return false; 
		}


		return true;
		
}

//------------------------------------- End Section ----------------------------------------