﻿function DropTest(sender, eventArgs)
{
    var source = eventArgs.get_sourceNode();
    var target = eventArgs.get_htmlElement();
        
    if (target.tagName == "TEXTAREA" && source.get_value())
    {
        target.style.cursor = "default";
        target.value = target.value.replace(/(\s+$)/, '')
        var lAddText = "";
        if (target.value != "") {
            if (target.value.match(/(AND|OR)$/i)) {
                lAddText = " " + source.get_value() + " = ";
            }
            else if (target.value.match(/=$/)) {
                lAddText = " % AND " + source.get_value() + " = ";
            }
            else {
                lAddText = " AND " + source.get_value() + " = ";
            }
        }
        else {
            lAddText = source.get_value() + " = ";
        }
        target.value += lAddText;
        target.focus();
    }    
    return false;
}

function DoPrint()
{
    window.print(); 
}

function hidebox()
    {
        var lSearchForm = document.getElementById("searcharea").style;
        lSearchForm.display = "none";
        
        var lSearchForm = document.getElementById("ctl00_PageContent_corners").style;
        lSearchForm.display = "none";
        
        var lHide = document.getElementById("jshide").style;
        lHide.display = "none";
        
         var lShow = document.getElementById("jsshow").style;
        lShow.display = "block";
        
        var lHitList = document.getElementById("ctl00_PageContent_hitlist").style;
        lHitList.marginTop = "20px";
    }
    
     function showbox()
    {
        var lSearchForm = document.getElementById("searcharea").style;
        lSearchForm.display = "block";
        
        var lSearchForm = document.getElementById("ctl00_PageContent_corners").style;
        lSearchForm.display = "block";
        
         var lHide = document.getElementById("jshide").style;
        lHide.display = "block";
        
         var lShow = document.getElementById("jsshow").style;
        lShow.display = "none";
        
        var lHitList = document.getElementById("ctl00_PageContent_hitlist").style;
        lHitList.marginTop = "5px";
        
    }

 //rotate elements in hitlist for eldocs
function Rotate(contentList, imgId, linkList, linkId, containerId, direction, description) {
    var imgId = document.getElementById(imgId);
    var linkId = document.getElementById(linkId);
    var container = document.getElementById(containerId);
    var list = contentList.split('|');
    var linkList = linkList.split('|');
    var descriptionList = description.split('|');
    var stupidBrowsers = imgId.className;
    
    if (direction == 'left') {
        imgId.className = (imgId.className == 0) ? list.length-1 : imgId.className-1;
    }
    else {
        imgId.className = ++stupidBrowsers % list.length;
    }
    
    imgId.src = list[imgId.className];
    linkId.href = linkList[imgId.className];
    imgId.title = descriptionList[imgId.className];
    container.style.width = imgId.src.substring(imgId.src.indexOf('imgWidth=')+9, imgId.src.length) + 'px';
}

/*Functions for creating javascript-popup*/
var fTooltipIDName = "TooltipImageControl";

//create an image tooltip
function ShowImageTooltip(aSrcControl, e) {
	if ( e.clientX && e.clientY && document.getElementById && document.createDocumentFragment && document.createElement && document.appendChild ) {
		var lContainer = document.createDocumentFragment();
		var lMain = document.createElement('div');
		lMain.id = fTooltipIDName;
		lMain.style.position = 'absolute';
		lMain.style.border = '1px solid blue';
		lMain.style.padding = '2px';
		lMain.style.backgroundColor = '#ffffff';
		lMain.style.zIndex = '1000';
		lMain.style.opacity = 0; 
        lMain.style.MozOpacity = 0; 
        lMain.style.KhtmlOpacity = 0; 
        lMain.style.filter = "alpha(opacity=" + 0 + ")";

		var lImg = document.createElement('img');
		lImg.src = aSrcControl.src;
		lImg.style.padding = '0px';
		lImg.style.margin = '0px';
		lImg.style.display = 'block';
		lMain.appendChild(lImg);

	    //IE can't detect image size until after the object is added to the document (always returns 0), so make sure IE adds it invisible
	    if (lImg.width == 0) {
	        lMain.style.visibility = 'hidden';
	    }
		if ( (lImg.width > 5 && lImg.height > 5) || lImg.width == 0) {
			SetXYPos(lMain, e);
			lContainer.appendChild(lMain);
			aSrcControl.parentNode.appendChild(lContainer);
			opacity(fTooltipIDName, 0, 100, 400, e);
		}
		if (lImg.width < 5 && lImg.height < 5) {
			ClearTooltip();
		}
		
	}
}

