// portal.js
function buildLinkThemesSelectBox(themeArray) {
var theme, themeValue, themeDescription;
var selectBox=document.webpageLinkAddPost.webpageThemeId;
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  for (theme=0; theme<themeArray.length; theme++) {
    themeValue=themeArray[theme].substring(0,11);
    themeDescription=themeArray[theme].substring(12);
    selectBox.options[theme]=new Option(themeDescription,themeValue);
  }
  selectBox.options[0].selected='selected';
  selectBox.options.length=themeArray.length;
}

function buildWebpageAddThemesSelectBox(themeArray) {
var theme, themeValue, themeDescription;
var selectBox=document.webpageAddPost.webpageThemeId;
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  for (theme=0; theme<themeArray.length; theme++) {
    themeValue=themeArray[theme].substring(0,11);
    themeDescription=themeArray[theme].substring(12);
    selectBox.options[theme]=new Option(themeDescription,themeValue);
  }
  selectBox.options[0].selected='selected';
  selectBox.options.length=themeArray.length;
}

function buildWebpageEditThemesSelectBox(themeArray) {
var theme, themeValue, themeDescription;
var selectBox=document.webpageEditPost.webpageThemeId;
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  for (theme=0; theme<themeArray.length; theme++) {
    themeValue=themeArray[theme].substring(0,11);
    themeDescription=themeArray[theme].substring(12);
    selectBox.options[theme]=new Option(themeDescription,themeValue);
  }
  selectBox.options[0].selected='selected';
  selectBox.options.length=themeArray.length;
}

function buildSelectedThemesSelectBox(themeArray) {
var theme, themeValue, themeDescription;
var selectBox=document.themeDisplayForm.themeIdSelected;
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  for (theme=0; theme<themeArray.length; theme++) {
    themeValue=themeArray[theme].substring(0,11);
    themeDescription=themeArray[theme].substring(12);
    selectBox.options[theme]=new Option(themeDescription,themeValue);
  }
  selectBox.options[0].selected='selected';
  selectBox.options.length=themeArray.length;
}

function getLinkThemes(theme) {
var themeArray=[];
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  xmlHTTP.open("GET", "/portal/getAllSubThemes.php?themeIdSelected="+theme);
  xmlHTTP.onreadystatechange=function() {
    if (xmlHTTP.readyState===4 && xmlHTTP.status===200) {
      themeArray=xmlHTTP.responseText.split("|");
      buildLinkThemesSelectBox(themeArray);
    }
  };
  xmlHTTP.send(null);
}

function getSelectedThemes(theme) {
var themeArray=[];
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  xmlHTTP.open("GET", "/portal/getSelectedSubThemes.php?themeIdSelected="+theme);
  xmlHTTP.onreadystatechange=function() {
    if (xmlHTTP.readyState===4 && xmlHTTP.status===200) {
      themeArray=xmlHTTP.responseText.split("|");
      buildSelectedThemesSelectBox(themeArray);
    }
  };
  xmlHTTP.send(null);
}

function getWebpageAddThemes(theme) {
var themeArray=[];
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  xmlHTTP.open("GET", "/portal/getAllSubThemes.php?themeIdSelected="+theme);
  xmlHTTP.onreadystatechange=function() {
    if (xmlHTTP.readyState===4 && xmlHTTP.status===200) {
      themeArray=xmlHTTP.responseText.split("|");
      buildWebpageAddThemesSelectBox(themeArray);
    }
  };
  xmlHTTP.send(null);
}

function getWebpageEditThemes(theme) {
var themeArray=[];
var supported=(document.getElementById || document.all || document.layers);
  if (!supported) { alert("Galleries onLine is not supported by your Internet Browser!"); }
  xmlHTTP.open("GET", "/portal/getAllSubThemes.php?themeIdSelected="+theme);
  xmlHTTP.onreadystatechange=function() {
    if (xmlHTTP.readyState===4 && xmlHTTP.status===200) {
      themeArray=xmlHTTP.responseText.split("|");
      buildWebpageEditThemesSelectBox(themeArray);
    }
  };
  xmlHTTP.send(null);
}

function webpageAddValidation() {
var element, errorMessage;
  if (document.webpageAddPost.webpageThemeId.value=='0') {
    createDiv('errorDiv','380px','150px','#c0c0c0','#e0e0e0','#006633');
    errorMessage="<br /><h4 style='margin-left: 1em; margin-right: 1em; text-align: center; color: #006633;'>Please select a Webpage Theme!<br /><br /><input type='button' value='OK' class='functionButton' onmouseover=\"this.className='functionButtonHover'\" onmouseout=\"this.className='functionButton'\" onclick=\"destroyDiv('errorDiv');\" /></h4>";
    element=document.getElementById('errorDiv');
    element.innerHTML=errorMessage;
    floatDiv('errorDiv');
    return;
  }else{
    createDiv('postDiv','380px','150px','#c0c0c0','#e0e0e0','#006633');
    floatDiv('postDiv');
    postForm('webpageAddPost', '/portal/webpageAdd.php', 'postDiv');
  }
}

function webpageEditValidation() {
var element, errorMessage;
//  if (document.webpageAddPost.webpageThemeId.value=='0') {
//    createDiv('errorDiv','380px','150px','#c0c0c0','#e0e0e0','#006633');
//    errorMessage="<br /><h4 style='margin-left: 1em; margin-right: 1em; text-align: center; color: #006633;'>Please select a Webpage Theme!<br /><br /><input type='button' value='OK' class='functionButton' onmouseover=\"this.className='functionButtonHover'\" onmouseout=\"this.className='functionButton'\" onclick=\"destroyDiv('errorDiv');\" /></h4>";
//    element=document.getElementById('errorDiv');
//    element.innerHTML=errorMessage;
//    floatDiv('errorDiv');
//    return;
//}
  createDiv('postDiv','380px','150px','#c0c0c0','#e0e0e0','#006633');
  floatDiv('postDiv');
  postForm('webpageEditPost', '/portal/webpageEdit.php', 'postDiv');
}

function webpageLinkAddValidation() {
var element, errorMessage;
  if (document.webpageLinkAddPost.webpageThemeId.value=='0') {
    createDiv('errorDiv','380px','150px','#c0c0c0','#e0e0e0','#006633');
    errorMessage="<br /><h4 style='margin-left: 1em; margin-right: 1em; text-align: center; color: #006633;'>Please select a Webpage Theme!<br /><br /><input type='button' value='OK' class='functionButton' onmouseover=\"this.className='functionButtonHover'\" onmouseout=\"this.className='functionButton'\" onclick=\"destroyDiv('errorDiv');\" /></h4>";
    element=document.getElementById('errorDiv');
    element.innerHTML=errorMessage;
    floatDiv('errorDiv');
    return;
  }else{
    createDiv('linkAddDiv','380px','150px','#c0c0c0','#e0e0e0','#006633');
    floatDiv('linkAddDiv');
    postForm('webpageLinkAddPost', '/portal/webpageLinkAdd.php', 'linkAddDiv');
  }
}

