// JavaScript Document
//key1 is  0(zero) if from is not entered

// explorer and search mixed.................

function getPlaceSearch(placename){
	 var journey_form=0;
 	 if($id('journey_form'))
		journey_form=1;
	 searchPlace('place',journey_form, placename);
}

function expPlaceExpand(placeId, type, gmc1, gmc2, gmz, elementname, elementID, placename ){
	setTitle("<span style='text-transform:capitalize;'>"+unescape(type)+'</span>: '+unescape(elementname));
	storeInHistory();
	
	aj_exp(placeId);
	if(placename)
	{
		try{ showByPoint(gmc1, gmc2, gmz, placename)}catch(e){};
	}
	else
	{
		try{ showByPoint(gmc1, gmc2, gmz, elementname); }
		catch(e){};
	}
	switch(type)
	{
		case 'place': changeContent(placeId,type); break;
		
		case 'hotel': changeContent(elementID,type); break;
	}
}

function view_hotel(hotel_key,hotel_key1,place_id)
{
	$.post(ROOT_PATH+"aj_request.php?aj=places.search1_pagination&type=hotel&hotel_key="+hotel_key+"&hotel_key1="+hotel_key1+"&placeId="+place_id+"&search_id=1",'',hotel_search);
}

function show_this_hotel(hotel_id)
{
	window.location = ROOT_PATH+"index.php?id="+hotel_id+"&type=hotel";
}

function expand_select(topic)
{
	var oSelect = $id('select_box');
 
	$id('selected_heading').innerHTML = stripslashes(topic);
	$id('selected_description').innerHTML = stripslashes($id(topic+'_div').innerHTML);
 

	if(topic == 'Hotel Description')
	{
		
		$id('pic1').innerHTML = $id('hotel_pic1').innerHTML;
		$id('pic2').innerHTML = $id('hotel_pic2').innerHTML;
		return;
	}
	
	if($id(topic+'pic1'))
	$id('pic1').innerHTML = $id(topic+'pic1').innerHTML ;
	
	if($id(topic+'pic2'))
	$id('pic2').innerHTML = $id(topic+'pic2').innerHTML ;
 

  
}

function htlSrchPg(url){
	setLocation('getPage',url,'','Hotel Search');
}

function showByPoint(lat,lng,z, elementname, type){ 
	 window.frames.maps_frame.showByPoint(lat,lng,z, elementname, type);
}

function showJourney(placeId, journeyId, from_gmc1, from_gmc2, to_gmc1, to_gmc2, journey_title)
{
	alert("showJourney");
	var title="Journey: "+unescape(journey_title);
	setTitle("<span  >Journey</span>: "+unescape(journey_title));
	storeInHistory();
	
	window.frames.maps_frame.map.clearOverlays(); 
	
	aj_exp(placeId);
	changeContent(journeyId,'journey');
	window.frames.maps_frame.drawJourneyLine(unescape(from_gmc1), unescape(from_gmc2), unescape(to_gmc1), unescape(to_gmc2), unescape(journey_title));
	
}

function sorthotel_rating(hotel_key,placeId)
{
	var key2;
	
	if(!placeId || placeId == '')
		key2='%';
	else
		key2=placeId;
	$.post(ROOT_PATH+'aj_request.php?aj=places.search1_pagination&type=hotel&hotel_key='+escape(hotel_key)+'&placeId='+escape(key2)+'&orderby=Hotel_rating&search_id=1&order=desc','',hotel_search); 	
}

function sorthotel_location(hotel_key,placeId)
{
	var key2;
	
	if(!placeId || placeId == '')
		key2='%';
	else
		key2=placeId;
	
	$.post(ROOT_PATH+'aj_request.php?aj=places.search1_pagination&type=hotel&hotel_key='+escape(hotel_key)+'&placeId='+escape(key2)+'&orderby=Hotel_location&search_id=1&order=asc','',hotel_search); 	
}

