var tLength= new Array('1', '2', '3', '4', '5','6', '7','8', '9','10','11','12','13','14','15','16','17','18','19','20','30','60','90','180');

var numSpan=2;

var selectsTotal= 3;
   
function AutofillStay(i) {
	var select= document.searchPasses.elements["ddlTravelLength" + i];
	var selectStay = document.searchPasses.elements["ddlLengthStay" + i];

	for (var j= 0; j< tLength.length; j++) {
		if (tLength[j]=='30') {
			select.options[select.options.length] = new Option('1 month',tLength[j]); 
			selectStay.options[selectStay.options.length] = new Option( '1 month',tLength[j]); 
		}
		else if (tLength[j]=='60') {
			select.options[select.options.length] = new Option('2 months',tLength[j]);
			selectStay.options[selectStay.options.length] = new Option('2 months',tLength[j]);	  
		}
		else if (tLength[j]=='90') {
			select.options[select.options.length] = new Option('3 months',tLength[j]);
			selectStay.options[selectStay.options.length] = new Option('3 months',tLength[j]);
		}
		else if (tLength[j]=='180') {
			select.options[select.options.length] = new Option('6 months',tLength[j]);
			selectStay.options[selectStay.options.length] = new Option('6 months',tLength[j]);
		}
		else if (tLength[j]=='1') {
			select.options[select.options.length] = new Option('1 day',tLength[j]);
			selectStay.options[selectStay.options.length] = new Option('1 day',tLength[j]);
		}
		else {
			select.options[select.options.length] = new Option(tLength[j] + ' days' ,tLength[j]);
			selectStay.options[selectStay.options.length] = new Option(tLength[j] + ' days' ,tLength[j]);	  
		}
		if (tLength[j]=='2') {
			select.options[j].selected= true;
			selectStay.options[j].selected= true;
		}
	}
}

function renderDestination()
{
	var numDest = numSpan - 1;
	if (numSpan <7) {
		var objDest = document.getElementById("txtDestination"+numDest).value;
		if (objDest == "" || objDest == "Enter a Pass or Destination Country Here") {
			errMsg = "Please enter a destination before adding items";
			alert(errMsg);
//			document.getElementById("errMessage").innerHTML = errMsg;
//			showBox("errBox");		
		}
		else {
			if (document.getElementById("errBox").style.display == "block") {
				document.getElementById("errMessage").innerHTML = "";
				hideBox("errBox");			
			}
			var obj = document.getElementById('dest' + numSpan);
			obj.style.display = "block";
			AutofillStay(numSpan);
			numSpan = numSpan + 1;
		} 
	}
}

