/**
* @constructor
*/
var PanelTemplate = false;
var CWPrinted = false;
 
try
{
PanelTemplate = parent.GetPanelTemplate(); //see if action was ran from in a panel template
}
    catch (er)
    {
    
    }
    
function CWBrowseObject(browseControlId, treeViewId)
{
    this.browsControlId = browseControlId;
    this.treeViewId = treeViewId;
}

CWBrowseObject.prototype = {
    SetSelectedUrl : function(url)
    {        
        Anthem_InvokeControlMethod(this.browsControlId,'SetSelectedUrl', [url], function(result) { });
    }
}

function CWSBrowseSelectNode(ctrlId, node)
{
    var treeView = ISGetObject(ctrlId);
    var nodes = treeView.GetArrayNodes();
    for(i = 0; i< nodes.length; i++)
        nodes[i].Enabled = false;
        
    var browse = new CWBrowseObject(node.Tag,ctrlId);
    browse.SetSelectedUrl(node.Value);
}
    
function CWActionDescription(name,description,location, locationUrl)
{
    this.name = name;
    this.description = description;
    this.location = location;
    this.locationUrl = locationUrl;
}

CWActionDescription.prototype = {

    ShowDescription : function(nameControlId,descriptionControlId,urlControlId)
    {
        var name =  document.getElementById(nameControlId);
        if(name)
        {           
            name.innerHTML = this.name;
        }
        
         var description =  document.getElementById(descriptionControlId);
        if(description)
        {        
        description.innerHTML = this.description;
        }
        
        var url =  document.getElementById(urlControlId);
        if(url)
        {            
            url.innerHTML= this.location;
            url.href= this.locationUrl;
            url.target = '_new';
        }     

    }
}
 

DHTML_modalMessage = function()
{
	var url;								// url of modal message
	var htmlOfModalMessage;					// html of modal message
	
	var divs_transparentDiv;				// Transparent div covering page content
	var divs_content;						// Modal message div.
	var iframe;								// Iframe used in ie
	var layoutCss;							// Name of css file;
	var width;								// Width of message box
	var height;								// Height of message box
	
	var existingBodyOverFlowStyle;			// Existing body overflow css
	var dynContentObj;						// Reference to dynamic content object
	var cssClassOfMessageBox;				// Alternative css class of message box - in case you want a different appearance on one of them
	var shadowDivVisible;					// Shadow div visible ? 
	var shadowOffset; 						// X and Y offset of shadow(pixels from content box)
	var MSIE;
		
	this.url = '';							// Default url is blank
	this.htmlOfModalMessage = '';			// Default message is blank
	this.layoutCss = 'modal-message.css';	// Default CSS file
	this.height = 200;						// Default height of modal message
	this.width = 400;						// Default width of modal message
	this.cssClassOfMessageBox = false;		// Default alternative css class for the message box
	this.shadowDivVisible = true;			// Shadow div is visible by default
	this.shadowOffset = 5;					// Default shadow offset.
	this.MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0) this.MSIE = true;	
  
}