function change_img(id1)
{
	if($id('div'+id1).style.display == '')
	{
		$id('div'+id1).style.display = 'none';
		$id(id1+'2').style.display = '';
		var x=document.getElementsByName('img'+id1);
		x[0].src = ROOT_PATH+'images/arrow.jpg';
		$id('aref'+id1).className = 'place-explorer';
	}
	else
	{
		$id('div'+id1).style.display = '';
		$id(id1+'2').style.display = 'none';
		var x=document.getElementsByName('img'+id1);
		x[0].src = ROOT_PATH+'images/arrow2.jpg';
		$id('aref'+id1).className = 'parent-place-explorer';
	}
}

function aj_exp(placeId)
{
	
	try{
		var len=$id('div'+placeId).childNodes.length;	
		if(len==0)
		{
			$.get(ROOT_PATH+'aj_request.php?aj=places.aj_exp_search&pid='+placeId,'', function(resp){$('#explorer').html(resp); bolding(resp);});
		}
		else{
			change_img(placeId);
			$id('aref'+placeId).className = 'selected-place-explorer';
			$id('div'+placeId).innerHTML = '';
		}
	}catch(exc){//alert("3")
		$.get(ROOT_PATH+'aj_request.php?aj=places.aj_exp_search&pid='+placeId,'', function(resp){$('#explorer').html(resp); bolding(resp);});
	}
	
}

function bolding(res)
{
/*	try{
		var lst_bldelement = $id('last_bldelement');
		$id('aref'+lst_bldelement.value).className = '';
		lst_bldelement.parentNode.removeChild(lst_bldelement);
		}catch(err)
			{
			}*/

	var bldId = $id('boldelement').value;
	$id('aref'+bldId).className = 'selected-place-explorer';
}

function indexChanged(title_no,titlecount)
{
	try{
	
	for (var i=1; i <= titlecount ; i++)
	{
		$id('title_'+i).style.display = 'none';
	}
	if($id('title_'+title_no))
		$id('title_'+title_no).style.display = '';
	}catch(exc){}
}
function edit_coment()
{
	$id('view_coment').style.display='none';
	$id('edit_coment').style.display='';
}

var notes;
function update_coment(placeId)
{
	notes=$id('txt_coment').value;
	if(notes=='')
		alert('Enter any Text u want to save!!')
	else
		$.post(ROOT_PATH+'aj_request.php?aj=places.update_notes', 'placeId='+placeId+'&notes='+escape(notes), add_coment_resp);
}

function add_coment_resp(resp)
{
	if(resp=='true')	
	{
		
		$id('personal_notes').innerHTML = 'View Personal Notes';
		$id('coment_content').innerHTML=notes;
		$id('view_coment').style.display='';
		$id('edit_coment').style.display='none';	
	}
	else
	{
		$id('coment_response').innerHTML='';
		$id('txt_coment').innerHTML=$id('coment_content').innerHTML;
	}
	
}

function edit_journey_coment()
{
	$id('view_coment').style.display='none';
	$id('edit_coment').style.display='';
}

function update_journey_coment(journey_id)
{
	var journey_notes='';
	journey_notes=$id('txt_coment').value;
	if(journey_notes=='')
		alert('Enter any Text u want to save!!')
	else
		$.post(ROOT_PATH+'aj_request.php?aj=places.update_journey_notes', '&journey_id='+journey_id+'&notes='+escape(journey_notes),function(resp){ add_journey_coment_resp(resp, journey_notes, journey_id)} );
}

function add_journey_coment_resp(resp, journey_notes, journey_id)
{
	if(resp=='true')	
	{
		
		$id('personal_notes').innerHTML = 'View Personal Notes';
		$id('personal_notes').onclick=function(){ showJourneyComment(journey_id, journey_notes)}
		$id('coment_content').innerHTML= journey_notes;
		$id('view_coment').style.display='';
		$id('edit_coment').style.display='none';	
	}
	else
	{
		$id('coment_response').innerHTML='';
		$id('txt_coment').innerHTML=$id('coment_content').innerHTML;
	}
	
}

function edit_hotel_coment()
{
	$id('view_coment').style.display='none';
	$id('edit_coment').style.display='';
}

var hotel_notes;
function update_hotel_coment(hotel_id)
{
	hotel_notes=$id('txt_coment').value;
	if(hotel_notes=='')
		alert('Enter any Text u want to save!!')
	else
		$.post(ROOT_PATH+'aj_request.php?aj=places.update_hotel_notes', 'hotel_id='+hotel_id+'&hotel_notes='+escape(hotel_notes), add_hotel_coment_resp);
}

