/***************************************************************************************************
  This js file combines what common.js, date.js, DrawDates.js, geography.js once contained
/**************************************************************************************************/
/***************************************************************************************************
  start common.js
/**************************************************************************************************/  
var allData;

function setImg(arg) {
   imgHolder = document.getElementById("resortDivingImg");
   imgHolder.src=arg;
}

//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06
var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
   var ulid=linkobj.parentNode.parentNode.id //id of UL element
   var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
   for (var i=0; i<ullist.length; i++){
      ullist[i].className="" //deselect all tabs
      if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
         document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
   }
   linkobj.parentNode.className="selected" //highlight currently clicked on tab
   document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
   saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
   var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
   if (thetab.getAttribute("rel"))
      expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
   if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
      tabcontentIDs[ulid]=new Array()
   tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
   if (enabletabpersistence==1) //if persistence feature turned on
      setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
   var ullist=document.getElementById(ulid).getElementsByTagName("li")
   for (var i=0; i<ullist.length; i++){
      if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
         return ullist[i].getElementsByTagName("a")[0]
         break
      }
   }
}

function initializetabcontent(){
   for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
      if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
         setCookie(arguments[i], "")
      var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
      var ulobj=document.getElementById(arguments[i])
      var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
      for (var x=0; x<ulist.length; x++){ //loop through each LI element
         var ulistlink=ulist[x].getElementsByTagName("a")[0]
         if (ulistlink.getAttribute("rel")){
            savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
            ulistlink.onclick=function(){
               expandcontent(this)
               return false
            }
            if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
               expandcontent(ulistlink) //auto load currenly selected tab content
         }
      } //end inner for loop
      if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
         var culistlink=getullistlinkbyId(arguments[i], clickedontab)
         if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
            expandcontent(culistlink) //auto load currenly selected tab content
         else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
            expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
      }
   } //end outer for loop
}

function getCookie(Name){
   var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
   if (document.cookie.match(re)) //if cookie found
      return unescape(document.cookie.match(re)[0].split("=")[1]); //return its value
   return "";
}