DHTML_modalMessage.prototype = {
	// {{{ setSource(urlOfSource)
    /**
     *	Set source of the modal dialog box
     * 	
     *
     * @public	
     */		
	setSource : function(urlOfSource)
	{
		this.url = urlOfSource;
		
	}	
	// }}}	
	,
	// {{{ setHtmlContent(newHtmlContent)
    /**
     *	Setting static HTML content for the modal dialog box.
     * 	
     *	@param String newHtmlContent = Static HTML content of box
     *
     * @public	
     */		
	setHtmlContent : function(newHtmlContent)
	{
		this.htmlOfModalMessage = newHtmlContent;
		
	}
	// }}}		
	,
	// {{{ setSize(width,height)
    /**
     *	Set the size of the modal dialog box
     * 	
     *	@param int width = width of box
     *	@param int height = height of box
     *
     * @public	
     */		
	setSize : function(width,height)
	{	
		if(width)this.width = width;
		if(height)this.height = height;		
	}
	// }}}		
	,		
	// {{{ setCssClassMessageBox(newCssClass)
    /**
     *	Assign the message box to a new css class.(in case you wants a different appearance on one of them)
     * 	
     *	@param String newCssClass = Name of new css class (Pass false if you want to change back to default)
     *
     * @public	
     */		
	setCssClassMessageBox : function(newCssClass)
	{
	
		this.cssClassOfMessageBox = newCssClass;
		if(this.divs_content){
			if(this.cssClassOfMessageBox)
				this.divs_content.className=this.cssClassOfMessageBox;
			else
				this.divs_content.className='modalDialog_contentDiv';
				
				
		}
					
	}
	// }}}		
	,	
	// {{{ setShadowOffset(newShadowOffset)
    /**
     *	Specify the size of shadow
     * 	
     *	@param Int newShadowOffset = Offset of shadow div(in pixels from message box - x and y)
     *
     * @public	
     */		
	setShadowOffset : function(newShadowOffset)
	{
		this.shadowOffset = newShadowOffset
					
	}
	// }}}		
	,	
	// {{{ display()
    /**
     *	Display the modal dialog box
     * 	
     *
     * @public	
     */		
	display : function()
	{
		if(!this.divs_transparentDiv){
			this.__createDivs();
		}	
		
		// Redisplaying divs
		this.divs_transparentDiv.style.display='block';
		this.divs_content.style.display='block';
		this.divs_shadow.style.display='block';		
		if(this.MSIE)this.iframe.style.display='block';	
		this.__resizeDivs();
		
		/* Call the __resizeDivs method twice in case the css file has changed. The first execution of this method may not catch these changes */
		window.refToThisModalBoxObj = this;		
		setTimeout('window.refToThisModalBoxObj.__resizeDivs()',150);
		
		this.__insertContent();	// Calling method which inserts content into the message div.
	}
	// }}}		
	,
	// {{{ ()
    /**
     *	Display the modal dialog box
     * 	
     *
     * @public	
     */		
	setShadowDivVisible : function(visible)
	{
		this.shadowDivVisible = visible;
	}
	// }}}	
	,
	// {{{ close()
    /**
     *	Close the modal dialog box
     * 	
     *
     * @public	
     */		
	close : function()
	{
		//document.documentElement.style.overflow = '';	// Setting the CSS overflow attribute of the <html> tag back to default.
		
		/* Hiding divs */
		this.divs_transparentDiv.style.display='none';
		this.divs_content.style.display='none';
		this.divs_shadow.style.display='none';
		if(this.MSIE)this.iframe.style.display='none';
		
	}	
	// }}}	
	,
	// {{{ __addEvent()
    /**
     *	Add event
     * 	
     *
     * @private	
     */		
	addEvent : function(whichObject,eventType,functionName,suffix)
	{ 
	  if(!suffix)suffix = '';
	  if(whichObject.attachEvent){ 
	    whichObject['e'+eventType+functionName+suffix] = functionName; 
	    whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );} 
	    whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName+suffix] ); 
	  } else 
	    whichObject.addEventListener(eventType,functionName,false); 	    
	} 
	// }}}	
	,
	// {{{ __createDivs()
    /**
     *	Create the divs for the modal dialog box
     * 	
     *
     * @private	
     */		
	__createDivs : function()
	{
		// Creating transparent div
		this.divs_transparentDiv = document.createElement('DIV');
		this.divs_transparentDiv.className='modalDialog_transparentDivs';
		this.divs_transparentDiv.style.left = '0px';
		this.divs_transparentDiv.style.top = '0px';
		
		document.body.appendChild(this.divs_transparentDiv);
		// Creating content div
		this.divs_content = document.createElement('DIV');
		this.divs_content.className = 'modalDialog_contentDiv';
		this.divs_content.id = 'DHTMLSuite_modalBox_contentDiv';
		this.divs_content.style.zIndex = 100000;
		
		if(this.MSIE){		    
			this.iframe = document.createElement('<IFRAME src="about:blank" frameborder=0>');
			this.iframe.style.zIndex = 90000;
			this.iframe.style.position = 'absolute';
			document.body.appendChild(this.iframe);	
		}
			
		document.body.appendChild(this.divs_content);
		// Creating shadow div
		this.divs_shadow = document.createElement('DIV');
		this.divs_shadow.className = 'modalDialog_contentDiv_shadow';
		this.divs_shadow.style.zIndex = 95000;
		document.body.appendChild(this.divs_shadow);
		window.refToModMessage = this;
		this.addEvent(window,'scroll',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		

	}
	// }}}
	,
	// {{{ __getBrowserSize()
    /**
     *	Get browser size
     * 	
     *
     * @private	
     */		
	__getBrowserSize : function()
	{
    	var bodyWidth = document.documentElement.clientWidth;
    	var bodyHeight = document.documentElement.clientHeight;
    	
		var bodyWidth, bodyHeight; 
		if (self.innerHeight){ // all except Explorer 
		 
		   bodyWidth = self.innerWidth; 
		   bodyHeight = self.innerHeight; 
		}  else if (document.documentElement && document.documentElement.clientHeight) {
		   // Explorer 6 Strict Mode 		 
		   bodyWidth = document.documentElement.clientWidth; 
		   bodyHeight = document.documentElement.clientHeight; 
		} else if (document.body) {// other Explorers 		 
		   bodyWidth = document.body.clientWidth; 
		   bodyHeight = document.body.clientHeight; 
		} 
		return [bodyWidth,bodyHeight];		
		
	}
	// }}}	
	,
	// {{{ __resizeDivs()
    /**
     *	Resize the message divs
     * 	
     *
     * @private	
     */	
    __resizeDivs : function()
    {
    	
    	var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

		if(this.cssClassOfMessageBox)
			this.divs_content.className=this.cssClassOfMessageBox;
		else
			this.divs_content.className='modalDialog_contentDiv';	
			    	
    	if(!this.divs_transparentDiv)return;
    	
    	// Preserve scroll position
    	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
    	var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
    	
    	window.scrollTo(sl,st);
    	setTimeout('window.scrollTo(' + sl + ',' + st + ');',10);

    	this.__repositionTransparentDiv();
    	

		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];
    	
    	// Setting width and height of content div
      	this.divs_content.style.width = this.width + 'px';
    	this.divs_content.style.height= this.height + 'px';  	
    	
    	// Creating temporary width variables since the actual width of the content div could be larger than this.width and this.height(i.e. padding and border)
    	var tmpWidth = this.divs_content.offsetWidth;	
    	var tmpHeight = this.divs_content.offsetHeight;
    	
    	
    	// Setting width and height of left transparent div
    	
    	

    	
    	
		
    	this.divs_content.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px';;
    	this.divs_content.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
    	
 		if(this.MSIE){
 			this.iframe.style.left = this.divs_content.style.left;
 			this.iframe.style.top = this.divs_content.style.top;
 			this.iframe.style.width = this.divs_content.style.width;
 			this.iframe.style.height = this.divs_content.style.height;
 		}
 		
    	this.divs_shadow.style.left = (this.divs_content.style.left.replace('px','')/1 + this.shadowOffset) + 'px';
    	this.divs_shadow.style.top = (this.divs_content.style.top.replace('px','')/1 + this.shadowOffset) + 'px';
    	this.divs_shadow.style.height = tmpHeight + 'px';
    	this.divs_shadow.style.width = tmpWidth + 'px';
    	
    	
    	
    	if(!this.shadowDivVisible)this.divs_shadow.style.display='none';	// Hiding shadow if it has been disabled
    	
    	
    }
    // }}}	
    ,
	// {{{ __insertContent()
    /**
     *	Insert content into the content div
     * 	
     *
     * @private	
     */	    
    __repositionTransparentDiv : function()
    {
    	this.divs_transparentDiv.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
    	this.divs_transparentDiv.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];
    	this.divs_transparentDiv.style.width = bodyWidth + 'px';
    	this.divs_transparentDiv.style.height = bodyHeight + 'px';		
		   	
    }
	// }}}	
	,
	// {{{ __insertContent()
    /**
     *	Insert content into the content div
     * 	
     *
     * @private	
     */	
    __insertContent : function()
    {
		if(this.url){	// url specified - load content dynamically
			ajax_loadContent('DHTMLSuite_modalBox_contentDiv',this.url);
		}else{	// no url set, put static content inside the message box
			this.divs_content.innerHTML = this.htmlOfModalMessage;	
		}
    }		
} 

