/* Open specified URL in new window (small) */
function popUp(URL) {
	var day = new Date();
	var id = day.getTime();
	var width = 450;
	var height = 300;
	var left = (1024 - width) / 2;
	var top = (768 - height) / 2;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",left =" + left + ",top = " + top + "');");
}

// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety =  8;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip()
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
	if(document.myform.town_name.value) {
    lixlpixel_tooltip.innerHTML = document.myform.town_name.value;
	}
	else {
	lixlpixel_tooltip.innerHTML = "No locations have been specified.";
	}
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}

function tooltip_text(tip)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
	
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}
function ChatWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=0'
	win = window.open(mypage,myname,settings)
}

function checkFields() {

if (document.form5.shipname.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;First Name";

}

if (document.form5.shipsurname.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Last Name";

}


if (document.form5.shipmail.value == "" || !isValidEmail( document.form5.shipmail.value ) ) {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;E-mail";

}

if (document.form5.adult_code.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Username";

}


if (document.form5.password.value == "" || document.form5.password2.value == "" || document.form5.password.value!=document.form5.password2.value) {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Password";

}




if (missinginfo != "") {


missinginfo = 

"You have not filled correctly the following fields:<br>" +

missinginfo;

document.getElementById('errors').style.display = "block";
document.getElementById('errors').innerHTML=missinginfo;
scroll(0,0);

return false;

}

else 

return true;

}
function NewWindowPopup(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=0'
	win = window.open(mypage,myname,settings)
}

function insertdates()	{
	window.opener.document.searchform.arrival.value=document.datesform.arrival.value;
	window.opener.document.searchform.departure.value=document.datesform.departure.value;
	self.close();
}

function updatepage($villa_id)	{
	window.opener.location='villa-details.php?property_id=' + $villa_id + '&arrival=' + document.datesform.arrival.value + '&departure=' + document.datesform.departure.value;
	self.close();
}



function submitform()
{
if(document.searchform.arrival.value == '' || document.searchform.departure.value == '') {
	alert('Please select the dates of your holiday, in order to proceed to the next step');
}
else {
  document.searchform.submit();
}
}

function submitextras()
{
  document.extrasform.submit();
}

function submitnoextras()
{
  document.noextrasform.submit();
}

function submitpayment()
{
  document.paymentform.submit();
}

function submitinquiry()
{
  document.inquiryform.submit();
}

function submitairport()
{
  document.airportform.submit();
}

function submitcar()
{
  document.carform.submit();
}

function submittestimonials()
{
  document.prtestimonials.submit();
}

function submitNews()
{
  document.NewsLetterForm1.submit();
}

function isValidEmail( fieldValue ) {
	if ( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/.test(fieldValue) )
		return true;
	
	return false;
}


function checkBookingFrom() {

missinginfo = "";

if (document.bookingform.shipname.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;First Name";

}

if (document.bookingform.shipsurname.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Last Name";

}


if (document.bookingform.shipmail.value == "" || !isValidEmail( document.bookingform.shipmail.value ) ) {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;E-mail";

}


if (document.bookingform.shiptel.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Home Telephone";

}

if (document.bookingform.shipcountry.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Country";

}


if (document.bookingform.shipmobile.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Mobile";

}

if (document.bookingform.shippostal.value == "") {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;Postal Code";

}

if (!document.bookingform.agreement.checked) {

missinginfo += "<br>&nbsp;&nbsp;&bull;&nbsp;You have to read the Terms & Condition before you proceed to the payment.";


}


if (missinginfo != "") {


missinginfo = 

"<strong>Information Required</strong><br />" +

missinginfo;

document.getElementById('errors').style.display = "block";
document.getElementById('errors').innerHTML=missinginfo;
scroll(0,0);

return false;

}

else 

return document.bookingform.submit();

}

function createDateTo() {
	dateFrom = document.getElementById('arrival').value;
	
	document.getElementById('departure').value = dateFrom;
}
function showDetails(name) {
	if(document.getElementById(name).className = "hidd") {
		document.getElementById(name).className = "shown";
	}
}

function hideDetails(name) {
	if(document.getElementById(name).className = "shown") {
		document.getElementById(name).className = "hidd";
	}
}