﻿
// JScript File
function activeMenu(suffix){
    document.getElementById('bmnu_'+suffix).style.color='#ffffff';
    document.getElementById('bmnu_'+suffix).style.fontWeight='bold';
    document.getElementById('img_'+suffix).src=jsPathPrefix+'images/menu_'+suffix+'_vn_off.gif';
}
function isActiveUrl(strUrl){
    var url=window.location.href.toLowerCase();
    if(url.indexOf(strUrl)>-1){
        return true;  
    }
    return false;
}
function actionActiveMenu(){
    if (isActiveUrl('/gioi-thieu/')){
        activeMenu('aboutus');
    }       
    else if(isActiveUrl('/san-pham/')){
        activeMenu('product');
    }    
    else if (isActiveUrl('/tin-tuc/')){
        activeMenu('news'); 
    }
    else if (isActiveUrl('/tu-van-hoi-dap/')){
        activeMenu('faq'); 
    }   
    else if(isActiveUrl('/lien-he/')){
        activeMenu('contact');
    } 
    else{
        activeMenu('home');
    }
}


function enterSubmit(e){
    var eventInstance = window.event ? event : e;  
    var unicode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;  

    if( unicode == 13){
		doSearch();
		return false;
	}
	else{
		return true;
	}
}
function doSearch(){
	var f=document.frmMain;
	if(f.txtQuery.value!='' && f.txtQuery.value!='tìm kiếm'){
	    var q=f.txtQuery.value;
	    
	    while(q.indexOf('  ')>-1){
	        q=q.replace('  ', ' ');
	    }
	    q=toTitleCase(q);		    
	    while(q.indexOf(' ')>-1){
	        q=q.replace(' ', '-');
	    }

	    q=encodeURI(q);
	    
	    while(q.indexOf('%')>-1){
	        q=q.replace('%', '$');
	    }
       if(q.length>255){
             alert('Từ cần tìm quá dài! Hãy gõ từ ngắn hơn!');
        }
        else{
	        var nextUrl=jsPathPrefix+'vn/Tim-Kiem/' + q + '/';
	        self.location.href=nextUrl;
	    }
	}
	else{
	    alert('Hãy nhập từ cần tìm!');
	    f.txtQuery.value='';
	    f.txtQuery.focus();
	}
}
function myBoolean(x){
    x=x.toLowerCase();
    if (x=='true')
        return true;
    return false;
}
        function lh_init(){
            if(lh_displayimg()){
                //Cau hinh khung chua slide 
                var lh_top='-329';
                
                var lh_left= document.getElementById('iframeMediaPlayer') ? '-222' : '127';
                var lh_background='#ffffff';
                var lh_width='308px';
                var lh_height='329px';
                //Phan khong thay doi
                lh_slide_div= document.getElementById('lh_slide_div');
                lh_slide_div.style.top=lh_top;
                lh_slide_div.style.left=lh_left;
                lh_slide_div.style.background=lh_background;
                lh_slide_div.style.width=lh_width;
                lh_slide_div.style.height=lh_height;
                //An khung nay di
                lh_slide_div.style.display='none';  
                return true;  
            }   
            return false;    
        }
        function setSlide(){
            var x=parseInt(document.getElementById('lh_img_current_pos').value);
            if (x==lh_realA.length-1){
                  document.getElementById('lh_img_current_pos').value=-1;           
            }
            lh_slide_next();
            lh_k=setTimeout("setSlide()",lh_milliseconds);
        }
        function stopSlide(){
            var lh_stop=!myBoolean(document.getElementById('lh_stop_slide').value);
            document.getElementById('lh_stop_slide').value=lh_stop;
            if (lh_stop){
                clearTimeout(lh_k);
            }else{
                setSlide();
            }
        }
        
        function setImg(x){
            if(lh_showPopupA[x]==1){
                document.getElementById('lh_a_slide').href=lh_realA[x];
                document.getElementById('lh_a_slide').style.cursor='pointer';
            }else{
                document.getElementById('lh_a_slide').href='javascript:void(0)';
                document.getElementById('lh_a_slide').style.cursor='default';
            }
            document.getElementById('lh_img_slide').src=lh_realImg[x];
            document.getElementById('lh_img_current_pos').value=x;
            //clearTimeout(lh_k);
            //setSlide();
        }
        function lh_slide(x){
            var lh_has_open=myBoolean(document.getElementById('lh_has_opened_slide').value);
            if(lh_has_open)
                return;
            else
                document.getElementById('lh_has_opened_slide').value="true";
            document.getElementById('lh_stop_slide').value='false';
            //Hien thi layer
            lh_slide_div.style.display='block';
            //Cau hinh hinh trong khung
            var lh_img_width='214px';
            var lh_img_height='234px';
            //Cau hinh hinh trong slide
            var lh_img_slide=document.getElementById('lh_img_slide');
            lh_img_slide.style.width=lh_img_width;
            lh_img_slide.style.height=lh_img_height;
            //Hien thi hinh duoc chon
            setImg(x);
            //Chay slide
            setTimeout("setSlide()",lh_milliseconds);
        }
        function lh_slide_first(){
            setImg(0);
        }
        function lh_slide_last(){
            setImg(lh_realA.length-1);
        }
        function lh_slide_previous(){
            var x=parseInt(document.getElementById('lh_img_current_pos').value);
            if (x!=0)
                setImg(x-1);
        }
        function lh_slide_next(){
            var x=parseInt(document.getElementById('lh_img_current_pos').value);
            if (x!=lh_realA.length-1){
                setImg(x+1);
            }
        }
        function lh_closeSlide(){
            stopSlide(true);
            lh_slide_div.style.display='none';
            document.getElementById('lh_has_opened_slide').value="false";
        }
        function lh_displayimg(){
            //An cac hinh nhap o trang detail
            document.getElementById('lh_imgdetail').style.display='none';
            var lh_result='';
            //Kich thuoc hinh o phan hien thi chi tiet
            var lh_width=125;
            var lh_height=137;
            //Co su dung style/ class khong
            var lh_useClass=false;
            var lh_class='';
            var lh_useStyle=true;
            var lh_style='margin:9px 31px 0 0;';
            //Lay tat ca cac hinh nam trong lh_imgdetail
            var lh_arrImg=document.getElementById('lh_imgdetail').getElementsByTagName('img');
            //Bien luu so luong that
            var j=0;
            //Chay qua tat ca cac hinh nam trong lh_imgdetail
            for (var i=0;i<lh_arrImg.length;i++){
                //Neu khong phai la trans va coming moi xu ly
                if(lh_arrImg[i].src.indexOf('images/trans.gif')==-1 && lh_arrImg[i].src.indexOf('images/coming_soon.jpg')==-1){
                    //Lay ra src
                    var lh_src=lh_arrImg[i].src;
                    //Xet xem hinh nay co thuoc tinh a hay khong
                    if(lh_arrImg[i].parentNode.tagName.toLowerCase()=="a"){
                        lh_showPopupA[j]=1;
                        var lh_href=lh_arrImg[i].parentNode.href;
                        //
                        lh_realA[j]=lh_href;
                        //Xu ly lay ra src cua hinh
                        var findStr='?fileName=';
                        var findPos=lh_href.indexOf(findStr)+findStr.length;
                        var temp=lh_href.substring(findPos);
                        findStr="'";
                        findPos=temp.indexOf(findStr);
                        var lh_url=temp.substring(0,findPos);
                        //Cho src cua hinh lay duoc vao danh sach
                        lh_realImg[j]=lh_url;
                        j++;
                    }else{
                        lh_showPopupA[j]=0;
                        var mysrc23032010=lh_src.substring(0,lh_src.indexOf('/thumb'));
                        mysrc23032010+=lh_src.substring(lh_src.indexOf('/thumb')+6);
                        mysrc23032010=mysrc23032010.substring(lh_src.indexOf(jsPathPrefix+'upload/'))
                        lh_realA[j]=lh_href="javascript:showPopup('image_viewer.aspx?fileName="+mysrc23032010+"', 217,261)";
                        lh_realImg[j]=mysrc23032010;
                        j++;
                    }
                    //
                    lh_result+='<div class="panel">';
                    lh_result+= '<a href="javascript:lh_slide('+(j-1)+')">';
                    lh_result+='<img src="'+lh_src+'" width="'+lh_width+'" height="'+lh_height+'" border="0"';
                    lh_result+= lh_useClass ? ('class="'+lh_class+'"') : '';
                    lh_result+= lh_useStyle ? ('style="'+lh_style+'"') : '';
                    lh_result+='/>';
                    lh_result+= '</a>';
                    lh_result+= '</div>';
                 }
            }
            if(lh_realImg.length==0)
                return false;
            //Xu ly hinh chinh
            var lh_src=document.getElementById('lh_imgdetail_main').src;
            if (document.getElementById('lh_imgdetail_main').parentNode.tagName.toLowerCase()=="a"){
                //
                var lh_href=document.getElementById('lh_imgdetail_main').parentNode.href;
                //
                lh_realA[j]=lh_href;
                //Xu ly lay ra src cua hinh
                var findStr='?fileName=';
                var findPos=lh_href.indexOf(findStr)+findStr.length;
                var temp=lh_href.substring(findPos);
                findStr="'";
                findPos=temp.indexOf(findStr);
                var lh_url=temp.substring(0,findPos);
                //Cho src cua hinh lay duoc vao danh sach
                lh_realImg[j]=lh_url;
                j++; 
                //Thay lai url cho hinh chinh
                document.getElementById('lh_imgdetail_main').parentNode.href='javascript:lh_slide('+(j-1)+')';
            }else{
                lh_showPopupA[j]=0;
                var mysrc23032010=lh_src.substring(0,lh_src.indexOf('/thumb'));
                mysrc23032010+=lh_src.substring(lh_src.indexOf('/thumb')+6);
                mysrc23032010=mysrc23032010.substring(lh_src.indexOf(jsPathPrefix+'upload/'))
                lh_realA[j]=lh_href="javascript:showPopup('image_viewer.aspx?fileName="+mysrc23032010+"', 217,261)";
                lh_realImg[j]=mysrc23032010;
                j++;
                //Thay lai url cho hinh chinh
                document.getElementById('lh_imgdetail_main').cursor="pointer";
                document.getElementById('lh_imgdetail_main').onclick=set_main_img;
            }
            //
            lh_result+='<div class="panel">';
            lh_result+= '<a href="javascript:lh_slide('+(j-1)+')">';
            lh_result+='<img src="'+lh_src+'" width="'+lh_width+'" height="'+lh_height+'" border="0"';
            lh_result+= lh_useClass ? ('class="'+lh_class+'"') : '';
            lh_result+= lh_useStyle ? ('style="'+lh_style+'"') : '';
            lh_result+='/>';
            lh_result+= '</a>';
            lh_result+= '</div>';
            
            
            //Cap nhat vao phan hien thi chi tiet
            document.getElementById('lh_imgdetail_show').innerHTML=lh_result;
            return true;
        }
        function set_main_img(){
            lh_slide(lh_showPopupA.length-1);
        }
function countCharacter(origString, characterToCount){
    characterToCount=characterToCount.toLowerCase();
    var myArray = origString.toLowerCase().split('');
    var counter=0;
    for (i=0;i<myArray.length;i++)
    {
        if (myArray[i] == characterToCount)
        {
            counter++;
        }
    }
    return counter;
}




