/*++
/*============================================================================
/* Produced by Logica UK, Energy & Utilities Division.
/* Copyright (c) 2000 Logica UK Ltd.
/*
/* FILENAME:    functions.ujs
/* VERSION:     1.16
/* PATHNAME:    /app/kfigkernel/master/neta/sw/bmra/server/bsp/js/s.functions.ujs
/* LAST CHANGE: 08/08/27
/*
/* DESCRIPTION
/* This file contains all the function that are used in order to perform
/* comparisons of high watermarks, hash values, update graphs and finally
/* make ajax calls.
/*============================================================================
--*/
/*
*Initialising Appropriate Variables
*/
var checkbox = [];
var iters = 0;
var updated_times = ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1','1','1'];
var color = "4";
var graphHeight = "400";
var mostrecentlyUpdated = "\"list-style:none; color:red; font-size:10px;  font-weight:bold;\"";
var lessrecentlyUpdated = "\"list-style:none; color:green; font-size:10px;  font-style:italic;\"";
var notrecentlyUpdated = "\"list-style:none; color:#000000; font-size:10px; \"";
var disabled = "\"list-style:none; color:#778899; font-size:10px; \"";
var path = "additional/";
var highWaterMarksDivContainer = document.getElementById('watermarks');
var queue = [];
var queueflag = 'false';

/*
*This function is used to transform the XML documents into teh relevant tables/graphs
*Also filters the items that are supposed to be displayed from each graph
*/

function tranformXML(parameter, elementType, excludedLines, excludedPermanent){
	var excludedPermanentElements = excludedPermanent ||'';
    var chartnumber = parameter;
    var excludedElements = excludedLines || '';

	
		if ( onetoone == false) {    

		if (elementType=='csv'&&!(document.implementation && document.implementation.createDocument)){	var xsl = "xsl/" + elementType + ".xsl";}
		else{		
			var xsl = loadXMLDoc("xsl/" + elementType + ".xsl"); 		}
		}
	
		else{ 

			if(elementType=='graphdataastable'){ 		
				var xsl = loadXMLDoc("xsl/" + pageElements[parameter][6] + "table.xsl");		
			}
			else{
	 
				var xsl = loadXMLDoc("xsl/" + domidnamechange(parameter) + ".xsl");		
			}
		}
    


    
    // code for IE
    if (window.ActiveXObject) {
		
   
        var xslt = new ActiveXObject("Msxml2.XSLTemplate");
        var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
        var xslProc;
        xslDoc.async = false;
        xslDoc.resolveExternals = false;
        xslDoc.load(xsl);
        xslt.stylesheet = xslDoc;
        var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
        xmlDoc.async = false;
        xmlDoc.resolveExternals = false;
        xmlDoc.load(pageElements[parameter][10]);
        xslProc = xslt.createProcessor();
        xslProc.input = xmlDoc;
        if (elementType == 'graph') {
            xslProc.addParameter("excludedLines", excludedElements);
			xslProc.addParameter("excludedPermanent", excludedPermanentElements);
        }
        
        xslProc.transform();
        var str;
        str = xslProc.output;
        
        resultDocument = str;
        
    }
    // code for Mozilla, Firefox, Opera, etc.
    else 
        if (document.implementation && document.implementation.createDocument) {
        
            xsltProcessor = new XSLTProcessor();
            
            xsltProcessor.importStylesheet(xsl);
            if (elementType == 'graph') {
                xsltProcessor.setParameter(null, "excludedLines", excludedElements);
				xsltProcessor.setParameter(null, "excludedPermanent", excludedPermanentElements);
            }
            resultDocument = xsltProcessor.transformToFragment(pageElements[parameter][10], document);
            var serializer = new XMLSerializer();
            var resultDocument = serializer.serializeToString(resultDocument);
            
        }
    
    return resultDocument;
    
}
/*
*Parses a string containing serialized XML and transforms it in a JavaScript XML document
*/

function parseXML(xmlstring){
	if(xmlstring==''){
		
		xmlstring="<data></data>";
		
	}
	
    try //Internet Explorer
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(xmlstring);
    } 
    catch (e) {
        try //Firefox, Mozilla, Opera, etc.
        {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(xmlstring, "text/xml");
        } 
        catch (e) {
        
            return;
        }
    }
    return (xmlDoc);
    
}

