/*
 * Holiday UI IndexPage index.js 1.0
 *
 * Copyright (c) 2009 Cox & Kings India Ltd
 *
 * Depends:
 *	$-ui-datepicker.js
 *	$.rvs.js
*/

/*
 * "fromDate" is the field name for the departure date input
 * Set the date picker option for the departure date
 * The starting date should be the current date
 * Maximum date range has been set to 5 months from the current date
 * The select option is set on the calendar icon
 
*/




/*
 * "destinationId" is the field name for calling the ajax function
 * Once the destinationId is selected and passed on to citySuccess.php
 * "citySelect" div is popluated by the city data
  
*/

function go(clickto) {
window.location.href = clickto;
}


  $(document).ready(function() {
		$('select#destinationId').change(function() {
		var destinationId = this.value;
		if (destinationId != '')
		{
		$('#indicator').show();
		$.ajax({
			url: "holidays/rooming?destinationId=" + this.value,
      dataType: "text/html",
      success: (function(data) {
				$('#roomingDefault').hide();
				$('#rooming').html(data);
				$('#rooming1').show();
//				$('#childvalue1').hide();
//				$('#childagevalue11').hide();
//				$('#childagevalue12').hide();
//				$('#rooming2').hide();
//				$('#childvalue2').hide();
//				$('#childagevalue21').hide();
//				$('#childagevalue22').hide();
      })
		});
		$.ajax({
			url: "holidays/city?destinationId=" + this.value,
      dataType: "text/html",
      success: (function(data) {
				$('select#cityName').hide();
				$('#indicator').hide();
				$('#citySelect').html(data);
	      var destinationCutOff = $('#cutOffDate').val();
		    $('#fromDate').datepicker({dateFormat: 'dd/mm/yy', altFormat: 'yy-mm-dd', minDate: destinationCutOff, maxDate: '+5M', showOn: 'button', buttonImage: '../../images/home/calendar.gif', buttonImageOnly: true});
      })
		});
   }
	});
	   
}); 

function showage(val,cnt)
{     

      if(parseInt(val)>0 )
      {
	      
	      for(var i=1;i<=parseInt(val);i++)
	      {
		      document.getElementById('childAge'+cnt+i).style.visibility='visible';
		      document.getElementById('childAge'+cnt+i).style.display = '';	
	      }
	  }
	  else
	  {
	  }

	  for(var i=parseInt(val)+1;i<=2;i++)
	 {
		      document.getElementById('childAge'+cnt+i).style.visibility='hidden';
		      document.getElementById('childAge'+cnt+i).style.display = "none";	
	 }

}

function showhidechild(thisVal,cnt)
{

    if(thisVal=='SGL1')
     {
      	document.getElementById("adult"+cnt).value = 1;
      	document.getElementById("adult"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='hidden';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"2").style.display='none';
      	document.getElementById("extraBed"+cnt).style.visibility='hidden';
      	document.getElementById("extraBed"+cnt).style.display='none';
      	document.getElementById("extraBedValue"+cnt).style.visibility='hidden';
      	document.getElementById("extraBedValue"+cnt).style.display='none';
     }

    if(thisVal=='DBL2')
     {
      	document.getElementById("adult"+cnt).value = 2;
      	document.getElementById("adult"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='hidden';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"2").style.display='none';
      	document.getElementById("extraBed"+cnt).style.visibility='hidden';
      	document.getElementById("extraBed"+cnt).style.display='none';
      	document.getElementById("extraBedValue"+cnt).style.visibility='hidden';
      	document.getElementById("extraBedValue"+cnt).style.display='none';
     }
     
    if(thisVal=='DBC2')
     {
      	document.getElementById("adult"+cnt).value = 2;
      	document.getElementById("adult"+cnt).selected = true;
        document.getElementById("child"+cnt).value = 1;
        document.getElementById("child"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='visible';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='visible';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"2").style.display='none';
      	document.getElementById("childAge"+cnt+"2").value = 0;
      	document.getElementById("extraBed"+cnt).style.visibility='visible';
      	document.getElementById("extraBed"+cnt).style.display='';
      	document.getElementById("extraBedValue"+cnt).style.visibility='visible';
      	document.getElementById("extraBedValue"+cnt).style.display='';

     }
     
    if(thisVal=='DBCX')
     {
      	document.getElementById("adult"+cnt).value = 2;
      	document.getElementById("adult"+cnt).selected = true;
        document.getElementById("child"+cnt).value = 2;
        document.getElementById("child"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='visible';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='visible';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='visible';
      	document.getElementById("childagevalue"+cnt+"2").style.display='';
      	document.getElementById("extraBed"+cnt).style.visibility='hidden';
      	document.getElementById("extraBed"+cnt).style.display='none';
      	document.getElementById("extraBedValue"+cnt).style.visibility='hidden';
      	document.getElementById("extraBedValue"+cnt).style.display='none';

     }
     
    if(thisVal=='TRPX')
     {
      	document.getElementById("adult"+cnt).value = 3;
      	document.getElementById("adult"+cnt).selected = true;
        document.getElementById("child"+cnt).value = 1;
        document.getElementById("child"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='visible';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='visible';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"2").style.display='none';
      	document.getElementById("childAge"+cnt+"2").value = 0;
      	document.getElementById("extraBed"+cnt).style.visibility='hidden';
      	document.getElementById("extraBed"+cnt).style.display='none';
      	document.getElementById("extraBedValue"+cnt).style.visibility='hidden';
      	document.getElementById("extraBedValue"+cnt).style.display='none';

     }
     if(thisVal=='TRP3')
     {	 
      	document.getElementById("adult"+cnt).value = 3;
      	document.getElementById("adult"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='hidden';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"2").style.display='none';
      	document.getElementById("extraBed"+cnt).style.visibility='hidden';
      	document.getElementById("extraBed"+cnt).style.display='none';
      	document.getElementById("extraBedValue"+cnt).style.visibility='hidden';
      	document.getElementById("extraBedValue"+cnt).style.display='none';
     }
     if(thisVal=='QUD4')
     {	 
      	document.getElementById("adult"+cnt).value = 4;
      	document.getElementById("adult"+cnt).selected = true;
      	document.getElementById("childvalue"+cnt).style.visibility='hidden';
      	document.getElementById("childvalue"+cnt).style.display='';
      	document.getElementById("childagevalue"+cnt+"1").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"1").style.display='';
      	document.getElementById("childagevalue"+cnt+"2").style.visibility='hidden';
      	document.getElementById("childagevalue"+cnt+"2").style.display='none';
      	document.getElementById("extraBed"+cnt).style.visibility='hidden';
      	document.getElementById("extraBed"+cnt).style.display='none';
      	document.getElementById("extraBedValue"+cnt).style.visibility='hidden';
      	document.getElementById("extraBedValue"+cnt).style.display='none';
     }
}

