// DreamServer Client Script Component Copyright (c) 1996-2008, David Molson, CreativeTraders (uk)
// The file is part of the DreamServer Classic Library and may not be used by anything other than a DreamServer Application, 
// subject to the DreamServer Licensing Requirements.  No part of this file may not be copied or redistributed.
// DreamServer and all components / files are the Copyright (c) 1996-2008 David Molson, CreativeTraders (uk)
// DreamServer.Net, DreamServer Classic, DreamServer, Codename "Qpoint Services", DreamServer SLI, 
// Pathfinder the Pathfinder and DreamServer logos are trademarks and Copyright (c) David Molson, CreativeTraders (uk)
// 
// DSX Generic Client Script 

function GenericClient_Version(){
	return '03.00.013';
}

var DreamServer_LoadedModules = new Array();

function switchMDIKey(){
	try{
		DSXControl_MDI_AskKey()
	}catch(e){
		alert('The DreamServer MDI Control has not been loaded by this application');
	}
}

function RegisterLoad(text){
    setStatus(text);
    DreamServer_LoadedModules[DreamServer_LoadedModules.length] = text;
}

function setStatus(text){
	try{
		window.status = text;
	}catch(e){
		// fail
	}
}
function alertStatus(text){
	setStatus(text);
	alert(text);
}
function showCookies(){
	var sStream;
	var sNewStream
	sStream = new String(document.cookie);
	sNewStream = new String('');
	var aCookies=sStream.split('; ') ;
	for(sCookie in aCookies){
		sNewStream = sNewStream + aCookies[sCookie] + '\n';
	}
	alert(sNewStream);
}
function chooseValue(sPreferred,sDefault){
	var sValue;
	if(sPreferred==null||sPreferred==''){
		sValue = sDefault;
	}else{
		sValue = sPreferred;
	}
	return sValue;
}

function DSXClientDriver_AskCommand(){
	var sCommand = '';
	var sLastCommand = '';

	var bDSXCommandDriverResult = false;

	try{sLastCommand = getCookie('DSXCommand_LastCommand');}catch(e){setStatus('DSXClientDriver cannot read Cookies');};
	if(sLastCommand==null||sLastCommand==null){
		sLastCommand=''
		try{setCookie('DSXCommand_LastCommand','');}catch(e){setStatus('DSXClientDriver cannot read Cookies');};
	}
	sCommand=prompt('DSXClientDriver:  Enter DSX Shell or Scripting Command',sLastCommand);
	DSXClientDriver_ParseCommand(sCommand);
	return true;
}
function DSXClientDriver_ParseCommand(sCommand){
    var bDSXCommandDriverResult;
    try{
        setStatus('DSXClientDriver calling DSXCommand Driver for: ' + sCommand);
        bDSXCommandDriverResult = DSXCommandDriver_RunHandler(sCommand)
    }catch(e){
    }
	if(bDSXCommandDriverResult==true){
	    // Dont do anything now
	}else{
	    setStatus('DSXClientDriver calling EVAL for: ' + sCommand);
	    try{
	        eval(sCommand);
	    }catch(e){
	        alert('DSXClientDriver failed to Evaluate: ' + sCommand);
	    }
	}
}

function DSXStartAppConsole(){
    var bLoaded_WindowManager = false;
    var bActive_WindowManager = false;
    var sTemp = '';
    try{
        sTemp=DSXWindowManager_Version();
        bActive_WindowManager=isWindowManagerOpen();
        bLoaded_WindowManager=true;
    }catch(e){
        bLoaded_WindowManager=false;
    }
    if(bLoaded_WindowManager==true){
//        if(bActive_WindowManager==false){
            try{
                openWindowManager();
                window.scrollBy(-100000,-100000);
            }catch(e){
                alert('StartAppConsole failed to activate the WindowManager');
                DSXClientDriver_AskCommand();
            }
//        }else{
//            setStatus('StartAppConsole calling BasicClient AskCommand');
//            DSXClientDriver_AskCommand();
//        }
    }
}
function DSXControl_LoadEventLog(){
	popupWinWithStatus('LastEventLog','/DSXServices.Net/Handlers/LoadLastEventLog/LoadLastEventLog.aspx?DSXSessionID=' + DSX_SessionID());
}


//*****************************************************************************************************************************************

// About Stuff

function DSXGUIAbout(){
	var clientVer;
	try{
		clientVer=WebFormClient_Version();
	}
	catch(e){
		clientVer='Not loaded';
	}
	popupWindow('DSXAbout','/DSXServices/ASPComponents/About/About.asp?DSXSessionID=' + DSX_SessionID(),'800','700','','');
}

function ShowLoadedModules(){
    var sDSXVersion = '';
    try{
        sDSXVersion = DSX_Version();
    }catch(e){
        sDSXVersion = 'DreamServer version unavailable';
    }
    var sMessage = '';
    for(i=0;i<DreamServer_LoadedModules.length;i++){
        sMessage = sMessage + ' - ' + DreamServer_LoadedModules[i] + '\n';
    }
    sMessage = sDSXVersion + '\n\nDreamServer Loaded Client Modules\n' + sMessage;
	alert(sMessage);
}

function killMySessions(){
	window.open('/DSXServices/Handlers/KillMySessions.asp?DSXSessionID=' + DSX_SessionID());
}
function killMySessionHistory(){
	window.open('/DSXServices/Handlers/KillMySessions.asp?KillHistory=True&DSXSessionID=' + DSX_SessionID());
}

function killObject(sName){
    try{
        var oKillObject = document.getElementById(sName);
        var oKillObjectParent=oKillObject.parentNode;
        oKillObjectParent.removeChild(oKillObject);
    }catch(e){
        alert('Failed to locate object: ' + sName);
    }
}
RegisterLoad('DreamServer.Net Basic Client v ' + GenericClient_Version());
