// JavaScript Document

var wishlist_dir_add;
var listbox_displayed='listbox_places';
var listbox_places_arr;
var listbox_journey_arr;
var listbox_hotels_arr;
var listbox_monument_arr;

function text_check(id, arg, value)
{
	var name=$id(id);
	if(arg=='1')
	{
		if(name.value==value)
		name.value='';
	}
	if(arg=='2')
	{
		if(name.value=='')
		name.value=value;
	}

}


function update_planninglist()
{
	$.get(ROOT_PATH+'aj_request.php?aj=user.aj_addtowishlist&itineraryId='+itineraryId,'',add_place_itiner_response);
}  

function add_place_itiner_response(response)
{ 
	var html='';
	 if(response == 'invalid')
	 {
		 show_error_login_div();
	 }
	  else
	 {
		
		 eval("var res = "+response);
		html+= "<table width='100%'><tr align='center'><td colspan='2'><table align='left' width='100%' >";
			//$id('planninglist_div').style.height = (parseInt((res.length * 20)+150))+'px';
		var td_height = (res.length * 20)+40 ;
		html+="<tr><th class='subheading' align='left' colspan='2' >The Holiday Planner process begins with a list of places you want to go to:</th></tr><tr><td valign='top' height="+td_height+" style='border:2px solid #ccc; padding:10px; overflow:auto'><table width='100%' align='left'>";
		

		var cnt=1;
		if(res.length>0)
		{
			html+="<tr align='left'><td align ='left'  colspan='2'  >"+cnt+". You can pick Places to include in your Holiday Planner from your Wishlists. Pick the wishlists you want to select places from (you can pick more than 1): </td></tr>";
			cnt++;
		
				
			for(i=0;i<res.length;i++)
			{
				g=res[i];
				if(g['iti_exist'])
				{
				html+="<tr align='left'><td width='10%'><input type='checkbox' checked='checked' disabled='disabled' name='wishlist_check' value='"+ g['wishlistID'] +"' ></td><td width='90%' class='search' align='left' title='"+ g['Wishlistname'] +"'>"+ g['Wishlistname'] +"</td></tr>";
				}else
				{
					html+="<tr align='left'><td width='10%'><input type='checkbox' name='wishlist_check' value='"+ g['wishlistID'] +"' ></td><td width='90%' class='search' align='left' title='"+ g['Wishlistname'] +"'>"+ g['Wishlistname'] +"</td></tr>";
					
				}
			}  
	
			html+="<tr  ><td width='100%' align='right'  colspan='2'><table width='100%' ><tr align='center' valign='bottom'><td align='right'><input type='image' src='"+ROOT_PATH+"images/go.jpg' width='26' height='19' border='0' onclick=\"import_wishlist('1');\"  /></td></tr></table></td></tr>";
			html+="<tr align='left'><td align ='center'  colspan='2'  ><b>(OR)</b></td></tr>";	
		}
	
		html+="<tr align='left'><td align ='left'  colspan='2' >"+cnt+".";
		if(cnt>1)
		html+="Or ";
		html+="You can pick from a list of all places that we currently cover. (This can be a very long list). </td></tr>";
		
		cnt++;
		html+="<tr ><td  width='100%'   colspan='2'align='right'><table width='100%' ><tr align='center' valign='bottom'><td align='right'><input type='image' src='"+ROOT_PATH+"images/go.jpg' width='26' height='19' border='0' onclick=\"import_wishlist('2');\"  /></td></tr></table></td></tr>";

		html+="<tr align='left'><td align ='center'  colspan='2'  ><b>(OR)</b></td></tr>";
	
		html+="<tr align='left'><td align ='left'  colspan='2'  >"+cnt+". You can proceed to the next page and directly type in the places you are interested in. </td></tr>";
		cnt++;
		
		html+="<tr align='left'><td  colspan='2'  width='100%'  align='right'><table width='100%' ><tr align='center' valign='bottom'><td align='right'><input type='image' src='"+ROOT_PATH+"images/go.jpg' width='26' height='19' border='0' onclick=\"import_wishlist('3');\"  /></td></tr></table></td></tr>";
	
	
	
	
	html+="</table></td></tr></table>";
	$id('planninglist_td').innerHTML = html;
	showDisableDiv('planninglist_div');
	}
}




