var clickmessage="All graphics Copyright © 2009 Property Service SARL / www.cannes-filmfestival-accommodation.com";
function disableclick(e){
if(document.all){if(event.button==2||event.button==3){if(event.srcElement.tagName=="IMG"){alert(clickmessage);
return false;}}}else if(document.layers){if(e.which==3){alert(clickmessage);return false;}}
else if(document.getElementById)if(e.which==3&&e.target.tagName=="IMG")setTimeout("alert(clickmessage)",0);}
function associateimages(){for(i=0;i<document.images.length;i++)document.images[i].onmousedown=disableclick;}
if(document.all){document.onmousedown=disableclick;for(var i_tem=0;i_tem<document.images.length;i_tem++)
document.images[i_tem].galleryimg='no';}else if(document.getElementById)document.onmouseup=disableclick;
else if (document.layers)associateimages();
if((typeof Prototype=='undefined')||(typeof Element=='undefined')||(typeof Element.Methods=='undefined'))
	throw("Prototype JS framework >= 1.6.0.3 is required");
Element.addMethods({pngHack:function(el){var el=$(el);
		var ie7plus=(Prototype.Browser.IE&&parseFloat(navigator.appVersion.split(';')[1].strip().split(' ')[1])>=7)?true:false;
    	if(!Prototype.Browser.IE||ie7plus)return el;var gif="images/s.gif";
    	if((el.match('img'))&&(el.src.include("png"))){var alphaImgSrc=el.src;var sizingMethod="scale";el.src=gif;
    	}else if(el.getStyle("backgroundImage").include("png")){
      		var bgc=el.getStyle("backgroundColor")||"",alphaImgSrc=el.getStyle("backgroundImage").gsub(/url\(|\)|'|"/,"");
      		var sizingMethod="crop";el.setStyle({background:[bgc,"url(", gif, ") no-repeat"].join("")});
    	}else{return el;}
    el.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{al}',sizingMethod='#{sz}')".interpolate({al: alphaImgSrc,sz:sizingMethod});return el;}
});
BannerAnimation=Class.create({
	initialize:function(){$("golden_palm").setStyle({opacity:0.0});$("sixty_second").setStyle({opacity:0.0});
		setTimeout(function(){new Effect.Opacity($("golden_palm"),{duration:7.0,from:0.0,to:1.0});},3000);
		setTimeout(function(){new Effect.Opacity($("sixty_second"),{duration:7.0,from:0.0,to:1.0});},10000);}
});
TextColorFx=Class.create({
	initialize:function(div,clr1,clr2,clr3,clr4,duration,delay){this.textDiv=$(div);this.color1=clr1;this.color2=clr2;
	this.color3=clr3;this.color4=clr4;this.originalColor=this.textDiv.getStyle("color");
	this.duration=duration;this.delay=delay;this.toClr1();},
	toClr1:function(){new Effect.Morph(this.textDiv,{style:"color:"+this.color1,delay:this.delay,duration:this.duration,afterFinish:this.toClr2.bind(this)});},
	toClr2:function(){new Effect.Morph(this.textDiv,{style:"color:"+this.color2,duration:this.duration,afterFinish:this.toClr3.bind(this)});},
	toClr3:function(){new Effect.Morph(this.textDiv,{style:"color:"+this.color3,duration:this.duration,afterFinish:this.toClr4.bind(this)});},
	toClr4:function(){new Effect.Morph(this.textDiv,{style:"color:"+this.color4,duration:this.duration,afterFinish:this.toOrigin.bind(this)});},toOrigin:function(){new Effect.Morph(this.textDiv,{style:"color:"+this.originalColor.toString(),duration:this.duration,afterFinish:this.toClr1.bind(this)});}
});
VillaPopupSubMenu=Class.create({
	initialize:function(){this.tc=0;this.vb=$("villa_hlink");this.vp=$("villa_popup");this.vpLinks=$$("a.vp_links");
		for(var i=0,l=this.vpLinks.length;i<l;++i){this.vpLinks[i].observe("click",this.hvp.bind(this));}
		this.vb.observe("mouseover",this.ch.bind(this,true));this.vb.observe("mouseout",this.ch.bind(this,false));
		this.vp.observe("mouseover",this.ch.bind(this,true));this.vp.observe("mouseout",this.ch.bind(this,false));},
	ch:function(s){if(s){
			this.vp.setStyle({display:"block",visibility:"visible",zIndex:7777});if(this.tc>0)window.clearTimeout(this.tc);
		}else this.tc=this.hvp.bind(this).delay(0.7);},
	hvp:function(){this.vp.setStyle({display:"none",visibility:"hidden",zIndex:0});}
});
SpamController=Class.create({
	initialize:function(spam){this.spammed=spam;if(this.spammed!=0)this.alertSpam();},
	alertSpam:function(){var spam_msg="Dear Visitor,";
		spam_msg+="\n\nSome fields in the submitted form contain URLs, HTTP and/or FTP links or characters used by spam robots.\n";
		spam_msg+="We can't insert the provided data into our database.\nPlease do not use \"line feed\" or ";
		spam_msg+="\"carriage return\" in single line fields or text containing \"http://\", \"ftp://\" or HTML markup tags.";
		spam_msg+="\n\nThank You.";alert(spam_msg);}});
FormManager=Class.create({
	initialize:function(form){
		this.form=$(form);this.formSubmitHandler=this.submitForm.bindAsEventListener(this);
		this.form.observe("submit",this.formSubmitHandler);
		this.setCalendarElements();this.setMandatoryFields();this.setLabels();this.setHandlers();this.startObservers();
	},
	setCalendarElements:function(){		
		this.arrivalCal=$("arr_img");this.departureCal=$("dep_img");this.arrivalInput=$("arrivaldate");
		this.departureInput=$("departuredate");
	},
	setMandatoryFields:function(){
		this.firstNameInput=$("firstname");this.lastNameInput=$("lastname");this.emailInput=$("email");
		this.phoneInput=$("phone");this.guestsInput=$("numberofguests");
	},
	setLabels:function(){
		this.fnLabel=$("first_name_label");this.lnLabel=$("last_name_label");this.emLabel=$("email_address_label");
		this.phLabel=$("telephone_number_label");this.ngLabel=$("sleeps_number_label");this.arrLabel=$("arrival_date_label");
		this.depLabel=$("departure_date_label");this.formTitle=$("contact_form_title");
	},
	setHandlers:function(){
		this.arrivalCalHoverHandler=this.hoverArrival.bind(this);
		this.arrivalCalOutHandler=this.outArrival.bind(this);
		this.arrivalCalClickHandler=this.clickArrival.bind(this);
		this.departureCalHoverHandler=this.hoverDeparture.bind(this);
		this.departureCalOutHandler=this.outDeparture.bind(this);
		this.departureCalClickHandler=this.clickDeparture.bind(this);
		this.arrivalInputClickHandler=this.clickArrival.bind(this);
		this.departureInputClickHandler=this.clickDeparture.bind(this);
	},
	startObservers:function(){
		this.arrivalCal.observe("mouseover",this.arrivalCalHoverHandler);
		this.arrivalCal.observe("mouseout",this.arrivalCalOutHandler);
		this.arrivalCal.observe("click",this.arrivalCalClickHandler);
		this.departureCal.observe("mouseover",this.departureCalHoverHandler);
		this.departureCal.observe("mouseout",this.departureCalOutHandler);
		this.departureCal.observe("click",this.departureCalClickHandler);
		this.arrivalInput.observe("click",this.arrivalCalClickHandler);
		this.departureInput.observe("click",this.departureCalClickHandler);
	},
	hoverArrival:function(){this.arrivalCal.setStyle({border:"1px solid #004489"});},
	outArrival:function(){this.arrivalCal.setStyle({border:"0px"});},
	clickArrival:function(){new XDCalendar("arrivaldate",{arrival:true});},
	hoverDeparture:function(){this.departureCal.setStyle({border:"1px solid #004489"});},
	outDeparture:function(){this.departureCal.setStyle({border:"0px"});},
	clickDeparture:function(){new XDCalendar("departuredate",{});},
	_oldIE:function(){return(Prototype.Browser.IE&&parseFloat(navigator.appVersion.split(';')[1].strip().split(' ')[1])<=6)?true:false;},
	isEmailValid:function(){
		var filter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return(filter.test(this.emailInput.getValue()))?true:false;
	},
	controlDates:function(arr,dep){if(arr==""||dep=="")return 0;
		var dateFlag=1,date1=new Date(arr),date2=new Date(dep);this.dateStr="";
		if((date1.getTime())>(date2.getTime())){this.dateStr="Departure Date should not be anterior to arrival!";dateFlag=2;
		}else if((date1.getTime())==(date2.getTime())){thisdateStr="Departure and Arrival Dates are the same!";dateFlag=2;}
		if(dateFlag==2)alert(this.dateStr);return dateFlag;
	},
	checkForm:function(){
		var checkedOk=true,emailEmpty=false,fields="",field_names_array=new Array(),missing_fields_array=new Array();
		var fnv=this.firstNameInput.getValue();
		if(fnv==""){missing_fields_array.push(this.fnLabel);field_names_array.push("First Name");}else this.resetLabel(this.fnLabel);
		var lnv=this.lastNameInput.getValue();
		if(lnv==""){missing_fields_array.push(this.lnLabel);field_names_array.push("Last Name");}else this.resetLabel(this.lnLabel);
		var emv=this.emailInput.getValue();
		if(emv==""){missing_fields_array.push(this.emLabel);field_names_array.push("Email Address");emailEmpty=true;}else this.resetLabel(this.emLabel);
		var phv=this.phoneInput.getValue();
		if(phv==""){missing_fields_array.push(this.phLabel);field_names_array.push("Phone Number");}else this.resetLabel(this.phLabel);
		var ngv=this.guestsInput.getValue();
		if(ngv==""){missing_fields_array.push(this.ngLabel);field_names_array.push("Number of Guests");}else this.resetLabel(this.ngLabel);
		var arv=this.arrivalInput.getValue();
		if(arv==""){missing_fields_array.push(this.arrLabel);field_names_array.push("Arrival Date");}else this.resetLabel(this.arrLabel);
		var dev=this.departureInput.getValue();
		if(dev==""){missing_fields_array.push(this.depLabel);field_names_array.push("Departure Date");}else this.resetLabel(this.depLabel);
		for(var i=0,l=missing_fields_array.length;i<l;i++){this.hiliteLabel(missing_fields_array[i]);}
		for(var i=0,l=field_names_array.length;i<l;i++){fields+=" - "+field_names_array[i]+"\n";}
		if(missing_fields_array.length>0){
			checkedOk=false;
			this.formTitle.update("<u><b><i>Thank You</i></b> for completing the <span style=\"color:red;\">missing fields.</span></u>");
			var alert_str="Please, we would invite you to complete any missing fields (highlighted in red):\n";
			alert_str+=fields+"to facilitate the handling of your enquiry.\n\nThank You.";
			alert(alert_str);
		}
		if(!emailEmpty){
			if(!this.isEmailValid()){checkedOk=false;this.hiliteLabel(this.emLabel);
				var alert_str="Your Email Address is not valid!\nPlease provide us with a valid email address so that ";
				alert_str+="we can get back to you.\nThank You.";alert(alert_str);
			}else this.resetLabel(this.emLabel);
		}
		var dateFlag=this.controlDates(arv,dev);
		if(dateFlag==2){
			checkedOk=false;this.hiliteLabel(this.arrLabel);this.hiliteLabel(this.depLabel);
		}else if(dateFlag==1){this.resetLabel(this.arrLabel);this.resetLabel(this.depLabel);}
		return checkedOk;
	},
	submitForm:function(e){if(!this.checkForm())e.stop();},
	hiliteLabel:function(c){c.setStyle({color:"#FF0000"});},
	resetLabel:function(l){l.setStyle({color:"#000000"});}
});
Event.observe(document,"dom:loaded",function(){									 
	new FormManager("contact");
	new BannerAnimation();
	new TextColorFx("contact_form_header_title","#00F","#006000","#000","#7C010E",4,4);
	new VillaPopupSubMenu();
});
