//<![CDATA[
var filePath = "http://file.kaybo.com/crazycombi/";
//cvr setting
var fcsObj = null; //global focus variable;
var cvrObj = null; //cover (blocking obj)
var posObj = null; //endPosition
var callFF = null; //for Firefox
var popObj = null; //inner pop
var ifrObj = null; //iframe division
var msgObj = null;
var msgTxt = null;
var msgExit = null;
var hideSaveObj = null; //save focus object for return
//-- chk browser
function setBrowser()
{
	var wna = window.navigator.userAgent;
	if(wna.indexOf('MSIE')!=-1){
		this.browser=0;
		appNum = eval(navigator.appVersion.substr(navigator.userAgent.indexOf("MSIE") - 3,3));
	}else if(wna.indexOf('Firefox')!=-1){
		this.browser=1;
	}else  if(wna.indexOf('Opera')!=-1){
		this.browser=2;
	}else  if(wna.indexOf('Safari')!=-1){
		this.browser=3;
	}else if(document.all){//etc = 0;
		this.browser=0;
	}else{
		this.browser=null;
	}
	return this.browser;
}
var app = setBrowser();

function setPng24(pobj) {
	pobj.width=pobj.height=1;
	pobj.className=pobj.className.replace(/\bpng24\b/i,''); 
	pobj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ pobj.src +"',sizingMethod='image');"
	pobj.src='about:blank;';
	return '';
}

function getPos(obj)
{
	var objLeft = 0;
	var objTop = 0;
	
	try	{
		if (obj.offsetParent) {
			do {
				objLeft += obj.offsetLeft;
				objTop += obj.offsetTop;
			} while (obj = obj.offsetParent);
			return [objLeft,objTop];
		}
	}
	catch ( err ) {
		//return [objLeft,objTop];
	}
}

//-- s:swf pickup
function writeSwf (obj, objId, width, height, winmode, mozid, divName, isTitle)
{
	var ewinmode, objName, pageSbj;
	
	if(isTitle != undefined) obj += "?";	
	if(isTitle == 1){//auto title
		try{
			var t1 = document.getElementById('dep1txt');
			var t2 = document.getElementById('dep2txt');
			var t3 = document.getElementById('subjtxt');
			pageSbj = t3.firstChild.nodeValue;			
			obj += "dep1txt="+encodeURIComponent(t1.firstChild.nodeValue)+"&dep2txt="+encodeURIComponent(t2.firstChild.nodeValue)+"&subjtxt="+encodeURIComponent(pageSbj)+"&";
			//set title
			document.getElementById(divName).attributes['title'].value = pageSbj;
		}catch(err){
			//alert(err.description);
		}		
	}
	
	var swfObj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ width + '" height="'+ height + '" id="'+ objId  + '" align="top">'
		+ '<param name="allowScriptAccess" value="always" />'
		+ '<param name="movie" value="' + obj + '" />'
		+ '<param name="menu" value="false" />'
		+ '<param name="quality" value="high" />'
		+ '<param name="allowFullScreen" value="true" />'
		+ '<param name="scale" value="noscale" />';

	if(winmode == 1){//transparent
		swfObj += '<param name="wmode" value="transparent" />';
		ewinmode = ' wmode="transparent"';
	}else if(winmode==2){//opaque
		swfObj += '<param name="wmode" value="opaque" />';
		ewinmode = ' wmode="opaque"';
	}else{ewinmode = '';}
	if(mozid){//swfObject control name for mozilla
		objName = ' name="'+objId+'"';
	}else{objName = '';}
	swfObj += '<embed src="' + obj + '" menu="false"' + ewinmode + objName + ' quality="high" scale="auto" bgcolor="#ffffff" width="' + width + '" height="'+ height  +'" id="' + objId + '" align="top" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true" allowScriptAccess="always" swLiveConnect="true" /></object>';
	if(divName){
		//alert(swfObj);
		document.getElementById(divName).innerHTML = swfObj;
	}else{document.write (swfObj);}
}
//-- e: swf pickup
//-- s: set swfsize
function setSwaveWH(a){
	//if(a) alert(getSwfObj('submnswf').height);
	getSwfObj('submnswf').height = a;
}
//-- e: set swfsize
function getSwfObj(movieName) {
	// IE and Netscape refer to the movie object differently.
	// This function returns the appropriate syntax depending on the browser.
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		return window[movieName]
	}else {
		return document[movieName]
	}
}


