﻿//	validate user input on the contact form
function ValidateForm()
{
	var valid = true;
	$('.required').each(function(){
		var val = $(this).val();
        if(val.length < 1){ 
             valid = false;
        }
    });
    if(valid==false)
    {
		$('#formMessage').text('Palun täitke kõik vormi väljad!');
		if($('#overlay').length > 0){
			w_height = $('#overBottomLeft').height();
			$('#overBottomLeft').css({height:(w_height+15)});
			$('#overBottomRight').css({height:(w_height+15)});
		}
    }
	else
	{
		RemoveOverlay();
	}
	return valid;
}

//	get pricelist details when selected from flash
function pricelist(floor){
	var url='list.php?korrus='+floor;
	$('#priceListWrapper').load(url);
	
}

//	object popup
function showpopup(appartment){
	window.open('popup.php?nr='+appartment, 'Korter', 'width=740,height=520,toolbar=0,location=0,status=0');
}

//	location popup
function showlocation(){
	window.open('gfx/asendiplaan.jpg', 'Asendiplaan', 'width=416,height=525,toolbar=0,location=0,status=0');
	return false;
}
//	open links in a new window
function openwindow(location){
	window.open(location);
	return false;
}
//	select apartment in the contact form
function bookapartment(nr){
	var w_height = $('#wrapper').height();
	var w_width = $('html').width();
	var browser = navigator.userAgent;
	var right_width = (w_width-940)/2+10;
	
	if(browser.indexOf('MSIE 7.0') > 0){
		w_height -= 52;
	}
	
	$('#formButton').css({visibility:'visible'});
	$('body').append('<div id="overlay"></div><div id="overBottomLeft"></div><div id="overBottomRight"></div>');
	$('#overlay').css({height:(w_height-260)});
	$('#overBottomLeft').css({top:(w_height-260),width:(right_width+600)});
	$('#overBottomRight').css({top:(w_height-260),width:right_width});
	
	w_height += 360;
	$('html, body').animate({scrollTop: w_height}, 100);
	$("#appartmentDropDown").val(nr);
	return false;
}

function RemoveOverlay(){
	$('#overlay, #overBottomLeft, #overBottomRight').remove();
	$('#formButton').css({visibility:'hidden'});
}


$(document).ready(function(){
	//	switch form submitt button
	$('.formButton').hover(function(){
		var i = $(this).attr('src');
		i = i.replace(/normal/i, "hover"); 
		$(this).attr({src:i});
	},function(){
		var i = $(this).attr('src');
		i = i.replace(/hover/i, "normal"); 
		$(this).attr({src:i});
	});
	//	validate form info when button clicked
	$('.formButton').click(function(){
		return ValidateForm();
	});
	// remove overlay if clicked on
	$('#formButton').click(function(){
		RemoveOverlay();
	});
});