﻿//'------------------------------------------------------------------------------------------------------------
//' cs_validation.js
//' 29/10/2007
//' Steve Rowland
//'
//' recreates the search form validation functionality in client-side code
//'------------------------------------------------------------------------------------------------------------
//' History           Author                          Modification(s)
//'
//' 29/10/2007        Steve Rowland                   Created
//'------------------------------------------------------------------------------------------------------------


//TODO: determine if this is required (logic moved to PackageSearchForm.js)
//document.onreadystatechange=restoreValues;

/*CONST*/
var numMessages = 20;
var messages = new Array(numMessages);
messages[0] = 'Each room must have at least one adult occupant.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&p_created=1132909608&p_sid=NstpJHJi&p_lva=154&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&p_li=&p_topview=1">Click here</A> for more information.';
messages[1] = 'Please enter the age of each child in the party.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&amp;p_created=1132909608&amp;p_sid=NstpJHJi&amp;p_lva=154&amp;p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&amp;p_li=&amp;p_topview=1"">Click here</A> for more information.'
messages[2] = 'Please enter a Hotel name.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&amp;p_created=1132909608&amp;p_sid=NstpJHJi&amp;p_lva=154&amp;p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&amp;p_li=&amp;p_topview=1"">Click here</A> for more information.'
messages[3] = 'Please enter a Brochure code.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&amp;p_created=1132909608&amp;p_sid=NstpJHJi&amp;p_lva=154&amp;p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&amp;p_li=&amp;p_topview=1"">Click here</A> for more information.'
messages[4] = 'Please enter a Holiday Locator number.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&amp;p_created=1132909608&amp;p_sid=NstpJHJi&amp;p_lva=154&amp;p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&amp;p_li=&amp;p_topview=1"">Click here</A> for more information.'
messages[5] = '<b>Please enter a valid Departure date (at least 3 days from today).</b>'
messages[6] = 'There must be at least one adult for every two children travelling.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&p_created=1132909608&p_sid=NstpJHJi&p_lva=154&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&p_li=&p_topview=1">Click here</A> for more information.';
messages[7] = 'There is a maximum of 9 aircraft seats per booking.'// <A class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=160&p_created=1118940814&p_sid=NstpJHJi&p_lva=181&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9MjAmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1tYXhpbXVtIHBhcnR5IHNpemU*&p_li=&p_topview=1">Click here</A> for more information.';
messages[8] = 'There must be at least 1 adult for each infant travelling.'// <a class="error redText" target="_blank" href="http://thomascooknew.custhelp.com/cgi-bin/thomascooknew.cfg/php/enduser/std_adp.php?p_faqid=181&p_created=1132909608&p_sid=NstpJHJi&p_lva=154&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZwX3Jvd19jbnQ9NTMmcF9wcm9kcz0wJnBfY2F0cz0mcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hfdGV4dD1vbmUgYWR1bHQgcGVyIGNoaWxk&p_li=&p_topview=1">Click here</a> for more information.';
messages[9] = 'Snow holidays are only available during the winter months of December to April. Please enter a new departure date.';
messages[10] = 'Holidays to Santorini are only available during the months of May to October. Please enter a new departure date.';
messages[11] = 'Holidays to Lapland are only available during the month of December. Please enter a new departure date.';

var errorMeassageID	= "errorMessage";
var LabelRMSID		= "LabelRMS";
var DDLabelID		= "DDLabel";
var uxHotelNameSelectID		 = "uxSearchFormControl_uxHotelNameSelect";
var uxBrochureCodeSelectID	 = "uxSearchFormControl_uxBrochureCodeSelect";
var uxHolidayLocatorSelectID = "uxSearchFormControl_uxHolidayLocatorSelect";

var BEFORE_BEGIN	= "beforeBegin";
var AFTER_BEGIN		= "afterBegin";
var BEFORE_END		= "beforeEnd";
var AFTER_END		= "afterEnd";

var MAIN_FORM		= "mainForm";
var HOTEL_NAME		= "hotelName";
var BROCHURE_CODE	= "brochureCode";
var HOLIDAY_LOCATOR = "holidayLocator";

/*VARIABLES*/
var partySize = 0;
var message;

