﻿function ADInfoList()
{
	this.ADCode=new Array();
	this.ADUrl=new Array();
	this.ADMode=new Array();
	this.ADType=new Array();
	this.ADText=new Array();
	this.ADWidth=new Array();
	this.ADHeight=new Array();
}

// Thêm vào Favorites
function AddFav()
{
	window.external.addFavorite(window.document.location.href,document.title);
}

function Trim(strValue)
{
	return strValue.replace(/^\s*|\s*$/g,"");
}

function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue);
}

function GetCookie(sName)
{
  var aCookie = document.cookie.split(";");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == Trim(aCrumb[0])) 
    {
    	return unescape(aCrumb[1]);
    }
  }

  return null;
}

function Request(strName)
{
	var strHref = window.document.location.href;
	var intPos = strHref.indexOf("?");
	var strRight = strHref.substr(intPos + 1);

	var arrTmp = strRight.split("&");
	for(var i = 0; i < arrTmp.length; i++)
	{
		var arrTemp = arrTmp[i].split("=");

		if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
	}
	return "";
}

function SelectAll(form) {
	for (var i=0; i < document.forms[0].elements.length; i++)
		document.forms[0].elements[i].checked = !document.forms[0].elements[i].checked;
}

function bbimg(o){
	var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
	return false;
}

//Kích vào ảnh trong trang nội dung để mở cửa sổ mới
function openImgSrc(obj)
{
	//return;	//Nếu không muốn mở cửa sổ mới, bỏ dấu '//' ở trước dòng này
	if (obj.resized==1 && obj.parentElement.tagName!="A")
	{
		window.open(obj.src);
	}
}

function changeImgSize(obj)
{
	if(obj.width>screen.width-400) obj.style.width=screen.width-400;
}

function getByID(StringID)
{
	try
	{
		return document.getElementById(StringID);
	}
	catch (e){}	
}

// hàm tạo ảnh xem trước theo tỷ lệ
//Các tham số là Đường dẫn ảnh, Độ rộng hiển thị, Độ cao hiển thị, Tự động co dãn theo kích thước, Chú thích thay ảnh, Kiểu ảnh, CSS của ảnh
function ShowPreviewImg(imageSrc,dispWidth,dispHeight,useAutoSize,Tips,Align,Style,CssClass)
{
	//By HongHaSoft.Com
	var newWidth = dispWidth;
	var newHeight = dispHeight;
	var sourceWidth;	// source image width
	var sourceHeight;	// source image height
	useAutoSize = eval(useAutoSize.toLowerCase());
	var outString = '<IMG Src="{Src}" Width="{Width}" Height="{Height}" Border="0"';
	// Tự động co dãn theo kích thước
	if (useAutoSize)
	{
		imageOriginal = new Image() ;
		imageOriginal.src = imageSrc ;
		sourceWidth = imageOriginal.width;
		sourceHeight = imageOriginal.height;
		newHeight = ((newWidth / 4) * 3);
		if (sourceWidth == 0)
		{
			sourceWidth = newWidth;
			sourceHeight = newHeight;
		}
		if (( Math.round(sourceWidth) / Math.round(sourceHeight)) >= 1.3333333333333333)
		{
			newHeight = ((sourceHeight * newWidth) / sourceWidth); 
		}
		else
		{
			newWidth = ((sourceWidth * newHeight) / sourceHeight); 
		}
	}
	outString = outString.replace("{Src}",imageSrc);
	outString = outString.replace("{Width}",newWidth);
	outString = outString.replace("{Height}",newHeight);
	if (Tips != null)
	{
		outString += " Alt='" + Tips + "'";
	}
	if (Style != null)
	{
		outString += " Style=" + Style;
	}
	if (CssClass != null)
	{
		outString += " Class=" + CssClass;
	}
	if (Align != null)
	{
		outString += " Align=" + Align;
	}
	
	outString += ">";
	document.write(outString);
}

// Phần hiển thị menu động
//By VcmsSite.Com
function ShowNavMenu(ID,NavMenuCount)
{
	for ( var i = 0; i < NavMenuCount; i++ )
	{
		try
		{
			document.all['NavMenu_' + i].style.display = "none";
			if ( i == ID)
			{
				document.all['NavMenu_' + ID].style.display = "inline";
			}
		}
		catch(e){}
	}
}


