﻿/* Employee Feedback */
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) ? true : false;
var msie_only = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
var msie_old = false; //all versions of MSIE older than 7
var msie_70  = false; // MSIE vesrion 7.0 or newer
var msie_60  = false; // only MSIE 6.0
var msie_55  = false; // only MSIE 5.5

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_70  = (parseFloat(verStr) >= 7.0) ? true : false;
  msie_60  = (parseFloat(verStr) == 6.0) ? true : false;
  msie_55  = (parseFloat(verStr) == 5.5) ? true : false;
}

document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
if ((msie_old == true) && (document.URL.indexOf("/spellcheck-page-") == -1)) {
   document.writeln('div.MainDiv {width:expression(document.body.clientWidth < 998 ? "996px" : "100%" )}\n'); 
   document.writeln('div.CentreColumn {margin-left:200px;}\n');
   document.writeln('.ProperAnswerIconKey, .ExcuseAnswerIconKey, .HelpIconKey {height:20px;}\n');
}

if (msie_only == true) {
  document.writeln('.TableList {top:2px;}\n');
  document.writeln('.EntityTable .TableList td, .EntityTable2 .TableList td  {padding-bottom:4px; padding-top:4px;}\n');
  document.writeln('.EntityTable .TableList .ColVer1, .EntityTable2 .TableList .ColVer1 {padding-top:0px;}\n');
  document.writeln('.EntityTable  .RadioButtonListVertical   tr td {padding-top:0px; padding-bottom:0px;}\n');  
  document.writeln('.EntityTable2 .RadioButtonListVertical   tr td {padding-top:0px; padding-bottom:0px;}\n');  
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList input {position:relative; top:1px;}\n');
  document.writeln('.CbVerticalList {left:-5px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:2px; margin-right:5px;}\n');
  document.writeln('.CheckBox {top:-2px;}\n');
}
if (msie_70 == true) {
  document.writeln('.FormTable .Editbox {padding-top:0px; top:-1px;}\n');
}
if (opera == true) {
  document.writeln('.FormTable .Editbox {padding-top:0px; padding-bottom:1px; height:15px;}\n');
  document.writeln('.CheckBox, .CheckBox2 {margin-left:3px; top:0px; margin-right:0px;}\n');
  document.writeln('.EntityTable .RadioButtonListHorizontal tr td input {margin-left:3px; top:1px; margin-right:0px;}\n');
  document.writeln('.EntityTable .RadioButtonListVertical   tr td input {margin-left:3px; top:-1px; margin-right:0px;}\n');
  document.writeln('.EntityTable .RadioButtonListVertical   tr td {}\n');
  document.writeln('.EntityTable2 .RadioButtonListHorizontal tr td input {margin-left:3px; top:1px; margin-right:0px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListVertical   tr td input {margin-left:3px; top:-1px; margin-right:0px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListVertical   tr td {}\n');
  document.writeln('.EntityTable2 .Textarea, .EntityTable2 .TextareaWide {width:357px;}\n');
  document.writeln('.EntityTable .RadioButtonListHorizontal tr td label, .EntityTable2 .RadioButtonListHorizontal tr td label {top:2px;}\n');
  document.writeln('.List td input {margin-bottom:3px; margin-top:1px; margin-left:2px;}\n');
  document.writeln('.FormTable .TextArea2  {width:546px;}\n');
  document.writeln('.RbVerticalList input {margin-top:2px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList input {margin-right:5px; margin-top:3px; margin-bottom:4px;}\n');
  document.writeln('.CbVerticalList td {text-indent:-22px; padding-left:22px;}\n');  
}
if (firefox == true) {
  document.writeln('.FormTable .Editbox {padding-top:2px; top:1px;}\n');
  document.writeln('.CheckBox, .CheckBox2 {margin:4px; margin-right:3px; top:1px;}\n');
  document.writeln('.EntityTable .RadioButtonListHorizontal tr td input {margin:4px; margin-right:3px; top:2px;}\n');
  document.writeln('.EntityTable .RadioButtonListVertical   tr td input {margin:0px 2px 0px 4px; top:2px;}\n');
  document.writeln('.EntityTable .RadioButtonListVertical   tr td {}\n');  
  //document.writeln('.EntityTable .Textarea, .EntityTable .TextareaWide {width:296px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListHorizontal tr td input {margin:4px; margin-right:3px; left:-5px; top:2px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListVertical   tr td input {margin:0px 2px 0px 4px; top:2px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListVertical   tr td {}\n');  
  //document.writeln('.EntityTable2 .Textarea, .EntityTable2 .TextareaWide {width:355px;}\n');
  document.writeln('.EntityTable .RadioButtonListHorizontal tr td label, .EntityTable2 .RadioButtonListHorizontal tr td label {top:-4px;}\n');
  document.writeln('.List td input {margin:4px;}\n');
  document.writeln('.RbVerticalList input {position:relative; top:2px; margin-top:2px; margin-bottom:4px;}\n');
  document.writeln('.RbVerticalList label {margin-left:8px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:2px; margin-right:8px; margin-top:3px; margin-bottom:5px;}\n');
  document.writeln('.CbVerticalList td {text-indent:-21px; padding-left:21px;}\n');  
}
if (safari == true) {
  document.writeln('.CheckBox, .CheckBox2 {margin:4px; top:1px;}\n');
  document.writeln('.EntityTable .RadioButtonListHorizontal tr td input {margin:4px; }\n');
  document.writeln('.EntityTable .RadioButtonListVertical tr td input {margin:0px 2px 0px 5px;}\n');
  document.writeln('.EntityTable .RadioButtonListVertical tr td {}\n');    
  //document.writeln('.EntityTable .Textarea, .EntityTable .TextareaWide {width:298px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListHorizontal tr td input {margin:4px; }\n');
  document.writeln('.EntityTable2 .RadioButtonListVertical tr td input {margin:0px 2px 0px 5px;}\n');
  document.writeln('.EntityTable2 .RadioButtonListVertical tr td {}\n');    
  document.writeln('.EntityTable2 .Textarea, .EntityTable2 .TextareaWide {width:357px;}\n');
  document.writeln('.EntityTable .RadioButtonListHorizontal tr td label, .EntityTable2 .RadioButtonListHorizontal tr td label {top:2px;}\n');  
  document.writeln('.FormTable .TextArea2  {width:546px;}\n');
  document.writeln('.RbVerticalList input {margin-top:1px; margin-bottom:4px; margin-left:0px;}\n');
  document.writeln('.RbVerticalList label {margin-left:8px;}\n');
  document.writeln('.CbVerticalList input {margin:2px 9px 8px 0px;}\n');
  document.writeln('.CbVerticalList td {text-indent:-21px; padding-left:21px;}\n');  
}
document.writeln('/*]]>*/\n</style>\n');

