
// Number of shipping item show function.

function show_blocks(value)
{

	divObj1 = document.getElementById('addDivs2');
	divObj1.innerHTML = '';
	for(var i=0;i < value;i++)
	{
		divObj1.innerHTML += '<h5 style="color:blue;">Item No. '+(i+1)+'</h5><div class="items"><span class="red">*</span>&nbsp;No. Shipping Units<br /><input type="text" name="shipment_unit[]" class="inptsmall" /></div><div class="items"><span class="red">*</span>&nbsp;Pkg. Type<br /><input type="text" name="pkg_type[]" class="inptsmall" /></div><div class="items"style="width:50px;">H/M<br/><br/><input type="checkbox" name="hm_chk[]" id="hm_'+(i+1)+'" onclick="javascript:hzShowHide('+(i+1)+')"/></div><div style="float:left;text-align:left;width:400px;display:none;" id="hzMaterial_'+(i+1)+'">Hazardous materials emergency contact number (if applicable)<br /><input type="text" name="hzMaterial[]" class="inptsmall" maxlength="12" onclick="javascript:getIt(this)" id="hzInpt_'+(i+1)+'" style="width:120px;" /></div><br class="clear" /><br /><br /><span class="red">*</span>&nbsp;Description of articles, special marks, and exceptions<br /><input type="text" name="desc[]" class="inptbig" /><br /><br /><div class="items">NMFC number<br /><input type="text" name="nmfc_number[]" class="inptsmall" /></div><div class="items"><span class="red">*</span>&nbsp;Class<br /><input type="text" name="class[]" class="inptsmall" /></div><div class="items"><span class="red">*</span>&nbsp;Weight (lb).<br /><input type="text" name="weight[]" class="inptsmall" /></div><div class="items">Length (in.)<br /><input type="text" name="length[]" class="inptsmall" /></div><div class="items">Width (in.)<br /><input type="text" name="width[]" class="inptsmall" /></div><div class="items">Height (in.)<br /><input type="text" name="height[]" class="inptsmall" /></div><br/><br/><br/><br /><br /><br /><hr />';
	}
}

function show_blocksdesc(value,descriptionlist)
{
var  descselect;
descselect='<select  name=desc[] class=slct_new >';

for(var i=0;i < descriptionlist.length ;i++)
{
descselect  +='<option value='+descriptionlist[i].split(' ').join('+')+' >'+descriptionlist[i]+'</option>';
}

descselect  +='</select>';

	divObj1 = document.getElementById('addDivs2');
	divObj1.innerHTML = '';

for(var i=0;i < value;i++)
	{

divObj1.innerHTML += '<h5 style="color:blue;">Item No. '+(i+1)+'</h5><div class="items"><span class="red">*</span>&nbsp;No. Shipping Units<br /><input type="text" name="shipment_unit[]" class="inptsmall" /></div><div class="items"><span class="red">*</span>&nbsp;Pkg. Type<br /><input type="text" name="pkg_type[]" class="inptsmall" /></div><div class="items"style="width:50px;">H/M<br/><br/><input type="checkbox" name="hm_chk[]" id="hm_'+(i+1)+'" onclick="javascript:hzShowHide('+(i+1)+')"/></div><div style="float:left;text-align:left;width:400px;display:none;" id="hzMaterial_'+(i+1)+'">Hazardous materials emergency contact number (if applicable)<br /><input type="text" name="hzMaterial[]" class="inptsmall" maxlength="12" onclick="javascript:getIt(this)" id="hzInpt_'+(i+1)+'" style="width:120px;" /></div><br class="clear" /><br /><br /><span class="red">*</span>&nbsp;Description of articles, special marks, and exceptions<br />'+descselect+'&nbsp;&nbsp;<br /><br /><div class="items">NMFC number<br /><input type="text" name="nmfc_number[]" class="inptsmall" /></div><div class="items"><span class="red">*</span>&nbsp;Class<br /><input type="text" name="class[]" class="inptsmall" /></div><div class="items"><span class="red">*</span>&nbsp;Weight (lb).<br /><input type="text" name="weight[]" class="inptsmall" /></div><div class="items">Length (in.)<br /><input type="text" name="length[]" class="inptsmall" /></div><div class="items">Width (in.)<br /><input type="text" name="width[]" class="inptsmall" /></div><div class="items">Height (in.)<br /><input type="text" name="height[]" class="inptsmall" /></div><br/><br/><br/><br /><br /><br /><hr />';
	}
}





		
// end here