function import_wishlist(arg)
{
		wishlistId=''
	if(arg=='1')
	{	
		try{
		var wishlists=document.getElementsByName('wishlist_check');
		
		if(wishlists.length==0)
		wishlistId=0;
		for(i=0;i<wishlists.length;i++)
		{
			if(wishlists[i].checked)
			{
				if(wishlistId=='')
					wishlistId = wishlists[i].value;
				else
					wishlistId += ','+wishlists[i].value;
			}
		}

		wishlist_dir_add=wishlistId;
		if(wishlistId=='')
		{
			alert('Please Select Wishlists To Import');
			return ;
		}
		
		}catch(e){}
	}
	$.get(ROOT_PATH+'aj_request.php?aj=user.aj_get_planninglist_places&wishlistId='+wishlistId+'&itineraryId='+itineraryId+'&type='+arg,'',show_wishlist_itiner_response);
}



function show_wishlist_itiner_response(response)
{
	if(response == 'No wishlists')
	{
		listbox_places_arr=new Array();
		listbox_journey_arr=new Array();
		listbox_hotels_arr=new Array();
		listbox_monument_arr=new Array();
			
		draw_listbox();
		elements_listbox();
		return;
	}
	
	//$id('test').value=response;
	html='';
	eval("var res = "+response);
	if(!res['nill'])
	{
		listbox_places_arr=res['places'];
		listbox_journey_arr=res['journey'];
		listbox_hotels_arr=res['hotels'];
		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();
		draw_listbox();
		elements_listbox();
	}
	else
		alert('no wishlists');
}


	
function draw_listbox()
{	listbox_displayed='listbox_places';
	html = '';
	html += "<p align='center'><a  href='javascript:void(0);' onclick='update_planninglist()' class='links2' style='text-decoration:underline'>Back To <br> Previous Screen</a></p>"
	html += "<table width='100%' align='center'><tr><td   align='center'>Select Items to add to Holiday Planner </td></tr></table>";
	
	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 align='center' ><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>';
	
	html += "<table align='center' width='100%' ><tr><td align='right' width='50%'><input type='button' value='add' onclick=\"places_listbox_fun('add')\"></td><td align='left'><input type='button' value='remove' onclick=\"places_listbox_fun('rem')\"></td></tr></table>";
	
	html += "<table align='center' width='100%' style='border-top:1px solid #5C9C00'  ><tr><td   align='center'>OR, just type in places here:</td></tr><tr><td align='center' colspan='2'><input type='text' style='width:260px' id='add_place_list' class='content'  value='e.g. Jaipur, Agra, Delhi etc....' onfocus=\"text_check('add_place_list','1','e.g. Jaipur, Agra, Delhi etc....')\" onblur=\"text_check('add_place_list','2','e.g. Jaipur, Agra, Delhi etc....'); \" ><input type='hidden' value='' id='add_list_hidden' /><input type='button' value='add' onclick=\"add_ele_itiner('place')\"></td></tr><tr><td colspan='2'>&nbsp;</td></tr></table></div>";
	
	
	
//journey listbox	
		
html += "<div align='center' width='70%' id='listbox_journey' class='listbox_div' style='display:none'><table  align='center' ><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>';
	html += "<table align='center' width='100%' ><tr><td width='50%' align='right'><input type='button' value='add' onclick=\"journey_listbox_fun('add')\"></td><td  align='left'><input type='button' value='remove' onclick=\"journey_listbox_fun('rem')\"></td></tr></table></div>";
	
//hotel listbox
			
	html += "<div align='center' width='70%' class='listbox_div' id='listbox_hotel' style='display:none'><table  align='center' ><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>';
	html += "<table align='center'  width='100%'><tr><td width='50%' align='right'><input type='button' value='add' onclick=\"hotel_listbox_fun('add')\"></td><td  align='left'><input type='button' value='remove' onclick=\"hotel_listbox_fun('rem')\"></td></tr></table></div>";
			
//monuments listbox
 
	html += "<div align='center' width='70%'  class='listbox_div' id='listbox_monuments' style='display:none'><table  align='center' ><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>';
	html += "<table align='center' width='100%' ><tr><td align='right' width='50%'><input type='button' value='add' onclick=\"monuments_listbox_fun('add')\"></td><td  align='left'><input type='button' value='remove' onclick=\"monuments_listbox_fun('rem')\"></td></tr></table>";
	
	
	
	html+="<table align='center' width='100%' style='border-top:1px solid #5C9C00'  ><tr><td   align='center' >OR, just type in monuments here:</td></tr><tr><td align='center' colspan='2'><input type='text' style='width:260px' id='add_mon_list' class='content' onfocus=\"text_check('add_place_list','1','ADD MONUMENTS')\" onblur=\"text_check('add_place_list','2','ADD MONUMENTS'); \" ><input type='button' value='add' onclick=\"add_ele_itiner('monument')\"></td></tr></table></div><table width='80%'><tr align='right'><td align='right' style='text-align:right'><a href='javascript:void(0)' onclick='planninglist_submit()' ><img border='0' src='"+ROOT_PATH+"images/go.jpg'></a></td></tr></table>";
	
	//$id('planninglist_div').style.height = '430px';
	$id('planninglist_td').innerHTML=html;
	showDisableDiv('planninglist_div');
	
	
	var _actb = new actb('add_place_list','', ROOT_PATH+'aj_request.php?aj=user.aj_autosugest&only_hp_places=1&value=' );  
	var _actb = new actb('add_mon_list','', ROOT_PATH+'aj_request.php?aj=user.aj_autosugest_mon&value=' );  
	
	
}






