//*** AJAX related functions
// Generic panel retrieve

function requestChangeUpperCentral(which) {
    dojo.io.bind({
        url: '/pages/coreContent/'+which,
        handler: changeUpperCentralCallback
    });
}

// Upper central callback to change display

function changeUpperCentralCallback(type, data, evt)
{
	var centralObjOutput = dojo.byId('upperContent');
    centralObjOutput.innerHTML = data;
}

// Generic left full panel retrieve

function requestChangeLeft(which) {
    dojo.io.bind({
        url: '/pages/leftContent/'+which,
        handler: changeUpperCentralCallback
    });
}

// Upper central callback to change display

function changeLeftCallback(type, data, evt)
{
	var leftObjOutput = dojo.byId('leftContent');
    leftObjOutput.innerHTML = data;
}

// Generic left sub panel retrieve

function requestChangeSubLeft1(which) {
    dojo.io.bind({
        url: '/pages/leftContent/'+which,
        handler: changeSubLeft1Callback
    });
}

function requestChangeSubLeft2(which) {
    dojo.io.bind({
        url: '/pages/leftContent/'+which,
        handler: changeSubLeft2Callback
    });
}

// Sub Left callback to change display

function changeSubLeft1Callback(type, data, evt)
{
	var leftObjOutput = dojo.byId('subLeftContent1');
	if (data == '') leftObjOutput.style.display="none";
	else leftObjOutput.style.display="block";
    leftObjOutput.innerHTML = data;
	changeSubLeft2Callback(type,'',evt);
}

function changeSubLeft2Callback(type, data, evt)
{
	var leftObjOutput = dojo.byId('subLeftContent2');
	if (data == '') leftObjOutput.style.display="none";
	else leftObjOutput.style.display="block";
    leftObjOutput.innerHTML = data;
}

//*** End of AJAX

function closeSubMenu(submenu) {
	// Make the submenu visible
	var style = document.getElementById(submenu).style.display;
	if (style=="none") {
		document.getElementById(submenu).style.display="block";
	}	
	else {
		document.getElementById(submenu).style.display="none";
	}
}

function selectPanel(panel, li) {
	// Make the selected panel visible and make all others invisible
	var style = document.getElementById(panel).style.display;
	if (style=="none") {
		document.getElementById("ActivitiesPanel").style.display="none";
		document.getElementById("SightsPanel").style.display="none";
		document.getElementById("TimingPanel").style.display="none";
		document.getElementById("TransportPanel").style.display="none";
		document.getElementById("PacePanel").style.display="none";
		document.getElementById("BudgetPanel").style.display="none";
		document.getElementById("ComfortPanel").style.display="none";
		document.getElementById("BordersPanel").style.display="none";

		document.getElementById(panel).style.display="block";

		document.getElementById("ActivitiesB").className="inactive";
		document.getElementById("SightsB").className="inactive";
		document.getElementById("TimingB").className="inactive";
		document.getElementById("TransportB").className="inactive";
		document.getElementById("PaceB").className="inactive";
		document.getElementById("BudgetB").className="inactive";
		document.getElementById("ComfortB").className="inactive";
		document.getElementById("BordersB").className="inactive";

		document.getElementById(li).className="active";
	}	
}

function selectResultsPanel(panel, li) {
	// Make the selected panel visible and make all others invisible
	var style = document.getElementById(panel).style.display;
	if (style=="none") {
		document.getElementById("DistancePanel").style.display="none";
		document.getElementById("TimePanel").style.display="none";
		document.getElementById("TourPanel").style.display="none";
		document.getElementById("SlidePanel").style.display="none";
		document.getElementById("MoviePanel").style.display="none";

		document.getElementById(panel).style.display="block";

		document.getElementById("DistanceB").className="inactive";
		document.getElementById("TimeB").className="inactive";
		document.getElementById("TourB").className="inactive";
		document.getElementById("SlideB").className="inactive";
		document.getElementById("MovieB").className="inactive";

		document.getElementById(li).className="active";
	}	
}