function showBox(boxID)
{
	document.getElementById(boxID).style.display = "block";
}
function hideBox(boxID)
{
	document.getElementById(boxID).style.display = "none";
}
function clearDestination(destNum)
{
	//document.getElementById("txtDestination"+destNum).value="Enter a Pass or Destination Country Here";
	//hideBox("dest"+destNum);
	//numSpan = numSpan - 1;
	//hideSelect(destNum);
	
	//alert('destNum' + destNum);
	
	//alert('numSpan' + numSpan);
	
	if (destNum < numSpan-1)
	{
	        
	
		for (i=destNum;i<=numSpan - 2;i++)
		{
		        var j=i+1;
		        
			divDestDisplay = document.getElementById("dest"+j).style.display;
			
			txtDest = document.getElementById("txtDestination"+j).value;
			
			if (divDestDisplay == "block") 
			{
                                
				var obj = document.getElementById('dest' + i);
											
				obj.style.display = "block";
				
				document.getElementById("txtDestination"+i).value = txtDest;

								
				
				try
				{	
				        //alert('main' + document.getElementById("Countries_" + j).style.display);
					
					if (document.getElementById("Countries_" + j).style.display=="block") 
					{


						var cobj = document.getElementById("Countries_" + i);
						
																		
						cobj.style.display = "block";
						
						selectsTotal =5;
						

						for (k=1; k<6; k++) {
						
						        
							if (document.getElementById("txtDestination_" +j + "_" + k).style.display == "block") {
							
							      document.getElementById("txtDestination_" + i + "_" + k).style.display = "block";
							       
								var cIndex = document.getElementById("Country" + k + "_" + j + "_" + k).selectedIndex;
								var cValue = document.getElementById("Country" + k + "_" + j + "_" + k)[cIndex].value;
								
								if(k==1)
								{
								
									var select= document.searchPasses.elements["Country" + k + "_" + i + "_" + k ];
								
									//alert(select.length);
									
									for (var c= 0; c< select.length; c++) {
									
																			
									if (select[c].value == cValue)
										{
										
										 select.options[c].selected = true;
										
										}
									}

									setSelects(k, i) ;
								}
								else
								{
																
									var select= document.searchPasses.elements["Country" + k + "_" + i + "_" + k ];
								
									//alert(select.length);
									
									for (var c= 0; c< select.length; c++) {
									
																			
									if (select[c].value == cValue)
										{
										
										 select.options[c].selected = true;
										
										}
									}
								
									setSelects(k, i) ;
								
								}

							}
							
							else
							
							{
							      document.getElementById("txtDestination_" +i + "_" + k).style.display = "none";
							
							
							}
							
						}
						
						//document.getElementById("Countries_" + j).style.display=="none";
					}
					else
					{
					
						document.getElementById("Countries_" + i).style.display="none";
					
					}

				}
				catch(e) {a=e;}

			}
			
			
			

		}

	
	}
	
		
	var currDest = numSpan-1;
	
	var currCountry = currDest-1;
	
	document.getElementById("txtDestination"+ currDest).value="Enter a Pass or Destination Country Here";
	
		
	
	if (destNum == numSpan-1)
	{
	
		
		if (document.getElementById("Countries_" + currDest).style.display=="block") 
		{
			document.getElementById("Countries_" + currDest).style.display = "none";

			
		}	
	}
	
	hideBox("dest"+currDest);
	numSpan = numSpan - 1;
	
	
}
function showAges()
{
	youthIndex = document.getElementById("ddlYouth").selectedIndex;
	youthVal = document.getElementById("ddlYouth")[youthIndex].value;
/*	if (youthVal != 0) {
		showBox("ageBox");
	}
	else {
		hideBox("ageBox");
	}*/
}
function passValidate()
{
	var i=1;
	var errMsg = "";
	var divDestDisplay = "";
	var txtDest = "";
	
	var mPeople =1;
	
	var valAdults = document.getElementById("ddlAdults").selectedIndex;
	var valYouth = document.getElementById("ddlYouth").selectedIndex;
	var valChildren = document.getElementById("ddlChildren").selectedIndex;
	var valSeniors = document.getElementById("ddlSeniors").selectedIndex;
	
	var valTotPassengers = valAdults + valYouth + valChildren + valSeniors;


	for (i=1;i<=6;i++)
	{
		divDestDisplay = document.getElementById("dest"+i).style.display;
		txtDest = document.getElementById("txtDestination"+i).value;
		if (divDestDisplay == "block") {
			if (txtDest == "" || txtDest == "Enter a Pass or Destination Country Here") {
				if (errMsg != "") {
					errMsg = errMsg + "<br>";
				}
				if (i == 1) {
					errMsg = errMsg + "Please enter a destination";
				}
				else {
					errMsg = errMsg + "Please enter all destinations";
				}
			}
			else
			{
				
			  mPeople = CheckMinPassengers(txtDest);
			  
			  //alert(mPeople);
			  
			  if (mPeople==2)
			  {
			  
			    if (valTotPassengers < mPeople)
			    {
			    
			      errMsg = errMsg + "This Product requires minimum 2 Passengers";
			    
			    }
			  
			  
			  }
			
			}

			try
			{
				var j = 1;
				var errMsgCtry = ""
				if (document.getElementById("Countries_" + i).style.display=="block") {
					for (j=1; j<6; j++) {
						if (document.getElementById("txtDestination_" +i + "_" + j).style.display == "block") {
							ctryObj = document.getElementById("Country" + j + "_" + i + "_" + j);
							if (ctryObj.selectedIndex == 0) {
								errMsgCtry = "Please select pass countries";
							}
						}
					}
				}
				if (errMsgCtry != "") {
					if (errMsg != "") {
						errMsg = errMsg + "<br>";
					}
					errMsg = errMsg + errMsgCtry;
				}

			}
			catch(e) {a=e;}
		}

	}


	//var valAge = document.getElementById("txtAge").value;

	if (valAdults==0 && valYouth==0 && valChildren==0 && valSeniors==0) {
		if (errMsg != "") {
			errMsg = errMsg + "<br>";
		}
		errMsg = errMsg + "Please select at least one traveler";
	}

	/*if (valYouth!=0 & valAge=="") {
		if (errMsg != "") {
			errMsg = errMsg + "<br>";
		}
		errMsg = errMsg + "Please enter a youth age";
	}*/

	if (errMsg=="") {
		displayResults();
	}
	else {
		document.getElementById("errMessage").innerHTML = errMsg;
		showBox("errBox");
	}
}