// Hazardious material input field hide and show function.

function hzShowHide(id){

	if(document.getElementById("hm_"+id).checked != false)
		document.getElementById("hzMaterial_"+id).style.display = 'block';
	else
		document.getElementById("hzMaterial_"+id).style.display = 'none';
}

// End here.

// payor inout fields hide and show function.
function showHidePayor(str){

	switch(str){
		case 'Prepaid':
			document.getElementById('payorBox').style.display = 'none';
			break;
		case 'Collect':
			document.getElementById('payorBox').style.display = 'none';
			break;
		case '3rd Party':
			document.getElementById('payorBox').style.display = 'block';
			break;
		default:
			break;
	}
}

// End here

/* Validate the input fields of online bill or lading form */
function validateBillLadingForm(){

	var theForm = document.billOfLading;
	var msg = '';

	if(theForm.date.value.length == 0)
	{
		if(theForm.Date01.value.length == 0){
		msg += 'In valid date format\n';
		}
	}

	if(document.getElementById('isLogedIn').value == '1'){

		if(document.getElementById('Payor').checked != true && document.getElementById('Consignee').checked != true && document.getElementById('Shipper').checked != true)
		{
			msg += 'Please select either Shipper/Consignee/Payor.\n';
		}
	}

	// shipper info vaidation

	if(theForm.shipper_name.value.length == 0)
	{
		msg += 'Please enter shipper name.\n';
	}
	if(theForm.shipper_address.value.length == 0)
	{
		msg += 'Please enter shipper address.\n';
	}
	if(theForm.shipper_city.value.length == 0)
	{
		msg += 'Please enter shipper city.\n';
	}
// 	if(theForm.shipper_zip.value.length == 0)
// 	{
// 		msg += 'Please enter shipper Zip/Postal.\n';
// 	}

	if(theForm.shipper_zip.value.length == 0)
	{
		msg += 'Please enter shipper Zip/Postal.\n';
	}else{

		if(!isZip(theForm.shipper_zip.value)){

			msg += "Shipper Zip/Postal code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)\n";

		}
	}
	if(theForm.shipper_state.selectedIndex == 0)
	{
		msg += 'Please select shipper state.\n';
	}

	if(document.getElementById("shipper_phone").value.length > 0)
	{
		var pattern = /^\d{3}\-\d{3}\-\d{4}$/;
		if(!pattern.test(document.getElementById("shipper_phone").value)){
			msg += "Please enter valid phone number (eg:NNN-NNN-NNNN where N = number) for shipper information.\n";
		}
	}

	// consignee info vaidation

	if(theForm.cons_name.value.length == 0)
	{
		msg += 'Please enter consignee name.\n';
	}
	if(theForm.cons_address1.value.length == 0)
	{
		msg += 'Please enter consignee address.\n';
	}
	if(theForm.cons_city.value.length == 0)
	{
		msg += 'Please enter consignee city.\n';
	}
// 	if(theForm.cons_zip.value.length == 0)
// 	{
// 		msg += 'Please enter consignee Zip/Postal.\n';
// 	}

	if(theForm.cons_zip.value.length == 0)
	{
		msg += 'Please enter consignee Zip/Postal.\n';
	}else{

		if(!isZip(theForm.cons_zip.value)){

			msg += "Consignee Zip/Postal code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)\n";

		}
	}
	if(document.getElementById("cons_phone").value.length > 0)
	{
		var pattern = /^\d{3}\-\d{3}\-\d{4}$/;
		if(!pattern.test(document.getElementById("cons_phone").value)){
			msg += "Please enter valid phone number (eg:NNN-NNN-NNNN where N = number) for consignee information\n";
		}
	}
	// payor info vaidation

	if(document.getElementById('3rd_Party').checked == true){

		if(theForm.payor_name.value.length == 0)
		{
			msg += 'Please enter payor name.\n';
		}
		if(theForm.payor_address1.value.length == 0)
		{
			msg += 'Please enter payor address.\n';
		}
		if(theForm.payor_city.value.length == 0)
		{
			msg += 'Please enter payor city.\n';
		}
// 		if(theForm.payor_zip.value.length == 0)
// 		{
// 			msg += 'Please enter payor Zip/Postal.\n';
// 		}

		if(theForm.payor_zip.value.length == 0)
		{
			msg += 'Please enter payor Zip/Postal.\n';
		}else{
		
			if(!isZip(theForm.payor_zip.value)){
	
				msg += "Payor Zip/Postal code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)\n";
	
			}
		}

		if(document.getElementById("payor_phone").value.length > 0)
		{
			var pattern = /^\d{3}\-\d{3}\-\d{4}$/;
			if(!pattern.test(document.getElementById("payor_phone").value)){
				msg += "Please enter valid phone number (eg:NNN-NNN-NNNN where N = number) for payor information\n";
			}
		}
	}

	var shipMentUnit 	= document.getElementsByName('shipment_unit[]');
	var pkgType 		= document.getElementsByName('pkg_type[]');
	var desc 		= document.getElementsByName('desc[]');
	var cls 		= document.getElementsByName('class[]');
	var weight 		= document.getElementsByName('weight[]');

	var isEmptyShipMentUnit = true;
	var isEmptyPkgType 	= true;
	var isEmptyDesc 	= true;
	var isEmptyDesc 	= true;
	var isEmptyClass 	= true;
	var isEmptyWeight 	= true;


	for (var i=0;i<shipMentUnit.length;i++){

		if (shipMentUnit[i].value == ""){
			isEmptyShipMentUnit = false;
			break;
		}
	}
	if (!isEmptyShipMentUnit){
		msg += 'Please enter all fields of No.of shipment units.\n';
	}
	
	for (var i=0;i<pkgType.length;i++){

		if (pkgType[i].value == ""){
			isEmptyPkgType = false;
			break;
		}
	}
	if (!isEmptyPkgType){
		msg += 'Please enter all fields of package type.\n';
	}

	for (var i=0;i<desc.length;i++){

		if (desc[i].value == ""){
			isEmptyDesc = false;
			break;
		}
	}
	if (!isEmptyDesc){
		msg += 'Please enter all fields of description.\n';
	}

	for (var i=0;i<cls.length;i++){

		if (cls[i].value == ""){
			isEmptyClass = false;
			break;
		}
	}
	if (!isEmptyClass){
		msg += 'Please enter all fields of class.\n';
	}
	
	for (var i=0;i<weight.length;i++){

		if (weight[i].value == ""){
			isEmptyWeight = false;
			break;
		}else{
			if(!isInteger(weight[i].value))
			isEmptyWeight = false;
			break;			
		}
	}
	
	if (!isEmptyWeight){
		msg += 'Please enter all fields of weight.\n';
	}
	var hm = document.getElementsByName('hm_chk[]');

	for(var i=0;i < hm.length;i++){
		if(document.getElementById("hm_"+(i+1)).checked != false)
		{
			if(document.getElementById("hzInpt_"+(i+1)).value == ""){
				msg += "Please enter valid Hazardous materials emergency contact number (eg:NNN-NNN-NNNN where N = number) for Item No "+(i+1)+"\n";
			}else{
				var pattern = /^\d{3}\-\d{3}\-\d{4}$/;
				if(!pattern.test(document.getElementById("hzInpt_"+(i+1)).value)){
					msg += "Please enter valid Hazardous materials emergency contact number (eg:NNN-NNN-NNNN where N = number) for Item No "+(i+1)+"\n";
				}
			}
		}
	}
	if(msg != "")
	{
		alert("Errors:\n"+msg);
		return false;
	}else{
		return true
	}
}