/*
*Loads the contents of an xml file
*/
function loadXMLDoc(fname){

    var xmlDoc;
    
    // code for IE
    if (window.ActiveXObject) {
    
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       
    }
    // code for Mozilla, Firefox, Opera, etc.
    else 
        if (document.implementation && document.implementation.createDocument) {
        
            xmlDoc = document.implementation.createDocument("", "", null);
            
        }
        
        else {
        
            alert('Your browser cannot handle this script');
            
        }
    
    xmlDoc.async = false;
    
    xmlDoc.load(fname);
    
    return (xmlDoc);
    
}



/*
* Browser Compatability function.
* Returns the correct XMLHttpRequest depending on the current browser.
*/
function getxmlhttp(){
    var xmlhttp = false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
	
    return xmlhttp;
}

/*
* Browser Compatability function.
* Returns the correct XMLHttpRequest depending on the current browser.
*/
function getthexmlhttp(theurl, themethod, asynch, callbackcase, parameter){

    var xmlhttp = getxmlhttp();
    xmlhttp.open(themethod, theurl, asynch);
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        
            response = xmlhttp.responseText;

            proccessAjax(response, callbackcase, parameter);
            
        }
    }
    return xmlhttp.send(null);
}


/*
* Creates the AJAX request. The functions accepts as parameters the url to request, the method(get or post) , 
* the type of request (asynch or synch, and a pair of parameters to parse in the call back function 
* (call back function is the function to be executed when the AJAX request is completed)
*/

function proccessAjax(response, callbackcase, parameter){

    if (callbackcase == "chwm") {

        var seperatedata = response.split('seperate');
        if (seperatedata.length == '2') {
            highwatermarks = seperatedata[1].split(',');
			for(var i=0; i<pageElements.length;i++){
            pageElements[i][2] = highwatermarks[i];
			}
            compareArrays();
        }
        
        else {
            for (i = 0; i < pageElements.length; i++) {
                pageElements[i][2] = ["-2"];
            }
            compareArrays();
        }
        
    }
    
    else 
        if (callbackcase == "hash") {
        
            var use_part = response.split('<!--hashelementvalue-->');
            if (use_part.length == '2') {

                currentHASH = use_part[1];

                
            }
            
            else {
                pageElements[parameter][1] = "manualadded" + iters;
                currentHASH = "manualadded" + iters;
            }
            
            compareCurrentAndInitialHashValue(currentHASH, parameter);
            
        }
        
        else 
            if (callbackcase == "updatetableelement") {

				var tableDiv = document.getElementById(pageElements[parseInt(parameter, 10)][4])
            
                if(response.search('invalid data')<0){
					
                pageElements[parameter][10] = parseXML(response);	
				tableDiv.innerHTML = tranformXML(parameter, 'table');				

				}
               
                else {


                
                    tableDiv.innerHTML = '<div style="width:100%;text-align:center"><img src="images/elexon_error.jpg" alt="Elexon"/></div>';
                }
                
            }
            
            else 
                if (callbackcase == "getchartXML") {
					
					if (response.search('invalid data') < 0) {
					pageElements[parameter][10] = parseXML(response);
                        var excludedLines = '';
                        
                        var test = document.getElementById(domidnamechange(parameter) + 'form');
                        
                        for (var i = 0; i < test.getElementsByTagName('a').length; i++) {
                        
                            var current = test.getElementsByTagName('a')[i];
                            
                            if (current.className == 'fakecheck') {
                            
                                excludedLines = excludedLines + current.name + ",";
                                
                            }
                            
                        }
                        
                        var chartObj = getChartFromId(pageElements[parameter][6]);
                        chartObj.setDataXML(tranformXML(parameter, 'graph', excludedLines));					
					
					}
                    
                    
                  else {
                    
                        var chartObj = getChartFromId(pageElements[parameter][6]);
                        chartObj.setDataXML('<chart></chart>');
                        
                    }
                    
                }
                
                else 
                    if (callbackcase == "storexmlinvariable") {
						
						if (response.search('invalid data') < 0) {
 						pageElements[parameter][10] = parseXML(response);	
        	      	   			update();						
						}
                       
                        else {

        	      	   			update();						                        
                        }
                        
                    }
    
}

/*============================================================================
 Called when the page loads every time when a fixed period of time is passed
 Calls the Setvars function
 ==============================================================================*/
function checkCurrent(){
	if (dT == 'NRT') { 
		setTimeout("checkCurrent()", parseInt(set_timeout, 10));
		if(document.getElementById('refreshIcon')) {}
		else {
		appendRefreshIcon ();
		}

	};

    setVars();
}

