
function AddFuelFee(op1,op2){
	var str = "";
	if(isFloat(op1)){
		str = (parseFloat(op1) + parseFloat(op2)).toFixed(2) + " %";
	}else{
		str = "<span class='red_h5'>Error</span>";
	}
	document.getElementById("fuel_surchage").innerHTML = str;
}

function setMaxLength(Object, max){
	return (Object.value.length <= max);
}


//-------------------------------------------------------------------------------------
// Function:		ValidateShipmentForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function isIllegalInput(input){
	var reg = /^([\d|\w|\.|\-|\s])*$/;
	return (reg.test(input)) ? false : true;
}

//-------------------------------------------------------------------------------------
// Function:		ValidateManageCurrencyForm(form)
// Parameters:      field's names
// Return:			enable or disable f2 base on f1 check
//-------------------------------------------------------------------------------------
function ValidateManageCurrencyForm(form){
	
	var status = true;
	var msg = "";
	var currency = form.currency_value.value;
	
	if(!isFloat(currency)){
		status = false;		
		msg = "Please Enter a Number";
	}

	document.getElementById("label_currency").innerHTML = "<span class=red_h5>"+msg+"</span>";

	return status;
}



//-------------------------------------------------------------------------------------
// Function:		enableDiscountField(f1,f2)
// Parameters:      field's names
// Return:			enable or disable f2 base on f1 check
//-------------------------------------------------------------------------------------
function enableDiscountField(f1,f2,zone){

	document.getElementById(f1).value =  Trim(document.getElementById(f1).value);
	
	if(f2 != ""){
		document.getElementById(f2).value =  Trim(document.getElementById(f2).value);
	}
	var value = document.getElementById(f1).value;
	
	document.getElementById("zone"+zone).align = "center";

	if(!isInt(value)){
		document.getElementById("zone"+zone).innerHTML = "<span class=red_h6><b>Zone " + zone +"</b></span>";
	}else{
		document.getElementById("zone"+zone).innerHTML = "<span class=blue_h6>Zone " + zone +"</span>";
	}

	if(f2 != ""){
		document.getElementById(f2).disabled = (!isInt(value)) ? true : false;
	}
}


