// ----------------------------------------------------
// open new image
// ----------------------------------------------------

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}


// ----------------------------------------------------
// show Dialog
// ----------------------------------------------------
function showDialog(vLink, vWidth, vHeight)
{
	return showWindow(vLink, false, true, true, false, false, false, true, true, vWidth, vHeight, 0, 0);
}

function showWindow(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vWidth, vHeight, vTop, vLeft)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;
	
	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');
	
	if (vCentered)
	{
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}
	else
	{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}
	
	open(sLink, '_blank', winDef);
	
	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

// ----------------------------------------------------
// popup windows
// ----------------------------------------------------
function poptastic(url,title,width,height)
{
	window.open(url,title,'height='+height+',width='+width+',left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=yes');
}

// ----------------------------------------------------
// ads rotate image
// Author: dungpt
// Contact: dungpt@clicknao.com
// ----------------------------------------------------
function DisRotateImg(strImgs,arImgs,numTimeDelay)
{
	
	var arImgsLength = eval(strImgs+'.length');
	var u=0;
	for(var i=0;i<arImgsLength;i++)
	{
		if(u+1<arImgsLength) u = i+1;
		if(eval(strImgs+"[i][5]")=='true')
		{
			if(eval(strImgs+"[i][2]")) var w = "width='"+eval(strImgs+"[i][2]")+"'"; else var w = '';
			if(eval(strImgs+"[i][3]")) var h = "height='"+eval(strImgs+"[i][3]")+"'"; else var h = '';
			var dis = "<a href='"+eval(strImgs+"[i][1]")+"' id='a_"+strImgs+"' target='"+eval(strImgs+"[i][4]")+"'><img src='"+eval(strImgs+"[i][0]")+"' "+w+" "+h+"  title='1xxxxx' id='i_"+strImgs+"' border=0></a>";
			document.write(dis);
			arImgs[i][5]='false';
			arImgs[u][5]='true';
			setInterval('ChangeBanner('+strImgs+',\''+strImgs+'\')', numTimeDelay);
			break;
		}		
	}
}
function ChangeBanner(arImgs,narImgs)
{	
	
	var u=0;
	for(var i=0;i<arImgs.length;i++)
	{
		if(i+1<arImgs.length) u = i+1; else u = 0;
		if(arImgs[i][5]=='true')
		{
			document.getElementById("a_"+narImgs).href= arImgs[i][1];
			document.getElementById("a_"+narImgs).target= arImgs[i][4];
			document.getElementById("i_"+narImgs).src = arImgs[i][0];
			if(arImgs[i][2]) { document.getElementById("i_"+narImgs).width = arImgs[i][2]; }
			if(arImgs[i][3]) { document.getElementById("i_"+narImgs).height = arImgs[i][3]; }	
			
			eval("this."+narImgs+"["+i+"][5]='false'");
			eval("this."+narImgs+"["+u+"][5]='true'");
			break;
		}
	}
}


// ----------------------------------------------------
// ads floating image
// Author: dungpt
// Contact: dungpt@clicknao.com
// ----------------------------------------------------
function ShowFloatBannerLeft(i,l,t)
{
	if (document.body.clientWidth > 785) { 
		var startX = 0;
		startY = t;
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		var pY = ns ? pageYOffset : document.documentElement.scrollTop;
		
		window.stayTopLeft=function()
		{
			var pY = ns ? pageYOffset : document.documentElement.scrollTop;
			
			ftlObjl.y += (pY + startY - ftlObjl.y)/8;
			
			ftlObjl.sP(ftlObjl.x, ftlObjl.y);
			
			setTimeout("stayTopLeft()", 10);
		};
		
		ftlObjl = ml(i,startX,startY);
		stayTopLeft();
	} else document.getElementById(i).style.display = 'none';
}

function ShowFloatBannerRight(i,r,t)
{
	if (document.body.clientWidth > 785) { 
		var startX = document.documentElement.offsetWidth-r;
		startY = t;
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		
		
		window.stayTopRight=function()
		{
			var pY = ns ? pageYOffset : document.documentElement.scrollTop;
			
			ftlObjr.y += (pY + startY - ftlObjr.y)/8;
			
			ftlObjr.sP(ftlObjr.x, ftlObjr.y);
			
			setTimeout("stayTopRight()", 10);
		};
		
		ftlObjr = ml(i,startX,startY);
		stayTopRight();
	} else document.getElementById(i).style.display = 'none';
}