/*function CWS_displayMessage(url)
{	
    messageObj = new DHTML_modalMessage();
	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(400,200);
	messageObj.setShadowDivVisible(true);	// Enable shadow for these boxes
	messageObj.display();
}*/

function CWSValidate()
{
var valid = true;
    
    if((typeof(Page_IsValid) != 'undefined'))
    {           
         Page_ClientValidate();
         valid = Page_IsValid;
    }
    
   return valid;
}

function greyOutContent(loadingImageURL)
{


    var strLoading = "Loading...";
    var contentFrm = document.body;//window.frames["Content"];
     
    var doc = document;
    
    var x = 0, y = 0;
    var h = 0, w = 0;
    var image = null;
    
    var greyDiv = doc.getElementById("AdminGreyedDiv");
    document.getElementsByTagName("body")[0].style.overflow = "hidden";
    
    //RS 2-4-09 added try catch for firefox. contentFrm was throwing exceptions stoppoing processing
    try{
        if(!greyDiv)
        {
            greyDiv = doc.createElement("div");
            greyDiv.setAttribute("id", "AdminGreyedDiv");
            greyDiv.style.position = "absolute";
            greyDiv.style.border = "1px solid #e0e0e0";
            greyDiv.style.filter = "alpha(opacity=70)";
            greyDiv.style.zIndex = 9999;
            
            doc.body.appendChild (greyDiv);
        }

        greyDiv.innerHTML = "<font size=\"+1\" color=\"#2F4F4F\"><b>" + strLoading + "</b></font>";    
        
                
        if( window.innerHeight && window.scrollMaxY ) // Firefox 
        {
                w = window.innerWidth + window.scrollMaxX;
                h = window.innerHeight + window.scrollMaxY;
            }
            else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
            {
                w = document.body.scrollWidth;
                h = document.body.scrollHeight;
            }
            else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
            { 
                w = document.body.offsetWidth + document.body.offsetLeft; 
                h = document.body.offsetHeight + document.body.offsetTop; 
            }
        
        var element = contentFrm;
        
        do
        {
            y += element.offsetTop || 0;
            x += element.offsetLeft || 0;
            element = element.offsetParent;
        } while (element)
        
        
        
        var imgURL = "url('"+loadingImageURL+"')";
        
        //loadingImageURL loaded server side ...
        greyDiv.style.backgroundImage = imgURL;
        
        greyDiv.style.backgroundRepeat   = 'no-repeat';
        //
        greyDiv.style.backgroundColor   = '#B0C4DE';
        greyDiv.style.backgroundPosition  = '50% 50%';
        greyDiv.style.textAlign  = 'center';
        if((h!= 'undefined') && (h != 0))
            greyDiv.style.paddingTop  = (h/2)-50 + 'px';
        greyDiv.style.width        = w  + 'px';
        greyDiv.style.height       = h  + 'px';
        greyDiv.style.left         = x + 'px';
        greyDiv.style.top          = y + 'px'
        greyDiv.style.display      = '';        
        
    }
    catch(er)
    {
    }
}

