﻿    var ajaxObj;
    var popupObj;
    var parentObj;
     
    function ajax_Request(location)
    {
        try
        {
            ajaxObj = window.XMLHttpRequest ? new XMLHttpRequest()
                                           : new ActiveXObject("Microsoft.XMLHTTP");
            ajaxObj.onreadystatechange = ajax_CallBack;
            ajaxObj.open('GET',location+'&DeCache='+Math.random(),true);
            ajaxObj.send(null);
        } 
        catch (e) 
        {
            alert(e.message);
        }
    }

    function ajax_CallBack()
    {
        var x, y, w;
        var parentWidth;
        
        if (ajaxObj.readyState == 4) // Request completed
        {
            if (ajaxObj.status == 200) // Request finished OK
            {
                popupObj.innerHTML=ajaxObj.responseText;
                var container = document.getElementById("container");
                container.appendChild(popupObj);
                
                x = YAHOO.util.Dom.getX(parentObj);
                y = YAHOO.util.Dom.getY(parentObj);
                w = 300;
                
                parentWidth=popupObj.parentNode.offsetWidth;
                
                if ((x+w) <= parentWidth)
                { // Fit to the left
                    YAHOO.util.Dom.setXY(popupObj, YAHOO.util.Dom.getXY(parentObj));
                }
                else
                {
                    if (x>=w)
                    { // Fit to right
                        x=x-w;
                        YAHOO.util.Dom.setX(popupObj, x);
                        YAHOO.util.Dom.setY(popupObj, YAHOO.util.Dom.getY(parentObj));
                    }
                    else
                    {
                        if (x<(parentWidth/2))
                        { // Fit to left
                            w=parentWidth-x;
                            YAHOO.util.Dom.setXY(popupObj, YAHOO.util.Dom.getXY(parentObj));
                            
                        }
                        else
                        { // Fit to right
                            w=x;
                            YAHOO.util.Dom.setX(popupObj, YAHOO.util.Dom.getX(parentObj) - w);
                            YAHOO.util.Dom.setY(popupObj, YAHOO.util.Dom.getY(parentObj));
                        }
                        
                    }
                }
                
                popupObj.style.width=w + "px";
                
                //YAHOO.util.Dom.setXY(popupObj, YAHOO.util.Dom.getXY(parentObj));
            
                ajaxObj=null;
            }
        }
    }
    
    function ShowHelpPopup(Context, HelpType, Name, Title, HelpIconElement)
    {
	
	    var parentIcon = document.getElementById(HelpIconElement);
	    if (!parentIcon.popupControl)
	    {
		    
	        parentIcon.popupControl = document.createElement("div");
            parentIcon.popupControl.id="dvhelp_" + Name;
            parentIcon.popupControl.style.position="absolute";
            
            parentIcon.popupControl.style.zIndex=999;
            
            popupObj=parentIcon.popupControl;
            parentObj=HelpIconElement;
            ajax_Request("../help/view.asp?Context=" + Context + "&Type=" + HelpType + "&Name=" + Name + "&Title=" + Title + "&DivClose=1");	    
       }
       
       parentIcon.popupControl.style.display='';
		
    }	
    
    function ShowContactDetails(PartyType, PartyId, SourceElementName, ShowSolicitorFirmContactDetails, CurrentUserTypeId)
	{
		var sURL;
		
		if (!ShowSolicitorFirmContactDetails)
		    ShowSolicitorFirmContactDetails=1;
		
		sURL="../" + PartyType + "/contactdetails.asp?ID=" + PartyId + "&ShowSolicitorFirmContactDetails=" + ShowSolicitorFirmContactDetails + '&DivClose=1' + '&CurrentUserTypeId=' + CurrentUserTypeId;

        var parentCell = document.getElementById(SourceElementName);
        if (!parentCell.popupControl)
        {
		    
            parentCell.popupControl = document.createElement("div");
            parentCell.popupControl.id="dvcontact_" + PartyId;
            parentCell.popupControl.style.position="absolute";
            
            parentCell.popupControl.style.zIndex=10;
            
            popupObj=parentCell.popupControl;
            parentObj=SourceElementName;
            ajax_Request(sURL);	    
       }
       
       parentCell.popupControl.style.display='';
	
	}
	
//	    Sub ShowContactDetailsPopup(PartyType, PartyId, SourceElementName)
//		If IsNumeric(PartyId) Then
//			BeginDownload "../" & PartyType & "/contactdetails.asp?SID=<%=sSID%>&ID=" & CStr(PartyId) & "&AlignIcon=R", 0
//			
//			With objPopup
//				On Error Resume Next				
//				.document.all("divContactDetails").innerHTML=""	
//				.show 0, 0, document.all(SourceElementName).clientWidth+28, 210, document.all(SourceElementName)
//			End With
//		End If
//	End Sub