/* standart functions */
function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getDocumentHeight(){
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}
function getDocumentWidth(){
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}
function getElementPosition(elemId){
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}
function getElementPosition2(elem){
    var elem = elem;
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
	var classes = elem[i].className;
	if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}; 
function getElementComputedStyle(elem, prop)
{
  if (typeof elem!="object") elem = document.getElementById(elem);
  
  // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
  if (document.defaultView && document.defaultView.getComputedStyle)
  {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  
  // external stylesheet for Explorer and Opera 9
  if (elem.currentStyle)
  {
    var i;
    while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
    return elem.currentStyle[prop];
  }
  
  return "";
}
/* end of standart functions */

function numbersonly(e, decimal) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if (decimal && (keychar == ".")) { 
  return true;
}
else
   return false;
}

function setActStar(starNumber) {
	var starsArray = new Array("star1", "star2", "star3", "star4", "star5");
	for (i = 0; i <= 4; i++) {
		document.getElementById(starsArray[i]).style.backgroundImage = "url(../_common/img/star.gif)";
	}
	for (i = 0; i <= (starNumber-1); i++) {
		document.getElementById(starsArray[i]).style.backgroundImage = "url(../_common/img/star_act.gif)";
		document.getElementById("stars_counter").value = (starNumber);
	}
}
function setActStarFr(starNumber) {
	var starsArray = new Array("star1", "star2", "star3", "star4", "star5");
	for (i = 0; i <= 4; i++) {
		document.getElementById(starsArray[i]).style.backgroundImage = "url(../../_common/img/star.gif)";
	}
	for (i = 0; i <= (starNumber-1); i++) {
		document.getElementById(starsArray[i]).style.backgroundImage = "url(../../_common/img/star_act.gif)";
		document.getElementById("stars_counter").value = (starNumber);
	}
}

function getScrollH()
{
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop;
	}else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop;
	}else if ( window.pageYOffset ){
		scrollY = window.pageYOffset;
	}else if ( window.scrollY ){
		scrollY = window.scrollY;
	}
	return scrollY;
}

function showFrameText(roomNumber) {
	scrollY = getScrollH();
	var browserName=navigator.appName;
	var iframeBlock = document.getElementById("iframeBlock");
	var blackBg = document.getElementById("blackBg");
	iframeBlock.style.top = scrollY + 15 + "px";
	blackBg.style.display = "block";
	blackBg.style.height = getElementPosition2(document.getElementsByClassName("footerBlock")[0]).top + 250 + "px";
	
	iframeBlock.style.display = "block";
	document.getElementById('catalogFrame').src="catalog/"+ roomNumber +".htm";
}
function showFrameTextFr(roomNumber) {
	scrollY = getScrollH();
	var browserName=navigator.appName;
	var iframeBlock = document.getElementById("iframeBlock");
	iframeBlock.style.top = scrollY + 15 + "px";
	document.getElementById("blackBg").style.display = "block";
	document.getElementById("blackBg").style.height = document.body.clientHeight + 250 + "px";
	
	document.getElementById('iframeBlock').style.display = "block";
	document.getElementById('catalogFrame').src="../catalog/"+ roomNumber +".htm";
}

function showFrameImages(roomNumber) {
	scrollY = getScrollH();
	var iframeBlock = document.getElementById("iframeBlock");
	iframeBlock.style.top = scrollY + 15 + "px";
	
	document.getElementById("blackBg").style.display = "block";
	document.getElementById("blackBg").style.height = document.body.clientHeight + 250 + "px";
	
	document.getElementById('iframeBlock').style.display = "block";
	document.getElementById('catalogFrame').src="catalog/"+ roomNumber +".htm#photos";
}

function hideFrameText() {
	document.getElementById("blackBg").style.display = "none";
	document.getElementById('iframeBlock').style.display = "none";
	document.getElementById('catalogFrame').src="";
}

// VALIDATION START
function show_alert_message(text){
	var hei = getElementPosition2(document.getElementsByClassName("footerBlock")[0]).top + 250;
	
	if(hei < getDocumentHeight()){
		hei = getDocumentHeight();
	}
	if(hei < getClientHeight()){
		hei = getClientHeight();
	}
	
	scrollY = getScrollH();
	show_hide_select("hidden");
	show_hide_video("hidden");
	document.getElementById("blackBg").style.display = 'block';
	document.getElementById("blackBg").style.height = hei + "px";
	var popupBlock = document.getElementById("form_alert_message");
	popupBlock.style.top = scrollY + 100 + "px"; 
	popupBlock.style.display = "block";
	document.getElementById("alert_getstarted").innerHTML = text;
}

function hide_alert_message(){
	show_hide_select("visible");
	show_hide_video("visible");
	document.getElementById("blackBg").style.display = 'none';
	var popupBlock = document.getElementById("form_alert_message");
	popupBlock.style.display = "none";	
}

