last_tab = 'tab01';

function show(layerName) {
document.getElementById(layerName).style.display = '';
}

function hide(layerName) {
document.getElementById(layerName).style.display = 'none';
}

function show_next(tab_name) {
document.getElementById(last_tab).className = 'tab';
var curr = document.getElementById(tab_name);
curr.className='tab_hover';
hide(last_tab+'_data');
show(tab_name+'_data');
last_tab=tab_name;
}
function showForm(blockid){
var id='#'+blockid;
$(id).slideDown("slow").toggle();
//$(id).slideToggle("slow");;
}
function showRoomType(elem){

var labelArray=new Array();
labelArray[1]='First';
labelArray[2]='Second';
labelArray[3]='Third';
labelArray[4]='Fourth';
roomcount=elem.value;
if(roomcount==1){
labelArray[1]='';

}
var resp1='';
var resp2='';
var resp=document.getElementById('roomtypeselect').innerHTML;
for (i=1;i<=roomcount;i++){
var label=labelArray[i];
resp1=resp.replace(/LABEL/, label);

resp1=resp2+resp1;
resp2=resp1
}
 //alert(resp2);  
document.getElementById('roomType').style.display='block';
document.getElementById('roomType').innerHTML=resp2;  
}
function showChild(elem){

var labelArray=new Array();
labelArray[1]='First';
labelArray[2]='Second';
labelArray[3]='Third';
labelArray[4]='Fourth';
var childcount=elem.value;
/*if(childcount==0) {

} */
if(childcount==1){
labelArray[1]='';

}
var resp1='';
var resp2='';
var resp=document.getElementById('childageselect').innerHTML;
for (i=1;i<=childcount;i++){
var label=labelArray[i];
resp1=resp.replace(/LABEL/, label);

resp1=resp2+resp1;
resp2=resp1
}
// alert(resp2);  
document.getElementById('childAge').style.display='block';
document.getElementById('childAge').innerHTML=resp2;  
}
function showhideRooms(elem,idd){
   var max_element=6;
   var id='#'+idd;
   val=elem.value;
   for(i=1;i<max_element;i++){
	   id1=id+i;
	   if(val>=i){
	   //alert(id1+'s')
	   $(id1).show();
	   }
	   else{
	   //alert(id1+'h')
		$(id1).hide();
		}
	   }
   }

function showhideNew(elem,idd){
   var max_element=3;
   //var id='#mydiv';
   var id='#'+idd;
   var id2=id+'label';
   val=elem.value;
   if(val==0){
   $(id2).css("visibility","hidden");
   }
   else{
   $(id2).css("visibility","visible");
   }
   for(i=1;i<max_element;i++){
   id1=id+i;
   if(val>=i){
   //alert(id1+'s') 
	$(id1).css("visibility","visible");
	//$(id1).show();
	}
	else{
	//alert(id1+'h')
	$(id1).css("visibility","hidden");
	//$(id1).hide();
	}
   }
}
 
 function checkAvailibility(){
	
	   url=RIRTL_URL+'tours/check-availibility.php';
       if(document.form1.DepartureDate.value==''){
       	alert('Please select departure date');
       	return false;
       }
	   id='#form1';
	   responceid='#resp';
	   var dataString =$(id).serialize();
	   var loading="#loading";
	   var responce='resp';
	   var responceId='#resp';
	   $.ajax({
		   type: "POST",
		   url:url,
		   data: dataString,
		   success: function(r)
		   {

				r=trim(r);

				if(r=='Y')
				{
					///$(responceid).html('Sorry ! The room plan you are looking for is not available.<br>Please select different room plan');  
					$(id).submit();
				}
				else if(r=='EX')
				{
					$(responceid).html('Total number of passengers can not be accommodate in single room.Please select additional rooms .');	
				}
				else if(r=='NOPAX')
				{
					$(responceid).html('Please Select at least one passenger .');	
				}
				else if(r=='CH')
				{
					//Change room automaticaly to double
					if(checkWarning())
					{
						alert("Since you are single traveler your room has been upgraded from Twin to Double");
					}
					$(id).submit();
				}
				else
				{					
					//status='The plan is not available.<br>Please select different plan';
					//alert('The plan is not available.<br>Please select different plan');
					$(responceid).html('Sorry ! The room plan you are looking for is not available.<br>Please select different room plan or <br>Please fill up our <a href="../bookings/index.php?Page=inquiry">Enquiry form</a> . We will contact you shortly regarding your enquiry. We value your patronage. Do visit us again at www.rirtl.com .');
					//$(responceid).html(r);
				}
		   }
	 });
	 
	 return false; 
	
 } 
 function checkWarning(){
 	var war='N';
 	frm=document.form1;
 	
 	var rooms=frm.rooms.value;
 	rooms=parseInt(rooms);
 	//alert(document.form1.cabinroom1.value)
 	if(frm.cabinroom1.value){
 		selRoom1=frm.cabinroom1.value;
 		if(selRoom1.indexOf('TWN')!=-1){
 			return true;
 		}
 	}
 if(rooms >1){
 	if(frm.cabinroom2){
 		selRoom2=frm.cabinroom2.value;
 		if(selRoom2.indexOf('TWN')!=-1){
 			return true;
 		}
 	}
 }
 return false;
}
function postformAjax(formId,reqURL,loadingid,responceid,type,loadMessage){
	id='#'+formId;
	responceid='#'+responceid;
	var dataString =$(id).serialize();
	var loading="#"+loadingid;
	var responce=responceid;
	var responceId='#'.responceid;
	
	$.ajax({
	  type: "POST",
	  url:reqURL,
	  data: dataString,
	  success: function(r) {
	  
		$(responceid).html(r); 
		status=r;
		 alert(status);
		
	  }
	 });
	  }
