﻿var opera = (navigator.appName.indexOf("Opera") != -1) ? true : false;
var firefox = navigator.userAgent.toLowerCase();
    firefox = (firefox.indexOf("firefox") != -1) ? true : false;
var safari = navigator.userAgent.toLowerCase();
    safari = ((safari.indexOf("safari") != -1) && (safari.indexOf("chrome") == -1)) ? true : false;
var chrome = navigator.userAgent.toLowerCase();
    chrome = (chrome.indexOf('chrome') != -1) ? true : false;
var msie_only = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
var msie_old = false; // MSIE versions older than 7
var msie_80 = false; // only MSIE 8.0 or newer
var msie_70 = false; // only MSIE 7.0
var msie_60 = false; // only MSIE 6.0

if (msie_only) {
  fullVerStr = navigator.appVersion;
  verStr = fullVerStr.substring(fullVerStr.indexOf('MSIE') + 4, fullVerStr.length);
  verStr = verStr.substring(0, verStr.indexOf(';'));
  msie_old = (parseFloat(verStr) < 7.0) ? true : false;
  msie_80 = (parseFloat(verStr) >= 8.0) ? true : false;
  msie_70 = (parseFloat(verStr) == 7.0) ? true : false;
  msie_60 = (parseFloat(verStr) == 6.0) ? true : false;
}

document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
if (msie_80) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbVerticalList {}\n');
  document.writeln('.RbVerticalList input {position:relative; margin-bottom:6px; top:4px}\n');
  document.writeln('.RbVerticalList label {top:1px;}\n');
  document.writeln('.CbVerticalList {left:-6px; top:-2px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:3px}\n');
  document.writeln('.LeftPanelDropDown {width:135px;}\n');
}
if (msie_70) {
  document.writeln('.Radio {left:-4px;}\n');
  document.writeln('.Radio input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CheckBox {left:-4px;}\n');
  document.writeln('.CheckBox input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList input {position:relative; top:2px}\n');
  document.writeln('.RbVerticalList label {top:1px;}\n');
  document.writeln('.CbVerticalList {left:-6px; top:-2px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:3px}\n');
  document.writeln('.LeftPanelDropDown {width:135px;}\n');  
  document.writeln('.AdminStdList hr {margin-top:0px; margin-bottom:0px;}\n');
  document.writeln('.FormTable .CheckBox {top:-2px;}\n');
  document.writeln('#CatSelection {margin-top:3px;}\n');
  document.writeln('#CatSelection input {margin-right:0px; top:2px;}\n');
  document.writeln('#CatSelection img.ListIconMinus, #CatSelection img.ListIconPlus, #CatSelection img.ListIconPlaceHolder {top:1px; margin-left:5px;}\n');
  document.writeln('.FormTable table .DropDown {width:205px;}\n');
}
if (msie_old) {
  document.writeln('.Radio {left:-4px;}\n');
  document.writeln('.Radio input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CheckBox {left:-4px;}\n');
  document.writeln('.CheckBox input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CbVerticalList {left:-6px; top:-2px;}\n');
  document.writeln('.RbHorizontalList input {left:-7px; top:3px}\n');
  document.writeln('.RbHorizontalList label {left:-7px;}\n');
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList label {top:-1px;}\n');
  document.writeln('.RbVerticalList input {}\n');
  document.writeln('.LeftPanelDropDown {width:136px;}\n');
  document.writeln('#pageContent {height:650px;}\n');
  document.writeln('.AdminStdList hr {margin-top:0px; margin-bottom:0px;}\n');
  document.writeln('.FormTable .CheckBox {top:-2px;}\n');
  document.writeln('#CatSelection {margin-top:3px;}\n');
  document.writeln('#CatSelection input {margin-right:0px; top:2px;}\n');
  document.writeln('#CatSelection img.ListIconMinus, #CatSelection img.ListIconPlus, #CatSelection img.ListIconPlaceHolder {top:1px; margin-left:5px;}\n');
}
if (msie_only) {
  document.writeln('.CategoryNavTreeView img {top:-2px;}\n');
}
if (opera) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {top:0px;}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbHorizontalList input {}\n');
  document.writeln('.RbHorizontalList label {top:0px;}\n');
  document.writeln('.RbVerticalList {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:2px;}\n');
  document.writeln('.CbVerticalList {left:-1px;}\n');
  document.writeln('.CbVerticalList input {margin-top:2px; margin-bottom:3px;}\n');
  document.writeln('.LeftPanelDropDown {width:135px;}\n');
  document.writeln('#CatSelection input {top:0px;}\n');
  document.writeln('#CatSelection img.ListIconMinus, #CatSelection img.ListIconPlus, #CatSelection img.ListIconPlaceHolder {top:2px;}\n');
}
if (firefox) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbHorizontalList label {top:-3px;}\n');
  document.writeln('.RbVerticalList {left:-1px;}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {position:relative; top:-3px; margin-left:6px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-3px; margin-left:6px;}\n');
  document.writeln('.FileUpload {height:auto !important;}\n');
}
if (safari) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {top:-3px; margin-left:7px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {margin-left:7px;}\n');
}
if (chrome) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {top:-2px; margin-left:5px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-2px; margin-left:7px;}\n');
  document.writeln('.FormTable table .TextArea {width:196px;}\n');
}
document.writeln('.ValidationComplianceTag {display:none;}\n');
document.writeln('/*]]>*/\n</style>\n');

