/*Functionality added to the main nav 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 value="Search" by default*/
function initSearchLabel(titleArg){
	if(!document.getElementById) return;
	
	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(title) labels[i].innerHTML = title;
	      	/*clear default value field of an input field*/
	      	if(field.value === 'Search'){
	      		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 fix to allow hover on non "a" tag elements in IE6. 
/*The copy of this fix already exists in general.js, 
/*but it is modified from the original.*/
/*Need to rewrite or completely remove this function from general.js - it is currently 
/*being used for old style navigation.*/
sfHoverGlobalNav = function() {
	var hasMenu = document.getElementById('globalMainNav');
	var liElems = (hasMenu) ? document.getElementById('globalMainNav').getElementsByTagName('li') : null;
	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 += " sfhover";
				/*if(this.className.match(new RegExp("\s?extendedContainer\\b")))
					this.className += " extendedContainer_sfhover";*/
				}
			}
			liElems[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
				/*this.className = this.className.replace(new RegExp(" extendedContainer_sfhover\\b"), "");*/
			}
		}
	}
}
var globalNavIframe = function(){
	var eDD = document.getElementById('mainMenu');
	var divs = (eDD) ? eDD.getElementsByTagName('div') : null;
	if(divs){
		for(var i = 0; i<divs.length; i++){
			if(divs[i].className.match(new RegExp("\s?tab"))){
				var nextTag = divs[i].firstChild;
						if (nextTag.nodeName != 'IFRAME') {
							var ulMat = document.createElement('iframe');
							ulMat.style.display = "block";
							ulMat.style.position = "absolute";
							ulMat.style.top = "0";
							ulMat.style.left = "0";
							ulMat.style.filter = "mask()";
							ulMat.style.width = "1000px";
							ulMat.style.height = "1000px";
							//ulMat.style.zIndex = divs[i].style.zIndex - 1;
							ulMat.style.zIndex = -1;
							divs[i].insertBefore(ulMat, divs[i].firstChild);						
						}
			}
		}
	}
}
/*If IE - attach sfHoverGlobalNav function call to onload event*/
if (window.attachEvent) window.attachEvent('onload', sfHoverGlobalNav);
if (window.attachEvent) window.attachEvent('onload', globalNavIframe);