function show_hide_select(types)
{
	
	for(i=0;i<document.getElementsByTagName("select").length;i++){
		document.getElementsByTagName("select")[i].style.visibility = types;
	}
	
}
function show_hide_video(type){
	if(document.getElementById("contents")){
		document.getElementById("contents").style.visibility = type;
	}
}

function getScrollH()
{
	
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop;
	}else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop;
	}else if ( window.pageYOffset ){
		scrollY = window.pageYOffset;
	}else if ( window.scrollY ){
		scrollY = window.scrollY;
	}
	return scrollY;
}
function validateEmail(email)
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email))
        return true
    else
        return false;
}
function check_contact()
{
	email = document.getElementById('email').value;
	fnames = document.getElementById('fname').value;
	lnames = document.getElementById('lname').value;
	/*phone = document.getElementById('telephone').value;
	messages = document.getElementById('message').value;*/

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
    /*if(phone == '')
    {
		txt += '<div class="alertRow">Téléphone</div>';
    }

    if(messages == '')
    {
		txt += '<div class="alertRow">Commentaire</div>';
    }*/

    if(txt == ""){
        document.contact.submit();
	}
	else{
		show_alert_message(txt);
	}
}

function check_your_need()
{
	email = document.getElementById('email').value;
	fnames = document.getElementById('fname').value;
	lnames = document.getElementById('lname').value;
	arrives = document.getElementById('arrive').value;
	departs = document.getElementById('depart').value;
	stay_lenghts = document.getElementById('stay_lenght').value;
	purposes = document.getElementById('purpose').value;
	/*adults = document.getElementById('adult').value;
	childs = document.getElementById('child').value;
	stars = document.getElementById('stars_counter').value;*/
	budgets = document.getElementById('budget').value;

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
    if(arrives == '')
    {
		txt += '<div class="alertRow">Date prévue d&acute;arrivée</div>';
    }

    if(departs == '')
    {
		txt += '<div class="alertRow">Date prévue de départ</div>';
    }
	
	 if(stay_lenghts == '')
    {
		txt += '<div class="alertRow">Durée du séjour</div>';
    }
	
	 if(purposes == '')
    {
		txt += '<div class="alertRow">Objectif du séjour<br>(travail, stage, vacances, études)</div>';
    }
	
	/* if(adults == '')
    {
		txt += '<div class="alertRow">adulte(s)</div>';
    }
	
	 if(childs == '')
    {
		txt += '<div class="alertRow">enfant(s)</div>';
    }
	
	 if(stars == '')
    {
		txt += '<div class="alertRow">Type de logement</div>';
    }*/
	
	 if(budgets == '')
    {
		txt += '<div class="alertRow">Votre budget (fourchette)</div>';
    }

    if(txt == ""){
        document.your_need.submit();
	}
	else{
		show_alert_message(txt);
	}
}

function check_hotels()
{
	email = document.getElementById('email').value;
	fnames = document.getElementById('fname').value;
	lnames = document.getElementById('lname').value;
	arrives = document.getElementById('arrive').value;
	departs = document.getElementById('depart').value;
	purposes = document.getElementById('purpose').value;
	/*adults = document.getElementById('adult').value;
	childs = document.getElementById('child').value;
	stars = document.getElementById('stars_counter').value;*/
	budgets = document.getElementById('budget').value;

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
    if(arrives == '')
    {
		txt += '<div class="alertRow">Date prévue d&acute;arrivée</div>';
    }

    if(departs == '')
    {
		txt += '<div class="alertRow">Date prévue de départ</div>';
    }
	
	 if(purposes == '')
    {
		txt += '<div class="alertRow">Objectif du séjour<br>(travail, stage, vacances, études)</div>';
    }
	
	/* if(adults == '')
    {
		txt += '<div class="alertRow">adulte(s)</div>';
    }
	
	 if(childs == '')
    {
		txt += '<div class="alertRow">enfant(s)</div>';
    }
	
	 if(stars == '')
    {
		txt += '<div class="alertRow">Type de logement</div>';
    }*/
	
	 if(budgets == '')
    {
		txt += '<div class="alertRow">Votre budget (fourchette)</div>';
    }

    if(txt == ""){
        document.hotels.submit();
	}
	else{
		show_alert_message(txt);
	}
}
/*-------------------------------------------*/
function check_studio_formule() {
	fnames = document.getElementById('fname').value;
	lnames = document.getElementById('lname').value;
	email = document.getElementById('email').value;
	arrives = document.getElementById('arrive').value;
	departs = document.getElementById('depart').value;

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
    if(arrives == '')
    {
		txt += '<div class="alertRow">Date prévue d&acute;arrivée</div>';
    }

    if(departs == '')
    {
		txt += '<div class="alertRow">Date prévue de départ</div>';
    }

    if(txt == ""){
        document.studio_formule.submit();
	}
	else{
		show_alert_message(txt);
	}
}

