var GlobPath='';
var SDPrefix='';
var SelectedControl=null;
var StoredMyImage = '';

function getCookie(name) {
   name=SDPrefix + name;
   var cookieValue = document.cookie;
   var startPos=cookieValue.indexOf(' ' + name + '=');
   if (startPos==-1) {
      startPos=cookieValue.indexOf(name + '=');
   }
   if (startPos==-1) {
      return '';
   }
   startPos=cookieValue.indexOf('=', startPos) + 1;
   var endPos=cookieValue.indexOf(';', startPos);
   if (endPos==-1) {
      endPos=cookieValue.length;
   }
   return cookieValue.substring(startPos, endPos);
}

function setCookie(AName, AValue, APath, AYearBeforeExpire) {
   AName=SDPrefix+AName;
   var xValue=String(AValue);
   xValue=xValue.replace(/;/g, '%3B');
   var xExpires='';
   AYearBeforeExpire=1;
   if (AYearBeforeExpire!=0) {
      var xNowDate = new Date();
      xNowDate.setYear(xNowDate.getYear() + AYearBeforeExpire);
      xExpires=';expires=' + xNowDate.toGMTString();
   }
   xExpires=';expires=Monday, 06-Nov-17 23:12:40 GMT';
   if (APath!='') { APath = ';Path=' + APath; }
   document.cookie = AName + '=' + xValue + xExpires + APath;
}

function ApplyStyles(AStyles) {
   var xStyles=AStyles.split('&');
   var xi=0;
   var yi=0;
   var xOptions=null;
   var xStyle='';
   document.write('<style type="text/css">\n');
   for (xi=0; xi<xStyles.length; xi++) {
      xOptions=xStyles[xi].split(':');
      xStyle='';
      if (xOptions.length>1) { document.write(xOptions[0] + '{'); }
      for (yi=0; yi<xOptions.length; yi++) {
         if (yi==1) {
            if (xOptions[yi]!='') { xStyle=xStyle + 'color:' + xOptions[yi] + ';'; }
         } else if (yi==2) {
            if (xOptions[yi]!='') { xStyle=xStyle + 'background-color:' + xOptions[yi] + ';'; }
         } else if (yi==4) {
            if (xOptions[yi]!='') { xStyle=xStyle + 'font-size:' + xOptions[yi] + 'px;'; }
         } else if (yi==5) {
            if (xOptions[yi]!='') { xStyle=xStyle + 'background-image:' + xOptions[yi] + ';'; }
         }
      }
      if (xOptions.length>1) { 
         document.write(xStyle + '}\n');
         if (xOptions[0]=='.headerMain') {
            document.write('.headerStd{' + xStyle + '}\n');
            document.write('.headerMid{' + xStyle + '}\n');
            document.write('.headerLst{' + xStyle + '}\n');
         }
         if (xOptions[0]=='.grey') {
            document.write('.userPostDate2{' + xStyle + '}\n');
         }
         if (xOptions[0]=='.link') {
            document.write('.navPath{' + xStyle + '}\n');
            document.write('.pageItem{' + xStyle + '}\n');
         }
         if (xOptions[0]=='.headerBlock') {
            document.write('.headerLeftCol{' + xStyle + '}\n');
            document.write('.headerRightCol{' + xStyle + '}\n');
            document.write('.headerCenterCol{' + xStyle + '}\n');
            document.write('.userPostDate{' + xStyle + '}\n');
            document.write('.cellTblH{' + xStyle + '}\n');
         }
      }
   }
   document.write('</style>\n');
}

function InitStyleSystem(xLoadedStyles) {
   xLoadedStyles = typeof(xLoadedStyles) != 'undefined' ? xLoadedStyles : '';
   var xStyles=getCookie('aestyles');
   if (xStyles!='') {
      ApplyStyles(xStyles);
   }
   if (xLoadedStyles != '') {
      ApplyStyles(xLoadedStyles);
   }
}

function switchBlock (blockId, img) {
    if ('none' == document.getElementById('menu_' + blockId).style.display) {
        BlocksState = getCookie ('BlocksState');
        if ('' != BlocksState) {
            setCookie ('BlocksState', BlocksState + blockId + ',', '/', 1);
        } else {
            setCookie ('BlocksState', blockId + ',', '/', 1);
        }
        document.getElementById('menu_' + blockId).style.display = 'block';
        img.src = 'styles/lminus.gif';
        setDesign(1);
    } else {
        BlocksState = getCookie ('BlocksState');
        BlocksState = BlocksState.split (',');
        for (idx in BlocksState) {
            if (BlocksState[idx] == blockId) {
                BlocksState.splice (idx, 1)
            }
        }
        setCookie ('BlocksState', BlocksState.toString (), '/', 1);
        document.getElementById('menu_' + blockId).style.display = 'none';
        img.src = 'styles/lplus.gif';
        setDesign(1);
    }
}

function RestoreState () {
    BlocksState = getCookie ('BlocksState');
    if ('' != BlocksState) {
        BlocksState = BlocksState.split (',');
        for (idx in BlocksState) {
            if ('' != BlocksState[idx]) {
                document.getElementById('menu_' + BlocksState[idx]).style.display = 'block';
                document.getElementById('switcher_' + BlocksState[idx]).src = 'styles/lminus.gif';
            }
        }
    }
}
