//SUSCKER FISH IE FIX
sfHover = function() {
	var sfEls = document.getElementById("sub_nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//JAVASCRIPT FIX FOR NAV STYLES - OVER & OUT STATES
function parentStyles(ele){
	if(document.getElementById(ele).className=='active'){
		document.getElementById(ele).className='active over';
	}else if(document.getElementById(ele).className==''){
		document.getElementById(ele).className='over';
	}else if(document.getElementById(ele).className=='active over'){
		document.getElementById(ele).className='active';
	}else if(document.getElementById(ele).className=='over'){
		document.getElementById(ele).className='';
	}
}

// jQuery fadeToggle plugin
jQuery.fn.fadeToggle = function(s, fn){
	return (this.is(":visible"))
		? this.fadeOut(1000, fn)
		: this.fadeIn(1000, fn);
};

// utilising fadeToggle to show/hide .content DIV
jQuery(function($){		
	$("#section5_nav").click(function(){
		$("#booking_form").fadeIn(1000);
		$("#section5_nav").addClass("active");
		return false;
	});
});

jQuery(function($){		
	$("#close_btn").click(function(){
		$("#booking_form").fadeOut(1000);
		$("#section5_nav").removeClass("active");
		return false;
	});
});	
	
function shownhide(id){ 
	if(document.getElementById(id)){ 
		var theElement = document.getElementById(id); 
		if(theElement.style.display == "none"){ 
			theElement.style.display = "block";
		}else{ 
			theElement.style.display = "none";
		}
	}
};

function goto(url){
	location.href=url;
}
function gotoBlank(url){
	window.open(url);
}

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});	
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);
}

function verify_email(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1){return false}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {return false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {return false;}
	if (str.indexOf(at,(lat+1))!=-1) {return false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {return false;}
	if (str.indexOf(dot,(lat+2))==-1) {return false;}
	if (str.indexOf(" ")!=-1) {return false;}
	return true;					
}

function form_input_is_numeric(input){
	if(input==""){ bln=false; }else{ bln=!isNaN(input);}
    return bln;
}

function checkform(form_id){
	var bln_valid=true;
	var str_message='Please complete all fields marked with *';
	if(form_id=="frm_meetings_and_events_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(!form_input_is_numeric(document.getElementById('party_size').value)){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('number_rooms').value)){
			bln_valid=false;
		}
		if(document.getElementById('corporate_requirements').value=="-"){
			bln_valid=false;
		}
	}else if(form_id=="frm_short_breaks_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(document.getElementById('package').value=="-"){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('num_nights').value)){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('number_rooms').value)){
			bln_valid=false;
		}
	}else if(form_id=="frm_wedding_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(document.getElementById('wedding_type').value=="-"){
			bln_valid=false;
		}
		if(document.getElementById('party_size').value=="-"){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('number_bedrooms').value)){
			bln_valid=false;
		}
	}else if(form_id=="frm_festive_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(document.getElementById('package').value=="-"){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('num_nights').value)){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('number_rooms').value)){
			bln_valid=false;
		}
	}else if(form_id=="frm_dunstane_house_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(!form_input_is_numeric(document.getElementById('num_nights').value)){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('number_rooms').value)){
			bln_valid=false;
		}
	}else if(form_id=="frm_dunstane_city_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(!form_input_is_numeric(document.getElementById('num_nights').value)){
			bln_valid=false;
		}
		if(!form_input_is_numeric(document.getElementById('number_rooms').value)){
			bln_valid=false;
		}
	}else if(form_id=="frm_dunstane_dining_enquiry_form"){
		if(document.getElementById('first_name').value==""){
			bln_valid=false;
		}
		if(document.getElementById('second_name').value==""){
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('enquiry_email').value)){
			bln_valid=false;
			str_message=str_message+", ensure the supplied email address is valid.";
		}
		if(!form_input_is_numeric(document.getElementById('party_size').value)){
			bln_valid=false;
		}
		if(document.getElementById('dining_preferences').value=="-"){
			bln_valid=false;
		}
	}else if(form_id=="frm_email_friend_form"){
		var str_message='';
		if(document.getElementById('recipients_name').value==""){
			str_message=str_message+'Please enter a recipient\'s name\n';
			bln_valid=false;
		}
		if(!verify_email(document.getElementById('recipients_email').value)){
			bln_valid=false;
			str_message=str_message+"Please enter a valid recipient\'s email address\n";
		}
		if(document.getElementById('your_name').value==""){
			bln_valid=false;
			str_message=str_message+"Please enter your name\n";
		}
		if(!verify_email(document.getElementById('your_email').value)){
			bln_valid=false;
			str_message=str_message+"Please enter a valid email address\n";
		}
	}
	
	if(!bln_valid){
		alert(str_message);
		return false;
	}else{
		document.getElementById(form_id).submit();
	}
}

