var ajaxRootElementId = "ajax_root";
var ajaxLoadingElementId = "ajax_loading";
var ajaxAddress = null;
var contentId = null;
var contentAddress = null;
var contentBaseAddress = null;
var contentTitle = null;
var contentItemTitle = null;
var contentLanguage = null;

function registerInit(callback) {
	/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", callback, false);
	}
	/* for other browsers */
	window.onload = callback;
}

registerInit(init);

var initOnce = { succes : false };
function init() {
	if (!initOnce.succes) {
		initOnce.succes = true;
		if (typeof(initLightBox) !== 'undefined') {
			initLightBox();
		}
		if ($('print_client_details') != null) {
			setTimeout("window.print()", 50);
		}
		initLinks();
		initResevationForm();
	}
};

function addEvent(element, type, handle) {
	if (typeof element != "undefined") {
		if (typeof window.attachEvent != "undefined") {
			// Internet Explorer
			element.attachEvent("on" + type, handle);
		} else { // W3C standards
			element.addEventListener(type, handle, false);
		}
	}
}



var currentStep = 0;
function showReservationStep(step) {
	var valid = validateReservationForm();
	if (valid) {
		switch(step) {
			case 1: setReservationHeader('title_step1', 1); break;
			case 2: setReservationHeader('title_step2', 2); break;
			case 3: setReservationHeader('title_step3', 3); break;
			case 4: setReservationHeader('title_step4', 4); break;
		}
		setReservationForm(step);
	}
}

function setReservationHeader(title_id, current) {
	var base = $('currentstep_one_of_base');
	var header = $('currentstep_title');
	var title = $(title_id);
	if (base != null && header != null && title != null) {
		header.innerHTML = base.innerHTML.replace('${current}', '' + current).replace('${total}', '4') + ': ' + title.innerHTML;
	}
}

/*function setReservationForm(step) {
	if (step == 3) {
		var formCountryDropdown = $('rf_country');
		var countryDropdown = $('country');
		var selectedFormCountry = formCountryDropdown.options[formCountryDropdown.selectedIndex].value
		for(var opt=0;opt<countryDropdown.options.length;opt++){
			var countryOption = countryDropdown.options[opt].value;
			if(countryOption==selectedFormCountry){
				countryDropdown.selectedIndex = opt;
			}
		}
		var strCountry = countryDropdown.options[countryDropdown.selectedIndex].value;
		var strCoords = countryDropdown.options[countryDropdown.selectedIndex].className;
		MMYME.LocationSearch.changeCountry(strCoords, strCountry);
	}
	var form1 = $('reservation_step' + step);
	if (form1 != null) {
		form1.className = 'reservation_content_active';
		var form2 = $('reservation_step' + currentStep);
		if (form2 != null && step != currentStep) {
			form2.className = 'reservation_content';
		}
	}
	var link1 = $('stepcrumb' + step);
	if (link1 != null) {
		link1.className = 'active';
		var link2 = $('stepcrumb' + currentStep);
		if (link2 != null && step != currentStep) {
			link2.className = '';
		}
	}
	
	currentStep = step;
}*/


function setReservationForm(step) {

	var form1 = $('reservation_step' + step);
	if (form1 != null) {
		form1.style.display = 'block';
		var form2 = $('reservation_step' + currentStep);
		if (form2 != null && step != currentStep) {
			form2.style.display = 'none';
		}
	}

	var link1 = $('breadcrumb' + step);

	if (link1 != null) {
		link1.className = 'breadcrumb active';
		var link2 = $('breadcrumb' + currentStep);
		if (link2 != null && step != currentStep) {
			link2.className = 'breadcrumb';
		}
	}
	currentStep = step;

	if (step == 3) {
		var formCountryDropdown = $('rf_country');
		var countryDropdown = $('country');
		var selectedFormCountry = formCountryDropdown.options[formCountryDropdown.selectedIndex].value
		for(var opt=0;opt<countryDropdown.options.length;opt++){
			var countryOption = countryDropdown.options[opt].value;
			if(countryOption==selectedFormCountry){
				countryDropdown.selectedIndex = opt;
			}
		}
		var strCountry = countryDropdown.options[countryDropdown.selectedIndex].value;
		var strCoords = countryDropdown.options[countryDropdown.selectedIndex].className;
		MMYME.LocationSearch.changeCountry(strCoords, strCountry);
	}

	if (step == 4) {
		var countryDropdown = $('country');
		var strCountry = countryDropdown.options[countryDropdown.selectedIndex].value
		var strCoords = countryDropdown.options[countryDropdown.selectedIndex].className
		MMYME.LocationSearch.changeCountry(strCoords, strCountry);
	}

	//if (step == 5) {
		// fill plate flash
	//	sendToConfirmFlash($('rf_plate_text_input').value);
	//}

}