// Test if cookies are enabled in the browser
SetCookie( "test", "none" );
// if Get_Cookie succeeds, cookies are enabled, since 
// the cookie was successfully created.
if ( GetCookie( "test" ) )
{
	// and these are the parameters for Delete_Cookie:
	// name, path, domain	
	DeleteCookie("test", "/", "");
}
// if the Get_Cookie test fails, cookies 
// are not enabled for this session.
else
{
	alert( "Warning \n\nCookies are not currently enabled in your browser. \nYou must have cookies enabled to use this site. \nPlease enable cookies and refresh the page before continuing." );
}

// implement insertAdjacentElement for Firefox
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{ 
    HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode) 
    { 
        switch (where)
        { 
            case BEFORE_BEGIN: 
                this.parentNode.insertBefore(parsedNode,this);
                break; 
            case AFTER_BEGIN: 
                this.insertBefore(parsedNode,this.firstChild); 
                break; 
            case BEFORE_END: 
                this.appendChild(parsedNode); 
                break; 
            case AFTER_END: 
                if (this.nextSibling) 
                {
                    this.parentNode.insertBefore(parsedNode,this.nextSibling); 
                }
                else 
                {
                    this.parentNode.appendChild(parsedNode); 
                }
                break; 
        } 
    } 

    HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) 
    { 
        var r = this.ownerDocument.createRange(); 
        r.setStartBefore(this); 
        var parsedHTML = r.createContextualFragment(htmlStr); 
        this.insertAdjacentElement(where,parsedHTML);
    }
    
    HTMLElement.prototype.insertAdjacentText = function(where,txtStr) 
    { 
        var parsedText = document.createTextNode(txtStr);
        this.insertAdjacentElement(where,parsedText);
    } 
}

function removeErrorMessage() {
	var errorDiv = $(errorMeassageID);
	if (errorDiv != null)
	{
		errorDiv.parentNode.removeChild(errorDiv);
	}
}

function addErrorMessage(container, errorMessage, where) {
	if (container != null)
	{
		var objDiv = document.createElement("DIV");                
		objDiv.id = errorMeassageID;                
		objDiv.innerHTML = errorMessage;
		objDiv.style.display = "block";
		objDiv.style.fontSize = "9pt";
		objDiv.style.color = "red";
		objDiv.style.marginBottom = "5px";         
		container.insertAdjacentElement(where, objDiv);
	}
}

function getElementParent(elementID){
	var element = $(elementID);
	if (element != null)
	{
		return element.parentNode;
	}
	return null;
}

function Page_ClientValidate(str)
{
	var valid = true;
	var msgDiv;
	   
	removeErrorMessage();

    if(!resetAjaxCalls())
    {
		return false;
	}

    if($("uiSearchHolidayLocator").style.display != "block")
    {
        $("hl").value = "";
    }
     
    storeValues();

    switch(str)
    {
        case MAIN_FORM:
			// Date validation			
			if(valid)
            {
                valid = validateDate(5);
                msgDiv = getElementParent(DDLabelID);
            }
            if(valid)
            {
                valid = validateSnow(9);
                msgDiv = getElementParent(DDLabelID);
            }
            if(valid)
            {
                valid = validateSantorini(10);
                msgDiv = getElementParent(DDLabelID);
            }
            if(valid)
            {
                valid = validateLapland(11);
                msgDiv = getElementParent(DDLabelID);
            }
            // PAX validation
            partySize = 0;			
            if(valid)
            {						
				valid = validateRoom(1);
				msgDiv = getElementParent(LabelRMSID);
			}
            if(valid)
            {
                valid = validateRoom(2);
                msgDiv = getElementParent(LabelRMSID);
            }
            if(valid)
            {
                valid = validateRoom(3);
                msgDiv = getElementParent(LabelRMSID);
            }
            break;            
        case HOTEL_NAME:
            if(valid)
            {
				valid = validateHotelName();
				msgDiv = $(uxHotelNameSelectID);				
                message = messages[2];                
            }
            break;
        case BROCHURE_CODE:
            if(valid)
            {
				valid = validateBrochureCode();
				msgDiv = $(uxHotelNameSelectID);
                message = messages[3];                
            }
            break;
        case HOLIDAY_LOCATOR:
            if(valid)
            {
				valid = validateHolidayLocator();
				msgDiv = $(uxHotelNameSelectID);
                message = messages[4];                
            }
            break;
        default:
            valid = true;        
    }
   
    if(!valid)
	{
		addErrorMessage(msgDiv, message, BEFORE_BEGIN);
	}  
    
    return valid;
}

