﻿var timeout = "";
var secs = timeout;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var openW = 0;
function selectSubjects(subjectid)
{
    if(document.getElementById("hdIDs").value != "")
    {
        var lenID = document.getElementById("hdIDs").value.indexOf(subjectid);       
        if(lenID > -1)
        {
            var strIDs = document.getElementById("hdIDs").value; 
            var strNewIDs = ","+subjectid;                  
            document.getElementById("hdIDs").value = strIDs.replace(strNewIDs,"");
        }
        else
            document.getElementById("hdIDs").value = document.getElementById("hdIDs").value +","+ subjectid;	            
    }
    else
        document.getElementById("hdIDs").value = document.getElementById("hdIDs").value +","+ subjectid;
}

function hideHome() {
//    document.getElementById("mHome").style.visibility = "hidden";
//    document.getElementById("mHome").style.display = "none";
    document.getElementById("mHome").innerHTML = "<span class='headerMenuHome'>Home</span>";

}

function highlightMenu(menuID) {

    document.getElementById(menuID).className = 'headerMenuNotLoggedInSelected';

}

function openTitle(appName, appDirName) {
    //setTimeout();
    var strBrowser = navigator.userAgent.toLowerCase();
    var h = screen.height
    var w = screen.width
    //h = "775px";
    var pageURL = "launchPage.aspx?app=" + appName + "&appDir=" + appDirName;
    if (appName.indexOf("_Flash") > -1) {
        var strBrowser = navigator.userAgent.toLowerCase();
        var h = screen.height
        var w = screen.width
        h = h + 20;
        w = 800;
        h = 600;
        if (window.screen) {
            if (strBrowser.indexOf('applewebkit') > 0) {
                w = window.screen.availWidth;
                h = window.screen.availHeight - 50;
            }
            else {
                w = window.screen.availWidth;
                h = window.screen.availHeight;
            }
        }
        document.getElementById("JSandCSS1_hdStopClock").value = 1;
        window.open(pageURL, "newwin", "toolbar=no,location=no,directories=no,menubar=no,resizable=yes," + 'width=' + w + ',height=' + h + ',top=0,left=0');
        return;
    }
    if(appDirName.indexOf("_atv")>-1) {
        document.getElementById("JSandCSS1_hdStopClock").value = 1;
        var windopts = "toolbar=no,location=no,directories=no,menubar=no,resizable=yes," + 'width=' + w + ',height=' + h + ',top=0,left=0';
        window.open(pageURL, "Home",windopts);
        return;
    }
    if (pageURL != 'NULL') {
        var windopts = "width=1024" + ",height= " + h + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
        if (strBrowser.indexOf('msie 7') > 0)
        //windopts = "width=1050" + ",height=   " + h + ",toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
            windopts = "width=1024" + ",height=780px " + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
        else if (strBrowser.indexOf('msie') > 0)
            windopts = "width=1024" + ",height= 780px,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
        else if (strBrowser.indexOf('firefox') > 0)
        //windopts = "width=1024" + ",height=   " + h + ",toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
            windopts = "width=1024" + ",height=780px " + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
        else if (strBrowser.indexOf('safari') > 0)
            windopts = "width=1024" + ",height= 780px,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
        else if (strBrowser.indexOf('chrome') > 0)
            windopts = "width=1024" + ",height= 780px,titlebar=no;toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top=" + (screen.height - 700) / 2 + ",left=" + (screen.width - 1050) / 2;
        if (document.getElementById("JSandCSS1_hdStopClock") != null)
            document.getElementById("JSandCSS1_hdStopClock").value = 1;
        window.open(pageURL, "Home", windopts);
    }
    else {
        alert('System not found');
    }

}

function loadText(url, divName) {

    Ext.get(divName).load({
        url: 'templates/modules/' + url
    });

}

function LoadAudio() {
    var flashvars = {};
    var params = {
        allowscriptaccess: "sameDomain",
        bgcolor: "#ffffff"
    };
    var attributes = {
        id: "audioPlayer",
        name: "audioPlayerPlayerName"
    };
    swfobject.embedSWF("audioPlayer.swf", "speakerDiv", "25", "25", "10.0.0", "expressInstall.swf", flashvars, params, attributes);

}