//Limits length of text in textarea "element" (dom reference), writes information in "info" (id), counts characters
function checkLength(element, info, max_length) {
  var actual_length = element.value.length;
  var characters_left = max_length - actual_length;
  if (characters_left < 0) characters_left = 0;

  if (actual_length == 0) {
    document.getElementById(info).innerHTML = "Maximum text length is " + max_length + " characters.";
  }
  if ((actual_length > 0) && (actual_length <= max_length)) {
    document.getElementById(info).innerHTML = "You may enter " + characters_left + " more characters.";
  }
  if (actual_length > max_length) {
    element.value = element.value.substr(0, max_length);
    document.getElementById(info).innerHTML = "You may enter " + characters_left + " more characters.";
  }
}

//init a textarea, textarea_container - id, for charaacters limit
function initLengthInfo(textarea_container, info_id, max_length) {
  if (document.getElementById(textarea_container)) {
    element_ref = document.getElementById(textarea_container).getElementsByTagName("textarea")[0];
    checkLength(element_ref, info_id, max_length);
  }
}

//trims only spaces from the end of a string
function trim(text) {
  while (text.charAt(text.length - 1) == " ") {
    text = text.substr(0, (text.length - 1));
  }
  return (text);
}

//Returns value stored in cookie with given id, or -1 if cookie didn't exist (or is expired), multi value cookies safe.
function toCookie(cookie_id, value) {
  var exp = new Date();
  exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 365));
  var cookie_name = "WeddingPlanner" + cookie_id + "=" + value;
  var cookie_expires = "expires=" + exp.toGMTString();
  document.cookie = cookie_name + ";" + cookie_expires + "; path=/";
}

//Returns value stored in cookie with given id, or -1 if cookie didn't exist (or is expired), multi value cookies resistant.
function fromCookie(cookie_id) {
  var labelName = "WeddingPlanner" + cookie_id;
  var labelLen = labelName.length;
  var cookieData = document.cookie;
  var cLen = cookieData.length;
  var i = 0;
  var cEnd;
  while (i < cLen) {
    var j = i + labelLen;
    if (cookieData.substring(i, j) == labelName) {
      cEnd = cookieData.indexOf(";", j);
      if (cEnd == -1) {
        cEnd = cookieData.length;
      }
      return unescape(cookieData.substring(j + 1, cEnd));
    }
    i++;
  }
  return "-1";
}

function getYear() {
  var d = new Date();
  document.getElementById('GetYear').innerHTML = d.getFullYear();
}