function setBlocking()
{	
	//set size	
	var pos = getPos(posObj); //required posObj
	cvrObj.style.width = pos[0]+"px";
	cvrObj.style.height = pos[1]+"px";
	if(callFF == null){
		cvrObj.style.display = "block";
		//return callFF = setTimeout(setBlocking,50); //delay error fix
	}else{
		clearTimeout(callFF);
		callFF = null;		
	}
}


var evtCntObj = [null,null];
function iframeParam(a)
{
	try {
		var tmp = a.split("_");
		var eObj = document.getElementById(tmp[0]);
		//alert(eObj.innerHTML);

		evtCntObj[0] = eObj.innerHTML;
		//evtCntObj[0] = eObj.firstChild.nodeValue;
		evtCntObj[1] = tmp[1];
	} catch(e) {
		alert(e.description);
	}
}


var dynUrl = null;
//var returnUrl = null;

function showBox(pmode,psize,purl,hObj,hUrl,param)
{
	try{
		var tSize;
		var pObj = popObj.style;
		var mObj = msgObj.style;
		if(pmode == 1)
		{
			//ifr
			if(psize == undefined || !psize) {
				//psize = "550_400";//default;
				alert("indicate the popup size");
				return;
			}
			tSize = psize.split("_");	
			cvrObj.style.display = pObj.display = "block";
			pObj.width = tSize[0] + "px";
			pObj.height = tSize[1] + "px";
			pObj.marginLeft = -(tSize[0]/2)+"px";
			pObj.marginTop = -(tSize[1]/2)+"px";
			pObj.zIndex = "101";
			ifrObj.src = purl;

			if (param) {
				iframeParam(param);
			}
		}
		else
		{
			//msg			
			if(psize == undefined || !psize) psize = "360_188";
			tSize = psize.split("_");
			cvrObj.style.display = "block";
			pObj.zIndex = "98";//101(risk!!)
			//pOb2.zIndex = "99";
			mObj.display = "block";
			mObj.width = tSize[0] + "px";
			mObj.height = tSize[1] + "px";
			mObj.marginLeft = -(tSize[0]/2)+"px";
			mObj.marginTop = -(tSize[1]/2)+"px";
			msgObj.attributes['title'].value = purl;
			msgTxt.innerHTML = purl;
			if(hObj) {
				hideSaveObj = hObj;
				if(hUrl) dynUrl = hUrl;
			}

			if(hUrl) dynUrl = hUrl;

			//msgExit.focus();
		}
		setBlocking();
	}catch(Err){
		//alert(Err);
	}
}
function hideBox(pmode)
{
	try{
		//alert(11);
		var pObj = popObj.style;
		//var pOb2 = popOb2.style;
		var mObj = msgObj.style;
		if(pmode == undefined){
			//alert("run in hide func");
			pObj.zIndex = "101";
			mObj.display = "none";
			pObj.display = "none";
			cvrObj.style.display = "none";
			ifrObj.src = "about:blank";
		}else{
			mObj.display = "none";
			if(pObj.display == "none" || pObj.display == "") cvrObj.style.display = "none";
			pObj.zIndex = "101";			
			if(fcsObj != null) {
				fcsObj.focus();
				fcsObj = null;
			}
			if(hideSaveObj != null){
				hideSaveObj.focus();
				hideSaveObj = null;
			}

			if ( dynUrl ) {
				location.href = dynUrl;
			}

			try {
				var logObj = document.getElementById('loginArea');
				var logCls = logObj.className;

				if(logCls == 'loginsb' || logCls == 'loginmn'){
					//window.location.refresh();
					window.location.reload();
				}
			}
			catch ( e ) { }
		}
		cvrObj.style.background = "#000";
	}catch(Err){alert(Err);}
}
//ifr control : detail
function iframePageReset(urlsCase)
{ 
	// ==== control link in iframe (inner popup)
	//alert(urlsCase);
	var wSize = '400_300', urls = "about:blank";
	switch (urlsCase) {
		case "login" :
			wSize = '800_343';
			urls = "";
		break;

		case "find_id" :
			wSize = '500_257';
			urls = "";
		break;
	}
	showBox(1,wSize,urls);
}


