function callValidate()
{
var checkResult = false;

	if (validatePrefix())
   {
	   if (validateAWBNumber())
      { 
          if (validateOrigin())
          {
		if (validateDest())
              {
	               if (validatePieceCount())
                  {
	                   if (validateWeight())
                      { 
					  		if (validateOrigindest())
                      		{ 
				checkResult = true;                        
                     	}	
					  }
                   }
                }
            }
        }
    }
	return checkResult;
}



// validation for the AWB Prefix field - only value currently allowed is 125
function validatePrefix()
{
	if (window.document.barcodeForm.AWBPREFIX.value.length != 3) 
	{
		window.alert("Please enter a correct AWB Prefix: it must consist of 3 Numerics.");
		return false;
	}	else	{
		return true;
	}
}

// Validation for the AWB number - the number is checked for length
// and then a checksum calculation is performed to ensure validity
function validateAWBNumber()
{
	awb1 = window.document.barcodeForm.AWBNUM1.value;
	awb2 = window.document.barcodeForm.AWBNUM2.value;
	
	if (awb1.length != 4) 
	{
		window.alert("Please enter a correct AWB Number: the first part must consist of 4 Numerics.");
		return false;
	}
	else if (awb2.length != 4)
	{
		window.alert("Please enter a correct AWB Number: the second part must consist of 4 Numerics.");
		return false;
	}
	else
	{
		for (i = 0; i < awb1.length; i++)
		{
			if (awb1.charAt(i) < "0" || awb1.charAt(i) > "9" ||
				  awb2.charAt(i) < "0" || awb2.charAt(i) > "9")
			{
			   window.alert("Please enter a correct AWB Number: Non Numeric Values are not allowed.") 
			   return false;
			}
		}
		awbComplete = awb1.concat(awb2);
	}
	if ((awbComplete.substring(0,7) % 7) != parseInt(awbComplete.substring(7,8),10))
		{
		  window.alert("Please enter a correct AWB Number: Invalid Check Digit.");
      return false;
	} else {	
		return true;
	}
}

// Validation for the Origin field - the length of the field is checked
// and the data is checked 1 character at a  time to ensure no illegal 
// numerical values 
function validateOrigin()
{
	if (window.document.barcodeForm.ORIGIN.value.length != 3) 
	{
		window.alert("Please enter a correct ORIGINATION CODE: it must consist of 3 Alpha Numeric Values.");
		return false;
	}	else {
		for (i = 0; i < window.document.barcodeForm.ORIGIN.value.length; i++)
		{
			if (window.document.barcodeForm.ORIGIN.value.charAt(i).toUpperCase() < "A" || window.document.barcodeForm.ORIGIN.value.charAt(i).toUpperCase() > "Z")
			{
				 window.alert("Please enter a correct ORIGINATION CODE: it must consist of 3 Alpha Numeric Values.");
			   return false;
			}
		}
		window.document.barcodeForm.ORIGIN.value = window.document.barcodeForm.ORIGIN.value.toUpperCase();
		return true;
	}
}

// Validation for the Destination field - the length of the field is checked
// and the data is checked 1 character at a  time to ensure no illegal 
// numerical values 
function validateDest()
{
	if (window.document.barcodeForm.DESTINATION.value.length != 3) 
	{
		window.alert("Please enter a correct DESTINATION CODE: it must consist of 3 Alpha Numeric Values.");
		return false;
	}	else {
		for (i = 0; i < window.document.barcodeForm.DESTINATION.value.length; i++)
		{
			if (window.document.barcodeForm.DESTINATION.value.charAt(i).toUpperCase() < "A" || window.document.barcodeForm.DESTINATION.value.charAt(i).toUpperCase() > "Z")
			{
				 window.alert("Please enter a correct DESTINATION CODE: it must consist of 3 Alpha Numeric Values.");
			   return false;
			}
		}
	
		window.document.barcodeForm.DESTINATION.value = window.document.barcodeForm.DESTINATION.value.toUpperCase();
		return true;
	}
}

