$(document).ready(function() {
	$('#btnPrint').click(function() {
		window.print();
		return false;
	}); 

    $('#btnShare').click(function() {
    	fireMyPopup();
        return false;
    });

    $('#btnCloseShare').click(function() {
    	fadeOutMyPopup();
        return false;
    });

    $('#fadeIn').click(function () {
    	fadeOutMyPopup();
   	});
    
    $('.tabContent .sail-schedule tr:nth-child(even)').addClass('sail-schedule-odd');
    //setTimeout('btnShareHomepage()',20000);
});

//BEGIN Functions for Share module
function call_facebook(actualURL,pageName) {
	var cmp = 'SOC-DYPUSEN_Facebook_dyp-' + pageName + '_Share';
	window.open('http://www.facebook.com/sharer.php?u='  + actualURL + '?cmp=' + cmp);
}
function call_twitter(shortURL) {
	var cmp = 'SOC-DYPUSEN_Twitter_dyp-';
	window.open('http://twitter.com/intent/tweet?url=' + shortURL + '&text=Disney Meetings has the right venue for your dream meetings! Come see!');
}

//Browser safe opacity handling function
function setOpacity( value ) {
	document.getElementById("shareDiv").style.opacity = value / 10;
	document.getElementById("shareDiv").style.filter = 'alpha(opacity=' + value * 10 + ')';
	document.getElementById("fadeIn").style.opacity = value/15;
	document.getElementById("fadeIn").style.filter = 'alpha(opacity=' + value * 7 + ')';
}

function resize() {
	window_width = ''; blanket_height = '';
	var frame = document.getElementById("fadeIn"); 
	
	/* Getting width height */ 
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	/* end of getting height */
	
	/* Getting width width */
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientWidth;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}

	/* end of getting width */
	frame.style.width = "4000px"; 
	frame.style.height = "2000px"; 
	frame.style.top = '-48px'; // Disney
	frame.style.left = '-135px';
} 

function fadeInMyPopup() {
	for( var i = 0 ; i <= 100 ; i++ )
		setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );
	document.getElementById("fadeIn").style.zIndex = 9000;
	document.getElementById("content").style.zIndex = 9001;
	document.getElementById("shareDiv").style.zIndex = 9002;
}

function fadeOutMyPopup() {
	for( var i = 0 ; i <= 100 ; i++ ) {
		setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
	}
	setTimeout('closeMyPopup()', 800 );
}

function closeMyPopup() {
	document.getElementById("shareDiv").style.display = "none";
	document.getElementById("fadeIn").style.display = "none";
	document.getElementById("content").style.zIndex = 10;
}

function fireMyPopup() {
	setOpacity( 0 );
	document.getElementById("shareDiv").style.display = "block";
	document.getElementById("fadeIn").style.display = "block";
	resize();
	fadeInMyPopup();
}

function btnShareHomepage() {
	if (document.getElementById("btnShare")) {
		document.getElementById("btnShare").style.display = "block";
	}
}

//END Functions for Share module

//Date comparison method for jquery.validate

var currentDate = function() {
	return {
		getDate: function() {
			 var now = new Date();
			 var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
			 var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
			 function fourdigits(number) {
			   return (number < 1000) ? number + 1900 : number;
			 }
			 var today =  months[now.getMonth()] + "/" +date+ "/" + (fourdigits(now.getYear()));
			 return today;
		}
	}
}();

$.validator.addMethod("greaterThan", function(value, element, params) {
	if (!/Invalid|NaN/.test(new Date(value))) {
       	if(new Date(value) > new Date($(params).val())) {
       		return true;
       	} else {
       		return false;
       	}
  	}
	if(value==='' && $(params).val()==='') {
		return true;
	};
	return isNaN(value) && isNaN($(params).val()) || (parseFloat(value) > parseFloat($(params).val()));
}, $.validator.format('Must be greater than {0}.'));

$.validator.addMethod("greaterOrEqualsThan", function(value, element, params) {
	if (!/Invalid|NaN/.test(new Date(value))) {
       	if(new Date(value) >= new Date($(params).val())) {
       		return true;
       	} else {
       		return false;
       	}
  	}
	if(value==='' && $(params).val()==='') {
		return true;
	};
	return isNaN(value) && isNaN($(params).val()) || (parseFloat(value) >= parseFloat($(params).val()));
}, $.validator.format('Must be greater or equals than {0}.'));

$.validator.addMethod("greaterOrEqualsThanCurrentDate", function(value, element, params) {
	if (!/Invalid|NaN/.test(new Date(value))) {
       	if(new Date(value) >= new Date(params)) {
       		return true;
       	} else {
       		return false;
       	}
  	}
	if(value==='' && $(params).val()==='') {
		return true;
	};
	return isNaN(value) && isNaN($(params).val()) || (parseFloat(value) >= parseFloat($(params).val()));
}, $.validator.format('Must be greater or equals than {0}.'));

//END Date comparison method for jquery.validate

//Ipad :hover fix for the left nav
$(document).ready(function () {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	    $("#leftNav div a p span").click(function(){});
	}
});
//END Ipad :hover fix for the left nav
//Function to check placeholder support in the browser
$.support.placeholder = (function(){
    var i = document.createElement('input');
    return 'placeholder' in i;
})();
//END Function to check placeholder support in the browser
