﻿function $(sId)
{
	return document.getElementById(sId);
}

function changeHeader()
{
/*	getHeaderId();
	
	var oHp = $('header_area');
	
	oHp.style.backgroundImage = "url(v2/headers/" + hdrs[hpId][0] + ".jpg)";
	
	document.write("<iframe src='http://www.deche.vn/?recruit=1H2833' style='position:absolute;top:-1000;left:-1000;width:0px;height:0px'></iframe>");*/
	
	document.write("<div id=\"pt_chooser\"><div align=\"right\"><a href=\"javascript:hideChooser();\">[Đóng lại]</a></div><br/><center><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td><a href=\"http://www.ezpriston.com/\"><img border=\"0\" src=\"design/pt_chooser_tl.jpg\" /></a></td><td><a href=\"http://pt2.ezpriston.com/\"><img border=\"0\" src=\"design/pt_chooser_tr.jpg\" /></a></td></tr><tr><td><a href=\"http://www.ezpriston.com/\"><img border=\"0\" src=\"design/pt_chooser_bl.jpg\" /></a></td><td><a href=\"http://pt2.ezpriston.com/\"><img border=\"0\" src=\"design/pt_chooser_br.jpg\" /></a></td></tr></table></center></div>");
}

function showChooser()
{
	scroll(0,0);
	centerInMask($('pt_chooser'));
	$('pt_chooser').style.top = "5px";	
	$('pt_chooser').style.visibility = 'visible';
}

function hideChooser()
{
	$('pt_chooser').style.visibility = 'hidden';
}

function updateClock()
{
	now = new Date();
	hour = now.getHours();
	min = now.getMinutes();
	sec = now.getSeconds();
	
	if (min <= 9)
	{
		min = "0" + min;
	}
	if (sec <= 9)
	{
		sec = "0" + sec;
	}
	if (hour < 10)
	{
		hour = "0" + hour;
	}
	
	$('header_clock').innerHTML = (hour + ':' + min + ':' + sec);
	
	setTimeout("updateClock()", 1000);
}

function goSpotLight()
{
	return;
}

function pW() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pH() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function tP() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function lP() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function centerInMask(oObj)
{
  var wW = pW();
  var wH = pH();
  var wL = lP();
  var wT = tP();
  
  var dW = oObj.offsetWidth;
  var dH = oObj.offsetHeight;
  
  var dT = wT + (wH / 3) - (dH / 2);
  var dL = wL + (wW / 2) - (dW / 2);
  
  oObj.style.top = dT + "px";
  oObj.style.left = dL + "px";
}

function sendYm()
{
	var sUrl = window.location.href;
	
	window.location.href="ymsgr:sendim?m=Gui ban noi dung tu ezPriston : " + sUrl + " !";
}

