﻿
function EnabledControl(Check, el){
    if(Check.checked){
        document.getElementById(el).disabled = "";
        document.getElementById(el).focus();
    }
    else{
        document.getElementById(el).disabled = "disabled";
    }
}

function EnabledDangKy(Check, el){
    if(Check.checked){
        document.getElementById(el).disabled = "";
        document.getElementById(el).title = "";
    }
    else{
        document.getElementById(el).disabled = "disabled";
        document.getElementById(el).title = "Bạn chưa đồng ý thỏa thuận sử dụng.";
    }
}

function EnabledCongTy(Check, txtTenCT, txtDiaChiCT, txtMaSoThue){
    if(Check.checked){
        document.getElementById(txtTenCT).disabled = "";
        document.getElementById(txtDiaChiCT).disabled = "";
        document.getElementById(txtMaSoThue).disabled = "";
        document.getElementById(txtTenCT).focus();
    }
    else{
        document.getElementById(txtTenCT).disabled = "disabled";
        document.getElementById(txtDiaChiCT).disabled = "disabled";
        document.getElementById(txtMaSoThue).disabled = "disabled";
    }
}

function ClosePopup(){
    top.document.body.style.overflow='auto';
    top.document.getElementById('divMain').style.visibility='hidden';
    top.document.getElementById('divMain').style.width=0;            
    top.document.getElementById('divMain').style.height=0;
    top.p1.Hide();
}

function EditPopup(url){
    document.body.style.overflow="hidden";
    
    document.getElementById("divMain").style.visibility='visible';
    document.getElementById("divMain").style.width=1500;            
    document.getElementById("divMain").style.height=3000;   
    
    var ran = Math.random(); 
    if(url.indexOf('?')>0) url=url + '&popup=' + ran;
    else url=url + '?popup=' + ran;
    
    p1.contentUrl=url;
    p1.Show();
}

function ReloadGridview() {
    top.g1.GetValuesOnCustomCallback('CurrentPage', function(result) {
        top.g1.GotoPage(result);
    });

}

function features(isStatus, isResizeable, isScrollbars, isToolbar, isLocation, 
isFullscreen, isTitlebar, isCentered, width, height, top, left){
    if (isCentered)
	{
		top = (screen.height - height) / 2;
		left = (screen.width - width) / 2;
	}
    return 'status=' + (isStatus ? 'yes' : 'no') + ','
	+ 'resizable=' + (isResizeable ? 'yes' : 'no') + ','
	+ 'scrollbars=' + (isScrollbars ? 'yes' : 'no') + ','
	+ 'toolbar=' + (isToolbar ? 'yes' : 'no') + ','
	+ 'location=' + (isLocation ? 'yes' : 'no') + ','
	+ 'fullscreen=' + (isFullscreen ? 'yes' : 'no') + ','
	+ 'titlebar=' + (isTitlebar ? 'yes' : 'no') + ','
	+ 'height=' + height + ',' + 'width=' + width + ','
	+ 'top=' + top + ',' + 'left=' + left;
}
function showDialog(url, width, height)
{
	open(url, '_blank', features(false, false, false, false, false, false, true, true, width, height, 0, 0));
}
function CloseWindow()
{
 Window.Close();
}
    
//Xu ly so
function FormatNumber(str){
	 var strTemp = GetNumber(str);
	 if(strTemp.length <= 3)
		  return strTemp;
	 strResult = "";
	 for(var i =0; i< strTemp.length; i++)
		  strTemp = strTemp.replace(",", "");
	 for(var i = strTemp.length; i>=0; i--)
	 {
		  if(strResult.length >0 && (strTemp.length - i -1) % 3 == 0)
			   strResult = "," + strResult;
		  strResult = strTemp.substring(i, i + 1) + strResult;
	  }	
	  return strResult;
}

function GetNumber(str)
{
	for(var i = 0; i < str.length; i++)
	{	
		var temp = str.substring(i, i + 1);		
		if(!(temp == "," || temp == "." || (temp >= 0 && temp <=9)))
		{
			  alert("Vui lòng nhập số (0-9)!");
			  return str.substring(0, i);
		}
		if(temp == " "){
		      return str.substring(0, i);
		}
	}
	return str;
}
            
function ConvertPriceText(strTemp)
{
	strTemp        = strTemp.replace(/,/g, "");
	var priceTy    = parseInt(strTemp/1000000000,0)
	var priceTrieu = parseInt((strTemp % 1000000000)/1000000,0)
	var priceNgan  = parseInt(((strTemp % 1000000000))%1000000/1000,0)
	var priceDong  = parseInt(((strTemp % 1000000000))%1000000%1000,0)
	var strTextPrice = ""      
	if(priceTy > 0 && parseInt(strTemp,0) > 900000000)
		strTextPrice = strTextPrice  + "<b>" + priceTy + "</b> tỷ "
	if(priceTrieu > 0)
		strTextPrice = strTextPrice  + "<b>" + priceTrieu + "</b> triệu "
	if(priceNgan > 0)
		strTextPrice = strTextPrice  + "</b>" + priceNgan + "</b> ngàn "
    if(document.getElementById("tiente").value == "vnd1")
    {
         if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
	         strTextPrice = strTextPrice  + "<b>VNĐ</b>"
    }
    if(document.getElementById("tiente").value == "sjc")
    {
        if(priceDong > 0)
           strTextPrice = strTextPrice + priceDong
        if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
		   strTextPrice = FormatNumber(strTemp) + "<b> lượng SJC</b>"
    }
    if(document.getElementById("tiente").value == "usd")
    {
        if(priceDong > 0)
            strTextPrice = strTextPrice + priceDong
        if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
		    strTextPrice = FormatNumber(strTemp) + "<b> USD</b>"
    }
    document.getElementById("priceText").innerHTML = strTextPrice
}
           
function FocusObj(name)
{
    document.getElementById(name).focus()
}
