//Kiểm Tra Tính Hợp Lệ Của Email Trên Trình Khách
function validEmail(obj) {
	var s = obj.value;
	for (var i=0; i<s.length; i++)
		if (s.charAt(i)==" "){
			return false;
		}
	var elem, elem1;
	elem=s.split("@");
	if (elem.length!=2)	return false;

	if (elem[0].length==0 || elem[1].length==0)return false;

	if (elem[1].indexOf(".")==-1)	return false;

	elem1=elem[1].split(".");
	for (var i=0; i<elem1.length; i++)
		if (elem1[i].length==0)return false;
	return true;
}
//------------------------------------------------------------------------
//Kiểm Tra Xem đã có dữ liệu nhập hay chưa
function testSpaceBar(obj){
	if(obj.value=="")return false;
	else{		
		var s = obj.value;
		var temp = s.split(" ");
		var str = "";
		for(var i=0; i<temp.length; i++)str=str + temp[i];
		if(str==""){
			obj.value = str.substring(0,str.length);
			return false;
		}
	}//else
	return true;
}

function isValideNumber(Cstring) {
	var inword = '0123456789';
	
	var i ;
	for ( i=0; i<Cstring.length; i++ ){
		if(inword.indexOf(Cstring.substring(i,i+1)) <0){
			return false;
		}
	}
	return true;
}

function isValidePicture(image){
	stmp = document.getElementById(image).value;
	if(stmp!=''){
		tarr = stmp.split(".");
		if(tarr.length<2)return false;
		stmp = tarr[tarr.length-1];
		stmp = stmp.toLowerCase();
		if(stmp != "gif" && stmp != "jpg" && stmp != "jpeg"){
			alert("Chỉ Chấp Nhận Những Định Dạng Hình Ảnh: *.jpg, *.jpeg, *.gif");
			document.getElementById(image).focus();
			return false;
		}
	}	
	return true;
}
//-----------------------------------------------------------------------

function docheck_I(status,from_){
	var alen=document.FrmList.elements.length;
	alen=(alen>2)?document.FrmList.chkOneDelete.length:0;
	if (alen>0){
		for(var i=0;i<alen;i++)
			document.FrmList.chkOneDelete[i].checked=status;
	}
	else {
		document.FrmList.chkOneDelete.checked=status;
	}
	if (from_>0)
		document.FrmList.chkAllDelete.checked=status;
}
//-----------------------------------------------------------------------	

function docheckone_I(){
	var alen=document.FrmList.elements.length;
	var isChecked=true;
	alen=(alen>3)?document.FrmList.chkOneDelete.length:0;
	if (alen>0){
		for(var i=0;i<alen;i++)
			if (document.FrmList.chkOneDelete[i].checked==false)
			isChecked=false;
	}
	else {
		if (document.FrmList.chkOneDelete.checked==false)
		isChecked=false;
	}
	document.FrmList.chkAllDelete.checked=isChecked;
}
//-----------------------------------------------------------------------

function checkall_I(){
	if (document.FrmList.chkAllDelete.checked==true)
		docheck_I(true,1);
	else
		docheck_I(false,2);
}
//-----------------------------------------------------------------------

function checkInput_I(obj,msg,msg_I) {
	var alen=document.FrmList.elements.length;
	var isChecked=false;
	alen=(alen>4)?document.FrmList.chkOneDelete.length:0;
	if (alen>0){
		for(var i=0;i<alen;i++)
			if (document.FrmList.chkOneDelete[i].checked==true)
				isChecked=true;
	}
	else {
		if(document.FrmList.chkOneDelete.checked==true)
			isChecked=true;
	}
	if(!isChecked){
		//GetBlackWindows('1');
		alert(msg);
		//GetBlackWindows('');
	}			 
	else{
		if (obj=="btnDelete")
			//GetBlackWindows('1');
			blnClick=confirm(msg_I);
		if (blnClick==true){
			isChecked=true;
			//GetBlackWindows('');
		}
		else{
			isChecked=false;
			//GetBlackWindows('');
		}
	}
	return isChecked;
}

function readOnlyForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
		var formElement = theform.elements[i];
			if (true) {
				formElement.readOnly = true;
			}
		}
	}
}