function selectRoResultsPanel(panel, li) {
	// Make the selected panel visible and make all others invisible
	var style = document.getElementById(panel).style.display;
	if (style=="none") {
		document.getElementById("DistancePanel").style.display="none";
		document.getElementById("TimePanel").style.display="none";
		document.getElementById("TourPanel").style.display="none";
		document.getElementById("SlidePanel").style.display="none";
		document.getElementById("MoviePanel").style.display="none";

		document.getElementById(panel).style.display="block";

		document.getElementById("DistanceB").className="roInactive";
		document.getElementById("TimeB").className="roInactive";
		document.getElementById("TourB").className="roInactive";
		document.getElementById("SlideB").className="roInactive";
		document.getElementById("MovieB").className="roInactive";

		document.getElementById(li).className="roActive";
	}	
}

function selectStatResultsPanel(panel, li) {
	// Make the selected panel visible and make all others invisible
	var style = document.getElementById(panel).style.display;
	if (style=="none") {
		document.getElementById("DistancePanel").style.display="none";
		document.getElementById("TimePanel").style.display="none";
		document.getElementById("TourPanel").style.display="none";
		document.getElementById("BackPanel").style.display="none";
		document.getElementById("LinksPanel").style.display="none";
		document.getElementById("ShopPanel").style.display="none";

		document.getElementById(panel).style.display="block";

		document.getElementById("DistanceB").className="roInactive";
		document.getElementById("TimeB").className="roInactive";
		document.getElementById("TourB").className="roInactive";
		document.getElementById("BackB").className="roInactive";
		document.getElementById("LinksB").className="roInactive";
		document.getElementById("ShopB").className="roInactive";

		document.getElementById(li).className="roActive";
	}	
}

function get_url_param(name)
{  
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
var regexS = "[\\?&]"+name+"=([^&#]*)";  
var regex = new RegExp( regexS );  
var results = regex.exec( window.location.href );  
if( results == null )    return "";  
else return results[1];
}

function selectPanelOnLoad() {
	var panel = get_url_param('panel');
	if ( panel != "" ) {
		selectPanel(panel+'Panel', panel+'B');
	}
}

// Build route form

function addNewRoute() {
	title = document.getElementById('routetitle').value;
	if (title != "") {
		document.location='add_new_route.php?title='+title;
	}
}

function editRouteName(routeId) {
	title = document.getElementById('routetitle').value;
	if (title != "") {
		document.location='update_route_name.php?routeId='+routeId+'&title='+title;
	}
}

function submitRoutePackage(routeId) {
	document.location='submit_route.php?routeId='+routeId;
}

function editRoute(routeId) {
	document.location='buildRoute.php?routeId='+routeId;
}

function showRoute(routeId) {
	document.location='showRoute.php?routeId='+routeId;
}

function delRoute(routeId) {
	document.location='del_route.php?routeId='+routeId;
}

function addSideJourney(posn,routeId) {
	document.location='addSideJourney.php?posn='+posn+'&routeId='+routeId;
}

function editSideTrip(posn,routeId) {
	document.location='editSideJourney.php?posn='+posn+'&routeId='+routeId;
}

function delSideTrip(posn,routeId) {
	document.location='del_side_trip.php?posn='+posn+'&routeId='+routeId;
}

function addBaseJourney(posn,routeId) {
	document.location='addBaseJourney.php?posn='+posn+'&routeId='+routeId;
}

function editBaseJourney(posn,routeId) {
	document.location='editBaseJourney.php?posn='+posn+'&routeId='+routeId;
}

function delBaseJourney(posn,routeId) {
	document.location='del_base_journey.php?posn='+posn+'&routeId='+routeId;
}

function refocus(formField) {
    var theForm = document.forms['journey'];
    theForm.elements[formField].focus();
}

function dateChange(formFieldRoot, fieldSpecific) {
    var theForm = document.forms['journey'];
    // Make the arrival date default to the departure
    if (formFieldRoot == 'departure') {
    	theForm.elements['arrival'+fieldSpecific].selectedIndex = theForm.elements['departure'+fieldSpecific].selectedIndex;
    }
}

function showLeg(legId, numLegs) {
    var theForm = document.forms['journey'];
    theForm.legCount.value = numLegs;	
    
    // Set combos depending on where button clicked
    var newLeafRoot = "transport"+legId.charAt(3)+"Arrival";
    var parentViaNum = legId.charAt(3)-1;
    var parentLeafRoot = "transport"+parentViaNum+"Arrival"
    theForm.elements[newLeafRoot+"Country"].value = theForm.elements[parentLeafRoot+"Country"].value;
    requestPlacesForCountryChange(newLeafRoot);    
    	
    document.getElementById(legId).style.display="block";
}