function elements_listbox()
{
	$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']));
		}
	}



}




function disp_listbox(arg)
{
	
	if(listbox_displayed=='')
	{
		$id('listbox_places').style.display='none';
		$id('td_listbox_places').className='listbox_td2';
		}
	else
	{
		$id(listbox_displayed).style.display='none';
		$id('td_'+listbox_displayed).className ='listbox_td2';
	}
	
	switch(arg)
	{
	case 1 :{ $id('listbox_places').style.display='';
			 $id('td_listbox_places').className='listbox_td1';
			  listbox_displayed='listbox_places'; 
			  break;
			  }
	case 2 : {
				$id('listbox_journey').style.display='';
				$id('td_listbox_journey').className='listbox_td1';
				listbox_displayed='listbox_journey'; 
				break;
				}
	case 3 :{
				$id('listbox_hotel').style.display='';
				$id('td_listbox_hotel').className='listbox_td1';
				listbox_displayed='listbox_hotel'; 
				break;
				}
	case 4 :{
				$id('listbox_monuments').style.display='';
				$id('td_listbox_monuments').className='listbox_td1';
				listbox_displayed='listbox_monuments'; 
				break;
				}
	
	}
	
}






function places_listbox_fun(add_rem)
{

	var from, to;
	if(add_rem=='add')
	{
		from='listbox1_places';
		to='listbox2_places';
	}
	if(add_rem=='rem')
	{
		to='listbox1_places';
		from='listbox2_places';
	
	}

	var elements=$id(from).options;

	for(var i = 0 ; i < elements.length; i++)
	{
		if(elements[i].selected)
		{
			var return_val=listbox_pla_arr_fun(elements[i].value, add_rem );
			if(return_val)
			return ;
			$id(to).options.add( new Option(elements[i].text,elements[i].value));
		}
	}
	
	for(var i = elements.length - 1 ; i >= 0 ; i--)
	{
	if(elements[i].selected)
		{
			$id(from).remove(i);
		}
	}
}

function listbox_pla_arr_fun(placeId, add_rem)
{

	for(var i=0;i < listbox_places_arr.length;i++)
	{
		if(listbox_places_arr[i]['placeId']==placeId)
	 	{
			if(add_rem=='add')
	 		 {
			 	listbox_places_arr[i]['selected']=1;
			}
			if(add_rem=='rem')
	  		{
			 	if(listbox_places_arr[i]['sub_elements'].length=='0')
				listbox_places_arr[i]['selected']='0';
				else
				{
					for(var j=0; j<listbox_places_arr[i]['sub_elements'].length; j++)
					{
						switch(listbox_places_arr[i]['sub_elements'][j]['type'])
						{
							case 'journey':
							{
						
								for(var k=0;k<listbox_journey_arr.length; k++)
								{
									if(listbox_places_arr[i]['sub_elements'][j]['elementId']==listbox_journey_arr[k]['journeyId'])
									alert('you hav to delete journey:'+listbox_journey_arr[k]['journey_title']+' in order to delete this place'  );
								}
							break;
							}
	
							case 'hotel':
							{
							
								for(var k=0;k<listbox_hotels_arr.length; k++)
								{
									if(listbox_places_arr[i]['sub_elements'][j]['elementId']==listbox_hotels_arr[k]['hotelId'])
									alert('you hav to delete a Hotel:'+listbox_hotels_arr[k]['hotelname']+' in order to delete this place'  );
								}break;
							}
							case 'monument':
							{
							
								for(var k=0;k<listbox_monument_arr.length; k++)
								{
									if(listbox_places_arr[i]['sub_elements'][j]['elementId']==listbox_monument_arr[k]['tourId'])
									alert('you hav to delete a Monument:'+listbox_monument_arr[k]['tourname']+' in order to delete this place'  );
								}break;
							}
							
						}
					}return true;
				}
			}
		}	
	}
}


	
	
	
	
	
	
	

