﻿var is_ie = ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );
var is_ie5 = ( is_ie && /msie 5\.0/i.test(navigator.userAgent) );
var is_ie6 = ( is_ie && /msie 6\.0/i.test(navigator.userAgent) );
var is_ie7 = ( is_ie && /msie 7\.0/i.test(navigator.userAgent) );
var is_opera = /opera/i.test(navigator.userAgent);
var is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
var is_xp=/windows NT 5\.1/i.test(navigator.userAgent);
function LTrim( value ) {var re = /\s*((\S+\s*)*)/;return value.replace(re, "$1");}
function RTrim( value ) {var re = /((\s*\S+)*)\s*/;return value.replace(re, "$1");}
function trim( value ) {return LTrim(RTrim(value));}
function $get(id) {return document.getElementById(id);}

function offsetView(){var offsetWidth = document.body.offsetWidth;var offsetHeight=window.document.body.clientHeight;offsetWidth=(offsetWidth > 0 ? offsetWidth : 1);offsetHeight=(offsetHeight > 0 ? offsetHeight : 1);return {width:offsetWidth, height:offsetHeight};}
var sizemin=980;
function write_cookie(name, value, path) {
            var path1 = "/";
            // Build the expiration date string:
            var expiration_date = new Date();
            expiration_date.setYear(expiration_date.getYear() + 1);
            expiration_date = (expiration_date.toGMTString()).replace('011', '11');
            // Build the set-cookie string:    
            var cookie_string = escape(name) + "=" + escape(value) + "; expires=" + expiration_date;
            //    if (path != undefined || path != null) {
            //        cookie_string += "; path=" + path1;
            //    }
            //    // Create/update the cookie:
            cookie_string += "; path=/";
            document.cookie = cookie_string;
        }

        function read_cookie(key, skips) {            
            if (skips == undefined || skips == null)
                skips = 0;            
            var cookie_string = "" + document.cookie;
            var cookie_array = cookie_string.split("; ");            
            for (var i = 0; i < cookie_array.length; ++i) {
                var single_cookie = cookie_array[i].split("=");
                if (single_cookie.length != 2) {
                    continue;
                }
                var name = unescape(single_cookie[0]);
                var value = unescape(single_cookie[1]);             
                if (key == name) {// && skips-- == 0)
                    return value;
                }
            } 
            return null;
        }
function resizecontent(){    
 
    var psize=offsetView();
    if(is_ie6){
        psize.width = psize.width-22 <= sizemin ? sizemin : psize.width;
        
        $get("divmain").style.width= "980px";   
        $get("mainContent").style.width="770px";
        $get("idFooter").style.width= "980px";   
    }
    else{psize.width = psize.width <= sizemin ? sizemin : psize.width;}    
    if($get("divmain")!=null){if(psize.width <= sizemin ){$get("divmain").style.width=sizemin + "px";}else{$get("divmain").style.width="100%";}}        
    //resizeFooter(0,500);            
}
var sizemincoviet=500;
function resizecontentcoviet(){     
    var psize=offsetView();
    if(is_ie6){
        psize.width = psize.width-22 <= sizemincoviet ? sizemincoviet : psize.width;
        $get("mainContent").style.width="980px";        
    }
    else{psize.width = psize.width <= sizemincoviet ? sizemincoviet : psize.width;}    
    if($get("divmain")!=null){if(psize.width <= sizemincoviet ){$get("divmain").style.width=sizemincoviet + "px";}else{$get("divmain").style.width="100%";}}                
}

var maxHeight=0;
function resizeFooter(lap,tglap)
{    
    if($get("idFooter"))
    {
        if(lap>50)return;
        lap++;                        
            var xH1=$get("idLeft").offsetHeight;
            var xH2=$get("idCenter").offsetHeight;        
            var xHder=10;
            if(xH2>xH1){xHder= 60;}        
            var maxHeight1 = Math.max(xH1,xH2) + xHder ;                                       
            if(maxHeight != maxHeight1)
            {
                $get("idFooter").style.top= maxHeight1 + "px";               
                $get("idFooter").style.display="";               
                maxHeight = maxHeight1;                                             
                setTimeout("resizeFooter("+lap+","+tglap+")",tglap);                                         
            }
            else
            {
                return;            
            }            
        }
}

