var helpWindow = null;
var demoWindow = null;
var privacyWindow = null;

function submitForm(form, action) {
  //alert("form: " + form.name + ", new action: " + action_url + ", args: " + arguments.length);
  if (arguments.length == 2) {
    if (form.mode == null) {
      alert("You must create a hidden form element called 'mode' to use this function.");
    } else {
      form.mode.value = action;
    }
  }
  form.submit();
}

function getHelp(anchor) {
  // Open window.
  helpWindow = window.open('/common/help.html?helpid=' + anchor, 'helpWindow',
    			   'width=450,height=300,top=120,left=190,scrollbars=yes,resizable=yes');
  // Set focus for window.
  helpWindow.focus();
}



function showPrivacyStatement() {
  // Open window.
  privacyWindow = window.open('/privacy.html', 'privacyWindow',
    			   'width=450,height=300,top=120,left=190,scrollbars=yes,resizable=yes');
  // Set focus for window.
  privacyWindow.focus();
}

function showDemo(demoFile) {
  // Open window.
  demoWindow = window.open('/demo/' + demoFile, 'demoWindow',
    			   'width=900,height=650,top=10,left=50,scrollbars=yes,resizable=yes');
  // Set focus for window.
  demoWindow.focus();
}

function openPreviewWindow(mode, branding_id, parent_branding_id) {

    // Form not given so open popup manually.
    var qstring = "";
    qstring = qstring + "&branding_id=" + branding_id;
    qstring = qstring + "&mode=" + mode;

    if (parent_branding_id != null) {
      qstring = qstring + "&parent_branding_id=" + parent_branding_id;
    }

    var previewWindow;
    if (mode.indexOf('portal') > -1) {
      previewWindow = window.open('/tap?_page=tapbrandpreview&_focus=tapbrandpreview&_action=refresh' + qstring, 'previewWindow', 'height=600,width=800,scrollbars=yes,resizable=yes');
    } else if (mode.indexOf('cscp') > -1) {
      previewWindow = window.open('/tap?_page=cscppreview&_focus=cscpcontentpreview&_action=refresh' + qstring, 'previewWindow', 'height=600,width=800,scrollbars=yes,resizable=yes');
    } else if (mode.indexOf('signup') > -1) {
      previewWindow = window.open('/tap?_page=signuppreview&_focus=signupcontentpreview&_action=refresh' + qstring, 'previewWindow', 'height=600,width=800,scrollbars=yes,resizable=yes');
    } else {
      previewWindow = window.open('/tap?_page=loginbrandpreview&_focus=logincontentpreview&_action=refresh' + qstring, 'previewWindow', 'height=600,width=800,scrollbars=yes,resizable=yes');
    }
    previewWindow.focus();
}

function toggleCheckbox(formName, elemName) {
  var form = eval("document." + formName);
  if (form.elements[elemName] != null) {
    form.elements[elemName].checked = !form.elements[elemName].checked;
  }
}