function $(ElementId)
{
    if(document.getElementById(ElementId) != null)
    {
	    return document.getElementById(ElementId);
	}
	else
	{
	    return document.getElementById('ctl00_ctl00_uiBodyPlaceHolder_uiWrappedContentPlaceHolder' + ElementId);
	}
}

function validateDate(msgNum)
{
    if($('DepartureDate').value == '' || !isValidDate($('DepartureDate').value))
    {
        message = messages[msgNum];
        return false;
    }
    if($("DepartureDate").value != '')
    {
        var deptdate = $("DepartureDate").value;
        dateArray = deptdate.split("/");
        day = dateArray[0];
        month = dateArray[1];
        year = dateArray[2];
        
        if(dateArray.length!=3)
        {
            message = messages[msgNum];
            return false;
        }
        
        if(year.toString().length == 2)
        {
            year = '20' + year;
        }
    
        var departureDate = new Date(1970,0,1);
        departureDate.setFullYear(year);	        
        departureDate.setDate(day);
        departureDate.setMonth((month-1));
        
        var deptDay = departureDate.getDate().toString();
        var deptMonth = (departureDate.getMonth()+1).toString();
        var deptYear =  departureDate.getFullYear().toString();
        if(deptDay.toString().length == 1)
        {
            deptDay = '0' + deptDay;
        }
        
        if(deptMonth.toString().length == 1)
        {
            deptMonth = '0' + deptMonth;
        } 
        var Date1 = deptDay + '/' + deptMonth + '/' + deptYear;
        var curDate = new Date();        
        var nDay = curDate.getDate().toString();
        var nMonth = (curDate.getMonth()+1).toString();
        
        if(nDay.toString().length == 1)
        {
            nDay = '0' + nDay;
        }
        
        if(nMonth.toString().length == 1)
        {
            nMonth = '0' + nMonth;
        }  
        var sDate = nDay + '/' + nMonth + '/' + curDate.getFullYear().toString(); 
                       	        
        curDate.DateDiff({interval:"d",date1:sDate,date2:Date1,delimiter:"/"});
        var diff = curDate.difference;
        if(diff <= 2) // date selected is prior to 2 days hence
        {
            message = messages[msgNum];
            return false;
        }
        if(!isValidDate(deptdate))
	    {
            message = messages[msgNum];
            return false;
        }
    }
        
    return true;
}

function validateSnow(msgNum)
{
    if($("DepartureDate").value != '')
    {
        var deptdate = $("DepartureDate").value;
        dateArray = deptdate.split("/");        
        month = dateArray[1];
        
        if((month > 4 && month != 12) && $('PRP').value.toLowerCase() == "aa453382-c7f2-11d7-b2ab-000629385218")
	    {
            message = messages[msgNum];
            return false;
        }
        
    }

    return true;
}

function validateSantorini(msgNum)
{
    if($("DepartureDate").value != '')
    {
        var deptdate = $("DepartureDate").value;
        dateArray = deptdate.split("/");        
        month = dateArray[1];
        
        if( !(month > 4 && month < 11) && $('DTN').value.toLowerCase().indexOf("santorini") != -1)
	    {
            message = messages[msgNum];
            return false;
        }
        
    }

    return true;
}

function validateLapland(msgNum)
{
    if($("DepartureDate").value != '')
    {
        var deptdate = $("DepartureDate").value;
        dateArray = deptdate.split("/");        
        month = dateArray[1];
        
        if( month != 12 && $('DTN').value.toLowerCase().indexOf("lapland") != -1)
	    {
            message = messages[msgNum];
            return false;
        }
        
    }

    return true;
}

