  function CurrencyFormatted(amount) {
  	var i = parseFloat(amount);
  	if(isNaN(i)) { 
  	  i = 0;
  	}
  	var minus = '';
  	if(i < 0) {
  	  minus = '-';
  	}
  	i = Math.abs(i);
  	i = parseInt((i + .005) * 100);
  	i = i / 100;
  	s = new String(i);
  	if(s.indexOf('.') < 0) { 
  	  //s += '.00';
  	}
  	if(s.indexOf('.') == (s.length - 2)) { 
  	  s += '0';
  	}
  	s = minus + s;
  	//add the comma
  	nStr = s + '';
  	x = nStr.split('.');
  	x1 = x[0];
  	x2 = x.length > 1 ? '.' + x[1] : '';
  	var rgx = /(\d+)(\d{3})/;
  	while (rgx.test(x1)) {
  	  x1 = x1.replace(rgx, '$1' + ',' + '$2');
  	}
  	return '$' + x1 + x2;
  
  }

// this variable used to hold which form was submitted (leftNavByDateYrMonthChannelForm  or
//   searchByDateYrMonthChannelForm)  until the AJAX call getMonths() returns.
var yrMonthChannelForm = null;

	
	// The following two functions - AJAX function getMonths  and the related function 
	// submitYearMonthChannelForm  are for the Year Radio Buttons and the Month Select Box
	// in the Left Nav - Find A Walking Tour Panel and the Middle column of Search Panel 
	// under the World Map 
	// Makes an AJAX call to /vgn-ext-templating/cw/jsp/cwGetMonthSubChannelsFromYearChannel.jsp?yearGUID=" + yearGuid
	// when the user selects a radio button for a year.  It returns the list of individual months for that year that have any 
	// tours scheduled.  
	function getMonths(yearGuid, radioBtn) {
		yrMonthChannelForm = radioBtn.form;
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
	
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("Your browser does not support AJAX!");
					return false;
				}
		    }
		}
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				yrMonthChannelForm.monthOptions.options.length = 0;
				// get the response from cwGetSearchToursFromCountry.jsp and trim spaces
				var allOptions=xmlHttp.responseText.replace(/^\s+/, '');
				// returning the list of month name and url in a list like January,url| February,url|....
				if (allOptions.length > 0) {
					var optionList = allOptions.split("|");
					for (i=0; i < optionList.length; i++) {
						// split the month name from the url
						var indOpt = optionList[i].split(",");
						var opt = indOpt[0];
						var val = indOpt[1];
						yrMonthChannelForm.monthOptions.options[i] = new Option(opt,val);
					}
				} else {
					yrMonthChannelForm.monthOptions.options.length = 0;
				}			
			}
			
		}
		
		var url = "/vgn-ext-templating/cw/jsp/cwGetMonthSubChannelsForYearChannel.jsp?yearGUID=" + yearGuid;
		xmlHttp.open("POST",url ,true);
		xmlHttp.send(null);
	}
	
	// When the user selects the GO button, this will do the redirect to the selected Year-Month Channel
	function submitYearMonthChannelForm(formBtn) {
		if ( formBtn.form.monthOptions.length > 0 )  {
			var submitUrl = formBtn.form.monthOptions.options[formBtn.form.monthOptions.selectedIndex].value;
			if (submitUrl != null  &&  submitUrl.length > 0)  {
		    	window.location.href = submitUrl;
		    }
		}
		return true;
	}

