﻿// KS added 03/11/11

//browser detection
var ver = parseFloat(navigator.appVersion);
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var isNS6 = strUserAgent.indexOf("netscape6") > -1;
var isNS4 = !isIE && !isNS6 && ver < 5;
var isMozilla = (document.all) ? 0 : 1;
var isFireFox = strUserAgent.indexOf("firefox") > -1;
var isOpera = strUserAgent.indexOf("opera") > -1;

function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function getClientWidth() {
    var myWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
    //return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function getClientHeight() {
    var myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
    //return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}

// dynamically add a div to display user wait message     (getClientWidth() / 2)
function buildWaitDiv() 
{

    document.write('<div id="wait" class="waitStyle" style="width:200px;' +
                   ' height:70px; top:' + ((getClientHeight() / 2) - 50) + 'px; left:' + (getClientWidth() / 2 - 100) + 'px;">' +
                   '</div>');
}

// dynamically add a div to dim all the page    window.screen.width 
function buildDimmerDiv() {
    document.write('<div id="dimmer" class="dimmerStyle" style="width:' + window.screen.width + 'px; height:' + window.screen.height*2 + 'px"></div>');
}

var tWidth = '0px';                  // width (in pixels)
var moStop = false;                     // pause on mouseover (true or false)
var tSpeed = 5;                        // scroll speed (1 = slow, 5 = fast)
var ltr = true;                     // true for left to right, false for right to left

var origScrollX = f_scrollLeft();
var origScrollY = f_scrollTop();
var scrollX = f_scrollLeft();
var scrollY = f_scrollTop();

// enter your marquee content here (use \/ and \' in place of / and ' respectively)
var content = '<img id="Img1" name="pb" style="border:3px solid green;height:23px:width 50px;" ';

if (isFireFox)
    content = content + 'src="~/dbfile.axd?name=ProgressBar.png" />'; // ff does not seem to like gif or jpg here
else
    content = content + 'src="~/dbfile.axd?name=ProgressBar.png" />'; //ProgressBar.GIF

//if (isFireFox)
//    content = content + 'class="progress1">'; 
//else
//    content = content + 'class="progress2">';

// Simple Cross-Browser Marquee
var cps = tSpeed; var aw, mq;

function startMarquee() {
    if (document.getElementById) {

        var url = window.location.href;
        var rootUrl =  url.substring(0, url.indexOf("//") + 2);
        var p = location.href.split("/");
        rootUrl += p[2];
        if (p[2] == "localhost") rootUrl += "/" + p[3];
        //alert(rootUrl);

        //alert(root_url);

            //tWidth = document.getElementById("wait").clientWidth; // not working
        var tick;
        tick = '<div style="border:0px solid blue;position:absolute;left:0px;top:0px;width:200px;height:70px;overflow:hidden;">';

//            tick += '><div id="mq" style="border:3px solid black;position:absolute;height:25px;width:200px;line-height:25px;left:0px;top:0px;white-space:nowrap;">' +
//             '<img id="Img1" name="pb" style="border:3px solid green;z-index:10000;width:200px;height:23px;" src="' + rootUrl + '/dbfile.axd?name=ProgressBar.png" />' +
//                        '</div></div>';

            if (isOpera) {
                 tick = tick + '<div style="border:0px solid blue;position:absolute;left:0px;top:18px;width:200px;height:35px;"' +
                          '<span style="width:200px;height:35px;"><p align=center>PLEASE WAIT...</p></span>';
            }
            else {
                tick += '<div id="mq" class="marqueestyle"><p align=center><font face="webdings" size="2" color="silver">&#x006E; &#x006E; &#x006E; &#x006E; &#x006E;</font></p></div>';

                tick = tick + '<div style="border:0px solid blue;position:absolute;left:0px;top:36px;width:200px;height:35px;"' +
                          '<span style="width:200px;height:35px;"><p align=center>PLEASE WAIT...</p></span>';
            }

            tick += '</div>';

            document.getElementById('wait').innerHTML = tick;

            mq = document.getElementById("mq");

            if (!isOpera) {
                if (ltr == true)
                    mq.style.left = "0px"; // to start at left
                else
                    mq.style.left = (parseInt(200) - 60) + "px"; // to start at right

                // mq.innerHTML = '<span height="25px" width="200px" id="tx">hello' + content + '</span>';
                // aw = document.getElementById("tx").width;  //offsetWidth;

                setTimeout(function () { scrollMarquee(ltr); }, 100);
                // setInterval("scrollMarquee(" + ltr + ")", 100);
            }
        

    }
}

function scrollMarquee(ltr) {
    if (ltr == true)
        mq.style.left = (parseInt(mq.style.left) < 199) ? parseInt(mq.style.left) + cps + "px" : "-59px";
    else
        mq.style.left = (parseInt(mq.style.left) > 59) ? parseInt(mq.style.left) - cps + "px" : "199px";

    setTimeout(function () { scrollMarquee(ltr); }, 100);
}

function PageChangeInit() {
    // add the div used to display wait image
    buildWaitDiv();

    // add the div used to dim the page
    buildDimmerDiv();
}

function SetOffset() {
    scrollY = origScrollY + document.body.scrollTop;
    scrollX = origScrollX + document.body.scrollLeft;

    document.getElementById('wait').style.pixelTop = scrollY;
    document.getElementById('wait').style.pixelLeft = scrollX;
}


PageChangeInit();


if (!isIE) document.captureEvents(Event.MOUSEMOVE); //If not IE 
document.onmousemove = getMouseLoc;

function Point(x, y) { this.x = x; this.y = y; }
mouseLocation = new Point(0, 0);

//Get the mouse position 
function getMouseLoc(e) {

    //var offtop = jQuery('html').scrollTop();
   // var offleft = jQuery('html').scrollLeft();


    if (isIE) {
        mouseLocation.x = event.clientX;
        mouseLocation.y = event.clientY;
    } else {  // grab the x-y pos.s if browser is NS 
        mouseLocation.x = e.pageX;
        mouseLocation.y = e.pageY;
    }
    // catch possible negative values  
    if (mouseLocation.x < 0) { mouseLocation.x = 0 }
    if (mouseLocation.y < 0) { mouseLocation.y = 0 }
    return true;
}


function positionDiv() {

    if (isIE || isFireFox) {
        var offtop = jQuery('html').scrollTop();
        var offleft = jQuery('html').scrollLeft();
    }
    else {
        var offtop = jQuery('body').scrollTop();
        var offleft = jQuery('body').scrollLeft();
    }

    //alert(offtop);

    //Set the position of the hidden div 

    // to mouse location
    //document.getElementById('wait').style.top = (mouseLocation.y - 20 + offtop) + "px";
    //document.getElementById('wait').style.left = (mouseLocation.x - 20 + offleft) + "px";

    // to center
    document.getElementById('wait').style.top = (getClientHeight() / 2) - 50 + offtop + "px";
    document.getElementById('wait').style.left = (getClientWidth() / 2) - 100 + offleft + "px";

    //document.getElementById('wait').style.position = "absolute";
} 

