// Generic LawyerShop (non-namespaced) functions
// TODO: import into EI namespace
// 
// Requires: ei.js, prototype.js
// 

// jump to link drop down menu
//-----------------------------------------------------
function JumpToLink ()
{
    // Identify associative array for which to pop new window
    var newWinArr =  new Array();
    var linkForm  = this.document.select_specialty_menu;
    var selMenu   = linkForm.links;
    var selItem   = selMenu.options[selMenu.selectedIndex];

        if ( newWinArr[selItem.text] > 0 )
                 window.open(selItem.value, 'PropertyWindow'+selMenu.selectedIndex, "");
        else
                  window.location.href = selItem.value;
}

// toggles display style of object w/ specified id
//-----------------------------------------------------
function toggleDisplay(obj_id,vis){
	if (document.getElementById) {
		var obj = document.getElementById(obj_id);
		if (obj) {
			if (vis != null) {
				var state = (vis ? 'block' : 'none');
			} else {
				if (obj.style.display == '' || obj.style.display == 'none')
					var state = 'block';
				else
					var state = 'none';
			}
			obj.style.display = state;
		}
	}
}

// stats backward compatibility
//-----------------------------------------------------
function showLayer(obj_id) { 
	if (document.getElementById) {
		var obj = document.getElementById(obj_id);
		if (obj) {
			obj.style.display = 'block';
			obj.style.visibility = 'visible';
		}
	}
}
function hideLayer(obj_id) { 
	if (document.getElementById) {
		var obj = document.getElementById(obj_id);
		if (obj) {
			obj.style.display = 'none';
			obj.style.visibility = 'hidden';
		}
	}
}

// clears and replaces text in input fields and textareas
// -----------------------------------------------------
function clearText(f) {
	if (f.defaultValue==f.value) { f.value = "" }
}

function replaceText(f) {
	if (f.value=="") { f.value = f.defaultValue }
}

// onchange jump menu - assumes absolute url as value
// -----------------------------------------------------
function selectJump(s) {
	if (s.selectedIndex > 0) location.href=s[s.selectedIndex].value;
}

// flyout menu IE compatibility
// -----------------------------------------------------
flyoutNav = function() {
	var nav = document.getElementById("nav-flyout");
	if (nav)
	{
		var lis = nav.getElementsByTagName("LI");
		for (var i=0; i<lis.length; i++) {
			lis[i].onmouseover=function() {
				this.className+=" iehover";
			}
			lis[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", flyoutNav);

// zip search validation required fields
//-----------------------------------------------------
function checkZipSearch(f)
{
	// store default form action for later usage
	if (f.defaultAction==null) f.defaultAction = f.action;
	var label;
	var error;
	var errorClassName = 'validation-error';
	// regexp tests for form fields
	var re = {
		'prod_id'  : /^\D*$/,
		'state_id' : /^\D*$/,
		'ping'     : /^$/i,
		'foo'      : /.*/,
		'bar'      : /.*/
	};
	// specialty
	if (f.ping) {
		label = f.select('label.locator-zip')[0];
		if (label && re.ping.test(f.ping.value)) {
			label.addClassName(errorClassName);
			error = true;
		}
		else label.removeClassName(errorClassName);
	}
	// specialty
	if (f.prod_id) {
		label = f.select('label.locator-product')[0];
		if (label && re.prod_id.test(f.prod_id.value)) {
			label.addClassName(errorClassName);
			error = true;
		}
		else label.removeClassName(errorClassName);
	}
	// country/region
	if (f.state_id) {
		label = f.select('label.locator-state')[0];
		if (label && re.state_id.test(f.state_id.value)) {
			label.addClassName(errorClassName);
			error = true;
		}
		else label.removeClassName(errorClassName);
	}
	// subspecialty check
	if (f.prod_id.value > 999)
		f.action = 'http://www.lawyershop.com/cgi-opt/subspec.cgi';
	else
		f.action = f.defaultAction;

	if (error) {
		var al = $('validation-alert');
		var p = (
			al
				? al.parentNode.removeChild(al)
				: document.createElement('p')
		);
		p.id = 'validation-alert';
		f.appendChild(p);
		p.innerHTML = '<img src="/assets/images/icon-alert.gif" alt="" /> <span>There are empty or unselected required fields</span>';
		return false;
	}
}

//------------------- pop up SWFs on /video/ -------------------//
function popUpSWF(url, type, Width, Height, arg1, arg2, arg3){
	tools = "resizable=no,toolbar=no,location=no,directories=no,status=no,scroll=no,scrollbars=no,menubar=no,width="+Width+",height="+Height+",left=0,top=0";
	if(type == "mp"){
		newWindow = window.open(url+"?bandwidth="+arg1+"&video="+arg2+"&lan="+arg3, 'newWin', tools);
	}
	if(type == "mc"){
		newWindow = window.open(url+"?category="+arg1+"&videoNum="+arg2, 'newWin', tools);
	}
	if(type == "media"){
		newWindow = window.open(url+"?bandwidth="+arg1+"&video="+arg2+"&lan="+arg3, 'newWin', tools);
	}
	newWindow.focus();
}

//------------------- Son-Of-Sucker-Fish IE Hack -------------------//
sfHover = function() {
  if (document.getElementById("nav")) {
	  var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	  for (var i=0; i < sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
		  this.className+=" sfHover";
		}
		sfEls[i].onmouseout=function() {
		  this.className=this.className.replace(new RegExp(" sfHover\\b"), "");
		}
	  }
   }
 }
 if (window.attachEvent) window.attachEvent("onload", sfHover);

/** JavaScript **/
ieHover = function() {
var ieULs = document.getElementById('nav').getElementsByTagName('ul');
/** IE script to cover <select> elements with <iframe>s **/
for (j=0; j<ieULs.length; j++) {
ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + ieULs[j].innerHTML);
/*ieULs[j].innerHTML = ('<iframe id="iePad' + j + '" src="about:blank" scrolling="no" frameborder="0" style=""></iframe>' + ieULs[j].innerHTML);
	var ieMat = document.getElementById('iePad' + j + '');*/
//	var ieMat = ieULs[j].childNodes[0];  alert(ieMat.nodeName); // also works...
	var ieMat = ieULs[j].firstChild;
		ieMat.style.width=ieULs[j].offsetWidth+"px";
		ieMat.style.height=ieULs[j].offsetHeight+"px";	
		ieULs[j].style.zIndex="99";
}
/** IE script to change class on mouseover **/
	var ieLIs = document.getElementById('nav').getElementsByTagName('li');
	for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
		ieLIs[i].onmouseover=function() {this.className+=" iehover";}
		ieLIs[i].onmouseout=function() {this.className=this.className.replace(' iehover', '');}
	}}
if (window.attachEvent) window.attachEvent('onload', ieHover);
/** end **/
