document.write("<script src='http://plugin.inicis.com/inipayFlash/AC_OETags.js' language='javascript'></script>");
document.write("<script src='http://plugin.inicis.com/inipayFlash/easykeytec.js' language='javascript'></script>");
var plugin = "";		// IE È¯°æÀÎÁö Ã¼Å©
var UI_TYPE = "3";
var user_agent = "";
var js_ver = "pay61_flash";
var checkwin;
var wmode = "window";
var merchant_form;
var usekeyprotect = false;

var hasFrame = false;
var frameName = "";
var isProcess = false;
var isIE6 = false;
//==============================================================================================
//	»óÁ¡ Á¤º¸¸¦ ¸®ÅÏÇÕ´Ï´Ù.
//  @param  
function Get_Store_Info()
{
	try{
		
		var info;
		var name;
		var shopObj=new Object();

		for(var i=0;i<merchant_form.elements.length;i++){
			
			name=merchant_form.elements[i].name;
			info=merchant_form.elements[i].value;		
			if(info != "" && info !=null) shopObj[name] = info;
		}

		shopObj.plugin = plugin ;
		shopObj.user_agent = user_agent;
		shopObj.js_ver = js_ver;
		shopObj.pageresult = false;
		shopObj.pagepost = true;
		shopObj.usekeyprotect = usekeyprotect ;
		thisMovie("INIFlash").sendStoreInfo(shopObj);	
	}catch(e){
		alert(e);
	}
}

function detectAgent() {
	var nAgt= navigator.userAgent;
	var fullVersion;
	var browserName;
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		browserName  = "MSIE";
		usekeyprotect = true;
		fullVersion  = parseFloat(nAgt.substring(verOffset+5));
		if(fullVersion==6) isIE6 = true;
	}else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
		browserName  = "Opera";
		usekeyprotect = true;
		fullVersion  = parseFloat(nAgt.substring(verOffset+6));
	}else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
		browserName  = "Firefox";
		usekeyprotect = true;
		fullVersion  = parseFloat(nAgt.substring(verOffset+8));
	}else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
		browserName  = "Chrome";
		usekeyprotect = true;
		fullVersion  = parseFloat(nAgt.substring(verOffset+7));
	}else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 	{
		browserName  = nAgt.substring(nameOffset,verOffset);
		fullVersion  = parseFloat(nAgt.substring(verOffset+1));
		usekeyprotect = true;
	}
	if(navigator.platform != "Win32") usekeyprotect  = false;
	user_agent = browserName  + fullVersion  ;
}
function detectOs() {
	var nAgt= navigator.userAgent;
	var osver;
	var verOffset;
	var temp;
	if ((verOffset=nAgt.indexOf("Windows "))!=-1) {
		temp = nAgt.substring(verOffset);
		osver  = temp.substring(0,temp.indexOf(";"));
	}else if (nAgt.match(/iPhone/i) || (nAgt.match(/iPod/i))) {
		osver  = "iPod/iPhone"
	}else if ((verOffset=nAgt.indexOf("Mac OS"))!=-1) {
		temp = nAgt.substring(verOffset);
		osver  = temp.substring(0,temp.indexOf(";"));
	}else if ((verOffset=nAgt.indexOf("Linux"))!=-1) {
		temp = nAgt.substring(verOffset);
		osver  = temp.substring(0,temp.indexOf(";"));
	}else 	{
		osver  = nAgt;
	}
	return osver  ;
}
function closeLater()
{
	setTimeout("F_Close()",100);
}
function getXMLHttpRequest()
{
  if (window.ActiveXObject){
    try{
      return new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
        return new ActiveXObject("Microsoft.XMLHTTP");
      }catch(e1){ return null;}
    }
  }else if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  }else{
    return null;
  }
}
var httpRequest = null;

function sendRequest(url, params, callback, method)
{
  httpRequest = getXMLHttpRequest();
  var httpMethod = method ? method : 'GET';
  if (httpMethod != 'GET' && httpMethod != 'POST')
  {
    httpMethod = 'GET';
  }
  var httpParams = (params == null || params == '') ? null : params;
  var httpUrl = url;
  if (httpMethod == 'GET' && httpParams != null)
  {
    httpUrl = httpUrl + "?" + httpParams;
  }
  httpRequest.open(httpMethod, httpUrl, true);
  httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  //httpRequest.onreadystatechange = callback;
  httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}