function CWS_displayStaticMessage(messageContent,cssClass,width,height)
{    
    
    var valid = true;
    
    if((typeof(Page_IsValid) != 'undefined'))
    {    
         Page_ClientValidate();
         valid = Page_IsValid;
    }
   
    if(valid)
   {
        messageObj = new DHTML_modalMessage();
   
	    messageObj.setHtmlContent(messageContent);
	    messageObj.setSize(width,height);
	    //messageObj.setCssClassMessageBox(cssClass);
	    messageObj.setSource(false);	// no html source since we want to use a static message here.
	    messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	    messageObj.display();	
	}
	
}

function CWSApplyValueFromSelect(selectId,ctrlId)
{
    var select = document.getElementById(selectId);
    var ctrl = document.getElementById(ctrlId);
    ctrl.value = select.options[select.selectedIndex].value
    alert(ctrl.value);
}

function CWDateClearFunctionBox(id)
{
    var select = document.getElementById(id);
    if(select)
    {
        select.options[0].selected = true;
    }
}

function CWDateClearDateBox(id)
{
    var box = document.getElementById(id);    
    if(box)
    {
        box.value = "";
    }
}

function CWClearLabel(id)
{
    var label = document.getElementById(id);    
    if(label)
    {
        label.innerText = "";
    }
}

