﻿document.domain = "uforia.com";

document.writeln("<" + "script language=\"javascript\" src=\"/Common/javascriptConfig.aspx\"></" + "script>");

function printSWF(id, flashUri, vWidth, vHeight, winMode, bgColor, param) {
    var _obj_ = "";
    _obj_ = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="' + vWidth + '" height="' + vHeight + '" id="' + id + '" align="middle">';
    _obj_ += '<param name="allowScriptAccess" value="always" />';
    _obj_ += '<param name="allowFullScreen" value="true" />';
    _obj_ += '<param name="movie" value="' + flashUri + '" />';
    _obj_ += '<param name="quality" value="high" />';
    _obj_ += '<param name="wmode" value="' + winMode + '" />';
    _obj_ += '<param name="bgcolor" value="' + bgColor + '" />';
    _obj_ += '<param name="flashvars" value="' + param + '"/>';
    _obj_ += '<embed src="' + flashUri + '?' + param + '" quality="high" wmode="' + winMode + '" bgcolor="' + bgColor + '" width="' + vWidth + '" height="' + vHeight + '" id="' + id + '" align="middle" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed>    ';
    _obj_ += '</object>';
    document.writeln(_obj_);

    eval("window." + id + " = document.getElementById('" + id + "');");
}

function CheckStr(strOriginal, strFind, strChange) {
    var position, strOri_Length;
    position = strOriginal.indexOf(strFind);

    while (position != -1) {
        strOriginal = strOriginal.replace(strFind, strChange);
        position = strOriginal.indexOf(strFind);
    }

    strOri_Length = strOriginal.length;
    return strOri_Length;
}

function UpInputTxt(strInput) {
    var strPath = self.location.toString();

    var intPathLimit = strPath.indexOf('/', 8);

    strPath = strPath.substring(0, intPathLimit);

    strUrl = "http://image.uforia.com/upfrm.aspx?txt=" + strInput + "&returnurl=" + strPath + "/Common/upend.html";

    WindowOpenCenter(strUrl, 440, 200, "WinUp", "no");
}

function UserUpInputTxt(strInput, ssel) {
    var strPath = self.location.toString();

    var intPathLimit = strPath.indexOf('/', 8);

    strPath = strPath.substring(0, intPathLimit);

    var strPage = "upfrm.aspx";

    if (ssel == 1) {
        strPage = "upfrm3king.aspx";
        strUrl = "http://image.uforia.com/" + strPage + "?txt=" + strInput + "&returnurl=" + strPath + "/Common/upend.html";

        WindowOpenCenter(strUrl, 400, 200, "WinUp", "no");
    }
}

function WindowOpenCenter(strUrl, intWidth, intHeight, winName, strScrollbar) {
    if (strScrollbar == null) {
        strScrollbar = "no";
    }

    var winW = intWidth;
    var winH = intHeight;

    var winL = (screen.width - winW) / 2;
    var winT = (screen.height - winH) / 2;

    var win = window.open(strUrl, winName, "width=" + winW + ",height=" + winH + ",scrollbars=" + strScrollbar + ",resizable=no,top=" + winT + ", left=" + winL);

    return win;
}

function OpenTerms() {
    WindowOpenCenter(this.GLOBAL_UFORIA_URL + "/Etc/terms_of_service.html", 720, 500, "WinTerms", "yes");
}

function OpenPolicy() {
    WindowOpenCenter(this.GLOBAL_UFORIA_URL + "/Etc/privacy_policy.html", 720, 500, "WinPolicy", "yes");
}

this.ImgViewRun = false;

function MakeViewImagDiv() {
    var divBlank = document.createElement("DIV");
    divBlank.id = "DivViewBackground"
    divBlank.style.backgroundColor = "white";
    divBlank.style.filter = "alpha(opacity=80)";
    divBlank.style.position = "absolute";
    divBlank.style.visibility = "hidden";
    divBlank.style.zIndex = 9998;

    var divLoading = document.createElement("DIV");
    divLoading.id = "DivViewLoading"
    divLoading.style.position = "absolute";
    divLoading.style.visibility = "hidden";
    divLoading.style.zIndex = 9999;
    divLoading.innerHTML = "<font color='#ffffff'>Loading...</font>";

    var divContent = document.createElement("DIV");
    divContent.id = "DivViewContent"
    divContent.style.position = "absolute";
    divContent.style.visibility = "hidden";
    divContent.style.zIndex = 10000;

    document.body.appendChild(divBlank);
    document.body.appendChild(divLoading);
    document.body.appendChild(divContent);
}

