/* ------------------------------------------------------------------------------------
	WEB++ - The System for Web Content Management, Online Community & E-Commerce
	
	Copyright(c) 2003-2004 by Hanoi Software JSC. All Rights Reserved.

	System Services - Java Script Library for Client

	Created: Jul-20, 2003 by Quynh Nguyen
------------------------------------------------------------------------------------ */

// Do nothing
function doNothing(){window.status='';}

// Open popup window
function doOpenLinkToPopupWindow(){
	var url = arguments[0]||'/';
	var width = arguments[1]||400;
	var height = arguments[2]||400;
	var resizable = arguments[3]||'yes';
	var scrollbars = arguments[3]||'yes';
	var left = ((document.body.clientWidth - width) / 2) + window.screenLeft;
	var top = (((document.body.clientHeight - height) / 2)) + window.screenTop;
	window.open(url, '', 'width='+width+',height='+height+',left='+left+',top='+top+',resizable='+resizable+',scrollbars='+scrollbars);
}

// Open banner
function doOpenWebPlusBanner(id,isGroup){
	if(isGroup==1)
	{
		eval("var current=crt" + id);
		eval("var itemID=bnrID" + id + current);
	}
	else
		var itemID=id;
	
	frmWebPlusHiddenForm.txtID.value = itemID;
	frmWebPlusHiddenForm.txtLocation.value = location.href;
	frmWebPlusHiddenForm.action = '../banner.asp?subobject=item&action=open';
	frmWebPlusHiddenForm.submit();
}

// Change banner (for web banner or special banner)
function doChangeWebPlusBanner(id,max){
	eval("var current=crt" + id);
	if(current<max)
	{
		eval("crt" + id + "++");
		current++;
	}
	else
	{
		eval("crt" + id + "=0");
		current=0;
	}	
	eval("var nextImg = bnr" + id + current);
	document.images['imgWebPlus'+id].src = nextImg.src;
}

// Open web link
function doOpenWebPlusLink(url){	
	window.open(url); 
}

// Information for updating hits counter
function doGetWebPlusCounterInfo(){
	// Browser
	var browser = '';
	if(navigator.appName=='Netscape')
		browser = 'NS';
	if(navigator.appName=='Microsoft Internet Explorer')
		browser = 'MSIE';
	if(navigator.appVersion.indexOf('MSIE 3')>0)
		browser = 'MSIE';
	// Screen resolution
	var screenWidth = screen.width;
	var screenHeight = screen.height; 
	// Color depth
	var colorDepth = 256;
	if (navigator.appName != 'Netscape')
		colorDepth = screen.colorDepth;
	else 
		colorDepth = screen.pixelDepth;
	// Referer
	var referer = '' + escape(document.referrer);
	// Counter URL
	return '&w=' + screenWidth + '&h=' + screenHeight + '&c=' + colorDepth + '&b=' + browser + '&r=' + referer
}

// Return the string determines full date of client (International)
function getFullDate(){
	var now = new Date();
	var month = "";
	var day = "";
	var first_date_num="";

  if (now.getDate() < 10)
		first_date_num="0";
	else
		first_date_num="";
			
	switch (now.getDay()){
		case 0: day="Sunday";break;
		case 1: day="Monday";break;
		case 2: day="Tuesday";break;
		case 3: day="Wednesday";break;
		case 4: day="Thursday";break;
		case 5: day="Friday";break;
		case 6: day="Saturday";break;
	}
	
	switch (now.getMonth()){
		case  0: month="January";break;
		case  1: month="February";break;
		case  2: month="March";break;
		case  3: month="April";break;
		case  4: month="May";break;
		case  5: month="June";break;
		case  6: month="July";break;
		case  7: month="August";break;
		case  8: month="September";break;
		case  9: month="October";break;
		case 10: month="November";break;
		case 11: month="December";break;
	}
	
	return day + ", " + month + " " + first_date_num + now.getDate() + ", " + now.getFullYear();
}

// Return the string determines full date of client (Vietnamese)
function getFullDateInVietnamese(){
	var now = new Date();
	var month = "";
	var day = "";
	var first_date_num="";

  if (now.getDate() < 10)
  	first_date_num="0";
	else
		first_date_num="";
			
	switch (now.getDay()){
		case 0: day="Ch&#7911; nh&#7853;t";break;
		case 1: day="Th&#7913; hai";break;
		case 2: day="Th&#7913; ba";break;
		case 3: day="Th&#7913; t&#432;";break;
		case 4: day="Th&#7913; n&#259;m";break;
		case 5: day="Th&#7913; s&#225;u";break;
		case 6: day="Th&#7913; b&#7843;y";break;
	}
	
	return day + ", ng&agrave;y " + first_date_num + now.getDate() + " / " + (now.getMonth()+1) + " / " + now.getFullYear();
}

// Return the string determines full date & time of client (GMT)
function getFullDateTimeInGMT(){
	var now = new Date();
	var month = "";
	var day = "";
	var date = now.getDate();

	if ((date==1)||(date==21)||(date==31)) {date = date + "st"};
	if ((date==2)||(date==22)) {date = date + "nd"};
	if ((date==3)||(date==23)) {date = date + "rd"};
			
	switch (now.getDay()){
		case 0: day="Sunday";break;
		case 1: day="Monday";break;
		case 2: day="Tuesday";break;
		case 3: day="Wednesday";break;
		case 4: day="Thursday";break;
		case 5: day="Friday";break;
		case 6: day="Saturday";break;
	}
	
	switch (now.getMonth()){
		case  0: month="January";break;
		case  1: month="February";break;
		case  2: month="March";break;
		case  3: month="April";break;
		case  4: month="May";break;
		case  5: month="June";break;
		case  6: month="July";break;
		case  7: month="August";break;
		case  8: month="September";break;
		case  9: month="October";break;
		case 10: month="November";break;
		case 11: month="December";break;
	}

	var time = new String(now.getUTCHours());
	if (time.length < 2){ time = "0"+ time};
		
	var minute = new String(now.getMinutes());
	if (minute.length < 2) {minute = "0"+ minute};
	
	time = time  + ":" + minute + " (GMT)"; 
	
	return day + ", " + date + " " + month + " " + now.getFullYear() + " " + time;
}

