/**
 * Tra cứu điểm thi tuyển sinh
 * (c) 2006 www.mrhoi.com - dungnq@fpt.net
 */
document.writeln('<script src="/Libs/javascript/vietuni/vietuni.js" type="text/javascript"></script>');

document.writeln('<div class="DiemThiTuyenSinh">  <h1>Thông tin chính thức từ bộ giáo dục và đào tạo</h1>  <h2>Chú ý:</h2>  <ul>    <li>Bạn có thể tìm theo tên hoặc số báo danh.</li>    <li>Số báo danh chỉ bao gồm phần số không bao gồm phần chữ.</li>    <li>Tên không phân biệt chữ hoa chữ thường.</li>    <li>Bạn có thể tìm theo họ tên đầy đủ hoặc một phần của họ tên.<br />        <strong>Ví dụ:</strong> Nguyễn Khắc Hiệp hoặc Hiệp hoặc Khắc Hiệp.</li>    <li>Bạn phải gõ tên bao gồm cả dấu. Tiếng việt theo mã Unicode. </li>  </ul>  <form action="" method="post" name="score" id="score" onSubmit="return false;">    <h1>Thông tin tìm kiếm</h1>    <table width="100%" border="0" cellspacing="1" cellpadding="3">      <tr>        <td width="30%">Bộ gõ tiếng Việt </td>        <td><input type=radio name="switcher" value="OFF" onfocus="setTypingMode(0)">          Off            <input type=radio name="switcher" value="TELEX" onfocus="setTypingMode(1)">          Telex          <input type=radio name="switcher" value="VNI" onfocus="setTypingMode(2)">          VNI          <input type=radio name="switcher" value="VIQR" onfocus="setTypingMode(3)">          VIQR          <input name="switcher" type=radio onfocus="setTypingMode(4)" value="ALL" checked>          Tự động</td>      </tr>      <tr>        <td width="30%">Họ tên thí sinh </td>        <td><label>          <input name="name" type="text" id="name" size="30" maxlength="50" onkeyup="initTyper(this);"/>        </label></td>      </tr>      <tr>        <td width="30%">Số báo danh </td>        <td><input name="code" type="text" id="code" size="15" maxlength="30" />          (chỉ nhập phần số) </td>      </tr>      <tr>        <td>Năm dự thi </td>        <td><select name="year" id="year">          <option value="">---------------</option>                </select></td>      </tr>      <tr>        <td width="30%">Trường dự thi </td>        <td><label>          <select name="uni" id="uni">  <option value="">---------------</option>          </select>        </label></td>      </tr>      <tr>        <td>Mã bảo mật </td>        <td><input name="security" type="text" id="security" size="10" maxlength="10" />            <img src="/Plus/securelog/image.asp" alt="security"/></td>      </tr>      <tr>        <td width="30%">&nbsp;</td>        <td><input name="submit" type="submit" value="Tìm kiếm" onClick="Score.process(this.form)" />            <input name="reset" type="reset" value="Chọn lại" /></td>      </tr>    </table>  </form></div><div id="KetQua" class="KetQua"></div>');

