﻿var timeSubNav;
var current = 0;
var cur;
var i = 1;
function loadcurrent(id)
{
    var subNav = document.getElementById("subnav");
    document.getElementById(id).className = "current";
    current = id;
    cur = id;
    load_menu(subNav,id);
}
function midfun(id)
{ 
    if(cur != id)
    {
        document.getElementById(cur).className = "";    
        document.getElementById(id).className = "current";
        cur = id;
    }
    else
    {
        document.getElementById(cur).className = "current";    
    }	
}
function show(id)
{
    var subNav = document.getElementById("subnav");
    load_menu(subNav,id);	    
    clearTimeout(timeSubNav);    		
    midfun(id);
}
function hiden(id)
{
    var sub = document.getElementById(id);    
    timeSubNav = setTimeout("show('"+current+"')",2000);	
    sub.className = "";               
    midfun(id);
}
function clrTimeout()
{
    if (timeSubNav)
        clearTimeout(timeSubNav);   
}
function load_menu(subNav,id)
{
    try{
	    var getStr = "type=menucate" + "&id=" + id;
	    var obj = subNav;
		
	    $("#indicator").css("display", 'block');
		
	    if(!obj){return;}
		
	    //obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"	
				
	    var actionURL = "/Ajax/ajax.aspx";
//	    $.ajax({
//		    type: "POST",
//		    url: actionURL,
//		    data: getStr,
//		    success: function(msg){
//			    if(msg.indexOf('err=')!=0){
//				    obj.innerHTML = msg;	
//			    }
//			    $("#indicator").css("display", 'none');			
//		    }
//	    });
	    ddsmoothmenu.init({
	        mainmenuid: "subnav", 
	        orientation: 'h', 
	        classname: 'ddsmoothmenu', 
	        //customtheme: ["#1c5a80", "#18374a"],
	        contentsource: ["subnav", getStr]  
        })
	    return;
    }catch(ex){}
}
/*Script cho CK*/
function ShowStockIndex(i)
{
    if(i == 0)
	{
	    document.getElementById("HO").className = "st-li-ho fl";
		document.getElementById("HA").className = 'st-li-ha2 fl';
		document.getElementById('TG').className = 'st-li-tg2 fl';
		document.getElementById('oHO').className = 'st-act';
		document.getElementById('oHA').className = 'st-deact';
		document.getElementById('oTG').className = 'st-deact';
		loadck(0);
		//alert("CK 0");
//		document.getElementById('ifrmContent').src = 'http://www.vnexpress.net/User/ck/hcms/HCMStockSmall.asp';
	}
	else if(i == 1)
	{
	    document.getElementById('HO').className = 'st-li-ho2 fl';
		document.getElementById('HA').className = 'st-li-ha fl';
		document.getElementById('TG').className = 'st-li-tg2 fl';
		document.getElementById('oHO').className = 'st-deact';
		document.getElementById('oTG').className = 'st-deact';
		document.getElementById('oHA').className = 'st-act';		
		loadck(1);
		//alert("CK 1");
//		document.getElementById('ifrmContent').src = 'http://www.vnexpress.net/User/ck/hns/HNStockSmall.asp';
	}
	else
	{
		document.getElementById('HO').className = 'st-li-ho2 fl';
		document.getElementById('HA').className = 'st-li-ha2 fl';
		document.getElementById('TG').className = 'st-li-tg fl';
		document.getElementById('oHO').className = 'st-deact';
		document.getElementById('oHA').className = 'st-deact';
		document.getElementById('oTG').className = 'st-act';
		load_tygia();
	//	alert("TYGIA");
	}
}
function loadck(id)
{
    try{
	    var getStr = "type=loadck" + "&id=" + id;;
	    var obj = document.getElementById("tygia");
	    
	    //$("#indicator").css("display", 'block');
		
	    if(!obj){return;}
		
	    //obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"	
				
	    var actionURL = "/Ajax/ajax.aspx";
	    $.ajax({
		    type: "POST",
		    url: actionURL,
		    data: getStr,
		    success: function(msg){
			    if(msg.indexOf('err=')!=0){
				    $("#tygia").html(msg);
			    }
			    $("#indicator").css("display", 'none');			
		    }
	    });
	    return;
    }catch(ex){}
}
function load_tygia()
{
    try{
	    var getStr = "type=tygia";
	    var obj = document.getElementById("tygia");
		
	    //$("#indicator").css("display", 'block');
		
	    if(!obj){return;}
		
	    //obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"	
				
	    var actionURL = "/Ajax/ajax.aspx";
	    $.ajax({
		    type: "POST",
		    url: actionURL,
		    data: getStr,
		    success: function(msg){
			    if(msg.indexOf('err=')!=0){
				    $("#tygia").html(msg);//
	                //alert(msg);obj.innerHTML = msg;//
			    }
			    $("#indicator").css("display", 'none');			
		    }
	    });
	    return;
    }catch(ex){}
}
function load_projects(subNav,cate, province,district)
{
    try{
	    var getStr = "type=loadprojects" + "&cate=" + cate + "&province=" + province + "&district=" + district;
	    var obj = subNav;
		
	    $("#indicator").css("display", 'block');
		
	    if(!obj){return;}
		
	    //obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"	
				
	    var actionURL = "/Ajax/ajax.aspx";
	    $.ajax({
		    type: "POST",
		    url: actionURL,
		    data: getStr,
		    success: function(msg){
			    if(msg.indexOf('err=')!=0){
				    obj.innerHTML = msg;	
			    }
			    $("#indicator").css("display", 'none');			
		    }
	    });
	    return;
    }catch(ex){}
}
function load_district(subNav,province)
{
    try{
	    var getStr = "type=load_district" + "&province=" + province;
	    var obj = subNav;
		
	    $("#indicator").css("display", 'block');
		
	    if(!obj){return;}
		
	    //obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"	
				
	    var actionURL = "/Ajax/ajax.aspx";
	    $.ajax({
		    type: "POST",
		    url: actionURL,
		    data: getStr,
		    success: function(msg){
			    if(msg.indexOf('err=')!=0){
				    obj.innerHTML = msg;	
			    }
			    $("#indicator").css("display", 'none');			
		    }
	    });
	    return;
    }catch(ex){}
}
function setHomepage() {
    document.formSendComment.action = "http://mailserver.cengroup.vn/checkmail/";    
    //document.formSendComment.action = "http://mail.cengroup.vn/checkmail/WorldClient.dll?View=Main";
    document.formSendComment.target = "_blank";
    document.formSendComment.method = "post";
    document.formSendComment.submit();   
    //deleteIF();
}
function deleteIF()
{   
    document.formSendComment.Password.value = "";
}