function CWSCloseActionStatus()
{
    try{
        if(typeof(messageObj) != 'undefined')
         {      
            messageObj.close();         
         }
         else if(typeof(parent.messageObj) != 'undefined')
         {
            parent.messageObj.close();   
         }
     }
    catch (er)
    {
    
    }
}

function CWInsertIntoRichText(textAreaId, valueToInsert)
{
    valueToInsert = STSHtmlEncode(valueToInsert);

    RTE_GiveEditorFocus(textAreaId);
    var selection=RTE_GetCurrentSelection(textAreaId);

    if (selection !=null)
    {

	    var textRange=selection.createRange();
	    if (textRange !=null)
	    {					 
           textRange.pasteHTML(valueToInsert);	
	    }

    }
}


function CWSDebugAlertProps(obj)
{
var strPops = '';
  for(prop in obj)
			{
			    strPops += prop.toString() + " = " + prop.value +"\n";
			}
			alert(strPops);
}

function CWSinsertFieldVarAtCursor(textAreaId,listId, isRichText) {

   try
   {
        var listBox = document.getElementById(listId); 
        var valueToInsert = '<%'+listBox.options[listBox.selectedIndex].value+'%>';
        var isFireFox = navigator.userAgent.toLowerCase().indexOf("firefox") > 0;
        if(isRichText && !isFireFox)
        {
            CWInsertIntoRichText(textAreaId,valueToInsert)
            return;
        }
        
      var textArea = document.getElementById(textAreaId); 
       
      if(textArea && listBox)
      {
      
          if (document.selection && !isFireFox) {            
            textArea.focus();
            sel = document.selection.createRange();
            sel.text = valueToInsert;
            
          }
          
          else if (textArea.selectionStart || textArea.selectionStart == '0') {         
            var startPos = textArea.selectionStart;
            var endPos = textArea.selectionEnd;
            textArea.value = textArea.value.substring(0, startPos)
                          + valueToInsert
                          + textArea.value.substring(endPos, textArea.value.length);
          
          } else {           
            textArea.value += valueToInsert;
           
          }
      }
    }
    catch (er)
    {
        
    }
}

function CWSOnDivScroll(id)
{
    var listBox = document.getElementById(id);

        if (listBox.options.length > 8)
    {
        listBox.size=listBox.options.length;
    }
    else
    {
        listBox.size=8;
    }
}


function CWSOnSelectFocus(divId,listId)
{    
    var div = document.getElementById(divId); 
    if (div.scrollLeft!= 0)
    {
        div.scrollLeft = 0;
    }

    var listBox = document.getElementById(listId);    
    if( listBox.options.length > 8)
    {
        listBox.focus();
        listBox.size=8;
    }
}

function CWSRefreshGrid(gridId,isDelete,itemCount,webPartId,webDialogId)
{
    var grid = "";
     
    
    if (PanelTemplate)
    {
        grid = parent.window.frames["Content"].ISGetObject(gridId);
    }
    else
    {
        grid = parent.ISGetObject(gridId);
    } 
    
  
    var items = CWSGetAllListItems(webPartId)
    //alert(items);
    if(grid)
    {
        try
        {            
            if(isDelete || grid.TotalRows == 0)
            {
            
                    if (PanelTemplate)
                    {    
                        parent.window.frames["Content"].location.href = parent.window.frames["Content"].location.href;
                    }
                    else
                    {
                        window.parent.location.href = window.parent.location.href;
                    }
             }
            else  
            {     
             
                if(!grid.IsInProgress)   
                {                    
                    grid.Refresh(); 
                    CWSResetAllChecks(webPartId);
                }  
                else
                {
                    if (PanelTemplate)
                    {    
                        parent.window.frames["Content"].location.href = parent.window.frames["Content"].location.href;
                    }
                    else
                    {
                        window.parent.location.href = window.parent.location.href;
                    }
                }              
                                  
            } 
        
                 
        }
         catch (er)
        {
              
        }
    }      
    
}

