
// ************ function Integration LSE **************** //


function SwitchPagingLinks(obj){
	var el = document.getElementById("menu"+obj);
	if(el.style.display == "none"){ 
		for (i=1; i<=4; i=i+1){
			document.getElementById("menu"+i).style.display="none";
		}
		el.style.display="block";
	}
}

function sendto(page)
{
	if (window.opener != null)
	{
		var win = this;
		window.opener.location.href = page;
		window.opener.parent.focus();
	}
	else
	{
		window.location.href = page;
	}
}

function openWin2(sURL, sWinName, iWidth, iHeight, sFeatures) {
	var iPopupLeft, iPopupTop;
	iPopupLeft = 10 //(screen.width - iWidth)/2;
	iPopupTop = 10 //(screen.height - iHeight)/2;
	sFeatures = sFeatures + 'screenX='+iPopupLeft+',screenY='+iPopupTop+',left='+iPopupLeft+',top='+iPopupTop+',height='+iHeight+',width='+iWidth;
	var oWindow = window.open(sURL, sWinName, sFeatures, true);
	// make sure that each instance of a portal parent window has a unique name
	window.name="portalparentwindow" + Math.random();
	oWindow.focus();
	return true;
}

function openWinBig(sURL) {
	if(sURL!=""){
		var oWindow = window.open(sURL);
		oWindow.focus();
		
	}else{
		return false;
	}
	return true;
}

// functions for Search Instruments //

var OpenerFormIdentifier;
var OpenerHiddenIdentifier;

function searchInstrument(formIdentifier,hiddenIdentifier, pageName, queryString)
{
	openString = pageName + "?FI=" + formIdentifier + "&HI=" + hiddenIdentifier + queryString;
	var win = window.open(openString, "SInstrument","width=685,height=620,status=yes,resizable=yes,menubar=no,scrollbars=no");
	OpenerFormIdentifier = formIdentifier;
	OpenerHiddenIdentifier = hiddenIdentifier;
		
	win.focus();
}

function Update(assetName, symbol) {		
	var namebox = document.getElementById(OpenerFormIdentifier);
	var hidsymbol = document.getElementById(OpenerHiddenIdentifier);
				
	if (namebox != null && hidsymbol != null)
	{
		namebox.value = assetName;
		hidsymbol.value = symbol;
		return true;
	}			
	return false
	
}

function UpdateOpener(assetName, symbol) {
	var update = true;
	
	if (window.opener.CheckForDuplicates != null)
	{
		update = !window.opener.CheckForDuplicates(symbol)
	}
			
	if (update)
	{
		
		if (window.opener.Update != null)
		{
			if (window.opener.Update(assetName,symbol)) self.close();
		}
	}
	else
	{
		alert('Asset has already been selected');
	}
}

// end functions for Search Instruments //






// ************ function Actual LSE **************** //

<!--

// Code for User Survey
function hideObject() {
	if (document.layers) {
	window.location.reload();
}
	else if (document.all) {
		window.location.reload();
	}
	else if (document.getElementById && !document.all) {
		window.location.reload();
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
		func();
		}
	}
}

var da = (document.all) ? 1 : 0;

var pr = (window.print) ? 1 : 0;

var mac = (navigator.userAgent.indexOf("Mac") != -1); 

// Prints a document in a new window and appends &print=true to the querystring
function printThisNewWin()
{
	// create reference to current location
	var url = document.location.href;
	var delim = "?";
	
	if (url.indexOf("?") > 0)
		delim = "&";
	
	url += delim + "print=true";
	
	popupscroll(url, 780, 500);
	
}
function isAutoPrint()
{
	var url = document.location.href;
	if (url.indexOf("print=true") > 0)
		return true;
	else
		return false;
}
function autoPrint()
{
	//determine if "print=true" exists in the QueryString
	if (isAutoPrint())
		printThis();
}
function printThis() 
{
	

	if (pr) 
	{ 	// NS4, IE5
		
		window.print();
	
	} 
	else if (da && !mac) 
	{ 	// IE4 (Windows)
		
		vbPrintPage();
	
	} 
	else 
	{ 	// other browsers
		
		alert("Sorry, your browser doesn't support this feature.\n\n Please try using the Print button on the browser toolbar.");
	
	}


}