var detailPopup = null;
function printReservation() {
	var frm = $('reservationform');
	if (frm != null) {
		var pAction = frm.action;
		var pTarget = frm.target;
		frm.action = 'print_reservation_details.jsp';
		frm.target = 'printed_details';
		
		detailPopup = openwindow('print_reservation_details.jsp', 'printed_details', 'scrollbars=yes,menubar=yes,width=800,height=600,top=35,left=75,status=yes,resizable=yes');
		setTimeout('postPrintReservation("' + pAction + '","' + pTarget + '");', 3000)
	}
}

function openwindow(url, title, attributes) {
	popw = window.open(url, title, attributes);
	setTimeout("setTimeout('popw.focus()',50);");
}


function postPrintReservation(pAction, pTarget) {
	var frm = $('reservationform');
	if (frm != null) {
		frm.submit();
		//setTimeout("detailPopup.focus()",50);
		
		frm.action = pAction;
		frm.target = pTarget;
	}
}

function initResevationForm() {
	if ($('reservation_form_container') != null) {
		showReservationStep(1);
	}
	if ($('newsletter_form_container') != null || $('reservation_step2') != null) {
		// create date dropdowns
		var date = new Date();
		var dayElement = $('rf_birth_day');
		for (var day = 1; day <= 31; day++) {
			dayElement.options[day - 1] = new Option('' + day, '' + day);
		}
		
		var monthElement = $('rf_birth_month');
		for (var month = 1; month <= 12; month++) {
			monthElement.options[month - 1] = new Option('' + month, '' + month);
		}
		
		var yearElement = $('rf_birth_year');
		for (var year = date.getFullYear() - 17; year >= date.getFullYear() - 87; year--) {
			yearElement.options[(date.getFullYear() - 17) - year] = new Option('' + year, '' + year);
		}
		
		var countryCount = 0;
		if (countryLocal == 'UK') {
			countryLocal = 'GB';
		}
		
		var countryElement = $('rf_country');
		for (var key in countries) {
			countryElement.options[countryCount] = new Option('' + countries[key], '' + key);
			if (key == countryLocal) {
				countryElement.selectedIndex = countryCount;
			}
			countryCount++;
		}
		
		var postalcodeElement = $('rf_postalcode');
		if (countryLocal == 'IE') {
			postalcodeElement.value = 'n.a.';
		}
		
		var ihaveabikeElement = $('rf_checkbox_haveabike');
		if (ihaveabikeElement != null) {
			var brandElement = $('rf_bikebrand');
			var modelElement = $('rf_bikemodel');
			var bikeyearElement = $('rf_bikeyear');
			addEvent(ihaveabikeElement, "click", haveBike);
			addEvent(brandElement, "change", changeBikeBrand);
			
			var brandCount = 0;
			for (var key in brandmodels) {
				brandElement.options[brandCount] = new Option('' + key, '' + key);
				brandCount++;
			}
			for (var year = date.getFullYear(); year >= date.getFullYear() - 25; year--) {
				bikeyearElement.options[(date.getFullYear()) - year] = new Option('' + year, '' + year);
			}
			bikeyearElement.options[26]  = new Option('Classic', 'Classic');
			haveBike();
			changeBikeBrand();
		}
		
	}
}

function clearDropDown(objSelect) {
	if (objSelect != null) {
		for (var i = (objSelect.options.length - 1); i >= 0; i--) {
			objSelect.options[i] = null;
		}
	}
}

function haveBike() {
	var ihaveabikeElement = $('rf_checkbox_haveabike');
	if (ihaveabikeElement != null) {
		$('rf_bikebrand').style.display = ihaveabikeElement.checked ? "block" : "none";
		$('rf_bikebrand_lbl').style.display = ihaveabikeElement.checked ? "block" : "none";
		$('rf_bikemodel').style.display = ihaveabikeElement.checked ? "block" : "none";
		$('rf_bikemodel_lbl').style.display = ihaveabikeElement.checked ? "block" : "none";
		$('rf_bikeyear').style.display = ihaveabikeElement.checked ? "block" : "none";
		$('rf_bikeyear_lbl').style.display = ihaveabikeElement.checked ? "block" : "none";
	}
}

