﻿/* LEF - London Energy Forum */
/* detecting type of browser; seting up variables available globally */
var by_id = (document.getElementById) ? true : false; //new browsers should use getElementById('zzzz')
var by_all = (document.all) ? true : false; //some old browsers
var opera = (navigator.appName.indexOf("Opera")!=-1) ? true : false;
var msie_only = (navigator.appName.indexOf("Microsoft")!=-1) ? true : false;  //all versions of MSIE
var msie_old = false; //all versions of MSIE older than 7
var msie_70  = false; // MSIE vesrion 7.0 or newer
var msie_55  = false; // only MSIE 5.5
var msie_60  = false; // only MSIE 6.0

/* setting msie_older, msie_55, msie_60 variables */
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;
  //window.alert('IE version-'+verStr+'  old MSIE-'+msie_old+'  60-'+msie_60+'  55-'+msie_55+'  70 or newer-'+msie_70+'  opera-'+opera );
}

if (opera) {
  document.writeln('<style type="text/css">\n');
  document.writeln('.RowWithSubmit {padding-right:5px;}\n');
  document.writeln('.form_table .FileUpload {width:99%;}\n'); 
  document.writeln('.form_table .DropDown {width:100.7%;}\n'); 
  document.writeln('.form_editbox_1 {width:271px;}\n');
  document.writeln('.BookDelegates .DropDown1 {width:524px;}\n');
  document.writeln('</style>\n'); 
}


if (msie_only) {
  document.writeln('<style type="text/css">\n');
  document.writeln('.CheckBox {position:relative; left:-4px;}\n');
  document.writeln('.BookDelegates .DropDown1 {width:526px;}\n');
  document.writeln('</style>\n'); 
}


/* corection of min-width handling for IE6, adjust the 2 css lines below to project needs */
function min_width_MSIE() {
  if (msie_55==true) {
    document.writeln('<style type="text/css">\n');
    document.writeln('.CenterSite1 { width:expression(document.body.clientWidth < 1002 ? "1000px" : "100%" )\n');      
    document.writeln('</style>\n'); 
  }
  if (msie_60==true) {
    document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
    document.writeln('.CenterSite1 { width:expression(document.body.clientWidth < 1002 ? "1000px" : "100%" )\n');      
    document.writeln('/*]]>*/\n</style>\n'); 
  }
}

if (msie_only) min_width_MSIE(); /*this is executed in head section and writes some CSS code there*/



/*This solves problem of lacking min-height in MSIE older than 7.0*/
function min_height_MSIE(layer, height) {
  if (msie_old) document.getElementById(layer).style.height=height;
}


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";
}

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);
  }
}

/*Initializing "number of chcracters left" fields*/
function initCharactersLeft(parent_id){
  var parent_ref = document.getElementById(parent_id);
  parent_ref.getElementsByTagName("textarea")[0].focus();
  parent_ref.getElementsByTagName("textarea")[0].blur();
  window.scrollTo(0,0);
}

//for search pannel
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 pannel
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;
}


// for 3D buttons
function buttonUp(which_one) {
  which_one.style.borderLeftColor='#4f5565';
  which_one.style.borderTopColor='#4f5565';
  which_one.style.borderRightColor='#222222';
  which_one.style.borderBottomColor='#222222';
}

function buttonFlat(which_one) {
  which_one.style.borderColor='#3E4350';
}

function buttonDown(which_one) {
  which_one.style.borderLeftColor='#222222';
  which_one.style.borderTopColor='#222222';
  which_one.style.borderRightColor='#4f5565';
  which_one.style.borderBottomColor='#4f5565';
}

//Popup info box on booking list page
function showBox(obj_ref) {
  var inner_text=obj_ref.nextSibling.innerHTML;
  if (inner_text.length > 68)
    obj_ref.nextSibling.style.display="block";
}

function hideBox(obj_ref) {
  obj_ref.nextSibling.style.display="none";
}