var flag_mode_vnh = 0;
var vnh_Dict="A0";
var vnh_Word="";
var language_vg="vi-VN";
var hiThemes="Normal";
var skey="";
var spid="";
function CompleteWord_vnh(_Dict,_Word)
{                
    if(_Word == null || _Word == "" ) return;       
    if(flag_mode_vnh==0)   
    {
        AjaxFuncs.GetCompleteWord_vnh(_Dict,_Word,language_vg,callback_Show_CompleteWord_vnh);    
    }
    else
    {
        AjaxFuncs.FTSCompleteList_vnh(_Word,language_vg,callback_Show_CompleteWord_vnh);            
    }        
}  

function onkeyup_Complete_vnh(wd)
{            
    if(wd != null && wd.value!="" && wd.value !='undefined')
    {
        CompleteWord_vnh(vnh_Dict,wd.value);
    }
    else
    {
        $get("divComplete_vnh").style.display="none";
    }
}

function clOvr(wrd)
{    
    if(flag_vnh == 1 ) 
    {        
        wrd.style.cursor = "";    
        if(node_vnh != -1)
        {
            $get("spComplete_"+ node_vnh).className="clout";
        }
    }
    else
    {
        if(node_vnh >= 0)
        {
            $get("spComplete_0").className="clout";                                                               
            $get("spComplete_"+ node_vnh).className="clout";
        }
        wrd.className="clovr";      
        var wrdid=wrd.id;
        wrdid=wrdid.substring(wrdid.indexOf("_") + 1);           
        node_vnh = wrdid*1
    }                          
}

function clOut(wrd)
{    
    if(wrd.style.cursor!="")
    {
        if(node_vnh >= 0)
        {
            $get("spComplete_" + node_vnh).className="clout";             
            wrd.className="clout";              
        }        
     }
    flag_vnh=0;                              
}
function GetTypeCbo()
{
    var id= $get("select_vnh").selectedIndex;  
    return $get("select_vnh").options[id].value;    
} 
var flagEnter_vnh=false;
function Click_btn_vnh()
{                     
    var el=$get("txtword_vnh");                 
    if(el!=null && el.value!=="")
    {
        window.location.href= "detail.aspx?pid="+""+"&key="+el.value+"&type="+GetTypeCbo()+"&stype="+ flag_mode_vnh;
    }
}
 
 function changeType()
 {
    vnh_Dict=$get("select_vnh").options[$get("select_vnh").selectedIndex].value;    
    nPlaceID="";
 }
    
function Enter(pid)
{
   var wrd = $get("txtword_vnh").value;                    
   window.location.href= "detail.aspx?pid="+pid+"&key="+wrd+"&type="+GetTypeCbo()+"&stype="+ flag_mode_vnh;
}    
function cw(pid,obj)
{   
    checkRadio_vnh("rdtk");
    var wrd = "";    
    if(obj!=''){wrd = $get(obj).innerHTML; }            
    window.location.href = "detail.aspx?pid="+pid+"&key="+wrd+"&type="+GetTypeCbo()+"&stype="+ flag_mode_vnh;
}
function cwadd(obj)
{    
    checkRadio_vnh("rdtv");
    window.location.href= "detail.aspx?pid=&key="+ $get(obj).innerHTML +"&type="+GetTypeCbo()+"&stype="+ flag_mode_vnh+"&fadd=true";
}
function cwExist(vnh_temp)
{
    if(vnh_temp.toLowerCase() == vnh_Word.toLowerCase())
    {                
        $get("divComplete_vnh").style.display="none";                             
        $get("txtword_vnh").value=vnh_temp;
        return 1;             
    }
    return 0;
}
function cwc(obj)
{     
       var vnh_temp="";                                                 
       flag_control=1;       
       var idd=obj.id;                        
       var idfull=idd.substring(idd.indexOf("_") + 1);          
       if(flag_mode_vnh == 0){            
            if(cwExist(trim(obj.innerHTML))==1)return;
            nPlaceID=$get("ip_" + idfull).value;
            cw(nPlaceID,'');    
       }
       else{            
            if(cwExist(obj.childNodes[0].innerHTML)==1)return;            
            window.location.href= "detail.aspx?pid="+""+"&key="+$get("name_" + idfull).value+"&type="+GetTypeCbo()+"&stype="+ flag_mode_vnh;
       }       
}
function checkRadio_vnh(id)
{       
    var el=$get(id);
    if(!el) return;
    el.checked="checked";    
    flag_mode_vnh=el.value;        
}
function mnOvr(obj)
{
    obj.className="fl mntextSel";
}
function mnOut(obj)
{
    obj.className="fl mntext";
}


