/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2009 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
**************************************************************************/

// ************************* API FUNCTIONS *******************************
function isDOMRequired()
{
  return false;
}

function canAcceptCommand(opt) 
{
	var dom = dw.getActiveWindow();
	if( dom == null )
		return false;
	
	switch(opt)
	{
		case 'freeze_javascript':
			if(!dom.getHideDisplaysInLiveView()) {
				return false;
			}
			else {
				return (dom.getDesignViewMode() == 'live' && dom.browser.javaScriptEnabled);
			}
		
		case 'disable_javascript':
			if(!dom.getHideDisplaysInLiveView()) {
				return false;
			}
			else {
				return true;
			}
		
		case 'hide_liveview_displays':
        {
            if (dom.getIsTemplateDocument())
         	   return false;
            else
               return (!dom.getLiveViewInspectMode());     //not in Inspect Mode
        }
			
		case 'disable_plugins':
			return true;

        case 'follow_the_next_link':
            {
                return (!dom.getLiveViewInspectMode());     //not in Inspect Mode
            }

        case 'follow_all_links':
            {
                return (!dom.getLiveViewInspectMode());     //not in Inspect Mode
            }

		case 'follow_link_context_menu_item':
		    return (!dom.getLiveViewInspectMode() && dom.browser.isCmdEnabled("followLinkContextMenuItem"));     //not in Inspect Mode
			
		case 'highlight_changes':
			return true;
		
		case 'auto_sync_remote':
			return true;
		
		case 'use_testing_server':
			return true;
		
		case 'use_local_links':
			return (dom.getLiveViewUsingServer());
		
		case 'edit_request_settings':
			return true;
	}
	return false;
}

function receiveArguments(opt) 
{
	var dom = dw.getActiveWindow();
	if( dom == null )
		return;
	
	switch(opt)
	{
		case 'freeze_javascript':
		    dom.browser.interactivityPaused = !dom.browser.interactivityPaused;
			break;
			
		case 'disable_javascript':	
			dom.browser.javaScriptEnabled = !dom.browser.javaScriptEnabled;
			if (dom.getDesignViewMode() == 'live') 
				dom.browser.refreshPage();
			break;
		
		case 'disable_plugins':
			dom.browser.pluginsEnabled = !dom.browser.pluginsEnabled;
			if (dom.getDesignViewMode() == 'live')
				dom.browser.refreshPage();
			break;

		case 'hide_liveview_displays':
			var hideLiveDisplays = !dom.getHideDisplaysInLiveView();
			if(dw.getDocumentDOM()&&!dw.getDocumentDOM().isFluidGridDoc())
			{
			    dom.setHideDisplaysInLiveView(hideLiveDisplays);
			}
			else
			{
				/*when the user says preview, we have to set FG unhide mode to false-​because 
				we dont want to see hidden elements while previewing. so when user disables preview mode, 
				getunhidemod​e will return false since we set it like that. here we remember 
				the state of unhide more before the user goes into preview mode. 
				after the user had disabled the preview mode, we restore back the hide/unhide mode .*/
				if( this.wasInUnhideMode === undefined )
					this.wasInUnhideMode = false;
				if(hideLiveDisplays)
				{
					this.wasInUnhideMode = dw.getDocumentDOM().getIsInUnhideMode();
					dw.getDocumentDOM().setIsInUnhideMode(false);
					dom.setHideDisplaysInLiveView(true);
				}
				else
				{
					dom.setHideDisplaysInLiveView(false);
					dw.getDocumentDOM().setIsInUnhideMode(this.wasInUnhideMode);
					this.wasInUnhideMode = false;
				}
			}
			break;
				
		case 'follow_the_next_link':
			dom.setLiveViewFollowsTheNextLink(!dom.getLiveViewFollowsTheNextLink());
			break;
		
		case 'follow_all_links':
			dom.setLiveViewFollowsAllLinks(!dom.getLiveViewFollowsAllLinks());
			break;

        case 'follow_link_context_menu_item':
            dom.browser.activateFollowLinkContextMenuItem();
            break;
					
		case 'highlight_changes':
			dom.setLiveCodeHighlightsChanges(!dom.getLiveCodeHighlightsChanges());
			break;
		
		case 'auto_sync_remote':
			dom.setLiveViewAutoSyncFilesOnServer(!dom.getLiveViewAutoSyncFilesOnServer());
			break;
		
		case 'use_testing_server':
			{
				//This will change the home page, so we need to re-load the page
				//if we were view the home page
				var check = dom.getLiveViewUsingServer();
				dom.setLiveViewUsingServer(!check);
				if (dom.getDesignViewMode() == 'live') {
					if(check) {
						dom.browser.openURL(dom.browser.getHomePage())
					} else {
						dom.synchronizeLiveView(true);
					}
				}
			}
			break;
		
		case 'use_local_links':
			dom.setLiveViewDependentsUsingServer(!dom.getLiveViewDependentsUsingServer());
			if (dom.getDesignViewMode() == 'live')
				dom.browser.refreshPage();
			break;
		
		case 'edit_request_settings':
			dom.showLiveViewParamatersDialog();
			break;
	}
}

function isCommandChecked(opt)
{
	var dom = dw.getActiveWindow();
	if( dom == null )
		return false;
	
	switch(opt)
	{
		case 'freeze_javascript':
			return(dom.getDesignViewMode() == 'live' && dom.browser.interactivityPaused);
	
		case 'disable_javascript':	
			return (!dom.browser.javaScriptEnabled);
			
		case 'hide_liveview_displays':
		    return (dom.getHideDisplaysInLiveView());
		
		case 'disable_plugins':
			return(!dom.browser.pluginsEnabled);
			
		case 'follow_the_next_link':
			return (dom.getLiveViewFollowsTheNextLink());

		case 'follow_all_links':
		    return (dom.getLiveViewFollowsAllLinks());

		case 'follow_link_context_menu_item':
		    return (false);		
			
		case 'highlight_changes':
			return (dom.getLiveCodeHighlightsChanges());
		
		case 'auto_sync_remote':
			return (dom.getLiveViewAutoSyncFilesOnServer());
		
		case 'use_testing_server':
			return (dom.getLiveViewUsingServer());
		
		case 'use_local_links':
			return (!dom.getLiveViewUsingServer() || !dom.getLiveViewDependentsUsingServer());
		
		case 'edit_request_settings':
			return (false); //this isn't a toggle setting
	}
	
	return false;
}

// ************************* UTILITY FUNCTIONS *******************************