// hide 0 or one element and show another element, indicated by id
// css width property is required for every switchable element. Can be in pixels or percents
function hideShow(id_hide, id_show, type) {
  switch (type) {
    case 'fade':
      if (id_hide == "-") {//only show, but wait to synchronize with other elements
        window.setTimeout("$('#" + id_show + "').fadeIn(400);",450);
      } else {
        $('#' + id_hide).fadeOut(200, function(){
          $('#' + id_show).fadeIn(400);
        });
      }
    break;
    case 'slide':
      if (id_hide == "-") {
        window.setTimeout("$('#" + id_show + "').slideDown(400);",450);
      } else {
        $('#' + id_hide).slideUp(200, function(){
          $('#' + id_show).slideDown(400);
        });
      }
    break;
    case 'blink':
      $('#' + id_hide).hide();
      $('#' + id_show).show();
    break;
  }
}

//show single element with given id
function show(id_show, type) {
  switch (type) {
    case 'fade':
      $('#' + id_show).fadeIn(400);
    break;
    case 'slide':
      $('#' + id_show).slideDown(400);
    break;
    case 'blink':
      $('#' + id_show).show();
    break;
  }
}

//hide single element with given id
function hide(id_hide, type) {
  switch (type) {
    case 'fade':
      $('#' + id_hide).fadeOut(200);
    break;
    case 'slide':
      $('#' + id_hide).slideUp(200);
    break;
    case 'blink':
      $('#' + id_hide).hide();
    break;
  }
}

// hide 0 or more elements and show 0 or more oter elements, indicated by id
// css width property is required for every switchable element. Can be in pixels or percents
// use example1: hideShowList(["id1","id2","id3"],["id6"],"blink");
// use example2: hideShowList(["-"],["id6","id7","id8"],"fade");
function hideShowList(hide_array, show_array, type) {
  if (hide_array[0] != '-') {
    for(var i=0; i<hide_array.length; i++) {
      hide(hide_array[i], type);
    }
  }
  
  if (show_array[0] != '-') {
    for(var i=0; i<show_array.length; i++) {
      show(show_array[i], type);
    }
  }
}

function assignSelectAll() {
  $('.CbVerticalList input').attr('checked', 'checked')
}
function assignDeselectAll() {
  $('.CbVerticalList input').removeAttr('checked')
}

//information box on validation image rollover - old validation mechanism
function validationInfo(operation, img_ref){
  if(operation == "show") {
    if (img_ref.alt.length > 0) img_ref.previousSibling.innerHTML = img_ref.alt;
    img_ref.alt = "";
    img_ref.previousSibling.style.display = "block";
  }
  if(operation == "hide") img_ref.previousSibling.style.display = "none";
}


//initial example value in a form field; disappears on focus, appears back on blur if is empty
function clearField (field_to_clear, initial_value) {
  if (initial_value==field_to_clear.value) field_to_clear.value="";
} 
function fillField (field_to_clear, initial_value) {
  if (field_to_clear.value=="") field_to_clear.value=initial_value;
}

/********* ADD MORE FORM FIELDS functions *********/
//show empty, hide not empty form fields (set of fields); needed on page load
function initFormSectionsVisibility(sh_box_class) {
  $("div." + sh_box_class).each(function() {
    if (isFormSectionEmpty(this)) {
      $(this).css('display','none');
    } else {
      $(this).css('display','block');
    };
  });
}

/* check if a set of fields in parent_ref is empty; needed on page load */
/* this function is specific to the actual form fields, more test may need to be added for different forms */
function isFormSectionEmpty(parent_ref) {  //extend the tests
  var all_inputs_in_the_section = parent_ref.getElementsByTagName('input');
  var all_selects_in_the_section = parent_ref.getElementsByTagName('select');
  //var all_textareas_in_the_section = parent_ref.getElementsByTagName('textarea');
  for (var i=0; i < all_inputs_in_the_section.length; i++) {
    if ((all_inputs_in_the_section[i].value != "") && ((all_inputs_in_the_section[i].value != "dd/mm/yyyy"))) return false; 
  }
  for (var i=0; i < all_selects_in_the_section.length; i++) {
    if (all_selects_in_the_section[i].selectedIndex != "0") return false; 
  }    
  return true;
}