function hideLeg(legId, numLegs) {
    var theForm = document.forms['journey'];
	theForm.legCount.value = numLegs;
	index = (numLegs*1)+1;
	hideVia(index+'-3','2','stopCount'+index);	
	hideVia(index+'-2','1','stopCount'+index);	
	hideVia(index+'-1','0','stopCount'+index);	
        showButton('leg'+index+'addvia');
	document.getElementById(legId).style.display="none";
}

function showButton(buttonId) {
	document.getElementById(buttonId).style.display="block";
}

function hideButton(buttonId) {
	document.getElementById(buttonId).style.display="none";
}

function showVia(viaId, numStops, stopCountId) {
    var theForm = document.forms['journey'];
    theForm.elements[stopCountId].value = numStops;
    
    // Set combos depending on where button clicked
    var newLeafRoot = "transport"+viaId.charAt(0)+"Via"+viaId.charAt(2)+"Arrival";
    var parentViaNum = viaId.charAt(2)-1;
    var parentLeafRoot = "transport"+viaId.charAt(0)+"Via"+parentViaNum+"Arrival"
    if (numStops == '1') {
    	parentLeafRoot = "transport"+viaId.charAt(0)+"Arrival"
    }
    theForm.elements[newLeafRoot+"Country"].value = theForm.elements[parentLeafRoot+"Country"].value;
    requestPlacesForCountryChange(newLeafRoot);
    
    document.getElementById(viaId).style.display="block";
}

function hideVia(viaId, numStops, stopCountId) {
    var theForm = document.forms['journey'];
	theForm.elements[stopCountId].value = numStops;
	document.getElementById(viaId).style.display="none";
}

var savedFormFieldRoot = 'departure'; // Default

function requestPlacesForCountryChange(formFieldRoot, tripId) {
	if ( tripId === undefined ) {
	   tripId = '-1';
	}
    countryFormField = formFieldRoot + 'Country';
    var theForm = document.forms['journey'];
    countrySelection = theForm.elements[countryFormField].value;
    var placesSelectorUrl;
	if (countrySelection == 'ZZZ') {
		placesSelectorUrl = '/trip/places_selector.php?country='+countrySelection+'&formFieldRoot='+formFieldRoot+'&tripId='+tripId;
	}
	else {
		placesSelectorUrl = '/trip/places_selector.php?country='+countrySelection+'&formFieldRoot='+formFieldRoot;
	}
    savedFormFieldRoot = formFieldRoot;
    if (countrySelection == 'NULL') {
        document.forms['journey'].elements["departureCountry"].focus();
    }
    else {
        dojo.io.bind({
            url: placesSelectorUrl,
            encoding: "utf-8",
            handler: changePlacesForCountryCallback
        });
    }
}

function changePlacesForCountryCallback(type, data, evt)
{
    countryFormField = savedFormFieldRoot+ 'Place';
    if (type != 'error') {
        var countryCallbackOutput = document.getElementById(countryFormField);
        countryCallbackOutput.innerHTML = data;
        document.forms['journey'].elements[countryFormField].focus();
    }

    checkForNewRequest(savedFormFieldRoot);
}

function checkForNewRequest(formFieldRoot) {
    placeFormField = formFieldRoot + 'Place';
    var theForm = document.forms['journey'];
    placeSelection = theForm.elements[placeFormField].value;
    if (placeSelection == 'NEW') {
                newElement = theForm.elements[placeFormField+'New'];
		newElement.value="";        
		newElement.style.color="#000000";        
		newElement.style.backgroundColor="#ffffff";        
		newElement.disabled=false;  
                newElement.focus();       
    }
    else {
        if (formFieldRoot.search(/Via/) != -1) {
	    theForm.elements[placeFormField+'New'].style.color="#faa";        
	    theForm.elements[placeFormField+'New'].style.backgroundColor="#faa";  
        }
        else if (formFieldRoot.search(/transport/) != -1) {
	    theForm.elements[placeFormField+'New'].style.color="#ccf";        
	    theForm.elements[placeFormField+'New'].style.backgroundColor="#ccf";  
        }
        else {
	    theForm.elements[placeFormField+'New'].style.color="#e8f8f8";        
	    theForm.elements[placeFormField+'New'].style.backgroundColor="#e8f8f8";  
        }      
	theForm.elements[placeFormField+'New'].disabled=true;        
    }
}

