function setdep(nday, nmonth, ntime, nferry)
{
	document.departureform.depday.selectedIndex = nday-1;
	document.departureform.depmonth.selectedIndex = nmonth-1;
	document.departureform.deptime.value = ntime;
	document.departureform.depship.value = nferry;
	for (i=0; i<document.images.length; i++) {
		if ((document.images[i].src.substr(document.images[i].src.length-selected.length, selected.length).toLowerCase() == selected) && (document.images[i].name.substr(0, 6) != "retimg")) {
			document.images[i].src = folderpath + unselected;
		}
	}
}

function setret(nday, nmonth, ntime, nferry)
{
	document.departureform.retday.selectedIndex = nday-1;
	document.departureform.retmonth.selectedIndex = nmonth-1;
	document.departureform.rettime.value = ntime;
	document.departureform.retship.value = nferry;
	for (i=0; i<document.images.length; i++) {
		if ((document.images[i].src.substr(document.images[i].src.length-selected.length, selected.length).toLowerCase() == selected) && (document.images[i].name.substr(0, 6) != "depimg")) {
			document.images[i].src = folderpath + unselected;
		}
	}
}

function refreshdepartures()
{
	S = "steg1.asp";
	S = S + "?depday=" + document.departureform.depday.options[document.departureform.depday.selectedIndex].value;
	S = S + "&depmonth=" + document.departureform.depmonth.options[document.departureform.depmonth.selectedIndex].value;
	if (document.departureform.retday != null) {
		S = S + "&retday=" + document.departureform.retday.options[document.departureform.retday.selectedIndex].value;
	}
	if (document.departureform.retmonth != null) {
		S = S + "&retmonth=" + document.departureform.retmonth.options[document.departureform.retmonth.selectedIndex].value;
	}
	S = S + "&dep=" + document.departureform.dep.options[document.departureform.dep.selectedIndex].value;
	if (document.departureform.ret != null) {
		if (document.departureform.type == 'select-one') {
			S = S + "&ret=" + document.departureform.ret.options[document.departureform.ret.selectedIndex].value;
		} else {
			S = S + "&ret=" + document.departureform.ret.value;
		}
	}
	S = S + "&deppax=" + document.departureform.deppax.options[document.departureform.deppax.selectedIndex].value;
	if (document.departureform.retpax != null) {
		S = S + "&retpax=" + document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value;
	}
	S = S + "&depvehicles=" + document.departureform.depvehicles.options[document.departureform.depvehicles.selectedIndex].value;
	if (document.departureform.retvehicles != null) {
		S = S + "&retvehicles=" + document.departureform.retvehicles.options[document.departureform.retvehicles.selectedIndex].value;
	}
	S = S + "&depcabins=" + document.departureform.depcabins.options[document.departureform.depcabins.selectedIndex].value;
	if (document.departureform.retcabins != null) {
		S = S + "&retcabins=" + document.departureform.retcabins.options[document.departureform.retcabins.selectedIndex].value;
	}
//	S = S + "&deppullman=" + document.departureform.deppullman.options[document.departureform.deppullman.selectedIndex].value;
//	S = S + "&retpullman=" + document.departureform.retpullman.options[document.departureform.retpullman.selectedIndex].value;
//	S = S + "&depmeals=" + document.departureform.depmeals.options[document.departureform.depmeals.selectedIndex].value;
//	S = S + "&retmeals=" + document.departureform.retmeals.options[document.departureform.retmeals.selectedIndex].value;
	S = S + "&deppets=" + document.departureform.deppets.options[document.departureform.deppets.selectedIndex].value;
	if (document.departureform.retpets != null) {
		S = S + "&retpets=" + document.departureform.retpets.options[document.departureform.retpets.selectedIndex].value;	
	}
	
	S = S + "&deptime=blank";
	S = S + "&rettime=blank";
	
	v=navigator.appVersion.substring(0,1);
	if (v >= "4") 
	{
		this.location.href = S;
	}
	else
	{
		window.open(S, target="CONTENT");
	}
}

function copytodep()
{	
	document.departureform.deppax.selectedIndex = document.departureform.retpax.selectedIndex;
	document.departureform.depvehicles.selectedIndex = document.departureform.retvehicles.selectedIndex;
	document.departureform.depcabins.selectedIndex = document.departureform.retcabins.selectedIndex;
//	document.departureform.deppullman.selectedIndex = document.departureform.retpullman.selectedIndex;
//	document.departureform.depmeals.selectedIndex = document.departureform.retmeals.selectedIndex;
	document.departureform.deppets.selectedIndex = document.departureform.retpets.selectedIndex;
}

function copytoret()
{
	if (document.departureform.retpax != null) {
		document.departureform.retpax.selectedIndex = document.departureform.deppax.selectedIndex;
		document.departureform.retvehicles.selectedIndex = document.departureform.depvehicles.selectedIndex;
		document.departureform.retcabins.selectedIndex = document.departureform.depcabins.selectedIndex;
	//	document.departureform.retpullman.selectedIndex = document.departureform.deppullman.selectedIndex;
	//	document.departureform.retmeals.selectedIndex = document.departureform.depmeals.selectedIndex;
		document.departureform.retpets.selectedIndex = document.departureform.deppets.selectedIndex;
	}
}