function validateRoom(rmNum)
{
    if($('RMS').value > (rmNum-1))
    {
        var roomAdults = parseInt($('RM'+rmNum+'A').value) + parseInt($('RM'+rmNum+'S').value);
        var roomChildren = parseInt($('RM'+rmNum+'C').value);
        var roomInfants = 0;
        partySize += roomAdults + roomChildren;
        
        for(var i=1; i<=roomChildren; i++)
        {
            if($('RM'+rmNum+'C'+i).value == '1')
            {
                roomInfants++;
            }
        }
        
        // each room must have at least one adult
        if  ( roomAdults == 0 )
        {
            message = messages[0];
            return false;
        }
        // does every child have a child age defined  
        for(var ch=1;ch<=roomChildren;ch++)
        {
          if(isNaN(parseInt($('RM'+rmNum+'C'+ch).value))||parseInt($('RM'+rmNum+'C'+ch).value) == 0) 
          {
            message = messages[1];
            return false;
          }
        }
       
        // is the ratio of adults to children correct
        if ( roomAdults > 0 && roomChildren > 0 && (roomChildren/roomAdults) > 2 )
        {
            message = messages[6];
            return false;
        }
        
         // is the ratio of adults to infants correct
        if ( roomAdults > 0 && roomInfants > 0 && (roomInfants/roomAdults) > 1 )
        {
            message = messages[8];
            return false;
        }
        
        // is the party size 9 or less
        if ( partySize > 9 )
        {
            message = messages[7];
            return false;
        }
    }
    return true;
}

function storeValues()
{    

  var value = {     
    PRP        : $('PRP').value,
    DPC        : $('DPC').value,
    DTN        : $('DTN').value,
    RST        : $('RST').value,
    DD         : $('DepartureDate').value,
    NN         : $('NN').value,
    RMS        : $('RMS').value,
    RM1A       : $('RM1A').value,
    RM1S       : $('RM1S').value,
    RM1C       : $('RM1C').value,
    RM2A       : $('RM2A').value,
    RM2S       : $('RM2S').value,
    RM2C       : $('RM2C').value,
    RM3A       : $('RM3A').value,
    RM3S       : $('RM3S').value,
    RM3C       : $('RM3C').value,
    RM1C1      : $('RM1C1').value,
    RM1C2      : $('RM1C2').value,
    RM1C3      : $('RM1C3').value,
    RM1C4      : $('RM1C4').value,
    RM1C5      : $('RM1C5').value,
    RM1C6      : $('RM1C6').value,
    RM2C1      : $('RM2C1').value,
    RM2C2      : $('RM2C2').value,
    RM2C3      : $('RM2C3').value,
    RM2C4      : $('RM2C4').value,
    RM2C5      : $('RM2C5').value,
    RM2C6      : $('RM2C6').value,
    RM3C1      : $('RM3C1').value,
    RM3C2      : $('RM3C2').value,
    RM3C3      : $('RM3C3').value,
    RM3C4      : $('RM3C4').value,
    RM3C5      : $('RM3C5').value,
    RM3C6      : $('RM3C6').value,
    BDG        : $('BDG').value,
    BB         : $('BB').value,
    SR         : $('SR').value
  };
  
  subcookiejar.bake('packageParams', value);
  
    /* TODO: restore these methods with renamed fields and div containers
    SetCookie('AN',$('AN').value);
    SetCookie('AC',$('AC').value);
    SetCookie('HR',$('HR').value);
    //save the div expansion properties
    SetCookie('uiSearchHotelName',$('uiSearchHotelName').style.display);
    SetCookie('uiSearchBrochureCode',$('uiSearchBrochureCode').style.display);
    SetCookie('uiSearchHolidayLocator',$('uiSearchHolidayLocator').style.display);
    */
}

