﻿function getXMLHTTPRequest() { 
	var xRequest = null;
	
	if (window.XMLHttpRequest) {
		xRequest = new XMLHttpRequest();
		if (xRequest.overrideMimeType) xRequest.overrideMimeType('text/xml');
	} else if (window.ActiveXObject){
		try	{
			xRequest = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try	{
				xRequest = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Trinh duyet cua ban khong the xem trang web nay');
				self.location.href = 'errorBrowser.htm';
			}
		}
	}
	return xRequest;
}

var req = null;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sendRequest(url, params, HttpMethod, divID, showProcess, useAlerter) { 
	if (!HttpMethod) HttpMethod = 'GET';
	req = getXMLHTTPRequest();
	if (req) {
		req.onreadystatechange = function() {dumpData(divID, showProcess, useAlerter)};
		req.open(HttpMethod, url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(params);
	}
}



var responseXML = null;
var responseText = null;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function dumpData(divID, showProcess, useAlerter){ 
	var sdata = null;
	var showAlertMessage = false;

	if (req.readyState == 4){
		crossObj('SPMusic_LoadingMessage').style.display = 'none';
		if (req.status == 200) {
			sdata = req.responseText;
			showAlertMessage = true;		
		} 
		else {
			sdata = 'Error !';
		}
	} 
	else {
		if (showProcess) crossObj('SPMusic_LoadingMessage').style.display = '';
	}

	
	if (divID && sdata && !useAlerter) {
		crossObj(divID).innerHTML = sdata;
	} 
	else if (useAlerter && showAlertMessage) {
		alert(sdata);
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function crossObj(id){ 
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	} else {
		return null;
	}
}

function load_data_bctc(){
	sendRequest("_bao_cao_tai_chinh.asp?msbc="+ report_name.value,null, 'GET', 'content_bctc', true)
	}
	
function EW_checkMyForm(EW_this) {

if (EW_this.date_begin && !EW_hasValue(EW_this.date_begin, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.date_begin, "TEXT", "Phải phập ngày bắt đầu"))
		return false;
}
if (!EW_checkusdate(EW_this.date_begin.value)) {
	if (!EW_onError(EW_this, EW_this.date_begin, "TEXT", "Nhập chưa đúng kiểu ngày(mm/dd/yyyy)"))
		return false; 
}

if (EW_this.date_end && !EW_hasValue(EW_this.date_end, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.date_end, "TEXT", "Phải phập ngày bắt đầu"))
		return false;
}
if (!EW_checkusdate(EW_this.date_end.value)) {
	if (!EW_onError(EW_this, EW_this.date_end, "TEXT", "Nhập chưa đúng kiểu ngày(mm/dd/yyyy)"))
		return false; 
}
return true;

}
function load_data_tbl_price(){
	if (EW_checkMyForm(search_price)){
	sendRequest("_tbl_price_search.asp?date_begin="+ search_price.date_begin.value + "&date_end="+ search_price.date_end.value,null, 'GET', 'table_price', true)
	//alert(search_price.date_end.value)
	}
}
function load_data_tbl_price_page(page_id){
	if (EW_checkMyForm(search_price)){
	sendRequest("_tbl_price_search.asp?date_begin="+ search_price.date_begin.value + "&date_end="+ search_price.date_end.value +"&page="+page_id,null, 'GET', 'table_price', true)
	//alert(search_price.date_end.value)
	}
}
function load_data_tbl_price_page_default(page_id){
	if (EW_checkMyForm(search_price)){
	sendRequest("_price_search_page_default.asp?page="+page_id,null, 'GET', 'table_price', true)
	//alert(search_price.date_end.value)
	}
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split(',');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function load_bc_cstc(){
	
	sendRequest("_aj_chisotaichinh.asp?ID="+ view_bctc_cs.value,null, 'GET', 'Content_view_bctc', true)
	}
function load_grid_stock(strKey){
	sendRequest("_list_stocks_search.asp?TTID="+ select_TT.value + "&NNID=" + select_NN_id.value + "&MCKID=" + MCK.value + "&Key=" + strKey,null, 'GET', 'grid_stock_view', true)
	}
	
function load_grid_stock_page(strKey,page){
	sendRequest("_list_stocks_search.asp?TTID="+ select_TT.value + "&NNID=" + select_NN_id.value + "&MCKID=" + MCK.value + "&page=" + page + "&Key=" + strKey,null, 'GET', 'grid_stock_view', true)
	}	


function load_grid_otcstock_page(page,mck,sb){
	sendRequest("_tbl_list_otc.asp?msid=2" + "&mck=" + mck + "&side=" + sb + "&page=" + page,null, 'GET', 'grid_otcstock_view', true)
	
	}	

function _OTC_trading_results(page,mck){
	sendRequest("_OTC_trading_results.asp?msid=2" + "&mck=" + mck +  "&page=" + page,null, 'GET', 'grid_OTC_trading_results', true)
	
	}

function BSmck(page,mck,side){
	sendRequest("_tbl_list_otc.asp?msid=2" + "&mck=" + mck + "&side=" + side + "&page=" + page,null, 'GET', 'grid_otcstock_view', true)
	
	}	

	
function load_about_us(id_us){
	sendRequest("_about.asp?id="+ id_us,null, 'GET', 'grid_stock_view', true)
	}
	


function redir_quich_search(msids){
	var form = document.quick_search;
	if (form.MCK.value =='ALL')
	{
		form.action="quick_search.asp?TTID="+ form.select_TT.value + "&NNID=" + form.select_NN_id.value + "&MCKID=" + form.MCK.value +"&msid=" + msids ;
		
	
	}
	else
	{
		form.action="company.asp?MCK=" + form.MCK.value +"&msid=" + msids ;
	}
    form.submit();
	
	}	
function load_imgvnindex() {
	sendRequest("_load_img_vnindex.asp",null, 'GET', 'img_index', true)
	}
function load_imghastcindex() {
	sendRequest("_load_img_hatcindex.asp",null, 'GET', 'img_index', true)
	}
	

function load_imgvnindex_page() {
	sendRequest("_load_img_vnindex_page.asp",null, 'GET', 'img_index', true)
	}
function load_imghastcindex_page() {
	sendRequest("_load_img_hatcindex_page.asp",null, 'GET', 'img_index', true)
	}


function tinnhanhck_load_imgvnindex() {
	sendRequest("_tinnhanhck_load_img_vnindex.asp",null, 'GET', 'img_index', true)
	}
function tinnhanhck_load_imghastcindex() {
	sendRequest("_tinnhanhck_load_img_hatcindex.asp",null, 'GET', 'img_index', true)
	}