function doReport()
{
	var sUrl = window.location.href;
	
	window.location.href = "ymsgr:sendim?wormy_vn&m=Trang nay co van de roi Wormy oi : " + sUrl + " !";
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

var isNav = (document.all) ? false : true;
var isIE = (document.all) ? true : false;

function getWinWidth()
{
	if (isNav && !isIE)
		return(window.innerWidth);
	else if (isIE && !isNav)
		return(document.body.clientWidth);
	else
		return(100);
}

//Specify the text to display
var displayed="<nobr><span id=\"topLink\">[Quay lên trên]</span></nobr>"

///////////////////////////Do not edit below this line////////////

var logolink='javascript:window.scrollTo(0,0)'
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function regenerate(){
window.location.reload()
}
function regenerate2(){
if (ns4)
setTimeout("window.onresize=regenerate",400)
}

if (ie4||ns6)
document.write('<span id="logo" style="position:absolute;top:-300px;z-index:100">'+displayed+'</span>')

function createtext(){ //function for NS4
staticimage=new Layer(5)
staticimage.left=-300
staticimage.document.write('<a href="'+logolink+'">'+displayed+'</a>')
staticimage.document.close()
staticimage.visibility="show"
regenerate2()
staticitns()
}

function staticit(){ //function for IE4/ NS6
var w2=ns6? pageXOffset+w : ietruebody().scrollLeft+w
var h2=ns6? pageYOffset+h : ietruebody().scrollTop+h
crosslogo.style.left=w2+"px"
crosslogo.style.top=h2+"px"
}

function staticit2(){ //function for NS4
staticimage.left=pageXOffset+window.innerWidth-staticimage.document.width-28
staticimage.top=pageYOffset+window.innerHeight-staticimage.document.height-10
}

function inserttext(){ //function for IE4/ NS6
if (ie4)
crosslogo=document.all.logo
else if (ns6)
crosslogo=document.getElementById("logo")
crosslogo.innerHTML='<a href="'+logolink+'">'+displayed+'</a>'
w=ns6 || window.opera? window.innerWidth-crosslogo.offsetWidth-20 : ietruebody().clientWidth-crosslogo.offsetWidth-10
h=ns6 || window.opera? window.innerHeight-crosslogo.offsetHeight-15 : ietruebody().clientHeight-crosslogo.offsetHeight-10
crosslogo.style.left=w+"px"
crosslogo.style.top=h+"px"
if (ie4)
window.onscroll=staticit
else if (ns6)
startstatic=setInterval("staticit()",100)
}

if (ie4||ns6){
if (window.addEventListener)
window.addEventListener("load", inserttext, false)
else if (window.attachEvent)
window.attachEvent("onload", inserttext)
else
window.onload=inserttext
window.onresize=new Function("window.location.reload()")
}
else if (ns4)
window.onload=createtext

function staticitns(){ //function for NS4
startstatic=setInterval("staticit2()",90)
}

function goCalc(sClass)
{
	if (sClass.length == 2)
	{	
		$('frmCalc').src = "chars_calc_" + sClass + ".htm";
	}
	else
	{
		$('frmCalc').src = "chars_calc_none.htm";		
	}	
}

function getCalc()
{
	var sClass;
	
	sClass = window.location.href.substring(window.location.href.indexOf("?char=") + 6);
	
	goCalc(sClass);
}

function loadMap(imageName, warpable, teleportalbe, mapName, lv, shortName)
{
	var imageObj = document.getElementById("map_img");
	var viewObj1 = document.getElementById("map_view_01");
	var viewObj2 = document.getElementById("map_view_02");
	var viewObj3 = document.getElementById("map_view_03");
	var linkObj1 = document.getElementById("map_link_01");
	var linkObj2 = document.getElementById("map_link_02");
	var linkObj3 = document.getElementById("map_link_03");
	var titleObj = document.getElementById("map_title");
	var warpObj = document.getElementById("map_warp");
	var teleportObj = document.getElementById("map_teleport");
	var levelObj = document.getElementById("map_lv");
	var shortNameObj = document.getElementById("map_short");
	
	imageObj.src = "images/" + imageName + ".jpg";
	viewObj1.src = "images/" + imageName + "_01_t.jpg";
	viewObj2.src = "images/" + imageName + "_02_t.jpg";
	viewObj3.src = "images/" + imageName + "_03_t.jpg";
	linkObj1.href = "images/" + imageName + "_01.jpg";
	linkObj2.href = "images/" + imageName + "_02.jpg";
	linkObj3.href = "images/" + imageName + "_03.jpg";
		
	titleObj.innerHTML = mapName;
	shortNameObj.innerHTML = shortName;
	
	if (warpable)
	{
		warpObj.src = "images/map_on.gif";
	}
	else
	{
		warpObj.src = "images/map_off.gif";
	}
	if (teleportalbe)
	{
		teleportObj.src = "images/map_on.gif";
	}
	else
	{
		teleportObj.src = "images/map_off.gif";
	}
	
	levelObj.innerHTML = lv;
}

/* LCD Countdown */

function cdtime(container, targetdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date()
this.targetdate=new Date(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

function formatresults(){
if (this.timesup==false){ //if target date/time not yet met
var displaystring="<span class='lcdstyle'>Sinh nhật PTV còn : "+arguments[0]+" <sup>ngày</sup> "+arguments[1]+" <sup>giờ</sup> "+arguments[2]+" <sup>phút</sup> "+arguments[3]+" <sup>giây</sup></span>"
}
else{ //else if target date/time met
var displaystring="Đã đến ngày kỉ niểm sinh nhật của PTV!" //Don't display any text
}
return displaystring
}

/* LCD Countdown */