// End here
function isInteger(s)
	{   
	 	var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}

/* print function for online bill */

function print_page(strId,goUrl)
{	
	Cont = document.getElementById(strId).innerHTML;
	frog = window.open("","wildebeast","width=800px,height=600,scrollbars=0,resizable=1");
	html = "<html><head></head><body>"+Cont+"</center></body></html>";
	frog.document.open();
	frog.document.write(html);
	frog.document.getElementById("bt").style.display = "none";
	frog.print();
	frog.document.close();	
	frog.close();
	setTimeout("redirect('','"+goUrl+"')",1000);
		
}


/*
function : print_NewPage()
desc : To print generated BOl page
called from : online-bill-lading.php.
*/
function print_NewPage(strId,goUrl)
{	
	if(confirm("Are you really want to print form?")){
		document.getElementById("bt").style.display = "none";
		window.print();
		setTimeout("redirect('','"+goUrl+"')",1000);
	}else{
		location.href="online-bill-ladingn.php";
		}
	
}


function print_MyNewPage(strId,goUrl)
{	
	document.getElementById("bt").style.display = "none";
	window.print();
	setTimeout("redirect('','"+goUrl+"')",1000);
}
/* End here */

/*
function : getIt and ValidatePhone()
desc : format the phone number
called from : online-bill-lading.php.php 

*/
function getIt(m){

	n=m.name;
	i = m.id;
	p1=m;
	ValidatePhone();
}

