function goLocation(href, prefWidth, prefHeight) {
    var _width  = (prefWidth)  ? prefWidth  : 640;
    var _height = (prefHeight) ? prefHeight : 480;
    w = window.open(href, "info", "resizable=yes,scrollbars=yes,width=" + _width + ",height=" + _height + ",left="+Math.floor((screen.width-_width)/2)+",top="+Math.floor((screen.height-_height)/2));
    if(w) w.focus();
}

function switchVisibility(elem, status) {
    var elm;
    elm = document.getElementById(elem);
    if (elm) {
        elm.style.display = (status) ? "" : "none";
    }
    var elemDVal = (status) ? false : true;
//    document.getElementById('to1').disabled = elemDVal;
    document.getElementById('arrDay').disabled = elemDVal;
    document.getElementById('arrCalendar').disabled = elemDVal;
}

function checkInfo(form){
	
	if (
			floatVal(document.getElementById('pass[ADT]').value) +
			floatVal(document.getElementById('pass[YCD]').value) +
			floatVal(document.getElementById('pass[YTH]').value) < 		
			floatVal(document.getElementById('pass[INF]').value)
	){
		alert(_m_m_booking_err1);
		return false;
	}
	
	
	
	
	var nowDate = getJDay('now');
	var depDate = getJDay('dep');
	var arrDate = getJDay('arr');

    if(document.getElementById('journey1').checked == true){    
        if(depDate > arrDate){
            alert(_m_m_booking_err3);
            return false
        }
    }
    alert('depDate: '+depDate+', arrDate: '+arrDate+', ' + nowDate);

	if(depDate < nowDate){
		alert(_m_m_booking_err4);
		return false
	}

	if(arrDate < nowDate+1){
//        alert('arrDate: '+arrDate+', nowDate: '+nowDate+', nowDate+86400: '+(nowDate+86400));
		alert(_m_m_booking_err5);
		return false
	}


    if(document.getElementById('from1').value == document.getElementById('to1').value)
{
    	alert(_m_m_booking_err2);
		return false
    
    }	return true;

}


function getDate(of){
	if(of == 'now'){
		var strDate = now;
	}else{
		var strDate = document.getElementById(of+'Month').options[document.getElementById(of+'Month').selectedIndex].value +'-'+document.getElementById(of+'Day').value;
	}
	
	var strDate = strDate.match(/(\d{4})\D(\d{1,2})\D(\d{1,2})/);
	
	if(!strDate[1] || !strDate[2] || !strDate[3]) return 0;
	
	var ret = new Date(strDate[1], strDate[2], strDate[3]).getTime();
    alert(of+': '+strDate[1]+' - '+strDate[2]+' - '+strDate[3]+',  result: '+ret);
    return ret;
}

function getDate(of){
	if(of == 'now'){
		var strDate = now;
	}else{
		var strDate = document.getElementById(of+'Month').options[document.getElementById(of+'Month').selectedIndex].value +'-'+document.getElementById(of+'Day').value;
	}
	
	var strDate = strDate.match(/(\d{4})\D(\d{1,2})\D(\d{1,2})/);
	
	if(!strDate[1] || !strDate[2] || !strDate[3]) return 0;
	
	var ret = julianDay(strDate[1], strDate[2], strDate[3]);
    return ret;
}

// calculate the modified Julian day number from Gregorian date
function julianDay(year,month,day) {
        var extra = 100.0*year+month-190002.5;
        var julian = 367.0*year;
        julian -= Math.floor(7.0*(year+Math.floor((month+9.0)/12.0))/4.0);
        julian += Math.floor(275.0*month/9.0);
        julian += day;
        julian -= 678985.5;
        julian -= 0.5*extra/Math.abs(extra);

        return julian;
}

function selectChangeOption(what){
   var adt = document.getElementById('pass[ADT]');
   var yth = document.getElementById('pass[YTH]');
   var chd = document.getElementById('pass[CHD]');
   var ycd = document.getElementById('pass[YCD]');
   var inf = document.getElementById('pass[INF]');
   var adtS = adt.options.selectedIndex;
   var ythS = yth.options.selectedIndex;
   var chdS = chd.options.selectedIndex;
   var ycdS = ycd.options.selectedIndex;
   var infS = inf.options.selectedIndex;



 kiek = floatVal(yth.value) + floatVal(adt.value);
 kiek2 = kiek + floatVal(chd.value) + floatVal(ycd.value);
//alert(kiek2);
   max = 9 - kiek2;

     inf.options.length = kiek;
   for(var i=kiek;i<=10;i++){
   inf.options[i] = null;
   }
    for(var i=0;i<=kiek;i++){
   inf.options[i] = new Option(i,i);
   }
   if(infS <= kiek)
   {  inf.options.selectedIndex = infS; }
   else { inf.options.selectedIndex = kiek; }
   
   switch (what) {
   case 'ADT': x = adtS; break;
   case 'YTH': x = ythS; break;
   case 'CHD': x = chdS; break;
   case 'YCD': x = ycdS; break;
}

   yth.options.length = 0;
   chd.options.length = 0;
   ycd.options.length = 0;
   adt.options.length = 0;


   
if(adtS >= 0){
    adt.options.length = 0;
    max2 = adtS+max;
    for(ix = 0; ix <= max2;ix++){
    adt.options[ix] = new Option(ix,ix);    
        
        }    
    }
if(ythS >= 0){
    yth.options.length = 0;
    max2 = ythS+max;
    for(ix = 0; ix <= max2;ix++){
    yth.options[ix] = new Option(ix,ix);    
        
        }    
    }
if(chdS >= 0){
    chd.options.length = 0;
        max2 = chdS+max;
    for(ix = 0; ix <= max2;ix++){
    chd.options[ix] = new Option(ix,ix);    
        
        }    
    }
if(ycdS >= 0){
    ycd.options.length = 0;
        max2 = ycdS+max;
    for(ix = 0; ix <= max2;ix++){
    ycd.options[ix] = new Option(ix,ix);    
        
        }    
    }
   

    adt.options.selectedIndex = adtS;
    yth.options.selectedIndex = ythS;
    chd.options.selectedIndex = chdS;
    ycd.options.selectedIndex = ycdS ;

  
    
}
