/* General Javascript include */

function navigate() { var menuIndex = document.formMenu.selectMenu.selectedIndex;
    location = document.formMenu.selectMenu.options[menuIndex].value;
}
function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}

// Show, Hide Layer
function toggleDisplay(id) {
       e = document.getElementById(id);
       if (e.style.display=="block") {
         e.style.display="none";
       } else {
         e.style.display="block";
       }
}

function resetQL(ids) {
    var items = ids.split(":");
    for(var i=0;i<items.length;i++){
        document.getElementById(items[i]+'2').style.display="none";
        document.getElementById(items[i]+'1').style.display="block";
    }
}

function printpage(strFilename) {
  printWindow = window.open(strFilename + "?print=1", "printWindow", "location=no,width=630,height=600,history=0"); 
  if (printWindow) {
    if (printWindow.print) printWindow.print();
    setTimeout("printWindow.close()",3000);
  }
}

/* Internal functions for Recommend Filename page - Not visible outside RedDot CMS */
var recommendedFilename = '';
function recommendFilename(strHeadline) {
    var rfwin = window.open("","rfwin","width=580,height=240,left="+ (screen.width-580)/2 +",top="+ (screen.height-240)/2 +",scrollbars=1,resizable=1,toolbar=0");
    var strRecommend = transformFilename(strHeadline);
    var html = '<ht'+'ml><he'+'ad><ti'+'tle>Recommend filename</ti'+'tle><LIN'+'K REL="Stylesheet" TYPE="text/css" HREF="stylesheets/ioStyleSheet.css"></he'+'ad><bo'+'dy class="bodyBGColorIoDialog" background="Icons/back5.gif" onload="document.forms[0].fn.focus();"><b>The recommended filename for page<br /><br />&quot;' + strHeadline + '&quot; :</b>';
    html += '<fo'+'rm><input type=text id="fn" name="fn" value="'+ strRecommend +'" size=70 readonly> <b>.html</b><br /><br /><b>This is only a suggestion!<br />You can adjust the filename on the next page.<br /><br /><br /><br />';
    html += '<table style="cursor:pointer;"><tr><td class="CommandButton" onclick="top.opener.recommendedFilename=document.forms[0].fn.value;if(top.opener && !top.opener.closed){top.opener.top.ioTop.document.getElementById(\'RDProperties\').click();top.opener.initiateFilenamePaste();}top.close();" onmouseover="this.style.borderColor=\'#000000\'" onmouseout="this.style.borderColor=\'#afafaf\'" nowrap><img class="CommandButtonIcon" src="Icons/CommandButtons/Ok.gif">&nbsp;Continue</td><td class="CommandButton" onclick="top.close()" onmouseover="this.style.borderColor=\'#000000\'" onmouseout="this.style.borderColor=\'#afafaf\'" nowrap><img class="CommandButtonIcon" src="Icons/CommandButtons/cancel.gif">&nbsp;Cancel</td></tr></table></fo'+'rm></bo'+'dy></ht'+'ml>';
    rfwin.document.open();
    rfwin.document.write(html);
    rfwin.document.close();
}
function transformFilename(strPagename) {
    var myFileName = strPagename.toLowerCase();
    var myExp1 = /\s/g;
    var myExpA = /[åäáàãâ]/g;
    var myExpO = /[öóòõô]/g;
    var myExpE = /[éêèë]/g;
    var myExpI = /[íìîï]/g;
    var myExpAnd = /\&/g;
    var myExpDot = /\./g;
    var myExpBind = /---/g;
    var myExpQM = /\?/g;
    myFileName = myFileName.replace(myExp1,"-");
    myFileName = myFileName.replace(myExpA,"a");
    myFileName = myFileName.replace(myExpO,"o");
    myFileName = myFileName.replace(myExpE,"e");
    myFileName = myFileName.replace(myExpI,"i");
    myFileName = myFileName.replace(myExpAnd,"och");
    myFileName = myFileName.replace(myExpDot,"");
    myFileName = myFileName.replace(myExpBind,"-");
    myFileName = myFileName.replace(myExpQM,"");
    return myFileName;
}
function initiateFilenamePaste() {
    setTimeout("doFilenamePaste()",500);
}
function doFilenamePaste() {
    var boolFilenamePasteDone = false;
    if (top.ioTop.objDialogWindow) oWinConnector = top.ioTop.objDialogWindow;
    if (oWinConnector) {
        if (oWinConnector.ioDialog) {
            if (oWinConnector.ioDialog.document.forms[0]) {
                if (oWinConnector.ioDialog.document.forms[0].PageName) {
                    boolFilenamePasteDone = true;
                    if (oWinConnector.ioDialog.document.forms[0].PageName.value.length == 0) {
                        oWinConnector.ioDialog.document.forms[0].PageName.value = recommendedFilename;
                        oWinConnector.ioDialog.document.forms[0].PageName.select();
                    }
                    else {
                        if (oWinConnector.confirm("A filename is already set for this page.\n\nDo you want to replace it with the recommended filename?")) {
                            oWinConnector.ioDialog.document.forms[0].PageName.value = recommendedFilename;
                            oWinConnector.ioDialog.document.forms[0].PageName.select();
                        }
                    }
                }
            }
        }
    }
    if (boolFilenamePasteDone != true) {
        initiateFilenamePaste();
    }
}

/* Text Size Script */

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

/*
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 expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
function Subscribe()
            {
                document.forms['frmPren'].elements['wpySubscribeAction'].value='begin';
                document.frmPren.submit();
            }
            function Unsubscribe()
            {
                document.forms['frmPren'].elements['wpySubscribeAction'].value='end';
                document.frmPren.submit();
            }
*/
function Subscribe()
            {
                document.forms['frmPren'].elements['wpySubscribeAction'].value='begin';
                document.frmPren.submit();
            }
            function Unsubscribe()
            {
                document.forms['frmPren'].elements['wpySubscribeAction'].value='end';
                document.frmPren.submit();
            }
 function submitform()
{
  document.myform.submit();
}