function check_colocation()
{
	email = document.getElementById('email').value;
	fnames = document.getElementById('fname').value;
	lnames = document.getElementById('lname').value;
	arrives = document.getElementById('arrive').value;
	departs = document.getElementById('depart').value;
	/*personnumbers = document.getElementById('personnumber').value;*/

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
    if(arrives == '')
    {
		txt += '<div class="alertRow">Date prévue d&acute;arrivée</div>';
    }

    if(departs == '')
    {
		txt += '<div class="alertRow">Date prévue de départ</div>';
    }
	
	/* if(personnumbers == '')
    {
		txt += '<div class="alertRow">Nombre de personnes</div>';
    }*/

    if(txt == ""){
        document.colocation.submit();
	}
	else{
		show_alert_message(txt);
	}
}

function check_owners1()
{
	email = document.getElementById('email').value;
	fnames = document.getElementById('fname').value;
	lnames = document.getElementById('lname').value;
	/*phone = document.getElementById('telephone').value;
	messages = document.getElementById('message').value;*/

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
   /* if(phone == '')
    {
		txt += '<div class="alertRow">Téléphone</div>';
    }

    if(messages == '')
    {
		txt += '<div class="alertRow">Commentaire</div>';
    }*/

    if(txt == ""){
        document.owners1.submit();
	}
	else{
		show_alert_message(txt);
	}
}

function check_owners2()
{
	email = document.getElementById('email2').value;
	fnames = document.getElementById('fname2').value;
	lnames = document.getElementById('lname2').value;
	/*phone = document.getElementById('telephone2').value;
	messages = document.getElementById('message2').value;*/

	var txt = "";
	if(fnames == ''){
		txt += '<div class="alertRow">Nom</div>';
    }
	if(lnames == ''){
		txt += '<div class="alertRow">Prénom</div>';
    }

	if(!validateEmail(email))
    {
		txt += '<div class="alertRow">Courriel</div>';
    }
    
    /*if(phone == '')
    {
		txt += '<div class="alertRow">Téléphone</div>';
    }

    if(messages == '')
    {
		txt += '<div class="alertRow">Commentaire</div>';
    }*/

    if(txt == ""){
        document.owners2.submit();
	}
	else{
		show_alert_message(txt);
	}
}
window.onload = function(){
	var messageBlock = document.getElementById("sentMessage");
	if(messageBlock){
		if(window.location.hash == "#send"){
			messageBlock.style.display = "block";
			messageBlock.innerHTML = "Merci, votre message sera traité dans les plus brefs délais.";
			setTimeout(function(){messageBlock.style.display = "none";}, 1000);
		}
	}
}
// VALIDATION END

function doFadeMeuble(){
	var num = 0;
	var count = $("#meubleRotate img").size();
	
	doFadeOut();
			
	function doFadeOut(){
		$("#meubleRotate img").eq(num).css("opacity", "1");
		$("#meubleRotate img").eq(num).css("position", "static");
		$("#meubleRotate img").eq(num).animate({opacity: 0}, 2000, function() { doFadeIn() });
	}
	function doFadeIn(){
		$("#meubleRotate img").eq(num).css("position", "absolute");
		
		if(num < count -1){
			num++;	
		}
		else{
			num = 0;	
		}
		$("#meubleRotate img").eq(num).css("position", "static");
		$("#meubleRotate img").eq(num).animate({opacity: 1}, 2000, function() { doFadeOut() });
	}	
}
function doFadeNonMeuble(){
	var num = 0;
	var count = $("#nonMeubleRotate img").size();
	
	doFadeOut();
			
	function doFadeOut(){
		$("#nonMeubleRotate img").eq(num).css("opacity", "1");
		$("#nonMeubleRotate img").eq(num).css("position", "static");
		$("#nonMeubleRotate img").eq(num).animate({opacity: 0}, 2000, function() { doFadeIn() });
	}
	function doFadeIn(){
		$("#nonMeubleRotate img").eq(num).css("position", "absolute");
		
		if(num < count -1){
			num++;	
		}
		else{
			num = 0;	
		}
		$("#nonMeubleRotate img").eq(num).css("position", "static");
		$("#nonMeubleRotate img").eq(num).animate({opacity: 1}, 2000, function() { doFadeOut() });
	}	
}


/*function doAlpha(){
	var flag = 1;
	var currentAlpha = 1;
	var alpha = 0.01;
	var block = document.getElementById("meubleRotate");
	var idInterval = setInterval(changeAlpha, 100);
	function changeAlpha(){
		setElementOpacity("meubleRotate",currentAlpha);
		if(currentAlpha <= alpha){
			flag = 0;
			for (i=0;i<=3;i++){
				document.getElementById("meubleRotate").src = "../_common/img/gallery/top/meuble0"+ i +".jpg";
			}
		}
		else if(currentAlpha >= 1){
			flag = 1;
		}
		if(currentAlpha > alpha && flag == 1){
			currentAlpha -= 0.02;
		}
		else{
			currentAlpha += 0.02;
		}
	}	
}*/