/*============================================================================
 Injects the refreshicon into the html of the page
 ==============================================================================*/

function appendRefreshIcon (){
			//creating the dom element that will hold the link and will be injected to the appropriate div
			var refreshline = document.createElement("a");
			refreshline.id = 'refreshIcon';
			refreshline.setAttribute('href', '/bwx_help.htm#pollingRefresh');
			refreshline.setAttribute('title', 'This page will update when new data become available');
			refreshline.setAttribute('target', '_blank');
			var refreshlinkimage = document.createElement("img");
			refreshlinkimage.setAttribute('src', '/bwx_refreshIcon.gif');
			refreshlinkimage.setAttribute('border','0');
			refreshline.appendChild(refreshlinkimage);
				//if page is BMRSSysteData like then 
				if(document.getElementById('banner')){
					document.getElementById('banner').appendChild(refreshline);
					document.getElementById('refreshIcon').style.top = '50px';
					document.getElementById('refreshIcon').style.right = '48px';
 
				}
				//if page is Warning page Like 
				else if (document.getElementById('swcontentwrapper'))
				{
					document.getElementById('swcontentwrapper').appendChild(refreshline);
					document.getElementById('refreshIcon').style.top = '50px';
					document.getElementById('refreshIcon').style.right = '48px';
				}
				else{
				//if page is Summary page then..
					document.getElementById('leftcolumnwrapper').appendChild(refreshline);
					document.getElementById('refreshIcon').style.top = '3px';
					document.getElementById('refreshIcon').style.right = '3px';
		
			}

			document.getElementById('refreshIcon').style.position = 'absolute';
}





/*
*	Initialises the High Water Mark values with a value of ‘-1’ and calls the drawSummary(), checkCurrent() and userTickUntick()
*/
function getInitialTXs(){
    for (i = 0; i < pageElements.length; i++) {
        pageElements[i][1] = "-1";
    }
    drawSummary();
    checkCurrent();
    userTickUntick();
}

/*
*	Increments the current iters variable (iters represents the number of polls for High Water Marks  
*   made to the server ) and triggers the AJAX request for the current High Water Marks.
*/

function setVars(){

    /*============================================================================
     If the page just loaded then just calls the function that fills the floating
     menu
     ==============================================================================*/
    iters++;
    var currentHWMs;
    getthexmlhttp(path + "getSectionTXs.php?element=" + pageid, "GET", "true", "chwm", "none");
   
}


function domidnamechange(elementnumber){

    if (pageElements[elementnumber][6] == 'demand214') {
    
        var domelement = '214demand';
        
    }
    
    else 
        if (pageElements[elementnumber][6] == 'surplus214') {
        
            var domelement = '214surplus';
            
        }
        
        else {
        
            var domelement = pageElements[elementnumber][6];
            
        }
    
    return domelement;
    
}


/*
*	Compares the cHWM values of each element against the iHWM ones. If there is a difference then it 
*	triggers the AJAX call to get the iHASH value for that element and calls the drawSummary() 
*	in order to update the update status of the menu elements.
*/

function compareArrays(){

    for (i = 0; i < pageElements.length; i++) {
        if (checkbox[i] != "") {
            if ((pageElements[i][1].replace(/^\s+|\s+$/g, '')) != (pageElements[i][2].replace(/^\s+|\s+$/g, ''))) {
                //if we have difference in the ith place of iHWM with cHWM			
                pageElements[i][1] = pageElements[i][2].replace(/^\s+|\s+$/g, '');
                //Replace the iHWM value with the current one
                ajax_me(i);
            }
        }
    }
    drawSummary();
}



function ajax_me(iteration){

    queue.push(iteration);
    
    if (queueflag == 'false') {
        queueflag = 'true';
        setTimeout("ajaxqueueing()", parseInt(70, 10));
        
    }
    
}

function ajaxqueueing(){

    if (queue.length > 20) {
    
    }
    
    else {
    
        var i = queue.shift();
        
      getthexmlhttp(path + "getSectionHash.php?element=" + domidnamechange(i), "GET", "true", "hash", i)
        
    }
    if (queue.length == '0') {
    
        queueflag = 'false';
    }
    else {
        setTimeout("ajaxqueueing()", parseInt(300, 10));
    }
    
}

