/*var flashvars = false;
var params = {
	wmode: "transparent"};
var attributes = false;
swfobject.embedSWF("img/logo.swf", "logo", "310", "66", "8.0.0", "", flashvars, params, attributes);*/
$(function()
{
	$(".default_button, .default_button_120, .default_button_150").mouseover(function(){
		$(this).addClass("over");
	}).mouseout(function(){
		$(this).removeClass("over");
	});
});

function createDropdown(b,e,s)
{
	for (i=b; i<=e; i++)
	{
		if (i==s)
			document.write('<option value="'+i+'" selected="selected">'+i+'</option>');
		else
			document.write('<option value="'+i+'">'+i+'</option>');
	}
}

function openCalendar(url)
{
  var params="menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,dependent,top=0,left=0,width=680,height=210";
  popupWin = window.open(url, 'calendar',params);
  popupWin.focus();
}

function setGuests(br)
{
	f = document.form;
	adults = 0;
	children = 0;
	m = f.rooms.options[f.rooms.selectedIndex].value;
	lb = "";
	if (br==1)
		lb = "<br />";
	for (i=1; i<=m; i++)
	{
		if ((f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='doubleroom')||(f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='twin')||(f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='family3'))
			adults = adults + 2;
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='single')
			adults = adults + 1;
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='triple')
			adults = adults + 3;
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='family1')
		{
			adults = adults + 2;
			children = children + 1;
		}
		if (f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value=='family2')
		{
			adults = adults + 2;
			children = children + 2;
		}
	}

	if (br!=2)
	{
		if ((children==0)&&(adults>0))
			document.getElementById('guestText').innerHTML = adults + ' adultes';
		else if (adults>0)
			document.getElementById('guestText').innerHTML = adults + ' adultes, ' + lb + children + ' enfants (Âge :' + f.kidsage.value + ')';
		else
			document.getElementById('guestText').innerHTML = '';
	}
	f.adults.value = adults;
	f.children.value = children;
}

function showKidsAge()
{

	f = document.form;
	s = document.getElementById('kidsage_row');
	r1 = document.form.roomtype1.options[document.form.roomtype1.selectedIndex].value;
	r2 = document.form.roomtype2.options[document.form.roomtype2.selectedIndex].value;
	r3 = document.form.roomtype3.options[document.form.roomtype3.selectedIndex].value;
	r4 = document.form.roomtype4.options[document.form.roomtype4.selectedIndex].value;
	r5 = document.form.roomtype5.options[document.form.roomtype5.selectedIndex].value;
	r = document.form.rooms.options[document.form.rooms.selectedIndex].value;

	if ((r1.indexOf('family1')>-1) || (r2.indexOf('family1')>-1) || (r3.indexOf('family1')>-1) || (r4.indexOf('family1')>-1) || (r5.indexOf('family1')>-1) || (r1.indexOf('family2')>-1) || (r2.indexOf('family2')>-1) || (r3.indexOf('family2')>-1) || (r4.indexOf('family2')>-1) || (r5.indexOf('family2')>-1))
	{
		s.style.display = 'block';
		kidspace=31;
	}
	else
	{
		s.style.display = 'none';
		kidspace=0;
	}
}

function showKidsAge2()
{

	f = document.form;
	s = document.getElementById('kidsage_row');
	r1 = document.form.roomtype1.options[document.form.roomtype1.selectedIndex].value;
	r2 = document.form.roomtype2.options[document.form.roomtype2.selectedIndex].value;
	r3 = document.form.roomtype3.options[document.form.roomtype3.selectedIndex].value;
	r4 = document.form.roomtype4.options[document.form.roomtype4.selectedIndex].value;
	r5 = document.form.roomtype5.options[document.form.roomtype5.selectedIndex].value;

	if ((r1.indexOf('family1')>-1) || (r2.indexOf('family1')>-1) || (r3.indexOf('family1')>-1) || (r4.indexOf('family1')>-1) || (r5.indexOf('family1')>-1) || (r1.indexOf('family2')>-1) || (r2.indexOf('family2')>-1) || (r3.indexOf('family2')>-1) || (r4.indexOf('family2')>-1) || (r5.indexOf('family2')>-1))
	{
		s.style.display = 'block';
	}
	else
	{
		s.style.display = 'none';
	}
}

