﻿/*
 * Single Sign On Sript file
 *
 * 작성자 : 한빛소프트 김성재 (zeru@hanbitsoft.co.kr)
 * 
 */

//trust site 등록 activex
var ts_vistar_codebase = "http://www.hanbiton.com/cab/TrustSite.cab#version=1,0,0,1";
var ts_vistar_clsid = "07BBFE34-8B6B-4C96-B965-C7C2878118D0";

var errorUrl = "/home/ssoerror.html";

var isVistar = false;
var ts = null;

function CheckOS() { 

	if(navigator.userAgent.indexOf('Win') != -1)
	{ 
		var Version;
		var temp = navigator.userAgent.split(";");
		
		for(i=0;i<temp.length;i++)
		{
			if(temp[i].indexOf('Win') != -1)
			{
				Version = temp[i];
			}
		}
		
		if(Version.indexOf('6.0') != -1)
		{
			var OpSys = "Vistar"; 			
			isVistar = true; 
		} else {
			var OpSys = "Windows Me or NT or 2000"; 
			isVistar = false;
		}
	}	
	
	return OpSys;
}



// Parent Ts Check And Ts Object Load
function LoadCheckParentTS()
{
	if (document.all["hanbitonts"] ) {
		ts = document.all["hanbitonts"];
	}

	if(ts == null)
	{
		if(parent != null && parent != this)
		{
			if(top.ts != null)
				ts = top.ts;
		}
		
	}
	
}



// Ts Object Load
function LoadHanbitOnTS() {

	CheckOS();
	LoadCheckParentTS();
	if (ts != null) {			
		return;
	} else {
		if(isVistar) 
		{			
			var str='<OBJECT id="hanbitonts" codebase="' + ts_vistar_codebase + '" classid="CLSID:' + ts_vistar_clsid + '" style="display:none"></OBJECT>';
			document.write(str);	
			ts = document.all["hanbitonts"];				
		}	
	}		
}


function ActiveXError() {
	// alert("한빛온에서 제공하는 서비스를 모두 이용하시려면 ActiveX를 받아야합니다");
}

function timeOutMessage()
{
	var w = window.open("/MsgPopup/timeout.html", "HanbitON_TimeOut", "width=425,height=290,status=no,scrollbars=no");
	
	if(w != null)
		w.focus();
	else
		alert('장시간 서비스를 이용하지 않아 고객정보\n안전을 위해 자동 로그아웃 됩니다.\n다시 로그인 하시면 서비스를 이용하실 수 있습니다.');		
}


function setCookie( name, value, expiredays ){
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + ";path=/; expires=" + todayDate.toGMTString() + ";"
    //document.cookie = name + "=" + escape( value ) + "; path=" + "/hanbiton" + "; expires=" + todayDate.toGMTString() + ";"
}
	
function setCookieAgree( name, value ){
    document.cookie = name + "=" + escape( value ) + "; domain=hanbiton.com; path=/;" 
}

function clearCookieAgree(name) {
    var expire_date = new Date();
    expire_date.setDate(expire_date.getDate() - 1);
    document.cookie = name + "= " + "; expires=" + expire_date.toGMTString() + "; domain=hanbiton.com; path=/";
}

function getCookie( name )
{	
   var nameOfCookie = name + "=";
   var x = 0;
   while ( x <= document.cookie.length ){
        var y = (x+nameOfCookie.length);
        if ( document.cookie.substring( x, y ) == nameOfCookie ) {
             if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                  endOfCookie = document.cookie.length;
             return unescape( document.cookie.substring( y, endOfCookie ) );
        }
        x = document.cookie.indexOf( " ", x ) + 1;
        if ( x == 0 )
            break;
    }
	return "";
}