//-- s: login prcs
function logCheck()
{
	var frm = arguments[0];
	var prePath = "";
	if(arguments[1]) prePath = arguments[1];
	if(frm.id.value.length == 0){
		alert('\n▒ Ingrese su Usuario    ');//id required
		frm.id.focus();
		return false;
	}
	if(frm.pw.value.length == 0){
		alert('\n▒ Ingrese su contraseña    ');//pwd required
		frm.pw.focus();
		return false;
	}
	//return true;
	////return loginCtrl();
	var prm = "id=" + encodeURIComponent(frm.id.value) +
		"&pw=" + encodeURIComponent(frm.pw.value) +
		"&gamecode=" + encodeURIComponent("COMBI") +
		"&acturl=" + encodeURIComponent("http://crazycombi.kaybo.com/login/front_login.html");
	//ajax call
	setBlocking();
	cvrObj.style.background = "#000 url('http://file.kaybo.com/crazycombi/_common/ajaxLoader1.gif') center fixed no-repeat";
	
	setXHR('POST',prePath + '/login/front_login.html',true,'','','',true,prm,onResponse);
	//setXHR('POST',prePath + '/login/front_login.html',true,'','','',true, "id=" + encodeURIComponent(frm.id.value),onResponse);
}


function inputSelect()
{
	if(arguments[0].value.length > 0){
		try{
			arguments[0].select();
		}catch(e){}
	}
}

//-- s: addEvent Model
function addEvtFnc(f,types)
{
	var evtFnc = window[types];
	if(typeof evtFnc != 'function'){
		window[types] = function(){
			try{eval(f);}
			catch(err){alert(err.description);}
		}
	}else{
		var setFnc = function(){eval(f);}
		window[types] = function(){
			if(evtFnc) evtFnc();
			try{setFnc();}
			catch(err){alert(err.description);}
		}
	}
}
//-- e: addEvent Model