function add_hotel_coment_resp(resp)
{
	if(resp=='true')	
	{
		
		$id('personal_hotel_notes').innerHTML = 'View Personal Notes';
		$id('coment_content').innerHTML=hotel_notes;
		$id('view_coment').style.display='';
		$id('edit_coment').style.display='none';	
	}
	else
	{
		$id('coment_response').innerHTML='';
		$id('txt_coment').innerHTML=$id('coment_content').innerHTML;
	}
	
}

function fun(arg)
{
  $id('div1').style.display='none';
  $id('div2').style.display='none';
  $id('div3').style.display='none';
   switch(arg)
   {
	case '1' : $id('div1').style.display=''; break;
	case '2' : $id('div2').style.display=''; break;
	case '3' : $id('div3').style.display=''; break;
	}
}	

var exp_name;
function exp_fun(elementId )
{ 
	exp_name=name;
	$.get(ROOT_PATH+'aj_request.php?aj=places.aj_explorer&id='+elementId,'', function(resp){  $('#div'+elementId).html(resp); bolding(resp);} );
		
}

function changeContent(elementId, type)
{	
	$id('element_type').value=type;
	$id('element_page').value=elementId;
	
	var journey_form=0;
	if($id('journey_form'))
		journey_form=1;	
	if(type=='place')
		$.get(ROOT_PATH+"aj_request.php?aj=places.aj_search&journey_form="+journey_form+"&pid="+elementId,'',function(resp){  $('#main_div').html(resp); indexChanged(resp); });
	 else
 		$.get(ROOT_PATH+'aj_request.php?aj=places.aj_search_contents&pid='+elementId+"&journey_form="+journey_form+'&type='+escape(type),'',function(resp){ $('#main_div').html(resp); indexChanged(resp); });
 
   }

function form_submited()
{
	var ele='';
	var x=document.getElementsByName('type');
	for(var i=0;i<x.length;i++) {
		if(x[i].checked)
	 		ele=x[i].value;
	}
	switch(ele)
	{
		case 'place':if(document.search_form.place_key.value=='Place Name'){
						alert('Enter any place Name'); 
						return false; 
					 }
					 break;
		
		case 'hotel':if((document.search_form.hotel_key.value=='Enter Name')&&(document.search_form.hotel_key1.value=='Enter Place') ) {
						alert('Enter any of them'); 
						return false; 
					 }
					 break;
		
		case 'journey' :if((document.search_form.journey_key.value=='Destination')&&(document.search_form.journey_key1.value=='From') ) {
							alert('Enter any of them'); 
							return false; 
						}
						break;
	}
		
	if($id('ajax_form').value=='1')
	{
		var place_key=document.search_form.place_key.value;
		var hotel_key=document.search_form.hotel_key.value;
		var hotel_key1=document.search_form.hotel_key1.value;
		var journey_key=document.search_form.journey_key.value;
		var journey_key1=document.search_form.journey_key1.value;

		if(place_key=='Place Name')
			place_key='';
		
		if(hotel_key=='Enter Name')
			hotel_key='';
		
		if(hotel_key1=='Enter Place')
			hotel_key1='';
		
		if(journey_key=='Destination')
			journey_key='';
		
		if(journey_key1=='From')
			journey_key1='';
		
		var journey_form=0;
		
		if($id('journey_form'))
			journey_form=1;
	
		switch(ele)
		{
			case 'place':{
					if(journey_form=='1')
						searchPlace(ele, journey_form, place_key);
					else{				
						//setLocation("#searchPlace&1="+escape(ele)+"&2="+escape(journey_form)+"&3="+escape(place_key));
						setLocation('searchPlace',escape(ele),escape(journey_form),escape(place_key));
					}
					break;
				}
			case 'hotel':{	
					if(hotel_key1=='') {
						if(journey_form=='1')
							searchHotel(ele, journey_form, hotel_key);
						else{
							//setLocation("#searchHotel&1="+escape(ele)+"&2="+escape(journey_form)+"&3="+escape(hotel_key));
							setLocation('searchHotel',escape(ele),escape(journey_form),escape(hotel_key));
						}
					}
					else {
						if(journey_form=='1')
							searchHotelInPlace(ele, journey_form, hotel_key, hotel_key1);
						else{
							//setLocation("#searchHotelInPlace&1="+escape(ele)+"&2="+escape(journey_form)+"&3="+escape(hotel_key)+"&4="+escape(hotel_key1));
							setLocation('searchHotelInPlace',escape(ele),escape(journey_form),escape(hotel_key),escape(hotel_key1));
						}
					}
					break;
				}
			
			case 'journey':
				{
					if(journey_key==journey_key1)
					{
						alert(' Please Choose Different Places for the Start and End of Your Journey');
						return;
					}
					if(journey_form=='1')
						searchJourney(ele, journey_form, journey_key, journey_key1);
					else {
						//setLocation("#searchJourney&1="+escape(ele)+"&2="+escape(journey_form)+"&3="+escape(journey_key)+"&4="+escape(journey_key1));
						setLocation('searchJourney',escape(ele),escape(journey_form),escape(journey_key),escape(journey_key1));
					}
					break;
				}
			}
			
		if($id('journey_form'))
		{
			if($id('div_info').style.position=='relative')
				show_info_div();
		}
	}
	return false;
}