function setCookie(name, value){
   document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

function showResortHelp() {
   popupWin=window.open('resort_help.asp','','directories=No,location=No,menubar=no,status=YES,titlebar=no,toolbar=no,scrollbars=yes,width=800')
}

function showIconHelp() {
   popupWin=window.open('icons_help.asp','','directories=No,location=No,menubar=no,status=YES,titlebar=no,toolbar=no,scrollbars=yes,width=800')
}

function showDiv(arg) {
   objAll = document.getElementById("displayAll");
   objAll.style.display="none";
   obj = document.getElementById(arg);
   obj.style.display="";
}

function hideDiv(arg) {
   obj = document.getElementById(arg);
   obj.style.display="none";
   objAll = document.getElementById("displayAll");
   objAll.style.display="";
}

function openPopup(url) {
   var width = 800;
   var height = 600;
   var top = (screen.availHeight - height) / 2;
   var left = (screen.availWidth  - width)  / 2;
   var features = "directories=No,location=No,menubar=no,status=YES,titlebar=no,toolbar=no,scrollbars=yes,width="+width+",height="+height+", top="+top+", left="+left+",resizable=no";
   var newWin = open(url,"newWin",features);
}

function getRating(rating) {
   outHTML=""
   var fullRating = 0;
   var halfRating = "N";
   rating = rating.toLowerCase();
   if(rating.indexOf('t')>-1)
   {
   for(var cnt=0;cnt < rating.length;cnt++)
   {
   if(rating.substring(cnt,cnt+1)=='t')
      fullRating++;
   }
   }
   if(rating.indexOf('+')>-1 || rating.indexOf(' ')>-1 || rating.indexOf('p')>-1) {
      halfRating = "Y";
     if(rating.indexOf('t')<0)
      fullRating = parseInt(rating);
   }
   else if(rating.indexOf('t')<0)
      fullRating = Number(rating);
   for(var cntr=0;cntr<fullRating;cntr++) {
      outHTML+="<img src='/AtcomCMSLImages/swoosh_bullet.gif'/>";
   }
   if(halfRating == "Y")
      outHTML+="<img src='/AtcomCMSLImages/swoosh_bullet_half.gif'/>";
   document.write(outHTML);
}
function getRating(rating,fullRatingURL,halfRatingURL) {
   outHTML="";
   if(rating.toLowerCase().indexOf('star')>-1 || rating.toLowerCase().indexOf('category')>-1)
   {
      document.write("<span class='splrating'> <b>Official Rating:</b><br/> "+rating+"</span>");
       return;
   }
   if(rating.length > 10)
   {
      document.write("<span class='splrating'>"+rating+"</span>");
      return;
   }
   var fullRatingImg = "<img src='"+ fullRatingURL +"'/>";
   var halfRatingImg = "<img src='"+ halfRatingURL +"'/>";
   var fullRating = 0;
   var halfRating = "N";
   rating = rating.toLowerCase();
   if(rating.indexOf('t')>-1)
   {
   for(var cnt=0;cnt < rating.length;cnt++)
   {
   if(rating.substring(cnt,cnt+1)=='t')
      fullRating++;
   }
   }
   if(rating.indexOf('+')>-1 || rating.indexOf(' ')>-1 || rating.indexOf('p')>-1 || rating.indexOf('.')>-1) {
      halfRating = "Y";
     if(rating.indexOf('t')<0)
      fullRating = parseInt(rating);
   }
   else if(rating.indexOf('t')<0)
      fullRating = Number(rating);
   for(var cntr=0;cntr<fullRating;cntr++) {
      outHTML+=fullRatingImg;
   }
   if(halfRating == "Y")
      outHTML+=halfRatingImg;
   document.write(outHTML);
}

function getRatingSpl(rating) {
   outHTML=""
   var fullRating = 0;
   var halfRating = "N";
   rating = rating.toLowerCase();
   if(rating.indexOf('t')>-1)
   {
   for(var cnt=0;cnt < rating.length;cnt++)
   {
   if(rating.substring(cnt,cnt+1)=='t')
      fullRating++;
   }
   }
   if(rating.indexOf('+')>-1 || rating.indexOf(' ')>-1 || rating.indexOf('p')>-1 || rating.indexOf('.')>-1) {
      halfRating = "Y";
     if(rating.indexOf('t')<0)
      fullRating = parseInt(rating);
   }
   else if(rating.indexOf('t')<0)
      fullRating = Number(rating);
   for(var cntr=0;cntr<fullRating;cntr++) {
      outHTML+="<img src='/AtcomCMSLImages/swoosh_bullet.gif' width='25' height='8'/>";
   }
   if(halfRating == "Y")
      outHTML+="<img src='/AtcomCMSLImages/swoosh_bullet_half.gif' width='25' height='8'/>";

   return outHTML;
}

function addDealOfWeek() {
   outHTML = "<tr><td class='dwResortData'>"+arguments[0]+"</td><td class='dwAccomData'>"+ arguments[1] +"</td><td class='dwBoardData'>"+ getRatingSpl(arguments[2]) +"</td><td class='dwBoardData2'>"+ arguments[3] +"</td><td class='dwDepData'>"+ arguments[4] +"</td><td class='dw7NightData'>"+ arguments[5] +"</td></tr>"
   allData = allData + outHTML;
   document.write (outHTML);
}

function addSplOffer() {
   outHTML = "<tr><td class='splResData'>"+ arguments[0] +"</td><td class='splAccomData'>"+ arguments[1] +"</td><td class='splBoardData'>"+ getRatingSpl(arguments[2]) +"</td><td class='splBoardData2'>"+ arguments[3] +"</td><td class='splDepData'>"+ arguments[4] +"</td><td class='splBrPriceData'>"+ arguments[5] +"</td><td class='splOfferPriceData'>"+ arguments[6] +"</td></tr>"
   allData = allData + outHTML;
   document.write (outHTML);
}

function addPkgSplOffer() {
   outHTML = "<tr><td class='splpkgResData'>"+ arguments[0] +"</td><td class='splpkgAccomData'>"+ arguments[1] +"</td><td class='splpkgBoardData'>"+ arguments[2] +"</td><td class='splpkgDepData'>"+ arguments[3] +"</td><td class='splpkgBrPriceData'>"+ arguments[4] +"</td><td class='splOfferPriceData'>"+ arguments[5] +"</td></tr>"
   allData = allData + outHTML;
   document.write (outHTML);
}

function truncateSentence(sentence,numWords) {
   var str='';
   var splitStr = sentence.split(' ');
   var totalNumWords = splitStr.length;
   for(i=0;i<numWords && i<totalNumWords;i++)
   {
      str=str+splitStr[i]+" ";
   }
   document.write(str);
}

function call_Country(obj) {
   cntry=obj.value;
   if(cntry!="")
   {
      window.open("anitenextpage.asp?p=STO-02COUNTRY_"+cntry+"&xml=PARENTCOUNTRYID%20"+cntry,"_top");
   }
}

function createPax(){
   totalPax=8;
   for(i=1;i<=totalPax;i++) document.write("<option value='"+i+"'>"+i+"</option>");
}

function chekPax() {
   document.getElementById("Pax").selectedIndex =0;
}

function changePax(alPax) {
   var tablerow = "<table cellpadding='0' cellspacing='3' border='0'>";
   tablerow += "<tr>";
   tablerow += "<td width='13%'>Title</td>";
   tablerow += "<td width='29%'>First Name</td>";
   tablerow += "<td width='29%'>Surname</td>";
   tablerow += "<td width='29%'>DOB(dd/mm/yyyy)</td>";
   tablerow += "</tr>";

   for (i=1;i<=alPax;i++) {
      tablerow += "<tr>";
      tablerow += "<td><select name='title"+i+"' id='title"+i+"'>";
      tablerow += "<option value='Mr'>Mr</option>";
      tablerow += "<option value='Mrs'>Mrs</option>";
      tablerow += "<option value='Miss'>Miss</option>";
      tablerow += "<option value='Ms'>Ms</option>";
      tablerow += "<option value='Dr'>Dr</option>";
      tablerow += "<option value='Master'>Master</option>";
      tablerow += "</select></td>";
      tablerow += "<td><input type='text' name='forename"+i+"' id='forename"+i+"'></td>";
      tablerow += "<td><input type='text' name='surname"+i+"' id='surname"+i+"'></td>";
      tablerow += "<td><input type='text' name='dob"+i+"' id='dob"+i+"'></td>";
      tablerow += "</tr>";
   }

   tablerow += "</table>";
   document.getElementById("paxtable").innerHTML = tablerow;
}

function validateEmailQuote(obj) {
      //Check for empty strings
      if(trim(document.getElementById("forename").value) ==''||
      trim(document.getElementById("surname").value) ==''||
      trim(document.getElementById("housenumber").value) ==''||
      (trim(document.getElementById("streetname").value) =='' && obj=='frmEmail' ) ||
      trim(document.getElementById("postcode").value) ==''||
      trim(document.getElementById("country").value) ==''||
      (trim(document.getElementById("telephone").value) =='' && obj=='frmEmail') ||
      trim(document.getElementById("email").value) =='') {
         alert('Please complete all the fields marked with *');
         return false;
      }

      if(document.getElementById("telephone").value!=''){
         var telString = document.getElementById("telephone").value;
         var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
         if(isNaN(stripped) == true){
            alert("Please enter a valid Telephone number");
            return false;
         }
      }

      //Validate email strings
      var emailString = document.getElementById("email").value;

      var emailFilter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      if(!(emailString.match(emailFilter))) {
         alert("Please enter a valid Email address");
         return false;
      }

      var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
      if(emailString.match(illegalChars)) {
         alert("The Email address contains illegal characters");
         return false;
      }

      //Check for Lead passenger and privacy acceptance in Email Me a Quote
      if(obj=='frmEmail') {

   if(document.getElementById("CTY1_ID").selectedIndex == 0) {
      alert('Please select a destination');
      document.getElementById("CTY1_ID").focus();
      return false;
   }
   if(document.getElementById("CTY3_ID").selectedIndex == 0) {
      alert('Please select a resort');
      document.getElementById("CTY3_ID").focus();
      return false;
   }

         if(document.getElementById("privConfirmation").checked == false) {
            alert('Please accept the Privacy Policy checkbox to proceed');
            return false;
         }
      }

   //Check for Brochure receipt in Signup for enews
   if(obj=='frmEnews') {
      if(
         document.getElementById("africa").checked == false &&
         document.getElementById("cio").checked == false &&
         document.getElementById("americaCanada").checked == false &&
         document.getElementById("cities").checked == false &&
         document.getElementById("asiaArabian").checked == false &&
         document.getElementById("escortedTouring").checked == false &&
         document.getElementById("ausNewzealand").checked == false
      ) {
         alert('Please tick any of the products');
         return false;
      }
   }
   var resort = document.getElementById("resort");
   resort.value = getSelectedText("CTY3_ID");
}

function validateFormEnews(obj) {

      //Check for empty strings
      if(trim(document.getElementById("forename").value) ==''||
      trim(document.getElementById("surname").value) ==''||
      trim(document.getElementById("town").value) ==''||
      trim(document.getElementById("postcode").value) ==''||
      trim(document.getElementById("email").value) =='') {
         alert('Please complete all the fields marked with *');
         return false;
      }

      if(document.getElementById("telephone").value!=''){
         var telString = document.getElementById("telephone").value;
         var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
         if(isNaN(stripped) == true){
            alert("Please enter a valid Telephone number");
            return false;
         }
      }

      //Validate email strings
      var emailString = document.getElementById("email").value;

      var emailFilter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      if(!(emailString.match(emailFilter))) {
         alert("Please enter a valid Email address");
         return false;
      }

      var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
      if(emailString.match(illegalChars)) {
         alert("The Email address contains illegal characters");
         return false;
      }

         if(document.getElementById("privacyConfirm").checked == false) {
            alert('Please accept the Privacy Policy checkbox to proceed');
            return false;
         }
      if(
         document.getElementById("africa").checked == false &&
         document.getElementById("cio").checked == false &&
         document.getElementById("americaCanada").checked == false &&
         document.getElementById("cities").checked == false &&
         document.getElementById("asiaArabian").checked == false &&
         document.getElementById("escortedTouring").checked == false &&
         document.getElementById("ausNewzealand").checked == false
      ) {
         alert('Please tick any of the products');
         return false;
   }
}

function validateFormCIT(obj) {

      //Check for empty strings
      if(trim(document.getElementById("title").value) ==''||
      trim(document.getElementById("forename").value) ==''||
      trim(document.getElementById("surname").value) ==''||
      trim(document.getElementById("housenumber").value) ==''||
      trim(document.getElementById("postcode").value) ==''||
      trim(document.getElementById("telephone").value) =='' ||
      trim(document.getElementById("email").value) =='') {
         alert('Please complete all the fields marked with *');
         return false;
      }

      if(document.getElementById("telephone").value!=''){
         var telString = document.getElementById("telephone").value;
         var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
         if(isNaN(stripped) == true){
            alert("Please enter a valid Home Telephone number");
            return false;
         }
      }
      if(document.getElementById("txtPhoneWork").value!=''){
         var telString = document.getElementById("txtPhoneWork").value;
         var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
         if(isNaN(stripped) == true){
            alert("Please enter a valid Work Telephone number");
            return false;
         }
      }
   if(document.getElementById("txtComments").value=='')
   {
      alert("Please fill in the comments");
      document.getElementById("txtComments").focus();
   }
      //Validate email strings
      var emailString = document.getElementById("email").value;

      var emailFilter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      if(!(emailString.match(emailFilter))) {
         alert("Please enter a valid Email address");
         return false;
      }

      var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
      if(emailString.match(illegalChars)) {
         alert("The Email address contains illegal characters");
         return false;
      }
 if (document.getElementById("hidAgree").value == "NO")
   {
      alert("You must agree to the terms and conditions");
      return false;
   }
/*
         if(document.getElementById("privacyConfirm").checked == false) {
            alert('Please accept the Privacy Policy checkbox to proceed');
            return false;
         }*/
}

function validateFormCITBro(obj) {
   if(trim(document.getElementById('title1').value) ==""||
   trim(document.getElementById('forename').value) ==""||
   trim(document.getElementById('surname').value) ==""||
   trim(document.getElementById('housenumber').value) ==""||
   trim(document.getElementById('postcode').value) ==""||
   trim(document.getElementById('telephone').value) =="" ||
   trim(document.getElementById('towncity').value) =="" ||
   trim(document.getElementById("email").value) =="") {
      alert("Please complete all the fields marked with *");
      return false;
   }

   if(document.getElementById("telephone").value!=''){
      var telString = document.getElementById("telephone").value;
      var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
      if(isNaN(stripped) == true){
         alert("Please enter a valid Telephone number");
         return false;
      }
   }

   var emailString = document.getElementById("email").value;
   var emailFilter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
   if(!(emailString.match(emailFilter))) {
      alert("Please enter a valid Email address.");
      return false;
   }

   var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
   if(emailString.match(illegalChars)) {
      alert("The Email address contains illegal characters");
      return false;
   }

   //Check for Brochure checkboxes
   if(obj.id =='frmEnews' || obj.id =='frmbrochure') {
      if(
         document.getElementById("africa").checked == false &&
         document.getElementById("cio").checked == false &&
         document.getElementById("americaCanada").checked == false &&
         document.getElementById("cities").checked == false &&
         document.getElementById("asiaArabian").checked == false &&
         document.getElementById("escortedTouring").checked == false &&
         document.getElementById("ausNewzealand").checked == false &&
         document.getElementById("disney").checked == false
      ) {
         alert('Please tick any one of the products');
         return false;
      }

    // To limit the brochure tick to 6 code start here
   var NewCount = 0
     if (document.getElementById("africa").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("cio").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("americaCanada").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("cities").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("asiaArabian").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("escortedTouring").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("ausNewzealand").checked)
     {NewCount = NewCount + 1}
   if (document.getElementById("disney").checked)
     {NewCount = NewCount + 1}
   if (NewCount > 6)
   {
    alert('Please tick up to 6 products only')
    return false;
   }

  // To limit the brochure tick to 6 code ends here
   }

   if (document.getElementById("hidAgree").value == "NO") {
      alert("You must agree to the terms and conditions");
      return false;
   }
}

function validateForm(obj) {

      //Check for empty strings
      if(trim(document.getElementById("forename").value) ==''||
      trim(document.getElementById("surname").value) ==''||
      trim(document.getElementById("housenumber").value) ==''||
      trim(document.getElementById("postcode").value) ==''||
      trim(document.getElementById("country").value) ==''||
      (trim(document.getElementById("telephone").value) =='' && obj=='frmEmail') ||
      trim(document.getElementById("email").value) =='') {
         alert('Please complete all the fields marked with *');
         return false;
      }

      if(document.getElementById("telephone").value!=''){
         var telString = document.getElementById("telephone").value;
         var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
         if(isNaN(stripped) == true){
            alert("Please enter a valid Telephone number");
            return false;
         }
      }

   if(document.getElementById("destination").selectedIndex == 0) {
      alert('Please select a destination');
      document.getElementById("destination").focus();
      return false;
   }
   if(document.getElementById("resort").selectedIndex == 0) {
      alert('Please select a resort');
      document.getElementById("resort").focus();
      return false;
   }

      //Validate email strings
      var emailString = document.getElementById("email").value;

      var emailFilter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      if(!(emailString.match(emailFilter))) {
         alert("Please enter a valid Email address");
         return false;
      }

      var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
      if(emailString.match(illegalChars)) {
         alert("The Email address contains illegal characters");
         return false;
      }

      //Check for Lead passenger and privacy acceptance in Email Me a Quote
      if(obj=='frmEmail') {
         /*
         if(trim(document.getElementById("forename1").value) ==''||
         trim(document.getElementById("surname1").value) ==''||
         trim(document.getElementById("dob1").value) =='') {
            alert('Please enter atleast the lead passenger surname and forename');
            return false;
         }
         */

         if(document.getElementById("privConfirmation").checked == false) {
            alert('Please accept the Privacy Policy checkbox to proceed');
            return false;
         }
      }

   //Check for Brochure receipt in Signup for enews
   if(obj=='frmEnews') {
      if(
         document.getElementById("africa").checked == false &&
         document.getElementById("cio").checked == false &&
         document.getElementById("americaCanada").checked == false &&
         document.getElementById("cities").checked == false &&
         document.getElementById("asiaArabian").checked == false &&
         document.getElementById("escortedTouring").checked == false &&
         document.getElementById("ausNewzealand").checked == false
      ) {
         alert('Please tick any of the products');
         return false;
      }
   }
}

function trim(string) {
   return string.replace(/^\s*(.*)\s*$/,'$1');
}

function submitSearchRequest()
{
   if(ds_validate() && validate())
   {
      document.frmSubmitReq.START.value = document.frmSubmit.STDD.value+"-"+document.frmSubmit.STMM.value+"-"+document.frmSubmit.STYYYY.value;
      document.frmSubmitReq.STAY.value = document.frmSubmit.STAYN.value;
      document.frmSubmitReq.PX_A.value = document.frmSubmit.PXA.value;
      document.frmSubmitReq.PX_C.value = document.frmSubmit.PXC.value;
      document.frmSubmitReq.PX_I.value = document.frmSubmit.PXI.value;
      document.frmSubmitReq.PX_C01_DD.value = document.frmSubmit.CH1DD.value;
      document.frmSubmitReq.PX_C02_DD.value = document.frmSubmit.CH2DD.value;
      document.frmSubmitReq.PX_C03_DD.value = document.frmSubmit.CH3DD.value;
      document.frmSubmitReq.PX_C04_DD.value = document.frmSubmit.CH4DD.value;
      document.frmSubmitReq.PX_C05_DD.value = document.frmSubmit.CH5DD.value;
      document.frmSubmitReq.PX_C06_DD.value = document.frmSubmit.CH6DD.value;
      document.frmSubmitReq.PX_C07_DD.value = document.frmSubmit.CH7DD.value;
      document.frmSubmitReq.PX_C08_DD.value = document.frmSubmit.CH8DD.value;
      document.frmSubmitReq.PX_C09_DD.value = document.frmSubmit.CH9DD.value;

      document.frmSubmitReq.PX_C01_MM.value = document.frmSubmit.CH1MM.value;
      document.frmSubmitReq.PX_C02_MM.value = document.frmSubmit.CH2MM.value;
      document.frmSubmitReq.PX_C03_MM.value = document.frmSubmit.CH3MM.value;
      document.frmSubmitReq.PX_C04_MM.value = document.frmSubmit.CH4MM.value;
      document.frmSubmitReq.PX_C05_MM.value = document.frmSubmit.CH5MM.value;
      document.frmSubmitReq.PX_C06_MM.value = document.frmSubmit.CH6MM.value;
      document.frmSubmitReq.PX_C07_MM.value = document.frmSubmit.CH7MM.value;
      document.frmSubmitReq.PX_C08_MM.value = document.frmSubmit.CH8MM.value;
      document.frmSubmitReq.PX_C09_MM.value = document.frmSubmit.CH9MM.value;

      document.frmSubmitReq.PX_C01_YY.value = document.frmSubmit.CH1YYYY.value;
      document.frmSubmitReq.PX_C02_YY.value = document.frmSubmit.CH2YYYY.value;
      document.frmSubmitReq.PX_C03_YY.value = document.frmSubmit.CH3YYYY.value;
      document.frmSubmitReq.PX_C04_YY.value = document.frmSubmit.CH4YYYY.value;
      document.frmSubmitReq.PX_C05_YY.value = document.frmSubmit.CH5YYYY.value;
      document.frmSubmitReq.PX_C06_YY.value = document.frmSubmit.CH6YYYY.value;
      document.frmSubmitReq.PX_C07_YY.value = document.frmSubmit.CH7YYYY.value;
      document.frmSubmitReq.PX_C08_YY.value = document.frmSubmit.CH8YYYY.value;
      document.frmSubmitReq.PX_C09_YY.value = document.frmSubmit.CH9YYYY.value;

      document.frmSubmitReq.PX_I01_DD.value = document.frmSubmit.IN1DD.value;
      document.frmSubmitReq.PX_I02_DD.value = document.frmSubmit.IN2DD.value;
      document.frmSubmitReq.PX_I03_DD.value = document.frmSubmit.IN3DD.value;
      document.frmSubmitReq.PX_I04_DD.value = document.frmSubmit.IN4DD.value;
      document.frmSubmitReq.PX_I05_DD.value = document.frmSubmit.IN5DD.value;
      document.frmSubmitReq.PX_I06_DD.value = document.frmSubmit.IN6DD.value;
      document.frmSubmitReq.PX_I07_DD.value = document.frmSubmit.IN7DD.value;
      document.frmSubmitReq.PX_I08_DD.value = document.frmSubmit.IN8DD.value;
      document.frmSubmitReq.PX_I09_DD.value = document.frmSubmit.IN9DD.value;

      document.frmSubmitReq.PX_I01_MM.value = document.frmSubmit.IN1MM.value;
      document.frmSubmitReq.PX_I02_MM.value = document.frmSubmit.IN2MM.value;
      document.frmSubmitReq.PX_I03_MM.value = document.frmSubmit.IN3MM.value;
      document.frmSubmitReq.PX_I04_MM.value = document.frmSubmit.IN4MM.value;
      document.frmSubmitReq.PX_I05_MM.value = document.frmSubmit.IN5MM.value;
      document.frmSubmitReq.PX_I06_MM.value = document.frmSubmit.IN6MM.value;
      document.frmSubmitReq.PX_I07_MM.value = document.frmSubmit.IN7MM.value;
      document.frmSubmitReq.PX_I08_MM.value = document.frmSubmit.IN8MM.value;
      document.frmSubmitReq.PX_I09_MM.value = document.frmSubmit.IN9MM.value;

      document.frmSubmitReq.PX_I01_YY.value = document.frmSubmit.IN1YYYY.value;
      document.frmSubmitReq.PX_I02_YY.value = document.frmSubmit.IN2YYYY.value;
      document.frmSubmitReq.PX_I03_YY.value = document.frmSubmit.IN3YYYY.value;
      document.frmSubmitReq.PX_I04_YY.value = document.frmSubmit.IN4YYYY.value;
      document.frmSubmitReq.PX_I05_YY.value = document.frmSubmit.IN5YYYY.value;
      document.frmSubmitReq.PX_I06_YY.value = document.frmSubmit.IN6YYYY.value;
      document.frmSubmitReq.PX_I07_YY.value = document.frmSubmit.IN7YYYY.value;
      document.frmSubmitReq.PX_I08_YY.value = document.frmSubmit.IN8YYYY.value;
      document.frmSubmitReq.PX_I09_YY.value = document.frmSubmit.IN9YYYY.value;

      document.frmSubmitReq.CTY1.value = document.frmSubmit.CTY1_ID.value;
      document.frmSubmitReq.CTY2.value = document.frmSubmit.CTY2_ID.value;
      document.frmSubmitReq.CTY3.value = document.frmSubmit.CTY3_ID.value;
      document.frmSubmitReq.ACCOM.value = document.frmSubmit.ACC_ID.value;
      document.frmSubmitReq.DEP.value = document.frmSubmit.DEP_PT_ID.value;
      document.frmSubmitReq.submit();
   }
   else
      return false;
}
function submitSearchRequestCIT()
{
   if(ds_validate_CIT() && validate())
   {
      if(document.frmSubmit.ACC_ID.value!='' && !checkNights())
         return false;
      document.frmSubmitReq.START.value = document.frmSubmit.STDD.value+"-"+document.frmSubmit.STMM.value+"-"+document.frmSubmit.STYYYY.value;
      document.frmSubmitReq.STAY.value = document.frmSubmit.STAYN.value;
      document.frmSubmitReq.PX_A.value = document.frmSubmit.PXA.value;
      document.frmSubmitReq.PX_C.value = document.frmSubmit.PXC.value;
      document.frmSubmitReq.PX_I.value = document.frmSubmit.PXI.value;
      document.frmSubmitReq.PX_C01_DD.value = document.frmSubmit.CH1DD.value;
      document.frmSubmitReq.PX_C02_DD.value = document.frmSubmit.CH2DD.value;
      document.frmSubmitReq.PX_C03_DD.value = document.frmSubmit.CH3DD.value;
      document.frmSubmitReq.PX_C04_DD.value = document.frmSubmit.CH4DD.value;
      document.frmSubmitReq.PX_C05_DD.value = document.frmSubmit.CH5DD.value;
      document.frmSubmitReq.PX_C06_DD.value = document.frmSubmit.CH6DD.value;
      document.frmSubmitReq.PX_C07_DD.value = document.frmSubmit.CH7DD.value;
      document.frmSubmitReq.PX_C08_DD.value = document.frmSubmit.CH8DD.value;
      document.frmSubmitReq.PX_C09_DD.value = document.frmSubmit.CH9DD.value;

      document.frmSubmitReq.PX_C01_MM.value = document.frmSubmit.CH1MM.value;
      document.frmSubmitReq.PX_C02_MM.value = document.frmSubmit.CH2MM.value;
      document.frmSubmitReq.PX_C03_MM.value = document.frmSubmit.CH3MM.value;
      document.frmSubmitReq.PX_C04_MM.value = document.frmSubmit.CH4MM.value;
      document.frmSubmitReq.PX_C05_MM.value = document.frmSubmit.CH5MM.value;
      document.frmSubmitReq.PX_C06_MM.value = document.frmSubmit.CH6MM.value;
      document.frmSubmitReq.PX_C07_MM.value = document.frmSubmit.CH7MM.value;
      document.frmSubmitReq.PX_C08_MM.value = document.frmSubmit.CH8MM.value;
      document.frmSubmitReq.PX_C09_MM.value = document.frmSubmit.CH9MM.value;

      document.frmSubmitReq.PX_C01_YY.value = document.frmSubmit.CH1YYYY.value;
      document.frmSubmitReq.PX_C02_YY.value = document.frmSubmit.CH2YYYY.value;
      document.frmSubmitReq.PX_C03_YY.value = document.frmSubmit.CH3YYYY.value;
      document.frmSubmitReq.PX_C04_YY.value = document.frmSubmit.CH4YYYY.value;
      document.frmSubmitReq.PX_C05_YY.value = document.frmSubmit.CH5YYYY.value;
      document.frmSubmitReq.PX_C06_YY.value = document.frmSubmit.CH6YYYY.value;
      document.frmSubmitReq.PX_C07_YY.value = document.frmSubmit.CH7YYYY.value;
      document.frmSubmitReq.PX_C08_YY.value = document.frmSubmit.CH8YYYY.value;
      document.frmSubmitReq.PX_C09_YY.value = document.frmSubmit.CH9YYYY.value;

      document.frmSubmitReq.PX_I01_DD.value = document.frmSubmit.IN1DD.value;
      document.frmSubmitReq.PX_I02_DD.value = document.frmSubmit.IN2DD.value;
      document.frmSubmitReq.PX_I03_DD.value = document.frmSubmit.IN3DD.value;
      document.frmSubmitReq.PX_I04_DD.value = document.frmSubmit.IN4DD.value;
      document.frmSubmitReq.PX_I05_DD.value = document.frmSubmit.IN5DD.value;
      document.frmSubmitReq.PX_I06_DD.value = document.frmSubmit.IN6DD.value;
      document.frmSubmitReq.PX_I07_DD.value = document.frmSubmit.IN7DD.value;
      document.frmSubmitReq.PX_I08_DD.value = document.frmSubmit.IN8DD.value;
      document.frmSubmitReq.PX_I09_DD.value = document.frmSubmit.IN9DD.value;

      document.frmSubmitReq.PX_I01_MM.value = document.frmSubmit.IN1MM.value;
      document.frmSubmitReq.PX_I02_MM.value = document.frmSubmit.IN2MM.value;
      document.frmSubmitReq.PX_I03_MM.value = document.frmSubmit.IN3MM.value;
      document.frmSubmitReq.PX_I04_MM.value = document.frmSubmit.IN4MM.value;
      document.frmSubmitReq.PX_I05_MM.value = document.frmSubmit.IN5MM.value;
      document.frmSubmitReq.PX_I06_MM.value = document.frmSubmit.IN6MM.value;
      document.frmSubmitReq.PX_I07_MM.value = document.frmSubmit.IN7MM.value;
      document.frmSubmitReq.PX_I08_MM.value = document.frmSubmit.IN8MM.value;
      document.frmSubmitReq.PX_I09_MM.value = document.frmSubmit.IN9MM.value;

      document.frmSubmitReq.PX_I01_YY.value = document.frmSubmit.IN1YYYY.value;
      document.frmSubmitReq.PX_I02_YY.value = document.frmSubmit.IN2YYYY.value;
      document.frmSubmitReq.PX_I03_YY.value = document.frmSubmit.IN3YYYY.value;
      document.frmSubmitReq.PX_I04_YY.value = document.frmSubmit.IN4YYYY.value;
      document.frmSubmitReq.PX_I05_YY.value = document.frmSubmit.IN5YYYY.value;
      document.frmSubmitReq.PX_I06_YY.value = document.frmSubmit.IN6YYYY.value;
      document.frmSubmitReq.PX_I07_YY.value = document.frmSubmit.IN7YYYY.value;
      document.frmSubmitReq.PX_I08_YY.value = document.frmSubmit.IN8YYYY.value;
      document.frmSubmitReq.PX_I09_YY.value = document.frmSubmit.IN9YYYY.value;

      document.frmSubmitReq.CTY1.value = document.frmSubmit.CTY1_ID.value;
      document.frmSubmitReq.CTY2.value = document.frmSubmit.CTY2_ID.value;
      document.frmSubmitReq.CTY3.value = document.frmSubmit.CTY3_ID.value;
      document.frmSubmitReq.ACCOM.value = document.frmSubmit.ACC_ID.value;
      document.frmSubmitReq.DEP.value = document.frmSubmit.DEP_PT_ID.value;
      if("HE" == searchType)
      {
         var startDt = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
         var returnDt = new Date(document.frmSubmit.RSTYYYY.value,document.frmSubmit.RSTMM.value-1,document.frmSubmit.RSTDD.value);
         if(returnDt.getTime() < startDt.getTime())
         {
            alert("Return date should be after Departure date");
            return false;
         }
         /*var daysbetween = startDt.getDaysBetween(returnDt);
         if(daysbetween > 7) {
            alert('The Returning date can be 7 or less than 7 days from the Departure date');
            return false;
         }*/
         var diff = returnDt.getTime() - startDt.getTime();
         var noDays = parseInt(diff/(24*60*60*1000));
         document.frmSubmitReq.STAY.value = noDays;
         document.frmSubmitReq.TRS_TP.value = "ES";
         document.frmSubmitReq.CLASS.value = document.frmSubmit.CAB_CLASS.value;
         document.frmSubmitReq.DEP_TM.value = document.frmSubmit.DepTime.value;
         document.frmSubmitReq.ARR_TM.value = document.frmSubmit.ArrTime.value;
      }

      /*START: Code for retricting 4 days..uses 3 JS files >> dates.packed.js, dates.js, dates.min.js*/
      var startDtTemp = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
      var todayTemp = new Date();
      var startDtTemp1 = new Date(startDtTemp);
      var daysFromToday = todayTemp.getDaysBetween(startDtTemp1);
      if(daysFromToday < 4) {
         alert("Please select Departure date 4 days from today");
         return false;
      }
      /*END: Code for retricting 4 days*/

      if("" == searchType)
      {
         document.frmSubmitReq.TRS_TP.value = "FLT";
      }
      document.frmSubmitReq.action=bookingURL;
      document.frmSubmitReq.submit();
   }
   else
      return false;
}

function submitSearchRequestTAF() {
    if (TAF_validate()) {
      document.frmSubmitReq.START.value = document.frmSubmit.STDD.value+"-"+document.frmSubmit.STMM.value+"-"+document.frmSubmit.STYYYY.value;
      /*document.frmSubmitReq.START.value = document.frmSubmit.ST_DT.value*/
      document.frmSubmitReq.STAY.value = document.frmSubmit.STAYN.value;
      document.frmSubmitReq.PX_A.value = document.frmSubmit.PPXA.value;
      document.frmSubmitReq.PX_C.value = document.frmSubmit.PPXC.value;
      document.frmSubmitReq.PX_I.value = document.frmSubmit.PPXI.value;
      document.frmSubmitReq.CTY1.value = document.frmSubmit.CTY1_ID.value;
      /*document.frmSubmitReq.CTY2.value = document.frmSubmit.CTY2_ID.value;*/
      document.frmSubmitReq.CTY3.value = document.frmSubmit.CTY3_ID.value;
      document.frmSubmitReq.ACCOM.value = document.frmSubmit.ACC_ID.value;

      if (GetAffiliate("ThomsonAlfrescoSource") == 'aw') {document.frmSubmitReq.AFF_CD.value = "aw";}
      checkAgentUser();
      document.frmSubmitReq.submit();
  }
}

function searchPanelValidation() {
  var lsStartDate = $f('PSTDD').value+"-"+$f('PSTMM').value+"-"+$f('PSTYYYY').value;
  if (!gbValidateDate("PST", "Arrival Date")) return false;
  var ldStartDate = getDateFromFormat(lsStartDate,gsDateFormat,true);
  if (ldStartDate < startDate) {
    return setFocus("If you wish to travel before " + formatDate(startDate, gsDateCalcFormat) + " please call Thomson Al Fresco Reservations 0871 231 3293*. *BT calls cost 10p/min. Other networks may vary.", $f('STDD'));
  }

  return true;
}

function PsubmitSearchRequestTAF() {
  if (searchPanelValidation()) {
    document.frmSubmitReq.START.value = $f('PSTDD').value+"-"+$f('PSTMM').value+"-"+$f('PSTYYYY').value;
    document.frmSubmitReq.STAY.value = $f('PSTAYN').value;
    document.frmSubmitReq.PX_A.value = $f('PPPXA').value;
    document.frmSubmitReq.PX_C.value = $f('PPPXC').value;
    document.frmSubmitReq.PX_I.value = $f('PPPXI').value;
    document.frmSubmitReq.CTY1.value = "";
    document.frmSubmitReq.CTY3.value = ""; 
    document.frmSubmitReq.ACCOM.value = $f('selctedaccom').value ;
    if (GetAffiliate("ThomsonAlfrescoSource") == 'aw') document.frmSubmitReq.AFF_CD.value = "aw";

    document.frmSubmitReq.submit();
  }
}



//{"ResortId,AirportId,AirportName,Valid Day,Starting Date, End Date"}
//var airportList = new Array("2148802,1358025,London Gatwick,1,05-05-2008,27-10-2008","2148802,1358025,London Gatwick,1,26-05-2008,27-10-2008","2148802,1358032,Manchester,1,05-05-2008,27-10-2008","2148802,1358015,Glasgow,1,09-06-2008,27-10-2008","1368611,1358025,London Gatwick,6,03-05-2008,01-11-2008","1368611,1358025,London Gatwick,3,07-05-2008,29-10-2008","1368611,1358003,Birmingham,6,03-05-2008,01-11-2008","1368611,1358003,Birmingham,3,07-05-2008,29-10-2008","1368611,1358032,Manchester,3,07-05-2008,29-10-2008","1398645,1358025,London Gatwick,5,02-05-2008,31-10-2008","1398645,1358032,Manchester,5,02-05-2008,31-10-2008","1398648,1358025,London Gatwick,0,04-05-2008,02-11-2008","1398648,1358025,London Gatwick,4,01-05-2008,30-10-2008","1398648,1358007,Bristol,4,01-05-2008,30-10-2008","1398648,1358010,Cardiff,4,01-05-2008,30-10-2008","1398648,1358003,Birmingham,4,01-05-2008,30-10-2008","1398648,1358013,East Midlands,4,01-05-2008,12-06-2008","1398648,1358032,Manchester,0,04-05-2008,02-11-2008","1398648,1358032,Manchester,4,01-05-2008,30-10-2008");
//Moved to site specific JS file.
//Days Array
var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var monthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function drawCombos(resortObj)
{
   var resortId = resortObj.value;
   var inArray=new Array();
   var clear=false;
   for (j=0;j<airportList.length;j++)
   {
      inArray = airportList[j].split(',');
      if(inArray[0]==resortId)
      {
         if((typeof(inArray[6])!='undefined' && searchType!=inArray[6]+""))
         {//this IF condition added to avoid Eurostar Validation
            break;
         }
         if(inArray[1]==0 || inArray[1]=="0")
         {
            break;
         }
         if(!clear)
         {
            clearDeptList(document.frmSubmit.DEP_PT_ID);
            clear = true;
         }
         var exists = false;
         for(cntr=0; cntr<document.frmSubmit.DEP_PT_ID.options.length; cntr++)
         {
            if(inArray[1]==document.frmSubmit.DEP_PT_ID.options[cntr].value)
            {
               exists = true;
            }
         }
         if(!exists)
         {
            g = new Option(inArray[2],inArray[1]);
            g.setAttribute('level',inArray[0]);
            document.frmSubmit.DEP_PT_ID.options[document.frmSubmit.DEP_PT_ID.options.length] = g;
         }
      }
   }
   if(!clear)
   {
      populateDefaultDeptList(document.frmSubmit.DEP_PT_ID);
   }
}
function clearDeptList(objList)
{
   objList.options.length = 0;
   g = new Option("Select...","");
   g.setAttribute('level',"");
   document.frmSubmit.DEP_PT_ID.options[document.frmSubmit.DEP_PT_ID.options.length] = g;
}
function populateDefaultDeptList()
{
   document.frmSubmit.DEP_PT_ID.options.length = 0;
   g = new Option("Select...","");
   g.setAttribute('level',"");
   document.frmSubmit.DEP_PT_ID.options[document.frmSubmit.DEP_PT_ID.options.length] = g;
   try{
      for(i=0;i<DATList.length;i++)
      {
         inArray = DATList[i];
         g = new Option(inArray[1],inArray[0]);
         g.setAttribute('level',"");
         document.frmSubmit.DEP_PT_ID.options[document.frmSubmit.DEP_PT_ID.options.length] = g;
      }
   }
   catch(e) {}
}


function validate()
{
   if(!checkDateRange())
      return false;
   if(!checkEndDate())
      return false;
   if(chkIsBusyHour())
   {
      //alert("Due to routine maintenance, bookings cannot be made on our site between 05:00 and 08:00am on Wednesday the 27th of February.");
      window.open("/javascript/bulletin.html","Alert","menubar=no,width=420,height=200,screenX=350,ScreenY=300,toolbar=no");
      return false;
   }
   return true;
}
function chkIsBusyHour()
{

   /*
   //Implement the Logic to define the busy period.
   var dt_today = new Date();
   var hour = dt_today.getHours();
   var day = dt_today.getDay(); //0 = Sunday, ... , 6 = Saturday
   //alert(hour + " " + day);
   if(hour > 4 && hour < 8)
   {
      return true;
   }
   else
   {
      return false;
   }
   */
   return false;
}
function checkDateRange()
{
   var resortId = document.frmSubmit.CTY3_ID.value;
   var depAirportId = document.frmSubmit.DEP_PT_ID.value;
   var inArray=new Array();
   var dateRangeArray=new Array();
   var i=0;
   for (j=0;j<airportList.length;j++)
   {
      inArray = airportList[j].split(',');
      if(inArray[0]==resortId && (inArray[1]==depAirportId || inArray[1] == 0))
      {
         dateRangeArray[i]=inArray;
         i++;
      }
   }

   var dateErr = false;

   if(dateRangeArray.length>0)
   {
      var selDate = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
      for(var i=0;i<dateRangeArray.length;i++)
      {
         var dates = ""+dateRangeArray[i];
         var inArray = dates.split(',');
         var tmpBeginDate = inArray[4].split('-');
         var tmpEndDate = inArray[5].split('-');
         if(!(tmpBeginDate[1] == "00" && tmpEndDate[1] == "00"))
         {
            var beginDate = new Date(tmpBeginDate[2],tmpBeginDate[1]-1,tmpBeginDate[0]);
            var endDate = new Date(tmpEndDate[2],tmpEndDate[1]-1,tmpEndDate[0]);
            /*if(beginDate.getTime() > selDate.getTime())
            {
               dateErr = true;
               msg = "Please select a date after :" + inArray[4];
            }
            if(endDate.getTime() < selDate.getTime())
            {
               dateErr = true;
               msg = "Please select a date before :" + inArray[5];
            }*/
            if(tmpBeginDate[1] != "00" && selDate.getTime() < beginDate.getTime())
            {
               dateErr = true;
            }
            else if(tmpEndDate[1] != "00" && selDate.getTime() > endDate.getTime())
            {
               dateErr = true;
            }
            else
            {
               if(inArray[3] == selDate.getDay() || inArray[3] > 6)
               {
                  return true;
               }
               else
               {
                  dateErr = true;
               }
            }
         }
         else
         {
            if(!(inArray[3] == selDate.getDay()) && inArray[3] < 7)
            {
               dateErr = true;
            }
            else
               return true;
         }
      }
      if(dateErr)
      {
         var msg="For " + getSelectedText("CTY3_ID") + " Resort the available Travel days are ...\n\n";
         var currDate = new Date();
         for(var i=0;i<dateRangeArray.length;i++)
         {
            var dates = ""+dateRangeArray[i];
            var inArray = dates.split(',');
            var tmpBeginDate = inArray[4].split('-');
            var tmpEndDate = inArray[5].split('-');
            var beginDate = new Date(tmpBeginDate[2],tmpBeginDate[1]-1,tmpBeginDate[0]);
            var endDate = new Date(tmpEndDate[2],tmpEndDate[1]-1,tmpEndDate[0]);
            //if((tmpEndDate[1] != "00" && endDate.getTime() >= currDate.getTime()) || tmpEndDate[1] == "00")
            //{
               if(tmpBeginDate[1] != "00")
                  msg += beginDate.getDate() +"-" + monthArray[beginDate.getMonth()] + "-" + beginDate.getFullYear();
               if(tmpBeginDate[1] != "00" && tmpEndDate[1] != "00")
                  msg += " To ";
               if(tmpBeginDate[1] != "00" && tmpEndDate[1] == "00")
                  msg += " onwards ";
               if(tmpBeginDate[1] == "00" && tmpEndDate[1] != "00")
                  msg += " Until ";
               if(tmpEndDate[1] != "00")
                  msg += endDate.getDate() +"-" + monthArray[endDate.getMonth()] + "-" + endDate.getFullYear();
               if(tmpBeginDate[1] == "00" && tmpEndDate[1] == "00")
                  msg += "All year "
               if(inArray[2]!="" && inArray[2]!="0" && inArray[2]!=0)
                  msg += " from " + inArray[2];
               if(inArray[3] < 7)
                  msg += " on every " + dayArray[inArray[3]] + "\n";
               else
                  msg += " everyday\n";
            //}
         }
         alert(msg);
         document.frmSubmit.STDD.focus();
         return false;
      }
   }
   return true;
}
function defaultToPos(lstObjId,minEntries,defPos)
{
   var lstObj = document.getElementById(lstObjId);
   if(lstObj.options.length == (parseInt(minEntries) + 1))
   {
      lstObj.options[defPos].selected = true;
   }
   if(lstObj.onchange)
      lstObj.onchange();
}
function checkEndDate()
{
   var selDate = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
   if(typeof(endDate)!='undefined' && endDate!=null && endDate!='' && endDate.getTime() < selDate.getTime())
   {
      alert('Please select Departure date prior to ' + endDate.getDate()+"-"+(endDate.getMonth()+1)+"-"+endDate.getFullYear());
      document.frmSubmit.STDD.focus();
      return false;
   }
   return true;
}
function getSelectedText(lstName)
{
   var lstObj = document.getElementById(lstName);
   var selIndex = lstObj.selectedIndex;
   return lstObj.options[selIndex].text;
}

function restrictDates(arg)
{
   var resortId = document.frmSubmit.CTY3_ID.value;
   var selDate = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
   var tmpDate = startDate.split('-');
   var allowDate = new Date(tmpDate[2],tmpDate[1]-1,tmpDate[0]);
   if(resortId!='' && resortId!='5603173' && resortId!='5603168' && resortId!='5603163' && selDate.getTime() < allowDate.getTime())
   {
      alert('Thank you for your interest in Thomson Worldwide holidays to Asia. Online booking is available for travel after May 1st 2008. For dates prior please contact our specialist Asia and Arabian Gulf team on 0871 230 2802 who will be happy to help with your enquiry');
      document.frmSubmit.STDD.focus();
      return false;
   }
   if(arg=='book')
      submitSearchRequest();
   else
      return true;
}
function restrictDatesCIO(arg)
{
   var countryId = document.frmSubmit.CTY1_ID.value;
   if(countryId!='' && countryId == '1347065' )
   {
      alert('Thank you for your interest in Thomson Worldwide holidays to Cuba.  Online booking is available for travel after March 1st 2008.  For dates prior please contact our specialist Caribbean and Indian Ocean team on 0871 230 2801 who will be happy to help with your enquiry.');
      document.frmSubmit.CTY1_ID.focus();
      return false;
   }
   if(arg=='book')
      submitSearchRequest();
   else
      return true;
}
function restrictDatesCIOResort(arg)
{
   var resortId = document.frmSubmit.CTY3_ID.value;
   if(resortId!='' && resortId=='1368608')
   {
      alert('Please note your journey to Varadero is via Havana airport with road transfer to your chosen hotel.');
   }
   if(arg=='book')
      submitSearchRequest();
   else
      return true;
}
function showAlert()
{
   //window.open("/javascript/bulletin.html","Alert","menubar=no,width=420,height=200,screenX=350,ScreenY=300,toolbar=no");
}
function fnBook(ob,ob1,ob2,ob3)
{
   //alert(ob);

    //document.getElementById('hidacom').value=ob;
    document.getElementById('divBook').style.display="block";
   document.getElementById('divA').innerHTML = ob3;
   setDestValues(ob);
   SplDates(ob1,ob2);
}

function setDestValues(ob) {
   accomDtlsArr = getAccomDtls(ob);
   if(accomDtlsArr!='' && accomDtlsArr!=null)
   {
      $('CTY1_ID').value = accomDtlsArr.Cty1Id;
      $('CTY3_ID').value = accomDtlsArr.Cty3Id;
      $('ACC_ID').value = accomDtlsArr.Id;
      setLstValue('CTY1_ID',accomDtlsArr.Cty1Id);
      setLstValue('CTY3_ID',accomDtlsArr.Cty3Id);
      setLstValue('ACC_ID',accomDtlsArr.Id);
   }
}

function setRetDate() {
   var startDt = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
   var retDate = new Date(startDt.getTime() + (3 * (24 * 60 * 60 * 1000)));
   var retDays = ""+retDate.getDate();
   var retMonths = (retDate.getMonth()+1)+"";
   if(retDays.length==1)
      retDays = "0"+retDays;
   if(retMonths.length==1)
      retMonths = "0"+retMonths;
   document.getElementById("RSTDD").value= retDays;
   document.getElementById("RSTMM").value= retMonths;
   document.getElementById("RSTYYYY").value= retDate.getFullYear();
}

function setLstValue(lstId,lstVal) {
   var lstObj = document.getElementById(lstId);
   for(var cntr=0;cntr < lstObj.length;cntr++)
   {
      lstObj.options[cntr].value;
      break;
      if(lstObj.options[cntr].value == lstVal)
      {
         lstObj.options[cntr].selected= true;
         if(lstObj.onChange)
            lstObj.onChange();
      }
   }
}

function getAccomDtls(accomCode)
{
   for(var cntr=0;cntr<gaAccomList.length;cntr++)
   {
      if(accomCode==gaAccomList[cntr].Id)
      {
         return gaAccomList[cntr];
      }
   }
}

function SplDates(ob1,ob2)
{
   var day = document.getElementById("STDD");
   var month = document.getElementById("STMM");
   day.value=ob1;
   month.value=ob2;
}

function checkNights()
{
   var accomId = document.frmSubmit.ACC_ID.value;
   var nightsSel = document.frmSubmit.STAYN.value;
   var inArray=new Array();
   var dateRangeArray=new Array();
   var i=0;
   for (j=0;j<nights.length;j++)
   {
      inArray = nights[j].split(',');
      if(inArray[0]==accomId)
      {
         dateRangeArray[i]=inArray;
         i++;
      }
   }
   var dateErr = false;
   if(dateRangeArray.length>0)
   {
      var selDate = new Date(document.frmSubmit.STYYYY.value,document.frmSubmit.STMM.value-1,document.frmSubmit.STDD.value);
      for(var i=0;i<dateRangeArray.length;i++)
      {
         var dates = ""+dateRangeArray[i];
         var inArray = dates.split(',');
         var tmpBeginDate = inArray[2].split('-');
         var tmpEndDate = inArray[3].split('-');
         if(!(tmpBeginDate[1] == "00" && tmpEndDate[1] == "00"))
         {
            var beginDate = new Date(tmpBeginDate[2],tmpBeginDate[1]-1,tmpBeginDate[0]);
            var endDate = new Date(tmpEndDate[2],tmpEndDate[1]-1,tmpEndDate[0]);
            if(tmpBeginDate[1] != "00" && selDate.getTime() < beginDate.getTime())
            {
               dateErr = true;
            }
            else if(tmpEndDate[1] != "00" && selDate.getTime() > endDate.getTime())
            {
               dateErr = true;
            }
            else
            {
               if(inArray[1] <= nightsSel)
               {
                  return true;
               }
               else
               {
                  dateErr = true;
               }
            }
         }
         else
         {
            if(!(inArray[1] == nightsSel))
            {
               dateErr = true;
            }
            else
               return true;
         }
      }
      if(dateErr)
      {
         var msg = "Between ";
         var currDate = new Date();
         for(var i=0;i<dateRangeArray.length;i++)
         {
            var dates = ""+dateRangeArray[i];
            var inArray = dates.split(',');
            var tmpBeginDate = inArray[2].split('-');
            var tmpEndDate = inArray[3].split('-');
            var beginDate = new Date(tmpBeginDate[2],tmpBeginDate[1]-1,tmpBeginDate[0]);
            var endDate = new Date(tmpEndDate[2],tmpEndDate[1]-1,tmpEndDate[0]);
               if(tmpBeginDate[1] != "00")
                  msg += beginDate.getDate() +"-" + monthArray[beginDate.getMonth()] + "-" + beginDate.getFullYear();
               if(tmpBeginDate[1] != "00" && tmpEndDate[1] != "00")
                  msg += " and ";
               if(tmpBeginDate[1] != "00" && tmpEndDate[1] == "00")
                  msg += " onwards ";
               if(tmpBeginDate[1] == "00" && tmpEndDate[1] != "00")
                  msg += " until ";
               if(tmpEndDate[1] != "00")
                  msg += endDate.getDate() +"-" + monthArray[endDate.getMonth()] + "-" + endDate.getFullYear();
               if(tmpBeginDate[1] == "00" && tmpEndDate[1] == "00")
                  msg += " all year "
               if(inArray[1]!="" && inArray[1]!="0" && inArray[1]!=0)
                  msg += " the minimum stay at " + getSelectedText('ACC_ID') + " is " + inArray[1] + " nights. Please update the Duration to a minimum of " + inArray[1] + ", or select an alternative accommodation.";
            }
         alert(msg);
         document.frmSubmit.STAYN.focus();
         return false;
      }
   }
   return true;
}


// Enquiry form validation added by tharun On 22 July 2008 starts here
function validateEForm()
{
  //alert("Filling Form...");
   //Check for empty strings
      if(trim(document.getElementById("forename").value) =='' || trim(document.getElementById("surname").value) =='' || trim(document.getElementById("parc1").value) =='' || trim(document.getElementById("date").value) =='' || trim(document.getElementById("nights").value) =='' || trim(document.getElementById("persons").value) =='' || trim(document.getElementById("telephone").value) =='' || trim(document.getElementById("email").value) =='') 
    {
         alert('Please complete all the fields marked with *');
         return false;
      }
    
  var dt1 = trim(document.getElementById("date").value);
  if(isDate1(dt1) == false)
    {
    document.getElementById("date").focus();
    return false;
  }	
        
  if(IsNumeric(trim(document.getElementById("nights").value)) == false)
  {
    alert("Please enter no. of nights as a numeric value");
    document.getElementById("nights").focus();
    return false;
  }

  if(IsNumeric(trim(document.getElementById("persons").value)) == false)
  {
    alert("Please enter no. of persons as a numeric value");
    document.getElementById("persons").focus();
    return false;
  }

  if(document.getElementById("telephone").value!='')
  {
    var telString = document.getElementById("telephone").value;
    var stripped = telString.replace(/[\(\)\.\-\ ]/g, '');
    if(isNaN(stripped) == true)
    {
     alert("Please enter a valid Telephone number");
     document.getElementById("telephone").focus();
     return false;
    }
  }

  if (trim(document.getElementById("email").value) != trim(document.getElementById("cemail").value))
  {
      alert("Your Confirm Email Address doesn't match Email Address.");
    document.getElementById("email").focus();
    return false;
  } 

    //Validate email strings
    var emailString = document.getElementById("email").value;
    var emailFilter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    if(!(emailString.match(emailFilter))) 
    {
     alert("Please enter a valid Email address");
     document.getElementById("email").focus();
     return false;
    }
   var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
   if(emailString.match(illegalChars))
   {
     alert("The Email address contains illegal characters");
     document.getElementById("email").focus();
     return false;
   }
    //return false;
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function isInteger(s){
  var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
  var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
  // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
  for (var i = 1; i <= n; i++) {
    this[i] = 31
    if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
    if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate1(dtStr)
{
  //alert("test");
  var dtCh= "/";
  var minYear=1900;
  var maxYear=2100;

  var daysInMonth = DaysArray(12)
  var pos1=dtStr.indexOf(dtCh)
  var pos2=dtStr.indexOf(dtCh,pos1+1)
  //var strMonth=dtStr.substring(0,pos1)
  //var strDay=dtStr.substring(pos1+1,pos2)
  var strDay=dtStr.substring(0,pos1)
  var strMonth=dtStr.substring(pos1+1,pos2)
  var strYear=dtStr.substring(pos2+1)
  strYr=strYear
  if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
  if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
  for (var i = 1; i <= 3; i++) {
    if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
  }
  month=parseInt(strMonth)
  day=parseInt(strDay)
  year=parseInt(strYr)
  if (pos1==-1 || pos2==-1){
    alert("The date format should be dd/mm/yyyy")
    return false
  }
  if (strMonth.length<1 || month<1 || month>12){
    alert("The date format should be dd/mm/yyyy")
    return false
  }
  if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
    alert("The date format should be dd/mm/yyyy")
    return false
  }
  if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
    //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
    alert("The date format should be dd/mm/yyyy");
    return false
  }
  if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
    //alert("Please enter a valid date")
    alert("The date format should be dd/mm/yyyy");
    return false
  }
return true
}

// <-- Enquiry form validation added by tharun On 22 July 2008 Ends here
function TAF_validate() {
 
  if (defaultDate == 0) defaultDate = gdTodaysDate;
 if (!gbValidateDate("ST", "Arrival date")) return false;

 var ldCheckDate = getDateFromFormat(getDateStr("ST"), gsDateFormat, true);
 if (ldCheckDate < defaultDate) {
 return setFocus("If you wish to travel before " + formatDate(defaultDate, "dd-NNN-yyyy")+ " please call Thomson Al Fresco Reservations 0871 231 3293*. *BT calls cost 10p/min. Other networks may vary.", $f('STDD'));
 }

 var lsCty1 = (gsGeogCty1 == 'Y') ? $f('CTY1_ID').value : '';
 var lsCty2 = (gsGeogCty2 == 'Y') ? $f('CTY2_ID').value : '';
 var loCty1 = (gsGeogCty1 == 'Y') ? $f('CTY1_ID') : (gsGeogCty2 == 'Y') ? $f('CTY2_ID') : $f('CTY3_ID');
 if (($f('CTY3_ID').value == "") && (lsCty2 == "") && (lsCty1 == "") && ($f('ACC_ID').value == ""))
 return setFocus("Please select your preferred country, region or parc.", loCty1);


  var loAdults = $f('PPXA');
  var loChildren = $f('PPXC');
  var loInfants = $f('PPXI');
  var llAduVal = Number(loAdults.value);
  var llChdVal = Number(loChildren.value);
  var llInfVal = Number(loInfants.value);
  
  if((llAduVal + llChdVal + llInfVal) > 6)
  {
    return setFocus("For bookings of more than six people, please call 0871-231-3293 Calls cost 10p per minute plus network charges.", $f('PPXA'));
  }


 return true;
}


function $f(element) {
  if (arguments.length > 1) {
   for (var i = 0, elements = [], length = arguments.length; i < length; i++)
   elements.push($f(arguments[i]));
   return elements;
   }
  if (typeof element == 'string')
  element = document.getElementById(element);
  return element;
}

// ------------------------------------------------------------------
// Check if we've come from the Agent Portal
// ------------------------------------------------------------------
function checkAgentUser() {
  $("#AGTID").val(getCookie("_AgentId"));
  $("#EMPNO").val(getCookie("_AgentEmpNo"));
  $("#RETURL").val(getCookie("_AgentRetUrl"));
  $("#TOKEN").val(getCookie("_AgentToken"));
}

$(function() {
  // Hide brochure request for agents
  if (getCookie("_AgentId") != "") $(".brochure").hide();
  
  // Lower case breadcrumb friendly URLs
  if ($("a.lowerCase").length) {
    $("a.lowerCase").each(function() {
      $(this).attr("href", $(this).attr("href").toLowerCase());
    });
  }
});
/***************************************************************************************************
  end common.js
/**************************************************************************************************/  


/***************************************************************************************************
  start date.js
/**************************************************************************************************/  
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

function isDate(val,format) {
 var date=getDateFromFormat(val,format,false);
 if (date==0) { return false; }
 return true;
}

function compareDates(date1,dateformat1,date2,dateformat2) {
 var d1=getDateFromFormat(date1,dateformat1,false);
 var d2=getDateFromFormat(date2,dateformat2,false);
 if (d1==0 || d2==0) {
 return -1;
 } else if (d1 > d2) {
 return 1;
 }
 return 0;
}

function formatDate(date,format) {
 format=format+"";
 var result="";
 var i_format=0;
 var c="";
 var token="";
 var y=date.getYear()+"";
 var M=date.getMonth()+1;
 var d=date.getDate();
 var E=date.getDay();
 var H=date.getHours();
 var m=date.getMinutes();
 var s=date.getSeconds();
 var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
 // Convert real date parts into formatted versions
 var value=new Object();
 if (y.length < 4) {y=""+(y-0+1900);}
 value["y"]=""+y;
 value["yyyy"]=y;
 value["yy"]=y.substring(2,4);
 value["M"]=M;
 value["MM"]=LZ(M);
 value["MMM"]=MONTH_NAMES[M-1];
 value["NNN"]=MONTH_NAMES[M+11];
 value["d"]=d;
 value["dd"]=LZ(d);
 value["E"]=DAY_NAMES[E+7];
 value["EE"]=DAY_NAMES[E];
 value["H"]=H;
 value["HH"]=LZ(H);
 if (H==0){value["h"]=12;}
 else if (H>12){value["h"]=H-12;}
 else {value["h"]=H;}
 value["hh"]=LZ(value["h"]);
 if (H>11){value["K"]=H-12;} else {value["K"]=H;}
 value["k"]=H+1;
 value["KK"]=LZ(value["K"]);
 value["kk"]=LZ(value["k"]);
 if (H > 11) { value["a"]="PM"; }
 else { value["a"]="AM"; }
 value["m"]=m;
 value["mm"]=LZ(m);
 value["s"]=s;
 value["ss"]=LZ(s);
 while (i_format < format.length) {
 c=format.charAt(i_format);
 token="";
 while ((format.charAt(i_format)==c) && (i_format < format.length)) {
 token += format.charAt(i_format++);
 }
 if (value[token] != null) { result=result + value[token]; }
 else { result=result + token; }
 }
 return result;
}

function _isInteger(val) {
 var digits="1234567890";
 for (var i=0; i < val.length; i++) {
 if (digits.indexOf(val.charAt(i))==-1) { return false; }
 }
 return true;
}

function _getInt(str,i,minlength,maxlength) {
 for (var x=maxlength; x>=minlength; x--) {
 var token=str.substring(i,i+x);
 if (token.length < minlength) { return null; }
 if (_isInteger(token)) { return token; }
 }
 return null;
}

function getDateFromFormat(val,format,abDate) {
 val=val+"";
 format=format+"";
 var i_val=0;
 var i_format=0;
 var c="";
 var token="";
 var token2="";
 var x,y;
 var now=new Date();
 var year=now.getYear();
 var month=now.getMonth()+1;
 var date=1;
 var hh=now.getHours();
 var mm=now.getMinutes();
 var ss=now.getSeconds();
 var ampm="";

 while (i_format < format.length) {
 // Get next token from format string
 c=format.charAt(i_format);
 token="";
 while ((format.charAt(i_format)==c) && (i_format < format.length)) {
 token += format.charAt(i_format++);
 }
 // Extract contents of value based on format token
 if (token=="yyyy" || token=="yy" || token=="y") {
 if (token=="yyyy") { x=4;y=4; }
 if (token=="yy") { x=2;y=2; }
 if (token=="y") { x=2;y=4; }
 year=_getInt(val,i_val,x,y);
 if (year==null) { return 0; }
 i_val += year.length;
 if (year.length==2) {
 if (year > 70) { year=1900+(year-0); }
 else { year=2000+(year-0); }
 }
 } else if (token=="MMM"||token=="NNN") {
 month=0;
 for (var i=0; i<MONTH_NAMES.length; i++) {
 var month_name=MONTH_NAMES[i];
 if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
 if (token=="MMM"||(token=="NNN"&&i>11)) {
 month=i+1;
 if (month>12) { month -= 12; }
 i_val += month_name.length;
 break;
 }
 }
 }
 if ((month < 1)||(month>12)){return 0;}
 } else if (token=="EE"||token=="E"){
 for (var i=0; i<DAY_NAMES.length; i++) {
 var day_name=DAY_NAMES[i];
 if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
 i_val += day_name.length;
 break;
 }
 }
 } else if (token=="MM"||token=="M") {
 month=_getInt(val,i_val,token.length,2);
 if(month==null||(month<1)||(month>12)){return 0;}
 i_val+=month.length;
 } else if (token=="dd"||token=="d") {
 date=_getInt(val,i_val,token.length,2);
 if(date==null||(date<1)||(date>31)){return 0;}
 i_val+=date.length;
 } else if (token=="hh"||token=="h") {
 hh=_getInt(val,i_val,token.length,2);
 if(hh==null||(hh<1)||(hh>12)){return 0;}
 i_val+=hh.length;
 } else if (token=="HH"||token=="H") {
 hh=_getInt(val,i_val,token.length,2);
 if(hh==null||(hh<0)||(hh>23)){return 0;}
 i_val+=hh.length;
 } else if (token=="KK"||token=="K") {
 hh=_getInt(val,i_val,token.length,2);
 if(hh==null||(hh<0)||(hh>11)){return 0;}
 i_val+=hh.length;
 } else if (token=="kk"||token=="k") {
 hh=_getInt(val,i_val,token.length,2);
 if(hh==null||(hh<1)||(hh>24)){return 0;}
 i_val+=hh.length;hh--;
 } else if (token=="mm"||token=="m") {
 mm=_getInt(val,i_val,token.length,2);
 if(mm==null||(mm<0)||(mm>59)){return 0;}
 i_val+=mm.length;
 } else if (token=="ss"||token=="s") {
 ss=_getInt(val,i_val,token.length,2);
 if(ss==null||(ss<0)||(ss>59)){return 0;}
 i_val+=ss.length;
 } else if (token=="a") {
 if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
 else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
 else {return 0;}
 i_val+=2;
 } else {
 if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
 else {i_val+=token.length;}
 }
 }
 // If there are any trailing characters left in the value, it doesn't match
 if (i_val != val.length) { return 0; }
 // Is date valid for month?
 if (month==2) {
 // Check for leap year
 if (((year%4==0) && (year%100 != 0)) || (year%400==0)) {
 // leap year
 if (date > 29) {
 return 0;
 }
 } else {
 if (date > 28) {return 0;}
 }
 }
 if ((month==4)||(month==6)||(month==9)||(month==11)) {
 if (date > 30) { return 0; }
 }
 // Correct hours value
 if (hh<12 && ampm=="PM") {
 hh=hh-0+12;
 } else if (hh>11 && ampm=="AM") {
 hh-=12;
 }
 var newdate=new Date(year,month-1,date,hh,mm,ss);
 if (abDate) {
 return newdate;
 } else {
 return newdate.getTime();
 }
}

