﻿    var Status_titles = "UCC 솔루션 & 임대(ASP) 서비스";
    window.status=Status_titles;

    var Domain = document.URL;
    Domain = Domain.split("//"); //.replace("http://","").replace("kr.","")
    Domain = Domain[1].substr(0, Domain[1].indexOf("/"));


    if (Domain == "kr.movieupservice.com") {
        document.domain = "movieupservice.com";
    }
    else {
        try {
            document.domain = "mymovieup.com";
        } catch (e) {
        }
    }
    
   // document.oncontextmenu = nocontextmenu;   // IE5+ 용
    //document.onmousedown = norightclick;      // 다른 브라우저 용

    if (navigator.appName == "Netscape")       //넷스케이프에서만 대문자 E.
    {
        document.captureEvents(Event.MOUSEUP); // mouse up 이벤트를 잡음
    }

    function nocontextmenu() // IE4에서만 적용, 다른 브라우저는 무시
    {
        event.cancelBubble = true;
        event.returnValue = false;
        return false;
    }

    function norightclick(e)   // 다른 모든 브라우저에서 작동
    {
        if (navigator.appName == "Netscape")   // 다시, IE 또는 NAV ?
        {
            if (e.which == 2 || e.which == 3)
                return false;
        }
        else {
            if (event.button == 2 || event.button == 3) {
                event.cancelBubble = true;
                event.returnValue = false;
                return false;
            }
        }
    }
    
// Ajax 용 함수.
var http_request = false;
var id;

function Login(p) {
	if (p == 0) {
		id = document.frm.Id.value;
		var pwd = document.frm.Pwd.value;
		var ck;
		
		if (frm.cookie.checked == true) {
			ck = "Y";
		} else {
			ck = "N";
		}
		
		if (id == '') {
			alert('아이디를 입력해주십시오.');
			document.frm.Id.focus();
			return;
		}
		if (pwd == '') {
			alert('비밀번호를 입력해주십시오.');
			document.frm.Pwd.focus();
			return;
		}

		LoginProcess(id, pwd, 'N', ck);
	} else if (p == 1) {
		LoginProcess(id, pwd, 'Y');
	}
}


function LoginProcess(id, pwd, out, ck) {

	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('XMLHTTP instance를 만들 수 없습니다.');
		return false;
	}
	http_request.onreadystatechange = LoginResult;
	http_request.open('POST', '/Login/LoginP.asp', true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
	http_request.send('ID='+ id +'&PW='+ pwd + '&out=' + out + '&ck=' + ck);
}

function decodeURL(str){
    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str
    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";        // local str to parse as int
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;      // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }
    return s0;

}