// Nhóm hàm khu vực quảng cáo
//--------------------------------
// Các định nghĩa liên quan đến quảng cáo như sau
//ADList_0.ADCode[k] = Mã quảng cáo
//ADList_0.ADUrl[k]  = Liên kết của quảng cáo
//ADList_0.ADMode[k] = Dạng quảng cáo (Ảnh=1,FLASH=2,HTML=3)
//ADList_0.ADType[k] = Loại quảng cáo
//ADList_0.ADText[k] = Mô tả quảng cáo
//ADList_0.ADWidth[k] = Độ rộng của quảng cáo
//ADList_0.ADHeight[k] = Độ cao của quảng cáo
// hàm show quảng cáo
function ShowAD(ADList)
{
	var thisads = ADList.ADType.length;
	var now = new Date()
	var sec = now.getSeconds()
	var k = sec % thisads;
	switch(ADList.ADMode[k]){
		case "1":	//Quảng cáo ảnh
			document.write('<div align="center">');
			document.write('<a href=\"' + ADList.ADUrl[k] + '\" target=\"_blank\">');
			document.write('<img src=\"' + ADList.ADCode[k] + '\" width=')
			document.write(ADList.ADWidth[k] + ' height=' + ADList.ADHeight[k] + ' ');
			document.write('alt=\"' + ADList.ADText[k] + '\" border=0 valign=\"absmiddle\"></a>');
			document.write('</div>');
			break;
		case "2":	//Quảng cáo FLASH
			document.write('<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=\"'+ADList.ADWidth[k]+'"\" height=\"'+ADList.ADHeight[k]+'\"><PARAM NAME=movie VALUE=\"'+ADList.ADCode[k]+'\"><PARAM NAME=quality VALUE=high><embed src=\"'+ADList.ADCode[k]+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+ADList.ADWidth[k]+'\" height=\"'+ADList.ADHeight[k]+'\">'+ADList.ADCode[k]+'</embed></OBJECT>');
			break;
		case "3":	// Quảng cáo HTML
			document.write(ADList.ADCode[k]);
			break;
		case "4":	//Quảng cáo trôi
			document.write('<a href="' + ADList.ADUrl[k] + '" target="_blank" onmouseover=stopme("MoveAD"); onmouseout=movechip("MoveAD");>');
			document.write('<img src="' + ADList.ADCode[k] + '" border="0" width="'+ ADList.ADWidth[k] + '" height="' + ADList.ADHeight[k] + '" alt=' + ADList.ADText[k] + '></a>');
			break;
	}
}

// kiểm tra tham số người dùng
function CheckLogin(form){
	if (form.UserName.value==""){
		alert("Bạn hãy nhập người dùng");
		form.UserName.focus();
		return false;
	}
	if (form.PassWord.value==""){
		alert("Bạn hãy nhập mật khẩu");
		form.PassWord.focus();
		return false;
	}
}

function openWindow(url, width, height){
	var Win = window.open(url,"openWin",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=yes' );
}

// phần quảng cáo trôi
var brOK=false;
var mie=false;
var vmin=2;
var vmax=5;
var vr=3;
var timer1;
var MoveAD;

function movechip(chipname){
	if(brOK){
		eval("chip="+chipname);
		if(!mie){
			pageX=window.pageXOffset;
			pageW=window.innerWidth;
			pageY=window.pageYOffset;
			pageH=window.innerHeight;
		}else{
			pageX=window.document.body.scrollLeft;
			pageW=window.document.body.offsetWidth-8;
			pageY=window.document.body.scrollTop;
			pageH=window.document.body.offsetHeight;
		}
		chip.xx=chip.xx+chip.vx;
		chip.yy=chip.yy+chip.vy;
		chip.vx+=vr*(Math.random()-0.5);
		chip.vy+=vr*(Math.random()-0.5);
		if(chip.vx>(vmax+vmin))  chip.vx=(vmax+vmin)*2-chip.vx;
		if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
		if(chip.vy>(vmax+vmin))  chip.vy=(vmax+vmin)*2-chip.vy;
		if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;
		if(chip.xx<=pageX){
			chip.xx=pageX;
			chip.vx=vmin+vmax*Math.random();
		}
		if(chip.xx>=pageX+pageW-chip.w){
			chip.xx=pageX+pageW-chip.w;
			chip.vx=-vmin-vmax*Math.random();
		}
		if(chip.xx>=680){
			chip.xx=chip.xx-20;
			chip.vx=-vmin-vmax*Math.random();
		}
		if(chip.yy<=pageY){
			chip.yy=pageY;
			chip.vy=vmin+vmax*Math.random();
		}
		if(chip.yy>=pageY+pageH-chip.h){
			chip.yy=pageY+pageH-chip.h;
			chip.vy=-vmin-vmax*Math.random();
		}
		if(!mie){
			eval('document.'+chip.named+'.top ='+chip.yy);
			eval('document.'+chip.named+'.left='+chip.xx);
		}else{
			eval('document.all.'+chip.named+'.style.pixelLeft='+chip.xx);
			eval('document.all.'+chip.named+'.style.pixelTop ='+chip.yy);
		}
		chip.timer1=setTimeout("movechip('"+chip.named+"')",80);
	}
}

function stopme(chipname){
	if(brOK){
		eval("chip="+chipname);
		if(chip.timer1!=null){
			clearTimeout(chip.timer1)
		}
	}
}

function MoveAD(){
	if(navigator.appName.indexOf("Internet Explorer")!=-1){
		if(parseInt(navigator.appVersion.substring(0,1))>=4) brOK=navigator.javaEnabled();mie=true;
	}
	if(navigator.appName.indexOf("Netscape")!=-1){
		if(parseInt(navigator.appVersion.substring(0,1))>=4) brOK=navigator.javaEnabled();
	}
	MoveAD.named="MoveAD";
	MoveAD.vx=vmin+vmax*Math.random();
	MoveAD.vy=vmin+vmax*Math.random();
	MoveAD.w=1;
	MoveAD.h=1;
	MoveAD.xx=0;
	MoveAD.yy=0;
	MoveAD.timer1=null;
	movechip("MoveAD");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}