//grouprequests_common.js
//contains all functions that are common among all
//group request forms

var eventsFilled = 0;   // global variable to indicate how many events have been filled; used only in meetingMultiple

function forwardTo(url) {
  var ref = document.referrer;
  if ((ref && (ref.match(/worldagentdirect/) != null)) || (getParam('w') == '1')) { //from world agent direct
    url += "?w=1";
  }
  location.href = url;
}

//equivalent to the getParameter method
//of Java's HttpServletRequest Object
function getParam(parm) {
  var query = window.location.search;
  var value = "";
  if (query != null || query != "") {
    query = query.substring(1);
  }
  if (query == null || query == "") {
    return;
  }
  else { //process the query
    var vars        = query.split('&');
    var queryValues = new Array();
    for (var i = 0; i < vars.length; i++) {
      var variable = vars[i].split('=');
      var varname  = variable[0];
      var varvalue = variable[1];
      if (varname == parm) {
        value = varvalue;
      }
    }
  }
  return value;
}

function trim(str) {
  str = str.replace(/^[\s]+/g, "");
  str = str.replace(/[\s]+$/g, "");
  return str;
}

function disable(flag) {
  if (flag) {
    if (document.getElementById) {
      if (!document.getElementById('submitImage').disabled) {
        document.getElementById('submitImage').disabled = true;
      }
    }
    else if (document.all) {
      if (!document.all['submitImage'].disabled) {
        document.all['submitImage'].disabled = true;
      }
    }
  }
  else {
    if (document.getElementById) {
      if (document.getElementById('submitImage').disabled) {
        document.getElementById('submitImage').disabled = false;
      }
    }
    else if (document.all) {
      if (document.all['submitImage'].disabled) {
        document.all['submitImage'].disabled = false;
      }
    }
  }
}

function requiredIsPopulated(frm, forChecking) {
  var reqPattern1 = /\*$/;
  var reqPattern2 = /REQ/;
  var strAlert    = "";
  var multiple    = false;
  var iataNum     = "";
  var gdsSystem   = "";
  //mich 05/08/2007
  var officeID	  = "";

  multiple = (frm.pagetype.value == "meetingMultiple");
  
  with (frm) {
    var frmLen = frm.elements.length;
    for (var i = 0; i < frmLen; i++) {

	  var eleName = frm.elements[i].name;
	  if (!eleName.match(/submitImage/)) {
	      frm.elements[i].style.background = "#FFFFFF";
	  }

	  
      //conditions specific to certain fields
      if (eleName.match(/Country/) != null) {
        var country = frm.elements[i].value;
      }
      else if (eleName.match(/selGDS/) != null) {
        iataNum = document.getElementById('txtIATA*');
        if (document.getElementById('txtIATA')) {
          iataNum = document.getElementById('txtIATA');
        }
        gdsSystem = frm.elements[i].options[frm.elements[i].selectedIndex].value;
		
        if (isValidIATA(iataNum) && (gdsSystem == "")) {
          alert("Please select an option from the GDS dropdown.");
          frm.elements[i].style.background = "#FFFF99";
          disable(false);
          return false;
        }
        else if (!isValidIATA(iataNum) && (gdsSystem != "")) {
          alert("Please provide a valid ARC/IATA Number for the GDS system you have selected.");
          iataNum.style.background = "#FFFF99";
          disable(false);
          return false;
        }                                       
        //start of change-05/07/2007 - validates Office ID value
        else if (gdsSystem == "Amadeus") {                              	
        	officeId = document.getElementById('txtOfficeID'); 
        	lenOfficeId = officeId.value.length;      	        	      	      	    
        	if ((trim(officeId.value) != "") && (!hasValidAlphaNumeric(officeId, lenOfficeId))) {
        	  alert("Please provide a valid Office ID");
        	  officeId.style.background = "#FFFF99";
              disable(false);
              return false;
        	}          	  	
        }     
        //end of change-05/07/2007   
	  }
        else if (eleName.match(/selAddlGDS/) != null) {
          var gdsIdx = eleName.match(/(\d)/);
          var iataNum = document.getElementById('txtAdditional_IATA_' + gdsIdx[0]);
          var gdsSystem = frm.elements[i].options[frm.elements[i].selectedIndex].value;

          if (!isValidIATA(iataNum) && (gdsSystem != "")) {
            alert("Please provide a valid ARC/IATA Number for the GDS system you have selected.");
            iataNum.style.background = "#FFFF99";
            disable(false);
            return false;
          }                                       
          else if (gdsSystem == "Amadeus") {                                
            var officeId = document.getElementById('txtAddlOfficeID_' + gdsIdx[0]); 
            var lenOfficeId = officeId.value.length;                                      
            if ((trim(officeId.value) != "") && (!hasValidAlphaNumeric(officeId, lenOfficeId))) {
              alert("Please provide a valid Office ID");
              officeId.style.background = "#FFFF99";
              disable(false);
              return false;
            }
          }
        }
	  
      if (eleName.match(reqPattern1) != null) {
        if (trim(frm.elements[i].value) == "") {
          strAlert += getDisplayName(eleName) + ",";
          frm.elements[i].style.background = "#FFFF99";
        }
      }
      else if ((!multiple) && (eleName.match(reqPattern2) != null)) {
        if (trim(frm.elements[i].value) == "") {
          strAlert += getDisplayName(eleName) + ",";
          frm.elements[i].style.background = "#FFFF99";
        }
      }
    }
  }
  
  if (strAlert != "") {
    var aEmail;
      var aREmail;
    if (document.getElementById) {
      aREmail = document.getElementById('txtReenterAlternateEmail');
         aEmail = document.getElementById('txtAlternateEmail');
    }
    else if (document.all) {
      aREmail = document.all['txtReenterAlternateEmail'];
         aEmail = document.all['txtAlternateEmail'];
    }
    if (isBlank(aREmail) && !isBlank(aEmail)) {
      aREmail.style.background = "#FFFF99";
      strAlert += getDisplayName(aREmail.name) + ",";
    }

    if(!forChecking) {
    }
    else {
      alert("Please fill up the required fields above prior to adding a new " + forChecking);
      return false;
    }
    strAlert = strAlert.replace(/\,$/, "");
    strListArr = strAlert.split(',');
    strNew = "";
    for (var i = 0; i < strListArr.length; i++) {
      if (strListArr[i].match(/AgencyName/) && (document.frmFormType.field2.value == 'travelAgent')) {
        strListArr[i] = 'Travel Agency/Customer Name';
      }
      if ((i + 1) % 3 == 0 && (i + 1) < strListArr.length) 
        strNew += strListArr[i] + ",\r\n";
      else if ((i + 1) < strListArr.length)
        strNew += strListArr[i] + ", ";
      else
        strNew += strListArr[i];
    }
    strNew = strNew.replace(/\,$/, "");
    alert("Fields with * are required. Please enter the following information:\n" + strNew);
    disable(false);
    return false;
  }
  else {
    var aEmail;
      var aREmail;
    if (document.getElementById) {
      aREmail = document.getElementById('txtReenterAlternateEmail');
         aEmail = document.getElementById('txtAlternateEmail');
    }
    else if (document.all) {
      aREmail = document.all['txtReenterAlternateEmail'];
         aEmail = document.all['txtAlternateEmail'];
    }
    if (isBlank(aREmail) && !isBlank(aEmail)) {
      aREmail.style.background = "#FFFF99";
      alert("Please enter the following information:\nRe-enter Alternate E-mail Address");
      disable(false);
      return false;
    }

    
    if (multiple) {  // joe 10/6/2005 changed validation rule for meetingMultiple events
      var ctr = frm.hidaddctr.value;
      var i, flag = 0, mask = 0;
      var val = 0;
      var incFound = false;   // incomplete flag
      
      for (i=1; i<=ctr; i++) {
        val = checkComplete(frm, i);   // (-1) - incomplete   0 - blank  1 - completely filled 
        if (val < 0) {
          val++;
          incFound = true;
        }
  
        flag += val << (i - 1);
        mask += 1 << (i - 1);
      }
      if (((flag & 1) == 0 ) || (incFound)) {  // if there are incomplete events
        highlightBlankFields(frm, "Fields with * are required. Please enter the following information:\n");
        disable(false);
        return false;
      } else if ((flag ^ mask) != 0) { // if there are blank events
        if ((ctr != 4) || ((ctr == 4) && ((flag & 14) != 0))) { // 14 == 1110 binary. only events 2,3 and 4 are allowed to be blank and only when there are four events
          if (ctr == 4) {
            highlightBlankFields(frm, "Please fill up the fields completely or for 2-3 events please use separate forms:\n");
          } else {
            highlightBlankFields(frm, "Fields with * are required. Please enter the following information:\n");
          }
          disable(false);
          return false;
        }
      }
      if (flag == 1) { // if only the first event is filled
        eventsFilled = 1;
      }
    }
  }
  return true;
}

