function show(rid) {
	current=(document.getElementById(rid).style.display == 'none') ? 'block' : 'none'
	document.getElementById(rid).style.display = current
}

function createOption(selectObj, value, text, selected) {
	var obj = document.createElement("OPTION");
	selectObj.options.add(obj);
	obj.text = text;
	obj.value = value;
	obj.selected = selected;	
} 

function clearSelect(selectObj) {
	selectObj.innerHTML = "";

} 

function showCalendar(field, button) {
	displayCalendar(field, 'yyyy-mm-dd', button, false, false);
}


function boolToYesNo(value) {
	return value ? 'yes' : 'no' ;
}

function openWindow(oPConfig) {

	var ret_val = null;
	
	var window_params = '';
	
	var oConfig = {
		
		'x' 		: -1,
		'y' 		: -1,
		'width' 	: 400,
		'height' 	: 400,
		'nodups'	: true,
		'scroll'	: true,
		'status'	: false,
		'location'	: false,
		'menubar'	: false,
		'toolbar'	: false,
		'hotkeys'	: false,
		'fullscreen': false,
		'resize'	: false,
		'name'		: 'dialog',
		'url'		: 'about:blank'
		
	}

	if( oPConfig && typeof( oPConfig ) == 'object' ) {
		
		for( var idx in oPConfig ) {
			if( typeof( oConfig[idx] ) != 'undefined' ) {
				oConfig[idx] = oPConfig[idx];
			}
		}
				
		
		if( oConfig.x < 0 ) {
			oConfig.x = Math.round( ( screen.height - oConfig.height ) / 2 );
		}
		
		if( oConfig.y < 0 ) {
			oConfig.y = Math.round( ( screen.width - oConfig.width ) / 2 );
		}
		
		window_params = 
			
			'top=' + oConfig.x + ',' +
			'left=' + oConfig.y + ',' +
			'width=' + oConfig.width + ',' +
			'height=' + oConfig.height + ',' +
			'location=' + boolToYesNo( oConfig.location ) + ',' +
			'menubar=' + boolToYesNo( oConfig.menubar ) + ',' +
			'toolbar=' + boolToYesNo( oConfig.toolbar ) + ',' +
			'hotkeys=' + boolToYesNo( oConfig.hotkeys ) + ',' +
			'fullscreen=' + boolToYesNo( oConfig.fullscreen ) + ',' +
			'resizable=' + boolToYesNo( oConfig.resize ) + ',' +
			'status=' + boolToYesNo( oConfig.status ) + ',' +
			'scrollbars=' + boolToYesNo( oConfig.scroll );
		
		ret_val = window.open(oConfig.url, oConfig.name, window_params);
		
	}
	
	return ret_val;
}

function show(id){
	var row = document.getElementById(id);
	row.style.display = '';
}

function hide(id){
	var row = document.getElementById(id);
	row.style.display = 'none';
}

function change(id) {
	var row = document.getElementById(id);
	if (row.style.display == 'none') row.style.display = '';
	else row.style.display = 'none';
}

function add_rooms(var_r) {
	if (var_r<6) {
		show('r'+var_r);
		var_r++;
	} else {
		show('r'+var_r);
		hide('add_rooms');
	}
	return(var_r);
}

function blank(id, defaulttext) {
	if (id.value == defaulttext) {
		id.value = "";
	}
}

function restore(id, defaulttext) {
	if (id.value == "") {
		id.value = defaulttext;
	}
}

function postbackForm(form, action) {
	form.action = "";
	
	if (typeof(form["postback_url"]) != 'undefined') {
		form["act"].value = form["postback_url"].value;	
	}
	form.method = "get";
	
	if (action) {
		form["postback_action"].value = action;
	}
	form.submit();
}


function getNextDate(value) {
	var tmp = value.split("-");
	var fromDate = new Date(parseInt(tmp[0], 10), parseInt(tmp[1], 10) - 1, parseInt(tmp[2], 10));		
	var nextDate = new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate() + 1);	

	return nextDate.getFullYear() + "-" + (nextDate.getMonth() + 1 > 9 ? nextDate.getMonth() + 1 : "0" + (nextDate.getMonth()  + 1)) + "-" + (nextDate.getDate() > 9 ? nextDate.getDate() : "0" + nextDate.getDate())
} 