function playSound(url) {
    document.getElementById("audioPlayer").playSound(url);
}
var x; var y; 
    function setXY()
    {
       x="1";
       y="1";
    }
    function getXY(event)
    { 
       x=event.clientX;
       y=event.clientY;            
    }
    function doLogout(event)
    {
        var strBrowser = navigator.userAgent.toLowerCase();  
//        if(strBrowser.indexOf('firefox') >0)
//        {
//            alert(x +" , "+ y);
//            if(x == undefined && y == undefined)
//            {
//               alert("this is fireFox ");
//            }
//            //window.location = "Logout.aspx";
//        }
//          
//        if (strBrowser.indexOf('firefox')>0)
//        {
//            if(y < 1 && y > -10)
//            {
//                window.location = "Logout.aspx";
//            }
//        }
//        
        if (strBrowser.indexOf('msie')>0)
        { 
            x=event.clientX;
            y=event.clientY;      
            if(y < 1)
            {       
                window.location = "Logout.aspx";
            }
        }
    }
    function getCookie(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            // alert("cs = " + c_start);
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1)
                    c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return "";
    }
    function setCookie(c_name) {
        if (document.getElementById("chkStartup") != null)
            document.cookie = c_name + "=" + document.getElementById("chkStartup").checked;
        else
            document.cookie = c_name + "=false";
    }
    function checkCookie(c_name) {
        var startup = getCookie(c_name);
        if (startup == "" || startup == undefined) {
            setCookie(c_name);
            return true;
        }
        if (startup != null && startup != "") {
            return startup;
        }
        else {
            if (startup != null && startup != "") {
                setCookie(c_name);
                return true;
            }
            return true;
        }
    }
    function showIndex(str) {
        document.cookie = "c_index=" + str;
    }
    function loadLastIndex() {
        if (checkCookie('c_index') != undefined) {
            window.location.hash = checkCookie('c_index') + 1;
        }
    }
    function compareText(txtFirst, txtSecond, valCompare, boxno) {
        txtFirst = document.getElementById(txtFirst);
        txtSecond = document.getElementById(txtSecond);
        valCompare = document.getElementById(valCompare);
        if (boxno == 2) {
            if (txtFirst.value != "") {
                if (txtFirst.value != txtSecond.value) {
                    ValidatorEnable(valCompare, true);
                    return;
                }
                else
                    ValidatorEnable(valCompare, false);
            }
            else
                ValidatorEnable(valCompare, false);
        }
        if (txtFirst.value != "" && txtSecond.value != "") {
            if (txtFirst.value != txtSecond.value)
                ValidatorEnable(valCompare, true);
            else
                ValidatorEnable(valCompare, false);
        }
        else
            ValidatorEnable(valCompare, false);
    }
    function openPPproducts(pageName) {
          var pageURL = "http://www.primalpictures.com/"+pageName;
    
        var windopts = "toolbar=1,location=1,directories=1,menubar=1,resizable=yes";
        window.open(pageURL, "",windopts);


    }
    function getRootFolder(mediaURL) {
        var strPath = window.location.href;
        var ct = strPath.lastIndexOf("/");        
        strPath = strPath.substring(0, ct + 1);
        document.getElementById("hdRootFolder").value = strPath + "cedaandp/" + mediaURL.substring(0, mediaURL.lastIndexOf("/") + 1);
        document.getElementById("hdPath").value = mediaURL.substring(mediaURL.lastIndexOf("/") + 1).replace(".jpg", ".xml");
        alert("ff - "+mediaURL);
        //varFolderPath = strPath;
    }
    function showSlideViewer(mediaURL) {
        $(document).ready(function () {           
            $('#btndf').click(function () {
                //centerPopup(); // Centering with Css
                loadPopup(); // Load PopUp
            });
            $('#aClose').click(function () {
                disablePopup();
            });

            {
                document.getElementById("hdRootFolder").value = "";
                document.getElementById("hdPath").value = "";
                var strPath = window.location.href;
                var ct = strPath.lastIndexOf("/");
                strPath = strPath.substring(0, ct + 1);
                document.getElementById("hdRootFolder").value = strPath + "cedaandp/" + mediaURL.substring(0, mediaURL.lastIndexOf("/") + 1);
                document.getElementById("hdPath").value = mediaURL.substring(mediaURL.lastIndexOf("/") + 1).replace(".jpg", ".xml");
                // getRootFolder(mediaURL);
                centerPopup(); // Centering with Css
                loadPopup(); // Load PopUp
                $('#viewSlide').load('SlideViewer.aspx', function () {
                    //alert('Load was performed.');
                });

            }

            $('#btnCancelPopup').click(function () {
                disablePopup();
            });

            var popupStatus = 0;
            function loadPopup() {

                $("#backgroundPopup").css({ "opacity": "0.7" });
                $("#backgroundPopup").fadeIn("slow");
                $("#dvslideViewer").fadeIn("slow");

            }
            function disablePopup() {

                $("#backgroundPopup").fadeOut("slow");
                $("#dvslideViewer").fadeOut("slow");
            }

            function centerPopup() {
                var windowWidth = document.documentElement.clientWidth;
                var windowHeight = document.documentElement.clientHeight;
                var popupHeight = "650"; // $("#customerPopUpForm").height();
                var popupWidth = "980"; // $("#customerPopUpForm").width();
                //centering               
                $("#dvslideViewer").css({
                    "position": "absolute",
                    "top": 20,
                    "left": (screen.width / 2) - (popupWidth / 2)
                });
                //only need force for IE6

                $("#backgroundPopup").css({
                    "height": windowHeight
                });
            }
        });
    }   
    function setTimeoutAlert() {
        if (document.getElementById("JSandCSS1_hdStopClock").value == 0) {
            if (document.getElementById("JSandCSS1_hdTimeout").value > 1) {
                secs = parseInt(document.getElementById("JSandCSS1_hdTimeout").value) * 60;
                setTimeout('doLogout();', 1000);
            }
        }
        else
            secs = parseInt(document.getElementById("JSandCSS1_hdTimeout").value) * 60; 
    }
    function showAlert() {
        if (confirm('Are you sure you want to leave the page?'))// if (confirm('The application will time out in 1 minutes. If you wish to remain logged in, please click on OK'))
            window.location = "logout.aspx?ia=y";
        else
            setTimeoutAlert();        
    }