function parseDate(val) {
 var preferEuro=(arguments.length==2)?arguments[1]:false;
 generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
 monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
 dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
 var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
 var d=null;
 for (var i=0; i<checkList.length; i++) {
 var l=window[checkList[i]];
 for (var j=0; j<l.length; j++) {
 d=getDateFromFormat(val,l[j],false);
 if (d!=0) { return new Date(d); }
 }
 }
 return null;
}

var gdTodaysDate = new Date();
gdTodaysDate.setHours(0,0,0);

// ------------------------------------------------------------------
// Page load functions
// ------------------------------------------------------------------
function bodyOnLoad() {
 handleBackButton();
 if (typeof(Init) == "function") Init();
 ErrorCheck();
}
// ------------------------------------------------------------------
// String functions
// ------------------------------------------------------------------
function strltrim() {return this.replace(/^\s+/,'');}
function strrtrim() {return this.replace(/\s+$/,'');}
function strtrim() {return this.replace(/^\s+/,'').replace(/\s+$/,'');}
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

function isInteger(asIntStr) {
 var lsdigits="1234567890";
 for (var llLoop=0; llLoop < asIntStr.length; llLoop++) {
 if (lsdigits.indexOf(asIntStr.charAt(llLoop))==-1) {return false;}
 }
 return true;
}