function searchPlace(type, journey_form, place_key)
{
	var title='';
	if(place_key!='')
		title+=' \''+place_key+'\'';
		

	setTitle("<span  >Place Search:</span>"+title);
	storeInHistory();
	
	$.post(ROOT_PATH+'aj_request.php?aj=places.search_pagination&type='+type+"&journey_form="+journey_form+"&place_key="+Url.encode(place_key),'',function(resp){$('#main_div').html(resp); search_resp(resp, place_key); } );
}

function searchHotel(ele, journey_form, hotel_key)
{
	var title= '';
	
	if(hotel_key!='')
		title+=' \''+hotel_key+'\'';
		
	setTitle("<span  >Hotel Search:</span>"+title);
	storeInHistory();
	$.post(ROOT_PATH+'aj_request.php?aj=places.search_pagination&type='+ele+"&hotel_key="+Url.encode(hotel_key) ,'',hotel_search);
}

function searchHotelInPlace(ele, journey_form, hotel_key, hotel_key1)
{
	var title='';
	if(hotel_key!='')
		title+=' \''+hotel_key+'\'';
	else
		title+=' \'Hotels \'';

	if(hotel_key1!='')
		title+=' in \''+hotel_key1+'\'';
	
	setTitle("<span  >Hotel Search:</span>"+title);
	storeInHistory();	
	
	$.post(ROOT_PATH+'aj_request.php?aj=places.search1_pagination&type='+ele+"&journey_form="+journey_form+"&hotel_key="+Url.encode(hotel_key)+"&hotel_key1="+Url.encode(hotel_key1),'',hotel_search);
}

function searchJourney(ele, journey_form, journey_key, journey_key1)
{
	var title= '';
	if(journey_key!='')
		title+='to \''+stripslashes(journey_key)+'\'';

	if(journey_key1!='')
		title+=' From \''+stripslashes(journey_key1)+'\'';
		
	setTitle("<span  >Journey Search:</span> "+title);
	storeInHistory();

	$.post(ROOT_PATH+'aj_request.php?aj=places.search1_pagination&type='+ele+"&journey_form="+journey_form+"&journey_key="+Url.encode(journey_key)+"&journey_key1="+Url.encode(journey_key1),'',journey_search_resp);
}

var search_content;
// key1 is  0(zero) if from place is not entered
var journey_content;
var per_page_journey;
var page_anchors_journey_from;
var page_anchors_journey_to;
var count_journey_from;
var count_journey_to;
var total_pages_journey_from;
var total_pages_journey_to;