//any field with default value functionality
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;
}

//information box on validation image rollover
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";
}

//Limits length of text in textarea "element" (dom reference), writes information in "info" (id)
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.";
  }
}

//textarea_container (id)
function initLengthInfo(textarea_container, info_id, max_length) {
  element_ref = document.getElementById(textarea_container).getElementsByTagName("textarea")[0];
  checkLength(element_ref, info_id, max_length);
}

//for search panel
function clearSearchField (field_to_clear) {
  var tmp_obj = field_to_clear.previousSibling;
  tmp_obj=tmp_obj.previousSibling;
  var initial_value = tmp_obj.value;
  if (initial_value == field_to_clear.value) field_to_clear.value="";
} 

//for search panel
function fillSearchField (field_to_fill) {
  var tmp_obj = field_to_fill.previousSibling;
  tmp_obj=tmp_obj.previousSibling;
  var initial_value = tmp_obj.value;
  if (field_to_fill.value == "") field_to_fill.value=initial_value;
}

function entityHelp(button_ref, noAnswerText, ableToAnswerText) {
  var hidden_field_ref  = (((((button_ref.parentNode).parentNode).parentNode).parentNode).parentNode).getElementsByTagName("input")[0];
  var proper_answer_ref = ((((button_ref.parentNode).parentNode).parentNode).parentNode).getElementsByTagName("div")[4];
  var dont_know_ref     = ((((button_ref.parentNode).parentNode).parentNode).parentNode).getElementsByTagName("div")[3];
  var please_state_reason_ref = ((((button_ref.parentNode).parentNode).parentNode).parentNode).getElementsByTagName("div")[2];
  
  if (hidden_field_ref.value == "1") {
    please_state_reason_ref.style.display = "block";
    dont_know_ref.style.display = "block";
    proper_answer_ref.style.display = "none";
    button_ref.className = 'ExcuseAnswerIcon';
    button_ref.title = ableToAnswerText;
    hidden_field_ref.value = "0"
  } else {
    please_state_reason_ref.style.display = "none";
    dont_know_ref.style.display = "none";
    proper_answer_ref.style.display = "block";
    button_ref.className = 'ProperAnswerIcon';
    button_ref.title = noAnswerText;
    hidden_field_ref.value = "1"
  }
  //alert(hidden_field_ref.value );
}


function entitiesInit(button_ref) {
  var entities_list = new Array();
  var all_divs_on_page = document.getElementsByTagName("div");
  var total_number_of_tds;
  var j = 0;
  
  for (var i = 0; i < all_divs_on_page.length; i++ ) {
    if ((all_divs_on_page[i].className.indexOf('EntityContainer') > -1) && (all_divs_on_page[i].className.length == 15)) {
      entities_list[j] = all_divs_on_page[i];
      if (entities_list[j].getElementsByTagName("input")[0].value == "0") {
        entities_list[j].getElementsByTagName("div")[2].style.display = "block"; /* "Please state the reason..." */
        entities_list[j].getElementsByTagName("div")[3].style.display = "block"; /* don't know answer block */
        entities_list[j].getElementsByTagName("div")[4].style.display = "none"; /* proper answer block */
        total_number_of_tds = entities_list[j].getElementsByTagName("td").length;
        entities_list[j].getElementsByTagName("td")[total_number_of_tds - 3].getElementsByTagName("div")[0].className = 'ExcuseAnswerIcon'; /* "button?!" image */
        entities_list[j].getElementsByTagName("td")[total_number_of_tds - 3].getElementsByTagName("div")[0].title = 'Click here if you are able to provide an answer to this question.'; /* "button?!" title */
      }
      j++;
    }
  }
}

function openSpellChecker(text_box_id) {
  main_page_text_box_id_for_popup_window = text_box_id; //global
  spellcheck_window_handle = window.open("spellcheck-page-1.aspx", "SpellCheckerWindow", "menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no, width=420, height=270, top=200, left=300"); //spellcheck_window_handle is a global variable
  id_TiOu=window.setTimeout("spellChceckerContinue('" + text_box_id + "')", 700); //delay to make sure that spellcheck popup is opened
}

function spellChceckerContinue(text_box_id) {
  var main_page_text_box_ref = document.getElementById(text_box_id);
  var popup_page_text_box_ref = spellcheck_window_handle.document.getElementsByTagName("textarea")[0];
  popup_page_text_box_ref.value = main_page_text_box_ref.value;
}

function insertMergeField(field_name, text_area_container) {
	var container_ref = document.getElementById(text_area_container);
	var text_area_ref = container_ref.getElementsByTagName("textarea")[0];
  text_area_ref.value = text_area_ref.value + field_name;
  text_area_ref.focus();
}