function keypress(e){
//Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
	var keypressed = null;
	if (window.event)	{
	keypressed = window.event.keyCode; //IE
	}
	else	{ 
	keypressed = e.which; //NON-IE, Standard
	}
	if (keypressed < 48 || keypressed > 52)	{ //CharCode của 0 là 48 (Theo bảng mã ASCII)	//CharCode của 9 là 57 (Theo bảng mã ASCII)
		if (keypressed == 8 || keypressed == 127 || keypressed == 13)	{//Phím Delete và Phím Back va Phím Enter
		return;
		}
	return false;
	}
}

function keypress09(e){
//Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
	var keypressed = null;
	if (window.event)	{
	keypressed = window.event.keyCode; //IE
	}
	else	{ 
	keypressed = e.which; //NON-IE, Standard
	}
	if (keypressed < 48 || keypressed > 57)	{ //CharCode của 0 là 48 (Theo bảng mã ASCII)	//CharCode của 9 là 57 (Theo bảng mã ASCII)
		if (keypressed == 8 || keypressed == 127 || keypressed == 13)	{//Phím Delete và Phím Back va Phím Enter
		return;
		}
	return false;
	}
}

function makeRequest(url, obj_response, method, parameters, linkImagesLoad) {
	var http_request	= false;
	var show_id			= document.getElementById(obj_response);
	if (!show_id) {
		//alert('Cannot find object response data !');	
		return false;
	}
	if(url == ""){
		return false;
	}
	show_id.innerHTML	= linkImagesLoad;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request	= new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			//set type accordingly to anticipated content type
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				http_request = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange=	function(){
													if (http_request.readyState == 4) {
														if (http_request.status == 200) {
															//alert(http_request.responseText);
															show_id.innerHTML = http_request.responseText;     
														} else {
															//alert('There was a problem with the request.');
															return false;
														}
													}
												}
	if(method == 'GET'){
		http_request.open('GET', url, true);
		http_request.send('');
	}
	else if(method == 'POST'){
		http_request.open('POST', url, true);
		http_request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		http_request.setRequestHeader('Content-length', parameters.length);
		http_request.setRequestHeader('Connection', 'close');
		http_request.send(parameters);
	}
}
function OpenWindows(url, name, location, status, scrollbars, resizable, width, height)
	{
		window.open(url,name,'location='+location+',status='+status+',scrollbars='+scrollbars+',resizable='+resizable+',width='+width+',height='+height+'');
	}

function DisableTab2(RecourdCount,Recordset,RecourdCount1,Recordset1, var1, var2)
{
	stoper();
	var i=1, x=1;
	x+=RecourdCount;
	for(i=1;i<x;i++){
		if (i==Recordset){
			document.getElementById('oit_'+i+'_1').className='menu_top_1_l';
			document.getElementById('oit_'+i+'_2').className='menu_top_1_c';
			document.getElementById('oit_'+i+'_3').className='menu_top_1_r';
			if(var1!=''){
				toolTip(var1,var2);
			}
		} 
		else{
			document.getElementById('oit_'+i+'_1').className='menu_top_1_l_dfa';
			document.getElementById('oit_'+i+'_2').className='menu_top_1_c_dfa';
			document.getElementById('oit_'+i+'_3').className='menu_top_1_r_dfa';
		}
	}
	var ii=1, xx=1;
	xx+=RecourdCount1;
	for(ii=1;ii<xx;ii++){
		if (ii==Recordset1){
			document.getElementById('menu_2_'+ii).className='menu_top_2';
		} 
		else{
			document.getElementById('menu_2_'+ii).className='menu_top_2_hide';
		}		
	}

}


function setHomePage(URLPage){    
if(document.all){document.body.style.behavior='url(#default#homepage)';document.body.setHomePage(URLPage);}else if (window.sidebar){ if(window.netscape){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}catch(e){alert("Hành động này đã bị khóa bởi trình duyệt của bạn, nếu bạn muốn mở nó lên,Hãy vui lòng tìm hiểu về cách cấu hình đường dẫn từ trình duyệt của bạn và thay đổi giá trị của signed.applets.codebase_principal_support thành true");}}var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);prefs.setCharPref('browser.startup.homepage',URLPage);}} 


var theObj="";

function toolTip(text,me) {
  theObj=me;
  theObj.onmousemove=updatePos;
  document.getElementById('toolTipBox').innerHTML=text;
  document.getElementById('toolTipBox').style.display="block";
  window.onscroll=updatePos;
}

