function findPosX(obj)
    {
        var curleft = 0;
        if (obj.offsetParent)
        {
            while (obj.offsetParent)
            {
                curleft += obj.offsetLeft
                obj = obj.offsetParent;
            }
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    }

function findPosY(obj)
    {
        var curtop = 0;
        if (obj.offsetParent)
        {
            while (obj.offsetParent)
            {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    }

function findWidth(obj)
    {
        var width = 0;
        if(navigator.appName==("Microsoft Internet Explorer"))
        {
            width = obj.clientWidth==0?obj.offsetParent.clientWidth:obj.clientWidth;
        }
        else
        {
            width = obj.clientWidth;
        }
        return width;
    }

function findHeight(obj)
    {
        var height = 0;
        if(navigator.appName==("Microsoft Internet Explorer"))
        {
            height = obj.clientHeight==0?obj.offsetParent.clientHeight:obj.clientHeight;
        }
        else
        {
            height = obj.style.height;
        }
        return height;
    }

function findMaxX(obj)
    {
        var maxX = 0;
        var x = findPosX(obj);
        var width = findWidth(obj);
        maxX = x+width;
        return maxX;
    }

function findMaxY(obj)
    {
        var div;
        var maxY = 0;
        var y = findPosY(obj);
        var height = findHeight(obj);
        maxY = y+height;
        return maxY;
    }

function showPPopup(source,popupTopDiv, popupSubDiv ,text)
  {
    var obj = document.getElementById(popupTopDiv);
	//If text is containing single quote then the sigle quote 
	//replaced with ~ symbol. Now I replacing ~ with single quote
	text = text.replace("~","'"); //changed by sunny 
	////////////////////////////////////////////////
    document.getElementById(popupSubDiv).innerHTML = text;
    obj.style.display="inline";
    offset=6;  // Offset by 6 pixels so distinct from table
    if((findMaxX(source)+300) < document.body.clientWidth)
      {
        if(navigator.appName==("Microsoft Internet Explorer"))
          {
              obj.style.left = (findMaxX(source))-offset;
              obj.style.top = (findMaxY(source)-findHeight(source))+offset;
          }
        else
          {
              obj.style.left = (findMaxX(source))-offset+"px";
              obj.style.top = (findMaxY(source)-findHeight(source))+offset+"px";
          }
      }
      else
      {
        if(navigator.appName==("Microsoft Internet Explorer"))
          {
             obj.style.left = (findPosX(source)-300+8+offset);    // fudge by +8 for IE only
             obj.style.top = (findMaxY(source)-findHeight(source));
          }
        else
          {
             obj.style.left = (findPosX(source)-300+offset)+"px";
             obj.style.top = (findMaxY(source)-findHeight(source))+"px";
          }
      }
      if((getAnchorWindowPosition(obj).y) > document.body.clientHeight)


//      if((event.clientY + findHeight(source) + findHeight(obj) + offset + offset) > document.body.clientHeight)
      {
        if(navigator.appName==("Microsoft Internet Explorer"))
          {
              //obj.style.left = (findMaxX(source))-offset;
              obj.style.top = (findPosY(source)-findHeight(obj))-offset;
              //obj.style.top = (document.body.clientHeight-findHeight(obj))-offset;
              //alert("Notfit");
          }
        else
          {
              //obj.style.left = (findMaxX(source))-offset+"px";
              obj.style.top = (findPosY(source)-findHeight(obj))-offset+"px";
          }
      }
      /*else
      {
        if(navigator.appName==("Microsoft Internet Explorer"))
          {
             //obj.style.left = (findPosX(source)-300+8+offset);    // fudge by +8 for IE only
             //obj.style.top = (findMaxY(source)-findHeight(source));
             //alert(offset + "Notfit");
          }
        else
          {
             //obj.style.left = (findPosX(source)-300+offset)+"px";
             //obj.style.top = (findMaxY(source)-findHeight(source))+"px";
          }
      }*/
  }

function hidePPopup(popupTopDiv)
	{
	    var obj = document.getElementById(popupTopDiv);
		obj.style.display="none";
	}

    // getAnchorPosition(anchorname)
    //   This function returns an object having .x and .y properties which are the coordinates
    //   of the named anchor, relative to the page.
    function getAnchorPosition(anchorname) {
    	// This function will return an Object with x and y properties
    	var useWindow=false;
    	var coordinates=new Object();
    	var x=0,y=0;
    	// Browser capability sniffing
    	var use_gebi=false, use_css=false, use_layers=false;
    	if (document.getElementById) { use_gebi=true; }
    	else if (document.all) { use_css=true; }
    	else if (document.layers) { use_layers=true; }
    	// Logic to find position
     	if (use_gebi && document.all) {
    		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
    		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
    		}
    	else if (use_gebi) {
    		var o=document.getElementById(anchorname);
    		x=AnchorPosition_getPageOffsetLeft(o);
    		y=AnchorPosition_getPageOffsetTop(o);
    		}
     	else if (use_css) {
    		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
    		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
    		}
    	else if (use_layers) {
    		var found=0;
    		for (var i=0; i<document.anchors.length; i++) {
    			if (document.anchors[i].name==anchorname) { found=1; break; }
    			}
    		if (found==0) {
    			coordinates.x=0; coordinates.y=0; return coordinates;
    			}
    		x=document.anchors[i].x;
    		y=document.anchors[i].y;
    		}
    	else {
    		coordinates.x=0; coordinates.y=0; return coordinates;
    		}
    	coordinates.x=x;
    	coordinates.y=y;
    	return coordinates;
    	}

    //   getAnchorWindowPosition(anchorname)
    //   This function returns an object having .x and .y properties which are the coordinates
    //   of the named anchor, relative to the window
    function getAnchorWindowPosition(anchorname) {
    	var coordinates=new Object(); //getAnchorPosition(anchorname);
    	coordinates.x=findMaxX(anchorname);
    	coordinates.y=findMaxY(anchorname);
    	var x=0;
    	var y=0;
    	if (document.getElementById) {
    		if (isNaN(window.screenX)) {
    		//alert("1");
    			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
    			y=coordinates.y-document.body.scrollTop+window.screenTop;
    			}
    		else {
    		//alert("2");
    			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
    			//alert(x);
    			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
    			}
    		}
    	else if (document.all) {
    		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
    		y=coordinates.y-document.body.scrollTop+window.screenTop;
    		}
    	else if (document.layers) {
    		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
    		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
    		}
    	coordinates.x=x;
    	coordinates.y=y;
    	return coordinates;
     	}

        // Functions for IE to get position of an object
        function AnchorPosition_getPageOffsetLeft (el) {
        	var ol=el.offsetLeft;
        	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
        	return ol;
        	}
        function AnchorPosition_getWindowOffsetLeft (el) {
        	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
        	}
        function AnchorPosition_getPageOffsetTop (el) {
        	var ot=el.offsetTop;
        	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
        	return ot;
        	}
        function AnchorPosition_getWindowOffsetTop (el) {
        	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
        	}
