
function LoadImage(id,src)
{
    if (id.getAttribute("loi") == null)
    {  
        id.setAttribute("loi","1");
    } 
    else 
    { 
        id.setAttribute("loi",eval(id.getAttribute("loi")) + 1);
    }
    if (eval(id.getAttribute("loi")) >=2)
    { 
        var width = src.substr(src.lastIndexOf("=") + 1,src.length - src.lastIndexOf("=")); 
        id.onerror = null; 
        id.src = "/Images/no_image.jpg"; 
    } 
    else 
    {
        id.src = src;
    }   
}
function $id(id) {
	if(document.getElementById(id))
		return document.getElementById(id);
	else 
		return null;
}
function ChangeImageDoanhNghiep(imgid,ctr,src, obj, obj1,alink, ahref)
{
    if (document.getElementById(imgid))
        document.getElementById(imgid).src = src;
        
    if (document.getElementById(alink))
        document.getElementById(alink).href=ahref;
        
    if (document.getElementById(obj))
    {
       document.getElementById(obj).className = "off";
    }
    if (document.getElementById(obj1)) 
    {
        document.getElementById(obj1).className = "off";
    }
    ctr.className = "on";
   
}
function ChangeImg(imgid,src,titleid, title, alink, ahref, alink1)
{
    if (document.getElementById(imgid))
        document.getElementById(imgid).src = src;
        
    if (document.getElementById(titleid))
        document.getElementById(titleid).innerHTML =title;
    /*    
    if (document.getElementById(alink))
        document.getElementById(alink).href=ahref;
        
    if (document.getElementById(alink1))
     document.getElementById(alink1).href=ahref;
     */
}
function restoreImage(src, title)
{
    if (document.getElementById('imgfocus'))
        document.getElementById('imgfocus').src = src;
    if (document.getElementById('idTitle'))
        document.getElementById('idTitle').innerHTML =title;
}
function SearchPress(event)
{
    var textSearch = document.getElementById('txtSearchTin');    
	var strSearch = textSearch.value;
    var url = "";	
    var key;    
    if(window.event)
    {
        key = window.event.keyCode;        
        if (key == 13)
        {                                     
            if(textSearch.value!="")
            {   
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');    
                if(strSearch=="") return false;
                else if(strSearch.indexOf("?")!=-1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/SearchNews.aspx?KeySearch="+strSearch+"&page=1&state=1";
                document.location.href = url;
                return false;
            }
            else
            {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }            
        }    
    }
    else
    {
        key = event.which;    
        if (key == 13)
        {
              
            if(textSearch.value!="")
            {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');    
                if(strSearch=="") return false;
                else if(strSearch.indexOf("?")!=-1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/SearchNews.aspx?KeySearch="+strSearch+"&page=1&state=1";
                document.location.href = url;
                return false;
            }
            else
            {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                
                return false;
            }
            
        }    
    }               
}
function SearchFocus(field) {
    if (field.value == "Tìm kiếm") field.value = "";
}

function SearchBlur(field) {
    if (field.value == "") field.value = "Tìm kiếm";
}
function SearchCtyFocus() {
    var textSearch = document.getElementById('txtSearchCongty');
    text = textSearch.value;
    if (text == "Tìm kiếm công ty") textSearch.value = "";
}

function SearchCtyBlur() {
    var textSearch = document.getElementById('txtSearchCongty');
    text = textSearch.value;
    if (text == "") textSearch.value = "Tìm kiếm công ty";
}
function optSearchClick(opt)
{
    var textCtySearch = document.getElementById('txtSearchCongty');
    var textTinSearch = document.getElementById('txtSearchTin');
    var textAwardSearch = document.getElementById('txtSearchAward');
    if(opt==1) 
    {
        textCtySearch.style.display="none";
        textTinSearch.style.display="";
        textAwardSearch.style.display="none";
    }
    else if(opt==2) 
    {        
        textCtySearch.style.display="";
        textTinSearch.style.display="none";
        textAwardSearch.style.display="none";
        autocompletestat();        
    }
    else if(opt==3) 
    {        
        textCtySearch.style.display="none";
        textTinSearch.style.display="none";
        textAwardSearch.style.display="";        
    }
}
function SearchOption()
{
    var value = getRadioCheckedValue('optionSearch');
    var textSearch;
    if(value==1)
    {
        textSearch = document.getElementById('txtSearchTin'); 
	    
    }        
    else if(value==2)
    {
        textSearch = document.getElementById('txtSearchAward');    
    }      
    var strSearch = textSearch.value;
    strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');    
    if(strSearch=="") return false;
    else if(strSearch.indexOf("?")!=-1) return false;
    strSearch = encodeURIComponent(strSearch);
	var url="";
    if(value==1)
    {    	
	    url = "/SearchNews.aspx?KeySearch="+strSearch+"&page=1&state=1";
	}
	else if(value==2)
	{
	    url = "/SearchAward.aspx?KeySearch="+strSearch+"&Page=1";  		
	}
    if(strSearch!="")
    {            
	    document.location.href= url;
        return false;
    }
    else
    {
        alert("Bạn chưa nhập từ khóa tìm kiếm !");
        return false;
    }      
}

function SearchAwardPress(event)
{
    var textSearch = document.getElementById('txtSearchAward');    
	var strSearch = textSearch.value;
    var url = "";	
    var key;    
    if(window.event)
    {
        key = window.event.keyCode;        
        if (key == 13)
        {                                     
            if(textSearch.value!="")
            {   
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');    
                if(strSearch=="") return false;
                else if(strSearch.indexOf("?")!=-1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/SearchAward.aspx?KeySearch="+strSearch+"&Page=1";
                document.location.href = url;                   
                return false;
            }
            else
            {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                return false;
            }            
        }    
    }
    else
    {
        key = event.which;    
        
        if (key == 13)
        {
              
            if(textSearch.value!="")
            {
                strSearch = strSearch.replace('?', '').replace(/"/g, '').replace(/^\s+|\s+$/g, '');    
                if(strSearch=="") return false;
                else if(strSearch.indexOf("?")!=-1) return false;
                strSearch = encodeURIComponent(strSearch);
                url = "/SearchAward.aspx?KeySearch="+strSearch+"&Page=1";
                document.location.href = url;                    
                return false;
            }
            else
            {
                alert("Bạn chưa nhập từ khóa tìm kiếm !");
                
                return false;
            }
            
        }    
    }               
}
function SearchAwardFocus() {
    var textSearch = document.getElementById('txtSearchAward');
    text = textSearch.value;
    if (text == "Tìm kiếm giải thưởng") textSearch.value = "";
}

function SearchAwardBlur() {
    var textSearch = document.getElementById('txtSearchAward');
    text = textSearch.value;
    if (text == "") textSearch.value = "Tìm kiếm giải thưởng";
}
function SynHeigth(divA,divB)
{
    var divA = document.getElementById(divA);
    var divB = document.getElementById(divB);
    if (!(divA && divB)) return;
    var divAHeight = divA.offsetHeight;
    var divBHeight = divB.offsetHeight;
    if(divBHeight>divAHeight)
    {
        divA.style.height = divBHeight + "px";
        divB.style.height = divBHeight + "px";
    }
    else if (divBHeight<divAHeight)
    {
        divA.style.height = divAHeight + "px";
        divB.style.height = divAHeight + "px";
    }
}
function equalheight(div_id1, div_id2) {
    var id2 = $id(div_id1);
    
    if (id2) {
        var height_id2 = id2.offsetHeight;
    }
    var id1 = $id(div_id2);
    if (id1) {
        var height_id1 = id1.offsetHeight;
    } else {
        var height_id1 = height_id2;
    }
    maxheight = Math.max(height_id1, height_id2);
    if (id1 != null) {
        id1.style.height = maxheight + "px";
    }
    if (id2) {
        id2.style.height = maxheight + "px";
    }
}
function getRadioCheckedValue(radio_name) {
    var oRadio = document.forms[0].elements[radio_name];
    for(var i = 0; i < oRadio.length; i++) {
    if(oRadio[i].checked) {
        return oRadio[i].value;
    }
}

return '';
} 
function ShowVideo(videoURL,pathLogo,videoname) 
{
    var s1 = new SWFObject("/Images/Video/thv.swf", "mediaplayer", "298", "264", "7");
    s1.addParam("allowfullscreen", "true");
    s1.addVariable("displayheight", "264");
    s1.addVariable("width", "298");
    s1.addVariable("height", "264");
    s1.addVariable("file", videoURL);
    s1.addVariable("logo", pathLogo);
    s1.addVariable("showstop", "false");
    s1.addVariable("autostart", "false");
    s1.addVariable("backcolor", "0x000000");
    s1.addVariable("lightcolor", "0x000000");
    s1.addVariable("frontcolor", "0xFEFEFE");
    s1.write("container");
}
function EmailSubject() {
    openMeExt("/Ajax/SendMail.aspx?url=".concat(escape(location.href)), 0, 0, 0, 0, 0, 0, 1, 1, 650, 650, 0, 0, "", 0);
    return false;
}
function openpopup(mainUrl) {
    openMeExt(mainUrl, 0, 0, 0, 0, 0, 0, 1, 1, 800, 650, 0, 0, "", 0);
    return false;
}
function openMeExt(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft, vID, vCounter) {
    var sLink = typeof vLink.href == "undefined" ? vLink : vLink.href;
    winDef = "";
    winDef = winDef.concat("status=").concat(vStatus ? "yes" : "no").concat(",");
    winDef = winDef.concat("resizable=").concat(vResizeable ? "yes" : "no").concat(",");
    winDef = winDef.concat("scrollbars=").concat(vScrollbars ? "yes" : "no").concat(",");
    winDef = winDef.concat("toolbar=").concat(vToolbar ? "yes" : "no").concat(",");
    winDef = winDef.concat("location=").concat(vLocation ? "yes" : "no").concat(",");
    winDef = winDef.concat("fullscreen=").concat(vFullscreen ? "yes" : "no").concat(",");
    winDef = winDef.concat("titlebar=").concat(vTitlebar ? "yes" : "no").concat(",");
    winDef = winDef.concat("height=").concat(vHeight - 140).concat(",");
    winDef = winDef.concat("width=").concat(vWidth).concat(",");
    if (vCentered) {
        winDef = winDef.concat("top=").concat((screen.height - vHeight) / 2).concat(",");
        winDef = winDef.concat("left=").concat((screen.width - vWidth) / 2);
    } else {
        winDef = winDef.concat("top=").concat(vTop).concat(",");
        winDef = winDef.concat("left=").concat(vLeft);
    }
    if (typeof vCounter == "undefined") {
        vCounter = 0;
    }
    if (typeof vID == "undefined") {
        vID = 0;
    }
    if (vCounter) {
        sLink = buildLink(vID, sLink);
    }
    open(sLink, "_blank", winDef);
    if (typeof vLink.href != "undefined") {
        return false;
    }
}
function tang()
{	    
	if(document.getElementById("divBodyTinChiTiet").style.fontSize=="")
	{
	   document.getElementById("divBodyTinChiTiet").style.fontSize="10pt";
	}
	var vfont = document.getElementById("divBodyTinChiTiet").style.fontSize;
	var new_size = (Number(String(vfont).substring(0,vfont.length-2)) + 1);
	if(new_size>16) new_size=16;
	document.getElementById("divBodyTinChiTiet").style.fontSize= new_size + "pt";
	TangCon(document.getElementById("divBodyTinChiTiet").style.fontSize);
}
	
function TangCon(size)
{
    var cha = document.getElementById("divBodyTinChiTiet");
    var listcon ;
    if (document.all)
        listcon = cha.all;
    else
        listcon = cha.getElementsByTagName("*");	        
    var len = listcon.length;
    for (var i = 0 ; i < len ; i++)
    {
        listcon[i].style.fontSize = size;
        listcon[i].style.fontFamily = "Arial"     
    }
}
function fixsizecontent(size,obj)
{
    var cha = document.getElementById(obj);
    var listcon ;
    if (document.all)
        listcon = cha.all;
    else
        listcon = cha.getElementsByTagName("*");	        
    var len = listcon.length;
    for (var i = 0 ; i < len ; i++)
    {
        listcon[i].style.fontSize = size;
        listcon[i].style.fontFamily = "Arial"     
    }
}
function giam()
{
    
	if(document.getElementById("divBodyTinChiTiet").style.fontSize=="")
	{
	   document.getElementById("divBodyTinChiTiet").style.fontSize="10pt";
	}
	else
	{
	    var vfont = document.getElementById("divBodyTinChiTiet").style.fontSize;
	    var new_size = (Number(String(vfont).substring(0,vfont.length-2)) - 1);
	    if(new_size<7) new_size=7;
	     document.getElementById("divBodyTinChiTiet").style.fontSize= new_size + "pt";
	}
	TangCon(document.getElementById("divBodyTinChiTiet").style.fontSize);
}
function TabMenu()
{
    var id; 
    if(document.getElementById("tabmenu"))
    {
        id = document.getElementById("tabmenu").value;
        if(document.getElementById("id_"+id))
            document.getElementById("id_"+id).className="active";
    }
    
}



/**/
var curent_CMTV = 1;
var number_CMTV = $("#hdTVMPageNumber").val();
function getPageCMTVPre()
{
    if (curent_CMTV == 1){ return false;}
    else
        curent_CMTV--;
    LoadCMTVPage(curent_CMTV);
}
function getPageCMTVNext()
{
    
    if (curent_CMTV >= number_CMTV) {
        curent_CMTV = number_CMTV; 
        return false;
    }
    else 
    {
        curent_CMTV++;
        if (curent_CMTV > number_CMTV) {
            return false;
            curent_CMTV = number_CMTV;    
        }
        else {
            LoadCMTVPage(curent_CMTV,1);
            return false;
       }
    }
    LoadCMTVPage(curent_CMTV);
}

function LoadCMTVPage(curent_CMTV){
    //alert(curent_CMTV);
    $.ajax({ type: 'Get',
        data: { p: curent_CMTV},
        url: '/Ajax/AjaxPageCMTV.aspx',
        //beforeSend: function () { $('#divCMTV').html('<img src="/Images/loading.gif" />'); },
        success: function (msg) {
            $('#divCMTV').html(msg);
        }
    });
}
/**/
/********************** Login *******************************/
function isValidEmail(strEmail) {
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    var x = strEmail.value;
    if (x.search(validRegExp) == -1) {
        alert('Bạn chưa nhập Email hoặc địa chỉ mail không đúng!');
        return false;
    }
    return true;
}
function isValidEm(strEmail) {
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    var x = strEmail;
    if (x.search(validRegExp) == -1) {
        alert('Bạn chưa nhập Email hoặc địa chỉ mail không đúng!');
        return false;
    }
    return true;
}
function hasWhiteSpace(s) {
    reWhiteSpace = new RegExp(/^\s+$/);
    if (reWhiteSpace.test(s)) {
        return false;
    }
    return true;
}


function showPopup(controlID) {
    var control = document.getElementById(controlID);
    document.getElementById("overlay").style.display = "block";
    if (control) {
        control.style.display = 'block';
        control.style.zIndex = '100';
        var top = (window.screen.availHeight - control.offsetHeight) / 2 - 100;
        var left = (document.documentElement.offsetWidth - control.offsetWidth) / 2;
        left += (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
        top += (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;

        control.style.left = left + 'px';
        control.style.top = top + 'px';

        return true;
    }
    return false;
}
function showformmodel(frm, username) {
    showPopup(frm);
    if (document.getElementById(username))
        document.getElementById(username).focus();
}

function hideeditform(hidpopup, hidoverlay) {
    var _objdivMaNhung = document.getElementById(hidoverlay);
    var _objbgFilter = document.getElementById(hidpopup);
    if (_objdivMaNhung)
        _objdivMaNhung.style.display = 'none';
    if (_objbgFilter)
        _objbgFilter.style.display = 'none';
}

function checkuser(user, pwd) {
    var _user = document.getElementById(user);
    var _pwd = document.getElementById(pwd);
    if (_user.value == '') {
        alert('Bạn chưa nhập họ tên');
        _user.focus();
        return false;
    }
    if (_pwd.value == '') {
        alert('Bạn chưa nhập mật khẩu');
        _pwd.focus();
        return false;
    }
}

function checEditUser() {
    var a = $('[id$=txtAcc]').val();
    var e = $('[id$=txtEmail]').val();
    var u = $('[id$=txtFullName]').val()
    if (a == null || a == '') {
        alert('Bạn chưa đăng nhập để sửa thông tin!');
        return false;
    }
    if (u == null || u == '') {
        alert('Bạn chưa nhập họ và tên!');
        $('[id$=txtFullName]').focus();
        return false;
    }
    if (!isValidEm(e))
        return false;
    return true;
}