// *************************************************************************************	
	// The following two functions - AJAX function getTours  and the related function 
	// submitTourURL  are for the "Choose A Country" and "Choose A Tour" Select Boxes
	// in the Left Nav - "Search For A Tour" Panel  under the SpotLight Image on the left.
	// World Map 
	// Makes an AJAX call to /vgn-ext-templating/cw/jsp/cwGetSearchToursFromCountry.jsp?countryGUID=" + tour
    // when the user selects a country from the drop down.  It returns the list of individual tours for
    // that country.  If there is only a single tour, then it redirects directly to that tour.
    function getTours(countryOptionsSelect) {
	    var xmlHttp;
	    try {
		// Firefox, Opera 8.0+, Safari
		    xmlHttp=new XMLHttpRequest();
	    } catch (e) {
		// Internet Explorer
		    try {
		        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
			    try {
				    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			    } catch (e) {
				    alert("Your browser does not support AJAX!");
				    return false;
			    }
	        }
	    }
	    xmlHttp.onreadystatechange=function() {
		    if(xmlHttp.readyState==4) {
			    document.tourSearchForm.toursOptions.options.length = 0;
			    // get the response from cwGetSearchToursFromCountry.jsp and trim spaces
			    var allOptions=xmlHttp.responseText.replace(/^\s+/, '');
			    // returning the list of tour name and urls in a list like
			    // Walking Italy|url,Walking Paris,url|....
			    if (allOptions.length > 0) {
				    var optionList = allOptions.split("|");
				    // if there is only 1 tour returned, don't show the All Tours option
				    if (optionList.length == 2)  {
					    var indOpt = optionList[1].split("#");
					    document.tourSearchForm.toursOptions.options[0] = new Option(indOpt[0],indOpt[1]);
					    return true;
				    // more than a single item, show them all
				    } else {
					    for (i=0; i < optionList.length; i++) {
						    // split the tour name from the url
						    var indOpt = optionList[i].split("#");
						    var opt = indOpt[0];
						    var val = indOpt[1];
						    document.tourSearchForm.toursOptions.options[i] = new Option(opt,val);
			    		}
    				}
			    // if no tours are returned, set the default option to All Tours
			    } else {
				document.tourSearchForm.toursOptions.options.length = 0;
				document.tourSearchForm.toursOptions.options[0] = new Option('All Tours','#');
		    	}		
		    }
	    }
	    var selectedCountryGuid = countryOptionsSelect.options[countryOptionsSelect.selectedIndex].value;
	    selectedCountryGuid = selectedCountryGuid.replace("\n", '');

	    if (selectedCountryGuid.length != 40) {
		    document.tourSearchForm.toursOptions.options.length = 0;
		    document.tourSearchForm.toursOptions.options[0] = new Option('All Tours','#');
		    return true;
	    }
	
	    var url = "/vgn-ext-templating/cw/jsp/cwGetSearchToursFromCountry.jsp?countryGUID=" + selectedCountryGuid;
	    xmlHttp.open("POST",url ,true);
	    xmlHttp.send(null);
    }


    // When the user selects the GO button in the "Search For a Tour" panel under the Spotlight Image in the left column
    //  this function will do the redirect to the selected tour
    function submitTourURL() {
	    location.href = document.tourSearchForm.toursOptions.options[document.tourSearchForm.toursOptions.selectedIndex].value;
	    return true;
    }
	

    
	// Javascript for changing the tabs on the cwTourContentInstance.jsp
	function setVisible (ob_block) {
    	ob_block.style.display="block";
	}

	function setHidden (ob_block) {
    	ob_block.style.display="none";
	}

	function initMenu (ob_ul,ob_tab) {
	// Traverses the <li> children of the <ul> object passed to initMenu
	// Naming convention:
	// tabs = "tab_{name}"
	// DHTML blocks = "block_{name}"
	// where {name} associates the tab with the appropriate child DIV 
	// in the "demo_content" DIV

    	for (i=0;i<ob_ul.childNodes.length;i++) {
       		if (ob_ul.childNodes[i].id) {
          		if (ob_tab==ob_ul.childNodes[i]) {
            		ob_ul.childNodes[i].firstChild.className="here";
             		//can test for applet-based blocks here to change the setVisible command
             		setVisible(document.getElementById("block_" + ob_ul.childNodes[i].id.substr(4)));
          		} else {
            		ob_ul.childNodes[i].firstChild.className="";
             		//can test for applet-based blocks here to change the setHidden command
             		setHidden(document.getElementById("block_" + ob_ul.childNodes[i].id.substr(4)));
          		}    
       		}
    	}
	}

	function changeTab(ob_tab) {
   		if (ob_tab!=currentTab) {
    		oldTab = currentTab;
    		ob_tab.childNodes[0].className="here";
    		oldTab.childNodes[0].className="";
    		//insert test for applet-based block
    		setHidden(document.getElementById("block_" + oldTab.id.substr(4)));
    		setVisible(document.getElementById("block_" + ob_tab.id.substr(4)));
    		currentTab=ob_tab;
    		
    		// for google analytics
    		pageTracker._trackEvent('Tabs', currentTab.id.substr(4), document.title);
		}   
	}
	
	// Get the selected tab from a request parameter named tourTab
	function getTourTabParameter() {
		var tabToReturn = document.getElementById('tab_Tour_Overview');
	   // Add "=" to the parameter name (i.e. parameterName=value)   
		var queryString = window.top.location.search.substring(1);
		var parameterName = "tourTab=";
		if (queryString.length > 0) {
			// Find the beginning of the string 
			var begin = queryString.indexOf(parameterName);      
			// If the parameter name is not found, skip it, otherwise return the value      
			if ( begin != -1 ) {         
				// Add the length (integer) to the beginning         
				begin += parameterName.length;         
				// Multiple parameters are separated by the "&" sign         
				var end = queryString.indexOf ( "&" , begin );      
				if (end == -1 ) {         
					end = queryString.length;    
				}
				var parameterValue = queryString.substring (begin, end);
				if (parameterValue == "overview") {
					tabToReturn = document.getElementById('tab_Tour_Overview');
				} else if (parameterValue == "details") {
					tabToReturn = document.getElementById('tab_Details');
				} else if (parameterValue == "itinerary") {
					tabToReturn = document.getElementById('tab_Itinerary');				 
				} else if (parameterValue == "accommodations") {
					tabToReturn = document.getElementById('tab_Accommodations');
				} else if (parameterValue == "guides") {
					tabToReturn = document.getElementById('tab_Your_Guides');
				} else if (parameterValue == "deckplans") {
					tabToReturn = document.getElementById('tab_Deck_Plans');
				} else if (parameterValue == "motorcoach") {
					tabToReturn = document.getElementById('tab_Motor_Coach_Experience');
				} else {
					tabToReturn = document.getElementById('tab_Tour_Overview');
				}
			}   
		}
		return tabToReturn;
	}
	// Javascript for changing the tabs on the cwTourContentInstance.jsp 
	
	  // function for the slideshow to make sure we get the correct number of slides.  Need 
	  // to get the href attribute from the first slide id=slide0, 
	  // and set them on the link.  Then remove the attribute from the hidden slide0.
	  // In order to switch from the image to the link, need to make sure only one of them
	  // have the rel="tour-slides" set
	  function openSlideshow(slides) {
		  var firstSlide = document.getElementById("slide0");
		  var slideAttrs = firstSlide.firstChild.attributes;
		  var nodeToChange = slides.firstChild;
		  nodeToChange.setAttribute("href", slideAttrs["href"].value);
		  nodeToChange.setAttribute("title", slideAttrs["title"].value);
		  nodeToChange.setAttribute("rel", "tour-slides");

		  if (slides != document.getElementById('slideImage1')) {
			  document.getElementById('slideImage1').firstChild.setAttribute("rel", "");
		  }
		  if (slides != document.getElementById('slideImage2')) {
			  document.getElementById('slideImage2').firstChild.setAttribute("rel", "");
		  }
		  if (slides != document.getElementById('slideImage3')) {
			  document.getElementById('slideImage3').firstChild.setAttribute("rel", "");
		  }		  
		  if (slides != document.getElementById('slideLink1')) {
			  document.getElementById('slideLink1').firstChild.setAttribute("rel", "");
		  }
		  if (slides != document.getElementById('slideLink2')) {
			  document.getElementById('slideLink2').firstChild.setAttribute("rel", "");
		  }
		  if (slides != document.getElementById('slideLink3')) {
			  document.getElementById('slideLink3').firstChild.setAttribute("rel", "");
		  }		  

		  
		  // remove the attribute from the first slide
		  firstSlide.firstChild.removeAttribute("rel")

} 