function checkComplete(frm, curIdx) {
  var expr = 'REQ_' + curIdx;
  var reqPattern1 = eval("/" + expr + "/");
  var filledEvent = false;
  var retVal = 0;  // -1 - incomplete   0 - all blank   1 - all filled up

  with (frm) {
    var frmLen = frm.elements.length;
    var startEvent = false;
    var eventNum = "";
    for (var i=0; i<frmLen; i++) {
      var eleName = frm.elements[i].name;
      if (eleName=="hidaddctr")
        startEvent=true;
      if (startEvent) {
        if (eleName.match(reqPattern1) != null) {
              if (trim(frm.elements[i].value) != "") {
                filledEvent = true;
            retVal = 1;
            } else {
            if (filledEvent) {
              retVal = -1;
              break;
            }
                filledEvent = false;
            }
          }
      }
    }
  }
  if ((!filledEvent) && (curIdx == 1)) {  // the first event is always required
    return (-1);
  } else {
    return retVal;
  }
}

function highlightBlankFields(frm, msg) {
  var frmLen = frm.elements.length;
  var reqPattern = /REQ_\d/;
  var strAlert = "";

  for (var i=0; i<frmLen; i++) {
    var elem = frm.elements[i];
    if (elem.name.match(reqPattern) != null) {
      if (trim(elem.value) == "") {
        strAlert += getDisplayName(elem.name) + ",";
        elem.style.background = "#FFFF99";
      }
    }
  }
  if (strAlert != "") {
    alert(msg + strAlert);
  }
}

function getDisplayMsg(elemName, str) {
  return getDisplayName(elemName) + str;
}

function getDisplayName(elemName) {
  elemName = elemName.replace(/^txt/,"");
  elemName = elemName.replace(/^sel/,"");
  elemName = elemName.replace(/^hid/,"");
  elemName = elemName.replace(/\*$/,"");
  elemName = elemName.replace(/REQ/,"");
  elemName = elemName.replace(/WPNumber/,"SkyMiles Number");
  if (elemName.match(/IATA/) == null && elemName.match(/SkyMiles/) == null) 
    elemName = elemName.replace(/([A-Z])/g, " $1");
  if (elemName.match(/IATA/) != null) 
    elemName = elemName.replace("IATA", "ARC/IATA");
  if (elemName.match(/Group Name/) != null && document.frmFormType.hidPage.value.match(/Multiple|RGS-MICECorp/) != null)
    elemName = elemName.replace(/Group/, "Event");
  if (elemName.match(/email/i)) {
    elemName = elemName.replace("Reenter", "Re-enter");
    elemName = elemName.replace(/email/i, "E-mail Address");
  }
    
  elemName = elemName.replace(/_/g," ");
  return elemName;
}