function ml(id,startX,startY)
{
	var el=document.getElementById?document.getElementById(id):document.all?document.all[id]:document.layers[id];
	
	if(document.layers) el.style=el;

	el.sP=function(x,y){
		this.style.left=x+'px';
		this.style.top=y+'px';
	};
	
	el.x = startX;

	el.y = startY;
	
	return el;
}

// width , top position
//ShowFloatBannerLeft('divStayTopLeft',267,100);
//ShowFloatBannerRight('divStayTopRight',267,100);




//--------------------------------
// Action Command ( with parameter )
// Author: dungpt
// Contact: dungpt@clicknao.com
//--------------------------------
var LoadStr = "<center><img src='images/loader.gif' /></center>";

//--------------------------------
// Transfering & Update message
// Author: dungpt
// Contact: dungpt@clicknao.com
//--------------------------------
function AjaxSGetData(url,pagename)
{
	$(document).ready(function(){
		$("#"+pagename).html(LoadStr);
		var CurrentURL = unescape(location.href);
		$.ajax({
		    url: url,
		    type: 'GET',
		    dataType: 'text',
		    timeout: 0,
		    error: function(){
		        alert('Error loading XML document');
		    },
		    success: function(xml){
		    	if(xml)
		    	{ $("#"+pagename).html(xml); }
		    	else { window.location.href = CurrentURL; }
		    }
		});
	});
}

function AjaxSGetData_R(url)
{
	$(document).ready(function(){
		$.ajax({
		    url: url,
		    type: 'GET',
		    dataType: 'text',
		    timeout: 0,
		    error: function(){
		        alert('Error loading XML document');
		    },
		    success: function(xml){
		    	if(xml)
		    	{ return xml; }
		    	else { return null; }
		    }
		});
	});
}

//--------------------------------
// AjaxTab
// Author: dungpt
// Contact: dungpt@clicknao.com
//--------------------------------
var AjaxTab = {
	init : function(a,b,c,d)
	{
		var TabIds = Array();
		var TabUrls = Array();
		var TabStyle = Array();
		var TabContentTitle = '';
		
		// tab urls assigning
		for(var i=0;i<b.length;i++)
		{
			TabUrls[i] = b[i];
		}
		
		// tab content title assign
		TabContentTitle = c; 
		
		// tab style
		for(var i=0;i<d.length;i++)
		{
			TabStyle[i] = d[i];
		}
			
		// tab id assigning
		for(var i=0;i<a.length;i++)
		{
			TabIds[i] = a[i];
			document.getElementById(a[i]).onclick = function() {
				for(var i=0;i<TabIds.length;i++)
				{
					if(TabIds[i]==this.id)
					{
						if(document.getElementById('c_'+TabIds[i]).innerHTML=="")
						{
							AjaxSGetData(TabUrls[i],TabContentTitle);
							
							// caching
							AjaxSGetData(TabUrls[i],'c_'+TabIds[i]);
						} else { document.getElementById(TabContentTitle).innerHTML = document.getElementById('c_'+TabIds[i]).innerHTML; }
						
						// customize selected tab style
						document.getElementById(TabIds[i]).className = TabStyle[0];		
						
					} else {
						// customize unselected tab style
						document.getElementById(TabIds[i]).className = TabStyle[1];	
					}
				}
			};
			
			// create caching container
			var dix = document.createElement("div");
			dix.setAttribute("id", "c_"+a[i]);
			dix.style.display="none";			
			document.getElementById(TabIds[i]).appendChild(dix);
		}

	}
};	