function F_Popup(link, width, height, mname)
{
	var winpops;
	try{
		var pop_win;
		if(mname == "") {
			winpops= window.open(link,"winpops","toolbar=no,menubar=no,resizable=no,scrollbars=yes,left=0,top=0,width=" + width+ ",height=" + height)
		} else {
			var name = String_Apart(mname);
			winpops=window.open(link+name,"winpops","toolbar=0,menubar=0,resizable=0,scrollbars=0,left=0,top=0,width=" + width+ ",height=" + height);	
		}
	}catch (e) {}
} 

function String_Apart(str)
{
	var str1 = str.split("|");
	var str2 = "";

	for(var i=0; i<str1.length; i++){
		str2 += String.fromCharCode(str1[i]);
	}
	return str2.substring(0, str2.length-1);
}


function inipayFlash_load( divid, type, width, height,txURL,layoutURL)
{	
	detectAgent();
	var requiredMajorVersion = 9;
	var requiredMinorVersion = 0;
	var requiredRevision = 28;
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	if(navigator.appName == 'Microsoft Internet Explorer' && navigator.platform == 'Win32')	
	{
		plugin = "ocx";
		wmode = "transparent";
	} else if (navigator.appName != 'Microsoft Internet Explorer' && navigator.platform == 'Win32'){
		plugin = "applet";
		wmode = "transparent";
	}else {
		plugin = "applet";
		wmode = "window";
	}
	var file_name;
	var rtnstr;
	try{if(plugin !="ocx") gthrData();}catch(e){}
if (plugin == "ocx" || hasRequestedVersion) {
	
	isProcess = true;
	if(isIE6 == true) inVisibleComboBox();

	file_name = "http://plugin.inicis.com/inipayFlash/d"+type+"/ini_loader_"+type+".swf";
	
	rtnstr = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ";
	rtnstr += "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0 onerror=OnErr()\" ";
	rtnstr += "width=\'"+width+"'\" height=\'"+height+"'\" id='INIFlash' align=\"middle\">";
	rtnstr += "<param name=\"movie\" value=\'"+file_name+"'  /><param name=\"quality\" value=\"high\" />";
	rtnstr += "<param name=\"bgcolor\" value=\"#ffffff\" />";
	rtnstr += "<param name='allowScriptAccess' value='always' />";
	rtnstr += "<param name=\"FlashVars\" value=\"frameName="+frameName;
	rtnstr += "&layoutURL="+layoutURL+"&txURL="+txURL+"\" /><param name=\"wmode\" value=\"transparent\"  /><embed src=\'"+file_name+"' ";
	rtnstr += "quality=\"high\" bgcolor=\"#ffffff\" width=\'"+width+"'\" height=\'"+height+"'\" ";
	rtnstr += "name='INIFlash' align='middle' wmode ='"+wmode +"'  SWLIVECONNECT='true' allowScriptAccess='always' FlashVars='frameName="+frameName+"&layoutURL="+layoutURL+"&txURL="+txURL+"' ";
	rtnstr += "type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>";
	
	rtnstr += "<script type='text/javascript' event='FSCommand(command,args)' for='INIFlash'>";
	rtnstr += "INIFlash_DoFSCommand(command, args)";
	rtnstr += "</script>";
	divid.innerHTML = rtnstr;
	
	thisMovie("INIFlash").focus();

  } else {  
		divid.style.width = 0;
		divid.innerHTML = "";
		var installmsg  = "INIpayFlash °áÁ¦¸¦ ÇÏ±â À§ÇØ¼­ Flash player 9 ÀÌ»óÀÇ È¯°æÀÌ ÇÊ¿äÇÕ´Ï´Ù. Flash Player¸¦ ¼³Ä¡ ÇÏ½Ã°Ú½À´Ï±î?\n\n";
		installmsg = installmsg + "[È®ÀÎ] À» ´©¸£½Ã¸é ¼³Ä¡ÆäÀÌÁö·Î ÀÌµ¿ÇÕ´Ï´Ù.\n";
		if (confirm( installmsg )){
			window.top.document.location.href = "http://www.macromedia.com/go/getflashplayer"; //document.location.href = szMZInstallUrl;
		}else{
			var info    = "Flash player¸¦ ¼³Ä¡¾ÈÇÔÀ» ¼±ÅÃÇÏ¿´½À´Ï´Ù.\n\n";
			info = info + "Flash player°¡ Áö¿øµÇ´Â È¯°æÀÎÁö È®ÀÎÇÏ¿© ÁÖ½Ê½Ã¿ä.\n";
			alert(info);
		}
	}
}
function gthrData()
{
	try{
	var analytics = (detectOs()+"-"+user_agent)+"-"+screen.width+"*"+screen.height;
	var location_url = (document.location);
	var sel_mid = (merchant_form.mid == null) ? "" : merchant_form.mid.value;
	var sel_paymethod = (merchant_form.gopaymethod == null) ? "" : merchant_form.gopaymethod.value;
	var url = "http://gthr.inicis.com/cgi-bin/g.cgi?ctype=PI&err_type=999999&mid="+sel_mid+"&paymethod="+sel_paymethod+"&err_code=00&err_msg="+analytics+"&server_url="+location_url+"&user_ip=&ftype=F";
	sendRequest(url ,null,showResult,"GET");
	}catch(e){
		createajaxFrame(url);
	}
}