function changeBikeBrand() {
	var brandElement = $('rf_bikebrand');
	var modelElement = $('rf_bikemodel');
	var modelCount = 0;
	clearDropDown(modelElement);
	for (var key in brandmodels[brandElement.value]) {
		modelElement.options[modelCount] = new Option('' + brandmodels[brandElement.value][key], '' + brandmodels[brandElement.value][key]);
		modelCount++;
	}

}

var currentDealer = null;
function selectDealer(dealerid, dealer, country) {
	currentDealer = dealer;
	var result = $('rf_display_dealer');
	var directresult = $('selected_dealer');
	if (directresult != null && result != null) {
		var html = ( dealer.name || '' ) + '<br/>' + ( dealer.street || '' ) + '<br/>' + ( dealer.street2 || '' ) + '<br/>' + ( dealer.town || '' ) + (country == 'gb' ? ('<br/>' + ( dealer.state || '' ) + '<br/>' + ( dealer.pc || '' ) + '<br/>' + ( dealer.telephone || '' )) : ('<br/>' + ( dealer.telephone || '' ) + '<br/>' + ( dealer.state || '' )));
		result.innerHTML = html;
		directresult.innerHTML = html;
		directresult.style.display = 'block';
		$('rf_dealer_info'). value = html;
		$('rf_dealer_id'). value = dealerid;
		$('rf_dealer_name').value = dealer.name;
	}
}

var othertext = "andere";
var mandatoryElements = new Array("rf_first_name", "rf_surname", "rf_street1", "rf_postalcode", "rf_city", "rf_country", "rf_phonenumber", "rf_email_address", "rf_color");
var mandatoryError = "Please enter a";
var invalidError = "Please enter a valid";
var checkBoxError = "Please select";
var noDealerError =  "You need to select a dealer!";
var currentCountry = "GB";
var countries = {	"":"-- Please select --",
					"AL":"Albania",
					"AT":"Austria",
					"BY":"Belarus",
					"BE":"Belgium",
					"BA":"Bosnia",
					"BG":"Bulgaria",
					"HR":"Croatia",
					"CY":"Cyprus",
					"CZ":"Czech Republic",
					"DK":"Denmark",
					"EE":"Estonia",
					"FI":"Finland",
					"FR":"France",
					"DE":"Germany",
					"GR":"Greece",
					"HU":"Hungary",
					"IS":"Iceland",
					"IE":"Ireland",
					"IT":"Italy",
					"LV":"Latvia",
					"LI":"Liechtenstein",
					"LT":"Lithuania",
					"LU":"Luxembourg",
					"MK":"Macedonia",
					"MT":"Malta",
					"MC":"Monaco",
					"NL":"Netherlands",
					"NO":"Norway",
					"PL":"Poland",
					"PT":"Portugal",
					"RO":"Romania",
					"RU":"Russia",
					"SK":"Slovakia",
					"SI":"Slovenia",
					"ES":"Spain",
					"SE":"Sweden",
					"CH":"Switzerland",
					"UA":"Ukraine",
					"GB":"United Kingdom" };