function mnClick(id)
{
    switch(id)
    {
        case "ttviet":
            location.href="Default.aspx?tab=ttvn";
        break;
        case "bvmoi":
            location.href="newArticle.aspx?tab=bvm";
        break;
        case "bvnbat":            
            window.location.href="detail.aspx?tab=bvnb";
        break;
        case "gykien":            
            var s=location.href;
            var idex=s.indexOf('?');
            if(idex>0)
            {
                s= "&"+s.substring(idex+1).replace("type=_A","type=A");
                if(s.indexOf('tab=')!=-1)
                {
                    s="";
                }
            }else
            {
                s="";
            }                            
            location.href="feedback.aspx?tab=gyk"+s;
        break;
    }
}

function selectTab(id){$get(id+"l").className="tsl fl";$get(id+"c").className="tsc fl ar s10 b clg d";$get(id+"r").className="tsr fl";}
function seltab(sdm,cpid,ckey,ctype)
{       
    
    if($get("hiIdPlaceVnh")){cpid=$get("hiIdPlaceVnh").value;} 
        
    if(cpid.split(';').length > 1)
    {
        if(sdm=="detail"){cpid="";}
    }
    ckey = $get(ckey).value;                   
    if($get("hiNameVnh")){ckey=$get("hiNameVnh").value;}     
    if(sdm.toLowerCase()=="sendarticle")
    {        
       var name = location.pathname;
       var vt = name.lastIndexOf('/');
       name = name.substring(vt+1,name.length-5);              
       window.location.href= sdm+".aspx?pid="+cpid+"&key="+ encodeURIComponent(ckey)+"&type="+ctype+"&u="+name;              
    }
    else
    {
        window.location.href= sdm+".aspx?pid="+cpid+"&key="+ encodeURIComponent(ckey) +"&type="+ctype;     
    }
    //encodeURIComponent()
     //encodeURI
}
    
    
    
    /*==============Detail=================*/
function anhien(id)
{     
    if($get(id).style.display == "none")
    {
        $get(id).style.display=""
        $get("mucluc_"+id).innerHTML="&nbsp;&nbsp;[<span class=\"select_toc\">Ẩn</span>]";
    }
    else
    {      
        $get(id).style.display="none"
        $get("mucluc_"+id).innerHTML="&nbsp;&nbsp;[<span class=\"select_toc\">Xem</span>]";
    }
    
}
function anhienContent(vt)
{
    if($get("divContent"+vt).style.display == "none")
    {           
        $get("divImgmenu"+vt).className="menumo";
        $get("divContent"+vt).style.display=""            
    }
    else
    {      
        $get("divImgmenu"+vt).className="menudong";
        $get("divContent"+vt).style.display="none"                       
    }
    
}
function gotoBm(rid,bmid)
    {
        var di = document.getElementById("divImgmenu"+rid);
        var dc = document.getElementById("divContent"+rid);
        if (di != null) di.className="menumo";
        if (dc != null) dc.style.display="";
    }

function fSearchbyType(strType,strNs,vl1, vl2, vl3,PosStart,StrP,id)
{
    flagPaging="sbytype";
    strSbytype = strType;                     
    namestart = strNs
    sVl1=vl1;
    sVl2=vl2;
    sVl3=vl3;    
    var i=0;      
    strType = strType.toUpperCase();    
    if(strType == "A6")
    {
        if($get('cbbthucvat')){
        $get('txtword_s').value=sVl2;       
        $get("divname_thucvat").innerHTML= "Tên " + sVl1;                               
        }
     }    
    if(strSbytype!="-1")
    {                        
        m_PosStart_vnh=PosStart;
        pageselect_vnh=StrP;    
        page_temp=pageselect_vnh;                                        
        doallpaging_vnh();                  
    }
 }     
 
function opi(fn,edit)
{    
    var readCfg = "";
    if (edit == 1) // editor
        readCfg = "http://www.vietgle.vn/editor.VnhImagesOrigin/";
    else
        readCfg = "http://www.vietgle.vn/VnhImagesOrigin/";
    fn = readCfg + fn
    window.open(fn,"myWindow",'location=0,status=0,scrollbars=1,menubar=0,resizable=1');            
}

function openNewWindow(fn)
{
    var my_window = window.open(fn,"my_window","location=0,status=0,scrollbars=1,menubar=0,resizable=1");                 
}

