function get_client_info(browser){
	var agt=navigator.userAgent.toLowerCase();

	// *** BROWSER VERSION ***
	// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);

	// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
	// If you want to allow spoofing, take out the tests for opera and webtv.
	var is_nav		= ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
					&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
					&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_nav2		= (is_nav && (is_major == 2));
	var is_nav3		= (is_nav && (is_major == 3));
	var is_nav4		= (is_nav && (is_major == 4));
	var is_nav4up	= (is_nav && (is_major >= 4));
	var is_navonly	= (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)));
	var is_nav6		= (is_nav && (is_major == 5));
	var is_nav6up	= (is_nav && (is_major >= 5));
	var is_gecko	= (agt.indexOf('gecko') != -1);

	var is_ie		= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3		= (is_ie && (is_major < 4));
	var is_ie4		= (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie4up	= (is_ie && (is_major >= 4));
	var is_ie5		= (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5_5	= (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	var is_ie5up	= (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up	= (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6		= (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie6up	= (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

	// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
	// or if this is the first browser window opened.  Thus the
	// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
	var is_aol		= (agt.indexOf("aol") != -1);
	var is_aol3		= (is_aol && is_ie3);
	var is_aol4		= (is_aol && is_ie4);
	var is_aol5		= (agt.indexOf("aol 5") != -1);
	var is_aol6		= (agt.indexOf("aol 6") != -1);

	var is_opera	= (agt.indexOf("opera") != -1);
	var is_opera2	= (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
	var is_opera3	= (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
	var is_opera4	= (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
	var is_opera5	= (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
	var is_opera5up	= (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

	var is_webtv	= (agt.indexOf("webtv") != -1);

	var is_TVNavigator	= ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
	var is_AOLTV		= is_TVNavigator;

	var is_hotjava		= (agt.indexOf("hotjava") != -1);
	var is_hotjava3		= (is_hotjava && (is_major == 3));
	var is_hotjava3up	= (is_hotjava && (is_major >= 3));

	// *** JAVASCRIPT VERSION CHECK ***
	var is_js;
	if (is_nav2 || is_ie3) is_js = 1.0;
	else if (is_nav3) is_js = 1.1;
	else if (is_opera5up) is_js = 1.3;
	else if (is_opera) is_js = 1.1;
	else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
	else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
	else if (is_hotjava3up) is_js = 1.4;
	else if (is_nav6 || is_gecko) is_js = 1.5;
	// NOTE: In the future, update this code when newer versions of JS
	// are released. For now, we try to provide some upward compatibility
	// so that future versions of Nav and IE will show they are at
	// *least* JS 1.x capable. Always check for JS version compatibility
	// with > or >=.
	else if (is_nav6up) is_js = 1.5;
	// NOTE: ie5up on mac is 1.4
	else if (is_ie5up) is_js = 1.3

	// HACK: no idea for other browsers; always check for JS version with > or >=
	else is_js = 0.0;

	// *** PLATFORM ***
	var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
	//        Win32, so you can't distinguish between Win95 and WinNT.
	var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	var is_win16	= ((agt.indexOf("win16")!=-1) || (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("windows 16-bit")!=-1) );
	var is_win31	= ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) || (agt.indexOf("windows 16-bit")!=-1));
	var is_winme	= ((agt.indexOf("win 9x 4.90")!=-1));
	var is_win2k	= ((agt.indexOf("windows nt 5.0")!=-1));

	// NOTE: Reliable detection of Win98 may not be possible. It appears that:
	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
	//       - On Mercury client, the 32-bit version will return "Win98", but
	//         the 16-bit version running on Win98 will still return "Win95".
	var is_win98	= ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	var is_winnt	= ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
	var is_win32	= (is_win95 || is_winnt || is_win98 || ((is_major >= 4) && (navigator.platform == "Win32")) || (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

	var is_os2		= ((agt.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (agt.indexOf("ibm-webexplorer")!=-1));

	var is_mac    = (agt.indexOf("mac")!=-1);
	// hack ie5 js version for mac
	if (is_mac && is_ie5up) is_js = 1.4;
	var is_mac68k	= (is_mac && ((agt.indexOf("68k")!=-1) || (agt.indexOf("68000")!=-1)));
	var is_macppc	= (is_mac && ((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1)));

	var is_sun		= (agt.indexOf("sunos")!=-1);
	var is_sun4		= (agt.indexOf("sunos 4")!=-1);
	var is_sun5		= (agt.indexOf("sunos 5")!=-1);
	var is_suni86	= (is_sun && (agt.indexOf("i86")!=-1));
	var is_irix		= (agt.indexOf("irix") !=-1);    // SGI
	var is_irix5	= (agt.indexOf("irix 5") !=-1);
	var is_irix6	= ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
	var is_hpux		= (agt.indexOf("hp-ux")!=-1);
	var is_hpux9	= (is_hpux && (agt.indexOf("09.")!=-1));
	var is_hpux10	= (is_hpux && (agt.indexOf("10.")!=-1));
	var is_aix		= (agt.indexOf("aix") !=-1);      // IBM
	var is_aix1		= (agt.indexOf("aix 1") !=-1);
	var is_aix2		= (agt.indexOf("aix 2") !=-1);
	var is_aix3		= (agt.indexOf("aix 3") !=-1);
	var is_aix4		= (agt.indexOf("aix 4") !=-1);
	var is_linux	= (agt.indexOf("inux")!=-1);
	var is_sco		= (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
	var is_unixware	= (agt.indexOf("unix_system_v")!=-1);
	var is_mpras	= (agt.indexOf("ncr")!=-1);
	var is_reliant	= (agt.indexOf("reliantunix")!=-1);
	var is_dec		= ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
	var is_sinix	= (agt.indexOf("sinix")!=-1);
	var is_freebsd	= (agt.indexOf("freebsd")!=-1);
	var is_bsd		= (agt.indexOf("bsd")!=-1);
	var is_unix		= ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || is_sco ||is_unixware || is_mpras || is_reliant || is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

	var is_vms		= ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

	if (browser==1)
	{
		if (is_ie) return "ie";
		if (is_gecko) return "gecko";
	}
}

function makeRequest(url, where, div) {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(http_request, where, div); };
	http_request.open('GET', url, true);
	http_request.send(null);
}

function alertContents(http_request, where, div) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (where=="self")
			{
				document.getElementById(div).innerHTML=http_request.responseText;
			}
			if (where=="window")
			{
				parent.document.getElementById(div).innerHTML=http_request.responseText;
			}
		} else {
			alert('There was a problem with the request.');
		}
	}

}

function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ro|eu)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
//		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
//			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
//			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	if (user.match(userPat)==null) {
//		alert("The username doesn't seem to be valid.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
//				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;

	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
//			alert("The domain name does not seem to be valid.");
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
//		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	if (len<2) {
//		alert("This address is missing a hostname!");
		return false;
	}
	return true;
}

// onmouseover floating layer functions
var cX = 0; var cY = 0;
function UpdateCursorPosition(e){
	cX = e.pageX;
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(e){
	cX = event.clientX;
	cY = event.clientY;
}
if(document.all) {
	document.onmousemove = UpdateCursorPositionDocAll;
}
else {
	document.onmousemove = UpdateCursorPosition;
}
function AssignPosition(d) {
	d.style.left = (cX+10) + "px";
	d.style.top = (cY+10) + "px";
}
function HideContent(d) {
	if(d.length < 1) return;
	setTimeout("do_hide('"+d+"');", 1000);
}
function do_hide(d){
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) return;
	var dd = document.getElementById(d);
	dd.style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) return;
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") {
		ShowContent(d);
	}
	else {
		HideContent(d);
	}
}

// moving error messages div arround //

if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
	if (document.getElementById('error_messages'))
	{

		minus=-15;
		document.getElementById('error_messages').style.top = yMousePos+15;
		document.getElementById('error_messages').style.left = xMousePos-minus;
	}
}

// moving error messages div arround //

function hide (obj){
	obj.className = "hidden";
}

function show (obj){
	obj.className = "shown";
}

function error (message){
	error_messages_obj = document.getElementById('error_messages');
	error_messages_obj.innerHTML = "<font color='red'><b>"+message+"</b></font>";
	error_messages_obj.className="shown";

	setTimeout('hide (error_messages_obj)', 2000);
}

// base64 encode/decode functions

function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

var END_OF_INPUT = -1;

var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}
function readReverseBase64(){   
    if (!base64Str) return END_OF_INPUT;
    while (true){      
        if (base64Count >= base64Str.length) return END_OF_INPUT;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    }
    return END_OF_INPUT;
}

function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}

function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != END_OF_INPUT){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != END_OF_INPUT){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}

var digitArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function toHex(n){
    var result = ''
    var start = true;
    for (var i=32; i>0;){
        i-=4;
        var digit = (n>>i) & 0xf;
        if (!start || digit != 0){
            start = false;
            result += digitArray[digit];
        }
    }
    return (result==''?'0':result);
}

function pad(str, len, pad){
    var result = str;
    for (var i=str.length; i<len; i++){
        result = pad + result;
    }
    return result;
}

function encodeHex(str){
    var result = "";
    for (var i=0; i<str.length; i++){
        result += pad(toHex(str.charCodeAt(i)&0xff),2,'0');
    }
    return result;
}

function decodeHex(str){
    str = str.replace(new RegExp("s/[^0-9a-zA-Z]//g"));
    var result = "";
    var nextchar = "";
    for (var i=0; i<str.length; i++){
        nextchar += str.charAt(i);
        if (nextchar.length == 2){
            result += ntos(eval('0x'+nextchar));
            nextchar = "";
        }
    }
    return result;
    
}

// base64 encode/decode funtions end

function Wpopup(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 50,top = 50');");
}

function check_book_form(){
	dateok = 1;
	if (document.getElementById('checkin_date').value=="")
	{
		error ('You have to select a check-in date');
		return false;
	}
	if (document.getElementById('checkout_date').value=="")
	{
		error ('You have to select a check-out date');
		return false;
	}
	return true;
}