// Get number of 3 letter month
function getMonthNum(name) {
    if (name == "Jan") {
        return "01";
    }
    if (name == "Feb") {
        return "02";
    }
    if (name == "Mar") {
        return "03";
    }
    if (name == "Apr") {
        return "04";
    }
    if (name == "May") {
        return "05";
    }
    if (name == "Jun") {
        return "06";
    }
    if (name == "Jul") {
        return "07";
    }
    if (name == "Aug") {
        return "08";
    }
    if (name == "Sep") {
        return "09";
    }
    if (name == "Oct") {
        return "10";
    }
    if (name == "Nov") {
        return "11";
    }
    if (name == "Dec") {
        return "12";
    }
}

// See if first date is later than the second date
function laterDate(firstDate, secondDate) {
	if (firstDate.substr(0,2) == "NO") {
		return "false";
	}
	if (secondDate.substr(0,2) == "NO") {
		return "false";
	}
	firstYear = firstDate.substr(0,4);
	secondYear = secondDate.substr(0,4);
	if (firstYear > secondYear) {
		return "true";
	}
	if (firstYear < secondYear) {
		return "false";
	}
	firstMonth = firstDate.substr(5,3);
	secondMonth = secondDate.substr(5,3);
	if (getMonthNum(firstMonth) > getMonthNum(secondMonth)) {
		return "true";
	}
	if (getMonthNum(firstMonth) < getMonthNum(secondMonth)) {
		return "false";
	}
	firstDay = firstDate.substr(9,2);
	secondDay = secondDate.substr(9,2);
	if (firstDay > secondDay) {
		return "true";
	}
	else {
		return "false";
	}
}

function checkSideJourneyForm(minDate, maxDate) {
    var theForm = document.forms['journey'];
    
    var depDate = ''+theForm.elements['departureYear'].value+"-"+theForm.elements['departureMonth'].value+"-"+
    	theForm.elements['departureDay'].value;
    var arrDate = ''+theForm.elements['arrivalYear'].value+"-"+theForm.elements['arrivalMonth'].value+"-"+
    	theForm.elements['arrivalDay'].value;
    	
    if (laterDate(minDate, depDate) == "true") {
       alert("Departure date too early!");
       theForm.elements['departureDay'].focus();
       return false;       
    }
    if (laterDate(arrDate, maxDate) == "true") {
       alert("Arrival date too late!");
       theForm.elements['arrivalDay'].focus();
       return false;       
    }
    if (laterDate(depDate, arrDate) == "true") {
       alert("Arrival date cannot be earlier than departure date!");
       theForm.elements['arrivalDay'].focus();
       return false;       
    }
    
    var name = theForm.elements['name'];
    if (name.value == '') {
       alert("Please enter a trip title!");
       name.focus();
       return false;       
    }
    var transportArrivalCountry= theForm.elements['transport1ArrivalCountry'];
    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
       alert("You must enter at least one leg in addition to the automatic return leg!");
       transportArrivalCountry.focus();
       return false;       
    }
    var transportArrivalPlace= theForm.elements['transport1ArrivalPlace'];
    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
       alert("You must enter at least one leg in addition to the automatic return leg!");
       transportArrivalPlace.focus();
       return false;       
    }
    var waypointStops=theForm.elements['stopCount1'];
    var stop=1;
    while (waypointStops.value >= stop) {
	    var transportArrivalCountry= theForm.elements['transport1Via'+stop+'ArrivalCountry'];
	    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
	       alert("Either select arrival country for waypoint or remove it!");
	       transportArrivalCountry.focus();
	       return false;       
	    }
	    var transportArrivalPlace= theForm.elements['transport1Via'+stop+'ArrivalPlace'];
	    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
	       alert("Either select arrival place for waypoint or remove it!");
	       transportArrivalPlace.focus();
	       return false;       
	    }
        stop = 1 + stop;
    }
    
    
    var transportLegs=theForm.elements['legCount'];
    var leg=2;
    if (transportLegs.value == '3') {
	    var transportArrivalCountry= theForm.elements['transport'+leg+'ArrivalCountry'];
	    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
	       alert("Either select arrival place for leg " + leg + " or remove it!");
	       transportArrivalCountry.focus();
	       return false;       
	    }
	    var transportArrivalPlace= theForm.elements['transport'+leg+'ArrivalPlace'];
	    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
	       alert("Either select arrival place for leg or remove it!");
	       transportArrivalPlace.focus();
	       return false;       
	    }
    	var waypointStops=theForm.elements['stopCount'+leg];
    	var stop=1;
	    while (waypointStops.value >= stop) {
		    var transportArrivalCountry= theForm.elements['transport'+leg+'Via'+stop+'ArrivalCountry'];
		    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
		       alert("Either select arrival country for waypoint or remove it!");
		       transportArrivalCountry.focus();
		       return false;       
		    }
	            var transportArrivalPlace= theForm.elements['transport'+leg+'Via'+stop+'ArrivalPlace'];
		    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
		       alert("Either select arrival place for waypoint or remove it!");
		       transportArrivalPlace.focus();
		       return false;       
		    }
	        stop = 1 + stop;
	    }
        leg = 1 + leg;
    }
    var waypointStops=theForm.elements['stopCount5'];
    var stop=1;
    while (waypointStops.value >= stop) {
	    var transportArrivalCountry= theForm.elements['transport5Via'+stop+'ArrivalCountry'];
	    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
	       alert("Either select arrival country for waypoint or remove it!");
	       transportArrivalCountry.focus();
	       return false;       
	    }
	    var transportArrivalPlace= theForm.elements['transport5Via'+stop+'ArrivalPlace'];
	    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
	       alert("Either select arrival place for waypoint or remove it!");
	       transportArrivalPlace.focus();
	       return false;       
	    }
        stop = 1 + stop;
    }

    return true;
}

