/* Written by John Fallis 2010 */

/* Email Validation 
************************/
jQuery.fn.validEmail = function() {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	var result = pattern.test($(this).val());
	if(result) {
		$(this).removeClass('error');
		$(this).addClass('valid');
	} 
	else {
		$(this).removeClass('valid');
		$(this).addClass('error');
		$(this).focus();
	}
	return result;
};

/* hidden 2 text input 
************************/
jQuery.fn.hidden2text = function() {
	this.focus(function(){
		$(this).removeClass('txt2input');
	}).blur(function(){
		$(this).addClass('txt2input');
	});
};


/* URL Redirection
**********************/
jQuery.fn.redirect = function() {
	window.location.href=$(this).val();
};

/* Language 
****************/
jQuery.fn.translate_standard = function(preload) {
	if($.cookie('translate')) {
		if($.cookie('translate_selection')){
			$(".translate_selection").html($.cookie('translate_selection')); // Set HTML default translation from cookie
		}
		if(($.cookie('translate') != 'en' && preload) || (!preload)) {
			$(this).translate('en', $.cookie('translate'), { //translate from english to the selected language
				not: 'link, script, form a, input, select, option, optgroup, button, label, textarea, submit, .translate, .dont_translate, #search_form' //exclude these elements
				,fromOriginal:true //always translate from english (even after the page has been translated)
			})
			$.unblockUI();
		}
	}
};

/* Members Area 
*******************/
function cancellationRequest(formId) {
	var question = 'Are you sure you want to cancel your reservation';
	if (window.confirm(question)) {
		document.getElementById(formId).submit();
	} else {
		return false;
	}
}

/* Text Expander
*******************/
jQuery.fn.textExpand = function() {
	$(this).each(function(i,item) {
		//if(jQuery.browser.msie && parseInt(jQuery.browser.version)<=7) {
			var cssObject = {
				'overflow' : 'auto'
				,'vertical-align' : 'text-top'
				,'border' : '#333333 thin dotted'
				,'margin' : 0+'px'
				,'padding' : 2+'px'
			}
			$(this).css(cssObject);
		/*
		} else {
			var cssObject = {
				'overflow' : 'hidden'
				,'vertical-align' : 'text-top'
				,'border' : '#333333 thin dotted'
				,'margin' : 0+'px'
				,'padding' : 0+'px'
			}
			$(this).prepend('<div class="textExpand" style="left:0%;padding-bottom:10px;top:'+($(this).outerHeight())+'px;position:relative;z-index:555;text-align:right;background-color:#FFFFFF;text-decoration:underline;cursor:pointer;cursor:hand;">Read More</div>').css(cssObject);
		}
		*/
	});
	$('.textExpand',this).click(function(){
		var parent = $(this).parent();
		var newSize = parent.attr('rel');
		var oldSize = parent.height();
		if(!parent.attr('rel')) {
			var newSize = oldSize*2;
			parent.css('overflow','auto');
		}
		parent.attr('rel',oldSize+'px').animate({ height: newSize}, 800);
		$(this).hide();
	});
};