function compareDates(dat_arrive,dat_depart){
    var str1 = dat_arrive;
    var str2 = dat_depart;
    var dt1  = parseInt(str1.substring(0,2),10);
    var mon1 = parseInt(str1.substring(3,5),10);
    var yr1  = parseInt(str1.substring(6,10),10);
    var dt2  = parseInt(str2.substring(0,2),10);
    var mon2 = parseInt(str2.substring(3,5),10);
    var yr2  = parseInt(str2.substring(6,10),10);
    var date1 = new Date(yr1, mon1, dt1);
    var date2 = new Date(yr2, mon2, dt2);
    if(date2 < date1){
       //alert("To date cannot be greater than from date");
        return false;
    }else{
        //alert("Submitting ...");
        //document.form1.submit();
		return true;
    }
} 

function checkAvail(){
	var bln_valid=true;
	var formAction = "";
	var str_message='';
	if(document.getElementById('Adult').value==""){
			str_message='Please select a No. of adults\n';
			bln_valid=false;
	}
	//if(!compareDates(document.getElementById('Arrive').value,document.getElementById('Depart').value)){
	//	str_message=str_message+'Please select a departure date which is after the arrival date.';
	//	bln_valid=false;
	//}
	if(!bln_valid){
		alert(str_message);
		return false;
	}else{
	
		for (i=0;i<document.booking_frm.hotel.length;i++)
		{
			  if (document.booking_frm.hotel[i].checked)
			  {
					var hotel = document.booking_frm.hotel[i].value;
			  }
		} 
	
		var Arrive = document.booking_frm.Arrive.value;
		var nights= document.booking_frm.nights[document.booking_frm.nights.selectedIndex].text;
		var promo = document.booking_frm.promo.value;
		var Adult= document.booking_frm.Adult[document.booking_frm.Adult.selectedIndex].text;
		var Rooms= document.booking_frm.Rooms[document.booking_frm.Rooms.selectedIndex].text;
		var Chain = document.booking_frm.Chain.value;
		var Dest = document.booking_frm.Dest.value;
		var shell = document.booking_frm.shell.value;
		var altdest = document.booking_frm.altdest.value;
		var locale = document.booking_frm.locale.value;
		var start = document.booking_frm.start.value;
		
		var formAction = "https://gc.synxis.com/rez.aspx?hotel="+ hotel +"&Arrive="+ Arrive +"&nights="+ nights +"&promo="+ promo +"&Adult="+ Adult +"&Rooms="+ Rooms +"&Chain="+ Chain +"&Dest="+ Dest +"&shell="+ shell +"&altdest="+ altdest +"&locale="+ locale +"&start="+ start;

	document.getElementById("booking_frm").action = formAction;
	document.getElementById("booking_frm").onsubmit();
	document.getElementById("booking_frm").method="";
	window.open(document.getElementById("booking_frm").action);
	}
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 2000);
	//Hide the current image
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
};

$(document).ready(function() {	
	$("body select#language").msDropDown();
	//FIX CONTENT CONTAINER HEIGHT
	var int_height = $("div.content").height();
	int_height=int_height-40;
	$("div#right_part").height(int_height);
	//INIT ROTATOR
	theRotator();
	$("#booking_frm").attr({ target: "_blank" });
	$("#ccoptin").attr({ target: "_blank" });
	/*
	 * jqBookmark - a jquery Bookmark script
	 *
	 * LICENSE
	 *
	 * This source file is subject to the new BSD license that is bundled
	 * with this package in the file license.txt.
	 * If you did not receive a copy of the license and are unable to
	 * obtain it through the world-wide-web, please send an email
	 * to calisza@gmail.com so we can send you a copy immediately.
	 *
	 */
	// add a "rel" attrib if Opera 7+
	if(window.opera) {
		if ($("a.jqbookmark").attr("rel") != ""){
			$("a.jqbookmark").attr("rel","sidebar");
		} 
	}
	$("a.jqbookmark").click(function(event){
		event.preventDefault();
		var url = this.href;
		var title = this.title;
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing
		} else { 
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}
	});
});