Score = {	
	current : Object(),
	
	addYear : function () {
		yearSelectBox = document.forms['score'].year;
		for (i=2005; i<=2006; i++) {
			var e = document.createElement('option');
			e.text = i.toString();
			e.value = i;			
			try {
				yearSelectBox.add(e);				
			}
			catch (err) {
				yearSelectBox.appendChild(e);
			}
		}
		yearSelectBox.onchange = function () {			
			Score.addUni(this.value);			
		}		
	},
	
	addUni : function (year) {
		uniSelectBox = document.forms['score'].uni;
		// remove all option old		
		while (uniSelectBox.options.length > 0) {			
			uniSelectBox.options[uniSelectBox.options.length - 1] = null;			
		}	
		
		e = document.createElement('option');
		e.text = 'Loading...';
		e.value = '';
		try {
			uniSelectBox.add(e);				
		}
		catch (err) {
			uniSelectBox.appendChild(e);
		}	
		uniSelectBox.options[0].selected = true;
		
		Request.debug = true;
		Request.load({
			url : '/Plus/TraCuu/DiemThiTuyenSinh/readUniData.asp',
			method		: 'POST',
			data		: 'year=' + year,
			callback	: function(xmlHttp, objHTML) {				
				if (xmlHttp.xml) {
					uniSelectBox.options[0].text = "Lựa chọn trường...";					
					
					for (i=0; i<xmlHttp.xml.uni.length; i++) {
						var e = document.createElement('option');
						e.text = xmlHttp.xml.uni[i].name;
						e.value = xmlHttp.xml.uni[i].code;		
						try {
							uniSelectBox.add(e);				
						}
						catch (err) {
							uniSelectBox.appendChild(e);
						}
					}	
				}
				else if (xmlHttp.text == 0) {
					uniSelectBox.options[0].text = "...";					
				}
				else {
					uniSelectBox.options[0].text = "Lỗi kết nối...";
					
				}
			},		 	
			loadingType	: 0,			
			objActive	: 'KetQua'
		});	
	},
	
	page : function(over) {
		if (over) {over = 3;}		
		var total 	= parseInt(Score.html.xml.totalRec);
		var number	= parseInt(Score.html.xml.sizePage);
		var current	= parseInt(Score.html.xml.currentPage);
			
		var content = [];
		page = Math.ceil((total)/number);		
			
		if (page > 1 && current <= page) {
			for (i=1; i <= page; i++) {				
				if (i == current) {						
					content[content.length] = {page:i, text:i, selected:1}; 
				}
				else {
					content[content.length] = {page:i, text:i, selected:0};
				}				
			}					
			return content;
		}
		else {
			return null;	
		}
	},
		
	process : function (obj, page) {
		if (!page) {
			page = 1;	
		}
		else {
			page = parseInt(page);
		}
		
		if (!obj.name.value && !obj.code.value) {
			alert ('Xin vui lòng nhập Họ tên thí sinh hoặc Số báo danh.');			
			return false;
		}
		else {
			p = /^[0-9]*$/;			
			if (!p.test(obj.code.value)) {
				alert ('Số báo danh chỉ cần nhập phần số.');		
				return false;
			}			
		}
		
		if (!obj.year.value) {
			alert('Xin vui lòng chọn Năm dự thi');
			return false;
		}
		
		if (!obj.uni.value) {
			alert('Xin vui lòng chọn Trường dự thi');
			return false;
		}
		
		if (!obj.security.value) {
			alert('Xin vui lòng nhập Mã bảo mật');
			return false;
		}
		
				
		Request.load({
			url : '/Plus/TraCuu/DiemThiTuyenSinh/findScore.asp',
			method		: 'POST',
			data		: 'year=' + obj.year.value + '&name=' + encodeURIComponent(obj.name.value) + '&code=' + obj.code.value + '&uni=' + obj.uni.value + '&security=' + encodeURIComponent(obj.security.value),
			callback	: function(xmlHttp, objHTML) {				
				Score.html = new Object();				
				if (xmlHttp.xml) {					
					Score.html.xml = xmlHttp.xml;
					Score.html.xml.year = obj.year.value;
					Score.html.xml.page	= Score.page(5);
					Score.html.xml.request = 'year=' + obj.year.value + '&name=' + encodeURIComponent(obj.name.value) + '&code=' + obj.code.value + '&uni=' + obj.uni.value + '&security=' + encodeURIComponent(obj.security.value);
					Request.load({
						url : '/Plus/TraCuu/DiemThiTuyenSinh/findScore.html',						
						callback	: function(xmlHttp, objHTML) {				
							if (xmlHttp.text) {															
								Score.html.tpl = xmlHttp.text;							
								content = Score.html.tpl.process(Score.html.xml);
								
								PositionX = 0;
								PositionY = 0;
								
								defaultWidth  = 800;
								defaultHeight = 600;
								
								var opt='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
								resultWin=window.open('about:blank','',opt);								
								with (resultWin.document){
									writeln(content);
								}
							}							
							else {
								alert('Lỗi kết nối.');					
							}
						},		 	
						loadingType	: 0,			
						objActive	: objHTML
					});						
				}
				else if (xmlHttp.text == -1) {
					alert('Mã bảo mật của bạn không chính xác.');	
				}
				else if (xmlHttp.text == 0) {
					alert('Xin lỗi, chúng tôi không tìm được kết quả nào với dữ kiện của ban.');	
				}
				else {
					alert('Lỗi kết nối.');					
				}
			},		 	
			loadingType	: 0,			
			objActive	: 'KetQua'
		});	
	}
};
window.onload = function () {
	setTypingMode(4);	
	Score.addYear();
}
