
  
 var isPreNN6 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) <= 4);
 var ns4 = (document.layers)? true:false;
 function addNS4Content()  {
   if (ns4)   
   {  
     document.write("You will be automatically<BR>enrolled in <nobr>Mileage Plus&reg;.</nobr>");
   }
 }
 function swap() {
     if (!ns4)  
     {
     	
       group1=document.customerSelectSWPRedemption.numOfFirstChoice.value;
       group2=document.customerSelectSWPRedemption.numOfSecondChoice.value;
       group3=document.customerSelectSWPRedemption.numOfThirdChoice.value;
       group4=document.customerSelectSWPRedemption.numOfFourthChoice.value;       
       if(group1=="0" && group2=="0" && group3=="0" && group4=="0")
       {
       	document.getElementById("goAhead").style.display = "none";
       }else
       {
       	document.getElementById("goAhead").style.display = "";
       }
 	
     }
 }
 

function validateRedemption(formName)
{
	
	var sumCert = 0;
	var maxAllowed = 4;
			
	sumCert = (formName.numOfFirstChoice.value * 1)  + 
			(formName.numOfSecondChoice.value * 1) + 
			(formName.numOfThirdChoice.value * 1)  + 
			(formName.numOfFourthChoice.value * 1);
					
	if(sumCert>formName.maxNoOfCertAllowed.value)
	{
	   	showMessage("The number of certificates you selected "+
	   			(((maxAllowed*1)-(formName.maxNoOfCertAllowed.value*1))+sumCert)+
	   			", exceeds the\r\nmaximum allowed "+
	   			"number of certificates "+maxAllowed+	   			
	   			". Please change\r\nthe number or amount "+
				"of certificates to continue.");
		return false;
	   	
	}
	
	return true;
	
}
function sendMails (f)
{
   if (f.ccList.value.length != 0)
	{
        var v=f.ccList.value;
        var ccAr=v.split(",");
        var length=ccAr.length;
        for(var i=0;i<length;i++)
		{
			if (!validateCcList(ccAr[i]))
			{
				return false;
			}
        }
    }
   return true;    
}
function validateCcList(emailStr){
   
    var checkTLD=1;
    
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM)$/;
    
    var countryDomain = /^(co.uk|co.us|co.au|co.ca|co.in|co.it|CO.UK|CO.US|CO.AU|CO.CA|CO.IN|CO.IT)$/;
	
    var emailPat=/^(.+)@(.+)$/;
    
    var invalidChars = '\/\\ ";:?!()[]\{\}^|#%&*+$';
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    
    var validChars="\[^\\s" + specialChars + "\]";
    
    var quotedUser="(\"[^\"]*\")";
    
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    
    var atom=validChars + '+';
    
    var word="(" + atom + "|" + quotedUser + ")";
    
    // The following pattern describes the structure of the user
    
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    
    var matchArray=emailStr.match(emailPat);
    if (matchArray==null) {
    
        alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    
	for (i=0; i<invalidChars.length; i++) 
	{
		if (emailStr.indexOf(invalidChars.charAt(i),0) > -1) 
		{
			alert('Email address contains invalid characters.');
			return false;
		}
	}
    var user=matchArray[1];
    var domain=matchArray[2];
    
    // Start by checking that only basic ASCII characters are in the strings (0-127).
    
    for (i=0; i<user.length; i++) {
        if (user.charCodeAt(i)>127) {
            alert("Ths username contains invalid characters.");
            return false;
        }
    }
    for (i=0; i<domain.length; i++) {
        if (domain.charCodeAt(i)>127) {
            alert("Ths domain name contains invalid characters.");
            return false;
        }
    }
    
    // See if "user" is valid 
    
    if (user.match(userPat)==null) {
    
    // user is not valid
    
        alert("The username doesn't seem to be valid.");
        return false;
    }
    
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
    
    // this is an IP address
    
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                alert("Destination IP address is invalid!");
                return false;
            }
        }
        return true;
    }
     
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
        if (domArr[i].search(atomPat)==-1) {
            alert("The domain name does not seem to be valid.");
            return false;
        }
    }
    
    if (checkTLD && domArr[domArr.length-1].length!=2 && 
    domArr[domArr.length-1].search(knownDomsPat)==-1) {
        alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }
    
    if (len<2) {
        alert("This address is missing a hostname!");
        return false;
    }
	
	for (i=0; i<domArr[domArr.length-1].length; i++) 
	{
		if(domArr[domArr.length-1].length == 2 && (domArr[domArr.length-1].charAt(i) > 0 && domArr[domArr.length-1].charAt(i) < 9))
		{
			alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
		}
	}
	var indexOfDomain = emailStr.indexOf(".");
    var domain = emailStr.substr(indexOfDomain);
	var count = 0;
	
	for(i=0;i<domain.length ;i++ )
	{
		if(domain.charAt(i) == ".")
		{
			count++;
		}
		if(count>2)
		{
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}
	if(count == 2)
	{
		if(domain.search(countryDomain) != -1)
		{
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

    return true;
}