/*
* Accepts a cHASH value and compares it with the stored initial hash value of the i-th  pageElement. 
* If the same then does nothing but if not it means that the data for this element have changes and 
* thus replaces the initial hash value with the current one and then it triggers the AJAX 
* call that fetches the new data that will be used to render the new element.
*/

function compareCurrentAndInitialHashValue(cHASH, i){

    var currentHASH = cHASH.replace(/^\s+|\s+$/g, '');

    if ((pageElements[i][3]) != (currentHASH)) { 
 
    	var toBeUpdatedListElement = document.getElementById(pageElements[i][4] + "list");
        pageElements[i][3] = currentHASH; //Replace the iHASH value with the current one
        updateElement(i);
        updated_times[i] = iters;
        if (toBeUpdatedListElement) {
            toBeUpdatedListElement.innerHTML = updateMenuElements(i);
        }
        
    }
}


/*
* Updates the status of an element in the left-hand-side float menu. 
*/

function updateMenuElements(i){

    var currentstyle = '';
    var display_hide = 'exclude';
    var difference = (parseInt(iters, 10) - parseInt(updated_times[i], 10));
    
    if (difference <= (parseInt(color, 10))) {
        currentstyle = mostrecentlyUpdated;
        
    }
    else 
        if (difference > parseInt(color, 10) && difference < 10) {
            currentstyle = lessrecentlyUpdated;
        }
        else {
        
            currentstyle = notrecentlyUpdated;
            
        }
    
    if (checkbox[i] == "") {
        currentstyle = disabled;
        display_hide = 'include'
    }
    
    var update_me = "<div  id=\"" + pageElements[i][4] + "list\" class=\"IHWM\"  value=\"" + pageElements[i][1] + "\"><a href='#SummaryPage' title='Click here to " + display_hide + " the " + pageElements[i][8] + " " + pageElements[i][0] + "' onclick='show_hide_div(" + i + ");userTickUntick();' class='fakecheck fake" + checkbox[i] + "' id='fakecheckbox" + i + "''  style='color:white' >_</a><input style='display:none'  type='checkbox' name='" + pageElements[i][7] + "' " + checkbox[i] + " \><a title='Click here to scroll to the " + pageElements[i][8] + " " + pageElements[i][0] + "' style=" + currentstyle + " href=#" + pageElements[i][5] + ">" + pageElements[i][8] + "</a></div>";
    
    return update_me;
}

/*
* Renders the menu list on the left hand side menu 
*/

function drawSummary(){

    var texts = '';
	    
    for (i = 0; i < pageElements.length; i++) {
        texts = texts + updateMenuElements(i);
    }
    
    if (highWaterMarksDivContainer) {
    
        highWaterMarksDivContainer.innerHTML = texts;
        
    }
   
}

/*
* This function servers the purpose of a toggle. When called it changes the height of 
* all the graph DIVS in the page. It switches between to preset height values 
*/
function resizeMe(){
    if (graphHeight == "400") {
        graphHeight = "250";
    }
    else {
        graphHeight = "410";
    }
    for (i = 0; i < pageElements.length; i++) {
		var resizeGraphs = document.getElementById(pageElements[i][4]);
        if (pageElements[i][0] == "graph") {
            resizeGraphs.style.height = parseInt(graphHeight, 10) + "px";
            updateElement(i, 'true');
        }
    }
}

function FC_Rendered(domId){

    for (i = 0; i < pageElements.length; i++) {
    
        if (pageElements[i][6] == domId) {
        
            var chartnumber = i;
            
        }
    }
    
    getthexmlhttp(path + 'soapfunctions.php?element=' + domidnamechange(chartnumber), "GET", "true", "getchartXML", chartnumber)
    
    return true;
}