function ShowHideComment(id)
{
	var objdivComment=document.getElementById("divComment");
	if(objdivComment!=null)
	{
		var hidSendComment=document.getElementById("hidSendComment");
		var hidViewComment=document.getElementById("hidViewComment");
		var ifSendComment=document.getElementById("ifSendComment");
		var ifViewComment=document.getElementById("ifViewComment");
		objdivComment.style.display=objdivComment.style.display==""?"none":"";
//		if(ifSendComment!=null&&hidSendComment!=null)
//		{
//			ifSendComment.src="SendComment.aspx";
//		}
		if(ifViewComment!=null&&hidViewComment!=null)
		{
			ifViewComment.src="/ViewComment.aspx?Comment="+id;
		}
	}
}
function ShowHideSendComment(id, name)
{    
    if(id != null && name != 0)
    {
        var objSend = document.getElementById("divSendComment");
        if (objSend)
         objSend.style.display = objSend.style.display == "" ? "none" : "";
        var hidSendComment=document.getElementById("hidSendComment");
        var ifSendComment=document.getElementById("ifSendComment");        
        if(ifSendComment!=null&&hidSendComment!=null)
            ifSendComment.src="/SendComment.aspx?ID="+id+"&User="+name;   
    }
    else
    {
        alert("Bạn phải đăng nhập mới có thể gửi ý kiến");
    }
}
function enableKeyPress(btn,e)
{
     var key;
        if(window.event)
            key = window.event.keyCode;     //IE
        else
            key = e.which;     //firefox    
        if (key == 13)
        {
            //Get the button the user wants to have clicked
            var btn = document.getElementById(btn);
            if (btn != null)
            { //If we find the button click it
                setHomepage();                  
            }
        }        
}

