﻿
function eGridForm(gridformID){

    var gridformID = gridformID;
    var gridform   = document.getElementById(gridformID)
    var currentHoverPanel
     
    function attachHovePanels(){
        if (gridform == null) return;
        
        for (var i = 0; i < gridform.rows.length; i++){
            if (gridform.rows[i].getAttribute("hoverpanelid") != null)
                if (gridform.rows[i].getAttribute("hoverpanelid") != ""){
                    gridform.rows[i].onmouseout  = mouseMoveOut;
                    gridform.rows[i].onmouseover = mouseMoveIn;
                }
                else{
                    gridform.rows[i].onmouseout  = mouseOutStyle;
                    gridform.rows[i].onmouseover = mouseOverStyle;            
                }
        }
    }
    
    attachHovePanels();
    
    function mouseMoveIn(ev){

        ev = ev || window.event;
        var target   = ev.target || ev.srcElement;        
        var hideHoverPanel = false;
        while (target && target.tagName.toUpperCase()!="TR")
        {
            if (target.tagName.toUpperCase() == "TD") {
	                var re = new RegExp("(?:viewcolumn|editcolumn|deletecolumn|imgShowChild)","ig")
	                if (target.id.match(re) != null) {hideHoverPanel = true;}
            }
	        target = target.parentNode;
        }
       	
        mouseOverStyle(ev);
        with (target){
            if (getAttribute("hoverpanelID")){
                var hp = document.getElementById(getAttribute("hoverpanelID"))
                if (hideHoverPanel && hp) {hp.style.display  = 'none'; return;}
                if  (currentHoverPanel != getAttribute("hoverpanelID")) {
                    currentHoverPanel = getAttribute("hoverpanelID")
                    var hp = document.getElementById(getAttribute("hoverpanelID"))
                    if (hp != null){
                        hp.style.position = 'absolute';
                        hp.style.left     = (mouseCoords(ev).x + 3)  + 'px';
                        hp.style.top      = (mouseCoords(ev).y + 10) + 'px';
                        hp.style.display  = 'block';
                    }
                    
                }
            }
        }
    }

    function mouseMoveOut(ev){
       
        var target   = getTarget(ev);
        mouseOutStyle(ev);
        with (target){
            if (getAttribute("hoverpanelID")){
                var hp = document.getElementById(getAttribute("hoverpanelID"))
                if (hp != null)
                    hp.style.display = 'none';
                    currentHoverPanel = '';
            }
        }
    }

    function mouseOverStyle(ev){
        var target   = getTarget(ev);
        var old_className,old_cssText
        
        with (target){
            if (getAttribute("mark") != 'true') {
                old_className       = className;
                old_cssText         = style.cssText;
                setAttribute("old_className", old_className);
                setAttribute("old_cssText", old_cssText);
                className           = "GridFormMouseOver";
            }
        }
    }

    function mouseOutStyle(ev){
        var target   = getTarget(ev);

        with (target){
            if (getAttribute("mark") != 'true') {
                className           = getAttribute("old_className");
                style.cssText       = getAttribute("old_cssText");
            }
        }
    }

    function  mouseCoords(ev){
    //debugger

	        if(ev.pageX || ev.pageY){
		        return {x:ev.pageX, y:ev.pageY};
	        }
	        else{
	            var pos = getPosition(ev.srcElement);
	            return  {x: pos.x + ev.offsetX, y: pos.y + ev.offsetY};
		    };
    }

    function getTarget(ev){
            ev = ev || window.event;
            var target   = ev.target || ev.srcElement;
   	        while (target && target.tagName.toUpperCase()!="TR"){
   		        target = target.parentNode;
   	        }
   	    return target;
    }

    function getPosition(e){
	    var left = 0;
	    var top  = 0;

	    while (e.offsetParent){
		    left += e.offsetLeft;
		    top  += e.offsetTop;
		    e     = e.offsetParent;
	    }

	    left += e.offsetLeft;
	    top  += e.offsetTop;

	    return {x:left, y:top};
    }

}

eGridForm.ExportExcel  = function (url){

    var oExportIframe;
    oExportIframe           = document.getElementById("GridFormExportIframe");
    if(oExportIframe == undefined){
		    oExportIframe   = document.createElement("iframe");
		    oExportIframe.id = "GridFormExportIframe";
		    oExportIframe.style.display = "none";
		    document.body.appendChild(oExportIframe);
	}
	if (oExportIframe.document) //IE
	   oExportIframe.document.location.href = url;
	else if (oExportIframe.contentDocument) //FF
	   oExportIframe.contentDocument.location.href = url;
}


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();