/*
*	This function is used to trigger the AJAX requests that will result in the update of an element. 
*   Also when it comes to a graph if the graph has not been created on the page 
*   (because it was set to be disabled or because the page loads for the first time) then this 
*   function is embedding it to the page.
*/
function updateElement(elementnumber, resize){

    /*============================================================================
     When the element is graph
     ==============================================================================*/
    if (pageElements[elementnumber][0] == "xml") {
    
        getthexmlhttp(path + 'soapfunctions.php?element=' + domidnamechange(elementnumber), "GET", "true", "storexmlinvariable", elementnumber);
        
    }
    
    else 
        if (pageElements[elementnumber][0] == "graph") {
            if ((iters == "1") || (resize == 'true')||(getChartFromId(domidnamechange(elementnumber)) == null)) {
            
                var chartid = "chart" + elementnumber;
                chartid = new FusionCharts(path + "Charts/" + pageElements[elementnumber][11]+'?ChartNoDataText=There is currently no data to display', pageElements[elementnumber][6], "600", graphHeight, "0", "1");
                chartid.setDataXML("<chart></chart>");
                chartid.render(pageElements[parseInt(elementnumber, 10)][4]);
            }
            
            else {
            
                getthexmlhttp(path + 'soapfunctions.php?element=' + domidnamechange(elementnumber), "GET", "true", "getchartXML", elementnumber)
                
            }
            
        }
        /*============================================================================
     When the element is table
     ==============================================================================*/
        else {

            getthexmlhttp(path + "soapfunctions.php?element=" + pageElements[elementnumber][6], "GET", "true", "updatetableelement", elementnumber)
            
        }
}


function tickUntick(action){

    for (i = 0; i < pageElements.length; i++) {
    var divDisplayStatus = document.getElementById(pageElements[i][7]).style;
        if (action == "tick") {
            if (checkbox[i] == "checked") {
                checkbox[i] = "";
                divDisplayStatus.display = "none";
                
            }
            show_hide_div(i);
            
        }
        
        else {
        
            if (checkbox[i] == "") {
                checkbox[i] = "";
                divDisplayStatus.display = "block";
            }
            show_hide_div(i);
            
        }
    }
    userTickUntick();
}

function userTickUntick(){
    var count = '1';
    var display = '';
	var showHideCheckboxes = document.getElementById('tick');
    for (i = 0; i < pageElements.length; i++) {
    
        if (checkbox[i] == "checked") {
            count++;
        }
    }
    
    if (count == 1) {
        display = "<div style='cursor:pointer;' onclick=\"tickUntick(\'tick\')\"><a href='#'  class='fakecheck' style='color:white' >_</a>Display All</div> ";
    }
    
    else {
        display = "<div  style='cursor:pointer;' onclick=\"tickUntick(\'untick\')\" ><a href='#'  class='fakecheck fakechecked'style='color:white' >_</a>Hide All</div>";
    }
    
    if (document.getElementById('tick')) {
    
        showHideCheckboxes.innerHTML = display;
        
    }
    
}

/*
*	This function is triggered when a user decides to hide/display an element within the page. 
* 	For example if a user wants to exclude System Warnings table from the page, he will have to click on 
*   the checkbox next to the System Warnings link (the one in the left hand side floating menu). 
*   This function get the current display property of the element. If the element is hidden then changes 
*   to displayable and also updates the element on the menu list.
*/

function show_hide_div(divid){
var ElementsID = document.getElementById(pageElements[divid][7]);
var ElementsListID = document.getElementById(pageElements[divid][4] + "list");
    if (ElementsID.style.display == "none") {
    
        document.getElementById(pageElements[divid][7]).style.display = "block";
        checkbox[divid] = "checked";
        ajax_me(divid);
        
    }
    
    else {
    
        ElementsID.style.display = "none";
        checkbox[divid] = "";
        
    }
    
    var updateResult = updateMenuElements(divid);
    ElementsListID.innerHTML = updateResult;
	
	ElementsID = null;
    ElementsListID = null;
}

/*
*	This function is triggered when a users decides to disable/enable the plotting of an element within a graph. 
*/

function displayHideGraphElement(formid, element){

    var excludedLines = '';
    
    var test = document.getElementById(formid);
    
    formid = formid.split('form');
    
    var current = test.getElementsByTagName('a')[element];
    
    if (current.className == "fakecheck fakechecked") {
    
        current.className = "fakecheck";
        
    }
    
    else {
    
        current.className = "fakecheck fakechecked";
        
    }
    
    for (var i = 0; i < test.getElementsByTagName('a').length; i++) {
    
        var current = test.getElementsByTagName('a')[i];
        
        if (current.className == 'fakecheck') {
        
            excludedLines = excludedLines + current.name + ",";
            
        }
        
    }
    
    for (i = 0; i < pageElements.length; i++) {
        if (pageElements[i][6] == formid[0]) {
            parameter = i;
        }
    }
    
    var chartObj = getChartFromId(pageElements[parameter][6]);
    
    chartObj.setDataXML(tranformXML(parameter, 'graph', excludedLines));
    
}

/*
*	This function generates the modal window
*/