function isChecked(asField) {
 return ($(asField).checked) ? "Y" : "N";
}

// ------------------------------------------------------------------
// Class functions
// ------------------------------------------------------------------
function removeClassName (elem, className) {
 elem.className = elem.className.replace(className, "").trim();
}

function addClassName (elem, className) {
 removeClassName (elem, className);
 elem.className = (elem.className + " " + className).trim();
}

function setClassName (elem, className) {
 elem.className = className;
}

// ------------------------------------------------------------------
// Date build functions
// ------------------------------------------------------------------
function setDateField(asField, asDate) {
 var lsSetDD, lsSetMM, lsSetYY;
 if (arguments.length > 2) {
 lsSetDD = asDate;
 lsSetMM = arguments[2];
 lsSetYY = arguments[3];
 } else {
 lsSetDD = asDate.substr(0, 2);
 lsSetMM = asDate.substr(3, 2);
 lsSetYY = asDate.substr(6, 4);
 }
 $(asField + "DD").value = lsSetDD;
 $(asField + "MM").value = lsSetMM;
 $(asField + "YYYY").value = lsSetYY;
}

function getDateStr(asField) {
 return $f(asField + "DD").value + "-" + $f(asField + "MM").value + "-" + $f(asField + "YYYY").value;
}

function gbValidateDate(asField, asFieldLabel) {
 if (!isDate(getDateStr(asField), gsDateFormat)) {
 return setFocus(asFieldLabel + " is an invalid date", $(asField + "DD"));
 }
 return true;
}