//-------------------------------------------------------------------------------------
// Function:		enableDiscountField(f1,f2)
// Parameters:      field's names
// Return:			enable or disable f2 base on f1 check
//-------------------------------------------------------------------------------------
function validateZone(zone){

	var error = false;
	var status = true;

	// weight
	var w1 = document.getElementById("weight"+zone+"1").value;
	var w2 = document.getElementById("weight"+zone+"2").value;
	var w3 = document.getElementById("weight"+zone+"3").value;
	var w4 = document.getElementById("weight"+zone+"4").value;

	// discount
	var d1 = document.getElementById("discount"+zone+"1").value;
	var d2 = document.getElementById("discount"+zone+"2").value;
	var d3 = document.getElementById("discount"+zone+"3").value;
	var d4 = document.getElementById("discount"+zone+"4").value;

	//make sure both weight and discount for all ranges eigther filled or empty
	error = (xor(w1,d1) || xor(w2,d2) || xor(w3,d3) || xor(w4,d4));


	// Range 1 check
	// 1. if (w1,d1) are filled, they must be intergers
	if(!error && and(w1,d1)){
		error = (isInt(w1) && isInt(d1)) ? false : true;
	}

	// Range 2 check
	// 1. if (w2,d2) are filled, (w1,d1) must also be filled
	// 2. (w2,d2) must be integers
	// 3. (w2,d2) must be greater than (w1,d1) respectively
	if(!error){
		if(and(w2,d2)){
			error = !and(w1,d1);
			if(!error){
				error = (isInt(w2) && isInt(d2)) ? false : true;
				if(!error){
				//	error = (isGreaterThanOrEqual(w2,w1) && isGreaterThanOrEqual(d2,d1)) ? false : true;
					error = (isGreaterThan(w2,w1)) ? false : true;
				}
			}
		}
	}

	// Range 3 check
	// 1. if (w3,d3) are filled, (w1,d1),(w2,d2) must also be filled
	// 2. (w3,d3) must be integers
	// 3. (w3,d3) must be greater than (w1,d1) and (w2,d2) respectively
	if(!error){
		if(and(w3,d3)){
			error = !(and(w1,d1) && and(w2,d2));
			if(!error){
				error = (isInt(w3) && isInt(d3)) ? false : true;
				if(!error){
					//error = (isGreaterThanOrEqual(w3,w2) && isGreaterThanOrEqual(d3,d2)) ? false : true;
					error = (isGreaterThan(w3,w2)) ? false : true;
				}
			}
		}
	}

	// Range 4 check
	// 1. if (w4,d4) are filled, (w1,d1),(w2,d2),(w3,d3) must also be filled
	// 2. (w4,d4) must be integers
	// 3. (w4,d4) must be greater than (w1,d1), (w2,d2) and (w3,d3) respectively
	if(!error){
		if(and(w4,d4)){
			error = !(and(w1,d1) && and(w2,d2) && and(w3,d3));
			if(!error){
				error = (isInt(w4) && isInt(d4)) ? false : true;
				if(!error){
				//	error = (isGreaterThanOrEqual(w4,w3) && isGreaterThanOrEqual(d4,d3)) ? false : true;
					error = (isGreaterThanOrEqual(w4,w3)) ? false : true;
				}
			}
		}
	}
	
	status = (status) ? !error : status;

	document.getElementById("zone"+zone).align = "center";
	if(error){
		document.getElementById("zone"+zone).innerHTML = "<span class=red_h6><b>Zone " + zone +"</b></span>";
	}else{
		document.getElementById("zone"+zone).innerHTML = "<span class=blue_h6>Zone " + zone +"</span>";
	}

	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateShipmentForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateShipmentForm(form){

	var field = "";
	var error = true;
	var illegal = false;
	var status = true;
	var color = "black_h5";
	var date_valid = true;
	var carriage_declare = 0;
	var insurance_selected = form.insurance[0].checked;

	document.getElementById("message").innerHTML = "";

	//==========================================
	// Consignee Info
	//==========================================
	field = form.attention.value;
	illegal = isIllegalInput(field);
	error = (!isEmpty(field) && isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_attention").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Atencion:</span>";

	field = form.consignee_name.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_name").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Nombre:</span>";

	field = form.consignee_street.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_street").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Calle:</span>";

	field = form.consignee_city.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_city").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Ciudad:</span>";

	field = form.consignee_province.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_province").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Province:</span>";

	field = form.consignee_country.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_country").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Pais:</span>";

	field = form.consignee_zipcode.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_zipcode").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Zipcode:</span>";

	var phone = /^\d+$/;
	field = form.consignee_phone.value;
	field = field.replace(/\+|\-|\(|\)/g,"");
	error = (isEmpty(field) || !phone.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_consignee_phone").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Telefono:</span>";

	//==========================================
	// Shipper Info
	//==========================================
	field = form.send_by.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (!isEmpty(field) && isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_send_by").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Enviado por:</span>";

	field = form.shipper_name.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_name").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Nombre:</span>";

	field = form.shipper_street.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_street").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Calle:</span>";

	field = form.shipper_city.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_city").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Ciudad:</span>";

	field = form.shipper_province.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_province").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Provincia:</span>";

	field = form.shipper_country.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_country").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Pais:</span>";

	field = form.shipper_zipcode.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_zipcode").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Zipcode:</span>";

	var phone = /^\d+$/;
	field = form.shipper_phone.value;
	field = field.replace(/\+|\-|\(|\)/g,"");
	error = (isEmpty(field) || !phone.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_shipper_phone").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Telefono:</span>";

	//==========================================
	// Weight Info
	//==========================================
	field = form.pieces.value;
	error = (isEmpty(field) || !isInt(field) || isLessThan(field,1)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_pieces").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Piezas:</span>";

	var weight_error = false;
	field = form.weight.value;
	error = (isEmpty(field) || !isFloat(field)) ? true : false;
	// weight must be 0.5 and above
	if(!error){
		weight_error = (field < 0.5) ? true : false;
		error = weight_error;
	}
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_weight").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Peso: <span class=gray_h6>(min 0.5)</span></span>";

	field = form.carriage_declare.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_carriage_declare").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Valor Transporte:</span>";
	carriage_declare = field;

	field = form.custom_declare.value;
	error = (isEmpty(field) || !isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_custom_declare").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Valor Aduana:</span>";

	field = form.tender_date.value;
	date_valid = ValidateDate(field);
	error = (!date_valid) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_tender_date").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Fecha:</span>";

	field = form.description.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_description").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Descripcion de<br>&nbsp;&nbsp;&nbsp;Contenido:</span>";

	field = form.instruction.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}	
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("label_instruction").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;&nbsp;Instrucciones<br>&nbsp;&nbsp;&nbsp;Especiales:</span>";

	var message = "";
	
	if(status == false){	
		message = "<span class=red_h5>PLEASE ENTER VALID INPUT FOR RED FIELD</span>";
		if(illegal){
			message = "<span class=red_h5>SYSTEM ACCEPTS ONLY ALPHA, NUMERIC, DASH (-), DOT (.), AND SPACE</span>";
		}
		document.getElementById("message").innerHTML = message;
	}

	if(weight_error){
		message = "<span class=red_h5>PLEASE ENTER WEIGHT MINIMUM 0.5 AND ABOVE</span>";
		document.getElementById("message").innerHTML = message;
	}

	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateShipperAddUserForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateShipperAddUserForm(form){
	return ValidateHostAddUserForm(form);
}


//-------------------------------------------------------------------------------------
// Function:		ValidateHostAddUserForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHostAddUserForm(form){

	var field = "";
	var error = true;
	var status = true;
	var color = "black";
	var message = "";

	field = form.user_name.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("user_name").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;User Name:</span>";

	field = form.password.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("password").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Password:</span>";

	field = form.fname.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("fname").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;First Name:</span>";

	field = form.lname.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("lname").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Last Name:</span>";


	var phone = /^\d+$/;
	field = form.phone.value;
	field = field.replace(/\+|\-|\(|\)/g,"");
	error = (!isEmpty(field) && !phone.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("phone").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Phone:</span>";

	field = form.extension.value;
	field = field.replace(/\+|\-|\(|\)/g,"");
	error = (!isEmpty(field) && !phone.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("extension").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Extension:</span>";

	if(status == false){
		message = "PLEASE ENTER VALID INPUT FOR RED FIELD";
		document.getElementById("message").innerHTML = message;
	}

	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateHostUpdateShipperForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHostUpdateShipperForm(form){
	return ValidateHostAddShipperForm(form);
}



//-------------------------------------------------------------------------------------
// Function:		ValidateHostAddShipperForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHostAddShipperForm(form){

	var field = "";

	var illegal = false;
	var status = true;
	var color = "black";
	var error = true;
	var account_error = false;
	var stock_start_error = false;
	var stock_end_error = false;
	var stock_start = 0;
	var stock_end = 1;
	var feul_fee = "";

	var message = "";

	field = form.name.value;
	illegal = isIllegalInput(field);
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("name").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Name</span>";

	field = form.street.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("street").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Street</span>";


	field = form.city.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("city").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;City</span>";


	field = form.province.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("province").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Province</span>";

	field = form.zipcode.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("zipcode").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Zipcode</span>";

	field = form.country.value;
	if(illegal == false){
		illegal = isIllegalInput(field);
	}
	error = (isEmpty(field) || isIllegalInput(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("country").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Country</span>";


	var phone = /^\d+$/;
	field = form.phone.value;
	field = field.replace(/\+|\-|\(|\)/g,"");

	error = (isEmpty(field) || !phone.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("phone").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Phone</span>";


	field = form.fax.value;
	field = field.replace(/\+|\-|\(|\)/g,"");

	error = (!isEmpty(field) && !phone.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("fax").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Fax</span>";


	field = form.fuel_fee.value;
	error = (isEmpty(field) || !isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("fuel_fee").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Fuel Fee: %</span>";


	var account_format = /^\d+$/;
	field = form.account.value;
	error = (isEmpty(field) || !account_format.test(field)) ? true : false;
	account_error = error;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("account").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Account</span>";

	field = form.echamp_account.value;
	error = (isEmpty(field) || !account_format.test(field)) ? true : false;
	account_error = error;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("echamp_account").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;eChamp Account</span>";

	var awb_format = /^\d{8}$/;
	field = form.stock_control_start.value;
	field = field.replace(/\+|\-|\(|\)/g,"");
	error = (isEmpty(field) || !awb_format.test(field)) ? true : false;
	stock_start_error = error;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("stock_control_start").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Stock Control Start</span>";
	stock_start = field;

	field = form.stock_control_end.value;
	field = field.replace(/\+|\-|\(|\)/g,"");
	error = (isEmpty(field) || !awb_format.test(field)) ? true : false;
	stock_end_error = error;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("stock_control_end").innerHTML = "<span class=" + color + ">&nbsp;&nbsp;Stock Control End</span>";
	stock_end = field;

	// zone discount
	error = !validateZone("A");
	status = (status) ? !error : status;
	error = !validateZone("B");
	status = (status) ? !error : status;
	error = !validateZone("C");
	status = (status) ? !error : status;
	error = !validateZone("D");
	status = (status) ? !error : status;
	error = !validateZone("E");
	status = (status) ? !error : status;
	error = !validateZone("F");
	status = (status) ? !error : status;
	error = !validateZone("G");
	status = (status) ? !error : status;
	error = !validateZone("H");
	status = (status) ? !error : status;
	error = !validateZone("I");
	status = (status) ? !error : status;


	if(illegal){
		message = "<font size=2 color=red>SYSTEM ACCEPTS ONLY ALPHA, NUMERIC, DASH (-), DOT (.), AND SPACE</font>";
	}else if(account_error){
		message = "ACCOUNT MUST BE ALL DIGITS";
	}else if(stock_start_error){
		message = "STOCK CONTROL START MUST BE 8 DIGITS IN LENGTH";
	}else if(stock_end_error){
		message = "STOCK CONTROL END MUST BE 8 DIGITS IN LENGTH";
	}else if(stock_start >= stock_end){
		status = false;
		message = "STOCK CONTROL START MUST BE LESS THAN STOCK CONTROL END";
	}else if(status == false){
		message = "PLEASE ENTER VALID INPUT FOR RED FIELD";
	}

	if(status == false){
		document.getElementById("message").innerHTML = message;
	}
	
	return status;
}

//-------------------------------------------------------------------------------------
// Function:		ValidateUserUpdateAccountForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateUserUpdateAccountForm(form){
	var field = "";
	var error = true;
	var status = true;
	var color = "black";

	var message = "";

	field = form.fname.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("fname").innerHTML = "<span class=" + color + ">&nbsp;First Name:</span>";

	field = form.lname.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("lname").innerHTML = "<span class=" + color + ">&nbsp;Last Name:</span>";

	if(status == false){
		message = "PLEASE ENTER VALID INPUT FOR RED FIELD";
		document.getElementById("message").innerHTML = message;
	}
	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateUserChangePasswordForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateUserChangePasswordForm(form){
	var field = "";
	var error = true;
	var status = true;
	var color = "black";
	var new_password = "";
	var confirm_password = "";
	var message = "";
	var password_length = 3;

	field = form.new_password.value;
	error = (field.length < password_length) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("new_password").innerHTML = "<span class=" + color + ">&nbsp;New Password:</span>";
	new_password = field;

	field = form.confirm_password.value;
	error = (isEmpty(field) || field.length < password_length) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("confirm_password").innerHTML = "<span class=" + color + ">&nbsp;Confirm Password:</span>";
	confirm_password = field;

	// new password must match confirm password
	error = (new_password != confirm_password) ? true : false;
	status = (status) ? !error : status;

	if(status == false){
		var msg_one = "NEW PASSWORD MUST MATCH CONFIRM PASSWORD.";
		var msg_two = "PASSWORD MUST HAVE ATLEAST " + password_length + " CHARACTERS IN LENGTH.";
		message = (new_password != confirm_password) ? msg_one : msg_two;
		document.getElementById("message").innerHTML = message;
	}
	return status;	
}




//-------------------------------------------------------------------------------------
// Function:		ValidateHistoryForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHistoryForm(form){
	var d1 = form.from_date.value;
	var d2 = form.to_date.value;
	var status = compareDate(d1,d2);
	document.getElementById("message").innerHTML = "Select a date to view history";

	if(status == false){
		document.getElementById("message").innerHTML = "<span class=red_h5>From Date cannot be after To Date</span>";
	}
	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateTrackingForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateTrackingForm(form){

	var status = false;
	var tracking = form.awb.value;
	var awb_format = /^\d{8}$/;
	document.getElementById("message").innerHTML = "Enter Your Tracking Number";

	status = awb_format.test(tracking);

	if(status == false){
		document.getElementById("message").innerHTML = "<span class=red_h5>Invalid Tracking Number</span>";
	}

	return status;
}


//-------------------------------------------------------------------------------------
// Function:		Today()
// Parameters:      none
// Return:			return today in format dd/mm/yyyy
//-------------------------------------------------------------------------------------
function Today(){
	var d = new Date();
	var dd = d.getDate();
	var mm = d.getMonth() + 1;
	var yy = d.getFullYear();

	dd = (dd < 10) ? "0" + dd : dd;
	mm = (mm < 10) ? "0" + mm : mm;

	return dd + "/" + mm + "/" + yy;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateDate(input)
// Parameters:      input in format nn/nn/nnnn where n is a number
// Return:			true if input is in correct format, false otherwise
//-------------------------------------------------------------------------------------
function ValidateDate(input){
	var status = false;
	var date_format = /^\d{2}\/\d{2}\/\d{4}$/;

	if (date_format.test(input)){
		var input = input.split("/")[1] + "/" + input.split("/")[0] + "/" + input.split("/")[2];
		var date = new Date(input);
		var today = new Date();
		today = new Date((today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear());
		status = (date < today) ? false : true;
	}
	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateHostUpdateCountryTaxForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHostUpdateCountryTaxForm(form){

	var field = "";
	var error = true;
	var status = true;
	var color = "black";
	var message = "";

	field = form.tax.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("tax").innerHTML = "<span class=" + color + ">&nbsp;Tax:</span>";

	if(status == false){
		message = "PLEASE ENTER VALID INPUT FOR RED FIELD";
		document.getElementById("message").innerHTML = message;
	}

	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateHostAddCityForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHostAddCityForm(form){

	var field = "";
	var error = true;
	var status = true;
	var color = "black";
	var message = "";
	var city_code_length = 3;

	field = form.city.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("city").innerHTML = "<span class=" + color + ">&nbsp;City:</span>";

	field = form.city_code.value;
	error = (field.length < city_code_length) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("city_code").innerHTML = "<span class=" + color + ">&nbsp;City Code:</span>";

	field = form.country.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("country").innerHTML = "<span class=" + color + ">&nbsp;Country:</span>";

	field = form.country_code.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("country_code").innerHTML = "<span class=" + color + ">&nbsp;Country Code:</span>";


	if(status == false){
		var msg_one = "CITY CODE MUST HAVE EXACTLY " + city_code_length + " CHARACTERS IN LENGTH.";
		var msg_two = "PLEASE ENTER VALID INPUT FOR RED FIELD";
		message = (field.length < city_code_length) ? msg_one : msg_two;
		document.getElementById("message").innerHTML = message;
	}

	return status;
}

//-------------------------------------------------------------------------------------
// Function:		ValidateForgetPasswordForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateForgetPasswordForm(form){
	var field = "";
	var error = true;
	var status = true;
	var color = "black";

	field = form.email.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;

	if(status == false){
		var message = "<span class=" + color + ">&nbsp;Required</span>";
		document.getElementById("message").innerHTML = message;
	}

	return status;
}


//-------------------------------------------------------------------------------------
// Function:		ValidateHostUpdateInformationForm(form)
// Parameters:      form
// Return:			true if form's fields are valid
//-------------------------------------------------------------------------------------
function ValidateHostUpdateInformationForm(form){

	var field = "";
	var error = true;
	var status = true;
	var color = "black";

	field = form.name.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("name").innerHTML = "<span class=" + color + ">&nbsp;Name:</span>";

	field = form.airport_code.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("airport_code").innerHTML = "<span class=" + color + ">&nbsp;AirPort Code:</span>";

	field = form.system_address.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("system_address").innerHTML = "<span class=" + color + ">&nbsp;System Address:</span>";

	var prefix_format = /^\d{3}$/;
	field = form.prefix.value;
	error = (!prefix_format.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("prefix").innerHTML = "<span class=" + color + ">&nbsp;Prefix:</span>";

	var system_address_format = /^[A-Z]{7}$/;
	field = form.system_address.value;
	error = (!system_address_format.test(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("system_address").innerHTML = "<span class=" + color + ">&nbsp;System Address:</span>";

	field = form.address.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("address").innerHTML = "<span class=" + color + ">&nbsp;Address:</span>";

	field = form.city.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("city").innerHTML = "<span class=" + color + ">&nbsp;City:</span>";

	field = form.country.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("country").innerHTML = "<span class=" + color + ">&nbsp;Country:</span>";


	field = form.document_fee.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("document_fee").innerHTML = "<span class=" + color + ">&nbsp;Document Fee:</span>";

	field = form.fuel_fee.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("fuel_fee").innerHTML = "<span class=" + color + ">&nbsp;Fuel Fee:</span>";

	field = form.collect_fee.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("collect_fee").innerHTML = "<span class=" + color + ">&nbsp;Collect Fee:</span>";

	field = form.insurance_max.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("insurance_max").innerHTML = "<span class=" + color + ">&nbsp;Insurance Max:</span>";

	field = form.first_limit.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("first_limit").innerHTML = "<span class=" + color + ">&nbsp;Declare Value Upto:</span>";


	field = form.first_price.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("first_price").innerHTML = "<span class=" + color + ">&nbsp;Charge Amount:</span>";

	field = form.last_price.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("last_price").innerHTML = "<span class=" + color + ">&nbsp;Each Additional<br>&nbsp;Declared Amount Of:</span>";

	field = form.over_amount.value;
	error = (!isFloat(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("over_amount").innerHTML = "<span class=" + color + ">&nbsp;Charge Amount:</span>";

	field = form.notice_email.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("notice_email").innerHTML = "<span class=" + color + ">&nbsp;Shipping Notice:</span>";

	field = form.notice_subject.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("notice_subject").innerHTML = "<span class=" + color + ">&nbsp;Subject:</span>";

	field = form.alert_email.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("alert_email").innerHTML = "<span class=" + color + ">&nbsp;Low AWB Stock Notice:</span>";

	field = form.alert_subject.value;
	error = (isEmpty(field)) ? true : false;
	color = (error) ? "red_h5" : "black_h5";
	status = (status) ? !error : status;
	document.getElementById("alert_subject").innerHTML = "<span class=" + color + ">&nbsp;Subject:</span>";

	if(status == false){
		var message = "PLEASE ENTER VALID INPUT FOR RED FIELD";
		document.getElementById("message").innerHTML = message;
	}

	return status;
}