function journey_search_resp(resp)
{
			
		var res;
		try{
			 eval(" res = "+resp);
		}catch(exc){ }
		if(res)
		{ 
			journey_content=res;
			var from='';
			var to='';
			
			if(res['places1'])
				 from=res['places1'];
			if(res['places2'])
				to= res['places2'];
		
			count_journey_from = from.length;
			per_page_journey= 10;
			
			total_pages_journey_from = Math.ceil(count_journey_from/per_page_journey);//alert('kk'+total_pages_journey_from)
			
			count_journey_to = to.length;
			per_page_journey= 10;
			
			total_pages_journey_to = Math.ceil(count_journey_to/per_page_journey);
			
			page_anchors_journey_from='';	
			page_anchors_journey_to='';	
			
			for(var page_no=1; page_no<=total_pages_journey_from;page_no++)
			{
				if(page_no == 1)
				page_anchors_journey_from+='<span><a class="heading_anchor" style="font-weight:bold" id="from_anchor_'+page_no+'" class="abc" href="javascript:void(0)" onclick="javascript:journey_search_limit('+page_no+',0,\'from_column\')">'+page_no+'</a></span>'+'&nbsp;';
				
				else
				page_anchors_journey_from+='<span><a class="heading_anchor" id="from_anchor_'+page_no+'" class="abc" href="javascript:void(0)" onclick="javascript:journey_search_limit('+page_no+',0,\'from_column\')">'+page_no+'</a></span>'+'&nbsp;';
			}
			
			for(var page_no=1; page_no<=total_pages_journey_to;page_no++)
			{
				if(page_no == 1)
				page_anchors_journey_to+='<span><a class="heading_anchor" style="font-weight:bold" id="to_anchor_'+page_no+'" class="abc" href="javascript:void(0)" onclick="javascript:journey_search_limit('+page_no+',0,\'to_column\')">'+page_no+'</a></span>'+'&nbsp;';
				
				else
				page_anchors_journey_to+='<span><a class="heading_anchor" id="to_anchor_'+page_no+'" class="abc" href="javascript:void(0)" onclick="javascript:journey_search_limit('+page_no+',0,\'to_column\')">'+page_no+'</a></span>'+'&nbsp;';
			}
			
	
			journey_search_limit(1,1,'');
			
			
		}else{
			$id('main_div').innerHTML=resp;
			search_resp(resp);
		}
			
		
	}