// Show scroll banner at the left/right of a webpage
function doShowScrollBanner(divId, type)
{
	// width of the scroll baner (pixels)
	var bannerWidth = arguments[2]||130;

	// computing the starting positions
	var startX, startY = 0;
	
	// hide banner if screen width is less than 980 pixels	
	if(document.body.clientWidth < 980)
		startX = -115;
	else
	{
		if (type==0)		// scroll left
			startX = 5;
		else						// scroll right
			startX = document.body.clientWidth - bannerWidth;
	}

	// define the method for displaying/scrolling the banner
	window.stayFloat = function(ftlObj, type, bannerWidth)
	{
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		
		var startX, startY;
		if(type==0)		// scroll left
			startX = 1;
		else
			startX = document.body.clientWidth - bannerWidth - 2;
		
		// hide banner if screen width is less than 980 pixels	
		if (document.body.clientWidth < 980)
			ftlObj.style.display = 'none';

		else		// display the banner and re-computing the positions
		{
			// display the banner
			ftlObj.style.display = '';			
			
			// computing offset
			if (document.documentElement && document.documentElement.scrollTop)
				var pY = ns ? pageYOffset : document.documentElement.scrollTop;
				
			else if (document.body)
				var pY = ns ? pageYOffset : document.body.scrollTop;

			// computing top position
			if (document.body.scrollTop > 50)
				startY = 3;
			else 
				startY = 50;

			// re-positions		
			ftlObj.y += (pY + startY - ftlObj.y)/8;
			ftlObj.style.left = startX;
			ftlObj.style.top = ftlObj.y;
		}
		
		// for smoothly
		setTimeout(function(){stayFloat(ftlObj,type,bannerWidth)}, 30);
	}

	// get the scroll banner by Id
	var ftlObj = document.getElementById ? document.getElementById(divId) : document.all ? d.all[divId] : document.layers[divId];
	if(!ftlObj)
		return;
		
	// set positions and scrolling
	ftlObj.x = startX;
	ftlObj.y = startY;
	stayFloat(ftlObj, type, bannerWidth);
}

// show action menu for a portlet
function __showLayer(parent, id, position, offsetLeft, offsetTop){

	// check layer existing first
	var obj = document.getElementById(id);
	if(!obj)
		return;
		
	// computing positions
	var nTop = 0, nLeft = 0;
	var objParent = parent;	
	while (objParent.tagName!="BODY")
	{
		nTop = nTop + objParent.offsetTop;
		nLeft = nLeft + objParent.offsetLeft;
		objParent = objParent.offsetParent;
	}
	
	// computing offset for the positions
	var nWidth = 0, nHeight = 0;
	switch(position)
	{
		case "left":
			nWidth = 0 - parent.offsetWidth;
			break;

		case "right":
			nWidth = parent.offsetWidth;
			break;
		break;

		case "top":
			nHeight = 0 - parent.offsetHeight;
		break;

		case "under":
			nHeight = parent.offsetHeight;
			break;

		default:
			break;
	}
	
	// re-position and show the layer
	obj.style.top = nTop + nHeight + offsetTop;
	obj.style.left = nLeft + nWidth + offsetLeft;
	obj.style.display = "";
	obj.style.visibility = "visible";
}

// hide a layer by Id on a webpage
function __hideLayer(id){
	var obj = document.getElementById(id);
	if(!obj)
		return;
	obj.style.visibility = "hidden";
}

// show an inline element in the HTML document (by Id)
function __show(){
	var id = arguments[0]||'';
	if(id=='') return;
	var objElement = document.getElementById(id);
	if(!objElement) return;
	if(!objElement.style) return;
	var left = arguments[1]||-1;
	var top = arguments[2]||-1;
	var offsetLeft = arguments[3]||0;
	var offsetTop = arguments[4]||0;
	objElement.style.display = "";
	objElement.style.visibility = "visible";
	if(left>=0) objElement.style.left = left + offsetLeft;
	if(top>=0) objElement.style.top = top + offsetTop;
}

// hide an inline element in the HTML document (by Id)
function __hide(id){
	var objElement = document.getElementById(id);
	if(!objElement) return;
	if(!objElement.style) return;
	objElement.style.display = "none";
	objElement.style.visibility = "hidden";
}

// show an element itself
function __showMe(obj){
	obj.style.visibility = "visible";
}

// hide an element itself
function __hideMe(obj){
	obj.style.visibility = "hidden";
}
/*-----------------------------------------------------------------------------------*/


/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+2)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-2+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-2+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

// Slide from right to left 
/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescrollerLeftRight(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescrollerLeftRight.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivleft=parseInt(pausescrollerLeftRight.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivleft*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescrollerLeftRight.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.left)>(this.visibledivleft+2)){
this.visiblediv.style.left=parseInt(this.visiblediv.style.left)-2+"px"
this.hiddendiv.style.left=parseInt(this.hiddendiv.style.left)-2+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescrollerLeftRight.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescrollerLeftRight.prototype.getinline=function(div1, div2){
div1.style.left=this.visibledivleft+"px"
div2.style.left=Math.max(div1.parentNode.offsetWidth, div1.offsetWidth)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescrollerLeftRight.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescrollerLeftRight.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