function show_big_image(image_path){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	document.getElementById('big_image_div').style.top = document.body.scrollTop+(winH/2-200);
	document.getElementById('big_image_div').style.left = (winW/2-300);

	document.getElementById('big_image_div').className="shown";
	document.getElementById('big_image').src='img/loading.gif';

	makeRequest('includes/inc/show_big_img.inc.php?link='+image_path, 'self', 'big_image_div');

}

function close_big_image(){
	document.getElementById('big_image_div').className="hidden";
}

function refresh_window(time, where){
	setTimeout ("window.location='"+where+"'", time);
}

function submit_book_form(date){
	document.getElementById('checkin_date').value = date;
	document.getElementById('book_form').submit();
}

function verify_booking(){
	if (document.getElementById('lastname').value=="")
	{
		alert ('"Last name" field is empty !');
		document.getElementById('lastname').focus();
		return false;
	}
	if (document.getElementById('firstname').value=="")
	{
		alert ('"First name" field is empty !');
		document.getElementById('firstname').focus();
		return false;
	}
	if (document.getElementById('telephone').value=="")
	{
		alert ('"Telephone" field is empty !');
		document.getElementById('telephone').focus();
		return false;
	}
	if (document.getElementById('email').value=="")
	{
		alert ('"E-mail" field is empty !');
		document.getElementById('email').focus();
		return false;
	}
	if (!emailCheck(document.getElementById('email').value))
	{
		alert ('You must enter a valid E-mail address !');
		document.getElementById('email').focus();
		return false;
	}
	return true;
}

function disabletext(e){
return false
}

function reEnable(){
return true
}

