$(document).ready(function(){
	$("#featured > ul").tabs({fx:{opacity: "toggle"},event: 'mouseover'}).tabs("rotate", 5000, true);
});


function validateContactUsForm(id,lang)
{
	var id = '#'+id;

	if(lang == 'zh')
	{
		var form = $(id).validate({
			messages:{
				"contact_person" : "產品名稱不能空白",
				"email" : "電郵格式不正確",
				"tel" : "聯絡電話不能空白",
				"detail" : "詳情不能空白"
			},
			rules:
			{
				email:{email:true}
			},
			errorClass : "form_error"
		
		});
	}
	else if(lang == 'cn')
	{
			var form = $(id).validate({
			messages:{
				"contact_person" : "产品名称不能空白",
				"email" : "电邮格式不正确",
				"tel" : "联络电话不能空白",
				"detail" : "详情不能空白"
			},
			rules:
			{
				email:{email:true}
			},
			errorClass : "form_error"
		
		});
	}
	else if(lang =='en')
	{
			var form = $(id).validate({
			messages:{
				"contact_person" : "Contact person is requested",
				"email" : "Email format is not correct",
				"tel" : "Telephone number is requested",
				"detail" : "Detail is requested"
			},
			rules:
			{
				email:{email:true}
			},
			errorClass : "form_error"
		
		});
	}
	
	if(form.form())
		$(id).submit();
	else
		return false;
}

function checkEmailContact(error_msg,attr, default_msg,form)
{
	var contact_person=document.getElementById('contact_name');
	var email=document.getElementById('email');
	var tel =document.getElementById('contact_tel');
	var check_in_day = document.getElementById('check_in_day');
	var check_in_month = document.getElementById('check_in_month');
	var check_out_day = document.getElementById('check_out_day');
	var check_out_month = document.getElementById('check_out_month');

	var msg='';
	var temp;
	
	temp=checkNull(contact_person.value, attr[0], error_msg[0]);
	if(typeof(temp)=='string')
		msg+=temp;
	
	temp=checkNull(email.value, attr[1], error_msg[0]);
	if(typeof(temp)=='string')
		msg+=temp;
	else
	{
		temp=checkEmail(email.value, attr[1], error_msg[1]);
		if(typeof(temp)=='string')
			msg+=temp;
	}
		
		
	temp=checkNull(tel.value, attr[3], error_msg[0]);
	if(typeof(temp)=='string')
		msg+=temp;
		
	temp=checkSupplied(check_in_day.value, '入住/去程日', '沒有選擇');
	if(typeof(temp)=='string')
		msg+=temp;
		
	temp=checkSupplied(check_in_month.value, '入住/去程月', '沒有選擇');
	if(typeof(temp)=='string')
		msg+=temp;
	
	temp=checkSupplied(check_out_month.value, '退房/回程日', '沒有選擇');
	if(typeof(temp)=='string')
		msg+=temp;
		
	temp=checkSupplied(check_out_month.value, '退房/回程月', '沒有選擇');
	if(typeof(temp)=='string')
		msg+=temp;
	
	if(msg=='')
		form.submit();
	else
		alert(default_msg+'\n'+msg);
}

function checkSupplied(val, attr, msg)
{
	if(val!='Not Supplied')
		return true;
	else
		return attr+' '+msg+'\n';
}

function checkStr(val,attr,msg,len)
{
	if(val.length<=len)
		return true;
	else
		return attr+' '+msg+' '+len+'\n';
}

function checkEmail(val,attr,msg)
{
	if((val.indexOf(".") > 2) && (val.indexOf("@") > 0))
		return true;
	else
		return attr+' '+msg+'\n';
}

function checkNull(val,attr, msg)
{
	if(val!='')
		return true;
	else
		return attr+' '+msg+'\n';
}

function checkConfirmPassword(pass1, pass2, msg)
{
	if(pass1==pass2)
		return true
	else
		return msg;
}