// For YMT BRC Validation

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function IsEmail(email) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}
return (false)
}


function checkBasicForm(formName) {

	var basicForm=document.form1;
	var ready = false;
	var message = "";
	var stripped = basicForm['telephone'].value.replace(/[\(\)\.\-\ ]/g, '');
	
	if (!basicForm['first'].value) {
		message += "First Name is missing\n";
		ready = false;
	}

	if (!basicForm['last'].value) {
		message += "Last Name is missing\n";
		ready = false;
	}

	if (!basicForm['email.override'].value) {
		message += "E-mail Address is missing\n";
		ready = false;
	} else if (!IsEmail(basicForm['email.override'].value)){
		message += "The e-mail address contains an error, please re-enter\n";
		ready = false;
	}

	if (basicForm['telephone'].value) {
		if (!IsNumeric(stripped)){
			message += "Your telephone number contains incorrect characters\n";
			ready = false;
		} else if (!(stripped.length == 10)) {
                	message += "The telephone number is the wrong length. Make sure you included an area code.\n";
                	ready = false;
		}	
	}

	if (!basicForm['timetocall'].value) {
		basicForm['timetocall'].value = "none provided";	
		}

	if (message!="") {
	alert("Please correct the following:\n\n" + message);
	return false;
	}

        if (ready!=false){
             basicForm.submit();
        }

}