function journey_search_limit(from_page_no,to_page_no,column)
{
	
	if(column == 'to_column')
	{
		to_page_no = from_page_no;
		from_page_no = $id('FROMPAGE').value;
		
	}
	if(column == 'from_column')
	{
		to_page_no = $id('TOPAGE').value;
	}
	
	
	var from = journey_content['places1'];
	 var from_count = from.length;
		var to = journey_content['places2'];
			 var to_count = to.length;

	 html = '';

	var res = journey_content;
	var results_from;
	
	var FROMjourney_results_from = per_page_journey*(parseInt(from_page_no)-1);
	
	if(to_page_no!=1)
		var TOjourney_results_from = per_page_journey*(parseInt(to_page_no)-1);
	else
		var  TOjourney_results_from = 0;

	var FROMjourney_results_to = FROMjourney_results_from + per_page_journey;
	var TOjourney_results_to = TOjourney_results_from + per_page_journey;
	
	html+="<input type='hidden' name='FROMPAGE' id='FROMPAGE' value="+from_page_no+"><input type='hidden' name='TOPAGE' id='TOPAGE' value="+to_page_no+">";
	html+="<form name='jou_checkform' action='javascript:void(0)' onsubmit=\"sub_journey('"+res['key1']+"', '"+res['key']+"'); return false;\"><table width='100%' align='center'>";
		
		
	if(res['key1'] > 0)
	{
		html +="<td align='center' width='50%'><span  align='left'>From</span><div width='80%' style='height:300px; '><table width='100%' >";
		
		if(FROMjourney_results_to>from_count)
			FROMjourney_results_to = from_count;
			
		html +="<tr><td colspan='2' width='100%'>showing "+(FROMjourney_results_from+1)+" to  "+FROMjourney_results_to+" from "+from_count+" result(s)</td></tr>";
			if(res['from_num']=='0')
				html +="<tr><td colspan='2' >Did you mean</td></tr>";
	
		if(res['ini_temp1']>0)
		{
			html +='<tr><td colspan="2">'+page_anchors_journey_from+'</td></tr>';
			for(var i=FROMjourney_results_from; i<FROMjourney_results_to ;i++)
			{							
				html +="<tr><td width='10px' ><input title=\""+addslashes(from[i]['placename'])+"\" type='radio' name='jou1_radio' value="+from[i]['placeId']+" /></td><td align='left' title=\""+addslashes(from[i]['placename'])+"\">"+from[i]['placename']+"</td></tr>";
			}
		}
		else
		{
			html +="<tr><td width='10px' ><input title=\""+addslashes(from[0]['placename'])+"\" type='radio' name='jou1_radio' value="+from[0]['placeId']+" /></td><td align='left' class='place-explorer' title=\""+addslashes(from[0]['placename'])+"\">";
			var count=0;
			for(var i=0; i<from.length;i++)
			{	if(count==0)
				{
					html+= from[i]['placename'];
					count++;
				}
				else
				{
					html+= ", "+from[i]['placename'];
				}
			}
			
			html+= "</td></tr>";
			
		}
		html+="</table></div></td>";
	}
	
	if(res['key'] > 0) 
	{
		html +="<td align='center' width='50%'><span  align='left'>To</span><div width='80%' style='height:300px; '><table width='100%' >";
		if(TOjourney_results_to>to_count)
			TOjourney_results_to = to_count;
	html +="<tr><td width='100%' colspan='2' >showing "+(TOjourney_results_from+1)+" to  "+TOjourney_results_to+" from "+to_count+" result(s)</td></tr>";

		if(res['to_num']=='0')
			html +="<tr><td colspan='2' >Did you mean</td></tr>";

		if(res['ini_temp2']>0)
		{
			html +='<tr><td colspan="2">'+page_anchors_journey_to+'</tr></td>';
			html +="<tr><td colspan='2' >Did you mean</td></tr>";
		//alert(TOjourney_results_to)
		
			for(var i=TOjourney_results_from; i<TOjourney_results_to ;i++)
			{		//alert(to[82]['placename'])						
				html +="<tr><td width='10px'><input title=\""+addslashes(to[i]['placename'])+"\" type='radio' name='jou2_radio' value="+to[i]['placeId']+" /></td><td align='left' title=\""+addslashes(to[i]['placename'])+"\">"+to[i]['placename']+"</td></tr>";
			}
		}
		else
		{
			html +="<tr><td width='10px'><input type='radio'title=\""+addslashes(to[0]['placename'])+"\" name='jou2_radio' value="+to[0]['placeId']+" /></td><td align='left' title=\""+addslashes(to[0]['placename'])+"\">";
			var count=0;
			for(var i=0; i<to.length ;i++)
			{			
				if(count==0)					
				{
					html+= to[i]['placename'];
					count++;
				}
				else
				html+= ", "+to[i]['placename'];
			}
			
			html+= "</td></tr>";
			
		}
		html+="</table></div></td></tr>";
	}
	
	html +="<tr><td style='padding:10px' align='right'><input type='image' src='"+ROOT_PATH+"images/go.jpg' width='26' height='19' border='0'  /></td></tr></tr></table></form>";
	
	$id('main_div').innerHTML=html;

	for(var page_no=1; page_no<=total_pages_journey_from;page_no++)
	{
		if(page_no == from_page_no)
		{
			if($id('from_anchor_'+page_no))	
				$id('from_anchor_'+page_no).style.fontWeight='bold';
		}
		else
		{
			if($id('from_anchor_'+page_no))
				$id('from_anchor_'+page_no).style.fontWeight='normal';
		}
	}
	for(var page_no=1; page_no<=total_pages_journey_to;page_no++)
	{
		
		if(page_no == to_page_no)
		{
			if($id('to_anchor_'+page_no))
			$id('to_anchor_'+page_no).style.fontWeight='bold';
		}
		else
		{
			if($id('to_anchor_'+page_no))
			$id('to_anchor_'+page_no).style.fontWeight='normal';
		}
	}
}