function resetAdvancedSearch(x)
{
	f = document.form;
	cookie = document.cookie;
	broken_cookie = cookie.split(";");
	m = broken_cookie.length;

	for (i=0; i<m; i++)
	{
		broken_cookie[i] = trimCookie(broken_cookie[i]);
		if (broken_cookie[i] == 'advanced=0')
		{
			clearAdvanced();
		}
		else if (broken_cookie[i] == 'advanced=1')
		{
			showAdvanced(0);
		}
	}
	advancedLinkCookie(x);
}

function trimCookie(str)
{
	return str.replace(/^\s+/,"").replace(/\s+$/,"").replace(/\s+/g," ");
}

function showAdvanced(c)
{
	f = document.form;
	s = document.getElementById('advancedSearch');
	a = document.getElementById('advancedLink');
	l = document.getElementById('selectEither');
	r = document.form.rooms.options[document.form.rooms.selectedIndex].value;
	kids=document.form.kidsage.value;
	if (kids=='') kidspace=0;
	else kidspace=31;

	if ((s.style.display=='')||(s.style.display=='none'))
	{
		s.style.display = 'block';
		a.className = 'black8';
		l.style.visibility = 'visible';
		document.cookie = "advanced=1";
	}
	else
	{
		s.style.display = 'none';
		a.className = 'green8';
		l.style.visibility = 'hidden';
		f.price.selectedIndex = 0;
		f.category.selectedIndex = 0;
		f.location.selectedIndex = 0;
		f.hotelname.selectedIndex = 0;
		f.facilities.selectedIndex = 0;
		document.cookie = "advanced=0";
	}
}

function advancedLinkCookie(x)
{
	f = document.form;
	cookie = document.cookie;
	broken_cookie = cookie.split(";");
	m = broken_cookie.length;

	for (i=0; i<m; i++)
	{
		if ((broken_cookie[i] == 'advancedLink=1') && (x == 1))
		{
			showAdvancedLink();
		}
	}
}

function checkHotelcookiecitypage(thiscity)
{
	cookie = document.cookie;
	broken_cookie = cookie.split(";");
	m = broken_cookie.length;
	hotelid=0;hname='';thumbnail='';hotelcurrency='';city='';

	for (i=0; i<m; i++)
	{
		broken_cookie[i] = trimCookie(broken_cookie[i]);
		if (broken_cookie[i].indexOf('hotelid=')>-1) hotelid=broken_cookie[i].substring(8);
		if (broken_cookie[i].indexOf('hname=')>-1) hname=broken_cookie[i].substring(6);
		if (broken_cookie[i].indexOf('city=')>-1) city=broken_cookie[i].substring(5);
		if (broken_cookie[i].indexOf('thumbnail=')>-1) thumbnail=broken_cookie[i].substring(10);
		if (broken_cookie[i].indexOf('hotelcurrency=')>-1) hotelcurrency=broken_cookie[i].substring(14);
		if (hotelid!=0 && hname!='' && city!='' && thumbnail!='' && hotelcurrency!='') 
		{
			if (city==thiscity) break;
			else 
			{
				hotelid=0;hname='';thumbnail='';hotelcurrency='';city='';
			}
		}
	}
}

function sameAddress()
{
	f = document.form;
	if (f.copy_address.checked==true)
	{
		f.ccaddress.value = f.address.value;
		f.cccity.value = f.custcity.value;
		f.ccstate.value = f.county.value;
		f.ccpostcode.value = f.postcode.value;
		f.cccountry.selectedIndex = f.country.selectedIndex;
	}
	else
	{
		f.ccaddress.value = '';
		f.cccity.value = '';
		f.ccstate.value = '';
		f.ccpostcode.value = '';
	}
}

function openWindow(url, w, h, s)
{
	var params="menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,dependent,top=0,left=0,width="+w+",height="+h;
	popupWin = window.open(url, 'popup',params);
	popupWin.focus();
}

function setHotelcookie(hotelid,hname,city,thumbnail,hotelcurrency)
{
	var now = new Date();
	now.setTime(now.getTime() + 7 * 24 * 60 * 60 * 1000);
	document.cookie = "hotelid=" + hotelid+"; domain=www.hotelsdirect.fr; path=/;expires="+now.toGMTString()+";";
	document.cookie = "hname=" + hname+"; domain=www.hotelsdirect.fr; path=/;expires="+now.toGMTString()+";";
	document.cookie = "city=" + city+"; domain=www.hotelsdirect.fr; path=/;expires="+now.toGMTString()+";";
	document.cookie = "thumbnail=" + thumbnail+"; domain=www.hotelsdirect.fr; path=/;expires="+now.toGMTString()+";";
	document.cookie = "hotelcurrency=" + hotelcurrency+"; domain=www.hotelsdirect.fr; path=/;expires="+now.toGMTString()+";";
}

