﻿//Variable for dialog support
var win=null;
var myWindow = null;

// This function calls the Web Service method.  
function ViewTextDlg(textId)
{                
    Notisum.WebServices.Text.GetPageText(textId, OnSucceeded);
}

// This is the callback function that
// processes the Web Service return value.
function OnSucceeded(result)
{
	LeftPosition=(screen.width)?(screen.width-400)/2:100;
	TopPosition=(screen.height)?(screen.height-400)/2:100;
	
	settings='width=400,height=400,top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no';
		
		if (myWindow != null)
		{
		    myWindow.close();
		   myWindow = null; 
		}

        myWindow = window.open("", "textDlg", settings);    
        if (!myWindow.opener)
        { 
            myWindow.opener = self;         
        }     
        myWindow.document.write('<html><head><title>Notisum Rättsnätet</title><link type=text/css rel=Stylesheet href=../Resources/Global/Css/Generic.css /><script language=javascript type=text/javascript src=../Resources/Global/Js/Generic.js></script></head><body style=""><div style=width:100%;text-align:right;background-color:#ffbd4a;padding:3px 3px 3px 3px><input type=button value=Stäng onclick=javascript:self.close(); /></div><div style=overflow:auto;width:100%;text-align:left;padding:10px 10px 10px 10px;>' + result + '</div></body></html>');
        myWindow.focus();

}
            
// Popup dialog that opens in the middle of the screen.
function ShowDialog(page,name,w,h,scrollbar)
{
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;

	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbar+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no';
	win=window.open(page,name,settings);
	if (!win.opener)
	{
		win.opener = self;
	}
	
	win.focus();
}

function showPageDialog()
{                                                                  
    var dialog = $find('pageDialog');
    dialog.show(); 
} 

function closePageDialog()
{
    var dialog = $find('pageDialog');
    dialog.hide(); 
}

function showChildItems(tagName)
{
    var div = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericTopMenu_'+tagName);   
    if (!div)
    { 
        div = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericTopMenu_'+tagName);
    }     
    div.style.display = 'inline'; 
}

function hideChildItems(tagName)
{
    var div = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericTopMenu_'+tagName);    
    if (!div)
    { 
        div = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericTopMenu_'+tagName);
    }
    div.style.display = 'none';  
}

function showIdentifyPanel()
{
    var div = document.getElementById('identifyMeContainer');
    div.style.display = 'inline'; 
}

function hideIdentifyPanel()
{
    var div = document.getElementById('identifyMeContainer');
    div.style.display = 'none'; 
}

var TRange=null

function findString()
{
    var elm = document.getElementById('t1');    
    var str = elm.value;
    
    if (parseInt(navigator.appVersion)<4) return;
    var strFound;
    if (navigator.appName=="Netscape")
    {
        strFound=self.find(str);
        if (!strFound) 
        {
            strFound=self.find(str,0,1)
            while (self.find(str,0,1)) continue
        }
    }
    
    if (navigator.appName.indexOf("Microsoft")!=-1) 
    {
        if (TRange!=null) 
        {
            TRange.collapse(false)
            strFound=TRange.findText(str)
            if (strFound) TRange.select()
        }
        if (TRange==null || strFound==0)
        {
            TRange=self.document.body.createTextRange()
            strFound=TRange.findText(str)
            if (strFound) TRange.select()
        }
    }
    if (!strFound) alert ("Sidan innehåller inte ordet '"+str+"'.")
}

function SettingsNotAvailable()
{
    alert('Du har loggat in med automatik och behöver identifiera dig för att komma åt dina inställningar.');
}

function SearchSelectAll()
{
    var selectAll = GetSearchAllOption();
   
    if (selectAll != null)
    { 
        if (selectAll.checked == true)
        {  
            var selRf = GetSearchAllRfOption();
            if (selRf != null)
            { 
                selRf.checked = false; 
                selRf.disabled = selectAll.checked;  
            }
            
            var law = GetLawOption();
            if (law != null)
            {  
                law.checked  = selectAll.checked;
            }
            var ind = GetLawIndexOption();
            if (ind != null)
            {  
                ind.checked  = selectAll.checked;
            }  
            var ext = GetExtOption();
            if (ext != null)
            {  
                ext.checked  = selectAll.checked;
            }    
            var hd = GetHdOption();
            if (hd != null)
            {  
                hd.checked  = selectAll.checked;
            } 
            var ad = GetAdOption();
            if (ad != null)
            {  
                ad.checked  = selectAll.checked;
            }                                            
            var md = GetMdOption();
            if (md != null)
            {  
                md.checked  = selectAll.checked;
            }  
            var mg = GetMgOption();
            if (mg != null)
            {  
                mg.checked  = selectAll.checked;
            }     
            var mo = GetMoOption();
            if (mo != null)
            {  
                mo.checked  = selectAll.checked;
            }    
            var prop = GetPropOption();
            if (prop != null)
            {  
                prop.checked  = selectAll.checked;
            }    
            var rh = GetRhOption();
            if (rh != null)
            {  
                rh.checked  = selectAll.checked;
            }    
            var rr = GetRrOption();
            if (rr != null)
            {  
                rr.checked  = selectAll.checked;
            }                                 
        }
        else
        {
            var selRf = GetSearchAllRfOption();
            if (selRf != null)
                selRf.disabled = selectAll.checked;  
                         
            var law = GetLawOption();
            if (law != null)
                law.disabled = selectAll.checked;          
            var ind = GetLawIndexOption();
            if (ind != null)
                ind.disabled = selectAll.checked;          
            var ext = GetExtOption();
            if (ext != null)
                ext.disabled = selectAll.checked;          
            var hd = GetHdOption();
            if (hd != null)
                hd.disabled = selectAll.checked;          
            var ad = GetAdOption();
            if (ad != null)
                ad.disabled = selectAll.checked;          
            var md = GetMdOption();
            if (md != null)
                md.disabled = selectAll.checked;          
            var mg = GetMgOption();
            if (mg != null)
                mg.disabled = selectAll.checked;          
            var mo = GetMoOption();
            if (mo != null)
                mo.disabled = selectAll.checked;          
            var prop = GetPropOption();
            if (prop != null)
                prop.disabled = selectAll.checked;          
            var rh = GetRhOption();
            if (rh != null)
                rh.disabled = selectAll.checked;          
            var rr = GetRrOption();
            if (rr != null)
                rr.disabled = selectAll.checked;          
        }    
    } 
}

