// JavaScript Document
 
function update_jp(itineraryId)
{
$.get(ROOT_PATH+"aj_request.php?aj=journeyplanner.select_jp_elements&itineraryId="+itineraryId+"&reopen=1",'',update_jp_resp); 
	
}
function drawJP(resp)
{
	var elements;
	eval( "elements="+resp);
	
var html='';
html+="<table width='100%' border='1px' bordercolor='#8ACB06' style='border: 1px #8ACB06;' cellpadding='2' cellspacing='0'><tr bgcolor='#8acb06' class='sel_heading'><td width='13%' align='center'>Date</td><td align='center'>Itinerary Element</td></tr>";

for(var i=0; i<elements.length; i++)
{
	element=elements[i];
	
	switch(element['element_type'])
	{
		case 'Localtour':
		{
			html+= "<tr><td align='center' class='sel_text'>"+element['date']+"</td><td align='left' class='sel_content' ><span class='sel_text'>LocalTour</span>- "+element['tour_title']+" |  "+element['Field2']+", "+element['Field3']+"</td></tr>";
			break;
		}
		case 'Transfer':
		{
		html +="<tr><td align='center' class='sel_text'>"+element['date']+"</td><td align='left' class='sel_content' ><span class='sel_text'>Transfer</span>- "+element['from']+" To "+element['to']+" - "+element['Field3']+"</td></tr>";
		break;
		}
		case 'Accommodation':
		{
			html+="<tr><td align='center' class='sel_text'>"+element['date']+"</td><td align='left' class='sel_content' ><span class='sel_text'>Accommodation</span> -";
			if(element['Field2']=='')
			{
				if(element['Field3']!='')
					html+=element['Field3']+"-";
			}else
			{
				html+=element['Field2'];
				if(element['Field3']=='')
				html+="-";
				else
				html+=", "+element['Field3']+"-";
			}
			html+=element['hotelname']+", "+element['Field4']+" Days</td></tr>";
			break;
		}
		case 'Excursion':
		{
			html+="<tr><td align='center' class='sel_text'>"+element['date']+"</td><td align='left' class='sel_content' ><span class='sel_text'>Excursion</span>- "+element['from']+" To "+element['to']+" - "+element['Field2']+"</td></tr>";
			break;
		}
		case 'Journey':
		{
			html+="<tr><td align='center' class='sel_text'>"+element['date']+"</td><td align='left' class='sel_content' ><span class='sel_text'>"+element['journey_type']+"</span>- "+element['journey_title']+" - "+element['Field2'];
			
			if(element['departure_time'] && element['departure_time']!='')
				html+=", "+element['departure_time'];
			
			html+="</td></tr>";
			break;
		}
	}
}
html+=" </table>";
	
return html	
	
}

function update_jp_resp(resp)
{
	var html=drawJP(resp);
	
	$id('jp_td').innerHTML=html;
	showDisableDiv("jp_div");
	
	
}



 function stat_areas_expand(itineraryId){
	$.get(ROOT_PATH+'aj_request.php?aj=user.aj_areas_expand&itineraryId='+itineraryId,'',function(response){
			var res;
			eval("var tot = "+response);
			var arr=tot['tot_pla'];
			var pla_db=tot['pla_db'];
			for(var j=0;j<arr.length; j++){
			//  res_Id=arr[i]['placeId'];
			var res=arr[j]['places'];
			var html='';
			for(var i=0; i<res.length; i++){
				html += "<div ><span style='overflow:hidden' title='"+res[i]['placename1']+"'><input type='checkbox' id='check_id"+res[i]['placeID']+"' name='area_check' value='"+res[i]['placeID']+"' disabled='disabled' /><a href='javascript:void(0)'  class='place-explorer' id = 'area_link"+res[i]['placeID']+"' >"+res[i]['placename1']+"</a></span><div style='margin-left:10px; display:none' id='areas_div"+res[i]['placeID']+"'></div><div id='areas_div2"+res[i]['placeID']+"'></div></div>";
			  }
			  if(arr[j]['placeId']==''){
				  $("#areas_main_div").html(html);
			  }else{
				  $("#areas_div"+arr[j]['placeId']).html(html);
				  $("#areas_div"+arr[j]['placeId']).css('display','');
				  $("#areas_div2"+arr[j]['placeId']).css('display','none');
			  }
			}
			
			for(var i=0;i<pla_db.length; i++){
			$("#check_id"+pla_db[i]).attr('checked', true);
			}
			showDisableDiv("areascovered_div");
		}
	);
}



function show_planninglist(itineraryId)
{
	$.get(ROOT_PATH+'aj_request.php?aj=user.aj_show_wishlist_itiner&wishlistId=&itineraryId='+itineraryId,'',show_planninglist_resp);
	
}

