﻿function hideAllDropDowns()
{
    var ddls=document.getElementsByTagName('select');
    var i=0;
    for(i=0;i<ddls.length;i++)
    {
        if(ddls[i].className!="control_popup")
        {
            //ddls[i].style.display='none';
            ddls[i].style.visibility='hidden';
        }
    }
}

function showAllDropDowns()
{
    var ddls=document.getElementsByTagName('select');
    var i=0;
    for(i=0;i<ddls.length;i++)
    {
        if(ddls[i].className!="control_popup")
        {
            //ddls[i].style.display='inline';
            ddls[i].style.visibility='visible';
        }
    }
}
function isIE6()
{
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 
 if (ieversion>=6 && ieversion < 7)
  return true;
 else
  return false;
}
else
 return false;

}
function getIEVersion()
{
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 return ieversion;
 }
 else{
 return 1000;
 }
}
function addCommasIntoNumber(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function allowNumber(e)
    {
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
//alert(key);
     //if(key == 13)
     if( key!=8 && key!=0 && key!=46 && (key<48 || key>57))
          return false;
     else
          return true;
    }
function getCubicFeet(pieces,length,width,height,unit)
{
        var tempCF=0;
		
		if(unit=="inch"){
			tempCF=pieces*(length/12)*(height/12)*(width/12);			
		}
		if(unit=="cm"){
			tempCF=pieces*(length*0.0328)*(height*0.0328)*(width*0.0328);			
		}
		return tempCF;
}

function getCubicMeter(pieces,length,width,height,unit)
{        
		var tempM=0;
		if(unit=="inch"){		
			tempM=pieces*(length*0.0254)*(height*0.0254)*(width*0.0254);
		}
		if(unit=="cm"){		
			tempM=pieces*(length/100)*(height/100)*(width/100);
		}
		return tempM;
}
function getLBPerCubicFeet(cf,weight,weight_unit)
{
    if(cf==0){
        return 0;
    }
    var lbpf=0;
    if(weight_unit=='lb')
    {
        lbpf=weight/cf;
    }
    if(weight_unit=='kg')
    {
        lbpf=(weight/0.45)/cf;
    }
    return lbpf;
}
function getKGPerCubicMeter(cm,weight,weight_unit)
{
    if(cm==0){
        return 0;
    }
    var kgpm=0;
   
    if(weight_unit=='lb')
    {
        kgpm=(weight*0.45)/cm;
    }
    if(weight_unit=='kg')
    {
        kgpm=weight/cm;
    }
    return kgpm;
}
function getLB(val,weight_unit)
{
   if(val!=""){
        if(weight_unit=='kg')
        {
            return Math.ceil(parseFloat(val)/0.45);
        }
        else{
            return Math.ceil(val);
        }
   }
   else{
        return "";
   }
}
function getInches(val, dim_unit)
{        
		var tempM = 0;
		if (dim_unit == "inch")
		{		
			tempM = val;
		}
		else if(dim_unit == "cm")
		{		
			tempM = val * .393700787;
		}
		return tempM;
}

function addParcelRow(){
var line_no=parseInt(document.getElementById('total_lines_entry').value)+1;

//var html='<tr><td align="right">'+getClassHTML(line_no)+'</td><td align="right"><input type="text" id="lcl_weight_'+line_no+'" name="lcl_weight_'+line_no+'" onblur="setTotalWeightVolume();" class="lcl_txt" /></td><td align="right"><input type="text" id="lcl_pieces_'+line_no+'" name="lcl_pieces_'+line_no+'" onblur="setTotalWeightVolume();" class="lcl_txt" /></td><td align="right"><input type="text" id="lcl_length_'+line_no+'" name="lcl_length_'+line_no+'" onblur="setTotalWeightVolume();" class="lcl_txt" /></td><td align="right"><input type="text" id="lcl_width_'+line_no+'" name="lcl_width_'+line_no+'" onblur="setTotalWeightVolume();" class="lcl_txt" /></td><td align="right"><input type="text" id="lcl_height_'+line_no+'" name="lcl_height_'+line_no+'" onblur="setTotalWeightVolume();" class="lcl_txt" /></td><td align="right"><label id="lcl_volume_'+line_no+'"></label></td><td align="right"><label id="lcl_cubic_meters_'+line_no+'"></label></td></tr>';
var html="<tr>"+
	        "<td>                "+
                "<input type='text' id='txtQty"+line_no+"' name='txtQty"+line_no+"' /><span id='vldQty"+line_no+"' style='color:Red; display:none;'>*</span>"+
	        "</td>"+
	        "<td>                "+
                "<input type='text' id='txtWeight"+line_no+"' name='txtWeight"+line_no+"' style='width: 64px' /><span id='vldWeight"+line_no+"' style='color:Red; display:none;'>*</span>"+
                "<select id='ddlWeightUnit"+line_no+"' name='ddlWeightUnit"+line_no+"'>"+
                    "<option value='kg'>kg</option>" +
                    "<option value='lb'>lb</option>"+
                "</select>                "+
	        "</td>"+
	        "<td>"+	         
	                getPackageTypeHTML(line_no)+	         
	        "</td>"+
	        "<td>"+
	         "   <input type='text' id='txtLength"+line_no+"' name='txtLength"+line_no+"' style='width: 64px' /><span id='vldLength"+line_no+"' style='color:Red; display:none;'>*</span>"+
	        "</td>"+
	        "<td><input type='text' id='txtWidth"+line_no+"' name='txtWidth"+line_no+"' style='width: 64px' /><span id='vldWidth"+line_no+"' style='color:Red; display:none;'>*</span></td>"+
	        "<td><input type='text' id='txtHeight"+line_no+"' name='txtHeight"+line_no+"' style='width: 64px' /><span id='vldHeight"+line_no+"' style='color:Red; display:none;'>*</span></td>"+
	        "<td><select id='ddlDimensionUnit"+line_no+"' name='ddlDimensionUnit"+line_no+"'><option value='in'>in</option><option value='cm'>cm</option></select> (per piece)</td>"+	        
	        "<td>"+
	         "   &nbsp;"+
	        "</td>" +
            "<td style='width:155px;'><input type='checkbox' style='padding-left:27px;' onClick='ShowHazBox(" + line_no + ")' id='cbxHaz" + line_no + "' name='cbxHaz" + line_no + "' style='margin-left:50px;'/><br/> <input type='text' style='width:60px; display:none;' id='txtHaz" + line_no + "' name='txtHaz" + line_no + "' /><span id='spnUnNum"+ line_no +"' style='display:none;'>U.N. number</span></td>" +
	       "</tr>	 ";
//$('#tbl_lcl_entry tr:last').before(html);
$('#tbl_lcl_entry tr:last').after(html);

document.getElementById('total_lines_entry').value=line_no;

}


function deleteParcelLastRow(){
var line_no=parseInt(document.getElementById('total_lines_entry').value);
if(line_no > 1){
var tbl=document.getElementById('tbl_lcl_entry');
var lastRow = tbl.rows.length-1;
tbl.deleteRow(lastRow);

document.getElementById('total_lines_entry').value=line_no-1;

}

}

function getPackageTypeHTML(num){
    var html="<select id='ddlPackageType"+num+"' name='ddlPackageType"+num+"'>"+
    '<option value="19">Your Packaging</option>'+
    "</select>";
    return html;
}

    function GetRadioButtonValue(rbName,count)
    {
        var i=0;
        while(document.getElementById(rbName+"_"+i)!=null)
        {
            if(document.getElementById(rbName+"_"+i).checked){
                return document.getElementById(rbName+"_"+i).value;
            }
            i+=1;
        }
        return "";
    }