function SearchSelectAllRf()
{
    var selectAllRf = GetSearchAllRfOption();
    
    if (selectAllRf != null)
    {
        if (selectAllRf.checked == true)
        {
            var selAll = GetSearchAllOption();
            if (selAll != null)
            {
                selAll.checked = false;
                selAll.disabled = selectAllRf.checked;  
            }                  
             
            var prop = GetPropOption(); 
            if (prop != null)
            {  
                prop.checked  = false;         
            }   
            var law = GetLawOption();
            if (law != null)
            {  
                law.checked  = false;
            }
            var ind = GetLawIndexOption();
            if (ind != null)
            {  
                ind.checked  = false;
            }  
            var ext = GetExtOption();
            if (ext != null)
            {  
                ext.checked  = false;
            }
                        
            var hd = GetHdOption();
            if (hd != null)
            {  
                hd.checked  = selectAllRf.checked;
            } 
            var ad = GetAdOption();
            if (ad != null)
            {  
                ad.checked  = selectAllRf.checked;
            }                                            
            var md = GetMdOption();
            if (md != null)
            {  
                md.checked  = selectAllRf.checked;
            }  
            var mg = GetMgOption();
            if (mg != null)
            {  
                mg.checked  = selectAllRf.checked;
            }     
            var mo = GetMoOption();
            if (mo != null)
            {  
                mo.checked  = selectAllRf.checked;
            }     
            var rh = GetRhOption();
            if (rh != null)
            {  
                rh.checked  = selectAllRf.checked;
            }    
            var rr = GetRrOption();
            if (rr != null)
            {  
                rr.checked  = selectAllRf.checked;
            }              
        }
        else
        {
            var selAll = GetSearchAllOption();
            if (selAll != null)
                selAll.disabled = selectAllRf.checked;  
        
            var prop = GetPropOption(); 
            if (prop != null)
                prop.disabled = selectAllRf.checked;          
            var law = GetLawOption();
            if (law != null)
                law.disabled = selectAllRf.checked;          
            var ind = GetLawIndexOption();
            if (ind != null)
                ind.disabled = selectAllRf.checked;          
            var ext = GetExtOption();
            if (ext != null)
                ext.disabled = selectAllRf.checked;          
                    
            var hd = GetHdOption();
            if (hd != null)
                hd.disabled = selectAllRf.checked;          
            var ad = GetAdOption();
            if (ad != null)
                ad.disabled = selectAllRf.checked;          
            var md = GetMdOption();
            if (md != null)
                md.disabled = selectAllRf.checked;          
            var mg = GetMgOption();
            if (mg != null)
                mg.disabled = selectAllRf.checked;          
            var mo = GetMoOption();
            if (mo != null)
                mo.disabled = selectAllRf.checked;              
            var rh = GetRhOption();
            if (rh != null)
                rh.disabled = selectAllRf.checked;          
            var rr = GetRrOption();
            if (rr != null)
                rr.disabled = selectAllRf.checked;         
        }     
    }         
}

// Specific get searchoption metods
function GetSearchAllOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_all');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_all');    
    
    return opt;
}

function GetSearchAllRfOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_all_rf');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_all_rf');                                                        
    
    return opt;
}

function GetLawOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_law');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_law');    
    
    return opt;
}

function GetLawIndexOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_register');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_register');    
    
    return opt;
}

function GetPropOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_prop');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_prop');    
    
    return opt;
}

function GetExtOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_ext');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_ext');    
    
    return opt;
}

function GetHdOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_hd');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_hd');    
    
    return opt;
}

function GetAdOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_ad');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_ad');    
    
    return opt;
}

function GetMdOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_md');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_md');    
    
    return opt;
}

function GetMgOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_mg');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_mg');    
    
    return opt;
}

function GetMoOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_mo');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_mo');    
    
    return opt;
}

function GetRrOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_rr');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_rr');    
    
    return opt;
}

function GetRhOption()
{
    var opt = document.getElementById('_ctl0_ContentPlaceHolder_GenericLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_rh');
    
    if (opt == null)
        opt = document.getElementById('_ctl0_ContentPlaceHolder_WideLayout_GenericBodyLayout_DynamicContentControl__ctl0_SearchExtendedControl_rh');    
    
    return opt;
}