function handleAjax(reqURL,loadingid,responceid,loadMessage){
	var loading="#"+loadingid;
	var responce=responceid;
	var responceId='#'.responceid;
	var loadd=loadMessage+'<img src="images/ajax-loader.gif" border="0">';
	document.getElementById(responce).innerHTML=loadd;
	jQuery.ajax({
		type:"GET",
		url:reqURL,
		cache: false,
		error:function(){
		alert('Server not responnding ')
		},
		start:function(){
		// alert('llll');
		},
		success:function(r){
			//alert(r);   
			document.getElementById(responce).innerHTML=r;
			document.getElementById(responce).style.display='block';
			
		}
	})
}    
function getCabinRoomDropDown(cabin,tourId,deptDate,resp,loading){
		  var cabinId=cabin.value;
		  //var cabinId=document.form1.CabinID[room].value;
			reqURL='../process_ajax.php?fun=getCabinRoom&tourId='+tourId+'&cabinId='+cabinId+'&deptDate='+deptDate+'&req=ajax';
			handleAjax(reqURL,'loading',resp,'l')
			

} 
function openwindow(url,width,height){
width=1000;
height=800;	
settings="location=0,status=0,resizable=1,scrollbars=1,width="+width+",height="+height;
	mywindow = window.open (url,
  "mywindow",settings);
  mywindow.moveTo(0,0);
  return false;
}
function showHide(id){
 id='#'+id;
 $(id).show();


}
function showHideToggle(id){
 id='#'+id;
 $(id).toggle();


}



function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}




function redirctTour_New(){
	
	//var url='/tours/index.php?link=tour&TourID='+id+'&TourDate='+TourDate+'';
	//alert("TourMonth :-> " + document.FrmTours.TourMonth.value);
	//alert("TourYear :-> " + document.FrmTours.TourYear.value);
	//alert("name :-> " + document.FrmTours.name.value);
	//alert("login :-> " + document.FrmTours.login.value);
	//return false;
	document.FrmTours.action="/tours/index.php";
	document.FrmTours.submit();
}
function redirctTour(){
	var id=document.getElementById('tour').value;
	var url='/tours/index.php?link=tour&TourID='+id+'';
   window.location=url;    
}
function loadBookingForm(respId,TourId,hideElementsId){
	url='tours/book-form.phtml?TourID='+TourId;
	
	respId='#'+respId;
	
	$(respId).load(url);
	$(respId).slideDown("fast");
	b=new String();
	b=hideElementsId;
	var h=new Array();
	h=b.split(',');
	//alert(h)
	$.each(h, function() {
		
      //alert($("#" + this).html(''));
     $("#" + this).html('');
     $("#" + this).hide();
      
    });

}