function isValidEmail(obj) {
  var emailPattern = /^([A-Za-z0-9]+(\.|_|-|\'|\’))*[A-Za-z0-9]+@([A-Za-z0-9]+(\.|_|-|\'|\’))*([A-Za-z0-9]+\.)[A-Za-z0-9]+$/;
  return (obj.value.match(emailPattern)!=null);
}

  // verify sure 2 email address are the same
function checkEmail(email1, email2){
   var eml1 = (email1).toUpperCase()
   var eml2 = (email2).toUpperCase()

   if(trim(eml1) != trim(eml2)){
      return false
   }
   else{
      return true
   }
 }

function isPositiveInteger(obj) {
  return isNaN(obj.value);
}



/*
/byu modification 05 Oct 2004
function isValidSkyMiles(obj) {
  var wpvalue = obj.value;
  wpvalue = wpvalue.replace(/\D/g, "");
  if (wpvalue.length != 9 && wpvalue.length != 12) {
    return false;
  }
  else {
    var wpinit = '';
    var wplast = '';
    var wpsl = (obj.value.length - 1);
    wpinit = (wpvalue.substr(0, wpsl) - 0);
    wplast = (wpvalue.substr(wpsl, 1) - 0);
    var cal = (parseInt((wpinit / 7 - parseInt(wpinit / 7)) * 7 + 0.5));
    if (cal != wplast) {
      return false;
    }
  }
  return true;
}
*/

//byu modification 05 Oct 2004
//KN modification, 8/13/2009 - modified to accept and  
//validate, via checkdigit, SkyMiles 10 digit account numbers.
function isValidSkyMiles(obj) {
  var wpvalue = obj.value;

  wpvalue = wpvalue.replace(/\D/g, "");

  if (wpvalue.length != 9 && wpvalue.length != 12 && wpvalue.length != 10) {
     return false;
  }
  //else if legacy WP #
  else if (wpvalue.length == 9 || wpvalue.length == 12)
  {    
     var wpinit = '';
     var wplast = '';
     var wpsl = (obj.value.length - 1);
     wpinit = (wpvalue.substr(0, wpsl) - 0);
     wplast = (wpvalue.substr(wpsl, 1) - 0);
     var cal = (parseInt((wpinit / 7 - parseInt(wpinit / 7)) * 7 + 0.5));
     if (cal != wplast) {      
       return false;
     }
  }
  //else 10 digit SkyMiles #, validate the check digit
  else 
  {
     var cntOdd = 0;
     var cntEven = 0;
	 var oddTotal = 0;
     var evenTotal = 0;
     var grandTotal = 0;
     var remainder = 0;
     var checkDig = 0;
     var digTotal = 0;
	 var digSum = 0;
     var temp = 0;
	 var tempStr = '';
     //Load each element of array with 1 digit from the SM acct #.
	 var skyMilesAcctNum=new Array(parseInt(wpvalue.substr(0,1)), 
                                   parseInt(wpvalue.substr(1,1)),
	                               parseInt(wpvalue.substr(2,1)),
                                   parseInt(wpvalue.substr(3,1)),
                                   parseInt(wpvalue.substr(4,1)),
                                   parseInt(wpvalue.substr(5,1)),
                                   parseInt(wpvalue.substr(6,1)),
                                   parseInt(wpvalue.substr(7,1)),
                                   parseInt(wpvalue.substr(8,1)),
                                   parseInt(wpvalue.substr(9,1)));

     //Loop through all the odd digits and run through formula
	 //and add them up.
	 for (cntOdd=0;cntOdd<=8;cntOdd+=2)
     {
	    temp = skyMilesAcctNum[cntOdd] * 2;
   	    if (temp < 10)
   	    {
           oddTotal += temp;
    	}
        else
        {
           tempStr = temp.toString();
//	       digTotal = (parseInt(tempStr[0]) + parseInt(tempStr[1]));
		   digTotal = (parseInt(tempStr.substr(0,1)) + parseInt(tempStr.substr(1,1)));
		   oddTotal += digTotal;
        }
	 }

     for (cntEven=1;cntEven<=7;cntEven+=2)
     {
	    evenTotal += skyMilesAcctNum[cntEven];
     }

     grandTotal = oddTotal + evenTotal;
	 remainder = grandTotal % 10;
     checkDig = 10 - remainder;

	 if (checkDig == 10)
     {
        checkDig = 0;
	 }

//     alert("checkDig = " + checkDig);

     //Compare calculated check digit with last digit in 
	 //the SM #, if same then it's valid, if different then 
	 //not valid.
	 if (checkDig != skyMilesAcctNum[9])
     {
        return false;
	 }
  }
  return true;
}


function isValidIATA(obj) {
  var iata = obj.value;
  var iata_len = iata.length;
  if (iata.match(/\D/)) {
    return false;
  }
//  else if (iata_len != 7 && iata_len != 9 && iata_len != 10 && iata_len != 12) {
  else if (iata_len != 5 && iata_len != 7) {
	return false;
  }
  return true;
}

function isValidZip(obj, country) {
  //ptogle modification 28 Sep 2004
  obj.value = obj.value.toUpperCase();
  var usPattern = /^(\d{5}|(\d{5}-\d{4}))$/;
  var caPattern1 = /^([A-Z]\d[A-Z] \d[A-Z]\d)$/;
  var caPattern2 = /^([A-Z]\d[A-Z]\d[A-Z]\d)$/
  if (country == "US")
    return (obj.value.match(usPattern)!=null);
  else if (country == "CA") {
    if (obj.value.match(caPattern1)) {
      return true;
    }
    else if (obj.value.match(caPattern2)) {
      obj.value = obj.value.replace(/^([A-Z]\d[A-Z])/,"$1 ");
      return true;
    }
    else
      return false;
  }
  return true;
}

function isValidPhone(obj) {
  var phonePattern = /^\d{3}-\d{3}-\d{4}$/;
  var phonePattern2 = /^\d{10}$/;
  var phonePattern3 = /^\d{3} \d{3} \d{4}$/;
  if (obj.value.match(phonePattern) == null) {
    if (obj.value.match(phonePattern2) == null) {
      if (obj.value.match(phonePattern3) == null) {
        return false;
      }
      else {
        obj.value = obj.value.replace(/\s/g, '-');
      }
    }
    else {
      obj.value = obj.value.substr(0, 3) + '-' + obj.value.substr(3, 3) + '-' + obj.value.substr(6, 4);
    }
  }
  return true;
}

function isValidExtension(obj) {
  var extPattern = /^\d{0,10}$/;
  return (obj.value.match(extPattern)!=null);
}

function isValidPassengerCount(obj) {
  if (isNaN(obj.value)) {
    alert("The number of passengers should be numeric.");
    obj.style.background = "#FFFF99";
    return false;
  }
  else if (obj.value < 10) {
    if (document.frmFormType.pagetype.value.match(/meeting(Multiple|Single)/) == null) {
      alert("The minimum number of passengers is 10.");
      obj.style.background = "#FFFF99";
      return false;
    }
    else {
      if (obj.value <= 0) {
        alert("The minimum number of passengers is 1.");
        obj.style.background = "#FFFF99";
        return false;
      }
    }
  }
  return true;
}

function hasValidChars(obj) {
  var namePattern = /^([A-Za-z0-9!@#$%&*\(\)':;,<>.?\\\/\s-_])+$/;
  return (obj.value.match(namePattern)!=null); 
}

function isValidTicketDesignator(obj) {
  var tktPattern = /^[a-zA-Z]{2}[a-zA-Z0-9]{3}$/
  return (obj.value.match(tktPattern)!=null);
}

function hasValidAlphaNumeric(obj,count) {
  //mtogle 10/18/2004 - removed checking for count since it should be present
  var anpattern = eval('/^([a-zA-Z0-9]){'+count+'}$/');
  return (obj.value.match(anpattern)!=null);
}

function isValidTradeCode(obj) {
  var anpattern = eval('/^[a-zA-Z0-9]+$/');
  return (obj.value.match(anpattern)!=null);
}

function isValidAgreementGroupCode(obj) {
//  var agcPattern = /^\w{1}\d{5}$/;
//  joe 10/06/2004 - changed \w to [a-zA-Z] to explicitly 
//  specify alphabet characters
  var agcPattern = /^[a-zA-Z]\d{5}$/;
  return (obj.value.match(agcPattern)!=null);
}

function isValidBulletinNumber(obj) {
//  var bnPattern = /^\w{2}\d{3}$/;
//  joe 10/06/2004 - changed validation rule to reject non-alphabet
//  in first 2 characters
  var bnPattern = /^([a-zA-Z]){2}\d{3}$/
  return (obj.value.match(bnPattern)!=null);
}

function isBlank(obj) {
  if (obj.value!=null && obj.value!="") return false;
  return true;
}

var lengthChecked = false;
function checkLength(obj, maxLen) {
  var curLen = obj.value.length;
  if (curLen > maxLen) {
    obj.value = obj.value.substring(0,maxLen);
    if (!lengthChecked) 
      alert("Only 2000 characters are allowed for "+getDisplayName(obj.name)+".");
    obj.style.background = "#FFFF99";
    lengthChecked = true;
  }
  return;
}

function validDate(month, day, year) {
  d = new Date(year, month, day);
  if ((d.getMonth() != month) || (d.getDate() != day) || (d.getFullYear() != year)) {
    return 0;
  } else {
    return 1;
  }
}

function isValidDateRange(d1,d2) {
  return d1.getTime() <= d2.getTime();
}

function isWithinTwo(m1, m2, d1, d2, y1, y2) {
  var diff = y2 - y1;
  if (diff == 2) {
    if (m2 > m1) {
      return false;
    }
    else if (m2 == m1) {
      if(d2 > d1) {
        return false;
      }
    }
  }
  return true;
}

function checkDate(monObj1, dayObj1, yrObj1, monObj2, dayObj2, yrObj2, datetype1, datetype2, infotype, index) {
  var outboundDate = new Date(yrObj1.value, monObj1.value, dayObj1.value);
  var returnDate   = new Date(yrObj2.value, monObj2.value, dayObj2.value);
  var currentDate  = new Date();  
  var strMsg = "";  
  currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
  if ((infotype != null) && (infotype != "")) {
    strMsg = " for " + infotype + " " + index;
  }
  if (validDate(monObj1.value, dayObj1.value, yrObj1.value) == 0) {
    alert("Invalid " + datetype1 + " Date" + strMsg + ".");
    monObj1.style.background = "#FFFF99";
    dayObj1.style.background = "#FFFF99";
    yrObj1.style.background = "#FFFF99";
    return false;
  }
  if (!isValidDateRange(currentDate, outboundDate)) {
    alert("The " + datetype1 + " Date" + strMsg + " should be later or the same as the current date.");
    monObj1.style.background = "#FFFF99";
    dayObj1.style.background = "#FFFF99";
    yrObj1.style.background = "#FFFF99";
    return false;
  }
  if (!isWithinTwo(currentDate.getMonth(), monObj1.value, currentDate.getDate(), dayObj1.value, currentDate.getFullYear(), yrObj1.value)) {
    alert("The " + datetype1 + " Date" + strMsg + " should not be later than two years from the current date.");
    monObj1.style.background = "#FFFF99";
    dayObj1.style.background = "#FFFF99";
    yrObj1.style.background = "#FFFF99";
    return false;
  }
  if ((monObj2.name.match(/return/i) != null) || (monObj2.name.match(/end/i) != null)) {
    if ((monObj2.value != '') || (dayObj2.value != '') || (yrObj2.value != '')) {
      if (validDate(monObj2.value, dayObj2.value, yrObj2.value) == 0) {
        alert("Invalid " + datetype2 + " Date" + strMsg + ".");
        monObj2.style.background = "#FFFF99";
        dayObj2.style.background = "#FFFF99";
        yrObj2.style.background = "#FFFF99";
        return false;
      }
      if (!isValidDateRange(currentDate, returnDate)) {
        alert("The " + datetype2 + " Date" + strMsg + " should be later or the same as the current date.");
        monObj2.style.background = "#FFFF99";
        dayObj2.style.background = "#FFFF99";
        yrObj2.style.background = "#FFFF99";
        return false;
      }
      if (!isWithinTwo(currentDate.getMonth(), monObj2.value, currentDate.getDate(), dayObj2.value, currentDate.getFullYear(), yrObj2.value)) {
        alert("The " + datetype2 + " Date" + strMsg + " should not be later than two years from the current date.");
        monObj2.style.background = "#FFFF99";
        dayObj2.style.background = "#FFFF99";
        yrObj2.style.background = "#FFFF99";
        return false;
      }
      if (!isValidDateRange(outboundDate, returnDate)) {
        alert("The " + datetype1 + " Date" + strMsg + " should be before or the same as the " + datetype2 + " Date.");
        monObj1.style.background = "#FFFF99";
        dayObj1.style.background = "#FFFF99";
        yrObj1.style.background = "#FFFF99";
        monObj2.style.background = "#FFFF99";
        dayObj2.style.background = "#FFFF99";
        yrObj2.style.background = "#FFFF99";
        return false;
      }
    }
  }
  return true;
}

/* joe-09302004 - added constants for displaying and removing links */
/* addEvent2Link - HTML tags for displaying the Add link in MiceCorp forms */
/* remEvent2Link - HTML tags for displaying the Remove link in MiceCorp forms */
var addEvent2Link = '<a href="javascript:void(0);" onClick="addEventInformation2();">Add Another Event</a>';
var remEvent2Link = '<a href="javascript:void(0);" onClick="remInformation(4);">Remove Last Event</a>';

/* addGroupLink - HTML tags for displaying the Add link in Series_Travel forms */
/* remGroupLink - HTML tags for displaying the Remove link in Series_Travel forms */
var addGroupLink = '<a href="javascript:void(0);" onClick="addGroupInformation();">Add Another Group</a>';
var remGroupLink = '<a href="javascript:void(0);" onClick="remInformation(2);">Remove Last Group</a>';

/* addGroup2Link - HTML tags for displaying the Add link in Meeting_Multiple forms */
/* remGroup2Link - HTML tags for displaying the Remove link in Meeting_Multiple forms */
var addGroup2Link = '<a href="javascript:void(0);" onClick="addGroupInformation2();">Add Another Event</a>';
var remGroup2Link = '<a href="javascript:void(0);" onClick="remInformation(3);">Remove Last Event</a>';
var minimumNote   = '<i><small>(To register minimum 4 events within a single contract)</small></i>';

/* addEvent3Link - HTML tags for displaying the Add link in Multi-meeting forms */
/* remEvent3Link - HTML tags for displaying the Remove link in Multi-meeting forms */
var addEvent3Link = '<a href="javascript:void(0);" onClick="addEventInformation3();">Add Another Event</a>';
var remEvent3Link = '<a href="javascript:void(0);" onClick="remInformation(5);">Remove Last Event</a>';

function hasInformationForAdd(frm, type) {
  var frm = document.frmFormType;
  var curIdx = frm.hidaddctr.value;
  var reqPattern1 = /\*$/;
  var reqPattern2 = /REQ/;
  var strAlert = "";
  
  with (frm) {
    var frmLen = frm.elements.length;
    var startEvent = false;
    for (var i=0; i<frmLen; i++) {
      frm.elements[i].style.background = "#cc0000";
      var eleName = frm.elements[i].name;
      if (eleName=="hidaddctr")
        startEvent=true;
      if (startEvent) {
        if (eleName.match(reqPattern1) != null) {
          if (trim(frm.elements[i].value) == "") {
            strAlert += getDisplayName(eleName) + ",";
            frm.elements[i].style.background = "#FFFF99";
          }
        }
        else if (eleName.match(reqPattern2) != null) {  
          if (trim(frm.elements[i].value) == "") {
            strAlert += getDisplayName(eleName) + ",";
            frm.elements[i].style.background = "#FFFF99";
          }
        }
      }
    }
  }
  
  if (strAlert!="") {
    alert("Please fill up the existing required " + type + " fields before adding a new " + type + ".");
    return false;
  }
  return true;
}

function prepareWorldDirect() {
  var frm = document.frmGeneral;
  var pageType = frm.pagetype.value;
  var choice1 = frm.selGen1.value;
  if (getParam('w') == "1") { //from world direct
    if (frm.selGen2 && frm.selGen2.type != "hidden")
      frm.selGen2.name = "";
    frm.hidGen2.name = "selGen2";
    frm.hidGen2.value = "travelAgent";
    frm.selGen2.value = "travelAgent";
    frm.worlddirect.value = "yes";
    var isMinIE4 = (document.all) ? 1 : 0;
    var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;
    var divSel = (isMinIE4) ? document.all["divSelGen2"] : document.getElementById("divSelGen2");
    divSel.innerHTML = '';
  }
  return;
}

function prepareIterations() {
  var frm = document.frmFormType;
  if (frm && frm != null && frm.hidaddctr) {
    if (frm.fromPreview && frm.fromPreview.value != 'yes') {
      frm.hidaddctr.value = 1;
    }
    else if (!frm.fromPreview) {
      frm.hidaddctr.value = 1;
    }
  }
}

function addGroupInformation() {
  var frm = document.frmFormType;
  var curIdx = frm.hidaddctr.value;
  var maxCount = 10;
  var minRemEvent = 1;

  if (!hasInformationForAdd(frm, 'group')) return false;

  if (curIdx<maxCount) {
    curIdx++;
    frm.hidaddctr.value = curIdx;
    var txt = '<table width="550" border="0" cellspacing="0" cellpadding="0">';
    txt += '<tr><td colspan="8"><br><hr width="100%" color="#b1b4c5" noshade size="1"></td></tr>';
    txt += '<tr><td colspan="8"><font color="#CC0000"><b>Group ' + curIdx + '</b></font></td></tr>';
    txt += '<tr><td colspan="8"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr><td colspan="4"><b>Group Name*</b><br>';
    txt += '<input name="txtGroupNameREQ_' + curIdx + '" type="text" id="txtGroupNameREQ_' + curIdx + '" size="40" maxlength="40"></td>';
    txt += '<td>&nbsp;</td><td colspan="3"><b>Group Description</b><br>';
    txt += '<input name="txtGroupDescription_' + curIdx + '" type="text" id="txtGroupDescription_' + curIdx + '" size="40" maxlength="40"></td></tr>';
    txt += '<tr><td colspan="8"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr><td colspan="8"><b>Number of Passengers*</b> <i><small>(Minimum of 10)</small></i><br>';
    txt += '<input name="txtPassengerCountREQ_' + curIdx + '" type="text" id="txtPassengerCountREQ_' + curIdx + '" size="4" maxlength="4"></td></tr>';
    txt += '<tr><td colspan="8"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr valign="middle"><td colspan="8"><b>Group will consider:</b>&nbsp;&nbsp;';
    txt += '<input name="chkAlternateDates_' + curIdx + '" type="checkbox" id="chkAlternateDates_' + curIdx + '" value="checkbox">Alternate Flights/Dates&nbsp;&nbsp;&nbsp;';
    txt += '<input name="chkSplittingGroup_' + curIdx + '" type="checkbox" id="chkSplittingGroup_' + curIdx + '" value="checkbox">Splitting Group&nbsp;&nbsp;&nbsp;';
    txt += '<input name="chkImmediateTicketing_' + curIdx + '" type="checkbox" id="chkImmediateTicketing_' + curIdx + '" value="checkbox">Immediate Ticketing</td></tr></table>';
    txt += '<table width="550" border="0" cellspacing="0" cellpadding="0">';
    txt += '<tr><td colspan="4"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr valign="top"><td width="70"><b>Outbound : </b></td>';
    txt += '<td width="200"><b>From*</b> <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)</small></i><br>';
    txt += genAirport('txtOutboundFromREQ', 'of', curIdx, '', true);
    txt += '</td><td width="10">&nbsp;</td>';
    txt += '<td width="270"><b>To*</b> <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)<br>';
    txt += genAirport('txtOutboundToREQ', 'ot', curIdx, '', true);
    txt += '</td></tr>';
    txt += '<tr><td colspan="4"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr valign="bottom"><td>&nbsp;</td><td><b>Date of Travel*</b><br>';
    txt += genDate('selOutboundMonthREQ', 'selOutboundDayREQ', 'selOutboundYearREQ', curIdx, '', '', '', true);
    txt += '</td><td>&nbsp;</td><td>';
    txt += genTimeOfDay('selOutboundTime', curIdx, 'AM', true);
    txt += '</td></tr>';
    txt += '<tr><td colspan="4"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr><td>&nbsp;</td>';
    txt += '<td><b>Flight Number</b><br>';
    txt += '<input name="txtOutboundFlightNumber_'+curIdx+'" type="text" size="6" maxlength="6">';
    txt += '</td><td>&nbsp;</td>';
    txt += '<td><b>Class of Service</b><br>';
    txt += genClass('selOutboundClass', curIdx, '', true);
    txt += '</td></tr>';
    txt += '<tr><td colspan="4"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr valign="top"><td><b>Return :</b></td>';
    txt += '<td><b>From</b> <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)</small></i><br>';
    txt += genAirport('txtReturnFrom', 'rf', curIdx, '', true);
    txt += '</td><td>&nbsp;</td>';
    txt += '<td><b>To</b>  <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)<br>';
    txt += genAirport('txtReturnTo', 'rt', curIdx, '', true);
    txt += '</td></tr>';
    txt += '<tr><td colspan="4"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr valign="bottom"><td>&nbsp;</td>';
    txt += '<td><b>Date of Travel</b><br>';
    txt += genDate('selReturnMonth', 'selReturnDay', 'selReturnYear', curIdx, '', '', '', true);
    txt += '</td><td>&nbsp;</td><td>';
    txt += genTimeOfDay('selReturnTime', curIdx, 'PM', true);
    txt += '</td></tr>';
    txt += '<tr><td colspan="4"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr><td>&nbsp;</td>';
    txt += '<td><b>Flight Number</b><br>';
    txt += '<input name="txtReturnFlightNumber_'+curIdx+'" type="text" size="6" maxlength="6">';
    txt += '</td><td>&nbsp;</td><td><b>Class of Service</b><br>';
    txt += genClass('selReturnClass', curIdx, '', true);
    txt += '</td></tr></table>';
    var isMinIE4 = (document.all) ? 1 : 0;
    var divEvent = (isMinIE4) ? document.all["divEvent_" + curIdx] : document.getElementById("divEvent_" + curIdx);
    var addLink = (isMinIE4) ? document.all["addlink"] : document.getElementById("addlink");

    divEvent.innerHTML = txt;
    /* joe-09302004 for displaying ang removing add group information link */
        if (curIdx >= minRemEvent){
         //LG 20050930 should only show remove link for 5 or more events
          addLink.innerHTML = '<h2>' + addGroupLink + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + remGroupLink + '</h2>';

    }else if (curIdx >= maxCount){
      addLink.innerHTML = '<h2>' + remGroupLink + '</h2>';
    }
    else {
      addLink.innerHTML = '<h2>' + addGroupLink + '</h2>';
    }
  }
  else {
    return;
  }
}

/* joe-09292004 - added function for removing Group Information */
function remInformation(infoType)
{
  var minCount = 1;
  var frm = document.frmFormType;
  var curIdx = frm.hidaddctr.value;
  var count = 1;  // number of events to be removed - for future use
    var isMinIE4 = (document.all) ? 1 : 0;
    var addLink = (isMinIE4) ? document.all["addlink"] : document.getElementById("addlink");
    var strAddLink = "";
    var strRemLink = "";
  var minRemEvent = 5;

  if (infoType) { // joe-09302004 - safety check 
    switch (infoType) {
    case 1: // event information for Meeting Single
      break;
    case 2: // Group information for Series Travel
      strAddLink = addGroupLink;
      strRemLink = remGroupLink;
      break;
    case 3: // Group information for Meeting Multiple
      strAddLink = addGroup2Link;
      strRemLink = remGroup2Link;
      break;
    case 4: // Event information for MiceCorp
      strAddLink = addEvent2Link;
      strRemLink = remEvent2Link;
      break;
    case 5: // Event information for Multi-meeting
      strAddLink = addEvent3Link;
      strRemLink = remEvent3Link;
      break;
    }
  
  }

  for (var i=0; i<count; i++) {
    if (curIdx > minCount) {
      var divEvent = (isMinIE4) ? document.all["divEvent_"+curIdx] : document.getElementById("divEvent_"+curIdx);
      curIdx--;
    divEvent.innerHTML = '';
    }
  }
    
  if (infoType == 3) {
    if (curIdx >= minRemEvent) {
      addLink.innerHTML = '<h2>' + strAddLink + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strRemLink + '</h2>';
    } else {
      addLink.innerHTML = '<b>' + strAddLink + '</b> ' + minimumNote;
    }
   } else {
    if (curIdx > minCount) {
      addLink.innerHTML = '<h2>' + strAddLink + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strRemLink + '</h2>';
    } else {
      addLink.innerHTML = '<h2>' + strAddLink + '</h2>';
  }

  }
   
  frm.hidaddctr.value = curIdx;
}

/* joe-09292004 - added function for adding Group Information in Meeting Multiple forms */
function addGroupInformation2() {
  var frm = document.frmFormType;
  var curIdx = frm.hidaddctr.value;
  var maxCount = 10;
  var count = 1;
  var minRemEvent = 5;

  if (!hasInformationForAdd(frm, 'event')) return false;

    var isMinIE4 = (document.all) ? 1 : 0;
    if (curIdx < 4) {
    count = 4 - curIdx;
  }
  for (var i=0; i<count; i++) { // joe-08012005 minimum of 4 events in meeting multiple forms
  if (curIdx<maxCount) {
    curIdx++;
    frm.hidaddctr.value = curIdx;

    var txt = '<table width="550" border="0" cellspacing="0" cellpadding="0">';
    txt += '<tr>';
    txt += '<td colspan="8"><br><hr width="100%" color="#b1b4c5" noshade size="1"></td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="8"><font color="#CC0000"><b>Event ' + curIdx + '</b></font></td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="8"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td>';
    txt += '</tr>';
    txt += '<tr><td width="270"><b>Event Name*</b><br>';
    txt += '<input name="txtGroupNameREQ_'+curIdx+'" type="text" id="txtGroupNameREQ_'+curIdx+'" size="35" maxlength="80"></td>';
    txt += '<td width="10">&nbsp;</td>';
    txt += '<td width="270"><b>Destination*</b> <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)</small></i><br>';
    txt += genCity('selDestinationREQ', curIdx, '', true);
    txt += '</td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td>';
    txt += '</tr>';
    txt += '<tr valign="bottom"><td><b>Number of Passengers*</b> <i><small>(Minimum of 10)</small></i><br>';
    txt += '<input name="txtPassengerCountREQ_'+curIdx+'" type="text" id="txtPassengerCountREQ_'+curIdx+'" size="5" maxlength="4">';
    txt += '</td>';
    txt += '<td>&nbsp;</td>';
    txt += '<td><b>Class of Service*</b></br>';
    txt += genClass('selClass', curIdx, '', true);
    txt += '</td></tr>';
    txt += '<tr>';
    txt += '<td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td>';
    txt += '</tr>';
    txt += '<tr valign="bottom">';
    txt += '<td><b>Start Date*</b><br>';
    txt += genDate('selStartMonthREQ', 'selStartDayREQ', 'selStartYearREQ', curIdx, '', '', '', true);
    txt += '</td>';
    txt += '<td>&nbsp;</td>';
    txt += '<td><b>End Date*</b><br>';
    txt += genDate('selEndMonthREQ', 'selEndDayREQ', 'selEndYearREQ', curIdx, '', '', '', true);
    txt += '</td>';
    txt += '</tr>';
    txt += '</table>';
      
    var divEvent = (isMinIE4) ? document.all["divEvent_"+curIdx] : document.getElementById("divEvent_"+curIdx);
      divEvent.innerHTML = txt;
    } else {
      break;
    }
  }
  
    var addLink = (isMinIE4) ? document.all["addlink"] : document.getElementById("addlink");

    if (curIdx >= maxCount){
      addLink.innerHTML = '<h2>' + remGroup2Link + '</h2>';
  } else if (curIdx >= minRemEvent){
    //LG 20050930 should only show remove link for 5 or more events
      addLink.innerHTML = '<h2>' + addGroup2Link + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + remGroup2Link + '</h2>';
  } else {
    addLink.innerHTML = '<b>' + addGroup2Link + '</b> ' + minimumNote;
  }
}

/* joe-09302004 - added function for adding Event Information in MiceCorp forms */
function addEventInformation2() {
  var frm = document.frmFormType;
  var curIdx = frm.hidaddctr.value;
  var maxCount = 10;
  var minRemEvent = 1;
  if (!hasInformationForAdd(frm, 'event')) return false;
  if (curIdx<maxCount) {
    curIdx++;
    frm.hidaddctr.value = curIdx;

    var txt = '<table width="550" border="0" cellspacing="0" cellpadding="0">';
    txt += '<tr>';
    txt += '<td colspan="3"><br><hr width="100%" color="#b1b4c5" noshade size="1"></td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="3"><font color="#CC0000"><b>Event ' + curIdx + '</b></font></td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td>';
    txt += '</tr>';
    txt += '<tr><td><b>Event Name*</b><br>';
    txt += '<input name="txtGroupNameREQ_'+curIdx+'" type="text" id="txtGroupNameREQ_'+curIdx+'" size="35" maxlength="40"></td>';
    txt += '<td width="10">&nbsp;</td>';
    txt += '<td><b>Destination*</b> <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)</small></i><br>';
    txt += genCity('selDestinationREQ', curIdx, '', true);
    txt += '</td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td colspan="3">';
    txt += '<b>Number of Passengers*</b> <i><small>(Minimum of 10)</small></i><br>';
    txt += '<input name="txtPassengerCountREQ_'+curIdx+'" type="text" id="txtPassengerCountREQ_'+curIdx+'" size="5" maxlength="4">';
    txt += '</td></tr>';
    txt += '<tr>';
    txt += '<td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td>';
    txt += '</tr>';
    txt += '<tr>';
    txt += '<td valign="bottom"><b>Start Date*</b><br>';
    txt += genDate('selStartMonthREQ', 'selStartDayREQ', 'selStartYearREQ', curIdx, '', '', '', true);
    txt += '</td>';
    txt += '<td>&nbsp;</td>';
    txt += '<td valign="bottom"><b>End Date*</b><br>';
    txt += genDate('selEndMonthREQ', 'selEndDayREQ', 'selEndYearREQ', curIdx, '', '', '', true);
    txt += '</td></tr></table>';
    var isMinIE4 = (document.all) ? 1 : 0;
    var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;
    var divEvent = (isMinIE4) ? document.all["divEvent_"+curIdx] : document.getElementById("divEvent_"+curIdx);
    var addLink = (isMinIE4) ? document.all["addlink"] : document.getElementById("addlink");
    divEvent.innerHTML = txt;

    if (curIdx >= maxCount){
      addLink.innerHTML = '<h2>' + remEvent2Link + '</h2>';
    } else if (curIdx >= minRemEvent){
    //LG 20050930 should only show remove link for 5 or more events
      addLink.innerHTML = '<h2>' + addEvent2Link + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + remEvent2Link + '</h2>';
    } else {
      addLink.innerHTML = '<h2>' + addEvent2Link + '</h2>';
    }
  } else {
    return;
  }
}

//roxanne 09/30/04 - added for multi-meeting registration form
function addEventInformation3() {
  var frm = document.frmFormType;
  var curIdx = frm.hidaddctr.value;
  var maxCount = 10;
  var minRemEvent = 1;
  if (!hasInformationForAdd(frm, 'event')) return false;
  if (curIdx<maxCount) {
    curIdx++;
    frm.hidaddctr.value = curIdx;

    var txt = '<table width="550" border="0" cellspacing="0" cellpadding="0">';
    txt += '<tr><td colspan="3"><br><hr width="100%" color="#b1b4c5" noshade size="1"></td></tr>';
    txt += '<tr><td colspan="3"><font color="#CC0000"><b>Event ' + curIdx + '</b></font></td></tr>';
    txt += '<tr><td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr><td width="270"><b>Number of Passengers*</b><br>';
    txt += '<input name="txtPassengerCountREQ_' + curIdx + '" type="text" id="txtPassengerCountREQ_' + curIdx + '" size="5" maxlength="4">';
    txt += '</td><td width="10">&nbsp;</td><td width="270">';
    txt += '<b>Destination*</b> <i><small>(City Name or </small></i><a href="javascript:openAirport(\'/grouprequest/airport_codes_popup.html\');"><i><small>Airport Code</small></i></a>)</small></i><br>';
    txt += genCity('selDestinationREQ', curIdx, '', true);
    txt += '</td></tr>';
    txt += '<tr><td colspan="3"><img src="/images/shared/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
    txt += '<tr><td><b>Start Date*</b><br>';
    txt += genDate('selStartMonthREQ', 'selStartDayREQ', 'selStartYearREQ', curIdx, '', '', '', true);
    txt += '</td><td>&nbsp;</td><td><b>End Date*</b><br>';
    txt += genDate('selEndMonthREQ', 'selEndDayREQ', 'selEndYearREQ', curIdx, '', '', '', true);
    txt += '</td></tr></table>';

    var isMinIE4 = (document.all) ? 1 : 0;
    var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;
    var divEvent = (isMinIE4) ? document.all["divEvent_"+curIdx] : document.getElementById("divEvent_"+curIdx);
    var addLink = (isMinIE4) ? document.all["addlink"] : document.getElementById("addlink");
    divEvent.innerHTML = txt;
    
    if (curIdx >= maxCount){
      addLink.innerHTML = '<h2>' + remEvent3Link + '</h2>';
    } else if (curIdx >= minRemEvent){
    //LG 20050930 should only show remove link for 5 or more events
      addLink.innerHTML = '<h2>' + addEvent3Link + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + remEvent3Link + '</h2>';    
    } else {
      addLink.innerHTML = '<h2>' + addEvent3Link +  '</h2>';
    }

  }
}

//checking for required
function validate() {
  var frm = document.frmFormType;
  var frmLen = frm.elements.length;
  var pageType = document.frmGeneral.pagetype.value;
  var email1 = "";
  var altEmail1 = "";
  
  disable(true);
  if (!requiredIsPopulated(frm)) {
    return false;
  }
  else {
    with (frm) {
      var eventItems = 1;
      var zipObj = null;
      var stateObj = null;
      var country = "";
      var useCorporateAccount = false;
      var accountCodeObj = "";
      for (var i=0; i<frmLen; i++) {
        var eleName = frm.elements[i].name;
        //IATA ID
        if (eleName.match(/txtIATA/)!=null) {
          if (frm.elements[i].value != "") {
            if ((!isValidIATA(frm.elements[i])) && (!isValidSkyMiles(frm.elements[i]))) {
              if ((eleName.match(/\*/) != null) && (frm.pagetype.value != 'Micecorp')) {
                alert("Invalid " + getDisplayMsg(eleName, " /SkyMiles Number."));
              }
              else {
                alert("Invalid " + getDisplayMsg(eleName, "."));
              }
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        else if (eleName.match(/Additional_IATA/) != null) {
          if (frm.elements[i].value != "") {
            if (!isValidIATA(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //Get State Obj
        else if (eleName.match(/State/)!=null) {
          if (frm.elements[i].value != "") {
            stateObj = frm.elements[i];
          }
        }
        //Get ZIP Code Object
        else if (eleName.match(/Zip/)!=null) {
          if (frm.elements[i].value != "") {
            zipObj = frm.elements[i];
          }
        }
        //Get Country
        else if (eleName.match(/Country/)!=null) {
          if (frm.elements[i].value != "") {
            country = frm.elements[i].value;
          }
        }
        //Use Corporate Account query (yes/no)
        else if (eleName.match(/UseCorporateAccount/)!=null) {
          if (frm.elements[i].value.toLowerCase() =="no")
            useCorporateAccount = true;
        }
        //Corporate Account Code/ID
        else if (eleName.match(/AccountCode/)!=null) {
          accountCodeObj = frm.elements[i];
        }
        //Phone
        else if (eleName.match(/Phone/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidPhone(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, ". Proper format should be \r\n(xxx-xxx-xxxx)."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //Extension
        else if (eleName.match(/Extension/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidExtension(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, " Number."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //Fax
        else if (eleName.match(/FaxNumber/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidPhone(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, ". Proper format should be \r\n(xxx-xxx-xxxx)."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //Email
        else if (eleName.match(/txtEmail/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidEmail(frm.elements[i])) {
              alert("Invalid E-mail address.");
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }else{
                email1 = frm.elements[i].value;
            }
          }
        }
        else if (eleName.match(/txtReenterEmail/)!=null) {
          if (!checkEmail(frm.elements[i].value, email1)) {
            alert("The E-mail addresses you have entered do not match");
            frm.elements[i].style.background = "#FFFF99";
            frm.elements[i].select();
            frm.elements[i].focus();
            disable(false);
            return false;
          }
        }
        else if (eleName.match(/txtAlternateEmail/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidEmail(frm.elements[i])) {
              alert("Invalid alternate E-mail address.");
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }else{
                altEmail1 = frm.elements[i].value;
            }
          }
            }
        else if (eleName.match(/txtReenterAlternateEmail/)!=null) {
          if ((altEmail1 != "") && (!checkEmail(frm.elements[i].value, altEmail1))) {
            if (isBlank(frm.elements[i])) {
              alert("Please enter the following information:\nRe-enter Alternate E-mail Address");
            } else {
              alert("The E-mail addresses you have entered do not match");
            }
            frm.elements[i].style.background = "#FFFF99";
            frm.elements[i].select();
            frm.elements[i].focus();
            disable(false);
            return false;
          }
        }

        //WorldPerks/SkyMiles Number
        else if (eleName.match(/WPNumber/)!=null) { // Edited by joe 28Sept2004
          if (frm.elements[i].value != "") {
            if ((!isBlank(frm.elements[i])) && (!isValidSkyMiles(frm.elements[i]))) {
              alert("Invalid SkyMiles Number.");
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //retrieve the number of events
        else if (eleName.toLowerCase()=="hidaddctr") {
          //get the number of event items
          if (frm.elements[i].value != "") {
            eventItems = frm.elements[i].value;
          }
        }
        //Passenger Count
        else if (eleName.match(/PassengerCount/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidPassengerCount(frm.elements[i])) {
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //Bulletin Number
        else if (eleName.match(/BulletinNumber/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidBulletinNumber(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              disable(false);
              return false;
            }
          }
        }
        //Additional Info
        else if (eleName.match(/AdditionalInfo/)!=null) {
          if (frm.elements[i].value != "") {
            if ((!isBlank(frm.elements[i]))&&(!hasValidChars(frm.elements[i]))) {
              alert("Invalid character found in " + getDisplayMsg(eleName, ".\r\nOnly the following characters are valid: a-zA-Z0-9!@#$%&*()':;,<>.?/\\-"));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
        //Ticket Designator
        else if (eleName.match(/TicketDesignator/)!=null) {
          if (frm.elements[i].value != "") {
            var retVal = false;
            retVal = isValidTicketDesignator(frm.elements[i]);
            if (!retVal) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              disable(false);
              return false;
            }
          }
        }
        // Agreement Code
        else if (eleName.match(/AgreementCode/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidAgreementGroupCode(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              disable(false);
              return false;
            }
          }
        }
        // Reservation/Bulletin/Contract/WorldFile Number
        else if (eleName.match(/ReservationNumber/)!=null) {
          if (frm.elements[i].value != "") {
            if ((!hasValidAlphaNumeric(frm.elements[i],6)) && (!isValidBulletinNumber(frm.elements[i]))) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              disable(false);
              return false;
            }
          }
        }
        // Trade Show Code
        else if (eleName.match(/TradeShowCode/)!=null) {
          if (frm.elements[i].value != "") {
            if (!isValidTradeCode(frm.elements[i])) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              disable(false);
              return false;
            }
          }
        }
        // Flight Number
        else if (eleName.match(/FlightNumber/)!=null) {
          if (frm.elements[i].value != "") {
            if (!hasValidAlphaNumeric(frm.elements[i], '1,6')) {
              alert("Invalid " + getDisplayMsg(eleName, "."));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              disable(false);
              return false;
            }
          }
        }
        //Check for illegal characters
        else if (eleName.match(/^txt/)!=null) {
          if (frm.elements[i].value != "") {
            if ((!isBlank(frm.elements[i]))&&(!hasValidChars(frm.elements[i]))) {
              alert("Invalid character found in " + getDisplayMsg(eleName, ".\r\nOnly the following characters are valid: a-zA-Z0-9!@#$%&*()':;,<>.?/\\-"));
              frm.elements[i].style.background = "#FFFF99";
              frm.elements[i].select();
              frm.elements[i].focus();
              disable(false);
              return false;
            }
          }
        }
      //end of for loop
      }
      
      //checking of zip code
      if (zipObj != null) {
        if (!isValidZip(zipObj, country)) {
          alert("Invalid " + getDisplayMsg(zipObj.name, " for " + country + "."));
          zipObj.style.background = "#FFFF99";
          zipObj.select();
          zipObj.focus();
          disable(false);
          return false;
        }
      }
      //check of state
      if ((stateObj != null) && (stateObj.value == "")) {
        if (stateObj.value == "AB"||stateObj.value == "BC"||stateObj.value == "MB"||
          stateObj.value == "NB"||stateObj.value == "NL"||stateObj.value == "NS"||
          stateObj.value == "NT"||stateObj.value == "NU"||stateObj.value == "ON"||
          stateObj.value == "PE"||stateObj.value == "QC"||stateObj.value == "SK"||
          stateObj.value == "YT") {
          if (country == "US") {
            alert("Invalid State for the chosen country.");
            stateObj.style.background = "#FFFF99";
            stateObj.focus();
            disable(false);
            return false;
          }
        }
        else {
          if (country == "CA") {
            alert("Invalid State for the chosen country.");
            stateObj.style.background = "#FFFF99";
            stateObj.focus();
            disable(false);
            return false;
          }
        }
      }
      
      //check of corporate ID query and code
      if (useCorporateAccount) {
        if (accountCodeObj.value == "") {
          alert("The Account Code is required if you have \r\nNOT opted to use your Corporate Account Code.");
          accountCodeObj.style.background = "#FFFF99";
          accountCodeObj.focus();
          disable(false);
          return false;
        }
        else if (!hasValidAlphaNumeric(accountCodeObj,'0,8')) {
          alert("Invalid Account Code. Only Alphanumeric characters are allowed.");
          accountCodeObj.style.background = "#FFFF99";
          accountCodeObj.focus();
          disable(false);
          return false;
        }
      }
      
      //checking of date
      var monthOutboundObj = "";
      var dayOutboundObj   = "";
      var yearOutboundObj  = "";
      var monthReturnObj   = "";
      var dayReturnObj   = "";
      var yearReturnObj  = "";

      if ((pageType == "leisure") || (pageType == "military")) {    
        monthOutboundObj = eval("frm.selOutboundMonthREQ_1");
        dayOutboundObj   = eval("frm.selOutboundDayREQ_1"  );
        yearOutboundObj  = eval("frm.selOutboundYearREQ_1" );
        monthReturnObj   = eval("frm.selReturnMonth_1");
        dayReturnObj   = eval("frm.selReturnDay_1"  );
        yearReturnObj   = eval("frm.selReturnYear_1" );        
        if (!checkDate(monthOutboundObj, dayOutboundObj, yearOutboundObj, monthReturnObj, dayReturnObj, yearReturnObj, "Outbound", "Return")) {
          disable(false);
          return false;
        }
      }
      else if ((pageType == "meetingSingle") || (pageType == "series")) {
        var infotype = "Group";
        for (var i = 1; i <= eventItems; i++) {
          monthOutboundObj = eval("frm.selOutboundMonthREQ_" + i);
          dayOutboundObj   = eval("frm.selOutboundDayREQ_" + i);
          yearOutboundObj  = eval("frm.selOutboundYearREQ_" + i);
          monthReturnObj   = eval("frm.selReturnMonth_" + i);
          dayReturnObj   = eval("frm.selReturnDay_" + i);
          yearReturnObj   = eval("frm.selReturnYear_" + i);

          if (!checkDate(monthOutboundObj, dayOutboundObj, yearOutboundObj, monthReturnObj, dayReturnObj, yearReturnObj, "Outbound", "Return", infotype, i)) {
            disable(false);
            return false;
          }
        }
      }
      else if ((pageType == "meetingMultiple") || (pageType == "Micecorp") || (pageType == "multiMeeting")) {
        var infotype = "Event";
        for (var i = 1; i <= eventItems; i++) {
          monthStartObj = eval("frm.selStartMonthREQ_" + i);
          dayStartObj   = eval("frm.selStartDayREQ_" + i);
          yearStartObj  = eval("frm.selStartYearREQ_" + i);
          monthEndObj   = eval("frm.selEndMonthREQ_" + i);
          dayEndObj   = eval("frm.selEndDayREQ_" + i);
          yearEndObj  = eval("frm.selEndYearREQ_" + i);
          
          if (pageType == "meetingMultiple") {
            if (!(isBlank(monthStartObj) && isBlank(dayStartObj) && isBlank(yearStartObj) && isBlank(monthEndObj) && isBlank(dayEndObj) && isBlank(yearEndObj)))
            {
          if (!checkDate(monthStartObj, dayStartObj, yearStartObj, monthEndObj, dayEndObj, yearEndObj, "Start", "End", infotype, i)) {
            disable(false);
            return false;
          }
        }
          } else {
            if (!checkDate(monthStartObj, dayStartObj, yearStartObj, monthEndObj, dayEndObj, yearEndObj, "Start", "End", infotype, i)) {
              disable(false);
              return false;
      }
    }
  }
      }
      /* minimum of 4 events for meeting multiple */
      if (pageType == "meetingMultiple") {
        var curIdx = frm.hidaddctr.value;
        if (eventsFilled != 0) {
          for (var i=0; i<(curIdx-eventsFilled); i++) {
            remInformation(3); /* remove excess Meeting Multiple events */
          }
          frm.hidaddctr.value = eventsFilled;
        }
      }
    }
  }
  return true;
}

function addARC() {
  var frm      = document.frmFormType;
  var curIdx   = frm.hidARCCount.value;
  var maxCount = 5;
  var txt      = '';
  var arrARC   = new Array();
  var isMinIE4   = (document.all) ? 1 : 0;

  for (var i = 1; i <= curIdx; i++) {
    var txtARC = (isMinIE4) ? document.all["txtAdditional_IATA_" + i] : document.getElementById("txtAdditional_IATA_" + i);
    if (txtARC) {
      arrARC.push(txtARC.value);
    }
  }
  arrARC.reverse();

  if (curIdx < maxCount) {
    curIdx++;
    frm.hidARCCount.value = curIdx;
    if (curIdx == 1) {
      txt += '<b>Additional ARC/IATA Number(s)</b> <i><small>(first seven digits)</small></i><br>';
    }
    txt += '<input name="txtAdditional_IATA_' + curIdx + '" type="text" id="txtAdditional_IATA_' + curIdx + '" size="10" maxlength="7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    var divEvent = (isMinIE4) ? document.all["addlARC"] : document.getElementById("addlARC");
    divEvent.innerHTML += txt;

    for (var i = 1; i < curIdx; i++) {
      var txtARC = (isMinIE4) ? document.all["txtAdditional_IATA_" + i] : document.getElementById("txtAdditional_IATA_" + i);
      if (txtARC) {
        txtARC.value = arrARC.pop();
      }
    }

    addAddlGDSSystem(curIdx);

    for (var i = 1; i <= curIdx; i++) {
      var txtARC = eval("frm.txtAdditional_IATA_" + curIdx);
      txtARC.focus();
    }
  }
  else {
    return;
  }
}

/* START 112107 - PTC-NRE: Add additional GDS */
function addAddlGDSSystem(curIdx) {
  var frm        = document.frmFormType;
  var isMinIE4   = (document.all) ? 1 : 0;
  var divAddlGDS = (isMinIE4) ? document.all["addlGDS"] : document.getElementById("addlGDS");
  var txtSelGDS = '<b>GDS Used for Ticketing</b> <i><small>(Travel Agency only)</small></i><br>';
  for (var i = 1; i < curIdx; i++) {
    var txtGDS = eval("frm.selAddlGDS_" + i);
    if (txtGDS) {
      txtSelGDS += genAddlGDSSystem(i, txtGDS.options[txtGDS.selectedIndex].value);
    }
  }
  txtSelGDS += genAddlGDSSystem(curIdx);
  divAddlGDS.innerHTML = txtSelGDS;
}
/* END   112107 - PTC-NRE: Add additional GDS */