function setdualmode()
{
	document.departureform.single.value = "false";
}

function setsinglemode()
{
	document.departureform.single.value = "true";
}

function gotodeparture(fdepd, fdepm, fretd, fretm)
{
	var S, v;
	S = "steg1.asp";
	S = S + "?depday=" + fdepd;
	S = S + "&depmonth=" + fdepm;
	S = S + "&retday=" + fretd;
	S = S + "&retmonth=" + fretm; 
	S = S + "&deppax=" + document.departureform.deppax.options[document.departureform.deppax.selectedIndex].value;
	if (document.departureform.retpax != null) {
		S = S + "&retpax=" + document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value;
	}
	S = S + "&depvehicles=" + document.departureform.depvehicles.options[document.departureform.depvehicles.selectedIndex].value;
	if (document.departureform.retvehicles != null) {
		S = S + "&retvehicles=" + document.departureform.retvehicles.options[document.departureform.retvehicles.selectedIndex].value;
	}
	S = S + "&depcabins=" + document.departureform.depcabins.options[document.departureform.depcabins.selectedIndex].value;
	if (document.departureform.retcabins != null) {
		S = S + "&retcabins=" + document.departureform.retcabins.options[document.departureform.retcabins.selectedIndex].value;
	}
//	S = S + "&deppullman=" + document.departureform.deppullman.options[document.departureform.deppullman.selectedIndex].value;
//	S = S + "&retpullman=" + document.departureform.retpullman.options[document.departureform.retpullman.selectedIndex].value;
//	S = S + "&depmeals=" + document.departureform.depmeals.options[document.departureform.depmeals.selectedIndex].value;
//	S = S + "&retmeals=" + document.departureform.retmeals.options[document.departureform.retmeals.selectedIndex].value;
	S = S + "&deppets=" + document.departureform.deppets.options[document.departureform.deppets.selectedIndex].value;
	if (document.departureform.retpets != null) {
		S = S + "&retpets=" + document.departureform.retpets.options[document.departureform.retpets.selectedIndex].value;
	}
	S = S + "&deptime=blank";
	S = S + "&rettime=blank";
	v=navigator.appVersion.substring(0,1);
	if (v >= "4") 
	{
		this.location.href = S;
	}
	else
	{
		window.open(S, target="CONTENT");
	}
}

function afterchange(fsender) {
	switch (fsender) {
		case 'dep' :
			deproutechanged = true;
			break;
		case 'depmonth' :
			depmonthchanged = true;
			break;
		case 'depday' :
			depdaychanged = true;
			break;
		case 'ret' :
			retroutechanged = true;
			break;
		case 'retmonth' :
			retmonthchanged = true;
			break;
		case 'retday' :
			retdaychanged = true;
			break;
	}
	if (((depmonthchanged == true) || (depdaychanged == true)) || ((retmonthchanged == true) || (retdaychanged == true))) {
		refreshdepartures();
	} else {
		if ((deproutechanged == true) || (retroutechanged == true)) {
			refreshdepartures();
		}
	}
}

function depforminit()
{
	var browser = navigator.appName.toLowerCase();
	var version = parseInt(navigator.appVersion);
	var depimgname = "", retimgname = "";
	
	if (document.departureform.deptime.value.length < 5) document.departureform.deptime.value = document.departureform.firstdeptime.value;
	depimgname = "depimg" + document.departureform.depday.options[document.departureform.depday.selectedIndex].value + document.departureform.depmonth.options[document.departureform.depmonth.selectedIndex].value + document.departureform.deptime.value.substr(0, 2) + document.departureform.deptime.value.substr(3, 2);
	
	if ((document.departureform.retday != null) && (document.departureform.retmonth != null) && (document.departureform.rettime != null)) {
		if (document.departureform.rettime.value.length < 5) document.departureform.rettime.value = document.departureform.firstrettime.value;
		retimgname = "retimg" + document.departureform.retday.options[document.departureform.retday.selectedIndex].value + document.departureform.retmonth.options[document.departureform.retmonth.selectedIndex].value + document.departureform.rettime.value.substr(0, 2) + document.departureform.rettime.value.substr(3, 2);
	}
//alert('depimgname: ' + depimgname);
//alert('retimgname: ' + retimgname);
	if (browser.indexOf('netscape', 0) != -1) {
		// NN
		document.departureform.eval(depimgname).src = folderpath + selected;
		if (retimgname != "") {
			document.departureform.eval(retimgname).src = folderpath + selected;
		}
	} else {
		// IE
		if (document.images[depimgname]) document.images[depimgname].src = folderpath + selected;
		if (retimgname != "" && document.images[retimgname]) {
			document.images[retimgname].src = folderpath + selected;
		}
	}	
}