if (da && !pr && !mac) with (document) 
{
	
	writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	
	writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	
	writeln('Sub window_onunload');
	writeln('  On Error Resume Next');
	
	writeln('  Set WB = nothing');
	writeln('End Sub');
	
	writeln('Sub vbPrintPage');
	writeln('  OLECMDID_PRINT = 6');
	
	writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
	
	writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
	
	writeln('  On Error Resume Next');
	
	writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
	
	writeln('End Sub');
	
	writeln('<' + '/SCRIPT>');

}


function bookmarkThis() 
{
	

	if (window.external) 
	{
		
		window.external.AddFavorite(location.href,document.title)
	
	} 
	else 
	{
	
		alert("Sorry, your browser doesn't support this feature.")
	}
	}


function imgOver(image) 
{
	
	if(document.images && image.src.indexOf("-over.gif")==-1) 
	{
   		
		image.src = image.src.substring(0,(image.src.indexOf(".gif"))) + "-over.gif";
    
	}

}


function imgOut(image) 
{
	
	if(document.images && image.src.indexOf("-over.gif")!=-1) 
	{
    	
		image.src = image.src.substring(0,(image.src.indexOf("-over.gif"))) + ".gif";
    
	}

}


function checkKeyPress(imageButton)

{	
	
	if (event.keyCode==13)
	
	{
		
		var theform;
		
		event.keyCode = 0;
		
		event.returnValue = false;
		
		event.cancelBubble = true;
		
		theform = document.forms[0];
		

		if (theform.__EVENTTARGET) 
		{
			
			theform.__EVENTTARGET.value = imageButton.split("$").join(":");
		
		}
		

		if (document.getElementById)
			
			document.getElementById(imageButton).click();
		
		else if (document.all)
			
			document.all[imageButton].click();				
	
	}

}



function js_forcessl()

{
	
	var strRootURL = location.href;
	
	var itMatches;
	
	itMatches = strRootURL.match(/^https/);


	if(itMatches!="https")
	
	{
		
		strRootURL = strRootURL.replace(/^http/,"https");
		
		location.replace(strRootURL);
		
		//window.navigate(strRootURL);
	
	}
	

}



function js_forcenonssl()

{
	
	var strRootURL = location.href;
	
	var itMatches;
	
	itMatches = strRootURL.match(/^https/);
	
	if(itMatches!="https")
	{
	}
	
	else
	
	{
		
		strRootURL = strRootURL.replace(/^https/,"http");
		
		location.replace(strRootURL);
		
		//window.navigate(strRootURL);
	
	}
	

}



function popup(strPath, iWidth, iHeight) 
{
	
	strWindow = window.open(strPath, 'popup', 'width=' + iWidth + ',height=' + iHeight)

}

function popupscroll(strPath, iWidth, iHeight) 
{
	
	strWindow = window.open(strPath, 'popup', 'scrollbars,resizable,width=' + iWidth + ',height=' + iHeight)
}


function popupscrollpositioned(strPath, iWidth, iHeight, iLeft, iTop)
{
	strWindow = window.open(strPath, 'popup', 'scrollbars,resizable,width=' + iWidth + ',height=' + iHeight + ',screenX=' + iLeft + ',screenY=' + iTop + ',left=' + iLeft + ',top=' + iTop)
	
}

// Keeps track of current control calling the event handler below. Allows us to access the same 
// control when it comes time to paste the resource into the placeholder
var currentEditor;

//applies event handlers for custom telerik buttons
function loadCustomEvents(clientID) 
{
	
	if (window.RadEditorCommandList)
	{
		//searches for a resource using the Resource Locator
		RadEditorCommandList['SearchResource'] = function(commandName, editor, oTool)
		{

		currentEditor = editor;
		
			//link to the resource locator
			var iHeight = 700;
			var iWidth = 900;
			var iLeft = ((screen.width - iWidth) / 2);
			var iTop = ((screen.height - iHeight) / 2);
			popupscrollpositioned('/LSECWS/Console/Applications/ResourceLocator.aspx?launchmode=telerik', iWidth, iHeight, iLeft, iTop);
			
			return false;

		}
	}
}

function pasteResource(clientID, itemPath, displayName, type)
{
    var editor = currentEditor;

    if (type == "image")
    {
    	editor.PasteHtml('<img src="'+itemPath+'" alt="'+displayName+'"></a>');
    }
    else
    {
    	editor.PasteHtml('<a href="'+itemPath+'">'+displayName+'</a>');
    }

}