function hotel_listbox_fun(add_rem)
{
	var from, to;
	if(add_rem=='add')
	{
		from='listbox1_hotel';
		to='listbox2_hotel';
	}
	if(add_rem=='rem')
	{
		to='listbox1_hotel';
		from='listbox2_hotel';
	
	}
	var elements=$id(from).options;
	for(var i = 0 ; i < elements.length; i++)
	{

		if(elements[i].selected)
		{
			listbox_hotel_arr_fun(elements[i].value, add_rem);
			$id(to).options.add( new Option(elements[i].text,elements[i].value));
			
		}
	}
	for(var i = elements.length - 1 ; i >= 0 ; i--)
	{
		if(elements[i].selected)
		{
			$id(from).remove(i);
		}
	}
}

	
	
	
	
	
	
function listbox_hotel_arr_fun(hotelId, add_rem)
{
	for(var i=0; i < listbox_hotels_arr.length;i++)
	{
		if(listbox_hotels_arr[i]['hotelId']==hotelId)
		{
			if(add_rem=='add')
			{
				listbox_hotels_arr[i]['selected']=1;
				
				var elements=$id('listbox1_places').options;
				for(var j = 0 ; j < elements.length; j++)
				{
					if(elements[j].value==listbox_hotels_arr[i]['placeId'])
					{
						elements[j].selected='selected';						
					}else
					elements[j].selected=false;
							
				}
			add_subelement(listbox_hotels_arr[i]['placeId'], listbox_hotels_arr[i]['hotelId'], 'hotel')
			places_listbox_fun('add');
			
			}
			
			
			
			if(add_rem=='rem')
			{
				listbox_hotels_arr[i]['selected']=0;
				
				for(var j=0;j<listbox_places_arr.length; j++)
				{
					if(listbox_places_arr[j]['placeId']==listbox_hotels_arr[i]['placeId'])
					{
						for(var k=listbox_places_arr[j]['sub_elements'].length - 1; k>=0; k--)
						{
							if((listbox_places_arr[j]['sub_elements'][k]['elementId']==listbox_hotels_arr[i]['hotelId'])&&(listbox_places_arr[j]['sub_elements'][k]['type']=='hotel'))
							{
							listbox_places_arr[j]['sub_elements'].splice(k,1);
							}
						}
						alert(listbox_places_arr[j]['placename']+'is not removed from places list');
					}
				}
						
			}
		}
	}
}




function monuments_listbox_fun(add_rem)
{
	var from, to;
	if(add_rem=='add')
	{
		from='listbox1_monument';
		to='listbox2_monument';
	}
	if(add_rem=='rem')
	{
		to='listbox1_monument';
		from='listbox2_monument';
	
	}
	var elements=$id(from).options;
	for(var i = 0 ; i < elements.length; i++)
	{

		if(elements[i].selected)
		{
			listbox_monument_arr_fun(elements[i].value, add_rem);
			$id(to).options.add( new Option(elements[i].text,elements[i].value));
			
		}
	}
	for(var i = elements.length - 1 ; i >= 0 ; i--)
	{
		if(elements[i].selected)
		{
			$id(from).remove(i);
		}
	}
}

	
	
	
	
	
	