function sub_journey(key1, key)
{
	var journey_key='',journey_key1='';
	
	var placeId1='';
	var placeId2='';
	if(key1=='0')
		placeId1=0;
	else
	{
		var opt1=document.getElementsByName('jou1_radio');
		
		var opt_val1=opt1.value;
		if(!opt_val1)
		{
			opt_val1=0;
			for(var i=0; i <opt1.length; i++)
			{
				if(opt1[i].checked)
				{
				 opt_val1=opt1[i].value;
				journey_key1=opt1[i].title;
				}
			}
		}
		if(opt_val1==0)
		{
			alert("select 'From' place");return;
		}
		else
		placeId1=opt_val1;
		
		}
		
	if(key=='0')
		placeId2=0;
	else
	{
		var opt2=document.getElementsByName('jou2_radio');
		var opt_val2=opt2.value;
		if(!opt_val2)
		{
			opt_val2=0;
			for(var i=0; i <opt2.length; i++)
			{
				if(opt2[i].checked)
				{
				 opt_val2=opt2[i].value;
				 journey_key=opt2[i].title;
				}
			}
		}
		if(opt_val2==0)
		{
			alert("select 'to' place"); return;
		}
		else
		placeId2=opt_val2;
		}
		if(journey_key==journey_key1)
		{
			alert(' Please Choose Different Places for the Start and End of Your Journey');
			return false;
			
		}
		
			if($id('journey_form'))
				searchJourneyPlaces(journey_key, journey_key1, placeId1, placeId2);
			else
				setLocation('#searchJourneyPlaces&1='+Url.encode(journey_key)+'&2='+Url.encode(journey_key1)+'&3='+escape(placeId1)+'&4='+escape(placeId2));
	
	
}

function searchJourneyPlaces(journey_key, journey_key1, placeId1, placeId2)
{
	$.post(ROOT_PATH+"aj_request.php?aj=places.search1_pagination&type=journey&journey_key="+Url.encode(journey_key)+"&journey_key1="+Url.encode(journey_key1)+"&placeId1="+placeId1+"&placeId2="+placeId2+"&search_id=1",'',journey_search_resp); 
		
	
}

var hotel_content;
var per_page_hotel;
var page_anchors;
var count;
var total_pages;
function hotel_search(resp)
{
	//alert(resp)
	var res;
	try{
		 eval(" res = "+resp);
	}catch(exc){ }
	if(res)
	{
		hotel_content=res;
		var arr1 = res['places'];//alert(arr['0']['placename']);
		 count = arr1.length;//alert(count)
		per_page_hotel= 10;
		total_pages = Math.ceil(count/per_page_hotel);
		html='';
		page_anchors='';	
		for(var i=1; i<=total_pages;i++)
		{	//var page_no = parseInt(i)-1;
			page_no = parseInt(i);
			if(page_no == 1)
			page_anchors+='<span><a style="font-weight:bold" class="heading_anchor" id="anchor_'+page_no+'" class="abc" href="javascript:void(0)" onclick="javascript:hotel_search_limit('+page_no+')">'+i+'</a></span>'+'  ';
			else
			page_anchors+='<span><a  class="heading_anchor" id="anchor_'+page_no+'" class="abc" href="javascript:void(0)" onclick="javascript:hotel_search_limit('+page_no+')">'+i+'</a></span>'+'  ';
		}
		hotel_search_limit(1);
		
		
	}else{//alert(1+"jaskdkhas")
		$id('main_div').innerHTML=resp;
		search_resp();
	}
		
	
}
function hotel_search_limit(page_no)
{	

html= page_anchors;
		
	//$id('anchor_'+page_no).class= 'current_page';
	//html = '';
	var res=hotel_content;
	var results_from;
	
	if(page_no!=1)
	results_from = per_page_hotel*(parseInt(page_no)-1);
	
	else
	results_from = 0;
	

	var to = results_from + per_page_hotel;
	
	var arr1=res['places'];
	var arr = new Array();
	if(to >= arr1.length)
	to = arr1.length;
	for(var i=results_from; i<to;i++)
		{
			arr[i] = new Array();
		}
		
		for(var i=results_from; i<to ;i++)
		{		
			arr[i]['placename'] =  arr1[i]['placename1'];
			arr[i]['placeId'] =  arr1[i]['placeID'];
		}
	    
		html+="<form name='hotel_checkform' action='javascript:void(0)' onsubmit=\"sub_hotels('"+addslashes(res['hotel_key'])+"'); return false;\"><table width='100%' align='center'><tr><th colspan='2'>showing "+(parseInt(results_from)+1)+" to "+to+" from "+count+" result(s)</th></tr><td align='center'><div width='80%' style='height:300px; '><table width='100%' ><tr><th>Did you mean</th></tr><tr>";
		for(var i=results_from; i<to;i++)
		{	
		html +="<tr><td width='10px' ><input type='radio' title=\""+addslashes(arr[i]['placename'])+"\" name='hotel_radio' value="+arr[i]['placeId']+" /></td><td title=\""+addslashes(arr[i]['placename'])+"\">"+arr[i]['placename']+"</td></tr>";
			
		}
		html+="</table></div></td></tr><tr><td style='padding:10px' align='right'><input type='image' src='"+ROOT_PATH+"images/go.jpg' width='26' height='19' border='0'  /></td></tr></table></form>";
		
		//if($id('page_content'))
		//html+='<br>'+page_anchors;
		
		$id('main_div').innerHTML=html;
		if($id('anchor_1'))
		{
			for(var i=1; i<=total_pages;i++)
			{	
				if(i==page_no)
				{	
					
				$id('anchor_'+i).style.fontWeight='bold'
				
				}
				else
				$id('anchor_'+i).style.fontWeight='normal'
			}
		}
		
		//else
		//return html;
}
	