// ----------------------------------------------------
// Blinking div
// Author: dungpt
// Contact: dungpt@clicknao.com
// ----------------------------------------------------
var BlinkDiv = {
	
	divObj : null,
	divdelay : 3000,
	divdata : Array(),
	divdataindex : 0,
	
	blinkstep : 30,
	blinkstepdelay : 40,
	fadecounter : null,
	startcolor : Array(255,255,255),
	endcolor : Array(55,83,137), 
	fadelinks : 1,

	init : function (a,b,c) 
	{
		// object data assigning
		this.divObj = a;
		this.divdata = b;
		this.divdelay = c;
		
		// blinking
		document.getElementById(this.divObj).style.color="rgb("+BlinkDiv.startcolor[0]+", "+BlinkDiv.startcolor[1]+", "+BlinkDiv.startcolor[2]+")";
		if (BlinkDiv.fadelinks) this.linkcolorchange(1);
		this.fade(1);

		// div data show
		document.getElementById(this.divObj).innerHTML = this.divdata[this.divdataindex];
		if(this.divdataindex<this.divdata.length-1) this.divdataindex++;
		else this.divdataindex=0;	
	},
	
	fade : function(step)
	{
		if(step<=BlinkDiv.blinkstep) {	
			document.getElementById(BlinkDiv.divObj).style.color=BlinkDiv.getstepcolor(step);
			if (BlinkDiv.fadelinks) BlinkDiv.linkcolorchange(step);
			step++;
			fadecounter=setTimeout("BlinkDiv.fade("+step+")",BlinkDiv.blinkstepdelay);
		}else{
			clearTimeout(fadecounter);
			document.getElementById(BlinkDiv.divObj).style.color="rgb("+BlinkDiv.endcolor[0]+", "+BlinkDiv.endcolor[1]+", "+BlinkDiv.endcolor[2]+")";
			setTimeout("BlinkDiv.init(BlinkDiv.divObj,BlinkDiv.divdata,BlinkDiv.divdelay)", BlinkDiv.divdelay);
		}   
	},
	
	linkcolorchange : function(step){
	  var obj=document.getElementById(BlinkDiv.divObj).getElementsByTagName("A");
	  if (obj.length>0){
	    for (i=0;i<obj.length;i++)
	      obj[i].style.color=BlinkDiv.getstepcolor(step);
	  }
	},
	
	getstepcolor : function(step) {
	  var diff;
	  var newcolor=new Array(3);
	  for(var i=0;i<3;i++) {
	    diff = (BlinkDiv.startcolor[i]-BlinkDiv.endcolor[i]);
	    if(diff > 0) {
	      newcolor[i] = BlinkDiv.startcolor[i]-(Math.round((diff/BlinkDiv.blinkstep))*step);
	    } else {
	      newcolor[i] = BlinkDiv.startcolor[i]+(Math.round((Math.abs(diff)/BlinkDiv.blinkstep))*step);
	    }
	  }
	  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
	}
};


// ----------------------------------------------------
// Misc
// ----------------------------------------------------
function showWeather()
{
	t = (screen.height - 150)/2;
	l = (screen.width - 133)/2;
	window.open("http://www.cand.com.vn/news/WeatherInfoP.aspx","my_new_window","scrollbars=no, resizable=no, width=133, height=150, top=" + t + ", left=" + t);
}

function showGoldPrice()
{
	t = (screen.height - 140)/2;
	l = (screen.width - 134)/2;	
	window.open("http://www.cand.com.vn/news/GoldPriceP.aspx","my_new_window","scrollbars=no, resizable=no, width=134, height=140, top=" + t + ", left=" + t);
}

function showMoneyRate()
{
	t = (screen.height - 195)/2;
	l = (screen.width - 134)/2;		
	window.open("http://www.cand.com.vn/news/MoneyRateP.aspx","my_new_window","scrollbars=no, resizable=no, width=134, height=195, top=" + t + ", left=" + t);
}

function showStock()
{		
	t = (screen.height - 590)/2;
	l = (screen.width - 800)/2;		
	myWin = open("http://www.bsc.com.vn/OP/OP.htm", "displayWindow", "width=800,height=590,status=no,toolbar=no,menubar=no, top=" + t + ", left=" + t);
}

function showInfo(zonename)
{
	t = (screen.height - 350)/2;
	l = (screen.width - 450)/2;		
	window.open("http://www.cand.com.vn/news/BigInfoP.aspx?ZURL=" + zonename,"my_new_window","scrollbars=yes, resizable=no, width=450, height=350, top=" + t + ", left=" + t);
}

function RowOn(Row,c)
{
  Row.className = c;
  Row.style.cursor = "pointer";
}
function RowOff(Row,c)
{
  Row.className = c;
}
