﻿$(document).ready(function() {	
	$("#frmSummary").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			cbCountry:{
				required 	: true			
			},
			cbProvince: {
				required	: true
			},
			cbDistrict: {
				required	: true
			}
		},
		messages: {
			cbCountry:{
				required : com_msg_requiredcountry
			},
			cbProvince: {
				required : com_msg_requiredprovince
			},
			cbDistrict: {
				required : com_msg_requireddistrict
			}
		}
	});	
	$("#frmSelf").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			txtIntroduce:{
				required 			: true,
				validateIntroduce 	: true,
				rangelength			: [30,500]
			},
			txtPersonality: {				
				validatePersonality	: true
			}
		},
		messages: {
			txtIntroduce:{
				required			: com_msg_requiredintroduce,
				rangelength			: com_msg_invalidintroduce,
				validateIntroduce 	: com_msg_invalidintroduce				
			},
			txtPersonality: {
				validatePersonality : com_msg_registerpersonality
			}
		}
	});	
	$.validator.addMethod('validateIntroduce', function() {
		$('#txtIntroduce').val(stripTags($('#txtIntroduce').val(),''));
		var txtIntroduce = $('#txtIntroduce').val();
		if (txtIntroduce.length < 30 || txtIntroduce.length > 500) return false;
		return true;
	});	
	$.validator.addMethod('validatePersonality', function() {		
		$('#txtPersonality').val(stripTags($('#txtPersonality').val(), '')); 
		return ($('#txtPersonality').val() != '' ? true : false);		
		return false;
	});	
});

function deleteWishes(username, offset, id)
{
	if (confirm(com_msg_confirmdelete)) {
		$.get (
			HOST_HAT + 'ajax/deletewishes?isajax=1&username='+username + '&offset='+offset + '&id='+id,		
			function(html) {				
				showUIMessage(com_msg_deletesuccess);
				$("#cvMyDream").html(html);				
			}
		);
	}
}
function showProvince(country, t)
{	
	if (t==undefined) t=0;
	$.get(
		HOST_HAT + 'ajax/province?id='+country+'&t='+t,
		function(result) {				
			$("#spanProvince").html(result);				
		}
	);	
}
function showDistrict(intProvinceId)
{
	if (intProvinceId) {
		$.get(
			HOST_HAT + 'ajax/district?id=' + intProvinceId,
			function(result) {
				if(result) {
					$("#spanDistrict").html(result);
				}
			}
		);
	}
}
