var gl_col;
var over_color = '#d9f7e1';
var down_color_1 = '#dceeff';
var down_color_2 = '#dcdeff';

function getOverColor(tr_id)
{
	gl_col = tr_id.bgColor;
	return over_color;
}

function getOutColor(tr_id)
{
	return gl_col;
}

function getDownColor(tr_id)
{
	var ret_col;

	if (gl_col == '#fffaf0' || gl_col == '#FFFAF0')
	{
		ret_col = gl_col = down_color_1;
		return ret_col;	
	}

	if (gl_col == '#f5f5f5' || gl_col == '#F5F5F5')
	{
		ret_col = gl_col = down_color_2;	
		return ret_col;
	}

	if (gl_col == down_color_1)
	{
		ret_col = gl_col = 'fffaf0';
		return ret_col;
	}

	if (gl_col == down_color_2)
	{
		ret_col = gl_col = 'f5f5f5';
		return ret_col;
	}

	return ret_col;
}

wmtt = null;
rfhd = null;
document.onmousemove = updateWMTT;
lp = 20;
tp = 20;
rfmax = 16;

function updateWMTT(e) {
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (wmtt != null) {
		wmtt.style.left = (x + lp) + "px";
		wmtt.style.top 	= (y + tp) + "px";
	}
}

function showWMTT(id) {
   if (navigator.appName == "Microsoft Internet Explorer"){
      for (var i = 1; i <= rfmax; i++){
         rfhd = document.getElementById('rf_' + i);
         rfhd.style.visibility = "hidden";
      }
   }
   wmtt = document.getElementById(id);
   wmtt.style.display = "block";
}

function hideWMTT() {
   if (navigator.appName == "Microsoft Internet Explorer"){
      for (var i = 1; i <= rfmax; i++){
         rfhd = document.getElementById('rf_' + i);
         rfhd.style.visibility = "visible";
      }
   }
	wmtt.style.display = "none";
}

function disableSecondDate() {
    forma = document.ReservationForm;

    if (forma.one_day_reservation.checked == true) {
        select_disable_status = true;
    } else {
        select_disable_status = false;
    }

    forma.rf_4.disabled = select_disable_status;
    forma.rf_5.disabled = select_disable_status;
    forma.rf_6.disabled = select_disable_status;
}

function disableDates(){
    forma = document.searchForm;

    if (forma.ignore_date.checked == true) {
        select_disable_status = true;
    } else {
        select_disable_status = false;
    }

    forma.j_yea.disabled = select_disable_status;
    forma.j_mon.disabled = select_disable_status;
    forma.j_day.disabled = select_disable_status;
    forma.d_yea.disabled = select_disable_status;
    forma.d_mon.disabled = select_disable_status;
    forma.d_day.disabled = select_disable_status;
}

// select dependence on
var d_yea_changed = 1;
var d_mon_changed = 1;
var d_day_changed = 1;

function ChangeDepSel (sel, tgt){
   if (tgt == 'd_yea' && d_yea_changed == 1)  document.ReservationForm.d_yea.value = sel.value;
   if (tgt == 'd_mon' && d_mon_changed == 1)  document.ReservationForm.d_mon.value = sel.value;
   if (tgt == 'd_day' && d_day_changed == 1)  document.ReservationForm.d_day.value = sel.value;
}

function ChangeSelDependence (tgt){
   // turn off select (journey -> departure) dependence
   if (tgt == 'd_yea')  d_yea_changed = 0;
   if (tgt == 'd_mon')  d_mon_changed = 0;
   if (tgt == 'd_day')  d_day_changed = 0;
}

function TurnOffSelDependences () {
   d_yea_changed = 0;
   d_mon_changed = 0;
   d_day_changed = 0;
}

function fillOtherFields (src, tgt, vname) {
   if (vname == 'paytype_'){
      var opt = 1;
   }
   var vars = tgt.split (',');
   var len = vars.length;
   var s = document.getElementById(vname + src);

   for (var i = 0; i < vars.length; i++) {

      if (vars[i] != src) {
         var t = document.getElementById(vname + vars[i]);
         if (t != null && (t.value == '' || opt == 1)){
            t.value = s.value;
         }
      }
   }
}