function validateBrc(fname) {
        var f=document.brc_form;
        var em = "";
        var ready = null;
        var stripped = document.getElementById('Ecom_BillTo_Telecom_Phone_Number').value.replace(/[\(\)\.\-\ ]/g, '');	

        if (!f["Ecom_BillTo_Postal_Name_First"].value) {
                em += "First Name is missing\n";
                ready = false;
        }

        if (!f["Ecom_BillTo_Postal_Name_Last"].value) {
                em += "Last Name is missing\n";
                ready = false;
        }

        if (!f["Ecom_BillTo_Online_Email"].value) {
                em += "Email is missing\n";
                ready = false;
        } else if (!IsEmail(document.getElementById('Ecom_BillTo_Online_Email').value)){
		em += "The e-mail address is invalid, please re-enter\n";
		ready = false;	
	}
       
 
        if (!f["Ecom_BillTo_Telecom_Phone_Number"].value) {
        	em += "Telephone is missing\n";
        	ready = false;
        } else if (!IsNumeric(stripped)) {
        	em += "The phone number contains illegal characters.\n";
        	ready = false;
    	} else if (!(stripped.length == 10)) {
        	em += "The phone number is the wrong length. Make sure you included an area code.\n";
        	ready = false;
    	} 


        if (em!=""){
        alert("Please correct the following:\n\n" + em);
        return false;
        }

	
	document.getElementById('dm.email.address').value = document.getElementById('Ecom_BillTo_Online_Email').value;
	document.getElementById('key_value').value = document.getElementById('Ecom_BillTo_Online_Email').value;
	document.getElementById('dm.brc.name.first').value = document.getElementById('Ecom_BillTo_Postal_Name_First').value;
	document.getElementById('dm.brc.name.middle').value = document.getElementById('Ecom_BillTo_Postal_Name_Middle').value;
	document.getElementById('dm.brc.name.last').value = document.getElementById('Ecom_BillTo_Postal_Name_Last').value;
	document.getElementById('dm.brc.name.suffix').value = document.getElementById('Ecom_BillTo_Postal_Name_Suffix').value;
	document.getElementById('dm.brc.address.first_line').value = document.getElementById('Ecom_BillTo_Postal_Street_Line1').value;
	document.getElementById('dm.brc.address.second_line').value = document.getElementById('Ecom_BillTo_Postal_Street_Line2').value;
	document.getElementById('dm.brc.address.city').value = document.getElementById('Ecom_BillTo_Postal_City').value;
	document.getElementById('dm.brc.address.state').value = document.getElementById('Ecom_BillTo_Postal_StateProv').value;
	document.getElementById('dm.brc.address.postal_code').value = document.getElementById('Ecom_BillTo_Postal_PostalCode').value;
	document.getElementById('dm.brc.address.country').value = document.getElementById('Ecom_BillTo_Postal_CountryCode').value;
	document.getElementById('dm.brc.telephone').value = document.getElementById('Ecom_BillTo_Telecom_Phone_Number').value;
	document.getElementById('dm.brc.email_address').value = document.getElementById('Ecom_BillTo_Online_Email').value;
	document.getElementById('redir_resp').value = "http://www.ymtvacations.com/Travel+Community/$100+Coupon";
		
	if(document.getElementById("dm.brc.answer_2").value!=""){
	document.getElementById("dm.brc.question_2").value="x2_Next vacation";
	}

	if(document.getElementById("dm.brc.answer_3").value!=""){
        document.getElementById("dm.brc.question_3").value="x3_How often vacation";
        }


	if (document.getElementById('dm.brc.optflag').value == 'Yes'){
		document.getElementById('dm.category.global.opt_in').value = true;
	} else {
		document.getElementById('dm.category.global.opt_in').value = false;
	}

        if (ready!=false){
             f.submit();
        }
}