function mostra()
  {
   if (document.all)
      document.all.bannerview.style.visibility="visible";
   if (document.layers)
      document.layers['bannerview'].visibility="visible";
   if (document.getElementById)
      document.getElementById('bannerview').style.visibility="visible";
}
//-->

function createAjaxObj(){
	var httprequest=false
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc
			httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
		}
		else if (window.ActiveXObject){ // if IE
			try {
				httprequest=new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					httprequest=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
			}
		}
		return httprequest
	}

var xmlhttp = createAjaxObj();

function switchFrame(container, urlframe){
	 var oOptions = {
       method: "get",
       evalScripts:true,
       onFailure: function(oXHR, oJson){
       	document.getElementById(container).innerHTML="&nbsp;";
       	//alert("unsuccessful!!!");
       }
   };
   var Destination = {
			success: container,
			failure: 'containerError'
   };
   
   var oRequest = new Ajax.Updater(Destination, urlframe, oOptions);
}

function requestContentForProtectedUrl (urlpage,idDiv,loginUrl) {

	var callbackProxy = function(dataFromServer) {
	  callbackFunc(dataFromServer, urlpage, idDiv, loginUrl);
	};

	var callMetaData = { callback:callbackProxy };

	SsoUtility.getSsoUserDwr(callMetaData);

}

function callbackFunc(dataFromServer, dataFromBrowser1, dataFromBrowser2, dataFromBrowser3) {
	if (dataFromServer.username != null && dataFromServer.status == 3){
		requestContentBase(dataFromBrowser1,'','',false,false,false,dataFromBrowser2);
	}else {
		parent.document.location.href = dataFromBrowser3; 
	}
}

//La variabile isBusy Š stata aggiunta per evitare un bug di mozilla (NS_ERROR_NOT_INITIALIZED)
//che si verifica quando una request non Š ancora conclusa e ne viene fatta un'altra.
var isBusy=false;
function requestContentBase(urlpage,formname,ordParams,isForm,checkForm,useWaitMessage,idDiv){
	if (isBusy)
	{
		xmlhttp.onreadystatechange = function () {}
		xmlhttp.abort();
		xmlhttp = createAjaxObj();
	}
	
	if(isForm){
		if(checkForm){	
			var queryString = getquerystring(formname);
			
			if(urlpage.indexOf("?")!=-1){
				if(ordParams != null && ordParams.length>0)
					xmlhttp.open("GET",urlpage+"&"+ordParams+"&"+queryString,true);
				else
					xmlhttp.open("GET",urlpage+"&"+queryString,true);
			}else{
				if(ordParams != null && ordParams.length>0)
					xmlhttp.open("GET",urlpage+"?"+ordParams+"&"+queryString,true);
				else
					xmlhttp.open("GET",urlpage+"?"+queryString,true);
			}
			isBusy=true;
		}else{
			return false;
		}
	}else{
		xmlhttp.open("GET",urlpage,true);
		isBusy=true;
	}
	
	//xmlhttp.onreadystatechange =statusListener;
	
	xmlhttp.onreadystatechange = function(){
		if(useWaitMessage){
			if (xmlhttp.readyState == 1) {
				if(document.getElementById('wait').innerHTML){
					document.getElementById(idDiv).innerHTML=document.getElementById('wait').innerHTML;
				}else{
					document.getElementById(idDiv).innerHTML="LOADING....";
				}
			}
		}
		if (xmlhttp.readyState == 4) {
			document.getElementById(idDiv).innerHTML=xmlhttp.responseText;
			var scripts = document.getElementById(idDiv).getElementsByTagName('script');
			var code;
			for (var i = 0; i < scripts.length; i++) {
				code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
					scripts[i].text ? scripts[i].text : 
					scripts[i].textContent;
				try {
					eval(code);
				} catch(e) {}
			}
			isBusy = false;
		
		}
	}
	xmlhttp.send(null);
}

//Questa funzione serve a seriazlizzare i paramerti della form mettendoli sotto forma di querystring
function getquerystring(formname) {
    
	var form = document.forms[formname];
	var qstr = "";
	
    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }
	
	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
					|| elemType == "BUTTON"
					|| elemType == "RESET"
					|| elemType == "SUBMIT"
					|| elemType == "FILE"
					|| elemType == "IMAGE"
                    || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}