function gsAddDaysStr(asDateStr, alDays) {
 if ((asDateStr != '') && (isDate(asDateStr, gsDateCalcFormat))) {
 var ldNewAddDate = getDateFromFormat(asDateStr, gsDateCalcFormat, true);
 if (ldNewAddDate != 0) {
 var alNewDays = ldNewAddDate.getDate();
 alNewDays += alDays;
 ldNewAddDate.setDate(alNewDays);
 return formatDate(ldNewAddDate, gsDateCalcFormat);
 }
 }
 return '';
}

// ------------------------------------------------------------------
// Common message functions
// ------------------------------------------------------------------
function addFlowCtl(asAct) {
 var lsXml = "<FLOCTL>";
 lsXml += '<CTLSITE>' + gsCtlSite + '</CTLSITE>';
 lsXml += "<CTLACT>" + asAct + "</CTLACT>";
 lsXml += "<CTLSCR>" + gsCtlScr + "</CTLSCR>";
 lsXml += "</FLOCTL>";
 return lsXml;
}

function xmlDateBuild(asField) {
 var lsXml = '';
 lsXml += "<DD>" + $(asField + "DD").value + "</DD>";
 lsXml += "<MM>" + $(asField + "MM").value + "</MM>";
 lsXml += "<YYYY>" + $(asField + "YYYY").value + "</YYYY>";
 return lsXml;
}