// Validation for the Piece Count field 
function validatePieceCount()
{	
	// Anfangswert leer? -> Fehler
	if (window.document.barcodeForm.PIECECOUNTSTART.value == "") {
			window.alert("Please enter a Piece Count FROM value!");
			return false;	
	}
	// Endwert leer? -> Anfangswert übernehmen
	if (window.document.barcodeForm.PIECECOUNT.value == "") {
			window.document.barcodeForm.PIECECOUNT.value = window.document.barcodeForm.PIECECOUNTSTART.value;
	}	
		
	var tempFrom = parseInt(window.document.barcodeForm.PIECECOUNTSTART.value);
	var tempTill = parseInt(window.document.barcodeForm.PIECECOUNT.value);
	
	// Anfangswert grösser als Endwert? -> Fehler
	if (tempFrom > tempTill) 
	{
		window.alert("Please enter a correct PIECE COUNT: the value FROM must be smaller than the value TILL.");
		return false;
	} else {
		var actTotal = tempTill - tempFrom + 1;	
	}

	// Anzahl Label 0? -> Fehler
	if (window.document.barcodeForm.PIECECOUNTTOTAL.value == "0")  {
			window.alert("Please enter a correct TOTAL PIECE number: it must be at least 1.");
			return false;	
	}
		
	// Anzahl Label leer? -> aus Anfangs- und Endwert berechnen
	if (window.document.barcodeForm.PIECECOUNTTOTAL.value == "")  {
	 	window.document.barcodeForm.PIECECOUNTTOTAL.value = actTotal;
	} 
	
	// Anzahl zu druckender Label grösser als 300? -> Fehler
	if (actTotal > 1000) {
			window.alert("Only 300 labels can be printed at once, please split the print into smaller amounts. We are sorry for this inconvinience.");
			return false;	
	} else {
		return true;
	}
}

// Validation for the Weight field - the length of the field is checked
// and the data is checked 1 character at a  time to ensure no illegal 
// none numerical values, the data is also checked to ensure only one 
// decimal point is used (optional).

function validateWeight()
{	var weight = parseFloat(window.document.barcodeForm.WEIGHT.value);
	var intPoint = 0;
	if (window.document.barcodeForm.WEIGHT.value.length < 1)
	{
		window.alert("Please enter a correct WEIGHT: less than 1 Numeric.");
		return false;
	}
	 if (window.document.barcodeForm.WEIGHT.value.length > 7)
	{
		window.alert("Please enter a correct WEIGHT: more than 7 Numerics.");
		return false;
	}
	if (window.document.barcodeForm.WEIGHT.value ==".")
	{
	window.alert("Please enter a correct WEIGHT: invalid weight.");
		return false;
	}
	 if (weight < 0.05)
	{
		window.alert("Please enter a correct WEIGHT: invalid weight.");
		return false;
	}
	else
	{
		for (i = 0; i < window.document.barcodeForm.WEIGHT.value.length; i++)
		{
			if (window.document.barcodeForm.WEIGHT.value.charAt(i) == ".")
			{
				intPoint++			
				if (intPoint > 1)
				{
					window.alert("Please enter a correct WEIGHT: includes More Than 1 Decimal Point)")
					return false;
				}
			}
		
			else if (window.document.barcodeForm.WEIGHT.value.charAt(i) < "0" || window.document.barcodeForm.WEIGHT.value.charAt(i) > "9")
			{
			   window.alert("Please enter a correct WEIGHT: includes None Numeric Value.") 
			   return false;
			}
			else if(window.document.barcodeForm.WEIGHT.value == "0")
			{
			window.alert ("Please enter a correct WEIGHT: includes zero value.");
			return false;
			}
		}
		return true;
	}
}

// Validation to make sure origin and destination fields are not equal
// The value of origin is checked against the value of destination

function validateOrigindest()
{
	if (window.document.barcodeForm.ORIGIN.value == window.document.barcodeForm.DESTINATION.value)
	{
		window.alert ("Error: the ORIGIN is the same as the DESTINATION.")
		return false;
	}
	else
	 {
		return true;
	 }
}