function checkBaseJourneyForm(minDate) {
    var theForm = document.forms['journey'];
    var depDate = ''+theForm.elements['departureYear'].value+"-"+theForm.elements['departureMonth'].value+"-"+
    	theForm.elements['departureDay'].value;
    var arrDate = ''+theForm.elements['arrivalYear'].value+"-"+theForm.elements['arrivalMonth'].value+"-"+
    	theForm.elements['arrivalDay'].value;
    	
    if (laterDate(minDate, depDate) == "true") {
       alert("Departure date too early!");
       theForm.elements['departureDay'].focus();
       return false;       
    }
    if (laterDate(depDate, arrDate) == "true") {
       alert("Arrival date cannot be earlier than departure date!");
       theForm.elements['arrivalDay'].focus();
       return false;       
    }
    
    var departureCountry= theForm.elements['departureCountry'];
    if (departureCountry.value == 'Select Value' || departureCountry.value == 'NULL') {
       alert("You must enter a departure point!");
       departureCountry.focus();
       return false;       
    }
    var departurePlace= theForm.elements['departurePlace'];
    if (departurePlace.value == 'Select Value' || departurePlace.value == 'NULL') {
       alert("You must enter a departure point!");
       departurePlace.focus();
       return false;       
    }
    var transportArrivalCountry= theForm.elements['transport1ArrivalCountry'];
    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
       alert("You must enter at least one leg!");
       transportArrivalCountry.focus();
       return false;       
    }
    var transportArrivalPlace= theForm.elements['transport1ArrivalPlace'];
    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
       alert("You must enter at least one leg!");
       transport1ArrivalPlace.focus();
       return false;       
    }
    var waypointStops=theForm.elements['stopCount1'];
    var stop=1;
    while (waypointStops.value >= stop) {
	    var transportArrivalCountry= theForm.elements['transport1Via'+stop+'ArrivalCountry'];
	    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
	       alert("Either select arrival country for waypoint or remove it!");
	       transportArrivalCountry.focus();
	       return false;       
	    }
	    var transportArrivalPlace= theForm.elements['transport1Via'+stop+'ArrivalPlace'];
	    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
	       alert("Either select arrival place for waypoint or remove it!");
	       transportArrivalPlace.focus();
	       return false;       
	    }
        stop = 1 + stop;
    }
    
    
    var transportLegs=theForm.elements['legCount'];
    var leg=2;
    while (transportLegs.value >= leg) {
	    var transportArrivalCountry= theForm.elements['transport'+leg+'ArrivalCountry'];
	    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
	       alert("Either select arrival country for leg or remove it!");
	       transportArrivalCountry.focus();
	       return false;       
	    }
	    var transportArrivalPlace= theForm.elements['transport'+leg+'ArrivalPlace'];
	    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
	       alert("Either select arrival place for leg " + leg + " or remove it!");
	       transportArrivalPlace.focus();
	       return false;       
	    }
    	var waypointStops=theForm.elements['stopCount'+leg];
    	var stop=1;
	    while (waypointStops.value >= stop) {
		    var transportArrivalCountry= theForm.elements['transport'+leg+'Via'+stop+'ArrivalCountry'];
		    if (transportArrivalCountry.value == 'Select Value' || transportArrivalCountry.value == 'NULL') {
		       alert("Either select arrival country for waypoint or remove it!");
		       transportArrivalCountry.focus();
		       return false;       
		    }
	            var transportArrivalPlace= theForm.elements['transport'+leg+'Via'+stop+'ArrivalPlace'];
		    if (transportArrivalPlace.value == 'Select Value' || transportArrivalPlace.value == 'NULL') {
		       alert("Either select arrival place for waypoint or remove it!");
		       transportArrivalPlace.focus();
		       return false;       
		    }
	        stop = 1 + stop;
	    }
        leg = 1 + leg;
    }

    return true;
}

