                                                                                     
        function checkChar(inputStr, result) {                    
        for (i = 0;  i < inputStr.length;  i++) {               
           ch = inputStr.charAt(i);                                             
           for (j = 0;  j < result.length;  j++)               
                  if (ch == result.charAt(j))                          
                         break;                                                                 
           if (j == result.length)                                             
                  return false;                                                         
        }                                                                                               
        return true;                                                                    
        }                                                                                               
                                                                                                        
        function checkMOD(i, m) {                                               
        var tmp = (i - (i % 10)) ;                                              
        tmp /= 10 ;                                                                     
        return ((tmp % m) == (i % 10)) ;                                
        }                                                                                               
                                                                                                        
function loadPrefix(theForm) 
{                                   
	var AIR = "theForm.carrier.options[theForm.carrier.selectedIndex].value" ;
                                                                
	if(eval(AIR) == "NZ"){                                                                                
		theForm.prefix.value = "086";
	}else if (eval(AIR) == "UA"){
		theForm.prefix.value = "016";
	}else if (eval(AIR) == "LH"){
		theForm.prefix.value = "020";
	}else if (eval(AIR) == "AC"){
		theForm.prefix.value = "014";
	}else if (eval(AIR) == "OS"){
		theForm.prefix.value = "257";
	}else if (eval(AIR) == "SK"){
		theForm.prefix.value = "117";
	}else if (eval(AIR) == "EK"){
		theForm.prefix.value = "176";
	}else if (eval(AIR) == "SQ"){
		theForm.prefix.value = "618";
	} else if (eval(AIR) == "TG"){
		theForm.prefix.value = "217";
	}else if (eval(AIR) == "RG"){
		theForm.prefix.value = "042";
	}else if (eval(AIR) == "AA"){
		theForm.prefix.value = "001";
	}else if (eval(AIR) == "UL"){
		theForm.prefix.value = "603";
	}else if (eval(AIR) == "LM"){
		theForm.prefix.value = "119";
	} else if (eval(AIR) == "CI"){
		theForm.prefix.value = "297";
	} else if (eval(AIR) == "KL"){
		theForm.prefix.value = "074";
	} else if (eval(AIR) == "MU"){
		theForm.prefix.value = "781";
	} else if (eval(AIR) == "AY"){
		theForm.prefix.value = "105";
	}else if (eval(AIR) == "EI"){
		theForm.prefix.value = "053";
	} else if (eval(AIR) == "AF"){
		theForm.prefix.value = "057";
	} else if (eval(AIR) == "AZ"){
		theForm.prefix.value = "055";
	} else if (eval(AIR) == "BA"){
		theForm.prefix.value = "125";
	} else if (eval(AIR) == "BD"){
		theForm.prefix.value = "236";
	} else if (eval(AIR) == "FI"){
		theForm.prefix.value = "108";
	}else if (eval(AIR) == "DL"){
		theForm.prefix.value = "006";
	} else if (eval(AIR) == "GF"){
		theForm.prefix.value = "072";
	} else if (eval(AIR) == "JL"){
		theForm.prefix.value = "131";
	} else if (eval(AIR) == "KU"){
		theForm.prefix.value = "229";
	} else if (eval(AIR) == "LO"){
		theForm.prefix.value = "080";
	} else if (eval(AIR) == "MA"){
		theForm.prefix.value = "182";
	} else if (eval(AIR) == "US"){
		theForm.prefix.value = "037";
	} else if (eval(AIR) == "NW"){
		theForm.prefix.value = "012";
	} else if (eval(AIR) == "BR"){
		theForm.prefix.value = "695";
	} else if (eval(AIR) == "CX"){
		theForm.prefix.value = "160";
	} else if (eval(AIR) == "JP"){
		theForm.prefix.value = "165";
	} else if (eval(AIR) == "MK"){
		theForm.prefix.value = "239";
	} else if (eval(AIR) == "SV"){
		theForm.prefix.value = "065";
	} else if (eval(AIR) == "VN"){
		theForm.prefix.value = "738";
	} else if (eval(AIR) == "QR"){
		theForm.prefix.value = "157";
	}
}                                                                                               
                                                                                                        
     function ValidateForm(theForm)                          
        {                                                                                       
        var AIR = "theForm.carrier.options[theForm.carrier.selectedIndex].value";
        var WAYB= "theForm.awb";         
                          

   	if (theForm.prefix.value.length != 3) {                    
           alert("Invalid Air Waybill Prefix") ;                                
           theForm.prefix.focus() ;                                                
           return (false) ;                                                             
        }                                                                                               
        if (!checkChar(theForm.prefix.value, "0123456789")) {                                 
           alert("Invalid Air Waybill Prefix [" + theForm.prefix.value+ "]") ;             
           theForm.prefix.focus() ;                                                
           return (false);                                                              
        }                     
                                                                          
        if (eval(WAYB + ".value") == "") {                      
	
           if (theForm.Items.value > 1) {                               
                   return true ;                                                
           } else {                                                                             
                  alert("Invalid Air Waybill Number") ;                 
                  eval(WAYB + ".focus()") ;                             
                  return false ;                                                        
           }                                                                                    
	                                                    
        }    
                                                                                           
        if (eval(WAYB + ".value.length") != 8) {                
	 
           if (eval(WAYB + ".value.length") == 0) {     
                  if (theForm.Items.value > 1) {                        
                           return true ;                   
                  } else {                                                                      
                         alert("Empty Air Waybll Number") ;                    
                         eval(WAYB + ".focus()") ;return false ;                        
                  }                                                                                     
           } else {                                                                     
                  alert("Invalid Air Waybill Number") ;                 
                  eval(WAYB + ".focus()") ;                             
                  return false ;                                                        
           }                                                                                    
	                                                
        }                                                                                               
          
         if (!checkChar(eval(WAYB + ".value"), "0123456789")) {                                     
           alert("Invalid Air Waybill Number") ;                 
           eval(WAYB + ".focus()") ;                                    
           return (false);
         }
                                                                                   
        if (!checkMOD(eval(WAYB + ".value"), 7)) {      
                  alert("Invalid Air Waybill Number") ;                 
           eval(WAYB + ".focus()") ;                                    
           return (false);                                                              
        }  
                                                                       
        for (i=1 ; i < theForm.Items.value ; i++) {             
                                                                       
           var tW = "theForm.awb" + i + ".value";      
           var tA = "theForm.carrier"  + i + ".value";      
           var tP = "theForm.prefix"  + i + ".value";      
           if (eval(tW) != eval(WAYB + ".value"))               
                  continue ;                                                            
           if (eval(tA) != eval(AIR))                                   
                  continue ;                                                            
           if (eval(tP) != theForm.prefix.value)                   
                  continue ;                                                            
           break ;                                                                              
        }                                                                                               
        if (i < theForm.Items.value) {                                  
           alert("The air waybill already in track list. ") ;                                   
           eval(WAYB + ".focus()") ;                                    
           return (false);                                                              
        }                                                                                               
        return true;                                                                           
        }                                                               
