// JavaScript Document
var CONST_airm_postcards = 50;		// airmail rate for sending postcards to an location
var ParcelRates_4country = new Array;





function calc_LocalLetter(weight){
	if(weight>=0 && weight<=.23)		{return 30;}
	if(weight>.23 && weight<=.45)	{return 60;}
	if(weight>.45 && weight<=2)		{return 100;}
	
	return 'N/A : Exceed\'s 2kg Limit';
}

function calc_LocalParcel(weight){
	if(weight<=.5){return 80}
	if(weight>.5){
		overrun_mod = (weight/.5);
		if(isFloat(overrun_mod)){ return (parseInt(overrun_mod)+1)*80;}else{
				return parseInt(overrun_mod)*.80;
		}
	}
}


function calc_PrintPapers(weight){
	if(weight>=0 && weight<=.35)		{return 30;}
	if(weight>.35 && weight<=.45)	{return 40;}
	if(weight>.45 && weight<=2)		{return 60;}
	
	return 'N/A';
}

// SURFACE AIRLIFT
function calc_sair_PrintPaper(weight){
	if(weight>=0 && weight<=.03)		{return 60;}
	if(weight>.03 && weight<=.11)	{return 70;}
	if(weight>.11 && weight<=.23)	{return 80;}		
	if(weight>.23 && weight<=.45)	{return 90;}		
	if(weight>.45 && weight<=1)		{return 115;}		
	if(weight>1 && weight<=2)			{return 170;}		

//each additional KG greater than 2kilo
	if(weight>2){
			overrun_mod = (weight/2);
			if(isFloat(overrun_mod)){return (parseInt(overrun_mod)*90)+170;}else{ return ((overrun_mod-1)*90)+170;}
	}

}

function calc_sair_Books(weight){
	if(weight>=0 && weight<=2)		{return 200;}
	if(weight>2 && weight<=3)			{return 260;}
	if(weight>3 && weight<=4)			{return 360;}		
	if(weight>4 && weight<=5)			{return 430;}
	if(weight>5)									{return 'N/A : Exceed\'s 2kg Limit';}
}

function calc_sair_Packets(weight){
	if(weight>=0 && weight<=.11)		{return 60;}
	if(weight>.11 && weight<=.23)	{return 70;}
	if(weight>.23 && weight<=.45)	{return 80;}		
	if(weight>.45 && weight<=1)		{return 115;}	
	if(weight>1)									{return 'N/A : Exceed\'s 1kg Limit';}	
}

// AIRMAIL TO
function calc_airm_letters(weight,country){
		// ensure country exist and load values into array
		if(!loadCountry_ParcelRates(country)){ alert('No Country Found!'); return false;}
		
		
	var rate;
		switch(ParcelRates_4country.cells[8].innerHTML.toLowerCase()){
				case 'americas': 	rate = 60; break;
				case 'europe': 		rate = 70; break;
				case 'asia':		 	rate = 90; break;
				default: return 'N/A: Region Not Found';
		};

		if(weight<=.015){ return rate;}
		if(weight>.015){
			overrun_mod = (weight/.015);
			alert(overrun_mod);
			if(isFloat(overrun_mod)){
					return (parseInt(overrun_mod)+1)*rate;
			}else{
					return parseInt(rate)*overrun_mod;
			}
		}
}

function calc_airm_parcel(weight,country){
		// ensure country exist and load values into array
		if(!loadCountry_ParcelRates(country)){ alert('No Country Found!'); return false;}

		if(weight<=.5){
			// extract the value from the row cell
			i_value = ParcelRates_4country.cells[6].innerHTML;
			//	alert(isAlphabetic(i_value)+":"+typeof(i_value));
			if(isAlphabetic(i_value)){return  i_value;}
			if(isFloat(i_value)){return parseFloat(i_value);}else{return  i_value;}
		}else{
			if(weight>.5){
					// extract the value from the row cell

					i_value 				= ParcelRates_4country.cells[6].innerHTML;
					i2_value 			= ParcelRates_4country.cells[7].innerHTML;					
					overrun_mod 	= (weight/.5);

					if(isAlphabetic(i_value)){return  i_value;}
					if(isFloat(overrun_mod)){
							return (parseInt(overrun_mod)*i2_value)+parseInt(i_value);
					}else{ 
							return ((overrun_mod-1)*i2_value)+parseInt(i_value);
					}
			}
		}

}


function calc_sair_parcel(weight,country){
		// ensure country exist and load values into array
		if(!loadCountry_ParcelRates(country)){ alert('No Country Found!'); return false;}
		
		
		if(weight<=1){
			return ParcelRates_4country.cells[2].innerHTML;
		}
		if(weight>1 && weight<=3){
			return ParcelRates_4country.cells[3].innerHTML;			
		}
		if(weight>3 && weight<=5){
			return ParcelRates_4country.cells[4].innerHTML;			
		}
		if(weight>5 && weight<=10){
			return ParcelRates_4country.cells[5].innerHTML;			
		}
		if(weight>10){
				alert("Please consult customer relations, weight not applicable!")
				return false;
		}
}

function loadCountry_ParcelRates(country){
		var srcFlag=false;
	// ensure the table of parcel rates exists
	if(document.getElementById("IntParcelRates")){ PRate_0 = document.getElementById("IntParcelRates");}

			//find the rates for the country
			for(i=0;i< PRate_0.rows.length;i++){
				PRate_row = PRate_0.rows[i];
				ParseTxt = PRate_row.cells[1].innerHTML.toLowerCase();
				if(ParseTxt.search(country.toLowerCase())>=0 || ParseTxt == country.toLowerCase()){srcFlag=true;ParcelRates_4country = PRate_row; break;}
			}
	
	return srcFlag;
}