function listbox_monument_arr_fun(tourId, add_rem)
{
	for(var i=0; i < listbox_monument_arr.length;i++)
	{
		if(listbox_monument_arr[i]['tourId']==tourId)
		{
			if(add_rem=='add')
			{
				listbox_monument_arr[i]['selected']=1;
				
				var elements=$id('listbox1_places').options;
				for(var j = 0 ; j < elements.length; j++)
				{
					if(elements[j].value==listbox_monument_arr[i]['placeId'])
					{
						elements[j].selected='selected';						
					}else
					elements[j].selected=false;
							
				}
			add_subelement(listbox_monument_arr[i]['placeId'], listbox_monument_arr[i]['tourId'], 'monument')
			places_listbox_fun('add');
			
			}
			
			
			
			if(add_rem=='rem')
			{
				listbox_monument_arr[i]['selected']=0;
				
				for(var j=0;j<listbox_places_arr.length; j++)
				{
					if(listbox_places_arr[j]['placeId']==listbox_monument_arr[i]['placeId'])
					{
						for(var k=listbox_places_arr[j]['sub_elements'].length - 1; k>=0; k--)
						{
							if((listbox_places_arr[j]['sub_elements'][k]['elementId']==listbox_monument_arr[i]['tourId'])&&(listbox_places_arr[j]['sub_elements'][k]['type']=='monument'))
							{
							listbox_places_arr[j]['sub_elements'].splice(k,1);
							}
						}
						alert(listbox_places_arr[j]['placename']+'is not removed from places list');
					}
				}
			}
		}
	}
}


 




function journey_listbox_fun(add_rem)
{
	var from, to;
	if(add_rem=='add')
	{
		from='listbox1_journey';
		to='listbox2_journey';
	}
	if(add_rem=='rem')
	{
		to='listbox1_journey';
		from='listbox2_journey';
	
	}
	
	var elements=$id(from).options;
	for(var i = 0 ; i < elements.length; i++)
	{

		if(elements[i].selected)
		{
			listbox_jou_arr_fun(elements[i].value, add_rem);
			$id(to).options.add( new Option(elements[i].text,elements[i].value));
			
		}
	}
	
	for(var i = elements.length - 1 ; i >= 0 ; i--)
	{
		if(elements[i].selected)
		{
			$id(from).remove(i);
		}
	}
}





function listbox_jou_arr_fun(journeyId, add_rem)
{
	for(var i=0; i < listbox_journey_arr.length;i++)
	{
		if(listbox_journey_arr[i]['journeyId']==journeyId)
		{
			if(add_rem=='add')
			{
				listbox_journey_arr[i]['selected']=1;
				
				var elements=$id('listbox1_places').options;
				for(var j = 0 ; j < elements.length; j++)
				{
					if(elements[j].value==listbox_journey_arr[i]['place_from'] || elements[j].value==listbox_journey_arr[i]['place_to'])
					{
						elements[j].selected='selected';						
					}else
					elements[j].selected=false;
							
				}
				add_subelement(listbox_journey_arr[i]['place_from'], listbox_journey_arr[i]['journeyId'], 'journey');
				add_subelement(listbox_journey_arr[i]['place_to'], listbox_journey_arr[i]['journeyId'], 'journey');
			
			places_listbox_fun('add');
			}
			
			
			
			if(add_rem=='rem')
			{
				listbox_journey_arr[i]['selected']=0;
				
				for(var j=0;j<listbox_places_arr.length; j++)
				{
					if(listbox_places_arr[j]['placeId']==listbox_journey_arr[i]['place_from']|| listbox_places_arr[j]['placeId']==listbox_journey_arr[i]['place_to'])
					{
						for(var k=listbox_places_arr[j]['sub_elements'].length -1; k>=0; k--)
						{
							if((listbox_places_arr[j]['sub_elements'][k]['elementId']==listbox_journey_arr[i]['journeyId'])&&(listbox_places_arr[j]['sub_elements'][k]['type']=='journey'))
							{
							listbox_places_arr[j]['sub_elements'].splice(k,1);
							}
						}
						alert(listbox_places_arr[j]['placename']+'is not removed from places list');
					}
				}
						

			}
		}
	}
}




function add_subelement(placeId, elementId, type)
{
	for(var i=0; i < listbox_places_arr.length;i++)
	{ 
		if(listbox_places_arr[i]['placeId']==placeId)
		{
		var len=listbox_places_arr[i]['sub_elements'].length;
		var t = {'elementId':elementId , 'type':type}
		listbox_places_arr[i]['sub_elements'][len] = t;
	
		}
	}

}




	
	
	
	
	
	
