/***************************************************************************
clientSetting
***************************************************************************/

/**********************************************************************
SetSettings
***********************************************************************/
function SetSettings(){
//Selected options in Select
var selectList = top.frameMenu.document.getElementsByTagName('select');
var str = '';
for (var i=0; i<selectList.length; i++)
  if (selectList[i].getAttribute('id'))
    str += selectList[i].getAttribute('id')+':'+selectList[i].options[selectList[i].selectedIndex].value+'__';
top.settingList['select'] = str;


//Menu-node (open or close)
str = '_';
for (var i=0; i<top.frameMenu.menuList.length; i++)
  if (top.frameMenu.menuList[i].open)
    str += '_' + top.frameMenu.menuList[i].id + '_';
top.settingList['openMenus'] = str;

//Menu-node (selected)
str = '';
for (var i=0; i<top.frameMenu.menuList.length; i++)
  if (top.frameMenu.menuList[i].selected)
    str += '_' + top.frameMenu.menuList[i].id + '_';
top.settingList['selMenus'] = str;

//Selected items forMainMapGroup
str = '';
for (var i=0; i<top.frameMenu.mainMapGroupList.length; i++){
  var nextMMG = top.frameMenu.mainMapGroupList[i];
  if (nextMMG.select && nextMMG.selectedId)
    str += nextMMG.id+':'+nextMMG.selectedId + '__';
}  
top.settingList['selMMG'] = str;


//State and contents of open windowboxes
str = '';
for (var i=0; i<top.frameWindowBox.winList.length; i++){
  var nextWin = top.frameWindowBox.winList[i];
  if (nextWin.isOpen)
    str += nextWin.CookieString() + '__';
}
top.settingList['openWin'] = str;

}

/*******************************************************
SaveSettingsInCookies
********************************************************/
function LoadSettingsInCookies(postfix){
postfix = postfix || '';
for (var i=0; i<top.settingIdList.length; i++){
  var id = top.settingIdList[i];
  top.settingList[id] = GetCookie(top.cookieNamePrefix + id + postfix);
}
}

/*******************************************************
SaveSettingsInCookies
********************************************************/
function SaveSettingsInCookies(postfix, showStatus){
postfix = postfix || '';
if (CookiesAllowed(showStatus)){
  //Save setting as cookie
  for (var i=0; i<top.settingIdList.length; i++){
    var id = top.settingIdList[i];
    SetCookie(top.cookieNamePrefix + id + postfix, top.settingList[id])
  }
  if (showStatus)
    alert(top.cookieSaveStr);
}
}

/*******************************************************
RemoveSettingsFromCookies
********************************************************/
function RemoveSettingsFromCookies(postfix){
postfix = postfix || '';
for (var i=0; i<top.settingIdList.length; i++)
  DeleteCookie(top.cookieNamePrefix + top.settingIdList[i] + postfix);
}

/*******************************************************
SettingsExistsInCookies
********************************************************/
function SettingsExistsInCookies(postfix){
return GetCookie(top.cookieNamePrefix + top.settingIdList[0] + (postfix || ''));
}

/*******************************************************
AddToBookmark
********************************************************/
function AddToBookmark(){
var areaSelect = GetMainMapGroup(mmgAreaId).select;
var areaName = areaSelect.options[areaSelect.selectedIndex].text;
var title = top.title + ' - ' + areaName; 

var url = top.location.href; 
if (url.indexOf('?') == -1)
  url += '?'
else
  url += '&';
SetSettings();
for (var i=0; i<top.settingIdList.length; i++){
  var id = top.settingIdList[i];
  url += (i?'&':'')+id+'='+top.settingList[id];
}

if (window.sidebar){  // Mozilla Firefox Bookmark
  window.sidebar.addPanel(title, url, "");
}
else 
  if (window.external)  // IE Favorite
    window.external.addFavorite(url, title)
  else 
    if (window.opera && window.print){  // Opera Hotlist
      var elem = document.createElement('a');
      elem.setAttribute('href',url);
      elem.setAttribute('title',title);
      elem.setAttribute('rel','sidebar');
      elem.click();
    }
}

/*******************************************************
ResetToDefault
********************************************************/
function ResetToDefault(){
var url = top.location.href.split('?')[0] + (top.mainUrl ? '?' + top.mainUrl : '');

RemoveSettingsFromCookies();

top.location.replace(url);

}