function xmlDateValueBuild(asDate, asDatePrefix) {
 if (typeof(asDatePrefix) == "undefined") {asDatePrefix = "";}
 var lsXml = '';
 lsXml += "<" + asDatePrefix + "DD>" + asDate.substr(0, 2) + "</" + asDatePrefix + "DD>";
 lsXml += "<" + asDatePrefix + "MM>" + asDate.substr(3, 2) + "</" + asDatePrefix + "MM>";
 lsXml += "<" + asDatePrefix + "YYYY>" + asDate.substr(6, 4) + "</" + asDatePrefix + "YYYY>";
 return lsXml;
}

function xmlAddField(asField, asNode) {
 return "<" + asNode + ">" + $(asField).value + "</" + asNode + ">";
}

function xmlAddValue(asValue, asNode) {
 return "<" + asNode + ">" + asValue + "</" + asNode + ">";
}

// ------------------------------------------------------------------
// Alert functions
// ------------------------------------------------------------------
function setFocus(lsAlertMsg, aoField) {
 if (typeof(aoField) == "string") aoField = $(aoField);
 alert(lsAlertMsg);
 aoField.focus();
 return false;
}

// ------------------------------------------------------------------
// Radio button functions
// ------------------------------------------------------------------
function getRadioValue(asName) {
 var value = null;
 var radioButtonGroup = getInputsByName(asName);
 if (radioButtonGroup.length > 0) {
 for (var idx = 0; idx < radioButtonGroup.length; idx++)
 if (radioButtonGroup[idx].checked) value = radioButtonGroup[idx].value;
 }
 return value;
}