//open first hidden (empty) panel
function addMoreAddresses(button_class, related_sh_box_class) {
  $("div." + related_sh_box_class + ":hidden").eq(0).slideDown(300);
  updateButtonVisibility(button_class ,related_sh_box_class);
  return false;
}

/* decide whether to hide or show the "add more" button */
function updateButtonVisibility(button_class, related_sh_box_class) {
  if ($("div." + related_sh_box_class + ":hidden").length == 0) {
    $("div." + button_class + " span").css('display','none')
  } else {
    $("div." + button_class + " span").css('display','inline')
  }
}
/******* end ADD MORE functions ********/


/********* SELECT WITH FILTER functions *********/
//function invoked onload at body tag; or just before closiong body tag
function initArrays() {
  select_objects = document.getElementsByTagName('select'); //must be global
  all_selects = new Array();  //must be global, 3 dimensional array [ids of all selects][counter of each option in given select]['value' or 'text']= value or text of given option in given select
  options_selected = new Array(); //must be global, 2 dimensional array [ids of selects on which onchange or onkeydown function was invoked][values of selected options for associative addressing]=true ,but this boolean value is not used, existence of array entry is tested.
   
  for(var i=0; i<select_objects.length; i++) {
    var index = select_objects[i].id;  // id of select tag
    all_selects[index]= new Array();
    options_selected[index]= new Array();
    for (var j=0; j<select_objects[i].length; j++) {  //number of options elements in given select tag
      all_selects[index][j]= new Array();
      all_selects[index][j]['value'] = select_objects[i].options[j].value;
      all_selects[index][j]['text']  = select_objects[i].options[j].text;
    }//for j
  }//for i
}

//function invoked onkeyup of input tag containing search phrase
function filterFunction(container_id, filter) {
  //container_id - id of a div containing related ddl
  //filter - reference to input tag containing filter phrase or "" for bringing back all options into select
  //sel - reference to related dropdownlist (select)
  var container_ref = document.getElementById(container_id);
  var sel = container_ref.getElementsByTagName("select")[0];
  if (sel) { 
      var select_id = sel.id;
  } else {
      return; //if sendForm gives unpredictable id of other listboxes that don't use filter
  }

  if (options_selected[select_id].length == 0) 
     selectFunction(document.getElementById(select_id)); //remember already selected options, not only these selected manualy
  sel.options.length=0; 
  var k=0;
  for (var i=0; i<all_selects[select_id].length; i++) {
    var t = all_selects[select_id][i]['text'];
    var t_for_search = t.toLowerCase();
    var v = all_selects[select_id][i]['value'];
    var filter_text = (typeof filter == "object") ? filter.value.toLowerCase() : '';
    if (t_for_search.indexOf(filter_text) >= 0)  // == to search from the begining of the listbox item
       sel.options[k++] = new Option(t, v, false, (typeof options_selected[select_id][v] != "undefined"));
  }
}

//function invoked onchange at select tag, to remember the selected items
//At the moment cannot be used on autopsstback list, but maybe isn's important there, and can be omitted
function selectFunction(this_select) {
  var number_of_options = this_select.options.length;  //in given select
  for (var i=0; i<number_of_options; i++) {
    if (this_select.options[i].selected == true) {
      options_selected[this_select.id][this_select.options[i].value]=true;
    } else {
      if (typeof options_selected[this_select.id][this_select.options[i].value] != "undefined") 
          delete options_selected[this_select.id][this_select.options[i].value];
    }
  }   
}
/******* end SELECT WITH FILTER functions ********/


/* Function creates 2 row table from simplier repeater based table. Table should be hidden initially */
function makeTwoColumns(table_id) {
  var table_ref = document.getElementById(table_id);
  
  for (var i=1; i<table_ref.getElementsByTagName("tr").length; i++) { // 1 starts from second row
    table_ref.getElementsByTagName("tr")[i-1].getElementsByTagName("td")[1].innerHTML = table_ref.getElementsByTagName("tr")[i].getElementsByTagName("td")[0].innerHTML;
  }
  
  $(table_ref).find("tr:odd").remove();
  
  table_ref.style.display = "";
}