function getHotelcookie(page,thiscity)
{
	cookie = document.cookie;
	broken_cookie = cookie.split(";");
	m = broken_cookie.length;
	hotelid=0;hname='';thumbnail='';hotelcurrency='';city='';
	for (i=0; i<m; i++)
	{
		broken_cookie[i] = trimCookie(broken_cookie[i]);
		if (broken_cookie[i].indexOf('hotelid=')>-1) hotelid=broken_cookie[i].substring(8);
		if (broken_cookie[i].indexOf('hname=')>-1) hname=broken_cookie[i].substring(6);
		if (broken_cookie[i].indexOf('city=')>-1) city=broken_cookie[i].substring(5);
		if (broken_cookie[i].indexOf('thumbnail=')>-1) thumbnail=broken_cookie[i].substring(10);
		if (broken_cookie[i].indexOf('hotelcurrency=')>-1) hotelcurrency=broken_cookie[i].substring(14);
		if (hotelid!=0 && hname!='' && city!='' && thumbnail!='' && hotelcurrency!='') 
		{
		   if (page=='city') 
		   {
			if (city==thiscity) break;
			else 
			{
				hotelid=0;hname='';thumbnail='';hotelcurrency='';city='';
			}
		   }
		   else break;
		}
	}
	if (hotelid!=0 && hname!='' && city!='' && thumbnail!='' && hotelcurrency!='')
	{
		document.write("<div id=\"last_viewed\"><h2>Recently viewed</h2><p class=\"grey\"><strong>You recently viewed this hotel...</strong></p><div class=\"last_pic\"><a href=\"http://www.hotelsdirect.fr/webapp/hoteldirect/servlet/HDVoirPage?web=yes&purpose=hotel&hotelid="+hotelid+"&city="+city+"&currency="+hotelcurrency+"\"><img src=\""+thumbnail+"\" width=\"72\" height=\"47\" onclick=\"logOCPV('isconv=0|pover=Browsing_History');\" alt=\""+hname+"\" /></a></div><div class=\"last_text\"><h3><a onclick=\"logOCPV('isconv=0|pover=Browsing_History');\" href=\"http://www.hotelsdirect.fr/webapp/hoteldirect/servlet/HDVoirPage?web=yes&purpose=hotel&hotelid="+hotelid+"&city="+city+"&currency="+hotelcurrency+"\">"+hname+"</a></h3><p><a onclick=\"logOCPV('isconv=0|pover=Browsing_History');\" href=\"http://www.hotelsdirect.fr/webapp/hoteldirect/servlet/HDVoirPage?web=yes&purpose=hotel&hotelid="+hotelid+"&city="+city+"&currency="+hotelcurrency+"\">"+city+"</a></p><ul><li><a onclick=\"logOCPV('isconv=0|pover=Browsing_History');\" href=\"http://www.hotelsdirect.fr/webapp/hoteldirect/servlet/HDVoirPage?web=yes&purpose=hotel&hotelid="+hotelid+"&city="+city+"&currency="+hotelcurrency+"\">Hotel details</a></li></ul></div>");
		//document.write("<p><a href=\"\">Voir more hotels like this</a></p>");
		document.write("</div>");
	}
}

function showYear()
{
	now = new Date();
	document.write(now.getFullYear()); 
}