function depformsubmit(fcancelurl)
{
	var v;
	if (document.departureform.retpax != null) {
		if ((document.departureform.retpax.selectedIndex == 0) &&
		(document.departureform.retvehicles.selectedIndex == 0) &&
		(document.departureform.retcabins.selectedIndex == 0)) {
			setsinglemode();
			if (depformvalidate())
			{
				switch (depformaftervalidate())
				{
					case 0 :
						document.departureform.submit();
						break;
					case 1 :
						v = navigator.appVersion.substring(0,1);
						if (v >= "4") 
						{
							this.location.href = fcancelurl;
						}
						else
						{
							window.open(fcancelurl, target="CONTENT");
						}
						break;
				}
			}
		} else {
			setdualmode();
			if (depformvalidate())
			{
				switch (depformaftervalidate())
				{
					case 0 :
						document.departureform.submit();
						break;
					case 1 :
						v = navigator.appVersion.substring(0,1);
						if (v >= "4") 
						{
							this.location.href = fcancelurl;
						}
						else
						{
							window.open(fcancelurl, target="CONTENT");
						}
						break;
				}
			}
		}
	} else {
		setsinglemode();
		if (depformvalidate())
		{
			switch (depformaftervalidate())
			{
				case 0 :
					document.departureform.submit();
					break;
				case 1 :
					v = navigator.appVersion.substring(0,1);
					if (v >= "4") 
					{
						this.location.href = fcancelurl;
					}
					else
					{
						window.open(fcancelurl, target="CONTENT");
					}
					break;
			}
		}
	}
}

function depformvalidate()
{
	var err = "";
	var valid = true;
	
	if (document.departureform.deptime.value.length < 5) {
		err = err + ErrorMsg[2];
		valid = false;
	}
	
	
	if (document.departureform.depvehicles.options[document.departureform.depvehicles.selectedIndex].value != "0") {
		
		if (document.departureform.deppax.options[document.departureform.deppax.selectedIndex].value != "0") {
			if (document.departureform.depcabins.options[document.departureform.depcabins.selectedIndex].value == "0") {
				err = err + ErrorMsg[18];
				valid = false;
			}
		}
		
	} else {
		
		if (document.departureform.deppax.options[document.departureform.deppax.selectedIndex].value == "0") {
			err = err + ErrorMsg[20];
			valid = false;
		} else {
			if (document.departureform.depcabins.options[document.departureform.depcabins.selectedIndex].value == "0") {
				err = err + ErrorMsg[18];
				valid = false;
			}
		}
				
	}
		
	if (document.departureform.single.value != "true") {
		
		if (document.departureform.rettime.value.length < 5) {
			err = err + ErrorMsg[8];
			valid = false;
		}
				
		if (document.departureform.retvehicles.options[document.departureform.retvehicles.selectedIndex].value != "0") {
		
			if (document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value != "0") {
				if (document.departureform.retcabins.options[document.departureform.retcabins.selectedIndex].value == "0") {
					err = err + ErrorMsg[19];
					valid = false;
				}
			}
			
		} else {
			
			if (document.departureform.deppax.options[document.departureform.deppax.selectedIndex].value == "0") {
				err = err + ErrorMsg[21];
				valid = false;
			} else {
				if (document.departureform.retcabins.options[document.departureform.retcabins.selectedIndex].value == "0") {
					err = err + ErrorMsg[19];
					valid = false;
				}
			}
			
		}
		
	}
	
	if (document.departureform.mustrefresh.value == "true") {
		err = err + ErrorMsg[13];
		valid = false;
	}
	if (document.departureform.single.value != "true") {
		if ((document.departureform.depday.selectedIndex == document.departureform.retday.selectedIndex) && (document.departureform.depmonth.selectedIndex == document.departureform.retmonth.selectedIndex)) {
			if ((document.departureform.deppax.options[document.departureform.deppax.selectedIndex].value != document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value) && (document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value != '0')) {
				err = err + ErrorMsg[15];
				valid = false;
			}
			if ((document.departureform.depcabins.options[document.departureform.depcabins.selectedIndex].value != document.departureform.retcabins.options[document.departureform.retcabins.selectedIndex].value) && (document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value != '0')) {
				err = err + ErrorMsg[16];
				valid = false;
			}
		}
	}
	
	if (!valid) alert(err)
	return valid;
}

function depformaftervalidate()
{
	var fresult = 0;
	if (document.departureform.retpax != null) {
		if (!(document.departureform.retpax.options[document.departureform.retpax.selectedIndex].value == '0'))
	//	(document.departureform.retvehicles.options[document.departureform.retvehicles.selectedIndex].value == '0') &&
	//	(document.departureform.retcabins.options[document.departureform.retcabins.selectedIndex].value == '0'))
		{
			if (document.departureform.dep.options[document.departureform.dep.selectedIndex].value == document.departureform.ret.options[document.departureform.ret.selectedIndex].value) {
				if (!confirm(ErrorMsg[14])) {
					fresult = 1;
				} else {
					fresult = 2;
				}
			}
		}
	}
	return fresult;
}