function swapLargeImage(img_index) {
  if (img_index != 0) $('#ProductLargeImages img.LargeProductImage').eq(0).stop(true, true).fadeOut(250);
  if (img_index != 1) $('#ProductLargeImages img.LargeProductImage').eq(1).stop(true, true).fadeOut(250);
  if (img_index != 2) $('#ProductLargeImages img.LargeProductImage').eq(2).stop(true, true).fadeOut(250);
  $('#ProductLargeImages img').eq(img_index).fadeIn(250);
}

/* a standard popup window */
function openPopup(url) {
  var win_handle = window.open(url, 'PopUpWindow', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=640,top=100,left=150');
  win_handle.focus();
}

//Category selection functionality
function initCategoryTree(max_to_check, version) {

 /*
  function createBreadCrumbsProduct() {
  var full_breadcrumb = "";
    var line_breadcrumb = "";
    var line_additions = new Array("1. ","2. ","3. ","4. ","5. ","6. ","7. ");
    
    $('#CatSelection input:checked').each(function(each_index) {
      $(this).parents("li").each(function(){    //<- slice to index of #CatSelection required if the list is inside some other list - unlikely
        line_breadcrumb = " &raquo; " + $(this).children("span").html() + line_breadcrumb;
      })
      full_breadcrumb += "<div>" + line_additions[each_index] + line_breadcrumb.substring(9, line_breadcrumb.length) + "</div>";
      line_breadcrumb = "";
    });
    for(var i = $('#CatSelection input:checked').length; i < max_to_check; i++) {
      full_breadcrumb += "<div>" + line_additions[i] + "- </div>";
    }
    $("#BreadCrumbs").html(full_breadcrumb);
  }
  
  function createBreadCrumbsCategory() {
    var full_breadcrumb = "";
    var line_breadcrumb = "";
    
    if ($('#CatSelection input:checked').length > 0) {
      $('#CatSelection input:checked').each(function(each_index) {
        $(this).parents("li").each(function(){    //<- slice to index of #CatSelection required if the list is inside some other list - unlikely
          line_breadcrumb = " &raquo; " + $(this).children("span").html() + line_breadcrumb;
        })
        full_breadcrumb += "<div>" + line_breadcrumb.substring(9, line_breadcrumb.length) + "</div>";
        line_breadcrumb = "";
      });
    } else {
      full_breadcrumb = "<div>Nothing selected</div>";
    }
    $("#BreadCrumbs").html(full_breadcrumb);
  }

  //Init the category breadcrumb trails    
  if (version == "category") createBreadCrumbsCategory();
  if (version == "product") createBreadCrumbsProduct();
  
  //open categories with checkboxes checked
  $('#CatSelection input:checked').each( function() {
    $(this).parents("ul").show(0);
  })
  
  //add "+", "-" icons 
  $('#CatSelection li').each( function() {
    if ($(this).find('ul').length > 0) //if there are subcategories
      if ($(this).find("ul").is(":visible")) { //and subcategory is open
        $(this).prepend("<img src='/images/list-icon-minus.gif' class='ListIconMinus' />");
      } else {
        $(this).prepend("<img src='/images/list-icon-plus.gif' class='ListIconPlus' />");
      }
    if ((version == "category") && ($(this).find('ul').length == 0)) //used when all the categories had a checkbox
      $(this).prepend("<img src='/images/spacer.gif' class='ListIconPlaceHolder' />");
  })
  
  //bind "+", "-" dynamic functionality
  $('#CatSelection img.ListIconMinus, #CatSelection img.ListIconPlus').each( function() { 
    $(this).bind('click', function(){
      if ($(this).nextAll("ul").is(":visible")) {
        $(this).nextAll("ul").slideUp(250);
        $(this).attr('src','/images/list-icon-plus.gif');
        $(this).attr('class','ListIconPlus');
      } else {
        $(this).nextAll("ul").slideDown(250);
        $(this).attr('src','/images/list-icon-minus.gif');
        $(this).attr('class','ListIconMinus');
      }
    })
  })
  */
  
  //bind checkbox dynamic functionality: validation for maximum number of categories selected and update the breadcrumb trails
  $('#CatSelection input').each( function() { 
    $(this).bind('click', function(event){
      if ($("#CatSelection input:checked").length > max_to_check) {
        $(this).removeAttr('checked');
        (max_to_check == 1) ? alert("You can select only one category.") : alert("You can select maximum of " + max_to_check + " categories.");
       }
      // if (version == "category") createBreadCrumbsCategory();
      // if (version == "product") createBreadCrumbsProduct();
    })
  })
}

/* category lists in popup boxes on the product list pages */
function ShowBreadcrumbPopup(link_ref) {
  $(link_ref).prev("div").stop(true,false).animate({height: "70"}, 250);
}

function HideBreadcrumbPopup(link_ref) {
  $(link_ref).prev("div").stop(true,false).animate({height: "0"}, 250, function(){
    $(this).css("display","none");
  });
}



function htmlEncode(s) {
  var str = new String(s);
  str = str.replace(/&/g, "&amp;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/"/g, "&quot;");
  return str;
}

function openWysiwyg(html_source_id, html_destination_id, editor_width, editor_height, popup_left, popup_top, style_filename, content_type) {
  //content_type = "email" for emails and "page" for page contents editing
  editor_width = parseInt(editor_width) + 18; //18px for editor scrollbars
  var popup_width = parseInt(editor_width) + 20;
  var popup_height = parseInt(editor_height) + 50;

  var ports;
  if (window.location.port == '') {
    ports = '';
  } else {
    ports = ':' + window.location.port;
  }
  var dynamic_url = window.location.protocol + "//" + document.domain + ports;
  var email_prefix = (content_type == "email") ? "email-" : "";

  var ww = window.open("", "EditorWindow", "resizable=no,width=" + popup_width + ",height= " + popup_height + ",top=" + popup_top + ",left= " + popup_left);

  ww.document.open();
  ww.document.writeln;
  ww.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n<title>WYSIWYG content editor</title>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n</head>\n<body>');
  ww.document.writeln('<div style="position:relative; left:15px; top:15px; font:normal 12px Arial; width:450px"><p>Please download and install the content editor using the following link to be able to add content (You only need to do this once)</p><p><a href="/xstandard/x-pro-win.exe">PC version</a>&nbsp;-&nbsp;<a href="/xstandard/x-pro-mac.dmg">Mac version</a></div>');
  ww.document.writeln('<div style="margin:auto; width:' + editor_width + 'px">');
  ww.document.writeln('<object style="margin-top:-70px" type="application/x-xstandard" id="editor1" width="' + editor_width + '" height="' + editor_height + '">');
  ww.document.writeln('<param name="Value" value="' + htmlEncode(document.getElementById(html_source_id).value) + '" />');

  ww.document.writeln('<param name="ImageLibraryURL" value="' + dynamic_url + '/xstandard/' + email_prefix + 'imagelibrary.aspx" />');
  ww.document.writeln('<param name="AttachmentLibraryURL" value="' + dynamic_url + '/xstandard/' + email_prefix + 'attachmentlibrary.aspx" />');
  ww.document.writeln('<param name="LinkLibraryURL" value="' + dynamic_url + '/xstandard/linklibrary.aspx" />');
  //ww.document.writeln('<param name="SpellCheckerURL" value="' + dynamic_url + '/xstandard/spellchecker.aspx" />'); //http://soap.xstandard.com/spellchecker.aspx for test
  ww.document.writeln('<param name="Styles" value="' + dynamic_url + '/xstandard/' + email_prefix + 'editor-styles.xml" />');
  ww.document.writeln('<param name="License" value="' + dynamic_url + '/xstandard/license.txt" />');
  ww.document.writeln('<param name="CSS" value="' + dynamic_url + '/xstandard/' + email_prefix + style_filename + '" />');
  ww.document.writeln('<param name="BackgroundColor" value="#f5f5f2" />');
  ww.document.writeln('<param name="BorderColor" value="#b48742" />');

  //ww.document.writeln('<param name="SpellCheckerLangFilter" value="en-gb, en-us" />');
  ww.document.writeln('<param name="SpellCheckerLang" value="en-us" />');
  ww.document.writeln('<param name="ProxySetting" value="direct" />'); //if default proxy settings stop it from working
  ww.document.writeln('<param name="EnableTimestamp" value="no" />'); //the comment inserted at the begining of html
  ww.document.writeln('<param name="EnablePasteMarkup" value="no" />'); //copying from word with formating retained - doesn't work good enough
  ww.document.writeln('<param name="Lang" value="en" />');
  ww.document.writeln('<param name="Dir" value="ltr" />');
  ww.document.writeln('<param name="IndentOutput" value="Yes" />');
  ww.document.writeln('<param name="Options" value="2136" />');  //hide line numbers, make images decorative by default, make divs don't disappear durind edition.
  ww.document.writeln('<param name="ClassImageFloatLeft"  value="LeftImage" />');
  ww.document.writeln('<param name="ClassImageFloatRight" value="RightImage" />');
  ww.document.writeln('<param name="ToolbarWysiwyg" value="strong, em, underline, strikethrough, align-left, align-center, align-right, ordered-list, unordered-list, definition-list, draw-layout-table, draw-data-table, separator, image, hyperlink, attachment, source, preview, screen-reader" />'); // spellchecker,
  ww.document.writeln('<param name="ToolbarPreview" value="wysiwyg, source, preview, screen-reader" />');
  ww.document.writeln('<param name="ToolbarSource" value="indent, whitespace, word-wrap, validate,, wysiwyg, source, preview, screen-reader" />');

  ww.document.writeln('<param name="Base" value="' + dynamic_url + '/cmsimages/" />'); //URL used to resolve relative URLs for images defined in markup.
  ww.document.writeln('</object>');

  ww.document.writeln('<div>\n<span style="float:right; height:16px; display:block; margin-top:10px; background-color:#b48742;"><a style="font-weight:bold; font-size:10px; font-family:Verdana; text-decoration:none; color:#fff; padding:1px 8px 2px 8px; display:block;" href="javascript:self.opener.document.getElementById(\'' + html_destination_id + '\').value=document.getElementById(\'editor1\').value; self.close();" title="Update the page form and close the editor">Close</a></span>\n</div>');
  ww.document.writeln('</body>\n</html>');
  ww.document.close();
}

function showYear() {
  var now = new Date();
  document.writeln(now.getFullYear());
}

/* Hide/show part of a form start */
//show correct panel initially based on the radio button state, assign the on change functions  
function initHSPanels(radio_container, panel_list) {
  var radio_list_ref = document.getElementById(radio_container).getElementsByTagName("input");
  
  for (var i=0; i<panel_list.length; i++) {
    if (radio_list_ref[i].checked == true) { document.getElementById(panel_list[i]).style.display = "block" }           
  }
  
  //these lines can be automated
  radio_list_ref[0].onclick  = function () {updatePanels('CardPanel', ['CardPanel','PayPalPanel'])};
  radio_list_ref[0].onchcnge = function () {updatePanels('CardPanel', ['CardPanel','PayPalPanel'])};
  radio_list_ref[1].onclick  = function () {updatePanels('PayPalPanel', ['CardPanel','PayPalPanel'])};
  radio_list_ref[1].onchange = function () {updatePanels('PayPalPanel', ['CardPanel','PayPalPanel'])};
}

// hide all but the one do display, show the one to display
function updatePanels(panel_to_show, panel_list) {
  for (var i=0; i<panel_list.length; i++) {
    if (panel_list[i] != panel_to_show) $('#' + panel_list[i]).slideUp(300);
  }
  $('#' + panel_to_show).slideDown(300);
}
/* Hide/show part of a form end */ 



/*
$(document).ready(function(){

}); //ready
*/