var n;
var p;
var p1;
var i;

function ValidatePhone(){

	var p=p1.value;
	if(p.length>3){
		d1=p.indexOf('(');
		d2=p.indexOf('-');
		if (d2==-1){

			l30=p.length;
			p30=p.substring(0,3);
			p30=p30+"-"
			p31=p.substring(3,l30);
			pp=p30+p31;
			document.getElementById(i).value = "";
			document.getElementById(i).value = pp;
		}
	}

	if(p.length>5){
	
		p11=p.substring(d1+1,d2);
		if(p11.length>3){

			p12=p11;
			l12=p12.length;
			l15=p.length;
			p13=p11.substring(0,3);
			p14=p11.substring(3,l12);
			p15=p.substring(d2+1,l15);
			document.getElementById(i).value = "";
			pp="("+p13+")"+p14+p15;
			document.getElementById(i).value = pp;

		}

		l16=p.length;
		p16=p.substring(d2+1,l16);
		l17=p16.length;
		if(l17>3&&p16.indexOf('-')==-1){
	
			p17=p.substring(d2+1,d2+4);
			p18=p.substring(d2+4,l16);
			p19=p.substring(0,d2+1);
			pp=p19+p17+"-"+p18;
			document.getElementById(i).value = "";
			document.getElementById(i).value = pp;
		}
	}

	setTimeout(ValidatePhone,100);
}

/* End here */


/*
function : validatetransit()
desc : Zip validation
called from : transit.php
*/
function validatetransit(){
		var msg = '';
	if(trim(document.getElementById('Ozip').value) == ""){
	msg += 'Please enter Origin Zip\n';
	}else{

		if(!isZip(trim(document.getElementById('Ozip').value))){

			msg += "Origin Zip code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)";
		}
	}
	if(trim(document.getElementById('Dzip').value) == ""){
	msg += 'Please enter Destination Zip\n';
	}else{

		if(!isZip(trim(document.getElementById('Dzip').value))){

			msg += "Destination Zip code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)";

		}
	}

	if(msg != "")
	{
		alert("Errors:\n"+msg);
		return false;
	}else{
		return true
	}
}




/*
function : validateUseraddress()
desc : user address validation
called from : userAdd.php

*/
function validateUseraddress(){

	var theForm = document.custAddressFrm;
	var msg = '';

//         if(theForm.custNum.value.length == 0)
// 	{
// 		msg += 'Customer number is required\n';
// 	}
	if(!theForm.custNum.value.length == 0)
	{
	if(!alphanumeric(theForm.custNum.value)){
		msg += "Customer number is not valid .\n (Must be Alphanumeric character.)\n";
	}

	}

	if(theForm.storename.value.length == 0)
	{
		msg += 'Store name is required\n';
	}else{
			if(checkIsSpecial(theForm.storename.value)){
				msg += "Following special characters are not allowed:\n( ? ^ : , } ] [ { ) + = \ |) for Store Name. \n";
			}
		}

	if(theForm.address.value.length == 0)
	{
		msg += 'Address is required\n';
	}else{
			if(checkIsSpecial(theForm.address.value)){
				msg += "Following special characters are not allowed:\n( ? ^ : , } ] [ { ) + = \ |) for Address \n";
			}
		}

	if(theForm.city.value.length == 0)
	{
		msg += 'City is required\n';
	}else{
			if(checkIsSpecial(theForm.city.value)){
				msg += "Following special characters are not allowed:\n( ? ^ : , } ] [ { ) + = \ |) for City \n";
			}
		}

	if(theForm.state.value.length == 0)
	{
		msg += 'state is required\n';
	}

	if(theForm.Zip.value.length == 0)
	{
		msg += 'Zip is required\n';
	}else{

		if(!isZip(theForm.Zip.value)){

			msg += "Zip/Postal code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)";

		}
	}

	if(theForm.Phone.length == 0)
	{
		msg += 'Phone is required\n';
	}else{
		var pattern = /^\d{3}\-\d{3}\-\d{4}$/;

		if(!pattern.test(theForm.Phone.value)){

			msg += "Please enter valid phone number (eg:NNN-NNN-NNNN where N = number)\n";

		}

	}




	if(msg != "")
	{
		alert("Errors:\n"+msg);
		return false;
	}else{
		return true
	}
}