//-- temp func
var logFrm = null;
function setLogFrm(){
	logFrm = document.loginFrm;
	if(logFrm == undefined) {
		return;	
	}
	var logid = logFrm.id;
	var logpw = logFrm.pw;
	if(logid){
		if(logid.value.length == 0) logid.focus();
		logid.onfocus = function(){
			if(this.value.length == 0) this.className = "loginid";
			else this.className = "loginput1";
		}
		logid.onblur = function(){
			if(this.value.length == 0) this.className = "loginid";
			else this.className = "loginput1";
		}
		logid.onclick = logid.onkeyup = function(){
			if(this.value.length > 0) this.className = "loginput1";
			else this.className = "loginid";
		}
	}
	if(logpw){
		logpw.onfocus = function(){
			if(this.value.length == 0) this.className = "loginpw";
			inputSelect(this);
		}
		logpw.onblur = function(){
			if(this.value.length == 0) this.className = "loginpw";
			else this.className = "loginput1";
		}
		logpw.onclick = logpw.onkeyup = function(){
			if(this.value.length > 0) this.className = "loginput1";
			else this.className = "loginpw";
		}
	}
	logid.focus();
}
//-- s: swap tab func
//var saveTabObj = [], tmpTabObj = [];//swapTap func variable
var tabGrpIdx = [], tabFocus = false;
var saveTabObj = [[],[],[],[]], tmpTabObj = [[],[],[]];//swapTap func variable
function tabSwap(a,b,c,d,e,f,g,h,i,   tracerImg)
{
	/***
	arg0: id, arg1:change img, arg2: mouse event(1:over,2:out,3:click), arg3:prePath , arg4: change div Name arrary, 
	arg5: div Name array idx, arg6: length; ,arg7: grp idx (for multi), arg8: urlPath, arg9: tracerImg
	***/
	//var tab_idx = tabGrpIdx[h] = h;
	var isOut = null;
	//alert(a);
	var tab_idx =  h;
	var obj = document.getElementById(a);
	//alert(obj.id);
	var isDir = getFileName(obj.src, 0);
	//alert(isDir);
	var isName = getFileName(obj.src, 1);
	if(d != undefined){
		var path = d+isDir + '/';
	}else{
		var path = isDir + '/';
	}
	//alert(path);
	if(saveTabObj[0][h] == undefined){
		//alert('no data');		
		saveTabObj[0][tab_idx] = obj;
		saveTabObj[1][tab_idx] = b;
		saveTabObj[2][tab_idx] = isName;
	}
	
	if(c==3){
		if(i != undefined){
			saveTabObj[3][tab_idx] = i;
		}
		if(obj != saveTabObj[0][tab_idx]){//save isClick
			saveTabObj[0][tab_idx] = obj;
			saveTabObj[1][tab_idx] = tmpTabObj[1][tab_idx];
			saveTabObj[2][tab_idx] = tmpTabObj[2][tab_idx];
		}else{
			var chkimg = getFileName(saveTabObj[0][tab_idx].src, 1);
			if(chkimg != saveTabObj[1][tab_idx]){
				obj.src = path + saveTabObj[1][tab_idx];
				
				if(tracerImg) {
					setDecoImg(tracerImg,obj);
				}
			}
		}
		
	}
	if(c == 1){
		tmpTabObj[0][tab_idx] = obj;
		tmpTabObj[1][tab_idx] = b;
		tmpTabObj[2][tab_idx] = isName;
		if(obj != saveTabObj[0][tab_idx]){
			obj.src = path + b;
			saveTabObj[0][tab_idx].src = path + saveTabObj[2][tab_idx];
			if(tracerImg) setDecoImg(tracerImg,obj);//alert(tracerImg.src);
		}
	}else if(c == 2){
		
		if(obj != saveTabObj[0][tab_idx]){
			isOut = saveTabObj[0][tab_idx];
			obj.src = path +b;
			saveTabObj[0][tab_idx].src = path + saveTabObj[1][tab_idx];
		}
		if(tracerImg) setDecoImg(tracerImg,saveTabObj[0][tab_idx]);
	}
	
	if(e != undefined){
		var idStr = String(e);
		var isObj = idStr + f;
		for(var k=0; k<g; k++){
			tObj = idStr + k;
			var dvObj = document.getElementById(tObj);
			if(tObj == isObj){
				dvObj.style.display = "block";
				if(tabFocus) {//onload only
					dvObj.focus();
				}else{
					tabFocus = true;
				}
			}else{
				dvObj.style.display = "none";
			}
		}
	}
	
}
//-- e: swap tab func
//-- s: swap tab (batch code)
function setTab(a,b,c,d,e,f,decoImg, fidx)
{
	//a:id for range, b:prefix(ex = 'tab1s'), c:prepath, d:div prefix, e:showhide total, f:multi tab idx, decoImg: trace img
	var tagObj = document.getElementById(a);
	var n = 1;
	var obj = null;
	var objW = 0;
	
	if(decoImg) {
		obj=document.getElementById(decoImg);
	}
	
	//check through all contained elements in selected range (for..in tagObj)
	var tagObjAll = tagObj.getElementsByTagName("*");
	for (var i = 0; i < tagObjAll.length; i++) {
		var elem = tagObjAll[i];
		var elemId = elem.getAttribute('id');
		
		elem.m = n;
		elem.o = obj;
		if(elemId && elem != obj){
			
			var isExt = getFileName(elem.getAttribute('src'), 1).split(".");
			elem.onmouseover = function(){
				tabSwap(this.id, b + this.m + "_2."+isExt[1],1,c,'','','',f,    '',this.o);
			}
			elem.onmouseout = function(){
				tabSwap(this.id, b + this.m + "_1."+isExt[1],2,c,'','','',f,    '',this.o);
			}
			elem.onclick = function(){
				tabSwap(this.id, b + this.m + "_2."+isExt[1],3,c,d,this.m-1,e,f,    '',this.o);
				tabIdx[f] = this.id;//save id for url index (event)
			}
			elem.style.cursor = "pointer";
			/*if(n==1) {
				tabSwap(elemId, b + n + "_2."+isExt[1],3,c,d,n-1,e,f,    '',elem.o);
				tabIdx[f] = elemId;//save id for url index (init)
			}
			n++;*/

			if(fidx){
				if((n-1) == fidx){
					tabSwap(elemId, b + n + "_2."+isExt[1],3,c,d,fidx,e,f,    '',elem.o);
					tabIdx[f] = elemId;
				}
			}else{     
				if(n==1) {
					tabSwap(elemId, b + n + "_2."+isExt[1],3,c,d,n-1,e,f,    '',elem.o);
					tabIdx[f] = elemId;//save id for url index (init)
				}
			}

			n++;
		}
	}
	
}
//-- e: swap tab (batch code)
function setDecoImg(decoObj,tabObj)
{
	decoObj.style.display = "block";

	//for tabSwap only
	//offsetParent is different (firefox and crome,opera)
	objParentX = tabObj.parentNode.parentNode.offsetLeft;//important(buggy?!) : parent depth
	mvImgX = objParentX + tabObj.parentNode.offsetLeft - ((decoObj.width- tabObj.width)/2);
	mvImgY = tabObj.parentNode.parentNode.offsetTop + tabObj.height;
	decoObj.style.left = mvImgX + "px";
	decoObj.style.top = mvImgY + "px";

	//decoObj.style.display = "block";
}