function ViewImage(sval) {
    if (navigator.appName.indexOf("Microsoft") > -1) {


        if (!this.ImgViewRun) {
            MakeViewImagDiv();
            this.ImgViewRun = true;
        }

        var divBlank = document.getElementById("DivViewBackground");
        var divLoading = document.getElementById("DivViewLoading");
        var divContent = document.getElementById("DivViewContent");

        var loadImg = document.createElement("img");
        loadImg.id = "ImgViewContent"
        loadImg.style.cursor = "hand";
        loadImg.attachEvent("onclick", CloseViewImg);
        loadImg.setAttribute("src", sval);

        divContent.appendChild(loadImg);

        //Select Tag 숨기기
        var selectobjects = document.getElementsByTagName("select");
        for (u = 0; u < selectobjects.length; u++) selectobjects[u].style.display = "none";

        divBlank.style.filter = "alpha(opacity=60)";
        if (getIEVersionNumber() <= 6) {
            divBlank.style.backgroundColor = "#d6d3ce";
        } else {
            divBlank.style.backgroundColor = "black";
        }
        divBlank.style.top = 0;
        divBlank.style.left = 0;

        var scleft = document.body.scrollLeft;
        var sctop = document.body.scrollTop;

        var screenwidth = document.body.clientWidth;
        var screenheight = document.body.clientHeight;

        divBlank.style.width = screenwidth + scleft;
        divBlank.style.height = screenheight + sctop;

        //Loading 이미지를 먼저 보여주고
        divBlank.style.visibility = "visible";
        divLoading.style.visibility = "visible";

        //이미지가 아직 로드되지 않았으면 다시 호출한다.
        if (loadImg.getAttribute("complete") == "false") {
            ViewImage(sval);
        }

        //Loading 이미지를 숨기고
        divLoading.style.visibility = "hidden";

        //Content위치를 조정한 다음 보여준다.
        var imgWidth = parseInt(loadImg.getAttribute("width"));
        var imgHeight = parseInt(loadImg.getAttribute("height"));

        if (imgWidth < 800) {
            imgWidth = 800;
        }

        if (imgHeight < 600) {
            imgHeight = 600;
        }

        if (imgWidth < 1024) {
            imgWidth = 1024;
        }

        if (imgHeight < 768) {
            imgWidth = 768;
        }


        divContent.style.left = (screenwidth / 2) - (imgWidth / 2);
        divContent.style.top = ((screenheight / 2) - (imgHeight / 2)) + sctop;

        //Content를 보여준다.
        divContent.style.visibility = "visible";
    }
    else {
        window.open(sval, "", "");
    }
}


function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

function CloseViewImg() {
    var selectobjects = document.getElementsByTagName("select");
    for (u = 0; u < selectobjects.length; u++) selectobjects[u].style.display = "";

    var divBlank = document.getElementById("DivViewBackground");
    var divLoading = document.getElementById("DivViewLoading");
    var divContent = document.getElementById("DivViewContent");

    divBlank.style.visibility = "hidden";
    divLoading.style.visibility = "hidden";
    divContent.style.visibility = "hidden";

    var loadImg = document.getElementById("ImgViewContent");
    divContent.removeChild(loadImg);

}

function vod_play(play_url, width, height) {

    var width_val = 320;
    var height_val = 310;
    if (width) width_val = width;
    if (height) height_val = height;
    str = "<object id=\"NSPlay\" width=" + width_val + " height=" + height_val + " viewastext style=\"z-index:1\" classid=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\">"
        + "<param name=\"FileName\" value=\"" + play_url + "\">"
        + "<param name=\"ANIMATIONATSTART\" value=\"1\">"
        + "<param name=\"AUTOSTART\" value=\"1\">"
        + "<param name=\"BALANCE\" value=\"0\">"
        + "<param name=\"CURRENTMARKER\" value=\"0\">"
        + "<param name=\"CURRENTPOSITION\" value=\"0\">"
        + "<param name=\"DISPLAYMODE\" value=\"4\">"
        + "<param name=\"ENABLECONTEXTMENU\" value=\"0\">"
        + "<param name=\"ENABLED\" value=\"1\">"
        + "<param name=\"FULLSCREEN\" value=\"0\">"
        + "<param name=\"INVOKEURLS\" value=\"1\">"
        + "<param name=\"PLAYCOUNT\" value=\"1\">"
        + "<param name=\"RATE\" value=\"1\">"
        + "<param name=\"SHOWCONTROLS\" value=\"1\">"
        + "<param name=\"SHOWSTATUSBAR\" value=\"-1\">"
        + "<param name=\"STRETCHTOFIT\" value=\"0\">"
        + "<param name=\"TRANSPARENTATSTART\" value=\"1\">"
        + "<param name=\"UIMODE\" value=\"FULL\">"
        + "<param name=\"displaybackcolor\" value=\"0\">"
        + "</object>"

    return str;
}

