// JavaScript Document

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;
	var minDigitsInIDNo = 9;
	var minDigitsInPhone = 6;

	function isInteger(s)
	{   
		var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	

	function stripCharsInBag(s, bag)
	{  
		 var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	function checkInternationalPhone(strPhone)
	{
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}
	function checkIDNo(id_no)
	{
		s=stripCharsInBag(id_no,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIDNo);
	}
	function checkPhone(phone)
	{
		s=stripCharsInBag(phone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInPhone);
	}
	
	/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	
	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++){   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function stripCharsInBag(s, bag){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++){   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
	
	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   } 
	   return this
	}
	
	function isDate(dtStr)
	{
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			//alert("The date format should be : dd/mm/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			//alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			//alert("Please enter a valid day")
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			//alert("Please enter a valid date")
			return false
		}
		return true
	}
	
	function splitEmail(email)
	{
		//document.news_form.TextBox5.value = document.news_form.TextBox5.value.replace(new RegExp(/^\s+/),"");
		email.value = email.value.replace(new RegExp(/\s+$/),"");
	}

	function CheckEmail(obj)
	{
		var re = /^([A-Za-z0-9\_\-]+\.)*[A-Za-z0-9\_\-]+@[A-Za-z0-9\_\-]+(\.[A-Za-z0-9\_\-]+)+$/;
		var sEMail = obj.value;
		if (sEMail.search(re) == -1)
		{
				return (false);
		}
		else
		{
			return (true);
		}
	}
	
	function update_preferred_contact_dream_register(s) 
	{			
		var preferred_contact = document.getElementById("preferred_contact");
		
		if(s=="1")
		{
			document.getElementById("phone").style.display = 'none';
			document.getElementById("home_phone").style.display = '';
		}
		else if(s=="2")
		{
			document.getElementById("phone").style.display = '';
			document.getElementById("home_phone").style.display = 'none';
			
		}
		else if(s=="3")
		{
			document.getElementById("phone").style.display = '';
			document.getElementById("home_phone").style.display = '';
		}
		else
		{
			document.getElementById("phone").style.display = 'none';
			document.getElementById("home_phone").style.display = 'none';
		}
	}
	
	function update_is_pru_staff(s) 
	{		
		if(document.getElementById("chk_pru_staff").checked == true)
		{
			document.getElementById("code").style.display = '';
		}
		else
		{
			document.getElementById("code").style.display = 'none';
		}
		/*var is_pru_staff = document.getElementById("is_pru_staff");
		
		if(s=="1")
		{
			document.getElementById("code").style.display = '';
		}
		else
		{
			document.getElementById("code").style.display = 'none';
		}*/
	}
	
	function update_preferred_contact(s) 
	{			
		var preferred_contact = document.getElementById("preferred_contact");
		
		if(s=="1")
		{
			document.getElementById("preferred_contact_phone").style.display = '';
			document.getElementById("preferred_contact_mobile").style.display = 'none';
			document.getElementById("preferred_contact_email").style.display = 'none';
		}
		else if(s=="2")
		{
			document.getElementById("preferred_contact_phone").style.display = 'none';
			document.getElementById("preferred_contact_mobile").style.display = '';
			document.getElementById("preferred_contact_email").style.display = 'none';
		}
		else if(s=="3")
		{
			document.getElementById("preferred_contact_phone").style.display = 'none';
			document.getElementById("preferred_contact_mobile").style.display = 'none';
			document.getElementById("preferred_contact_email").style.display = '';
		}
		else if(s=="4")
		{
			document.getElementById("preferred_contact_phone").style.display = '';
			document.getElementById("preferred_contact_mobile").style.display = '';
			document.getElementById("preferred_contact_email").style.display = '';
		}
	}
	
	function update_staff_dream_register(s) 
	{			
		var staff = document.getElementById("staff");
		
		if(s=="1" || s=="2")
		{
			document.getElementById("code").style.display = '';
		} else {
			document.getElementById("code").style.display = 'none';
			}
	}
	
	function show_hear_about_other(s) 
	{			
		var hear_about = document.getElementById("hear_about");
		var index = hear_about.selectedIndex;
		if(hear_about.options[index].text == "Khác")
		{
			document.getElementById("hear_about_other").style.display = '';
		}
		else
			document.getElementById("hear_about_other").style.display = 'none';
	}
	
	function CountWords (this_field)
	{
		var char_count = this_field.value.length;
		var fullStr = this_field.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		if (fullStr.length <2) {
			word_count = 0;
		}
		return word_count;
	}
	
	function validate_share_this_dream(theForm)
	{
		if(theForm.name.value == "")
		{
			alert("Vui lòng điền Tên của bạn!");
			theForm.name.focus(); 
			return false; 
		}
		if(theForm.email.value == "")
		{
			alert("Vui lòng điền Địa chỉ Email của bạn!");
			theForm.email.focus(); 
			return false; 
		}
		if(theForm.email.value != "")
		{
			splitEmail(theForm.email);
			if(!CheckEmail(theForm.email))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email.focus(); 
				return false; 
			}
		}
		if(theForm.name1.value == "")
		{
			alert("Vui lòng điền tên người nhận!");
			theForm.name1.focus(); 
			return false; 
		}
		if(theForm.email1.value == "")
		{
			alert("Vui lòng điền Địa chỉ Email người nhận");
			theForm.email1.focus(); 
			return false; 
		}
		if(theForm.email1.value != "")
		{
			splitEmail(theForm.email1);
			if(!CheckEmail(theForm.email1))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email1.focus(); 
				return false; 
			}
		}
		if(theForm.email2.value != "")
		{
			splitEmail(theForm.email2);
			if(!CheckEmail(theForm.email2))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email2.focus(); 
				return false; 
			}
			if(theForm.name2.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name2.focus(); 
				return false; 
			}
		}
		if(theForm.email3.value != "")
		{
			splitEmail(theForm.email3);
			if(!CheckEmail(theForm.email3))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email3.focus(); 
				return false; 
			}
			if(theForm.name3.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name3.focus(); 
				return false; 
			}
		}
		for(i=1;i<=3;i++)
			for(j=i+1;j<=3;j++)
			{
				email1 = theForm['email' + i].value;
				email2 = theForm['email' + j].value
				if(email2 != "" && email1 != "" && email1 == email2)
				{
					alert('Bạn đã điền địa chỉ email: '+ email1 + ' rồi!');
					theForm['email' + j].focus();
					return false;
				}
			}
		
		return true;
	}
	
	function validate_tell_a_friend(theForm)
	{
		if(theForm.name.value == "")
		{
			alert("Vui lòng điền Tên của bạn!");
			theForm.name.focus(); 
			return false; 
		}
		if(theForm.email.value == "")
		{
			alert("Vui lòng điền Địa chỉ Email của bạn!");
			theForm.email.focus(); 
			return false; 
		}
		if(theForm.email.value != "")
		{
			splitEmail(theForm.email);
			if(!CheckEmail(theForm.email))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email.focus(); 
				return false; 
			}
		}
		if(theForm.name1.value == "")
		{
			alert("Vui lòng điền tên người nhận!");
			theForm.name1.focus(); 
			return false; 
		}
		if(theForm.email1.value == "")
		{
			alert("Vui lòng điền Địa chỉ Email người nhận");
			theForm.email1.focus(); 
			return false; 
		}
		if(theForm.email1.value != "")
		{
			splitEmail(theForm.email1);
			if(!CheckEmail(theForm.email1))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email1.focus(); 
				return false; 
			}
		}
		if(theForm.email2.value != "")
		{
			splitEmail(theForm.email2);
			if(!CheckEmail(theForm.email2))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email2.focus(); 
				return false; 
			}
			if(theForm.name2.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name2.focus(); 
				return false; 
			}
		}
		if(theForm.email3.value != "")
		{
			splitEmail(theForm.email3);
			if(!CheckEmail(theForm.email3))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email3.focus(); 
				return false; 
			}
			if(theForm.name3.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name3.focus(); 
				return false; 
			}
		}
		for(i=1;i<=3;i++)
			for(j=i+1;j<=3;j++)
			{
				email1 = theForm['email' + i].value;
				email2 = theForm['email' + j].value
				if(email2 != "" && email1 != "" && email1 == email2)
				{
					alert('Bạn đã điền địa chỉ email: '+ email1 + ' rồi!');
					theForm['email' + j].focus();
					return false;
				}
			}
		
		return true;
	}
	
	function validate_share_dream(theForm)
	{	
		if(theForm.name.value == "")
		{
			alert("Vui lòng điền Tên của bạn!");
			theForm.name.focus(); 
			return false; 
		}
		if(theForm.email.value == "")
		{
			alert("Vui lòng điền Địa chỉ Email của bạn!");
			theForm.email.focus(); 
			return false; 
		}
		if(theForm.email.value != "")
		{
			splitEmail(theForm.email);
			if(!CheckEmail(theForm.email))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email.focus(); 
				return false; 
			}
		}
		
		if(theForm.name1.value == "")
		{
			alert("Vui lòng điền tên người nhận!");
			theForm.name1.focus(); 
			return false; 
		}
		if(theForm.email1.value == "")
		{
			alert("Vui lòng điền Địa chỉ Email người nhận");
			theForm.email1.focus(); 
			return false; 
		}
		if(theForm.email1.value != "")
		{
			splitEmail(theForm.email1);
			if(!CheckEmail(theForm.email1))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email1.focus(); 
				return false; 
			}
		}
		
		if(theForm.email2.value != "")
		{
			splitEmail(theForm.email2);
			if(!CheckEmail(theForm.email2))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email2.focus(); 
				return false; 
			}
			if(theForm.name2.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name2.focus(); 
				return false; 
			}
		}
		
		if(theForm.email3.value != "")
		{
			splitEmail(theForm.email3);
			if(!CheckEmail(theForm.email3))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email3.focus(); 
				return false; 
			}
			if(theForm.name3.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name3.focus(); 
				return false; 
			}
		}
		
		if(theForm.email4.value != "")
		{
			splitEmail(theForm.email4);
			if(!CheckEmail(theForm.email4))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email4.focus(); 
				return false; 
			}
			if(theForm.name4.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name4.focus(); 
				return false; 
			}
		}
		
		if(theForm.email5.value != "")
		{
			splitEmail(theForm.email5);
			if(!CheckEmail(theForm.email5))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email5.focus(); 
				return false; 
			}
			if(theForm.name5.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name5.focus(); 
				return false; 
			}
		}
		
		if(theForm.email6.value != "")
		{
			splitEmail(theForm.email6);
			if(!CheckEmail(theForm.email6))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email6.focus(); 
				return false; 
			}
			if(theForm.name6.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name6.focus(); 
				return false; 
			}
		}
		
		if(theForm.email7.value != "")
		{
			splitEmail(theForm.email7);
			if(!CheckEmail(theForm.email7))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email7.focus(); 
				return false; 
			}
			if(theForm.name7.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name7.focus(); 
				return false; 
			}
		}
		
		if(theForm.email8.value != "")
		{
			splitEmail(theForm.email8);
			if(!CheckEmail(theForm.email8))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email8.focus(); 
				return false; 
			}
			if(theForm.name8.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name8.focus(); 
				return false; 
			}
		}
		
		if(theForm.email9.value != "")
		{
			splitEmail(theForm.email9);
			if(!CheckEmail(theForm.email9))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email9.focus(); 
				return false; 
			}
			if(theForm.name9.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name9.focus(); 
				return false; 
			}
		}
		
		if(theForm.email10.value != "")
		{
			splitEmail(theForm.email10);
			if(!CheckEmail(theForm.email10))
			{
				alert("Địa chỉ Email không hợp lệ!");
				theForm.email10.focus(); 
				return false; 
			}
			if(theForm.name10.value == "")
			{
				alert("Vui lòng điền tên người nhận!");
				theForm.name10.focus(); 
				return false; 
			}
		}
		for(i=1;i<=10;i++)
			for(j=i+1;j<=10;j++)
			{
				email1 = theForm['email' + i].value;
				email2 = theForm['email' + j].value
				if(email2 != "" && email1 != "" && email1 == email2)
				{
					alert('Bạn đã điền địa chỉ email: '+ email1 + ' rồi!');
					theForm['email' + j].focus();
					return false;
				}
			}
		
		return true;
	}
	
	function validate_dream_register(forms)
	{
		if(forms.full_name.value == "")
		{
			alert("Vui lòng điền họ tên!");
			forms.full_name.focus();
			return false;
		}
		if(forms.date.selectedIndex == 0 || forms.month.selectedIndex == 0 || forms.year.selectedIndex == 0)
		{
			alert("Vui lòng điền ngày sinh dd/mm/yyyy");
			if(forms.date.selectedIndex == 0)
				forms.date.focus();
			else if(forms.month.selectedIndex == 0)
				forms.month.focus();
			else if(forms.year.selectedIndex == 0)
				forms.year.focus();
			return false;
		}
		if(forms.street_address.value == "")
		{
			alert("Vui lòng điền địa chỉ!");
			forms.street_address.focus();
			return false;
		}
		if (forms.province.selectedIndex == 0)
	  	{
			alert("Vui lòng chọn tỉnh/thành phố!");
			forms.province.focus(); 
			return false;  
	  	}
		if(forms.id_num.value == "")
		{
			alert("Vui lòng điền số CMND!");
			forms.id_num.focus();
			return false;
		}
		if (checkIDNo(forms.id_num.value)==false)
		{
			alert("Vui lòng điền số CMND hợp lệ!");
			forms.id_num.focus();
			return false;
		}
		
		if(forms.email.value == "")
		{
			alert("Vui lòng điền email của bạn!");
			forms.email.focus();
			return false;
		}
		if(!CheckEmail(forms.email))
		{
			alert("Email không hợp lệ!");
			forms.email.focus(); 
			return false; 
		}
		
		
		if(forms.preferred_contact.selectedIndex > 0 )
		{
			if(forms.preferred_contact.selectedIndex == 1)
			{
				if(forms.land_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại cố định!");
					forms.land_phone.focus();
					return false;
				}
				else
				{
					if(forms.land_phone.value.length < 7)
					{
						alert("Xin vui lòng nhập tối thiểu là 7 số!");
						forms.land_phone.focus();
						return false;
					}
					
					if(forms.land_phone.value.length > 11)
					{
						alert("Xin vui lòng nhập tối đa là 11 số!");
						forms.land_phone.focus();
						return false;
					}
					
					if (checkPhone(forms.land_phone.value)==false)
					{
						alert("Vui lòng nhập số điện thoại hợp lệ!");
						forms.land_phone.focus();
						return false;
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 2)
			{
				if(forms.cell_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại di động!");
					forms.cell_phone.focus();
					return false;
				}
				else
				{
					if(forms.cell_phone.value.substring(0,2) == "09" || forms.cell_phone.value.substring(0,2) == "01")
					{
						if(forms.cell_phone.value.substring(0,2) == "09" && forms.cell_phone.value.length != 10)
						{
							alert("Số điện thoại di động bắt đầu bằng 09 và có 10 số!");
							forms.cell_phone.focus();
							return false;
						}
						if(forms.cell_phone.value.substring(0,2) == "01" && forms.cell_phone.value.length != 11)
						{
							alert("Số điện thoại di động bắt đầu bằng 01 và có 11 số!");
							forms.cell_phone.focus();
							return false;
						}
						if (checkInternationalPhone(forms.cell_phone.value)==false)
						{
							alert("Vui lòng nhập số điện thoại di động hợp lệ!");
							forms.cell_phone.focus();
							return false;
						}
					}
					else
					{
						alert("Số điện thoại di động bắt đầu bằng 09 hoặc 01!");
						forms.cell_phone.focus();
						return false;
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 3)
			{
				if(forms.land_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại cố định!");
					forms.land_phone.focus();
					return false;
				}
				else
				{
					if(forms.land_phone.value.length < 7)
					{
						alert("Xin vui lòng nhập tối thiểu là 7 số!");
						forms.land_phone.focus();
						return false;
					}
					
					if(forms.land_phone.value.length > 11)
					{
						alert("Xin vui lòng nhập tối đa là 11 số!");
						forms.land_phone.focus();
						return false;
					}
					if (checkPhone(forms.land_phone.value)==false)
					{
						alert("Vui lòng nhập số điện thoại hợp lệ!");
						forms.land_phone.focus();
						return false;
					}
				}
				
				if(forms.cell_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại di động!");
					forms.cell_phone.focus();
					return false;
				}
				else
				{
					if(forms.cell_phone.value.substring(0,2) == "09" || forms.cell_phone.value.substring(0,2) == "01")
					{
						if(forms.cell_phone.value.substring(0,2) == "09" && forms.cell_phone.value.length != 10)
						{
							alert("Số điện thoại di động bắt đầu bằng 09 và có 10 số!");
							forms.cell_phone.focus();
							return false;
						}
						if(forms.cell_phone.value.substring(0,2) == "01" && forms.cell_phone.value.length != 11)
						{
							alert("Số điện thoại di động bắt đầu bằng 01 và có 11 số!");
							forms.cell_phone.focus();
							return false;
						}
						if (checkInternationalPhone(forms.cell_phone.value)==false)
						{
							alert("Vui lòng nhập số điện thoại di động hợp lệ!");
							forms.cell_phone.focus();
							return false;
						}
					}
					else
					{
						alert("Số điện thoại di động bắt đầu bằng 09 hoặc 01!");
						forms.cell_phone.focus();
						return false;
					}
				}
				
			}
		}
				
		/*if(forms.cell_phone.value != "")
		{
			if (checkPhone(forms.cell_phone.value)==false)
			{
				alert("Vui lòng điền số điện thoại hợp lệ!");
				forms.cell_phone.focus();
				return false;
			}
		}*/
		if(forms.chk_pru_staff.checked == true)
		{
			if(forms.pru_code.value == "")
			{
				alert("Vui lòng điền mã số!");
				forms.pru_code.focus();
				return false;
			}
		}
		if(forms.dream.value == "")
		{
			alert("Vui lòng điền giấc mơ!");
			forms.dream.focus();
			return false;
		}
		if(CountWords(forms.dream) > 80)
		{
			alert("Ước mơ của bạn không được vượt quá 80 từ!");
			forms.dream.focus(); 
			return false;
		}
		if(forms.agree.checked==false)
		{
			alert("Vui lòng đọc và chấp nhận với Quy định và Điều lệ của chương trình!");
			forms.agree.focus(); 
			return false;
		}
		/*if(confirm("Bạn có chắc về những thông tin mà bạn đã đăng ký?"))
			return true;
		else
			return false;*/
		
	}
	
	function validate_internal_dream_register(forms)
	{
		if(forms.full_name.value == "")
		{
			alert("Vui lòng điền họ tên!");
			forms.full_name.focus();
			return false;
		}
		if(forms.date.selectedIndex == 0 || forms.month.selectedIndex == 0 || forms.year.selectedIndex == 0)
		{
			alert("Vui lòng điền ngày sinh dd/mm/yyyy");
			if(forms.date.selectedIndex == 0)
				forms.date.focus();
			else if(forms.month.selectedIndex == 0)
				forms.month.focus();
			else if(forms.year.selectedIndex == 0)
				forms.year.focus();
			return false;
		}
		if(forms.street_address.value == "")
		{
			alert("Vui lòng điền địa chỉ!");
			forms.street_address.focus();
			return false;
		}
		if (forms.province.selectedIndex == 0)
	  	{
			alert("Vui lòng chọn tỉnh/thành phố!");
			forms.province.focus(); 
			return false;  
	  	}
		if(forms.id_num.value == "")
		{
			alert("Vui lòng điền số CMND!");
			forms.id_num.focus();
			return false;
		}
		if (checkIDNo(forms.id_num.value)==false)
		{
			alert("Vui lòng điền số CMND hợp lệ!");
			forms.id_num.focus();
			return false;
		}

		if(forms.email.value != "")
		{
			if(!CheckEmail(forms.email))
			{
				alert("Email không hợp lệ!");
				forms.email.focus(); 
				return false; 
			}	
		}
		
		
		if(forms.preferred_contact.selectedIndex > 0 )
		{
			if(forms.preferred_contact.selectedIndex == 1)
			{
				if(forms.land_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại cố định!");
					forms.land_phone.focus();
					return false;
				}
				else
				{
					if(forms.land_phone.value.length < 7)
					{
						alert("Xin vui lòng nhập tối thiểu là 7 số!");
						forms.land_phone.focus();
						return false;
					}
					
					if(forms.land_phone.value.length > 11)
					{
						alert("Xin vui lòng nhập tối đa là 11 số!");
						forms.land_phone.focus();
						return false;
					}
					if (checkPhone(forms.land_phone.value)==false)
					{
						alert("Vui lòng nhập số điện thoại hợp lệ!");
						forms.land_phone.focus();
						return false;
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 2)
			{
				if(forms.cell_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại di động!");
					forms.cell_phone.focus();
					return false;
				}
				else
				{
					if(forms.cell_phone.value.substring(0,2) == "09" || forms.cell_phone.value.substring(0,2) == "01")
					{
						if(forms.cell_phone.value.substring(0,2) == "09" && forms.cell_phone.value.length != 10)
						{
							alert("Số điện thoại di động bắt đầu bằng 09 và có 10 số!");
							forms.cell_phone.focus();
							return false;
						}
						if(forms.cell_phone.value.substring(0,2) == "01" && forms.cell_phone.value.length != 11)
						{
							alert("Số điện thoại di động bắt đầu bằng 01 và có 11 số!");
							forms.cell_phone.focus();
							return false;
						}
						if (checkInternationalPhone(forms.cell_phone.value)==false)
						{
							alert("Vui lòng nhập số điện thoại di động hợp lệ!");
							forms.cell_phone.focus();
							return false;
						}
					}
					else
					{
						alert("Số điện thoại di động bắt đầu bằng 09 hoặc 01!");
						forms.cell_phone.focus();
						return false;
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 3)
			{
				if(forms.land_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại cố định!");
					forms.land_phone.focus();
					return false;
				}
				else
				{
					if(forms.land_phone.value.length < 7)
					{
						alert("Xin vui lòng nhập tối thiểu là 7 số!");
						forms.land_phone.focus();
						return false;
					}
					
					if(forms.land_phone.value.length > 11)
					{
						alert("Xin vui lòng nhập tối đa là 11 số!");
						forms.land_phone.focus();
						return false;
					}
					if (checkPhone(forms.land_phone.value)==false)
					{
						alert("Vui lòng nhập số điện thoại hợp lệ!");
						forms.land_phone.focus();
						return false;
					}
				}
				
				if(forms.cell_phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại di động!");
					forms.cell_phone.focus();
					return false;
				}
				else
				{
					if(forms.cell_phone.value.substring(0,2) == "09" || forms.cell_phone.value.substring(0,2) == "01")
					{
						if(forms.cell_phone.value.substring(0,2) == "09" && forms.cell_phone.value.length != 10)
						{
							alert("Số điện thoại di động bắt đầu bằng 09 và có 10 số!");
							forms.cell_phone.focus();
							return false;
						}
						if(forms.cell_phone.value.substring(0,2) == "01" && forms.cell_phone.value.length != 11)
						{
							alert("Số điện thoại di động bắt đầu bằng 01 và có 11 số!");
							forms.cell_phone.focus();
							return false;
						}
						if (checkInternationalPhone(forms.cell_phone.value)==false)
						{
							alert("Vui lòng nhập số điện thoại di động hợp lệ!");
							forms.cell_phone.focus();
							return false;
						}
					}
					else
					{
						alert("Số điện thoại di động bắt đầu bằng 09 hoặc 01!");
						forms.cell_phone.focus();
						return false;
					}
				}
				
			}
		}
				
		/*if(forms.cell_phone.value != "")
		{
			if (checkPhone(forms.cell_phone.value)==false)
			{
				alert("Vui lòng điền số điện thoại hợp lệ!");
				forms.cell_phone.focus();
				return false;
			}
		}*/
		if(forms.chk_pru_staff.checked == true)
		{
			if(forms.pru_code.value == "")
			{
				alert("Vui lòng điền mã số!");
				forms.pru_code.focus();
				return false;
			}
		}
		/*if(forms.dream.value == "")
		{
			alert("Vui lòng điền giấc mơ!");
			forms.dream.focus();
			return false;
		}*/
		if(forms.dream.value != "" && CountWords(forms.dream) > 80)
		{
			alert("Ước mơ của bạn không được vượt quá 80 từ!");
			forms.dream.focus(); 
			return false;
		}
		
		return true;
		/*if(confirm("Bạn có chắc về những thông tin mà bạn đã đăng ký?"))
			return true;
		else
			return false;*/
		
	}
	
	function check_dream(forms)
    {
        if(CountWords(forms.dream) >= 80)
		{
			forms.dream.value = forms.dream.value.substr(0,forms.dream.value.length-1);
			//alert("Ước mơ của bạn không được vượt quá 80 từ!");
			//forms.dream.focus(); 
			//return false;
		}
		return true;
    }
	
	function dream_warning(forms)
	{
		if(forms.dream.value == "")
		{
			//alert('Xin vui lòng không chia sẻ ước mơ có liên quan đến chính trị, bạo lực hoặc nội dung tuyên truyền những điều trái pháp luật Việt Nam.');	
			alert("Xin vui lòng không chia sẻ ước mơ có liên quan đến chính trị, bạo lực, tình dục hoặc các nội dung trái với pháp luật và thuần phong mỹ tục Việt Nam.");
			forms.dream.focus();
		}
	}
	
	function validate(forms)
	{
		if(forms.full_name.value == "")
		{
			alert("Vui lòng nhập họ tên!");
			forms.full_name.focus();
			return false;
		}
		if(forms.street_address.value == "")
		{
			alert("Vui lòng nhập địa chỉ!");
			forms.street_address.focus();
			return false;
		}
		if (forms.province.selectedIndex == 0)
	  	{
			alert("Vui lòng chọn tỉnh/thành phố!");
			forms.province.focus(); 
			return false;  
	  	}
		if(forms.date.selectedIndex == 0 || forms.month.selectedIndex == 0 || forms.year.selectedIndex == 0)
		{
			alert("Vui lòng nhập ngày sinh dd/mm/yyyy");
			if(forms.date.selectedIndex == 0)
				forms.date.focus();
			else if(forms.month.selectedIndex == 0)
				forms.month.focus();
			else if(forms.year.selectedIndex == 0)
				forms.year.focus();
			return false;
		}
		if(forms.preferred_contact.selectedIndex == 0)
		{
			alert("Vui lòng chọn cách bạn muốn nhận thông tin!");
			forms.preferred_contact.focus();
			return false;
		}
		else
		{
			if(forms.preferred_contact.selectedIndex == 1)
			{
				if(forms.phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại cố định!");
					forms.phone.focus();
					return false;
				}
				else
				{
					if (checkPhone(forms.phone.value)==false)
					{
						alert("Vui lòng nhập số điện thoại hợp lệ!");
						forms.phone.focus();
						return false;
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 2)
			{
				if(forms.mobile.value == "")
				{
					alert("Vui lòng nhập số điện thoại di động!");
					forms.mobile.focus();
					return false;
				}
				else
				{
					if(forms.mobile.value.substring(0,2) == "09" || forms.mobile.value.substring(0,2) == "01")
					{
						if(forms.mobile.value.substring(0,2) == "09" && forms.mobile.value.length != 10)
						{
							alert("Số điện thoại di động bắt đầu bằng 09 và có 10 số!");
							forms.mobile.focus();
							return false;
						}
						if(forms.mobile.value.substring(0,2) == "01" && forms.mobile.value.length != 11)
						{
							alert("Số điện thoại di động bắt đầu bằng 01 và có 11 số!");
							forms.mobile.focus();
							return false;
						}
						if (checkInternationalPhone(forms.mobile.value)==false)
						{
							alert("Vui lòng nhập số điện thoại di động hợp lệ!");
							forms.mobile.focus();
							return false;
						}
					}
					else
					{
						alert("Số điện thoại di động bắt đầu bằng 09 hoặc 01!");
						forms.mobile.focus();
						return false;
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 3)
			{
				if(forms.email.value == "")
				{
					alert("Vui lòng nhập email!");
					forms.email.focus();
					return false;
				}
				else
				{
					if(!CheckEmail(forms.email))
					{
						alert("Vui lòng nhập email hợp lệ!");
						forms.email.focus(); 
						return false; 
					}
				}
			}
			if(forms.preferred_contact.selectedIndex == 4)
			{
				if(forms.phone.value == "")
				{
					alert("Vui lòng nhập số điện thoại cố định!");
					forms.phone.focus();
					return false;
				}
				else
				{
					if (checkPhone(forms.phone.value)==false)
					{
						alert("Vui lòng nhập số điện thoại hợp lệ!");
						forms.phone.focus();
						return false;
					}
				}
				
				if(forms.mobile.value == "")
				{
					alert("Vui lòng nhập số điện thoại di động!");
					forms.mobile.focus();
					return false;
				}
				else
				{
					if(forms.mobile.value.substring(0,2) == "09" || forms.mobile.value.substring(0,2) == "01")
					{
						if(forms.mobile.value.substring(0,2) == "09" && forms.mobile.value.length != 10)
						{
							alert("Số điện thoại di động bắt đầu bằng 09 và có 10 số!");
							forms.mobile.focus();
							return false;
						}
						if(forms.mobile.value.substring(0,2) == "01" && forms.mobile.value.length != 11)
						{
							alert("Số điện thoại di động bắt đầu bằng 01 và có 11 số!");
							forms.mobile.focus();
							return false;
						}
						if (checkInternationalPhone(forms.mobile.value)==false)
						{
							alert("Vui lòng nhập số điện thoại di động hợp lệ!");
							forms.mobile.focus();
							return false;
						}
					}
					else
					{
						alert("Số điện thoại di động bắt đầu bằng 09 hoặc 01!");
						forms.mobile.focus();
						return false;
					}
				}
				
				if(forms.email.value == "")
				{
					alert("Vui lòng nhập email!");
					forms.email.focus();
					return false;
				}
				else
				{
					if(!CheckEmail(forms.email))
					{
						alert("Vui lòng nhập email hợp lệ!");
						forms.email.focus(); 
						return false; 
					}
				}
			}
		}
		
		var hear_about = document.getElementById("hear_about");
		var index = hear_about.selectedIndex;
		if(hear_about.options[index].text == "Khác")
		{
			if(forms.hear_about_other.value == "")
			{
				alert("Vui lòng chỉ rõ bạn biết về Pru Link như thế nào!");
				forms.hear_about_other.focus(); 
				return false; 
			}
		}
		
		if(CountWords(forms.message) > 100)
		{
				alert("Thông điệp của bạn không vượt quá 100 từ!");
				forms.message.focus(); 
				return false;
		}
		return true;
	}