function _DateAdd(dt, days){
	var tmp = dt.split("-");
		
	var _dd = new Date( Date.UTC( parseInt( tmp[0], 10), (parseInt(tmp[1], 10)-1), parseInt(tmp[2], 10) )  );
	var n_days = (1000*3600*24*days);
	var tmp_time = (_dd.getTime()+n_days);
		
	var new_date = new Date( tmp_time );
	var tmp_month = (new_date.getMonth()+1);
	var tmp_year = new_date.getFullYear();
	var tmp_day = new_date.getDate();
		
	if( tmp_month < 10 ){
		var month = "0"+tmp_month;
	} else {
		var month = tmp_month;
	}
		
	if( tmp_day < 10 ) {
		var day = "0"+tmp_day;
	} else {
		var day = tmp_day;
	}
		
	var _pr = tmp_year+"-"+month+"-"+day;
	return _pr;
}

function SetNextWeek(frm, dt1, dt2){
	var out;
	eval("var _x = document."+frm+"."+dt1+".value;");
	out = _DateAdd(_x, 7);
	eval("document."+frm+"."+dt2+".value=out;");
}

function DatePopup(form, field, type){
	
	if( !type ){
		type = 0;
	} else {
		type = parseInt(type);
	}
	
	dateWin=window.open('flight.tools.php?tool=1&field='+field+'&form='+form+'&bd='+type,'_datepicker','width=200,height=200,left=' + ((screen.width-200)/2) + ',top=' + ((screen.height-200)/2) + ',toolbar=no,location=no,status=no,scrollbars=no,resizable=no,menubar=no,dependent=yes');
	dateWin.focus()
}

function _DateSelect(form, field, defdate) {
	dateWin=window.open('flight.tools.php?tool=1&field='+field+'&form='+form+'&defdate='+defdate+'&bd=0','_datepicker','width=220,height=240,left=' + ((screen.width-220)/2) + ',top=' + ((screen.height-200)/2) + ',toolbar=no,location=no,status=no,scrollbars=no,resizable=no,menubar=no,dependent=yes');
	dateWin.focus()
}

function getCity(form, field){
	var search = eval("document."+form+"."+field+".value");
	cityWin=window.open('flight.tools.php?tool=2&field='+field+'&form='+form+'&search='+search,'_citylist','width=400,height=300,left=' + ((screen.width-400)/2) + ',top=' + ((screen.height-300)/2) + ',toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no,dependent=yes');
	cityWin.focus()
}

function FareRules(index){
	winRules=window.open('flight.tools.php?tool=3&index='+index,'_rules','width=400,height=400,left=' + ((screen.width-400)/2) + ',top=' + ((screen.height-400)/2) + ',toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no,dependent=yes');
	winRules.focus()
}

function mAction(form, url){
	var frm = document.getElementById(form);
	frm.action = url;
	frm.submit();
}

function mStartSearch(form, url){
	__set_loader(1, "<b>Keresés folyamatban...</b><br>Kérem várjon!");
		
	var frm = document.getElementById(form);
	frm.action = url;
	frm.submit();
}

function ShowPaymodes(form, mode){
	var l_form = document.getElementById(form);
	if(document.all){
		disp = "block";
	}else{
		disp = "table";
	}
	if(mode==1){
		l_form.style.display = disp;
	}else{
		l_form.style.display = "none";
	}
}

/***************************************************************************************************************/
/* Date Mask function
/***************************************************************************************************************/

addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

MaskInput = function( f, m ){ //v1.0
	for( var i in ( !/^(.)\^(.*)$/.test( m ) && f.setAttribute( 'maxlength', m.length ), { keypress: 0, keyup: 1 } ) )
		addEvent( f, i, function( e ){
			var patterns = { "1": /[A-Z]/i, "2": /[0-9]/, "4": /[?-?]/i, "8": /./ }, rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8 };
			function validChar( c, rule ){
				var r = rules[rule] || 0;
				for( var i = 1; i <= r; i<<=1 )
					if( r & i && patterns[i].test( c ) )
						break;
				return i <= r || c == rule;
			}
			var k, mC, r, c = String.fromCharCode( k = e.key ), l = f.value.length;
			( !k || k == 8 ? 1 : ( r = /^(.)\^(.*)$/.exec( m ) ) && ( r[0] = r[2].indexOf( c ) + 1 ) + 1 ? r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : validChar( c, r[1] ) || r[0] : ( l = ( f.value += m.substr( l, ( r = /[A|9|C|\*]/i.exec( m.substr( l ) ) ) ? r.index : l ) ).length ) < m.length && validChar( c, m.charAt( l ) ) ) || e.preventDefault();
		} );
};


/***************************************************************************************************************/