var brandmodels = {
	"Yamaha" : {	0 : "BT 1100 Bulldog",
					1 : "DT 125 R/RE",
					2 : "DT 125 X",
					3 : "FJR 1300",
					4 : "FZ1 Fazer",
					5 : "FZ1 Naked",
					6 : "FZ6 Fazer",
					7 : "FZ6 Naked",
					8 : "FZR 1000/YZF 1000 ThunderAce",
					9 : "FZR 600/YZF 600 ThunderCat",
					10 : "FZS 1000 Fazer",
					11 : "FZS 600 Fazer",
					12 : "MT-01",
					13 : "MT-03",
					14 : "TDM 850/900",
					15 : "TDR 125",
					16 : "T-Max 500",
					17 : "TT 600",
					18 : "TW 125/225",
					19 : "TZR 125",
					20 : "V-max 1200",
					21 : "WR 250F",
					22 : "WR 250X",
					23 : "WR 400-450F",
					24 : "XJ 600 Diversion",
					25 : "XJ 900 Diversion",
					26 : "XJR 1200/1300",
					27 : "XT 125 R/X",
					28 : "XT 500-600",
					29 : "XT 660 R",
					30 : "XT 660 X",
					31 : "XTZ 600/660/750 Ténéré",
					32 : "XV 1600/1700",
					33 : "XV 1900 Midnight Star",
					34 : "XV 535 Virago",
					35 : "XV/XVS 125",
					36 : "XVS 1100/1300",
					37 : "XVS 650 Drag Star",
					38 : "YBR125",
					39 : "YBR250",
					40 : "YZ 125",
					41 : "YZ 250 (2-stroke)",
					42 : "YZ 250F (4-stroke)",
					43 : "YZ 400-450F",
					44 : "YZ 85",
					45 : "YZF-R1",
					46 : "YZF-R125",
					47 : "YZF-R6",
					48 : "..." },
	"Aprilia" : {	0 : "NA 850 Mana",
					1 : "Pegaso 650/660",
					2 : "RS 125",
					3 : "RS 250",
					4 : "RSV 1000",
					5 : "RXW 4.5",
					6 : "SL 750 Shiver",
					7 : "SMV 750 Dorsoduro",
					8 : "SXV 4.5",
					9 : "Tuono 1000",
					10 : "..." },
	"BMW" : {	0 : "F 650 GS(twin 850)",
				1 : "F 650 GS/ST/PD/CS",
				2 : "F 800",
				3 : "F 800 GS",
				4 : "G 650 X-series",
				5 : "HP 2",
				6 : "HP2 Sport",
				7 : "K 1200 LT/GT",
				8 : "K 1200 R",
				9 : "K 1200 RS",
				10 : "K 1200 S",
				11 : "K1100/1200LT",
				12 : "R 1100-1200 RS/ST",
				13 : "R 1100-1200 RT",
				14 : "R 1100-1200 S/Boxer Cup",
				15 : "R 850-1150 R",
				16 : "R 850-1200 GS",
				17 : "..." },
	"Ducati" : {	0 : "1098 series",
					1 : "748/916/996/998 series",
					2 : "749/999 series",
					3 : "Desmosedici RR",
					4 : "Hypermotard",
					5 : "Monster series",
					6 : "Multistrada series",
					7 : "Sport 1000 series",
					8 : "SS series",
					9 : "ST2/ST3/ST4",
					10 : "..." },
	"Harley-Davidson" : {	0 : "Dyna-series",
							1 : "Road King-series",
							2 : "Softtail-series",
							3 : "Sportster-series",
							4 : "Touring-series",
							5 : "V-Rod",
							6 : "XR 1200",
							7 : "..." },
	"Honda" : {	0 : "CB 1000 R",
				1 : "CB 1000/1100/X-11",
				2 : "CB 1300/S",
				3 : "CB 600 Hornet",
				4 : "CB 750",
				5 : "CB 900 Hornet",
				6 : "CB series 250-450",
				7 : "CBF 1000",
				8 : "CBF 500",
				9 : "CBF 600",
				10 : "CBR 1000 F",
				11 : "CBR 1100 XX Blackbird",
				12 : "CBR 125 R",
				13 : "CBR 600 F",
				14 : "CBR 600 RR",
				15 : "CBR 900/1000 RR FireBlade",
				16 : "CR series (2-stroke)",
				17 : "CRF series (4-stroke)",
				18 : "DN-01",
				19 : "GL 1500/1800 Goldwing",
				20 : "NTV 650/700 Deauville",
				21 : "NX/FMX/FX/SLR 650",
				22 : "ST 1100/1300 Pan European",
				23 : "VFR 750/800",
				24 : "VT 600 Shadow",
				25 : "VT 750-1100 Shadow",
				26 : "VTR 1000 SP1/SP2",
				27 : "VTR 1000F Firestorm",
				28 : "XL series 250-600",
				29 : "XLV 1000 Varadero",
				30 : "XLV 125 Varadero",
				31 : "XLV 600/650 Transalp",
				32 : "XR 600/650 R",
				33 : "XRV 650/750 Africa Twin",
				34 : "..." },
	"Kawasaki" : {	0 : "1400 GTR",
					1 : "ER-5",
					2 : "ER-6 F",
					3 : "ER-6 N",
					4 : "KLE 500",
					5 : "KLR/KLX 650",
					6 : "KX series (2-stroke)",
					7 : "KXF series (4-stroke)",
					8 : "Versys",
					9 : "VN Vulcan series",
					10 : "Z 750/1000",
					11 : "ZR-7/ZR 750",
					12 : "ZRX 1100/1200",
					13 : "ZX-10R Ninja",
					14 : "ZX-12R Ninja",
					15 : "ZX-6R/RR Ninja",
					16 : "ZX-7R Ninja",
					17 : "ZX-9R Ninja",
					18 : "ZZ-R 1200/1400",
					19 : "ZZ-R 600",
					20 : "..." },
	"KTM" : {	0 : "690 Enduro",
				1 : "690 Supermoto",
				2 : "Adventure/Enduro 950/990",
				3 : "Duke 640/690",
				4 : "EXC-series (2-stroke)",
				5 : "EXC-series (4-stroke)",
				6 : "LC4-series",
				7 : "RC 8",
				8 : "SuperDuke 950/990",
				9 : "Supermoto 950/990",
				10 : "SX-series (2-stroke)",
				11 : "SX-series (4-stroke)",
				12 : "..." },
	"Suzuki" : {	0 : "B-King 1300",
					1 : "DL 1000 V-Strom",
					2 : "DL 650 V-Strom",
					3 : "DR 125/250/350",
					4 : "DR/XF 650 Freewind",
					5 : "DR-Z 400",
					6 : "GS 500 E/F",
					7 : "GSF 1250 Bandit",
					8 : "GSF 600/650 Bandit",
					9 : "GSX 1200/1400/Inazuma",
					10 : "GSX 1300 R Hayabusa",
					11 : "GSX 600/750/1100 F",
					12 : "GSX 750",
					13 : "GSX-R 1000/1100",
					14 : "GSX-R 600",
					15 : "GSX-R 750",
					16 : "RM series (2-stroke)",
					17 : "RM-Z series (4-stroke)",
					18 : "SV 1000",
					19 : "SV 650",
					20 : "VN Marauder/Intruder-series",
					21 : "..." },
	"Triumph" : {	0 : "Classic series",
					1 : "Daytona 675",
					2 : "Daytona 955/1200",
					3 : "Rocket-3 (2.3)",
					4 : "Speed Triple 955/1050",
					5 : "Street Triple 675",
					6 : "Tiger",
					7 : "..." },
	"..." : {	0 : "..." }
}