function updatePos() {
  var ev=arguments[0]?arguments[0]:event;
  var x=ev.clientX;
  var y=ev.clientY;
  diffX=14;
  diffY=18;
  document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop+ "px";
  document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
  //theObj.onmouseout=hideMe;
}
function hideMe() {
  document.getElementById('toolTipBox').style.display="none";
}

function gmobj(o){
	if(document.getElementById){ m=document.getElementById(o); }
	else if(document.all){ m=document.all[o]; }
	else if(document.layers){ m=document[o]; }
	return m;
}

function ShowGoldPrice(){
	var sHTML = '';
	sHTML = sHTML.concat('<table class="giavang">');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td width="30%">Loại</td>');
	sHTML = sHTML.concat('		<td width="35%">Mua</td>');
	sHTML = sHTML.concat('		<td width="35%">Bán</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td width="30%">SBJ</td>');
	sHTML = sHTML.concat('		<td width="35%">').concat(vGoldSbjBuy).concat('</td>');
	sHTML = sHTML.concat('		<td width="35%">').concat(vGoldSbjSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td width="30%">SJC</td>');
	sHTML = sHTML.concat('		<td width="35%">').concat(vGoldSjcBuy).concat('</td>');
	sHTML = sHTML.concat('		<td width="35%">').concat(vGoldSjcSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td colspan="3">(Nguồn:<a href="http://www.sacombank-sbj.com" target="_blank"><img style="border: 0px none ; vertical-align: middle; width: 75px; height: 9px;" src="http://vnexpress.net/Images/logoSb.gif" alt="Sacombank"></a>)</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('</table>');
//	gmobj('eGold').innerHTML = sHTML;
}	
		
function ShowForexRate(){
	var sHTML = '';
	sHTML = sHTML.concat('<table class="ngoaite">');
	for(var i=0;i<vForexs.length;i++){
		sHTML = sHTML.concat('	<tr>');
		sHTML = sHTML.concat('		<td width="32%">').concat(vForexs[i]).concat('</td>');
		sHTML = sHTML.concat('		<td width="68%">').concat(vCosts[i]).concat('</td>');
		sHTML = sHTML.concat('	</tr>');		
	}
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td colspan="2">(Nguồn: <a href="http://www.eximbank.com.vn/"><img src="http://vnexpress.net/Images/logo-EXIM.gif"></a>)</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('</table>');
	gmobj('eForex').innerHTML = sHTML;
}

var DivLoad='<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\"><tr><td align=\"center\" valign=\"middle\" width=\"100%\">Dữ Liệu Đang Được Tải Về<br /><br /><img src=\"/img/themes/skin/loading.gif\" width=\"120\" height=\"15\" /></td></tr></table>'

function loadpic(id) {
	makeRequest('/ajax/thi_picture.asp', 'pic-online', 'POST', 'id='+id, DivLoad)	
}

function loadtrinhdo(id) {
	makeRequest('/ajax/thi_trinhdo.asp', 'TrinhDo', 'POST', 'id='+id,DivLoad)
}
function loaddethi(id) {
	makeRequest('/ajax/thi_dethi.asp', 'DeThi', 'POST', 'id='+id,DivLoad )
}

function loadAdvertisePosition(id) {
	if (id == -1 ) {
		document.getElementById('Advertise_2').style.display = ''
		document.getElementById('Advertise_1').style.display = 'none'
		document.getElementById('Advertise_3').style.display = 'none'
		document.getElementById('advertise_position_1').value= ''
		document.getElementById('advertise_position_3').value= ''
	}
	else if (id == -2 ) {
		document.getElementById('Advertise_3').style.display = ''
		document.getElementById('Advertise_1').style.display = 'none'
		document.getElementById('Advertise_2').style.display = 'none'
		document.getElementById('advertise_position_1').value= ''
		document.getElementById('advertise_position_2').value= ''
	}
	else {
		document.getElementById('Advertise_2').style.display = 'none'
		document.getElementById('Advertise_1').style.display = ''
		document.getElementById('Advertise_3').style.display = 'none'
		document.getElementById('advertise_position_2').value= ''
		document.getElementById('advertise_position_3').value= ''
	}
}

function loadsearch2(id, langnum) {
	makeRequest('/ajax/search_cat2.asp', 'search2', 'POST', 'id='+id+'&langnum='+langnum, DivLoad)	
}