function showhide(obj,s) 
{
  var count = parseInt(s,10);   
   
  if(count == 1)
  {
    document.getElementById('rooming1').style.visibility='visible';
    document.getElementById('rooming1').style.display = '';	
    document.getElementById('rooming2').style.visibility='hidden';
    document.getElementById('rooming2').style.display = 'none';
    
  }     
  else if(count == 2)
  {
    document.getElementById('rooming2').style.visibility='visible';
    document.getElementById('rooming2').style.display = '';	
    document.getElementById('rooming1').style.visibility='visible';
    document.getElementById('rooming1').style.display = '';
  } 
  else if(count == 3)
  {  
    document.getElementById('rooming3').style.visibility='visible';
    document.getElementById('rooming3').style.display = '';	
    document.getElementById('rooming1').style.visibility='visible';
    document.getElementById('rooming1').style.display = '';
    document.getElementById('rooming2').style.visibility='visible';
    document.getElementById('rooming2').style.display = '';
  
  } 
  else
  {
    document.getElementById('rooming3').style.visibility='hidden';
    document.getElementById('rooming3').style.display = 'none';	
    document.getElementById('rooming1').style.visibility='hidden';
    document.getElementById('rooming1').style.display = 'none';
    document.getElementById('rooming2').style.visibility='hidden';
    document.getElementById('rooming2').style.display = 'none';
  }

}


/*
 * Validation rules for holiday search parameters
*/
					var rules = [];
          rules.push("required,destinationId,Select holiday destination.");
          rules.push("required,checkLocation,Select one or more cities.");
          rules.push("required,fromDate,Select start date.");
					rules.push("if:roomType1=SGL1,range=1-1,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=SGL1,range=1-1,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=TWN2,range=2-2,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=TWN2,range=2-2,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=DBL2,range=2-2,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=DBL2,range=2-2,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=TRP3,range=3-3,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=TRP3,range=3-3,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=QUD4,range=4-4,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=QUD4,range=4-4,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=DBC2,range=2-2,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=DBC2,range=2-2,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=DBC2,range=1-1,child1, Select proper child passengers for room # 1");
					rules.push("if:roomType2=DBC2,range=1-1,child2, Select proper child passengers for room # 2");
					rules.push("if:roomType1=TRPX,range=3-3,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=TRPX,range=3-3,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=TRPX,range=1-1,child1, Select proper child passengers for room # 1");
					rules.push("if:roomType2=TRPX,range=1-1,child2, Select proper child passengers for room # 2");
					rules.push("if:roomType1=DBCX,range=2-2,adult1, Select proper adult passengers for room # 1");
					rules.push("if:roomType2=DBCX,range=2-2,adult2, Select proper adult passengers for room # 2");
					rules.push("if:roomType1=DBCX,range=2-2,child1, Select proper child passengers for room # 1");
					rules.push("if:roomType2=DBCX,range=2-2,child2, Select proper child passengers for room # 2");

	$(document).ready(function() {
		$("#holidaySearch").RSV({
//		onCompleteHandler: myOnComplete,
			rules: rules,
			displayType: "alert-one"

		});
	});