function getPermission(ob){
	groupName=ob.value;
	url='ajax.php?func=getPermission&group='+groupName;
	respId='#DF';
	
	$(respId).load(url);
	//$(respId).load(url);
}
function getTours(ob){
	tourId=ob.value;
	//alert(tourId);
	reqURL='ajax.php?func=getTour&tourId='+tourId;	
	//alert(reqURL);	
	$.ajax({
	type: "GET",
	url:reqURL,
    dataType: "json",
    success: function(r) {
    	//alert(reqURL);
    	dept=r.Departure;
    	cabin=r.Cabin;
    	//alert(dept);
    	$('#dept').html(dept) ;
    	$('#cabin').html(cabin) ;
    }
	});}
	
	function getTours1(ob){
	tourId=ob.value;
	//alert(tourId);
	reqURL='../admin/ajax.php?func=getTour&tourId='+tourId;		
	$.ajax({
	type: "GET",
	url:reqURL,
    dataType: "json",
    success: function(r) {
    	//alert(reqURL);
    	dept=r.Departure;
    	cabin=r.Cabin;
    	//alert(dept);
    	$('#dept').html(dept) ;
    	$('#cabin').html(cabin) ;
    }
	});}


function createOption(dataA){
	var objSelect=document.form1.celepax;
	objSelect.options.length=0;
	for(i=0;i<dataA.length;i++){
		var objOption = document.createElement("option");
		objOption.value =dataA[i][0];
		objOption.text = dataA[i][1];
		if(document.all && !window.opera) 
		{objSelect.add(objOption);}
		else
		{objSelect.add(objOption, null);};
	}
}
function populateSel(){
	var pop=new Array();
	adults=document.form1['totaladults'].value;
	child=document.form1['totalchilds'].value;
	var a=document.form1['Pax[FirstName]'].value;
	if(a!=''){
		var b=document.form1['Pax[LastName]'].value;
		var c=a+' '+b;
		pop[0]=new Array(c,c);
	}
	var j=1;
	for(i=1;i<adults;i++){
	var label='Pax'+i;
	var labeF=label+'[FirstName]';
	var labeL=label+'[LastName]';
	var a=document.form1[labeF].value;
    if(a!=''){
	var b=document.form1[labeL].value;
    var c=a+' '+b;
    pop[j]=new Array(c,c);
    j++;
    }
	}
for(i=1;i<=child;i++){
	var label='Child'+i;
	var labeF=label+'[FirstName]';
	var labeL=label+'[LastName]';
	var a=document.form1[labeF].value;
    if(a!=''){
	var b=document.form1[labeL].value;
    var c=a+' '+b;
    pop[j]=new Array(c,c);
    j++;
    }
}
////alert(pop);
if(pop.length>0){
createOption(pop);
}

}



/* Function for the show/hide FAM DETAILS dropdown during the  * 
*  Created by : Amit Kr. Sharma								   *
*  Created date: June 02, 2010    				               *
*  Used in File: /bookings/reservation-form.phtml              *
*  
*/

 function fam_group($val){
 	if($val=='FAM'){
 		$("#famDetail").show();	
 	}else{
 		$("#famDetail").hide();	
 		$("#txtFamDetails").val("");	
 	}
 	
 }



/*code for drop down menu*/
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

jQuery(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;
/*code for drop down menu end*/

/*code for Photo Gallery Start*/
function MM_Refresh(){
window.location.reload()
}
/*code for Photo Gallery Start*/


$(document).ready(function() {
	// $('#details tr:odd').css("background", "#DBDBDB");
	$("#famDetail").hide();
	$('#details tr').bind('click',function(event){
		
		$('#details tr').each(function(){
		    if($(this).hasClass('row_highlight')){
			$(this).removeClass('row_highlight')
		}
		
	});
		$(this).addClass('row_highlight');
	});
   
          // put all your jQuery goodness in here.
});