// ------------------------------------------------------------------
// Get first DOM child (Firefox fix)
// ------------------------------------------------------------------
function getFirstChild(theParent) {
 var theChild = theParent.firstChild;
 while (theChild.nodeType != 1) {
 theChild = theChild.nextSibling;
 }

 return theChild;
}

// ------------------------------------------------------------------
// Get element function
// ------------------------------------------------------------------
function $f(element) {
 if (arguments.length > 1) {
 for (var i = 0, elements = [], length = arguments.length; i < length; i++)
 elements.push($f(arguments[i]));
 return elements;
 }
 if (typeof element == 'string')
 element = document.getElementById(element);
 return element;
}


// ------------------------------------------------------------------
// Get input fields function
// ------------------------------------------------------------------
function getInputsByName(name) {
 var results = [];
 results.numChecked = 0;
 var input = document.getElementsByTagName("input");
 for (var i=0; i < input.length; i++) {
 if (input[i].name == name) {
 results.push(input[i]);
 if (input[i].checked)
 results.numChecked++;
 }
 }
 return results;
}

// ------------------------------------------------------------------
// Format a number to 2 decimal places
// ------------------------------------------------------------------
function formatNumber() {
 if (isNaN(this)) return("");
 var NumVal = new Number(this);
 var RetVal = new String();
 var IntegerPlaces = new Number(15);
 var DecimalPlaces = new Number(2);
 NumVal = Math.round(Math.ceil(NumVal * Math.pow(10, DecimalPlaces))) / Math.pow(10, DecimalPlaces);
 RetVal = String(NumVal);
 if (RetVal.indexOf('.') == -1) RetVal += '.';
 if (RetVal.substring(0, RetVal.indexOf('.')).length > IntegerPlaces) return("");
 while (RetVal.substr(RetVal.indexOf('.') + 1).length < DecimalPlaces) {RetVal += '0';}
 return(RetVal);
}

Number.prototype.format = formatNumber;

// ------------------------------------------------------------------
// Switch on holding page if we've got it
// ------------------------------------------------------------------
function useHolding() {
 if ($f('holdingPage')) {
 addClassName($f('maincontentHolder'), 'hideme');
 removeClassName($f('holdingPage'), 'hideme');
 }
}

function truncateSentence(sentence, numWords) {
 var str='';
 var splitStr = sentence.split(' ');
 var totalNumWords = splitStr.length;
 for (i=0;i<numWords && i<totalNumWords;i++) str=str+splitStr[i]+" ";
 document.write(str);
}

function adjustDays(dd,mm,yy)
{
 var day = document.getElementById(dd);
 var month = parseInt(document.getElementById(mm).value);
 var year=document.getElementById(yy).value;
 limitList(monthDays(month,year), dd);
}
function monthDays(month,year) {
  month--;
 var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  if ((year % 4 == 0) && (month==1)) {
 if (year % 100 == 0) {
 if (year % 400 == 0) {
 return 29;
 } else {
 return 28;
 }
 } else {
 return 29;
 }
 } else {
 return day[month];
 }
}