function displayResults()
{
    var nDest=numSpan-1;
	document.getElementById("numDest").value = nDest;
	document.searchPasses.submit();
}

function checkSelect(index)
{
	alert (document.getElementById("txtDestination"+index).value);
}

function CheckSelectCountry(value, index)
{
	try
	{
		var url;

		var intSel =0

		url="/includes/GetPassData.asp?type=3&input=" + value + "&AFF=" + AFF;//&cacheclear=true";


		Xmlreq.open("GET", url, false);
		Xmlreq.send(null);
		if (Xmlreq.readyState == 4) {
			if(Xmlreq.status == 200) 
			{			
				var xml = Xmlreq.responseText;
				//alert(xml);
				if (xml=='') intSel = '0';
				else intSel = xml
			}
		} 

		//hideAllSelect();	

		if (intSel=="3") {
			selectsTotal =3
			document.getElementById("Countries_" + index).style.display = "block";
			document.getElementById("txtDestination_" + index +"_1").style.display = "block";
			document.getElementById("txtDestination_" + index +"_2").style.display = "block";
			document.getElementById("txtDestination_" + index +"_3").style.display = "block";
			document.getElementById("txtDestination_" + index +"_4").style.display = "none";
			document.getElementById("txtDestination_" + index +"_5").style.display = "none";
		}

		if (intSel=="4") {
			selectsTotal =4
			document.getElementById("Countries_" + index).style.display = "block";
			document.getElementById("txtDestination_" + index +"_1").style.display = "block";
			document.getElementById("txtDestination_" + index +"_2").style.display = "block";
			document.getElementById("txtDestination_" + index +"_3").style.display = "block";
			document.getElementById("txtDestination_" + index +"_4").style.display = "block";
			document.getElementById("txtDestination_" + index +"_5").style.display = "none";
		}

		if (intSel=="5") {
			selectsTotal =5
			document.getElementById("Countries_" + index).style.display = "block";
			document.getElementById("txtDestination_" + index +"_1").style.display = "block";
			document.getElementById("txtDestination_" + index +"_2").style.display = "block";
			document.getElementById("txtDestination_" + index +"_3").style.display = "block";
			document.getElementById("txtDestination_" + index +"_4").style.display = "block";
			document.getElementById("txtDestination_" + index +"_5").style.display = "block";
		}

		if (intSel=="0") {
			hideSelect(index);	
			clearCountries(index);
		}

	}
	catch(e) { a=e;}
}


function hideAllSelect()
{
	document.getElementById("Countries_1").style.display = "none";
	document.getElementById("Countries_2").style.display = "none";
	document.getElementById("Countries_3").style.display = "none";
	document.getElementById("Countries_4").style.display = "none";
	document.getElementById("Countries_5").style.display = "none";
	document.getElementById("Countries_6").style.display = "none";
}

function hideSelect(index)
{
	document.getElementById("Countries_" + index).style.display = "none";
}


//********************
//* Select Countries *
//********************
<!--
var countryNames= new Array('Austria', 'Benelux', 'Bulgaria/Serbia/Montenegro', 'Denmark', 'Finland',
					'France', 'Germany','Greece', 'Hungary',
					'Ireland', 'Italy', 'Norway', 'Portugal',
					'Romania', 'Croatia/Slovenia', 'Spain', 'Sweden', 'Switzerland', 'Czech Republic');

var adjoinedCountries= new Array();
adjoinedCountries['Austria']= new Array(6, 8, 10, 14, 17, 18);
adjoinedCountries['Benelux']= new Array(5, 6, 9);
adjoinedCountries['Bulgaria/Serbia/Montenegro']= new Array(7, 8, 13, 14);
adjoinedCountries['Czech Republic']= new Array(6, 0);
adjoinedCountries['Denmark']= new Array(6, 11, 16);
adjoinedCountries['Finland']= new Array(6, 16);
adjoinedCountries['France']= new Array(1, 6, 9, 10, 15, 17);
adjoinedCountries['Germany']= new Array(0, 1, 3, 4, 5, 16, 17, 18);
adjoinedCountries['Greece']= new Array(2, 10);
adjoinedCountries['Hungary']= new Array(0, 2, 13, 14);
adjoinedCountries['Ireland']= new Array(1, 5);
adjoinedCountries['Italy']= new Array(0, 5, 7, 14, 15, 17);
adjoinedCountries['Norway']= new Array(3, 16);
adjoinedCountries['Portugal']= new Array('15');
adjoinedCountries['Romania']= new Array(2, 8);
adjoinedCountries['Croatia/Slovenia']= new Array(0, 2, 8, 10);
adjoinedCountries['Spain']= new Array(5, 10, 12);
adjoinedCountries['Sweden']= new Array(3, 4, 6, 11);
adjoinedCountries['Switzerland']= new Array(0, 5, 6, 10);