function modalWindow(action, element){

	var modalWindowWrapper = document.getElementById('modalWindowWrapper');
	var modalWindow = document.getElementById('modalWindow');
	if (action == 'exit') {

	 	modalWindowWrapper.style.display = 'none';			
		modalWindow.style.display = 'none';
		modalWindow.innerHTML ='';
			 if (document.all)
            {               
                document.body.scroll = "yes";
				document.getElementsByTagName('html')[0].style.overflow = 'scroll';
            }

	}
	else if(action=='display') {
			var datastring = tranformXML(element, 'graphdataastable');

			if(datastring.search('Error')>=0||datastring==''){
				datastring = "<div style='margin:auto;text-align:center;position:relative;top:40px;'>No data to display</div>";

			}

		
		 if (document.all)
		 {               
                document.body.scroll = "no";
				document.getElementsByTagName('html')[0].style.overflow = 'hidden';
				modalWindow.style.top = parseInt(document.documentElement.scrollTop,10) + parseInt(document.documentElement.clientHeight/2,10)+ "px"				

         }
		else
		{
				modalWindow.style.top= '50%';			
				modalWindow.style.position= 'fixed';				
			
		}
		
	 	modalWindowWrapper.style.display = 'block';			
		modalWindowWrapper.style.height = document.body.clientHeight+parseInt('500',10)+'px';
			
		
		var outputstring = "<div style='position:relative; top:10px; right:20px; text-align:right;'>";
			if(element!=15){
			outputstring = outputstring + "<a   href='additional/saveoutput.php?element="+pageElements[element][6]+"historic&output=XML' title='Save data as XML file' href='#saveasXML' target ='_blank' style='text-decoration:none;margin-right:5px;'><span class='orangeicon' >HISTORIC DATA XML</span></a>";
			outputstring = outputstring + "<a   href='additional/saveoutput.php?element="+pageElements[element][6]+"historic&output=CSV' title='Save data as EXCEL file' href='#saveasEXCEL' target ='_blank' style='text-decoration:none;'><span class='orangeicon' >HISTORIC DATA CSV</span></a>";			
			}
			if(element==15){
			outputstring = outputstring + "<a   href='additional/saveoutput.php?element="+pageElements[element][6]+"&output=XML' title='Save data as XML file' href='#saveasXML' target ='_blank' style='text-decoration:none;margin-right:5px;'><span class='orangeicon' >XML</span></a>";
			outputstring = outputstring + "<a   href='additional/saveoutput.php?element="+pageElements[element][6]+"&output=CSV' title='Save data as EXCEL file' href='#saveasEXCEL' target ='_blank' style='text-decoration:none;'><span class='orangeicon' >CSV</span></a>";			
			}
			outputstring = outputstring + "</div><div style='margin-top:20px;'>"+datastring+ "</div><div style='height:30px;width:100%; text-align:right;'><a href='#SummaryPage'   onClick='modalWindow(\"exit\",\"\");'><img src=\"images/sys_warn_button.jpg\" alt=\"Return to the main page\" border=\"0\"/> </a></div>";
		modalWindow.innerHTML = outputstring;								
		modalWindow.style.display = 'block';	
		modalWindow.scrollTop = '0px';
					
		
	}
	
	modalWindowWrapper = null;
 	modalWindow = null;
	datastring = null;
}

/*
*	Functions used to create,read and delete cookies
*/
function based_on_cookie(){

    for (var i = 0; i < pageElements.length; i++) {
    var divDisplayStatus = document.getElementById(pageElements[i][7]);
        if (checkbox[i] == "" && divDisplayStatus.style.display != "none") {
        
            divDisplayStatus.style.display = "none";
            
        }
        
    }
    
}

function createCookie(name, value, days){
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else 
        var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name){

    var ca = document.cookie.split('=');
 
    if (name == ca[0]) {
		    
        checkbox = document.cookie.split(',');

        var temp = checkbox[0].split('=');
        checkbox[0] = temp[1];
        
        for (i = 0; i < checkbox.length; i++) {
            if (checkbox[i] == "") {
            };
            
                    }
    }
    else {
    
        for (i = 0; i < updated_times.length; i++) {
        
            checkbox[i] = 'checked';
            
        }
        
    }
    
    return null;
    
}

function eraseCookie(name){
    createCookie(name, "", -1);
}

//end of cookies
function confirmExit(){

    createCookie('SummaryPageCookie', checkbox, 7);
    
}