function submitReservationForm() {
	currentStep = 4;
	if (validateReservationForm()) {
		$('reservationform').submit();
	}
}


function validateReservationForm() {
	var valid = true;
	var errorFieldCount = 0;
	var errorFields = "<ul>";
	var lastErrorField = "";
	
	var errMsg = null;
	switch(currentStep) {
		case 1: 
			// no validation needed
			break;
		case 2:
			// validate naw
			errMsg = $('step2_error_messages');
			errMsg.innerHTML = "";
			errMsg.style.visibility = "hidden";
			
			var inputs = document.getElementsByTagName("input");
			for (var i=0; i<inputs.length; i++) {
				if (inputs[i].className == "error") { 
					inputs[i].className = "";
				}
			}
			
			var labels = document.getElementsByTagName("label");
			for (var i=0; i<labels.length; i++) {
				if (labels[i].className.indexOf("error") >= 0) {
					labels[i].className = labels[i].className.substring(0, labels[i].className.indexOf("error"));
				}
			}
			
			for (var i=0; i<mandatoryElements.length; i++) {
				var mandatoryElement = $(mandatoryElements[i]);
				if (mandatoryElement != null && (mandatoryElement.value == null || mandatoryElement.value == "")) {
					mandatoryElement.className = "error";
					var label = $(mandatoryElements[i] + '_lbl');
					if (label != null) {
						lastErrorField = "<label for=\"" + label.htmlFor + "\" class=\"error\">" + label.innerHTML.substring(0, label.innerHTML.indexOf("<")) + "</label>";
						errorFields += "<li>" + lastErrorField + "</li>"
						label.className = "error";
						errorFieldCount++;
					}
					valid = false;
					errMsg.innerHTML = mandatoryError;
					errMsg.style.visibility = "visible";
				}
			}
			
			if (valid) {
				// check valid email
				var emailElement = $('rf_email_address');
				if (!echeck(emailElement.value)) {
					emailElement.className = "error";
					var label = $('rf_email_address_lbl');
					if (label != null) {
						lastErrorField = "<label for=\"" + label.htmlFor + "\" class=\"error\">" + label.innerHTML.substring(0, label.innerHTML.indexOf("<")) + "</label>";
						errorFields += "<li>" + lastErrorField + "</li>"
						label.className = "error";
						errorFieldCount++;
					}
					valid = false;
					errMsg.innerHTML = invalidError;
					errMsg.style.visibility = "visible";
				}
			}
			
			if (valid) {
				// check checkboxes checked
				var termsCheckboxElement = $('rf_checkbox_terms');
				if (termsCheckboxElement != null && !termsCheckboxElement.checked) {
					var label = $('rf_checkbox_terms_lbl');
					if (label != null) {
						lastErrorField = "<label for=\"" + label.htmlFor + "\" class=\"error\">" + label.childNodes[0].innerHTML + "</label>";
						errorFields += "<li>" + lastErrorField + "</li>"
						label.className = label.className + " error";
						errorFieldCount++;
					}
					valid = false;
					errMsg.innerHTML = checkBoxError;
					errMsg.style.visibility = "visible";
				}
			}
			errorFields += "</ul>";
			
			if (errorFieldCount > 0) {
				if (errorFieldCount == 1) {
					errMsg.innerHTML = errMsg.innerHTML.replace("${fields}", " <span class=\"errorlabel\">" + lastErrorField + "</span>");
				} else {
					errMsg.innerHTML = errMsg.innerHTML= errorFields;
				}
			}
			
			break;
		case 3:
			// check dealer selected
			var dID = $('rf_dealer_id');
			if (currentDealer == null || dID.value == null || dID.value == '') {
				valid = false;
				alert(noDealerError);
			}
			break;
		case 4:
			// check dealer selected
			var dID = $('rf_dealer_id');
			if (currentDealer == null || dID.value == null || dID.value == '') {
				valid = false;
				alert(noDealerError);
			}
			break;
	}
	
	syncReservationInputs();
	return valid;
}