//    function doLogout() {
//        if (document.getElementById("JSandCSS1_hdStopClock").value == 0) {            
//            if (document.getElementById('JSandCSS1_hdClickOk').value == 1) {
//                document.getElementById('JSandCSS1_hdClickOk').value = 0;
//                openW = 0;
//                secs = parseInt(document.getElementById("JSandCSS1_hdTimeout").value) * 60; 
//            }
//            if (secs == 0) {
//                // window.location = "logout.aspx?ia=y";
//                return;
//            }
//            else {
//                var t = 0;
//                self.status = secs
//                secs = secs - 1
//                timerRunning = true
//                timerID = self.setTimeout("doLogout()", delay);
//                if (openW == 0 && secs == 60) {
//                    //                var centerWidth = (window.screen.width - 350) / 2;
//                    //                var centerHeight = (window.screen.height - 300) / 2;
//                    //                var windopts = "titlebar=no,status=no,fullscreen=no,channelmode=no,toolbar=no,location=no,directories=no,menubar=no,resizable=no,width=350,height=80,left=" + 
//                    //                centerWidth + ",top=" + centerHeight;
//                    //                window.open("confirmAlert.aspx", "Renew Session", windopts, null);
//                    showConfirmationAlert();
//                    $('a[name=modal]').click();
//                    document.getElementById('JSandCSS1_hdClickOk').value = 0;
//                    openW = 1
//                    doLogoutIfNoResponse(60);
//                }
//            }
//        }
//        else
//            secs = parseInt(document.getElementById("JSandCSS1_hdTimeout").value) * 60;    
//    }
    function noTimeOut() {
        timerRunning = false;
        secs = parseInt(document.getElementById("JSandCSS1_hdTimeout").value) * 60; 
        document.getElementById('JSandCSS1_hdClickOk').value = 1; //window.opener.document.getElementById('JSandCSS1_hdClickOk').value = 1;
        openW = 0;
        //window.close();
    }
    function doTimeOut() {
        document.getElementById("JSandCSS1_hdLogin").value = 0;
        document.getElementById('JSandCSS1_hdClickOk').value = 2;
        document.getElementById("JSandCSS1_hdStopClock").value =1;
        window.location = "logout.aspx?ia=y"; //window.opener.location = "logout.aspx?ia=y";
        //window.close();
    }
    function doLogoutIfNoResponse(varTimeOut) 
    {
        if (document.getElementById("JSandCSS1_hdStopClock").value == 0) 
        {
            if (document.getElementById('JSandCSS1_hdClickOk').value == 1)
                return;
            secs = varTimeOut;
            if (secs == 0) {
                document.getElementById("JSandCSS1_hdLogin").value = 0;
                document.getElementById("JSandCSS1_hdTimeout").value = 0;
                document.getElementById('JSandCSS1_hdClickOk').value = 2;
                document.getElementById("JSandCSS1_hdStopClock").value = 1;
                window.location = "logout.aspx?ia=y";
                //window.close();
            }
            else {
                var t = 0;
                self.status = secs
                secs = secs - 1
                timerRunning = true
                timerID = self.setTimeout("doLogoutIfNoResponse(" + secs + ")", 1000)
            }
        }
        else
            secs = parseInt(document.getElementById("JSandCSS1_hdTimeout").value) * 60;
    }    
    function showConfirmationAlert() {
        $(document).ready(function () {
            //select all the a tag with name equal to modal
            $('a[name=modal]').click(function (e) {
                var id = $(this).attr('href');
                //Get the screen height and width
                var maskHeight = $(document).height();
                var maskWidth = $(window).width();

                //Set height and width to mask to fill up the whole screen
                $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

                //transition effect     
                $('#mask').fadeIn(1000);
                $('#mask').fadeTo("slow", 0.8);

                //Get the window height and width
                var winH = $(window).height();
                var winW = $(window).width();

                //Set the popup window to center
                $(id).css('top', winH / 2 - $(id).height() / 2);
                $(id).css('left', winW / 2 - $(id).width() / 2);

                //transition effect
                $(id).fadeIn(2000);
            });
            //if mask is clicked
            //            $('#mask').click(function () {
            //                $(this).hide();
            //                $('.window').hide();
            //                noTimeOut();
            //            });
            $('#btnOk').click(function () {
                window.location.reload(true);
                $('#mask').hide();
                $('.window').hide();
                noTimeOut();
            });
            $('#btnExit').click(function () {
                $(this).hide();
                $('.window').hide();
                doTimeOut();
            });

        });
    }
    function querySt(ji) {
        hu = window.location.search.substring(1);
        gy = hu.split("&");
        for (i = 0; i < gy.length; i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
                return ft[1];
            }
        }
    }
    function checkTimeOutPage() {
       
        var qs = querySt('c');
        if(qs == "y") {
            window.opener.location = "logout.aspx";
            window.close();
        }
        var cCookie = getCookie("style");
        if (cCookie == "ovid") {
            document.getElementById("polUser").style.visibility = "hidden";
            document.getElementById("polUser").style.display = "none";
            document.getElementById("ovidUser").style.visibility = "visible";
            document.getElementById("ovidUser").style.display = "block";
            setTimeout("window.location = 'http://ovidsp.ovid.com/ovidweb.cgi';",10000);
        }
        //window.open('login.aspx', 'winname', 'directories = 0, titlebar = 0, toolbar = 0, location = 0, status = 0, menubar = 0, scrollbars = no, resizable = no, width = 400, height = 350');
    }