function CWSResetAllChecks(webPartId)
{
    var checkboxes;
    if (PanelTemplate)
    {
        checkboxes = parent.window.frames["Content"].document.getElementsByName('CWActionBox'+webPartId);
    }
    else
    {
        checkboxes = parent.document.getElementsByName('CWActionBox'+webPartId);
    } 
    var i;
    for(i = 0; i<checkboxes.length; i++)
    {
        checkboxes[i].checked = false;         
    }     
 }
 
 function CWPrint(ids)
 {
  
  if(!parent.CWPrinted)
  {
         try
            {
                CWPrintClient = new ActiveXObject("CorasWorksPrintClient.Application");
                CWPrintClient.PrintFiles(ids);
                parent.CWPrinted = true;
                
            }
            catch (er)
            {
                //alert('Unable')
            }
    }
    
 }


function CWSInvokeActionFormControlMethod(actionFormControlId,itemsListControlId,webPartId) 
{    
    var itemsList = document.getElementById(itemsListControlId);
    itemsList.value = CWSGetSelectedListItems(webPartId);   
    Anthem_InvokePageMethod("DoAction", [], function(result) { }); 
}

function CWSDialogClosed(webDialogId, dialogResult)
{
    CWSCloseActionStatus();
    CWSClearActionForm(webDialogId);
    
}

function CWSClearActionForm(webDialogId)
{ 
    var wdb;

    try
    {
        wdb = parent.ISGetObject(webDialogId);
   
    if(wdb)
    {
        wdb.Window.SetContentURL('about:Blank'); 
        wdb.Window.LoadContent();    
    }
    }
    catch (er)
    {
    
    }
   
       
}

function CWSCloseActionForm(webDialogId)
{   
    var wdb 
    try
    {
     wdb = parent.ISGetObject(webDialogId); 
    
    if(wdb)
    {           
         CWSClearActionForm(webDialogId)    
         wdb.CloseDialog();
      
    }
    
    }
    catch (er)
    {
    
    }
}

function CWSLoadNewForm(actionFormControlId,gridId, list, webPartId,webDialogId, webUrl)
{
    actionUrl = 'NewForm';
        if (window.frameElement != null && window.frameElement.name == "Content")
    {
    
    window.parent.PanelTemplateCWSLoad(actionUrl,actionFormControlId,gridId,list,webPartId,'ctl00_PlaceHolderMain_content232222_ActionForm');
    }
    else
    {
    var qs = '?gridId='+ gridId + '&webDialogId='+webDialogId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId + '&listItem='+list;
    CWSActionPanel(qs,webDialogId,'New Item', webUrl);
    }
    return false; 
}

function CWSLoadEditForm(actionFormControlId,gridId,listItem,webPartId,webDialogId, webUrl)
{
    actionUrl = 'EditForm';
    if (window.frameElement != null && window.frameElement.name == "Content")
    {
    
    window.parent.PanelTemplateCWSLoad(actionUrl,actionFormControlId,gridId,listItem,webPartId,'ctl00_PlaceHolderMain_content232222_ActionForm');
    }
    else
    {
    var qs = '?gridId='+gridId + '&webDialogId='+webDialogId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId + '&listItem='+listItem;
    CWSActionPanel(qs,webDialogId,'Edit Item', webUrl);
    }
    return false; 
}