function sub_hotels(hotel_key)
{
	opt_val=document.hotel_checkform.hotel_radio.value;
	var hotel_key1;
	if(!opt_val)
	{
		var opt=document.hotel_checkform.hotel_radio;
		opt_val=0;
		for(var i=0; i <opt.length; i++)
		{
			
			if(opt[i].checked)
			{
				 opt_val=opt[i].value;
				 hotel_key1 = opt[i].title;
			}
		}
	}else
		hotel_key1 = document.hotel_checkform.hotel_radio.title;
	
	if( opt_val==0)
	alert('select any place');
	else
	{
		
		if($id('journey_form'))
			subHotelPlaces(hotel_key, hotel_key1, opt_val);
		else
			setLocation('#subHotelPlaces&1='+escape(hotel_key)+'&2='+escape(hotel_key1)+'&3='+escape(opt_val));
	}
}

function subHotelPlaces(hotel_key, hotel_key1, opt_val)
{
	$.post(ROOT_PATH+"aj_request.php?aj=places.search1_pagination&type=hotel&hotel_key="+Url.encode(hotel_key)+"&hotel_key1="+Url.encode(hotel_key1)+"&placeId="+opt_val+"&search_id=1",'',hotel_search); 
	
}

function search_resp(resp, key)
{


	//$id('main_div').innerHTML=res;
	//search_content =$id('main_div').innerHTML;
	/*	try{
	var hotel_name=$id('hotelname_search').value;	
	var place_name=$id('placename_search').value;	
	var hotel_address = $id('address').value;		
	var gmc=hotel_address.split('-');
	var placename=hotel_name+', '+place_name;
		showByPoint(gmc[0],gmc[1], gmc[2], placename, 'hotel'); 
		}catch(e){}*/
	
	try{
		var type = $id('type_search').value;
	}catch(e){}

	if(type)
	{
		
		var placeId = $id('placeId_search').value;
		var elementId = $id('elementId_search').value;
		var placename = $id('placename_search').value;
		var address=$id('address').value;
		var gmc=address.split('-');
		//alert(type+'-'+placeId+'-'+elementId+'-'+placename);
		$('#main_div').html('<b>Loading...</b>');
		//window.onload = function() { }
	
		if($id('journey_form'))
		{
			changeContent(elementId,type); 
			//showAddress(placename,type); 
		}
		else
		{
			
			if(type=='journey')
			{
				changeContent(elementId,type); 
			}
			else
			{
				
				if(gmc)
					showByPoint(gmc[0],gmc[1], gmc[2], placename, type); 
				aj_exp(placeId);
				changeContent(elementId,type); 
			}
		}
	}
}