function LoginResult() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
				var xmlDoc = http_request.responseXML;
				var userName = xmlDoc.getElementsByTagName("USERNAME")[0].childNodes[0].nodeValue;
				var sites = document.getElementById("GoSite");

				if (userName == "ID") {
				    alert('아이디가 올바르지 않습니다. \n다시 입력해주십시오.'); document.frm.Id.select();
				}
				else if (userName == "Emailcfm") {
				    alert('회원가입 승인진행중입니다. \n'); document.frm.Id.select();
				}
				else if (userName == "CFM_JP") {
				    alert('メール認証を行って下さい。');
				    window.open("http://jp.mymovieup.com/Japan/Login/ReConfirm.asp?UID=" + document.frm.Id.value, "CFM_JP", "width=400,height=293");
				}
				else if (userName == "CFM_US") {
				    alert('Email activation is required.\nPlease check your email.');
				    window.open("http://usa.mymovieup.com/Login/ReConfirm.asp?UID=" + document.frm.Id.value, "CFM", "width=400,height=293");
				}
				else if (userName == "PWD") {
				    alert('비밀번호가 올바르지 않습니다. \n다시 입력해주십시오.'); document.frm.Id.focus();
				}
				else if (userName != "N") {
				    location.href = '/index.asp';
				    /*		if (frm.cookie.checked == true) {
				    setCookie('cookieid',frm.Id.value);
				    alert(frm.Id.value);
				    }*/

				    document.getElementById("divLogin").style.display = "none";
				    document.getElementById("divLogout").style.display = "inline";
				    document.getElementById("divNm").innerHTML = userName;

				    //ID 쿠키 생성 전역변수 id를 활용할 것.
				    /*if (frm.cookie.checked == true) {
				    setCookie('CID', id);
				    }*/
				    var results = xmlDoc.getElementsByTagName("SITE");
				    var skeyResults = xmlDoc.getElementsByTagName("SKEY");
				    var option = null;
				    for (var i = 0; i < results.length; i++) {
				        option = document.createElement("option");
				        option.appendChild(document.createTextNode(results[i].firstChild.nodeValue));
				        //option.style.backgroundColor = "#EAE6D7";
				        //option.style.color = "#FD9420";
				        //option.value = "http://" + results[i].firstChild.nodeValue;
				        option.value = skeyResults[i].firstChild.nodeValue;
				        sites.appendChild(option);
				    }
				}
				else {
				    location.href = '/index.asp';
				    document.frm.Id.value = "";
				    document.frm.Pwd.value = "";
				    document.getElementById("divLogin").style.display = "inline";
				    document.getElementById("divLogout").style.display = "none";
				    for (var i = sites.options.length; i >= 1; i--) {
				        sites.remove(i);
				    }
				}
		} else if (http_request.status == 500) {
			alert('[ERROR] 서버페이지에 장애가 발생하였습니다.\n잠시후 다시 시도해주십시오.');
		} else if (http_request.status == 404) {
			alert('[ERROR] 네트워크에 장애가 발생하였습니다.\n잠시후 다시 시도해주십시오.');
		} else {
			alert('[ERROR] 처리중 장애가 발생하였습니다.\n잠시후 다시 시도해주십시오.');
		}
	}
}

function Move(page) {
	frm.action = location.href;
	frm.target = "_self";
	frm.method = 'post';
	frm.PageNo.value = page;
	frm.submit();
}

function Find(column) {
	if (column == "ID") {
		window.open("/My/LostID.asp", "lostid", "width=394,height=265,top=100,left=100");
	} else {
		window.open("/My/LostPwd.asp", "lostid", "width=394,height=265,top=100,left=100");
	}
}

function EmptyCheck(items,titleMent){ // 공백체크
    var patrn = /\S+/;
	if (!patrn.test(items.value)) {
         alert(titleMent + " 항목을 반드시 입력해 주십시오.");
		 items.value = "";
		 items.focus();
		 return false;
	}
	return true;
}

function goSite() {
	frm.action = '/My/CrntTraffic.asp';
	frm.target = "_self";
	frm.method = 'post';
	setCookie('SelSkey',frm.GoSite.options[frm.GoSite.selectedIndex].value);
	frm.submit();
}

function LoginSub(flg) {
	frm.action = '/Login/LoginSub.asp?out=' + flg + '&cPage=' + location.href;
	frm.target = "_self";
	frm.method = 'post';
	
	if (frm.cookieId.checked == true) {
		frm.ck.value = "Y";
	} else {
		frm.ck.value = "N";
	}
	frm.submit();
}

function initID(obj){
	if (obj.value == '') {
		obj.style.backgroundImage = "url('/images/join/id.gif')";
	}
}

function initPWD(obj){
	if (obj.value == '') {		
		obj.style.backgroundImage = "url('/images/join/pw.gif')";
	}
}

function Only_Num() {
	if(((event.keyCode>=48) && (event.keyCode<=57)) || ((event.keyCode>=96) && (event.keyCode<=105)) ||
		event.keyCode==8 || event.keyCode==9 || event.keyCode==46 || event.keyCode==37 || event.keyCode==39) {
		event.returnValue=true;
	}else {
		event.returnValue=false;
	}
}

