/*
 * function : define flash tag and write
 * @info    : ActivX IE modify
 * @param fID(Flash ID), fURL(Flash URL), w(width), h(height)
 *        wmode(wmode value[null,0 - non select mode, 1 - select mode])
 *        bgClr(background color[null - no value, value - set value])
 *        lstate(loop value[null,0 - not define loop, 2 - loop false])
 *        rtnV(return type[null,0 - null, 1 - string])
 */
function drawFlash(fID, fURL, w, h, wmode, bgClr, lstate, rtnV) {
	var tmpStr = "";
	tmpStr += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='" + w + "' height='" + h + "' id='" + fID + "' name='" + fID + "' align='middle' type='application/x-shockwave-flash'>";
	tmpStr += "<param name='allowScriptAccess' value='always' />";
	tmpStr += "<param name='movie' value='" + fURL + "' />";
	tmpStr += "<param name='quality' value='high' />";
	tmpStr += "<param name='menu' value='false' />";

	if (lstate == 2) tmpStr += "<param name='loop' value='false' />";
	if (wmode == 1) tmpStr += "<param name='wmode' value='transparent' />";
	if (wmode == 2) tmpStr += "<param name='wmode' value='opaque' />";
	if (bgClr != null && bgClr != "undefined") tmpStr += "<param name='bgcolor' value='" + bgClr + "' />";

	tmpStr += "<embed src='" + fURL + "' quality='high' ";
	if (lstate == 2) tmpStr += "loop='false' ";
	if (wmode == 1) tmpStr += "wmode='transparent' ";
	if (wmode == 2) tmpStr += "wmode='opaque' ";
	if (bgClr != null && bgClr != "undefined") tmpStr += "bgcolor='" + bgClr + "' ";

	tmpStr += "width='" + w + "' height='" + h + "' name='" + fID + "' menu='false' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'  />";
	tmpStr += "</object>";

	if (rtnV && rtnV == 1) { // return string
		return tmpStr;
	} else {
		document.write(tmpStr);
		eval("window."+fID+"=document.getElementById('"+fID+"');");
	}
}

/* function : check null */
function isNull(tObj) {
	if (tObj == null || tObj == "undefined") return true;
	return false;
}