// Validation for customer address

function validateUserdescription()
{


var theForm = document.custDescriptionFrm;
var msg = '';


if(theForm.description.value.length == 0)
	{
		msg += 'Description  is required\n';
	}


if(msg != "")
	{
		alert("Errors:\n"+msg);
		return false;
	}else{
		return true
	}



}



// Validation for Alpha-Numeric character
	function alphanumeric(alphane){
	var regex=/^[0-9A-Za-z]+$/; 
	if(!regex.test(alphane)){
		return false;
	} else {
		return true;
		}
	}
	
// Zip code validation	
	function isZip(s)
	{
		reZip = new RegExp(/(^\d{5}$)|(^[A-Za-z]{1}\d{1}[A-Za-z]{1} *\d{1}[A-Za-z]{1}\d{1}$)/);
		
		if (!reZip.test(s)) {
			return false;
		}else{
			return true;
		}
	
	}

// Special character validation
function checkIsSpecial(val){

	var charsInBag = "?^:,}][{)+=\|";
	flag = 0;
	for(var i=0;i < val.length;i++){
		
		for(var j=0;j < charsInBag.length;j++){
			if(val.charAt(i) == charsInBag.charAt(j)){
				flag = 1;
			}
		}
	}
	if(flag == 1)
	{
		return true;
	}else{
		return false;
	}
}
// called: from online-bill-ladingn.php
function print_pagen(goUrl)
{
	var ret = true;
	var goUrl = goUrl;
	//if(ret == true)
	if(validateBillLadingForm())
	{
		if(confirm("Are you really want to print and schedule this form form?")){

			window.print();
			var shipper_name 	= document.getElementById('shipper_name').value;
			var shipper_address 	= document.getElementById('shipper_address').value;
			var shipper_city 	= document.getElementById('shipper_city').value;
			var shipper_zip 	= document.getElementById('shipper_zip').value;
			var shipper_state 	= document.getElementById('shipper_state').value;
			var shipper_phone 	= document.getElementById('shipper_phone').value;
			var pcs 		= document.getElementsByName('shipment_unit[]')[0].value;
			var weight 		= document.getElementsByName('weight[]')[0].value;
			var hm_chk 		= document.getElementsByName('hm_chk[]')[0].checked;

			var cons_name		= document.getElementById('cons_name').value;
			var cons_zip 		= document.getElementById('cons_zip').value;


			var creatQuery 		= "?";
			if(document.getElementById('Payor').checked == true)
			{
				creatQuery += "&am=Neither";
			}
			if(document.getElementById('Consignee').checked == true)
			{
				creatQuery += "&am=Consignee";
			}
			if(document.getElementById('Shipper').checked == true)
			{
				creatQuery += "&am=Shipper";
			}
			if(shipper_name != ""){
				creatQuery += "&sn="+shipper_name;
			}
			if(shipper_address != ""){
				creatQuery += "&sa="+shipper_address;
			}
			if(shipper_city != ""){
				creatQuery += "&sc="+shipper_city;
			}
			if(shipper_zip != ""){
				creatQuery += "&sz="+shipper_zip;
			}

			if(shipper_state != ""){
				creatQuery += "&sst="+shipper_state;
			}
			
			if(cons_name != ""){
				creatQuery += "&cn="+cons_name;
			}
			if(cons_zip != ""){
				creatQuery += "&cz="+cons_zip;
			}

			if(pcs != ""){
				creatQuery += "&pcs="+pcs;
			}
			if(weight != ""){
				creatQuery += "&wt="+weight;
			}
			if(hm_chk != ""){
				creatQuery += "&hm_chk="+hm_chk;
			}
			setTimeout("redirect('"+creatQuery+"','"+goUrl+"')",1000);
		}
	}
}