function show_planninglist_resp(resp)
{
	
	html='';
	eval("var res = "+resp);
	if(!res['nill'])
	{
	var listbox_places_arr=res['places'];
	var listbox_journey_arr=res['journey'];
	var listbox_hotels_arr=res['hotels'];
	var listbox_monument_arr=res['monument'];
		//new ConnectToServer(ROOT_PATH+'aj_request.php?aj=user.aj_get_itiner_elements&itineraryId='+itineraryId,'',show_itiner_elements_response).goAndDo();
				
		listbox_displayed='listbox_places';
		html += "<table width='60%' align='center' class='subheading'><tr><td width='25%' id='td_listbox_places' class='listbox_td1' onclick='disp_listbox(1)'>Places</td><td width='25%' onclick='disp_listbox(2)' id='td_listbox_journey' class='listbox_td2'>Journeys</td><td width='25%' onclick='disp_listbox(3)' id='td_listbox_hotel' class='listbox_td2'>Hotels</td><td width='25%' onclick='disp_listbox(4)' class='listbox_td2' id='td_listbox_monuments'>Monuments</td></tr></table>" 
	
	
	//places listbox
	
		html += "<div align='center' width='70%' id='listbox_places' class='listbox_div'><table><tr><td>";
		html += "<select id='listbox1_places' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		/*for(i=0;i<res['places'].length; i++)
		{html +="<option value='"+res['places'][i]['placeId']+"' title='"+res['places'][i]['placename']+"'>"+res['places'][i]['placename']+"</option>";}*/
		html += '</select></td>';
		
		html+="<td><select id='listbox2_places' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		html += '</select></td></tr></table></div>';
		
		
	//journey listbox	
			
	html += "<div align='center' width='70%' id='listbox_journey' class='listbox_div' style='display:none'><table><tr><td>";
		html += "<select id='listbox1_journey' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
	/*	for(i=0;i<res['journey'].length; i++)
		{html +="<option value='"+res['journey'][i]['journeyId']+"' title='"+res['journey'][i]['journey_title']+"'>"+res['journey'][i]['journey_title']+"</option>";}*/
		html += '</select></td>';
		
		html+="<td><select id='listbox2_journey' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		html += '</select></td></tr></table></div>';
		
	//hotel listbox
				
		html += "<div align='center' width='70%' class='listbox_div' id='listbox_hotel' style='display:none'><table><tr><td>";
		html += "<select id='listbox1_hotel' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		/*for(i=0;i<res['hotels'].length; i++)
		{html +="<option value='"+res['hotels'][i]['hotelId']+"' title='"+res['hotels'][i]['hotelname']+"'>"+res['hotels'][i]['hotelname']+"</option>";}*/
		html += '</select></td>';
		
		html+="<td><select id='listbox2_hotel' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		html += '</select></td></tr></table></div>';
	
	
	//monuments listbox
	 
		html += "<div align='center' width='70%'  class='listbox_div' id='listbox_monuments' style='display:none'><table><tr><td>";
		html += "<select id='listbox1_monument' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		/*for(i=0;i<res['places'].length; i++)
		{//html +="<option value='"+res['places'][i]['placeId']+"' title='"+res['places'][i]['placename']+"'>"+res['places'][i]['placename']+"</option>";}*/
		html += '</select></td>';
		
		html+="<td><select id='listbox2_monument' style='width:160px; overflow:hidden;' size='15' multiple='multiple'>";
		html += '</select></td></tr></table></div>';
		$id('planninglist_td').innerHTML=html;
	//	html='';
		
			$id('listbox1_places').innerHTML='';
		$id('listbox2_places').innerHTML='';
		$id('listbox1_journey').innerHTML='';
		$id('listbox2_journey').innerHTML='';
		$id('listbox1_hotel').innerHTML='';
		$id('listbox2_hotel').innerHTML='';
		$id('listbox1_monument').innerHTML='';
		$id('listbox2_monument').innerHTML='';
	for(i = 0 ; i < listbox_places_arr.length; i++)
		{
		if(listbox_places_arr[i]['selected']=='0')
			{
				$id('listbox1_places').options.add( new Option(listbox_places_arr[i]['placename'],listbox_places_arr[i]['placeId']));
			}
			else
			{
				$id('listbox2_places').options.add( new Option(listbox_places_arr[i]['placename'],listbox_places_arr[i]['placeId']));
			}
		}
	
	
	for(i = 0 ; i < listbox_journey_arr.length; i++)
		{
		if(listbox_journey_arr[i]['selected']=='0')
			{
				$id('listbox1_journey').options.add( new Option(listbox_journey_arr[i]['journey_title'],listbox_journey_arr[i]['journeyId']));
			}
			else
			{
				$id('listbox2_journey').options.add( new Option(listbox_journey_arr[i]['journey_title'],listbox_journey_arr[i]['journeyId']));
			}
		}
		
		
	
	for(i = 0 ; i < listbox_hotels_arr.length; i++)
		{
			
		if(listbox_hotels_arr[i]['selected']=='0')
			{
				$id('listbox1_hotel').options.add( new Option(listbox_hotels_arr[i]['hotelname'],listbox_hotels_arr[i]['hotelId']));
			}
			else
			{
				$id('listbox2_hotel').options.add( new Option(listbox_hotels_arr[i]['hotelname'],listbox_hotels_arr[i]['hotelId']));
			}
		}
	
	for(i = 0 ; i < listbox_monument_arr.length; i++)
		{
			
		if(listbox_monument_arr[i]['selected']=='0')
			{
				$id('listbox1_monument').options.add( new Option(listbox_monument_arr[i]['tourname'],listbox_monument_arr[i]['tourId']));
			}
			else
			{
				$id('listbox2_monument').options.add( new Option(listbox_monument_arr[i]['tourname'],listbox_monument_arr[i]['tourId']));
			}
		}
	
	
		
		
	//	$id('planninglist_td').innerHTML=html;
		showDisableDiv('planninglist_div');
		
	}
	else
		alert('no wishlists');
	
	
}

