function PopupCenter(pageURL,w,h) 
{
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, 'popup', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

function showFLNameInputs(fields)
{
	if(fields && fields > 0)
	{
		container = document.getElementById('conatiner_adulti');
		txt ='';
		for(i = 0; i<fields; i++)
			txt +='<p>Adult '+(i+1)+': <input type="text" name="info_adulti[]" style="width:200px" value=""/></p>';
		
		container.innerHTML = txt;
	}
	
	(document.getElementById('detalii_adulti').style.display == 'none')?document.getElementById('detalii_adulti').style.display = '': document.getElementById('detalii_adulti').style.display = 'none';
}

function doCharterRoomPara(roomsArray, paraNr)
{
	var container = document.getElementById('multiroom');
	var returnContent = '';
	
	
	for(var i = 0; i < paraNr; i++)
	{
		returnContent += '<ul class="dynamic" id="dynamicul_'+(i+1)+'"><li><span>Tip camera:*</span> '+doCharterRoomsSelect(roomsArray, (i+1), 0)+'</li>'; 
		returnContent += '<li><span>Numar adulti:*</span>'+doAdultsSelect((i+1), 0)+'</li>'; 
		returnContent += '<li><span>Numar copii: </span>'+doChildsSelect((i+1), 0)+'</li>'; 
		returnContent += '</ul>';
	}
	container.innerHTML = returnContent;
}

function doCharterRoomsSelect(roomsArray, Id, selectedRoom)
{
	var myselect = '<select name="roomtype['+Id+']">';
	
	for(var i=0;i<roomsArray.length;i++)
	{
		myselect += (i == selectedRoom)?'<option value="'+i+'" selected="selected">'+roomsArray[i]+'</option>':'<option value="'+i+'">'+roomsArray[i]+'</option>';
	}

	myselect += '</select>';
	
	return myselect;
}

function doAdultsSelect(Id, selectedId)
{
	var myselect = '<select name="nr_adulti['+Id+']">';
	myselect += '<option value="0">--</option>';
	
	for(var i=1;i<=10;i++)
	{
		myselect += (i == selectedId)? '<option value="'+i+'" selected="selected">'+i+'</option>' : '<option value="'+i+'">'+i+'</option>';
	}
	
	myselect += '</select>';
	
	return myselect;
}

function doChildsSelect(Id, selectedId)
{
	var myselect = '<select name="nr_copii['+Id+']" onchange="doChildsAges(this.options[this.selectedIndex].value,'+Id+')">';
	myselect 	+= '<option value="0">--</option>';
	
	for(var i=1;i<=10;i++)
	{
		myselect += (i == selectedId)? '<option value="'+i+'" selected="selected">'+i+'</option>' : '<option value="'+i+'">'+i+'</option>';
	}
	
	myselect += '</select>';
	
	return myselect;
}

function doChildsAges(fieldsNr, containerId)
{
	var container = document.getElementById('dynamicul_'+containerId);
	var content = '';
	
	for(var i=0; i < fieldsNr; i++)
	{
		var name = i+1;
		content += '<span>Virsta copil '+name+':*</span> <input type="text" name="child_age['+containerId+'][]" value="" /><br />';
		
	}
	
	if(!document.getElementById('cage_'+containerId)) 
	{
		var new_element = document.createElement('li');
		new_element.id  = 'cage_'+containerId;
		new_element.innerHTML = content;
		container.appendChild(new_element);
	}
	else
	{
		document.getElementById('cage_'+containerId).innerHTML = content;
	}
}

function doAdultsNames(fieldsNr)
{
	var container = document.getElementById('adults_names');
	var content = '';
	
	for(var i=0; i < fieldsNr; i++)
	{
		var name = i+1;
		content += '<span>Nume adult '+name+':*</span> <input type="text" name="adult_name[]" value="" style="width:250px"/><br />';
	}
	
	if(fieldsNr > 0) 
	{
		container.innerHTML = content;
		container.style.display = "block";
	}
	else
	{
		container.innerHTML = content;
		container.style.display = "none";
	}
}

function DoSearchRegiuni(idTara)
{
	idTara = parseInt(idTara);
	
	if(regiuni[idTara].length > 0)
	{
		var myselect = '<select name="r">';
		myselect 	+= '<option value="0">Alege regiune</option>';
	
		for(i =0; i < regiuni_ids[idTara].length; i++)
			myselect += '<option value="'+regiuni_ids[idTara][i]+'">'+regiuni[idTara][parseInt(regiuni_ids[idTara][i])]+'</option>';
	}
	myselect += '</select>';
	document.getElementById('select_regiune').innerHTML = myselect;
}

function ShowSearchHotel()
{
	document.getElementById('cautahotel').style.display='block'; 
	document.getElementById('bileteavion').style.display='none'; 
	document.getElementById('bileteavionsel').className='bileteavion'; 
	document.getElementById('cautahotelsel').className='cautahotelsel';
}

function ShowSearchBilete()
{
	document.getElementById('bileteavion').style.display='block'; 
	document.getElementById('cautahotel').style.display='none'; 
	document.getElementById('cautahotelsel').className='cautahotel'; 
	document.getElementById('bileteavionsel').className='bileteavionsel';
}

function setRezervareBiletAction()
{
   for (var i=0; i < document.biletelist_form.tarif.length; i++)
   {
	   if (document.biletelist_form[i].checked)
	      location.href=document.biletelist_form.action+'&tid='+document.biletelist_form.tarif[i].value;
   }
   return false;
}