function createajaxFrame(url){
	try{
	var frameID = "gthr";
	var bodyID = document.getElementsByTagName('body')[0];
       var newDiv = document.createElement('div');
		newDiv.id = frameID;
		newDiv.style.position ='absolute';
		newDiv.style.visibility = 'hidden';
		newDiv.innerHTML = "<iframe name='if_gthr' id='if_gthr' src='"+url+"' frameborder='0' scrolling='no' ></iframe>" ; 
		bodyID.appendChild(newDiv);
	}catch(e){
	}
}
//----------------------------------------------------------------------------
//
//  INIpayFlash¸¦ ÀÌ¿ëÇÏ¿© °áÁ¦¸¦ ½ÃÀÛÇÕ´Ï´Ù.
//----------------------------------------------------------------------------
function flashPay(mer_form)
{
	merchant_form = mer_form;
	var txURL = mer_form.action;
	if(parent!=self && self.name!="") {
		var parentArray = parent.document.getElementsByTagName('body');
		if(parentArray.length>0) {hasFrame = true;frameName=self.name;}
	}
	createDivElement("install_layer_xpay");
	if(hasFrame==false) {
		disableScroll();
	}else {parent.document.body.style.overflow = "hidden";} 
	var width ='100%';	var height ='100%';
	var ini_flash_layer = (hasFrame==false) ? document.getElementById("install_layer_xpay") : parent.document.getElementById("install_layer_xpay");
  	ini_flash_layer.style.top  = (hasFrame==false) ? getScrollY() : parent.document.body.scrollTop;
  	ini_flash_layer.style.left = 0;
  	ini_flash_layer.style.width = width; 
  	ini_flash_layer.style.height = height; 

	inipayFlash_load(ini_flash_layer,UI_TYPE,width,height,txURL,"false");
}
function setiniField(name,param){
	try{
	merchant_form[name].value = param;
	}catch(e){
		//alert(e);
	}
}
function submitINIForm(){
	merchant_form.submit();
}
function dispose_flashpay()
{
	try{
	//INIpayEnd();
	if(isIE6 ==true) visibleComboBox();
	(hasFrame==false) ? enableScroll() : parent.document.body.style.overflow = "auto"; 
	var flashLayer = (hasFrame==false) ? document.getElementById("install_layer_xpay") : parent.document.getElementById('install_layer_xpay');
	flashLayer.style.width = 0; 
	flashLayer.style.height = 0; 
	flashLayer.innerHTML = "";
	}catch(e){}	
}
function F_Close(){
	//USE_FLASH = false;
	dispose_flashpay();
	try{flashPayClose();}catch(e){}	
}
function LoadInitechCipher()
{
	try{
	
	var installUrl = "http://plugin.inicis.com/initech/install_flex.js";

	var initechInstall = document.createElement("script"); 
	initechInstall.setAttribute("language", "JavaScript"); 
	initechInstall.setAttribute("type", "text/javascript"); 
	initechInstall.setAttribute("src", installUrl); 
	document.getElementsByTagName('head').item(0).appendChild(initechInstall);
	}catch(e){
		//alert(e);
	}	
}

function createDivElement(frameID)
{	
	try{
		if(document.getElementById(frameID)==null){
			var bodyID = (hasFrame==false) ? document.getElementsByTagName('body')[0] : parent.document.getElementsByTagName('body')[0]; 
			var newDiv = (hasFrame==false) ? document.createElement('div') : parent.document.createElement('div');
			newDiv.id = frameID;
			newDiv.style.position = "absolute";
			newDiv.style.zIndex = 9998;
			bodyID.appendChild(newDiv);
		}
	}catch(e){	alert("createDivElement " +e);	}
}

function checkWindow() {
	
	if(checkwin) {
		if(checkwin.closed) {
			 thisMovie("INIFlash").resultforWindow("popupclose");
		}else{
			self.setTimeout("checkWindow()", 1000);
		}
	} 
}