function getNightsCount(date1, date2) {
	var tmp = date1.split("-");
	var fromDate = new Date(parseInt(tmp[0], 10), parseInt(tmp[1], 10) - 1, parseInt(tmp[2], 10));		
	
	var tmp = date2.split("-");
	var toDate = new Date(parseInt(tmp[0], 10), parseInt(tmp[1], 10) - 1, parseInt(tmp[2], 10));	
	
	var DSTAdjust = 0;
    // constants used for our calculations below
    oneMinute = 1000 * 60;
    var oneDay = oneMinute * 60 * 24;
    // equalize times in case date objects have them
    fromDate.setHours(0);
    fromDate.setMinutes(0);
    fromDate.setSeconds(0);
    toDate.setHours(0);
    toDate.setMinutes(0);
    toDate.setSeconds(0);
    // take care of spans across Daylight Saving Time changes
    if (toDate > fromDate) {
        DSTAdjust = 
            (toDate.getTimezoneOffset() - fromDate.getTimezoneOffset()) * oneMinute;
    } else {
        DSTAdjust = 
            (fromDate.getTimezoneOffset() - toDate.getTimezoneOffset()) * oneMinute;    
    }
    var diff = Math.abs(toDate.getTime() - fromDate.getTime()) - DSTAdjust;
    return Math.ceil(diff/oneDay);
}

var Base64 = {
		 
		// private property
		_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	 
		// public method for encoding
		encode : function (input) {
			var output = "";
			var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
			var i = 0;
	 
			input = Base64._utf8_encode(input);
	 
			while (i < input.length) {
	 
				chr1 = input.charCodeAt(i++);
				chr2 = input.charCodeAt(i++);
				chr3 = input.charCodeAt(i++);
	 
				enc1 = chr1 >> 2;
				enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
				enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
				enc4 = chr3 & 63;
	 
				if (isNaN(chr2)) {
					enc3 = enc4 = 64;
				} else if (isNaN(chr3)) {
					enc4 = 64;
				}
	 
				output = output +
				this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
				this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
	 
			}
	 
			return output;
		},
	 
		// public method for decoding
		decode : function (input) {
			var output = "";
			var chr1, chr2, chr3;
			var enc1, enc2, enc3, enc4;
			var i = 0;
	 
			input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	 
			while (i < input.length) {
	 
				enc1 = this._keyStr.indexOf(input.charAt(i++));
				enc2 = this._keyStr.indexOf(input.charAt(i++));
				enc3 = this._keyStr.indexOf(input.charAt(i++));
				enc4 = this._keyStr.indexOf(input.charAt(i++));
	 
				chr1 = (enc1 << 2) | (enc2 >> 4);
				chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
				chr3 = ((enc3 & 3) << 6) | enc4;
	 
				output = output + String.fromCharCode(chr1);
	 
				if (enc3 != 64) {
					output = output + String.fromCharCode(chr2);
				}
				if (enc4 != 64) {
					output = output + String.fromCharCode(chr3);
				}
	 
			}
	 
			output = Base64._utf8_decode(output);
	 
			return output;
	 
		},
	 
		// private method for UTF-8 encoding
		_utf8_encode : function (string) {
			string = string.replace(/\r\n/g,"\n");
			var utftext = "";
	 
			for (var n = 0; n < string.length; n++) {
	 
				var c = string.charCodeAt(n);
	 
				if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}
	 
			}
	 
			return utftext;
		},
	 
		// private method for UTF-8 decoding
		_utf8_decode : function (utftext) {
			var string = "";
			var i = 0;
			var c = c1 = c2 = 0;
	 
			while ( i < utftext.length ) {
	 
				c = utftext.charCodeAt(i);
	 
				if (c < 128) {
					string += String.fromCharCode(c);
					i++;
				}
				else if((c > 191) && (c < 224)) {
					c2 = utftext.charCodeAt(i+1);
					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
					i += 2;
				}
				else {
					c2 = utftext.charCodeAt(i+1);
					c3 = utftext.charCodeAt(i+2);
					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
					i += 3;
				}
	 
			}
	 
			return string;
		}
	 
	}