function CWSLoadViewForm(actionFormControlId,gridId,listItem,webPartId,webDialogId, webUrl)
{
    actionUrl = 'ViewForm';
    if (window.frameElement != null && window.frameElement.name == "Content")
    {
    
    window.parent.PanelTemplateCWSLoad(actionUrl,actionFormControlId,gridId,listItem,webPartId,'ctl00_PlaceHolderMain_content232222_ActionForm');
    }
    else
    {
    var qs = '?gridId='+gridId + '&webDialogId='+webDialogId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId + '&listItem='+listItem;
    CWSActionPanel(qs,webDialogId,'View Item', webUrl)
    }
    return false; 
}

function PanelTemplateCWSLoad(actionUrl,actionFormControlId,gridId,listItem,webPartId,webDialogId, webUrl) 
{

        var qs = '?gridId='+gridId + '&webDialogId='+webDialogId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId + '&listItem='+listItem;
        CWSActionPanel(qs,webDialogId, '', webUrl)
        SetPanelTemplate();

}

function CWSLoadActionForm(actionFormControlId,gridId,actionUrl,listItem,webPartId,webDialogId,webUrl)
{
    if (window.frameElement != null && window.frameElement.name == "Content")
    {
    
        window.parent.PanelTemplateCWSLoad(actionUrl,actionFormControlId,gridId,listItem,webPartId,'ctl00_PlaceHolderMain_content232222_ActionForm');
    }
    else
    {

        var qs = '?gridId='+gridId + '&webDialogId='+webDialogId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId + '&listItem='+listItem;
        CWSActionPanel(qs,webDialogId, '', webUrl);   
    } 
    return false; 
}

function CWSLoadActionPanel(actionFormControlId,gridId,actionUrl,webPartId,webDialogId, webUrl)  
{

    if (window.frameElement != null && window.frameElement.name == "Content")
    {
    
    window.parent.PanelTemplateLoadActionPanel(actionFormControlId,gridId,actionUrl,webPartId,'ctl00_PlaceHolderMain_content232222_ActionForm', webUrl);
    }
    else
    {
        var qs = '?gridId='+gridId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId+ '&webDialogId='+webDialogId;
        CWSActionPanel(qs,webDialogId, '' , webUrl); 
    } 
    return false; 

}
function PanelTemplateLoadActionPanel(actionFormControlId,gridId,actionUrl,webPartId,webDialogId, webUrl) 
{

        var qs = '?gridId='+gridId + '&actionUrl=' + actionUrl + '&webPartId='+webPartId+ '&webDialogId='+webDialogId;
        CWSActionPanel(qs,webDialogId, '', webUrl);
        SetPanelTemplate();

}


function CWSActionPanel(querystring,webDialogId,actionName, webUrl)
{
var wdb;
var url;
var awHeight; 
var awWidth;
var defaultAwHeight = 600; 
var defaultAwWidth = 800; 
    try
    {
        
        wdb = ISGetObject(webDialogId);     
         
    
    if(wdb)
      {    
        
        actionName = 'CorasWorks Actions Form'; 
        wdb.WindowSettings.AllowMaximize = 'No';
        var ran = Math.round(Math.random()*1001);
        if(webUrl)
             url = webUrl + '/_layouts/CorasWorks.Central.Administration/ActionForm.aspx'+querystring+'&'+ran;
          else
            url =  '_layouts/CorasWorks.Central.Administration/ActionForm.aspx'+querystring+'&'+ran;
        
       var wdbWidth; 
       if(wdb.Width.length != null) 
            wdbWidth = wdb.Width.substring(0, (wdb.Width.length-2));  
       else 
            wdbWidth = wdb.Width;        
       
       if(document.body.clientWidth > 800) 
            awWidth=defaultAwWidth; 
       else if(document.body.clientWidth < 350) 
            awWidth=500;
       else 
        awWidth=document.body.clientWidth; 
        wdb.Width=awWidth; 
       
       if(document.body.clientHeight > 600) 
            awHeight=defaultAwHeight; 
       else if(document.body.clientHeight < 300) 
            awHeight=300;
       else awHeight=document.body.clientHeight; 
            wdb.Height=awHeight; 
       var xLoc = (document.body.clientWidth - awWidth)/2; 
       if((xLoc > 0) && (awWidth < document.body.clientWidth))       
        wdb.Location.X = xLoc; wdb.Location.Y = document.body.scrollTop + 30;
        wdb.SetContentURL(url);  
        wdb.Text = actionName;          
        wdb.ShowDialog();         
               
        }
    }
    catch (er)
    {
    
    }
wdb = null;
 
}