function setCounts(gLegCount, gStopCount1, gStopCount2, gStopCount3, gStopCount4, gStopCount5) {
    var theForm = document.forms['journey'];
    theForm.elements['legCount'].value = gLegCount;
    theForm.elements['stopCount1'].value = gStopCount1;
    theForm.elements['stopCount2'].value = gStopCount2;
    theForm.elements['stopCount3'].value = gStopCount3;
    theForm.elements['stopCount4'].value = gStopCount4;
    theForm.elements['stopCount5'].value = gStopCount5;
    if (gStopCount5 > 0) {
    	hideButton('leg5addvia');
    }
    if (gLegCount > 1) {
    	showButton('leg'+gLegCount+'subleg');
    }
}

function changeFlickr(routeId,userId,title) {
	url = document.getElementById('url').value;
        var where_is_mytool=document.getElementById('url').value;
        var mytool_array=where_is_mytool.split("/");
        if (mytool_array[2] == null) {
            mytool_array[2] = '';
        }
	if (url != "") {
		document.location='change_flickr.php?routeId='+routeId+'&url='+mytool_array[0]+'&set='+mytool_array[2]+'&userId='+userId+'&title='+title;
	}
}
function changeYouTube(routeId,userId,title) {
	url = document.getElementById('url').value;
	if (url != "") {
		document.location='change_youtube.php?routeId='+routeId+'&url='+url+'&userId='+userId+'&title='+title;
	}
}

function disableLegs() {
    var theForm = document.forms['journey'];
    legCount = theForm.elements['legCount'].value;
    document.getElementById('leg1').style.display="block";
    if (0+legCount > 1) {
    	document.getElementById('leg2').style.display="block";
    }
    else {
    	document.getElementById('leg2').style.display="none";
		theForm.elements['stopCount2'].value = '0';
		disableWpts('2');
	}    
    if (0+legCount > 2) {
    	document.getElementById('leg3').style.display="block";
    }
    else {
    	document.getElementById('leg3').style.display="none";
		theForm.elements['stopCount3'].value = '0';
		disableWpts('2');
	}    
}

function disableWpts(leg) {
    var theForm = document.forms['journey'];
    stopCount = theForm.elements['stopCount'+leg].value;
    if (0+stopCount > 0) {
    	document.getElementById(leg+'-1').style.display="block";
    }
    else {
    	document.getElementById(leg+'-1').style.display="none";
	}    
    if (0+stopCount > 1) {
    	document.getElementById(leg+'-2').style.display="block";
    }
    else {
    	document.getElementById(leg+'-2').style.display="none";
	}    
    if (0+stopCount > 2) {
    	document.getElementById(leg+'-3').style.display="block";
    }
    else {
    	document.getElementById(leg+'-3').style.display="none";
	}    
}

function disableSideLegs() {
    var theForm = document.forms['journey'];
    legCount = theForm.elements['legCount'].value;
    document.getElementById('leg1').style.display="block";
    document.getElementById('leg3').style.display="block";
    if (0+legCount > 2) {
    	document.getElementById('leg2').style.display="block";
    }
    else {
		document.getElementById('leg2').style.display="none";
		theForm.elements['stopCount2'].value = '0';
		disableWpts('2');
	}    
}