function print_pageLogOut(goUrl)
{
	var ret = true;
	var goUrl = goUrl;
	//if(ret == true)
	if(validateBillLadingForm())
	{
		if(confirm("Are you really want to print and schedule this form form?")){

			window.print();
			var shipper_name 	= document.getElementById('shipper_name').value;
			var shipper_address 	= document.getElementById('shipper_address').value;
			var shipper_city 	= document.getElementById('shipper_city').value;
			var shipper_zip 	= document.getElementById('shipper_zip').value;
			var shipper_state 	= document.getElementById('shipper_state').value;
			var shipper_phone 	= document.getElementById('shipper_phone').value;
			var pcs 		= document.getElementsByName('shipment_unit[]')[0].value;
			var weight 		= document.getElementsByName('weight[]')[0].value;
			var hm_chk 		= document.getElementsByName('hm_chk[]')[0].checked;

			var cons_name		= document.getElementById('cons_name').value;
			var cons_zip 		= document.getElementById('cons_zip').value;


			var creatQuery 		= "?&am=Neither";
// 			if(document.getElementById('Payor').checked == true)
// 			{
// 				creatQuery += "&am=neither";
// 			}
// 			if(document.getElementById('Consignee').checked == true)
// 			{
// 				creatQuery += "&am=consignee";
// 			}
// 			if(document.getElementById('Shipper').checked == true)
// 			{
// 				creatQuery += "&am=shipper";
// 			}
			if(shipper_name != ""){
				creatQuery += "&sn="+shipper_name;
			}
			if(shipper_address != ""){
				creatQuery += "&sa="+shipper_address;
			}
			if(shipper_city != ""){
				creatQuery += "&sc="+shipper_city;
			}
			if(shipper_zip != ""){
				creatQuery += "&sz="+shipper_zip;
			}

			if(shipper_state != ""){
				creatQuery += "&sst="+shipper_state;
			}
			
			if(cons_name != ""){
				creatQuery += "&cn="+cons_name;
			}
			if(cons_zip != ""){
				creatQuery += "&cz="+cons_zip;
			}

			if(pcs != ""){
				creatQuery += "&pcs="+pcs;
			}
			if(weight != ""){
				creatQuery += "&wt="+weight;
			}
			if(hm_chk != ""){
				creatQuery += "&hm_chk="+hm_chk;
			}
			setTimeout("redirect('"+creatQuery+"','"+goUrl+"')",1000);
		}
	}
}