function CWSEditXMLDoc(templateUrl, progId)
{
   xmlDocObject = new ActiveXObject("SharePoint.OpenXMLDocuments.1");
   if (xmlDocObject)
   {   
      // Open the XML document or form for editing.
      xmlDocObject.EditDocument(templateUrl,progId);      
  }
}

function CWSEditDoc(templateUrl)
{ 
   EditDocument = new ActiveXObject("SharePoint.OpenDocuments.2");
   if (EditDocument) 
   { 
      EditDocument.EditDocument(templateUrl);      
   } 

} 

function CWSViewDoc(docUrl)
{ 
   ViewDocument = new ActiveXObject("SharePoint.OpenDocuments.2");
   if (ViewDocument) 
   { 
      ViewDocument.ViewDocument(docUrl);      
   } 

}

function CWSGetAllListItems(webPartId)
 {
    var checkboxes = "";
    if (PanelTemplate)
    {
        checkboxes = parent.window.frames["Content"].document.getElementsByName('CWActionBox'+webPartId);
    }
    else
    {
        checkboxes = parent.document.getElementsByName('CWActionBox'+webPartId);
    } 
    return checkboxes.length;
 }

function CWSGetSelectedListItems(webPartId)
 {
 
    parent.CWPrinted = false;
    var checkboxes = "";
    if (PanelTemplate)
    {
        checkboxes = parent.window.frames["Content"].document.getElementsByName('CWActionBox'+webPartId);
    }
    else
    {
        checkboxes = parent.document.getElementsByName('CWActionBox'+webPartId);
    }    
    var i = 0;
    var j = 0;
    var checkedItems = new Array();
    
    for(i = 0; i < checkboxes.length; i++)
    {
        if(checkboxes[i].checked)
        {
            checkedItems[j] = checkboxes[i].getAttribute("itemUrl");            
            j++;
        }
    }  
    
    return checkedItems;
 }
 
function CWSGetBrowserSize()
	{
    	var bodyWidth = document.documentElement.clientWidth;
    	var bodyHeight = document.documentElement.clientHeight;
    	
		var bodyWidth, bodyHeight; 
		if (self.innerHeight){ // all except Explorer 
		 
		   bodyWidth = self.innerWidth; 
		   bodyHeight = self.innerHeight; 
		}  else if (document.documentElement && document.documentElement.clientHeight) {
		   // Explorer 6 Strict Mode 		 
		   bodyWidth = document.documentElement.clientWidth; 
		   bodyHeight = document.documentElement.clientHeight; 
		} else if (document.body) {// other Explorers 		 
		   bodyWidth = document.body.clientWidth; 
		   bodyHeight = document.body.clientHeight; 
		} 
		return [bodyWidth,bodyHeight];		
		
	}
	
function CWSPositionActionForm(formID) 
{
var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

    var div = document.getElementById(formID); 
    
    if(!div)
        return;
     div.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
     div.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';


// Preserve scroll position
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
	
	window.scrollTo(sl,st);
	setTimeout('window.scrollTo(' + sl + ',' + st + ');',10);    	

	var brSize = CWSGetBrowserSize();
	var bodyWidth = brSize[0];
	var bodyHeight = brSize[1];    	
	
	
	// Creating temporary width variables since the actual width of the content div could be larger than this.width and this.height(i.e. padding and border)
	var tmpWidth = div.offsetWidth;//this.divs_content.offsetWidth;	
	var tmpHeight = div.offsetHeight;//this.divs_content.offsetHeight;
	
	div.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px';    	
	if(bodyHeight > tmpHeight)
	{
	    div.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
     } 
	
 }

function Anthem_Error(result) {
    if (typeof CWDebugAjax !="undefined")
        {
					alert('CorasWorks AJAX Error was invoked with the following error message: ' + result.error);
					}
				}
