﻿function writeTime(ctlName, language)
{
	var mydate;
	
	mydate = new Date();
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour
	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	
	var second=mydate.getSeconds()
	if (second < 10)
		second = "0" + second
	
	var dayarray
	if (language=="vi-VN")
		dayarray =new Array("Chủ Nhật","Thứ Hai","Thứ Ba","Thứ Tư","Thứ Năm","Thứ Sáu","Thứ Bảy")
	else
		dayarray =new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
		
	document.getElementById(ctlName).value = dayarray[dayw]+", "+day+"/"+month+"/"+year+" "+hour+":"+minute+":"+second;	

	setTimeout("writeTime('"+ctlName+"','"+language+"')",1000);
}

function formatTime(n)
{
    var st = "";
    
    if(parseInt(n/3600,0) < 10)
        st = "0" + parseInt(n/3600,0) + ":";
    else    
        st = "" + parseInt(n/3600,0) + ":";
    
    if(parseInt((n%3600)/60,0) < 10)
        st += "0" + parseInt((n%3600)/60,0) + ":";
    else    
        st += "" + parseInt((n%3600)/60,0) + ":";
            
    if(parseInt((n%3600)%60,0) < 10)
        st += "0" + parseInt((n%3600)%60,0);
    else    
        st += "" + parseInt((n%3600)%60,0);
                
    return st;
}

function tabOver(e)
{
	if (e.className=='HomeTabStrip')
		e.className='HomeTabStripHover';
	else
		e.className='HomeTabStripHover1';
}
function tabOut(e)
{
	if (e.className=='HomeTabStripHover')
		e.className='HomeTabStrip';
	else
		e.className='HomeTabStrip1';
}

function menuItemOver(e)
{
	e.className='HomeMenuItem2Hover';
}
function menuItemOut(e)
{
	e.className='HomeMenuItem2';
}

function subMenuItemOver(e)
{
	e.className='HomeMenuItem3Hover';
}
function subMenuItemOut(e)
{
	e.className='HomeMenuItem3';
}

/*function showDialog(url)
{
	window.showModalDialog(url,window,"dialogWidth:500px; dialogHeight:400px; center:yes");
}*/


function showSendToFriendDialog(url)
{
	return showDialog(url,450,260);
}

function showDialog(url, width, height)
{
	return showWindow(url, false, false, false, false, false, false, true, true, width, height, 0, 0);
}

function showWindow(url, isStatus, isResizeable, isScrollbars, isToolbar, isLocation, isFullscreen, isTitlebar, isCentered, width, height, top, left)
{
	if (isCentered)
	{
		top = (screen.height - height) / 2;
		left = (screen.width - width) / 2;
	}

	open(url, '_blank', '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 SetMenu()
{
        var href = window.location.href;    
                                 
        for(i=70;i>0;i--)
        {
            st="";
            if(i < 10)
                st= "0" + i;
            else
                st = i;    
            MenuLink = document.getElementById("Menu" + st);            
            if(MenuLink != null)
            {
                if((MenuLink.href == "http://"+document.domain + "/") || (MenuLink.href == "http://wwww." + document.domain + "/") || (MenuLink.href == "http://"+document.domain + "/en/") || (MenuLink.href == "http://wwww." + document.domain + "/en/"))    
                {
                    if((href == "http://"+document.domain + "/") || (href == "http://wwww." + document.domain + "/") || (href == "http://"+document.domain + "/en/") || (href == "http://wwww." + document.domain + "/en/"))    
                        document.getElementById("Menu" + st).className = "current";
                }
                else if (href.indexOf(MenuLink.href) >= 0)
                {
                    document.getElementById("Menu" + st).className = "current";
                }
            }
        }
}    
function URLEncode (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return escape(utftext);
}
function replacevn(value){
    var str = value;   
    str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
    str= str.replace(/À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẳ/g,"A");
    str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
    str= str.replace(/È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ/g,"E");
    str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
    str= str.replace(/Ì|Í|Ị|Ỉ|Ĩ/g,"I");
    str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
    str= str.replace(/Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ/g,"O");
    str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
    str= str.replace(/Ù|Ú|Ụ|Ử|Ư\Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ/g,"U");
    str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
    str= str.replace(/Ỳ|Ý|Ỵ|Ỷ|Ỹ/g,"Y");
    str= str.replace(/đ/g,"d");
    str= str.replace(/Đ/g,"D");
    str= str.replace(/@|\$|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\'| |\"|\&|\#|\[|\]|~/g,"-");
    str= str.replace(/-+-/g,"-");
    str= str.replace(/^\-+|\-+$/g,"");
    str= str.replace("-","_");
    return str
}
 
function ChangeIndexVideoPlayer(path,imagesrc,index)
{   
    for(var i=1; i<6; i++)
    {
        if(i==index)
        {
           document.getElementById('media_' + i).style.fontWeight = 'bold'; 
        }
        else
        {
            try
            {
              document.getElementById('media_' + i).style.fontWeight = 'normal';  
            }
            catch(err){}           
        }
    }
    var link = "/home/videoplayer.aspx?path=" + path + "&imagesrc=" + imagesrc+ "&width=280";           
    ajax_loadContent('showVideoPlayer', link);
}

function ChangeTopUsual(curr, value)
{
    for(i=1;i<5;i++)
    {
        try
        {
            document.getElementById("sel_top_" + i).style.display="none";
            document.getElementById("top_" + i).className="";
        }
        catch(err){} 
    }
    curr.className="current";
    document.getElementById(value).style.display="block";                    
}

$.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function(){

	$('a[href*=#mainBody]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
				return false;
			}
		}
	});

});