function restoreValues()
{
//TODO: refactor this to account for InitialiseSearchForm method in PackageSearchForm.js    
    if(document.readyState == 'complete')
    {         
        var value;

        setCookieValue('PRP');
        setCookieValue('DPC');
        if(setCookieValue('DTN'))DestinationOnChangeHandler();
        setCookieValue('RST');
        
        value=GetCookie('DD');      
        if(value != null && value != "")
        {
            if($('DepartureDate') != null)
            {
                $('DepartureDate').value = value;
                document.getElementById('DepartureDate_txtDateLabel').innerHTML = getTheDay($('DepartureDate').value);
            }
        }
        else
        {
             if($('DepartureDate') != null)
            {
                var nDate = new Date();
                var nMonth;
                var nDay;
                nDate.setDate(nDate.getDate()+2)
                nDay = nDate.getDate(); 
                if(nDay.toString().length == 1)
                {
                    nDay = '0' + nDay;
                }
                nMonth = (nDate.getMonth()+1)
                if(nMonth.toString().length == 1)
                {
                    nMonth = '0' + nMonth;
                }
                var oDate = nDay + '/' + nMonth + '/' + nDate.getFullYear();
                var sDate = nDay.toString() + '/' + nMonth.toString() + '/' + nDate.getYear().toString();
                $('DepartureDate').value = oDate;
                document.getElementById('DepartureDate_txtDateLabel').innerHTML = getTheDay(sDate);
            }
        }
        
        if(!setCookieValue('NN'))
        {
            $('NN').value = '7 nights';
        }

        setCookieValue('RMS')
        
        if(!setCookieValue('RM1A'))
        {
            $('RM1A').value = '2';
        }
        for(var room=1;room<=3;room++)
        {
           setCookieValue('RM'+room+'A');
           setCookieValue('RM'+room+'S');
           setCookieValue('RM'+room+'C');
           
           for(var child=1;child<7;child++)
           {
             setCookieValue('RM'+room+'C'+child);
           };
        };
        if(!setCookieValue('BDG'))
        {
            $('BDG').value = 'All budgets';
        }

        if(!setCookieValue('BB'))
        {
            $('BB').value = 'All board basis';
        }

        if(!setCookieValue('SR'))
        {
            $('SR').value = 'All star ratings';
        }

        setCookieValue('uxSearchFormControl_an');
        setCookieValue('uxSearchFormControl_bc');
        setCookieValue('uxSearchFormControl_uxHolidayLocator');

        /* TODO: Field names appear to have changed - restore with amended field names
        uxSearchFormControl_uxSearchFormPaxRoomMixControl_toggleRoomFields($('RMS'));
        uxSearchFormControl_uxSearchFormPaxRoomMixControl_toggleRoom1ChildFields($('RM1C'),1);
        uxSearchFormControl_uxSearchFormPaxRoomMixControl_toggleRoom2ChildFields($('RM2C'),2);
        uxSearchFormControl_uxSearchFormPaxRoomMixControl_toggleRoom2ChildFields($('RM3C'),3);
        */
        value=GetCookie('uiSearchHotelName');
        if(value != null && value != "")
        {
            $('uiSearchHotelName').style.display = value;
        }
        value=GetCookie('uiSearchBrochureCode');
        if(value != null && value != "")
        {
            $('uiSearchBrochureCode').style.display = value;
        }
        value=GetCookie('uiSearchHolidayLocator');
        if(value != null && value != "")
        {
            $('uiSearchHolidayLocator').style.display = value;
        }
    }    
    
} 
function setCookieValue(elem)
{
   var value=GetCookie(elem);
   if(value != null && value != "")
   {
      $(elem).value = value;
      return true;
   }  
   return false;  
}
function validateHotelName()
{
  return !($('an').value == '' || $('an').value == 'Hotel name');
}
function validateBrochureCode()
{
return !($('bc').value == '' || $('bc').value == 'Brochure code');
}
function validateHolidayLocator()
{
return !($('hl').value == '' || $('hl').value == 'Holiday locator number');
}

