﻿/*-------------------------------------------------
* 
*  H G W L A B . C O M 
*          +
*  C B C - N E T . T A N K  
*          
* .De / S N P
* .In / H G W
* .He / F J M
* ------------------------------------------------*/



/*------------------------------------------------
*  getPageScroll
------------------------------------------------*/

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll);
	return arrayPageScroll;
}


/*------------------------------------------------
*  getPageSize
------------------------------------------------*/
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight; //+ window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.offsetHeight;//document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}




/*------------------------------------------------
*  checkCooky
------------------------------------------------*/
function checkCooky(objLink){
	var cN="cckyTank061130_2"
	var cookRaw = getCookie(cN);
	var cook = String(cookRaw);
	var cCheFrag=true;
	var cCheck=cook.split("!!!");
	
	if(objLink.id!=""){
		hideFlashTrg();
		for (var i=0;i<cCheck.length;i++){
			if(cCheck[i]==objLink.id){
				objLink.id="reg";
				break;
			}		
		}
		if(objLink.id!="reg"){
			cook=cook+"!!!"+objLink.id; 
			setCookie(cN, cook);
		}
	}
	showFlash(objLink,cook,cN);
}



/*------------------------------------------------
*  flash lay for tray
------------------------------------------------*/
function showFlash(objLink,cook,cookName){
	var file = objLink.href;
	var ver = objLink.ver;
	var idNum=objLink.id;
	if(navigator.appName.indexOf("Microsoft") > -1){
		var br = "ie";
	}else{
		if(navigator.userAgent.indexOf("Safari")>-1){
			var br = "safari";
		}else{
			var br = "other";
		}	
	}
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();	
	var objBody = document.body;
	var objOverlay = document.createElement("div");
	var myTag= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+'" width="100%" height="100%" id="overlayFlash" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+file+'" /><param name="quality" value="high" /><param name="salign" value="lt" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="FlashVars" value="entryIdNumber='+idNum+'&cookLen='+cook+'&cookNm='+cookName+'" /><embed src="'+file+'" quality="high" salign="lt" swLiveConnect=true wmode="transparent" bgcolor="#ffffff" FlashVars="entryIdNumber='+idNum+'&cookLen='+cook+'&cookNm='+cookName+'" width="100%" height="100%" name="overlayFlash" id="overlayFlash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	
	if(br == "ie" || br =="safari"){
		objOverlay.style.top =  (arrayPageScroll[1] + 'px');
		objOverlay.style.height = (arrayPageSize[3] + 'px');
	}else{
		objOverlay.style.top =  (arrayPageScroll[1] + 'px');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
	}
	
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '200';
 	objOverlay.style.width = '100%';
	objOverlay.innerHTML = myTag;
	objBody.insertBefore(objOverlay, objBody.firstChild);
	objOverlay.style.display = 'block';
	
	window.onresize = function(){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();	
		if(br == "ie" || br =="safari"){
			objOverlay.style.top =  (arrayPageScroll[1] + 'px');
			objOverlay.style.height = (arrayPageSize[3] + 'px');
		}else{
			objOverlay.style.top=(arrayPageScroll[1]+'px');
			objOverlay.style.height = (arrayPageSize[1] + 'px');
		}
	}
	
	window.onscroll = function(){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();	
		if(br == "ie" || br =="safari"){
			objOverlay.style.top =  (arrayPageScroll[1] + 'px');
			objOverlay.style.height = (arrayPageSize[3] + 'px');
		}else{
			objOverlay.style.top=(arrayPageScroll[1]+'px');
			objOverlay.style.height = (arrayPageSize[1] + 'px');
		}
	}	
	
}


/*------------------------------------------------
*  hide flash lay
------------------------------------------------*/
function hideFlash(){
	var objBody = document.body;
	objBody.removeChild(objBody.firstChild);
	showFlashTrg();
}


function initoverLayFlash(){
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "overLayFlash")){
			anchor.onclick = function () {
				checkCooky(this);
				//window.alert(this);
				return false;
			}
		}
	}
	
	showFlashTrg();

}




/*------------------------------------------------
*  setCookie
------------------------------------------------*/
function setCookieFromFla(val) {
	var sendval=val.split("???");
	setCookie(sendval[0],sendval[1]);
}
function setCookie(name, val) {
	//window.alert(name+"\n"+ val);

	var tmp = name + "=" + escape(val) + "; ";
	tmp += "expires=Tue, 31-Dec-2030 23:59:59; path=/tank;";
	document.cookie = tmp;
}


/*------------------------------------------------
*  getCookie
------------------------------------------------*/
function getCookie(name){
	var search = name + '=';
	if (document.cookie.length>0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1){
			offset += search.length;
			end     = document.cookie.indexOf(';',offset);
		if(end == -1)
			end = document.cookie.length;
			return unescape(document.cookie.substring(offset,end));
		}
	}
	return null;
}






/*------------------------------------------------
*  trgBtn
------------------------------------------------*/
function showFlashTrg(){
	var file = "http://www.cbc-net.com/tank/tank_trg_btn.swf";
	var ver = "8,0,0,0";
	
	
	if(navigator.appName.indexOf("Microsoft") > -1){
		var br = "ie";
	}else{
		if(navigator.userAgent.indexOf("Safari")>-1){
			var br = "safari";
		}else{
			var br = "other";
		}	
	}
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();	
	var objBody = document.body;
	var objOverlay = document.createElement("div");
	var myTag= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+'" width="40" height="100" id="overlayFlashBtn" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+file+'" /><param name="quality" value="high" /><param name="salign" value="lt" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><embed src="'+file+'" quality="high" salign="lt" swLiveConnect=true wmode="transparent" bgcolor="#ffffff" width="40" height="100" name="overlayFlashBtn" id="overlayFlashBtn" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	objOverlay.setAttribute('id','overlayFlashBtn');
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	
	if(br == "ie" || br =="safari"){
		objOverlay.style.top =  (arrayPageScroll[1] + 'px');
	}else{
		objOverlay.style.top =  (arrayPageScroll[1] + 'px');
	}
	
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '200';
 	objOverlay.style.width = '40';
	objOverlay.style.height = ('100px');
	
	objOverlay.innerHTML = myTag;
	objBody.insertBefore(objOverlay, objBody.firstChild);
	objOverlay.style.display = 'block';	
	
	window.onresize = function(){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();	
		if(br == "ie" || br =="safari"){
			objOverlay.style.top =  (arrayPageScroll[1] + 'px');
		}else{
			objOverlay.style.top=(arrayPageScroll[1]+'px');
		}
	}
	
	window.onscroll = function(){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();	
		if(br == "ie" || br =="safari"){
			objOverlay.style.top =  (arrayPageScroll[1] + 'px');
		}else{
			objOverlay.style.top=(arrayPageScroll[1]+'px');
		}
	}	
}




/*------------------------------------------------
*  hide TrgBtn and attachTray
------------------------------------------------*/
function attachTray(){
	var objBody = document.body;
	objBody.removeChild(objBody.firstChild);
	var dummyObj=window;
	dummyObj.id="";
	dummyObj.href="http://www.cbc-net.com/tank/tanksample1.swf";
	dummyObj.rel="overLayFlash"
	dummyObj.ver="8,0,0,0";
	checkCooky(dummyObj);
}

function hideFlashTrg(){
	var objBody = document.body;
	objBody.removeChild(objBody.firstChild);
}








/*------------------------------------------------
*  addLoadEvent
------------------------------------------------*/
function addLoadEvent(func)
{	
	var oldonload = window.onload;

	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


addLoadEvent(initoverLayFlash);	