//remove tooltip
function ClearTooltip() {
	if (document.getElementById) {
		var lDeadNodeWalking = document.getElementById(fTooltipIDName);
		if (lDeadNodeWalking) {
			lDeadNodeWalking.parentNode.removeChild(lDeadNodeWalking);
		}
	}
}

//adjusts the tooltip position after mouse
function MoveTooltip(e) {
	if (document.getElementById) {
		var lTooltipNode = document.getElementById(fTooltipIDName);
		if (lTooltipNode) {
			SetXYPos(lTooltipNode, e);
			lTooltipNode.style.visibility = 'visible';
		}
	}
}

function SetXYPos(aTarget, e) {
	var lOverflowY = document.documentElement.clientHeight - (e.clientY + aTarget.firstChild.height + 15);
	lOverflowY = lOverflowY < 0 ? aTarget.firstChild.height + 10 : 0;
	
	var lOverflowX = document.documentElement.clientWidth - (e.clientX + aTarget.firstChild.width + 15);
	lOverflowX = lOverflowX < 0 ? aTarget.firstChild.width + 20 : 0;

    if (e.pageX && e.pageY) {
		aTarget.style.left = ((e.pageX + 10) - lOverflowX) + 'px';
		aTarget.style.top = ((e.pageY + 10) - lOverflowY ) + 'px';
	}
	else {
		aTarget.style.left = ((e.clientX + document.documentElement.scrollLeft + 10) - lOverflowX) + 'px';
		aTarget.style.top = ((e.clientY + document.documentElement.scrollTop + 10) - lOverflowY ) + 'px';
	}
}

function opacity(id, opacStart, opacEnd, millisec, e) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    for(i = opacStart; i <= opacEnd; i++) 
        {
        setTimeout("changeOpac(" + i + ")",(timer * speed)); 
        timer++; 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity) { 
    var lTooltipNode = document.getElementById(fTooltipIDName); 
    if (lTooltipNode) {
        lTooltipNode.style.opacity = (opacity / 100); 
        lTooltipNode.style.MozOpacity = (opacity / 100); 
        lTooltipNode.style.KhtmlOpacity = (opacity / 100); 
        lTooltipNode.style.filter = "alpha(opacity=" + opacity + ")";
    }
}

//Functions for emulating text-overflow: elipsis in gecko
function initMozTextOverflow(obj) {

    function re_render() {
        doMozTextOverflow(obj);
    }
    setTimeout(re_render, 0);

}

function doMozTextOverflow(obj) {

    function _overflow(e) {
        var el = e.currentTarget;
        el.className = "_textOverflow";
    }

    function _underflow(e) {
        var el = e.currentTarget;
        el.className = "_textUnderflow";
    }

    obj.className = "_textUnderflow";
    obj.addEventListener("overflow", _overflow, false);
    obj.addEventListener("underflow", _underflow, false);
    obj.ins = document.createElement("ins");
    obj.ins.innerHTML = "&hellip;";
    obj.appendChild(obj.ins);

    obj.onmousedown = function(e) {
        this.selectStartX = e.clientX - document.getBoxObjectFor(this).x;
    }

    obj.onmouseup = function(e) {
        this.selectStartX = null;
    }

    obj.onmousemove = function(e) {
        if (this.selectStartX != null) {
            var mx = e.clientX - this.selectStartX;
            var ex = this.offsetWidth - this.selectStartX;

            if ((ex - mx) < (this.ins.offsetWidth + 3)) {
                if (this.className != "_textUnderflow") {
                    this.className = "_textUnderflow";
                    this.scrollLeft = 0;
                    var box = document.createElement("input");
                    box.setAttribute("type", "text");
                    box.value = 1111
                    this.appendChild(box);
                    box.select();
                    this.removeChild(box);
                    this.focus();
                }
            }
            else {
                if (this.className != "_textOverflow") {
                    this.className = "_textOverflow"
                }

            }
            return false;
        }
    };
}