function syncReservationInputs() {
	switch(currentStep) {
		case 1:
			// don't sync
			break;
		case 2:
			// sync naw
			$('rf_display_name').innerHTML = $('rf_title').value + '. ' + $('rf_first_name').value + ' ' + $('rf_surname').value;
			$('rf_display_address').innerHTML = $('rf_street1').value + '<br/>' + $('rf_street2').value + '<br/>' + $('rf_street3').value;
			$('rf_display_postalcode').innerHTML = $('rf_postalcode').value;
			$('rf_display_city').innerHTML = $('rf_city').value;
			$('rf_display_country').innerHTML = countries[$('rf_country').value];
			$('rf_display_phonenumber').innerHTML = $('rf_phonenumber').value;
			$('rf_display_email').innerHTML = $('rf_email_address').value;
			$('rf_display_birthdate').innerHTML = $('rf_birth_day').value + '-' + $('rf_birth_month').value + '-' + $('rf_birth_year').value;
			if ($('rf_checkbox_haveabike').checked) {
				$('rf_display_bike').innerHTML = '' + $('rf_bikebrand').value + '<br/>' + $('rf_bikemodel').value + '<br/>' + $('rf_bikeyear').value;
				$('rf_display_bike').style.display = 'inline';
				$('rf_display_bike_lbl').style.display = 'inline';
			} else {
				$('rf_display_bike').innerHTML = '&nbsp;';
				$('rf_display_bike').style.display = 'none';
				$('rf_display_bike_lbl').style.display = 'none';
			}
			break;
		case 3:
			// sync dealer
			break;
		case 4:
			// don't sync
			break;
	}
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) {
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1) {
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1) {
		return false;
	}
	if (str.indexOf(" ")!=-1) {
		return false;
	}
	return true;
}