function planninglist_submit()
{
var placeId='';
var hotelId='';
var journeyId='';
var tourId='';
var count=0;
for(var i=0;i<listbox_places_arr.length; i++)
{
	if(listbox_places_arr[i]['selected']=='1')
	{
		if(count==0)
		{
		 	placeId += listbox_places_arr[i]['placeId'];
		 	count++;
		 }
		 else
		 {
		 	placeId +=','+listbox_places_arr[i]['placeId'];
		 }
	}
		 
}

var count=0;
for(var i=0;i<listbox_hotels_arr.length; i++)
{
	if(listbox_hotels_arr[i]['selected']=='1')
	{
		if(count==0)
		{
		 	hotelId += listbox_hotels_arr[i]['hotelId'];
		 	count++;
		 }
		 else
		 {
		 	hotelId +=','+listbox_hotels_arr[i]['hotelId'];
		 }
	}
		 
}
var count=0;
for(var i=0;i<listbox_journey_arr.length; i++)
{
	if(listbox_journey_arr[i]['selected']=='1')
	{
		if(count==0)
		{
		 	journeyId += listbox_journey_arr[i]['journeyId'];
		 	count++;
		 }
		 else
		 {
		 	journeyId +=','+listbox_journey_arr[i]['journeyId'];
		 }
	}
		 
}

var count=0;
for(var i=0;i<listbox_monument_arr.length; i++)
{
	if(listbox_monument_arr[i]['selected']=='1')
	{
		if(count==0)
		{
		 	tourId += listbox_monument_arr[i]['tourId'];
		 	count++;
		 }
		 else
		 {
		 	tourId +=','+listbox_monument_arr[i]['tourId'];
		 }
	}
		 
}

$.post(ROOT_PATH+'aj_request.php?aj=user.aj_add_element_itinerary', 'placeId='+placeId+'&journeyId='+journeyId+'&hotelId='+hotelId+'&tourId='+tourId+'&id='+itineraryId, addelements_itiner_response);


}


// is at frame.tpl addelements_itiner_response(resp)




function add_ele_itiner(type)
{
	if(type=='place')
	var element =$id('add_place_list').value;	
		
	if(type=='monument')
	var element =$id('add_mon_list').value;	
	
	
	$.get(ROOT_PATH+'aj_request.php?aj=user.aj_add_auto_pla_itin&element='+element+'&Id='+itineraryId+'&type='+type,'',addpla_dir_itiner_response);
}

function addpla_dir_itiner_response(resp)
{
	eval("var res = "+resp);
	if(res['type']=='place')
	{
		var places=res['content'];
		for( var i=0; i<places.length; i++)
		{
			var count=0;
			for(var j=0; j<listbox_places_arr.length; j++)
			{
				if(listbox_places_arr[j]['placeId']==places[i]['placeId'])	
				{
					count++;
					listbox_places_arr[j]['selected']=1;
				}
			}
			if(count=='0')
			{
				listbox_places_arr.splice(listbox_places_arr.length, 0, places[i])	
			}
			
		}
		$id('add_place_list').value='';
	}
	
	if(res['type']=='monument')
	{
		var mon=res['content'];
		for( var i=0; i<mon.length; i++)
		{
			var count=0;
			for(var j=0; j<listbox_monument_arr.length; j++)
			{
				if(listbox_monument_arr[j]['tourId']==mon[i]['tourId'])	
				{
					count++;
					listbox_monument_arr[j]['selected']=1;
				}
			}
			if(count=='0')
			{
				mon[i]['selected']=1;
				listbox_monument_arr.splice(listbox_monument_arr.length, 0, mon[i])	
			}
	
			
			var temp=new Array();
			temp['placename']=mon[i]['placename'];
			temp['placeId']=mon[i]['placeId'];
			temp['selected']=1;

			temp['sub_elements']=new Array();
			
			count=0;
			for(var j=0; j<listbox_places_arr.length; j++)
			{
				if(listbox_places_arr[j]['placeId']==temp['placeId'])	
				{
					count++;
					listbox_places_arr[j]['selected']=1;
				}
			}
			if(count=='0')
			{
				listbox_places_arr.splice(listbox_places_arr.length, 0, temp)	
			}
			
			add_subelement(mon[i]['placeId'], mon[i]['tourId'], 'monument')
		}
		
		
		$id('add_mon_list').value='';

	}

		elements_listbox();
		
}