//Passenger Mix support JS

    var isAdultsOnly = false;
    
	function uxSearchFormControl_uxSearchFormPaxRoomMixControl_toggleRoomFields(ElementId)
	{
	    if(ElementId != null)
	    {
		    if(ElementId.value < 3)
		    {
			    document.getElementById('uiRoom3Container').style.display="none";
			    var myObj = document.getElementById('uiRoom3Container').getElementsByTagName("select");
			    for(var i=0;i<myObj.length;i++)myObj[i].value = '0';		}
		    else
		    {
			    document.getElementById('uiRoom3Container').style.display="";
		    }
		    if(ElementId.value < 2)
		    {
			    document.getElementById('uiRoom2Container').style.display="none";
			    var myObj = document.getElementById('uiRoom2Container').getElementsByTagName("select");
			    for(var i=0;i<myObj.length;i++)myObj[i].value = '0';		}
		    else
		    {
			    document.getElementById('uiRoom2Container').style.display="";
		    }
		}
	}

	function uxSearchFormControl_uxSearchFormPaxRoomMixControl_toggleRoomChildFields(ElementId, roomIndex)
	{
	    if(ElementId != null)
	    {
	        for(var child=6;child>0;child--)
	        {
	        	if(ElementId.value < child)
		         {
			         document.getElementById('uiRoom'+roomIndex+'Child'+child+'Container').style.display="none";
			         var myObj = document.getElementById('uiRoom'+roomIndex+'Child'+child+'Container').getElementsByTagName("select");
			        for(var i=0;i<myObj.length;i++)myObj[i].value = '';		}
		         else
		         {
			    document.getElementById('uiRoom'+roomIndex+'Child'+child+'Container').style.display="block";
		         }
	        }
		 }
	}
	function uxNext_Click()
	{
	    mooveDate("3");
	}
	function uxPrev_Click()
	{	
	    mooveDate("-3");
	}
	function mooveDate(days)
	{
		if(!resetAjaxCalls()) return;
	    var year;
	    var month;
	    var day;
	    if($("DepartureDate").value != '')
	    {
	        var deptdate = $("DepartureDate").value;
	        dateArray = deptdate.split("/");
	        day = dateArray[0];
	        month = dateArray[1];
	        year = dateArray[2];
	    
	        var departureDate = new Date(1970,0,1);
	        departureDate.setFullYear(year);
	        departureDate.setDate(day);
	        departureDate.setMonth((month-1));
	        
	        departureDate = DateAdd("d",days,departureDate);
	        
	        var nMonth = (departureDate.getMonth()+1);
            var nDay = departureDate.getDate();
            
            if(nDay.toString().length == 1)
            {
                nDay = '0' + nDay;
            }
           
            if(nMonth.toString().length == 1)
            {
                nMonth = '0' + nMonth;
            }                
            var sDate = nDay.toString() + '/' + nMonth.toString() + '/' + departureDate.getFullYear().toString();                	        
	        
	        $("DepartureDate").value = sDate;
	        subcookiejar.refresh('packageParams','DD', sDate);	        
	        if($('uiSearchHolidayLocator').style.display != "block")
            {
                $('hl').value = "";
            }
 //           $('MS').value = "true";
	        document.forms["form1"].submit();	        
	    }
	}
	function matrixOnClick(newDate)
	{
	    if(!resetAjaxCalls()) return;   
	    $('DepartureDate').value = newDate;
	    subcookiejar.refresh('packageParams','DD', newDate);
	    
	    if($('uiSearchHolidayLocator').style.display != "block")
        {
            $('hl').value = "";
        }	        
      //  $('MS').value = "true";
	    document.forms["form1"].submit();
	}
	
	function resetAjaxCalls()
	{
	    if(typeof(xmlReqs) != "undefined" && xmlReqs != null)
	    {
	        for(var index=0; index< xmlReqs.length; index++)
	        {
	            if(typeof(xmlReqs[index]) != "undefined")
	            {
//	                xmlReqs[index].onreadystatechange = function () {}	            
//	                xmlReqs[index].abort();
//	                xmlReqs[index] = null;
                    if(xmlReqs[index].readyState > 0 && xmlReqs[index].readyState < 4)
                    {
                        return false;
                        break;
                    }
	            }
	        }
//	        xmlReqs = null;
	    }
	    return true;
	}
	
	function DateAdd(timeU,byMany,dateObj) 
	{
	    var millisecond=1;
	    var second=millisecond*1000;
	    var minute=second*60;
	    var hour=minute*60;
	    var day=hour*24;
	    var year=day*365;

	    var newDate;
	    var dVal=dateObj.valueOf();
	    
        switch(timeU) 
        {
	        case "ms": newDate=new Date(dVal+millisecond*byMany); break;
	        case "s": newDate=new Date(dVal+second*byMany); break;
	        case "mi": newDate=new Date(dVal+minute*byMany); break;
	        case "h": newDate=new Date(dVal+hour*byMany); break;
	        case "d": newDate=new Date(dVal+day*byMany); break;
	        case "y": newDate=new Date(dVal+year*byMany); break;
        }
	    return newDate;
    }
    // custom javascript error handler. To use uncomment the line below
    function jserrorhandler(description,pagename,lineno)
    {
        alert
        (
            'An Error has occurred on the page \n'
            +'\n Description: \t'+description
            +'\n Page Name:      \t'+pagename
            +'\n At Line :       \t'+lineno
        )
        return true
    }
    //window.onerror=jserrorhandler;
function checkForValidDate(){
var ddlVMonth = document.getElementById("_ctl0_DropDownListMaanden");
var ddlVDay = document.getElementById("_ctl0_DropDownListDagen");
var ddlVYear = document.getElementById("_ctl0_DropDownListJaren");

if (!isDate(ddlVDay.value + '/' + ddlVMonth.value + '/' + ddlVYear.value))
{ return(false); }

return(true);
}

    