function setCookie(name, value) {
	document.cookie = name + '=' + escape( value ) + '; path=/;'
	
}

function getCookie(Name) {
  var search = Name + "="
  if (document.cookie.length > 0) { // 쿠키가 설정되어 있다면
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // 쿠키가 존재하면
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset)
      // 쿠키 값의 마지막 위치 인덱스 번호 설정
      if (end == -1)
        end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
  return "";
}

function saveid(form) {
  var expdate = new Date();
  // 기본적으로 30일동안 기억하게 함. 일수를 조절하려면 * 30에서 숫자를 조절하면 됨
  if (form.checksaveid.checked)
    expdate.setTime(expdate.getTime() + 1000 * 3600 * 24 * 1); // 30일
  else
    expdate.setTime(expdate.getTime() - 1); // 쿠키 삭제조건
  setCookie("saveid", form.id.value, expdate);
}
function getid(form) {
  form.checksaveid.checked = ((form.id.value = getCookie("saveid")) != "");
}

function ViewList(url) {
	POP = window.open( url, "WIN_SUB", "status=0,scrollbars=no,resizable=0,width=800,height=610" );
	
	if (POP == null)
    {
        alert("차단된 팝업을 허용해 주십시요.");
        return;
    }
	POP.focus();
}

function ChangeLan() {
		var SelectLan = frm.SiteLanguage.options[frm.SiteLanguage.selectedIndex].value;
		setCookie('Language',SelectLan);
		
		if (SelectLan == "KR") {
			parent.location.href = "http://kr.mymovieup.com/index.asp";
		}
		if (SelectLan == "JP") {
			parent.location.href = "http://jp.mymovieup.com/Japan/index.asp";
		}
		if (SelectLan == "EN") {
			parent.location.href = "http://www.mymovieup.com/index.asp";
		}
	}

function newsletter() {
		window.open("/NewsLetter/LetterApply.asp","Letter","width=393,height=330")
	}
	
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

    function ResizeWindow()
    {
        var num = 30;
        var x = 0;
        var y = 0;
        
        x = (document.body.scrollWidth > 1000) ? 1000 : document.body.scrollWidth;
        y = (document.body.scrollHeight > 900) ? 900 : document.body.scrollHeight;
        
        if (navigator.appVersion.indexOf("MSIE 6") > -1) num = 40;
        
        window.resizeTo(x-5,0);    
        window.resizeBy(1,y-num);
    }    
    
    function PopupWindow(strURL, strID, nWidth, nHight)
    {
	    winpos = "left=" + ((window.screen.width-"+nWidth+")/2) + ",top=" + ((window.screen.height-"+nHight+")/2);
	    winstyle="width="+nWidth+",height="+nHight+",status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
	    var win = window.open(strURL, strID ,winstyle);
	    //alert(strURL+" "+strID+" "+winstyle);
	    if (win == null)
        {
            alert("차단된 팝업을 허용해 주십시요.");
            return;
        }
	    win.focus();
    }	
    
    function OpenWin() 
    {
        var f = document.form1;
        
        var height_ =400;
        var width_ = 340;
        var left_ = screen.width;
        var top_ = screen.height;

        left_ = left_/2 - (width_/2);
        top_ = top_/2 - (height_/2);

        src = window.open('about:blank','AuthFrmUp',
          'height='+height_+',width='+width_+',status=yes,scrollbars=no,resizable=no,left='+left_+',top='+top_+'');
          
        try{
            if (src == null)
            {
                alert("차단된 팝업을 허용해 주십시요. \n\n도구(T)->팝업 차단(P)->팝업 차단 사용 안함(B)");
                return false;
            } 
            
            f.target = "AuthFrmUp";
            f.method = "post";
            f.action ="PhoneSend.aspx";
            f.submit();
            
            self.opener = self
            window.close()
        }
        catch(e)
        {
            alert("차단된 팝업을 허용해 주십시요. \n\n도구(T)->팝업 차단(P)->팝업 차단 사용 안함(B)");
        } 
    }