function dong_ngy(id)
{        
    $get(id).style.display="none";
    AjaxFuncs.write_cookie("view_ngy", "0").value;            
} 

function closeComplete()
{
    if($get("divComplete_vnh").style.display == "")
    {    
        if($get("divComplete_vnh").className=='divcomplete_css')
        {
            $get("divComplete_vnh").style.display = "none";
        }
    }    
}


/*============admin bvnb===================*/

function check_delete_all(){  

    var s=AjaxFuncs.GetResourceString("Global", language_vg, "question_delete").value  + "?";
    return window.confirm(s);	
}

////--------DeleteHomeWord_vnh---------
function DeleteHomeWord_vnh(strId,strType)
{
    if(check_delete_all())
    {        
        var a= AjaxFuncs.DeleteHomeWord(strType,strId).value;
        if(a!="0")
        {
            alert("Xóa không thành công. Do lỗi đọc/ghi cơ sở dữ liệu.")
            return;
        }
        var type_bvnb_add=$get("cbbop"+$get("cbb").selectedIndex).value;
        if(type_bvnb_add == "1"){type_bvnb_add="";}        
         $get(div_A1_bvnb_add).innerHTML = AjaxFuncs.ViewGetAllHomeWord("2", type_bvnb_add).value;        
         alert("Xóa thành công.");         
    }
}

function AddHomeWord_vnh()
{
  var strType="2";    
  var strDate="";
  var strPreword="";
  var strWord="";
  var pid="";
  var el=$get(txtDate_bvnb_add);
  if(el){
    strDate = el.value;
  }
    var el_Name = $get("hiNameVnh");
    if(el_Name)
    {
        strWord=el_Name.value;
        pid = $get("hiIdPlaceVnh").value;
    }
        
    if(strDate!="" && strWord!="" &&  pid!="")
    {      
        
        var showInHome_bvnb_add=$get("cbbop"+$get("cbb").selectedIndex).value;
        if(showInHome_bvnb_add!="1"){showInHome_bvnb_add="0";}
        AjaxFuncs.AddHomeWord(strType,showInHome_bvnb_add,strDate,"",strWord,pid,callback_AddHomeWordVnh);     
    }
    else if(strDate=="")
    {
        alert("Bạn chưa chọn ngày!");
    }
    else if(strWord=="")
    {
        alert("Bạn chưa chọn từ để gán!");
    }
}
function callback_AddHomeWordVnh(res)
{
    if(res==null || res.value=="") return;
    var result = res.value;
    var type_bvnb_add=$get("cbbop"+$get("cbb").selectedIndex).value;
        if(type_bvnb_add =="1"){type_bvnb_add="";}
    if(result =="0")
    {        
        $get(div_A1_bvnb_add).innerHTML = AjaxFuncs.ViewGetAllHomeWord("2", type_bvnb_add).value;        
        alert("Thêm thành công.");
    }
    else if(result =="961")
    {        
        var s="Ngày này đã được chỉ định địa danh hiển thị rồi.\n";
            s += "Bạn có muốn cập nhật lại không?";
        if(window.confirm(s))
        {             
            UpdateHomeWord_vnh();
            $get(div_A1_bvnb_add).innerHTML = AjaxFuncs.ViewGetAllHomeWord("2", type_bvnb_add).value;        
        }
    }
    else if(result =="960")
    {
        alert("Tham số không hợp lệ.");
    }    
    else if(result =="962")
    {
        alert("Lỗi đọc/ghi cơ sở dữ liệu.");
    }        
}
function UpdateHomeWord_vnh()
{  
  var strType="2";      
  var strDate=""; 
  var strPreword="";
  var strWord="";
  var el=$get(txtDate_bvnb_add);
  if(el){
    strDate = el.value;
  }       
    var el_Name = $get("hiNameVnh");
    if(el_Name)
    {
        strWord=el_Name.value;
    }          
    if(strDate!="" && strWord!="")
    {  
        if($get("hiIdPlaceVnh"))
        {        
            AjaxFuncs.UpdateHomeWord(strType,strDate,"",strWord,$get("hiIdPlaceVnh").value).value;     
        }
    }
    else
    {
        alert("Cập nhật không thành công!");
    }
}

function anhienImg(id,idico)
{
    if($get(id).style.display=="none"){$get(id).style.display=""; $get(idico).className="menumo fl m5r";}else{$get(id).style.display="none";$get(idico).className="menudong fl m5r";}
}