function alreadyInArray(arr, find) 
{
	for (var i=0; i< arr.length; i++) {
		if (find == arr[i]) {
			return true;
		}
	}
	return false;
}

function alreadySelected(find, selectToFill,index) 
{
	for (var i= selectToFill - 1; i> 0; i--) {
		var s= document.searchPasses.elements["Country" + i + "_" + index + "_" + i];
		if (find == s.options[s.selectedIndex].value) {
			return true;
		}
	}
	return false;
}

function getCountryArray(selectToFill,index) 
{
	var countries= new Array();

	for (var i= selectToFill - 1; i> 0; i--){
		var select= document.searchPasses.elements["Country" + i + "_" + index + "_" + i];
		var idx= select.options[select.selectedIndex].value;

		for (var j= 0; j< adjoinedCountries[idx].length; j++) {
			var c= countryNames[adjoinedCountries[idx][j]];
			if (!alreadySelected(c, selectToFill, index)) {
				if (!alreadyInArray(countries, c)) {
					countries[countries.length]= c;
				}
			}
		}
	}
	countries.sort();
	return countries;
}

function fillBox(selectToFill, countries,index) 
{

    if (selectToFill<=selectsTotal)
    {

	var select= document.searchPasses.elements["Country" + selectToFill + "_" + index + "_" + selectToFill ];

	select.options[select.options.length]=
	new Option("------------------------");
	for (var i= 0; i< countries.length; i++) {
		select.options[select.options.length]=
		new Option(countries[i], countries[i]);
	}
    }	
}

function setSelects(currentSelect, index) 
{
	var selectToFill= currentSelect + 1;

	for (var i= selectToFill; i<= selectsTotal; i++) {
		document.searchPasses.elements["Country" + i + "_" + index + "_" + i].options.length= 1;
		document.searchPasses.elements["Country" + i + "_" + index + "_" + i].options[0].selected= true;
	}
	if (document.searchPasses.elements["Country" + currentSelect + "_" + index + "_" + currentSelect].options[
	document.searchPasses.elements["Country" + currentSelect + "_" + index + "_" + currentSelect].selectedIndex
	].value) {
		fillBox(selectToFill, getCountryArray(selectToFill,index),index);
	}
}

function onLoadSetup() 
{
	var selectedIndexes= new Array(3);

	for (var i= 1; i<= selectsTotal; i++) {
		selectedIndexes[i - 1]=
		document.searchPasses.elements["Country" + i].selectedIndex;
	}
	for (var i= 1; i< selectsTotal; i++) {
		setSelects(i);
		var idx= i + 1;
		document.searchPasses.elements["Country" + idx].
		options[selectedIndexes[idx - 1]].selected= true;
	}
}



function checkSelection()
{
	if (document.searchPasses.Country1.selectedIndex < 2)
	{
		alert("You must choose Country 1 first!")
		document.orderform.Country1.focus()
	}
	else
	{
		setSelects(2)
	}
}
  
function clearCountries(index)
{
	//alert(document.searchPasses.elements["Country1_" + index + "_1"]);
	document.searchPasses.elements["Country1_" + index + "_1"].options[0].selected= true;
	document.searchPasses.elements["Country2_" + index + "_2"].options[0].selected= true;
	document.searchPasses.elements["Country3_" + index + "_3"].options[0].selected= true;
	document.searchPasses.elements["Country4_" + index + "_4"].options[0].selected= true;
	document.searchPasses.elements["Country5_" + index + "_5"].options[0].selected= true;

}


function CheckMinPassengers(value)
{
	try
	{
		var url;

		var intSel =1

		url="/includes/GetPassData.asp?type=4&input=" + value + "&AFF=" + AFF;//&cacheclear=true";

                //alert(url);

		Xmlreq.open("GET", url, false);
		Xmlreq.send(null);
		if (Xmlreq.readyState == 4) {
			if(Xmlreq.status == 200) 
			{			
				var xml = Xmlreq.responseText;
				//alert(xml);
				if (xml=='') intSel = '1';
				else intSel = xml
			}
		} 
		
		//alert(intSel);

		return 	intSel;


	}
	catch(e) { a=e;}
}	
