/* 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

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;
}

if (msie_55==true || by_id==false ) alert('Warning: You are using unsupported web browser. The site will not work correctly. Please upgrade your web browser.');


/* MSIE displays border around flash object on mouseover; this function gets rid of the border*/
function flashNoBorder() {
  if (msie_70) {
    flash_objects = document.getElementsByTagName("object");
    for (var i=0; i < flash_objects.length; i++) {
  	  flash_objects[i].outerHTML = flash_objects[i].outerHTML;
    }
  }
}

/* corection of min-width for IE6 and IE55, adjust the 2 css lines below to project needs, change CSS accordingly */
function minWidthForMSIE() {
  if (msie_55==true) {
    document.writeln('<style type="text/css">\n');
    document.writeln('#CenterSite {width:expression(document.body.clientWidth < 1004 ? "1002px" : "100%" )}\n');      
    document.writeln('</style>\n'); 
  }
  if (msie_60==true) {
    document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
    document.writeln('#CenterSite {width:expression(document.body.clientWidth < 1004 ? "1002px" : "100%" )}\n');      
    document.writeln('/*]]>*/\n</style>\n'); 
  }
}

if (msie_only) minWidthForMSIE(); /*this is executed in head section and writes some CSS code there*/

function menuCorrections() {
  document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
  document.writeln('#MenuBlock div ul li a {padding-top:3px; padding-bottom:3px;}\n');      
  document.writeln('/*]]>*/\n</style>\n'); 
}

if (msie_only) menuCorrections() /*this is executed in head section and writes some CSS code there*/

/* Adjust min-height for IE60 here. Read it from the style sheet (min-height somewhere)*/
function initialCorrections() {
  if (msie_old) {
    if(document.getElementById('MiddleBlockBackground')) document.getElementById('MiddleBlockBackground').style.height="550px";
    if(document.getElementById('MiddleBlockBackgroundNoImgBorder')) document.getElementById('MiddleBlockBackgroundNoImgBorder').style.height="550px";
    if(document.getElementById('MiddleBlock')) document.getElementById('MiddleBlock').style.height="570px";
  }
}

function prepareMenu() {
  navRoot = document.getElementById("MenuBlock");
  for (var intCounter=0; intCounter<navRoot.childNodes.length; intCounter++) {
    node = navRoot.childNodes[intCounter];
    if (node.nodeName.toLowerCase()=="div") {
      node.onmouseover = function() {this.className = "over";}
      node.onmouseout  = function() {this.className = ""; }
    }
  }
}

/*Limites length of text in textarea "element", writes information in "info" */
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);
  }
}

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";
}

/*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);
}