function redirect(str,goUrl){
	window.location=goUrl+str;
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

// function: buildPopUp()
// Called : From online-bill-lading.php
// Desc: To generate URL and open pop up

function buildPopUp(mypage,myname,w,h,scroll,pos,nametype){
	
	switch(nametype){
		case 'shipper':
				var shipper_name  	= trim(document.getElementById('shipper_name').value);
				var shipper_address  	= trim(document.getElementById('shipper_address').value);
				var shipper_city  	= trim(document.getElementById('shipper_city').value);
				var shipper_state  	= trim(document.getElementById('shipper_state').value);
				var shipper_zip  	= trim(document.getElementById('shipper_zip').value);
				var shipper_phone  	= document.getElementById('shipper_phone').value;
 				var shipper_number  	= document.getElementById('shipper_number').value;
			break;
		case 'consignee':
 				var shipper_name  	= trim(document.getElementById('cons_name').value);
				var shipper_address  	= trim(document.getElementById('cons_address1').value);
				var shipper_city  	= trim(document.getElementById('cons_city').value);
				var shipper_state  	= trim(document.getElementById('cons_state').value);
				var shipper_zip  	= trim(document.getElementById('cons_zip').value);
				var shipper_phone  	= document.getElementById('cons_phone').value;
				var shipper_number  	= document.getElementById('cons_number').value;
			break;
		default:
			break;
			}

	var creatQuery 		= "";
	
	if(shipper_name != ""){
		creatQuery += "&sn="+shipper_name;
	}
	if(shipper_address != ""){
		creatQuery += "&sa="+shipper_address;
	}
	if(shipper_city != ""){
		creatQuery += "&sc="+shipper_city;
	}
	if(shipper_zip != ""){
		creatQuery += "&sz="+shipper_zip;
	}
	if(shipper_state != ""){
		creatQuery += "&sst="+shipper_state;
	}
	if(shipper_phone != ""){
		creatQuery += "&sph="+shipper_phone;
	}
	if(shipper_number != ""){
		creatQuery += "&cnum="+shipper_number;
	}
	if(pos=="center"){

		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;

	}else if((pos!="center" && pos!="random") || pos==null){

		LeftPosition=0;
		TopPosition=20;
	}

	mypage = mypage+creatQuery;
		
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	
	win=window.open(mypage,myname,settings);
}

function buildPopUp2(mypage,myname,w,h,scroll,pos,nametype){
	
	switch(nametype){
		case 'description':
				var description_name  	= trim(document.getElementById('description').value);
				
			break;
		
		default:
			break;
			}

	var creatQuery 		= "";
	
	if(description_name != ""){
		creatQuery += "&dn="+description_name;
	}
	
	if(pos=="center"){

		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;

	}else if((pos!="center" && pos!="random") || pos==null){

		LeftPosition=0;
		TopPosition=20;
	}

	mypage = mypage+creatQuery;
		
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	
	win=window.open(mypage,myname,settings);
}










function NewWindow(mypage,myname,w,h,scroll,pos){

	//mypage = mypage+url;
	
	if(pos=="center"){

		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;

	}else if((pos!="center" && pos!="random") || pos==null){

		LeftPosition=0;
		TopPosition=20;
	}

	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	
	win=window.open(mypage,myname,settings);
	
}

// Function: validateShipConsBox()
// Called : From online-bill-lading.php
// Desc:   To validate the shipper and consignee box field values.


function validateShipConsBox(bx){

	var theForm = document.billOfLading;
	var msg = '';

	// shipper info vaidation
	switch(bx){
		case 'shipper':
				if(theForm.shipper_name.value.length == 0)
				{
					msg += 'Please enter shipper name.\n';
				}
				if(theForm.shipper_address.value.length == 0)
				{
					msg += 'Please enter shipper address.\n';
				}
				if(theForm.shipper_city.value.length == 0)
				{
					msg += 'Please enter shipper city.\n';
				}
// 				if(theForm.shipper_zip.value.length == 0)
// 				{
// 					msg += 'Please enter shipper Zip/Postal.\n';
// 				}
				if(theForm.shipper_zip.value.length == 0)
					{
						msg += 'Please enter shipper Zip/Postal.\n';
					}else{
				
						if(!isZip(theForm.shipper_zip.value)){
				
							msg += "Zip/Postal code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)";
				
						}
					}
				if(theForm.shipper_state.selectedIndex == 0)
				{
					msg += 'Please select shipper state.\n';
				}
				
				if(document.getElementById("shipper_phone").value.length > 0)
				{
					var pattern = /^\d{3}\-\d{3}\-\d{4}$/;
					if(!pattern.test(document.getElementById("shipper_phone").value)){
						msg += "Please enter valid phone number (eg:NNN-NNN-NNNN where N = number) for shipper information\n";
					}
				}
				break;
		case 'consignee':
				if(theForm.cons_name.value.length == 0)
				{
					msg += 'Please enter consignee name.\n';
				}
				if(theForm.cons_address1.value.length == 0)
				{
					msg += 'Please enter consignee address.\n';
				}
				if(theForm.cons_city.value.length == 0)
				{
					msg += 'Please enter consignee city.\n';
				}
// 				if(theForm.cons_zip.value.length == 0)
// 				{
// 					msg += 'Please enter consignee Zip/Postal.\n';
// 				}

				if(theForm.cons_zip.value.length == 0)
					{
						msg += 'Please enter consignee Zip/Postal.\n';
					}else{
				
						if(!isZip(theForm.cons_zip.value)){
				
							msg += "Zip/Postal code is not valid (e.g ##### or @#@#@# or @#@ #@#).\n# = Number.\n@ = Any Alphanumeric character.)";
				
						}
					}
				if(theForm.cons_state.selectedIndex == 0)
				{
					msg += 'Please select consignee state.\n';
				}
				
				if(document.getElementById("cons_phone").value.length > 0)
				{
					var pattern = /^\d{3}\-\d{3}\-\d{4}$/;
					if(!pattern.test(document.getElementById("cons_phone").value)){
						msg += "Please enter valid phone number (eg:NNN-NNN-NNNN where N = number) for consignee information\n";
					}
				}
				break;
		default:
				break;	
		}

	if(msg != "")
	{
		alert("Errors:\n"+msg);
		return false;
	}else{
		return true
	}

}