function vod_playHiddenBars(play_url, width, height) {

    var width_val = 320;
    var height_val = 310;
    if (width) width_val = width;
    if (height) height_val = height;
    str = "<object id=\"NSPlayHidden\" width=" + width_val + " height=" + height_val + " viewastext style=\"z-index:1\" classid=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\">"
        + "<param name=\"FileName\" value=\"" + play_url + "\">"
        + "<param name=\"ANIMATIONATSTART\" value=\"1\">"
        + "<param name=\"AUTOSTART\" value=\"1\">"
        + "<param name=\"BALANCE\" value=\"0\">"
        + "<param name=\"CURRENTMARKER\" value=\"0\">"
        + "<param name=\"CURRENTPOSITION\" value=\"0\">"
        + "<param name=\"DISPLAYMODE\" value=\"4\">"
        + "<param name=\"ENABLECONTEXTMENU\" value=\"0\">"
        + "<param name=\"ENABLED\" value=\"1\">"
        + "<param name=\"FULLSCREEN\" value=\"0\">"
        + "<param name=\"INVOKEURLS\" value=\"1\">"
        + "<param name=\"PLAYCOUNT\" value=\"1\">"
        + "<param name=\"RATE\" value=\"1\">"
        + "<param name=\"SHOWCONTROLS\" value=\"0\">"
        + "<param name=\"SHOWSTATUSBAR\" value=\"0\">"
        + "<param name=\"STRETCHTOFIT\" value=\"0\">"
        + "<param name=\"TRANSPARENTATSTART\" value=\"1\">"
        + "<param name=\"UIMODE\" value=\"FULL\">"
        + "<param name=\"displaybackcolor\" value=\"0\">"
        + "</object>"

    return str;
}

this.divPopupRun = false;
this.popupTimer;

function MakePopDiv() {
    var divBG = document.createElement("DIV");
    divBG.style.display = "none";
    divBG.id = "DivPopBackground"
    divBG.style.backgroundColor = "#000000";
    divBG.style.filter = "alpha(opacity=60)";
    divBG.style.opacity = "0.6";
    divBG.style.position = "absolute";
    divBG.style.zIndex = 9998;

    var divPOP = document.createElement("DIV");
    divPOP.style.display = "none";
    divPOP.id = "DivPopContent"
    divPOP.style.position = "absolute";
    divPOP.style.backgroundColor = "#ffffff";
    divPOP.style.padding = "10 10 10 10";
    divPOP.style.zIndex = 10000;

    var objBody = document.getElementsByTagName("body").item(0);
    objBody.appendChild(divBG);
    objBody.appendChild(divPOP);
}

function ViewPopup(sSrc, sWidth, sHeight, sScroll) {

    if (!this.divPopupRun) {
        MakePopDiv();
        this.divPopupRun = true;
    }
    var divBG = document.getElementById("DivPopBackground");
    var divPOP = document.getElementById("DivPopContent");

    if (window.addEventListener) {
        divBG.addEventListener("click", ClosePopDiv, false);
    } else {
        divBG.attachEvent("onclick", ClosePopDiv);
    }

    //Select Tag 숨기기
    var selectobjects = document.getElementsByTagName("select");
    for (u = 0; u < selectobjects.length; u++) selectobjects[u].style.display = "none";

    var iframeTag = "<iframe id='divPopiFrame' name='divPopiFrame' src='" + sSrc + "' width=" + sWidth + " height=" + sHeight + " scrolling=no frameborder=0 ></iframe>";

    //	var iFrmObj = document.createElement("IFRAME"); 
    //	iFrmObj.name = "divPopiFrame"; 
    //	iFrmObj.id = "divPopiFrame"; 
    //	iFrmObj.src = sSrc; 
    //	iFrmObj.scrolling = "no"; 
    //	iFrmObj.frameborder = "0"; 
    //
    //	iFrmObj.style.width = sWidth;
    //	iFrmObj.style.height = sHeight;
    //	iFrmObj.style.border = "none"; 
    //
    divBG.style.display = "";
    //			
    //	divPOP.appendChild(iFrmObj); 
    divPOP.innerHTML = iframeTag;

    var scleft = document.body.scrollLeft;
    var sctop = document.body.scrollTop;

    var screenwidth = document.body.clientWidth;
    var screenheight = document.body.clientHeight;

    var tmp = getPageSize();
    divBG.style.top = 0;
    divBG.style.left = 0;
    divBG.style.width = tmp[0];
    divBG.style.height = tmp[1];


    divPOP.style.left = (screenwidth / 2) - (sWidth / 2);
    divPOP.style.top = ((screenheight / 2) - (sHeight / 2)) + sctop;

    divPOP.style.height = sHeight;
    divPOP.style.display = "";

    if (sScroll) { this.popupTimer = window.setInterval("scrollPopDiv()", 1); }
}


