
// predefined messages
var msg_pop_close = 'click on the image to close this window';
var msg_form_err = 'Fill all required fields, please.';

/****
 * open a window and write img to it
 * pop_close -- notification message, which is set from outside this file
 * 'paspaudus ant paveiksliuko langas užsidaro'
 *
 * @param	string		image name
 * @param	integer		iamge width
 * @param	integer		iamge height
 */
function popImg(img, width, height) {
	var w = (width != undefined) ? ',width=' + width : '';
	var h = (height != undefined) ? ',height=' + height : '';
	oPop = window.open('', 'pop', 'status=0,toolbar=0,menubar=0,location=0,directories=0,left=60,top=30,' + w + h);
	// fix size
	if (oPop.document.all) {
		oPop.resizeTo(width, height);
		diffW = width - oPop.document.body.clientWidth;
		diffH = height - oPop.document.body.clientHeight;
	} else {
		oPop.resizeTo(width, height);
		diffW = width - oPop.innerWidth;
		diffH = height - oPop.innerHeight;
	}
	w = width + diffW;
	h = height + diffH;
	if (h >= screen.availHeight) w += 16;
	if (w >= screen.availWidth)  h += 16;
	w = Math.min(w, screen.availWidth);
	h = Math.min(h, screen.availHeight);
	oPop.resizeTo(w, h);
	// write contents
	oPop.document.open('text/html', 'replace');
	oPop.document.write(
		'<html><head><title> Viešbutis &#147;Lūgnė&#148; </title></head>'+
		'<body style="background: #001576; margin: 0; overflow: outo;">'+
		'<a href="javascript:void(0);" onClick="window.close();"><img src="img/'+ img +'" border=0 alt=" '+ msg_pop_close +' " /></a>'+
		'</body></html>'
	);
	oPop.document.close();
	oPop.focus();
}


/****
 * clear whitespaces from a beggining and end of e string
 *
 * @param	string
 */
function trim(str) {
	if (str != undefined) {
		str = str.replace(/^\W+/, '');
		str = str.replace(/\W+$/, '');
		return str;
	} else {
		return '';
	}
}

// formu privalomi laukai
var fReq = new Array();
	fReq['reservation'] = new Array('first_name', 'surname', 'tel', 'room_type', 'date_from', 'date_upto', '', '', '');

/***
 * formu privalomu lauku patikrinimas
 * form_err -- error message, which is set from outside this file
 *
 * @param	object		form
 */
function checkForm(oFrom) {
	var size = fReq[oFrom.name].length;
	for(var i = 0; i < size; i++) {
		if (trim(oFrom.elements[fReq[oFrom.name][i]].value) == '') {
			alert(msg_form_err);
			return false;
		}
	}
	return true;
}