//-- s: simple swap
function imgSwap(e)
{
	if(app == 0){
		var objId = e.srcElement.id;
	}else if(app == 1 || app == 2 || app == 3){
		var objId = e.target.id;
	}
	if(arguments[2]){
		var obj = parent[arguments[2]].document.getElementById(objId);
	}else{
		var obj = document.getElementById(objId);
	}
	var srcLen = obj.src.length, findIdx = obj.src.lastIndexOf('/');
	var imgName = obj.src.substring(findIdx+1,srcLen).length;
	var imgPath = obj.src.substring(0,srcLen-imgName);
	obj.src = imgPath+arguments[1];
}
//-- e: simple swap
//-- s: isId
function getEid(n,f) {	
	try{
		if(f){			
			var isObj = parent.main.document.getElementById(n);
		}else{
			var isObj = document.getElementById(n);
		}

		if(document.getElementById(n) != null){
			return isObj;
		}else{
			return null;
		}		
	}catch(err){
		return null;
	}
}
//-- e: isId
//-- s: get file name for URLPATH
function getFileName()
{
	//arg0: file url path, arg1: get file name or file's dir name[true, false]
	var objName = "";
	if(arguments[0]){
		var tmpAry = (arguments[0].replace("/ /gi","%20").replace("/\/gi","/")).split("/");
		var preDir = tmpAry[tmpAry.length-2];
		var preName = tmpAry[tmpAry.length-1];
		if(arguments[1]){
			var chkChar = ['?','#'], objName = preName;
			for(var i=0; i<chkChar.length; i++){
				var chkQryStr = objName.lastIndexOf(chkChar[i]);
				if(chkQryStr>=0){
					objName = objName.substr(0,chkQryStr);
				}else{
					objName = objName;
				}
			}
		}else{
			objName = preDir;
		}
		return objName;
	}else{
		return false;
	}
}
//-- e: get file name for URLPATH

function cmnFnc(){
	pageInit();
	setLogFrm();
	loadScroll();
	if(getEid('cBox_sbj')) writeSwf ("http://file.kaybo.com/crazycombi/_common/pagetitle.swf", "sbjswf", 749, 110,1,1,'cBox_sbj',1);
	if(getEid('floater')) writeSwf ("http://file.kaybo.com/crazycombi/_common/btntop.swf", "topswf", 38, 150,1,1,'floater');
}

function blockingInit(){
	try{	
		if(cvrObj == null) cvrObj = document.getElementById('vsCvr');
		if(posObj == null) posObj = document.getElementById('cvrEpos');
		if(popObj == null) popObj = document.getElementById('vsPop');
		if(ifrObj == null) ifrObj = document.getElementById('ifr');
		if(msgObj == null) msgObj = document.getElementById('vsMsg');
		if(msgTxt == null) msgTxt = document.getElementById('msgTxtArea');
		if(msgExit == null) msgExit = document.getElementById('btnMsgExit');
		if(cvrObj.style.display == "block") setBlocking();
	}catch(e){alert(e);}
}

try{
	addEvtFnc("blockingInit()","onload");
	addEvtFnc("blockingInit()","onresize");
	addEvtFnc("blockingInit()","onscroll");
	addEvtFnc("cmnFnc()","onload");
}catch(e){
	alert("event wrapper error : " + e.description);
}

function launchApp(){
	//logincheck required
	try {
		if(app == 0) {
			setXHR('POST','http://crazycombi.kaybo.com/launcher/swresult.html',true,'','','',false,'str=active',onResData);
		}else{
			//showBox(2,'360_188','Si deseas acceder a Crazy Combi 3D por favor instala MS Internet Explorer 6.0 o superior y reinicia tu computador    ');
			showBox(2,'360_188','Crazy Combi 3D requiere el uso dell launcher para poder jugar, descárguelo y siga las instrucciones.    ', '', 'http://crazycombi.kaybo.com/helpdesk/downloads.html' );
		}
	} catch(e) {
		//alert("launch err : " + e); 
	}
}

function onResData(rsStr){
	try {
		if(rsStr){
			var darray = rsStr.split("||");

			if ( darray[1] != '' ) {
				if ( darray[1] == 'check' ) {
					// 게임안됨
					showBox( 2, '360_188', darray[3] );
				} else {
					GameLauncher.Launch( darray[0], darray[1], darray[2] );
				}
			} else {
				// 로그인 필요
				showBox( 2, '360_188', darray[3] );
			}
		}
	}
	catch( e ){
		//alert( e.description );
		//alert( "--no activex--" );
	}
}
var csh_win = null;
function open_win( _url, _name, _width, _height, _option ) {
	csh_win = window.open( _url, _name, "width="+ _width + ", height=" + _height + _option );
}

function accordUrl(a) {
	var urls = [
		"http://crazycombi.kaybo.com/helpdesk/faq.html",
		"http://crazycombi.kaybo.com/helpdesk/videoclips.html",
		"http://crazycombi.kaybo.com/news/giftbox.html"
	];
	if(a != undefined) {
		window.location.href = urls[a];
	}
}

//]]>