/* function : add onload function */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof(window.onload) != "function") {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function goAigTopLink(idx, idy) {
	if (!aigMenu) return;
	if (!idy) idy = 0;
	var tmp1Depth = 0, tmp2Depth = 0;
	for (var i = 0; i < aigMenu.list.length; i ++) {
		if (aigMenu.list[i].depth == 1) {
			tmp1Depth++;
			tmp2Depth = 0;
		}
		if (aigMenu.list[i].depth == 2) tmp2Depth++;
		if (tmp1Depth == idx && tmp2Depth == idy) { // ¸Þ´º ¼±ÅÃ
//			alert(aigMenu.list[i].pID+"/"+aigMenu.list[i].mID);
			goAigLink(aigMenu.list[i].pID);
			break;
		}
	}
}


function goAigLink(pID) {
	if (!aigMenu) return;
	if (isNull(pID)) return;
	var mIdx = aigMenu.getMenuAttribute(pID,"idx");
	if (!mIdx) return;
	var tmpTarget = mIdx.lnkTarget;
	try {
		switch(tmpTarget) {
			case "aig":
				if (top.aig) {
					top.aig.document.location.href = mIdx.link;
				} else {
					top.document.location.href = "/index.html?skurl="+mIdx.link;
				}
				break;

			case "top":
				top.document.location.href = mIdx.link;
				break;
			case "new":
				window.open(mIdx.link,"");
				break;
			case "exec":
				eval(mIdx.link);
				break;
			case "engaig":
				top.document.location.href = mIdx.link;
				break;
		}
	} catch(e) {
		alert(e);
	}
}

function popWin(url,win,width,height,flag) {
	var tmpWin;
	var wd = width;
	var he = height;
	var topposition = (screen.height)?(screen.height-he)/2:0;
	var leftposition = (screen.width)?(screen.width-wd)/2:0;

	if (flag == "0" ) {
		tmpWin = window.open(url,win,"toolbar=0,menubar=0,scrollbars=no,resizable=no,width="+wd+",height="+he+",top="+topposition+",left="+leftposition);
		}
	else {
		tmpWin = window.open(url,win,"toolbar=0,menubar=0,scrollbars=yes,resizable=no,width="+wd+",height="+he+",top="+topposition+",left="+leftposition);
		}
		tmpWin.focus();
}


/*
 * function : define popup close
 */
function popClose() {
	try {
		if (window.opener != null && window.opener.closed) window.opener = self;
	} catch (e) {
		window.opener = self;
	}
	self.close();
}

/*
 * function : define english ver close
 */
function eng_close() {
	try {
	if (!parent.opener.closed) {
		parent.opener.focus();
		parent.close();
	} else {
		window.open("http://www.aiglife.co.kr","");
	}
	} catch(e) {
		window.open("http://www.aiglife.co.kr","");
	}
}

/* Set Cookie Function */
function setCookie(cookieName, cookieValue, cookiePath, cookieExpires){
	cookieValue = escape(cookieValue);
	if(cookieExpires == null || cookieExpires == "undefined" || cookieExpires == ""){
		var nowDate = new Date();
		nowDate.setDate(nowDate.getDate()+1);
		cookieExpires = nowDate.toGMTString();
	}
	if(cookiePath != ""){
		cookiePath = ";path=" + cookiePath;
	}
	document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath+";domain=work3.leenjang.com";
}


/* Get Cookie Function */
function getCookieValue(cookieName){
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
	if(cookieStartsAt == -1){
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	}

	if(cookieStartsAt == -1){
		cookieValue = null;
	}else{
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt)+1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if(cookieEndsAt == -1){
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
	}

	return cookieValue;
}

function itostr(num) {
	if (num <10) num = "0" + num; 
	return num;
}


/* Set Message Layer Function */
function setMsgLayer(w,h,atype,t,l) {
	var tmpStr = "";
	tmpStr += "<div id=\"aigdic\" style=\"";
	if (w) tmpStr += "width:"+w+"px;";
	if (h) tmpStr += "height:"+h+"px;";
	if (t) tmpStr += "top:"+t+"px;";
	if (l) tmpStr += "left:"+l+"px;";
	tmpStr += "\">";
	tmpStr += "	<dl class=\"mtop\">";
	tmpStr += "		<dt class=\"left\"><img src=\""+homepagepath+"/renewal/images/common/box_upl1.gif\" alt=\"\" \/><\/dt>";
	if (atype == "none"){
		tmpStr += "		<dd><img src=\""+homepagepath+"/renewal/images/common/box_upm1.gif\" alt=\"\" /><\/dd>";
	} else {
		tmpStr += "		<dd><img src=\""+homepagepath+"/renewal/images/common/box_upa1.gif\" alt=\"\" /><\/dd>";
	}
	tmpStr += "		<dt class=\"right\"><img src=\""+homepagepath+"/renewal/images/common/box_upr1.gif\" alt=\"\" \/><\/dt>";
	tmpStr += "	<\/dl>";
	tmpStr += "	<div class=\"mbody\" id=\"msgtxt\"></div>";
	tmpStr += "	<dl class=\"mfooter\">";
	tmpStr += "		<dt class=\"left\"><img src=\""+homepagepath+"/renewal/images/common/box_downl1.gif\" alt=\"\" \/><\/dt>";
	tmpStr += "		<dd><img src=\""+homepagepath+"/renewal/images/common/box_downm1.gif\" alt=\"\" /><\/dd>";
	tmpStr += "		<dt class=\"right\"><img src=\""+homepagepath+"/renewal/images/common/box_downr1.gif\" alt=\"\" \/><\/dt>";
	tmpStr += "	<\/dl>";
	tmpStr += "<\/div>";
	document.write(tmpStr);
}

/* Change Message Layer Text Function */
function chgMsgLayer(mid) {
	var tmpObj = document.getElementById(mid);
	var tmpMsg = document.getElementById("msgtxt");
	if (tmpMsg && tmpObj) tmpMsg.innerHTML = tmpObj.innerHTML;
}

function viewMsgLayer(e, pw, ph) {
	try {
		var standardbody=(document.compatMode=="CSS1Compat")?document.documentElement:document.body; //create reference to common "body" across doctypes
		standardbody.style.overflowX = "";
		standardbody.style.overflowY = "";

		var curr_x, curr_y;
		curr_x = parseFloat((document.all)?event.clientX:e.clientX)-(pw/2); // ÆË¾÷»çÀÌÁî/2
		curr_y = parseFloat((document.all)?event.clientY:e.clientY)+ph;
		curr_y += parseFloat(standardbody.scrollTop);
		var tmpObj = document.getElementById("aigdic");
		if (tmpObj) {
			tmpObj.style.left = (document.all)?curr_x:curr_x+"px";
			tmpObj.style.top = (document.all)?curr_y:curr_y+"px";
		}
	} catch(e) {
		alert(e);
	}
}

var preloadedQ = new Array();
function preload_Qimages() {
	for (var i = 0; i < arguments.length; i++){
		preloadedQ[i] = document.createElement('img');
		preloadedQ[i].setAttribute('src',arguments[i]);
	};
};
preload_Qimages(
	'/renewal/images/layout/tit_quick.gif',
	'/renewal/images/layout/btnq_myaig.gif',
	'/renewal/images/layout/btnq_design.gif',
	'/renewal/images/layout/btnq_recom.gif',
	'/renewal/images/layout/btnq_masterp.gif"',
	'/renewal/images/layout/btnq_branch.gif',
	'/renewal/images/layout/btnq_term.gif',
	'/renewal/images/layout/btn_rollup.gif',
	'/renewal/images/layout/btn_rolldown.gif',
	'/renewal/images/layout/quickbanner.gif'
);