/*
	Dmitriy Abragamov
*/

/*Functionality added to the search box which displays an overlabel on top of the search input, 
and hides it on focus making this form more accessible. In case if Javascript is disabled - input field has default value*/
function initSearchLabel(titleArg){
	if(!document.getElementById) return;
	
	if(!titleArg)titleArg = "Search";
	
	var title = titleArg || null;
	
	var field, id;	
	/*look for all lables with overlabel class*/
	var labels = document.getElementsByTagName("label");
	for( var i=0; i<labels.length; i++){
		if(labels[i].className.indexOf("overLabel") != -1){
			/*get input field associated with label*/
			id = labels[i].htmlFor || labels[i].getAttribute('for');
	      	if (!id || !(field = document.getElementById(id))) {
	        	continue;
	      	} 
	      	/*apply css style to label(it's hidden by default)*/
	      	labels[i].className = 'overLabel-apply';
	      	if(titleArg) labels[i].innerHTML = titleArg;
	      	/*clear default value field of an input field*/
	      	if(field.value === titleArg){
	      		field.value = '';
	      	}
	      	/*do not display label if the search box is not empty*/
	      	if (field.value !== '') {
		        hideLabel(field.getAttribute('id'), true);
		      }
			/*on focus hide label*/
		    field.onfocus = function () {
		        hideLabel(this.getAttribute('id'), true);
		    };
		    /*display label on blur if input field is still empty*/
		    field.onblur = function (){
		    	 if (this.value === '') {
			          hideLabel(this.getAttribute('id'), false);
			        }
		    };
		    /*Safari workaround for the label not passing focus to input field*/
		    labels[i].onclick = function () {
		        var id, field;
		        id = this.getAttribute('for');
		        if (id && (field = document.getElementById(id))) {
		          field.focus();
		        }
		      };
		}
	}
}
/*Hides or shows label explicitly specified for the input field passed as a first parameter(id) 
/*by setting or removing negative text indend.*/
function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-10000em' : '0px';
      return true;
    }
  }
}
/*
	SuckerFish script simulating "hover" event on li elements of a given list
*/
var sfHoverGlobalNav = function() {
	var liElems = document.getElementById('ms_menu').getElementsByTagName('li');
	if (liElems) {
		for (var i = 0; i < liElems.length; i++) {
			liElems[i].onmouseover = function() {
				if(!this.className.match(new RegExp("\s?navDivider\\b"))){
				this.className += " iehover";
				}
			}
			liElems[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
}
if(window.attachEvent) window.attachEvent('onload', sfHoverGlobalNav);