function openerWin(url,width,height) {
	
	var props = "toolbar=no,menubar=no,resizable=no,scrollbars=yes,left=0,top=0,width=" + width+ ",height=" + height;
	checkwin = window.open(url,'notiWin', props);
	if (checkwin == null) 
	{
		var msg = "ÆË¾÷ÀÌ Â÷´ÜµÇ¾ú½À´Ï´Ù. ÆË¾÷ ¼³Á¤À» Çã¿ëÇÏ¿© ÁÖ½Ê½Ã¿ä.";
		alert(msg);
	}	
	if (checkwin.opener == null) checkwin.opener = window;
	checkwin.opener.name = "opener";
	checkWindow();
}


function thisMovie(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1) {
        if(hasFrame==false) return window[movieName]; 
		else return parent.window[movieName];
    } else {
        if(hasFrame==false) return document[movieName];
		else return parent.document[movieName];
    }
}

function setChar(str){
			
	var output ="";
	var i = 0;				
	while (i<str.length) {
		output += str.substr(i,1);
		if ((i+1)%64 == 0 && i!=0) {
			output += "\n";
		}
		i++;
	}
	return output;
}

function URLEncode(data_str){

	var SAFECHARS = "0123456789"+     // Numeric
     				"ABCDEFGHIJKLMNOPQRSTUVWXYZ"+ // Alphabetic
     				"abcdefghijklmnopqrstuvwxyz"+
     				"-_.!~*'()";     // RFC2396 Mark characters
 	var HEX = "0123456789ABCDEF";
	var plaintext = data_str;
 	var encoded = "";
 	for(var i=0;i<plaintext.length;i++){
  		var ch=plaintext.charAt(i);
     	if(ch==" "){
      		encoded += "+";    // x-www-urlencoded, rather than %20
  		}else if(SAFECHARS.indexOf(ch)!=-1){
      		encoded += ch;
  		}else{
      		var charCode = ch.charCodeAt(0);
   			if(charCode > 255) {
	    		encoded += "+";
   			}else{
    			encoded += "%";
    			encoded += HEX.charAt((charCode >> 4) & 0xF);
    			encoded += HEX.charAt(charCode & 0xF);
   			}
  		}
 	} // for
	
	return encoded;
}

function openAcsWin(url,target_url,param1,param2,param3,param4){
	
	var mObject = new Object();
	mObject.url= (target_url);
   	mObject.pareq1 = (param1);
	mObject.pareq2 = (param2);
	mObject.pareq3 = (param3);
	mObject.pareq4 = (param4);
	
	var prop = "dialogwidth: 450; dialogheight: 550; resizable: no";

	var r = window.showModalDialog(url, mObject,prop);
   	thisMovie("INIFlash").acsValue(r);
}

function INIPayMessage( setValue )
{	
	try{
	var param=URLEncode(setChar(setValue));	
	var iniMsg = Make_FlashPayMessage(param);
	if(iniMsg!=false)	thisMovie("INIFlash").resultforAnsim(retData);
	}catch(e){
		//alert(e);
	}
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function INIFlash_DoFSCommand(command, args) {
	var fscommandObj = isInternetExplorer ? document.all.INIFlash : document.INIFlash;
	if(command=="Ansim"){
		INIPayMessage(args);
	}	
}

function canNavigator()
{
	thisMovie("INIFlash").checkJS("true");	
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY ;
}

function disableScroll()
{
	if( document.body  && document.body.scrollTop) {
	 document.body.style.overflow = "hidden"; 
	} else if( document.documentElement ) {
	document.documentElement.style.overflow = "hidden"; 
	}
}
function enableScroll()
{
	if( document.body && document.body.style.overflow) {
    document.body.style.overflow = "auto"; 
	} else if( document.documentElement && document.documentElement.style.overflow ) {
    document.documentElement.style.overflow = "auto"; 
	}
}

if(typeof window.addEventListener != "undefined")	window.addEventListener("unload",clearEvent, false);
if(typeof window.attachEvent != "undefined" )	window.attachEvent("onunload",clearEvent);		
function clearEvent()
{		
	if( typeof window.detachEvent != "undefined")	window.detachEvent("onunload",clearEvent);				
	if(isProcess==true) dispose_flashpay();
}
//-------------------------------------------------------------
function visibleComboBox(){
	try{
		var select_tag = (hasFrame==false) ? document.getElementsByTagName("select")  : parent.document.getElementsByTagName("select"); 
		for (var i = 0; i < select_tag.length; i++) { 
  		select_tag[i].style.display = "";
		}
	}catch(e){}
}
//--------------------------------------------------------------
function inVisibleComboBox(){
	try{
		var select_tag = (hasFrame==false) ? document.getElementsByTagName("select") : parent.document.getElementsByTagName("select"); 
		for (var i = 0; i < select_tag.length; i++) { 
  		select_tag[i].style.display = "none";
		}
	}catch(e){}
}

function getWinHeight(){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