function ClosePopDiv() {
    clearTimeout(this.popupTimer);

    var selectobjects = document.getElementsByTagName("select");
    for (u = 0; u < selectobjects.length; u++) selectobjects[u].style.display = "";

    var divBG = document.getElementById("DivPopBackground");
    var divPOP = document.getElementById("DivPopContent");

    //    var iFrmObj = document.getElementById("divPopiFrame");
    //    divPOP.removeChild(iFrmObj);
    divPOP.innerHTML = "";

    divBG.style.display = "none";
    divPOP.style.display = "none";

}

function scrollPopDiv() {
    try {
        if (document.getElementById('DivPopContent')) {
            var divPOP = document.getElementById('DivPopContent');
            divPOP.style.top = ((document.body.clientHeight / 2) - (divPOP.offsetHeight / 2)) + document.body.scrollTop;
        }
    } catch (e) {
        //	
    }
}



function MakeViewImagDiv2() {
    var divBlank = document.createElement("DIV");
    divBlank.style.display = "none";
    divBlank.id = "DivViewBackground"
    divBlank.style.backgroundColor = "#000000";
    divBlank.style.filter = "alpha(opacity=60)";
    divBlank.style.opacity = "0.6";
    divBlank.style.position = "absolute";

    divBlank.style.zIndex = 9998;

    var divLoading = document.createElement("DIV");
    divLoading.style.display = "none";
    divLoading.id = "DivViewLoading"
    divLoading.style.position = "absolute";

    divLoading.style.zIndex = 9999;
    divLoading.innerHTML = "<font color='#ffffff'>Loading...</font>";

    var divContent = document.createElement("DIV");
    divContent.style.display = "none";
    divContent.id = "DivViewContent"
    divContent.style.position = "absolute";
    divContent.style.backgroundColor = "#ffffff";
    divContent.style.padding = "10 10 10 10";
    divContent.style.zIndex = 10000;

    var objBody = document.getElementsByTagName("body").item(0);
    objBody.appendChild(divBlank);
    objBody.appendChild(divLoading);
    objBody.appendChild(divContent);
}

function ViewImage2(sval) {

    if (!this.ImgViewRun) {
        MakeViewImagDiv2();
        this.ImgViewRun = true;
    }
    var divBlank = document.getElementById("DivViewBackground");
    var divLoading = document.getElementById("DivViewLoading");
    var divContent = document.getElementById("DivViewContent");

    //Select Tag 숨기기
    var selectobjects = document.getElementsByTagName("select");
    for (u = 0; u < selectobjects.length; u++) selectobjects[u].style.display = "none";

    var loadImg = new Image();
    loadImg.id = "ImgViewContent"
    loadImg.style.cursor = "hand";

    try {
        loadImg.style.cursor = "pointer";
    } catch (e) {
        //ff
    }

    loadImg.src = sval;
    if (window.addEventListener) {
        loadImg.addEventListener("click", CloseViewImg2, false);
    } else {
        loadImg.attachEvent("onclick", CloseViewImg2);
    }

    divBlank.style.display = "";
    divLoading.style.display = "";


    if (loadImg.width == 0) {

        setTimeout("ViewImage2('" + sval + "')", 500);

    } else {
        var imgWidth = parseInt(loadImg.width);
        var imgHeight = parseInt(loadImg.height);

        divContent.appendChild(loadImg);

        var scleft = document.body.scrollLeft;
        var sctop = document.body.scrollTop;

        var screenwidth = document.body.clientWidth;
        var screenheight = document.body.clientHeight;

        var tmp = getPageSize();
        divBlank.style.top = 0;
        divBlank.style.left = 0;
        divBlank.style.width = tmp[0];
        divBlank.style.height = tmp[1];


        divContent.style.left = (screenwidth / 2) - (imgWidth / 2);
        divContent.style.top = ((screenheight / 2) - (imgHeight / 2)) + sctop;


        divContent.style.display = "";
        divLoading.style.display = "none";
    }

}

function CloseViewImg2() {
    var selectobjects = document.getElementsByTagName("select");
    for (u = 0; u < selectobjects.length; u++) selectobjects[u].style.display = "";

    var divBlank = document.getElementById("DivViewBackground");
    var divLoading = document.getElementById("DivViewLoading");
    var divContent = document.getElementById("DivViewContent");

    divBlank.style.display = "none";
    divLoading.style.display = "none";
    divContent.style.display = "none";

    var loadImg = document.getElementById("ImgViewContent");
    divContent.removeChild(loadImg);

}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    //	console.log(self.innerWidth);
    //	console.log(document.documentElement.clientWidth);

    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    //	console.log("xScroll " + xScroll)
    //	console.log("windowWidth " + windowWidth)

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    //	console.log("pageWidth " + pageWidth)

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}