function setCurrency(c)
{
	document.cookie = "currency=" + c;
	url = document.URL;
	pos=url.indexOf('?_$ja=');
	if (pos>-1)
	{
		pos2=url.indexOf('&');
		if (pos2>-1) url=url.substring(0,pos)+"?"+url.substring(pos2+1);
		else url=url.substring(0,pos);
	}
	if (url.indexOf('?')>-1)
	{
		pos=url.indexOf('currency=');
		if (pos>-1)
		{
			url=url.replace('currency=','currency2=');
			document.location = url + "&currency=" + c;
		}
		else document.location = url + "&currency=" + c;
	}
	else if (url.indexOf('?')==-1 && url.indexOf('HDFront')>-1)
	{
		document.newform.currency.value=c;
		document.newform.submit();
	}
	else if (url.indexOf('?')==-1 && url.indexOf('HDSearchDate')>-1)
	{
		document.form.currency.value=c;
		document.form.submit.click();
	}
	else
	{
		if (url.indexOf('currency=')>-1)
			document.location = url.substring(0, url.indexOf('currency=')) + "currency=" + c;
		else
		{
		  if (c=='usdollar') c='usd';
		  lastchar=url.length;
		  if (url.indexOf('.htm')==-1 && url.indexOf('servlet')==-1)
		  {
			document.location = url + "index_" + c+".htm";
		  }
		  else
		  {
		    if (url.indexOf('index_')>-1)
		    {
			if (c=='euro')
			{
			   pos=url.indexOf('index_');
			   document.location = url.substring(0,pos);		  	   
			}
			else
		  	{
			   pos=url.indexOf('index_');
	  	  	   document.location = url.substring(0,pos)+ "index_" + c+".htm";  
			}
		    }
		    else if (url.indexOf('.htm')>-1)
		    {
			pos=url.indexOf(".htm");
			if (c=='euro')
			{
			   pos2=url.indexOf('_usd.htm');
			   if (pos2>-1) document.location = url.substring(0,pos2)+".htm";  		  	   
			   else 
			   {	
				pos2=url.indexOf('_gbp.htm');
				if (pos2>-1) document.location = url.substring(0,pos2)+".htm";  		  	   
			   }
			}
			else
			{
			   pos2=url.indexOf('_usd.htm');
			   if (pos2>-1) document.location = url.substring(0,pos2)+"_"+c+".htm";  		  	   
			   else 
			   {	
				pos2=url.indexOf('_gbp.htm');
				if (pos2>-1) document.location = url.substring(0,pos2)+"_"+c+".htm";  		  	   
				else document.location = url.substring(0,pos)+"_"+c+".htm";
			   }
			}
		    }
		    else
			document.location = url + "?currency=" + c;
		  }
		}
	}
}


function getCurrency()
{
/*
	cookie = document.cookie;
	broken_cookie = cookie.split(";");
	m = broken_cookie.length;

	for (i=0; i<m; i++)
	{
		broken_cookie[i] = trimCookie(broken_cookie[i]);
		if ((broken_cookie[i]=='currency=usd') || (broken_cookie[i]=='currency=usdollar'))
		{
			$("#currency").val("usd");
			$("#currency_label").addClass("usd");
		}
		else if (broken_cookie[i]=='currency=euro')
		{
			$("#currency").val("euro");
			$("#currency_label").addClass("euro");
		}
		else
		{
			$("#currency").val("gbp");
			$("#currency_label").addClass("gbp");
		}
	}
*/
}

function printPage()
{
	if (window.print)
	{
		window.print();
	}
	else
	{
		alert("Sorry, your browser doesn't support this feature.");
	}
}

function showHabs(r, c)
{
	kids=document.form.kidsage.value;
	if (kids=='') kidspace=0;
	else kidspace=31;
	for (i=2; i<=5; i++)
	{
		document.getElementById('room_'+i).style.display = 'none';
	}
	if (r>1)
	{
		for (i=2; i<=r; i++)
		{
			document.getElementById('room_'+i).style.display = 'block';
		}
	}
}

function setGuestsFree()
{
	f = document.form;
	adults = 0;
	children = 0;
	
	if (f.family1.selectedIndex>0)
	{
		adults = adults + (2 * f.family1.selectedIndex);
		children = children + (1 * f.family1.selectedIndex);
	}
	if (f.family2.selectedIndex>0)
	{
		adults = adults + (2 * f.family2.selectedIndex);
		children = children + (2 * f.family2.selectedIndex);
	}
	f.adults.value = adults;
	f.children.value = children;
}

function ageOnly(field)
{
	var valid = "0123456789,"
	ok = 1;
	var temp;
	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0)
	{
		alert("Please only enter numbers in this field!");
		field.focus();
		field.select();
	}
}

function openMap(url, w, h)
{
	url=url.replace('2&3','2%263');
	var params="menubar=yes,toolbar=yes,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,dependent,top=0,left=0,width="+w+",height="+h;
	popupWin = window.open(url, 'popup',params);
	popupWin.focus();
}