function limitList(length, dd) {
 var list;
 var len1=length;
 var len2=0;
 var elOptNew29;
 var elOptNew30;
 var elOptNew31;

 var list=document.getElementById(dd);

 while (list.length > len1){
 list.remove(list.length - 1);
 }

 while (len1 > list.length){
 if (list.length == 28){
 elOptNew29 = document.createElement('option');
 elOptNew29.text = 29;
 elOptNew29.value = 29;
 try {
 list.add(elOptNew29, null); // standards compliant; doesn't work in IE
 }
 catch(ex) {
 list.add(elOptNew29); // IE only
 }
 }
 else if (list.length == 29){
 elOptNew29 = document.createElement('option');
 elOptNew29.text = 30;
 elOptNew29.value = 30;
 try {
 list.add(elOptNew29, null); // standards compliant; doesn't work in IE
 }
 catch(ex) {
 list.add(elOptNew29); // IE only
 }
 }
 else if (list.length == 30){
 elOptNew29 = document.createElement('option');
 elOptNew29.text = 31;
 elOptNew29.value = 31;
 try {
 list.add(elOptNew29, null); // standards compliant; doesn't work in IE
 }
 catch(ex) {
 list.add(elOptNew29); // IE only
 }
 }
 }
}
/***************************************************************************************************
  end date.js
/**************************************************************************************************/  


/***************************************************************************************************
  start DrawDates.js
/**************************************************************************************************/  
function DrawMonths(asField, asBlank) {
  var laMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  var sPos = 0;
  if (asBlank == 'Y') {
    $(asField).options[0] = new Option('Month', '');
    sPos = 1;
  }
  for (var j=0; j < laMonths.length; j++) $(asField).options[j + sPos] = new Option(laMonths[j], LZ(j+1));
}

function DrawDays(asField, asBlank) {
  for (var j=0; j < 31; j++) $(asField).options[j] = new Option(LZ(j+1), LZ(j+1));
}

function DrawYears(anRange, asDirection, asField, asBlank, adMinDate, adMaxDate) {
  adMinDate = adMinDate || null;
  adMaxDate = adMaxDate || null;
  var Base;
  if (adMinDate != null) Base = adMinDate.getFullYear();
  else Base = new Date().getFullYear();
  if (adMaxDate != null && asDirection == "+") {
    llMaxYear = adMaxDate.getFullYear();
    if ((Base + anRange) > llMaxYear) anRange = (llMaxYear - Base) + 1;
  }
  var sPos = 0;
  if (asBlank == 'Y') {
    $f(asField).options[0] = new Option('Year', '');
    sPos = 1;
  }
  for (var j=0; j < anRange; j++) {
    if (asDirection == "+")
      $f(asField).options[j + sPos] = new Option(Base + j, Base + j);
    else
      $f(asField).options[j + sPos] = new Option(Base - j, Base - j);
  }
}

function DrawYearsForCITChild(anRange, asDirection, asField, asBlank) {
  var Base = new Date().getFullYear() - 2;
  var sPos = 0;
  if (asBlank == 'Y') {
    $(asField).options[0] = new Option('Year', '');
    sPos = 1;
  }
  for (var j=0; j < anRange; j++) {
    if (asDirection == "+")
      $(asField).options[j + sPos] = new Option(Base + j, Base + j);
    else
      $(asField).options[j + sPos] = new Option(Base - j, Base - j);
  }
}

function DrawYearsForChild(anRange, asDirection, asField, asBlank) {
  var Base = new Date().getFullYear()-3;
  var sPos = 0;
  if (asBlank == 'Y') {
    $(asField).options[0] = new Option('Year', '');
    sPos = 1;
  }
  for (var j=0; j < 14; j++) {
    if (asDirection == "+")
      $(asField).options[j + sPos] = new Option(Base + j, Base + j);
    else
      $(asField).options[j + sPos] = new Option(Base - j, Base - j);
  }
}
/***************************************************************************************************
  end DrawDates.js
/**************************************************************************************************/  

/***************************************************************************************************
  start geography.js
/**************************************************************************************************/  
// ------------------------------------------------------------------
// global variables
// ------------------------------------------------------------------
var gaAccomList = new Array();
var gaCty1List = new Array();
var gaCty2List = new Array();
var gaCty3List = new Array();
var gsCty1 = '', gsCty2 = '', gsCty3 = '', gsDep = '', gsAccom = '';

// ------------------------------------------------------------------
// Geography objects
// ------------------------------------------------------------------
function accomObj(asStkId, asStkNm, asCty1Id, asCty2Id, asCty3Id) {
  this.Id = asStkId;
  this.Name = asStkNm;
  this.Cty1Id = asCty1Id;
  this.Cty2Id = asCty2Id;
  this.Cty3Id = asCty3Id;
}

function cty1Obj(asId, asNm) {
  this.Id = asId;
  this.Name = asNm;
}

function cty2Obj(asId, asNm, asCty1Id) {
  this.Id = asId;
  this.Name = asNm;
  this.Cty1Id = asCty1Id;
}

function cty3Obj(asId, asNm, asCty1Id, asCty2Id) {
  this.Id = asId;
  this.Name = asNm;
  this.Cty1Id = asCty1Id;
  this.Cty2Id = asCty2Id;
}

// ------------------------------------------------------------------
// Geography functions
// ------------------------------------------------------------------
function Reset(asThis, bClear) {
  var current_ID = '';
  if ($f(asThis + '_ID')) {
    current_ID = $f(asThis + '_ID').value;
  }
  if (current_ID != "") {
    if (asThis == 'CTY1') {
      if (gsGeogCty2 == 'Y') { $f('CTY2_ID').value = ""; }
      $f('CTY3_ID').value = "";
      if ($f('ACC_ID')) $f('ACC_ID').value = "";
    }
    if (asThis == 'CTY2') {
      $f('CTY3_ID').value = "";
      if ($f('ACC_ID')) $f('ACC_ID').value = "";
    }
    if (asThis == 'CTY3') {
      if ($f('ACC_ID')) $f('ACC_ID').value = "";
    }
    if (current_ID != '') $f(asThis + '_ID').value = current_ID;
  }
}

function buildGeogDep(laTrsList) {
  var cPos = 1;
  $f('DEP_PT_ID').options.length = 0;
  $f('DEP_PT_ID').options[0] = new Option("Select...", "");
  for (var idx=0; idx < laTrsList.length; idx++) {
    $f('DEP_PT_ID').options[cPos] = new Option(laTrsList[idx][1], laTrsList[idx][0]);
    cPos++;
  }
}
  
function buildGeogCty1() {
  var cPos = 1;
  document.getElementById('CTY1_ID').options.length = 0;
  document.getElementById('CTY1_ID').options[0] = new Option("Select country", "");
  for (var idx=0; idx < gaCty1List.length; idx++) {
    $f('CTY1_ID').options[cPos] = new Option(gaCty1List[idx].Name, gaCty1List[idx].Id);
    cPos++;
  }
}

function buildGeogCty2() {
  var cPos = 1;
  $f('CTY2_ID').options.length = 0;
  $f('CTY2_ID').options[0] = new Option("Select...", "");
  for (var idx=0; idx < gaCty2List.length; idx++) {
    if (($f('CTY1_ID').value == '') || ($f('CTY1_ID').value == gaCty2List[idx].Cty1Id)) {
      $f('CTY2_ID').options[cPos] = new Option(gaCty2List[idx].Name, gaCty2List[idx].Id);
      cPos++;
    }
  }
}

function buildGeogCty3() {
  var cPos = 1, lbFound;
  $f('CTY3_ID').options.length = 0;
  $f('CTY3_ID').options[0] = new Option("All regions", "");
  for (var idx=0; idx < gaCty3List.length; idx++) {
    lbFound = false;
    if ((gsGeogCty2 == 'Y')  && ($f('CTY2_ID').value != '')) {
      if ($f('CTY2_ID').value == gaCty3List[idx].Cty2Id) lbFound = true;
    } else if ((gsGeogCty1 == 'Y') && ($f('CTY1_ID').value != '')) {
      if ($f('CTY1_ID').value == gaCty3List[idx].Cty1Id) lbFound = true;
    } else
      lbFound = true;
    if (lbFound) {
      $f('CTY3_ID').options[cPos] = new Option(gaCty3List[idx].Name, gaCty3List[idx].Id);
      cPos++;
    }
  }
}

function buildGeogAccom() {
  var cPos = 1, lbAddAccom;
  var lsCty1 = '';
  var lsCty2 = '';
  var lsCty3 = $f('CTY3_ID').value;

  if (gsGeogCty1 == 'Y') {lsCty1 = $f('CTY1_ID').value; }
  if (gsGeogCty2 == 'Y') {lsCty2 = $f('CTY2_ID').value; }

  $f('ACC_ID').options.length = 0;
  $f('ACC_ID').options[0] = new Option("All parcs", "");
  for (var idx=0; idx < gaAccomList.length; idx++) {
    lbAddAccom = false;
    if (lsCty3 != '') {
      if (lsCty3 == gaAccomList[idx].Cty3Id) lbAddAccom = true;
    } else if (lsCty2 != '') {
      if (lsCty2 == gaAccomList[idx].Cty2Id) lbAddAccom = true;
    } else if (lsCty1 != '') {
      if (lsCty1 == gaAccomList[idx].Cty1Id) lbAddAccom = true;
    } else
      lbAddAccom = true;
    if (lbAddAccom) {
      $f('ACC_ID').options[cPos] = new Option(gaAccomList[idx].Name, gaAccomList[idx].Id);
      cPos++;
    }
  }
}

function buildGeogLists(asLevel) {
  if (asLevel == 'INIT') {
    if (typeof(DATList) != "undefined") {
      buildGeogDep(DATList)
    }
    if (gsDep != '') {$f('DEP_PT_ID').value = gsDep;}
    if (gsGeogCty1 == 'Y') { 
      buildGeogCty1();
      if (gsCty1 != '') {$f('CTY1_ID').value = gsCty1;}
    }
  }
  if ((asLevel == 'CTY1') || ((asLevel == 'INIT') && (gsGeogCty2 == 'Y'))	) {		
    if (gsGeogCty2 == 'Y') {
      buildGeogCty2();
      if (gsCty2 != '') {$f('CTY2_ID').value = gsCty2;}
    }
  }
  buildGeogCty3();
  if (gsCty3 != '') {$f('CTY3_ID').value = gsCty3;}
  if ($f('ACC_ID')) {
    buildGeogAccom();
    if (gsAccom != '') {$f('ACC_ID').value = gsAccom;}
  }
  gsCty1 = '', gsCty2 = '', gsCty3 = '', gsDep = '', gsAccom = '';
}



function SearchAccomList( accomcode)
{
   for (var idx=0; idx < gaAccomList.length; idx++) { 
      if (accomcode == gaAccomList[idx].Id   ) return gaAccomList[idx]; 

   }
  return null;
}



function SearchRegionList( RegionCode)
{
   for (var idx=0; idx < gaCty3List.length; idx++) { 
      if (RegionCode == gaCty3List[idx].Id   ) return gaCty3List[idx]; 

   }
  return null;
}
/***************************************************************************************************
  end geography.js
/**************************************************************************************************/  