function initLinks() {
	var sendtofriend = $('sendtofriend');
	if (sendtofriend != null) {
		addEvent(sendtofriend, "click", sendtofriendAction);
	}
	
	var printfriendly = $('printfriendly');
	if (printfriendly != null) {
		addEvent(printfriendly, "click", printfriendlyAction);
	}
	
	var blogthis = $('blogthis');
	if (blogthis != null) {
		addEvent(blogthis, "click", blogthisAction);
		blogthis.href = "javascript:void(0);"
	}
	
	var diggthis = $('diggthis');
	if (diggthis != null) {
		var diggthisurl = window.location.href;
		if (diggthisurl.indexOf("lang=") < 0) {
			var splits = (diggthisurl + "#").split("#");
			if (splits[0].indexOf("?") > 0) {
				splits[0] = splits[0] + "&lang=" + contentLanguage;
			} else {
				splits[0] = splits[0] + "?lang=" + contentLanguage;
			}
			diggthisurl = splits[0] + (("" + contentId).startsWith("tcm") ? "&id=" + contentId : "") + (splits[1] != "" && (contentId == "" || splits[1].indexOf(contentId) < 0) ? "#" + splits[1] : "");
		}
		if (contentTitle != null || contentItemTitle != null) {
			diggthis.href = "http://digg.com/submit?url=" + encodeURIComponent(diggthisurl) + "&title=" + encodeURIComponent("2009 - Yamaha VMAX - " + (contentItemTitle != null ? contentItemTitle : contentTitle)) + "";
		} else {
			diggthis.href = "http://digg.com/submit?url=" + encodeURIComponent(diggthisurl) + "&title=" + encodeURIComponent(document.title) + "";
		}
	}
}

function blogthisAction() {
	var blogthisurl = window.location.href;
	if (blogthisurl.indexOf("lang=") < 0) {
		var splits = (blogthisurl + "#").split("#");
		if (splits[0].indexOf("?") > 0) {
			splits[0] = splits[0] + "&lang=" + contentLanguage;
		} else {
			splits[0] = splits[0] + "?lang=" + contentLanguage;
		}
		blogthisurl = splits[0] + (("" + contentId).startsWith("tcm") ? "&id=" + contentId : "") + (splits[1] != "" && (contentId == "" || splits[1].indexOf(contentId) < 0) ? "#" + splits[1] : "");
	}
	var message = '';
	if (document.selection) {
		message = document.selection.createRange().text;
	} else if (window.getSelection) {
		message = window.getSelection();
	} else if (document.getSelection) {
		message = document.getSelection();
	}
	popw = null;
	if (contentTitle != null || contentItemTitle != null) {
		popw = window.open('http://www.blogger.com/blog_this.pyra?t=' + encodeURIComponent(message) + '&u=' + encodeURIComponent(blogthisurl) + '&n=' + encodeURIComponent("2009 - Yamaha VMAX - " + (contentItemTitle != null ? contentItemTitle : contentTitle)),'bloggerForm','scrollbars=no,width=475,height=300,top=175,left=75,status=yes,resizable=yes');
	} else {
		popw = window.open('http://www.blogger.com/blog_this.pyra?t=' + encodeURIComponent(message) + '&u=' + encodeURIComponent(blogthisurl) + '&n=' + encodeURIComponent(document.title), 'bloggerForm','scrollbars=no,width=640,height=480,top=175,left=75,status=yes,resizable=yes');
	}
	if (!document.all && popw != null) {
		T = setTimeout('popw.focus()',50);
	}
}

function sendtofriendAction() {
	popw = window.open('/sendtofriend/index.jsp?title=' + encodeURIComponent("2010 - Yamaha Super Ténéré - " + contentTitle) + '&url=' + encodeURIComponent(window.location.href.split("#")[0] + "?lang=" + contentLanguage + (("" + contentId).startsWith("tcm") ? "&id=" + contentId : "")),'vmaxsendtofriend','scrollbars=no,width=475,height=300,top=175,left=75,status=yes,resizable=yes');
	if (!document.all && popw != null) {
		T = setTimeout('popw.focus()',50);
	}
}

function printfriendlyAction() {
	popw = window.open('/print.jsp?title=' + encodeURIComponent("2010 - Yamaha Super Ténéré - " + contentTitle) + '&url=' + (contentAddress) + "&lang=" + contentLanguage + (("" + contentId).startsWith("tcm") ? "&id=" + contentId : ""),'vmaxsendtofriend','scrollbars=yes,menubar=yes,width=900,height=600,top=75,left=75,status=yes,resizable=yes');
	alert('here');
	if (!document.all && popw != null) {
		T = setTimeout('popw.focus()',50);
	}
	else{
	alert('else');	
	}
}

function switchcontent(view) {
	displaycontent("lang_active", view == "lang_active");
	displaycontent("lang_not_active", view == "lang_not_active");
}

function displaycontent(view, visible) {
	switch (view) {
		case "lang_active":
			if ($('lang_active') != null) {
				$('lang_active').style.display = visible ? 'block' : 'none';
			}
			break;
		case "lang_not_active":
			if ($('lang_not_active') != null) {
				$('lang_not_active').style.display = visible ? 'block' : 'none';
			}
			break;		
	}
}

