﻿function doSubmit(action, method) {
	switch (method) {
		case "GET": 
			{
				location.href = action;
				break;
			}
		case "POST":
		default:
			{
				var frm = document.forms[0];
				if (action)
					frm.action = action;
				frm.submit();
				break;
			}
	}
}

function openQuicklink(url, w, h, scrollbars) {
	width = (w) ? w : 500;
	height = (h) ? h : 600;
	if (!scrollbars)
		scrollbars = 'auto';
	window.open(url, '', 'width=' + width + ',height=' + height + ',scrollbars=' + scrollbars);
}


function splitString(stringToSplit, separator) {
	return stringToSplit.split(separator);
}

function showhide(id) {
	show = true;
	obj = $get(id + 'Content');
	if (obj) {
		if (obj.style.display != 'none') {
			show = false;
		}
		obj.style.display = (!show) ? 'none' : 'block';
	}

	obj = $get(id + '_collapseimg');
	if (obj) {
		obj.src = (!show) ? 'images/ic-maximize.gif' : 'images/ic-minimize.gif';
	}
}


function SetSelectOption(selectElement, value) {
	 for (var i = 0; i < selectElement.options.length; i++) { 
		if (selectElement.options[i].value == value) { 
			selectElement.options[i].selected = true;
			break;
		} 
	 } 
}


function AddAddress(startorstop, address) {
	
	var addr = new TripzoomLib.Element.Address(address);
	var frm = document.forms[0];

	var stations = frm.stations.value.split("|");
	switch (startorstop) {
		case "stop":
			stations[stations.length - 1] = address;
			break;
		case "start":
			if (stations.length > 1) {
				stations[0] = address;
			} else {
				stations.splice(0, 9, address);
			}
			break;
		case "via":
			stations.splice(stations.length - 1, 0, address);
			break;
	}
	frm.stations.value = stations.join("|");

	doSubmit("address.aspx");
}


// LanguageControle functions
function selectUICulture(name) {
	var frm = document.forms[0];
	frm.UICulture.value = name;
	doSubmit('');
}


