function toggle(obj) {
	var el = document.getElementById(obj);

	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = 'block';
	}

}


function hide(obj) {
	var el = document.getElementById(obj);
	el.style.display = 'none';
	}

function activateDropdown(currD, nextD) {
	var current = document.getElementById(currD);
	var next = document.getElementById(nextD);
	current.style.display = 'none';
}

function changeMlPage() {
	toggle('mlContent'); toggle('ml2Content');
}

function next(el) {
	do {
		el = el.nextSibling;
	} while (el && el.nodeType != 1);
	return el;
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

function clearSearchBox(){
	var sb = document.getElementById('Ntt');
	var val = sb.value;
	sb.blur();
	if (val != ''){
		sb.value = val;
	}

 }
//having a submit issue with 2 forms on the page. need this variable to distinguish between ml and main page search submit.
var ml = 0;
function submitMLSupportSearch() {
	var sTerm = document.mlSearchbarform.Ntt.value
	sTerm = sTerm.replace(/^\s+|\s+$/g, '');
	document.mlSearchbarform.Ntt.value = sTerm;
	if (sTerm == "" || sTerm == "enter your model # or keyword") {
		alert('Please enter a search term and try your search again.');
		return false;
	}
	cmCreateManualLinkClickTag('http://www2.panasonic.com/webapp/wcs/stores/servlet/PNAEndecaSearchCmd/?cm_sp=Homepage%20Support-_-Model%20Locator%20Light%20Box-_-Product%20Search', 'Product%20Search');
	document.mlSearchbarform.submit();
}
function performMLSupportSearch(e) {
    ml = 1;
	e = e || window.event;
	var unicode=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
	if (unicode == 13){
		return submitMLSupportSearch();
	}
}
function performSupportSearch(e) {
	e = e || window.event;
	var unicode=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
	if (unicode == 13){
		return submitSupportSearch();
	}
}
function submitSupportSearch() {
	if (!ml)
	{
	    var sTerm = document.supportSearch.Ntt.value
	    sTerm = sTerm.replace(/^\s+|\s+$/g, '');
	    document.supportSearch.Ntt.value = sTerm;

	    if (sTerm == "" || sTerm == "enter your model # or keyword") {
		        alert('Please enter a search term and try your search again.');
		        return false;
	    }
	    //frmSupportSearch.submit();
	    cmCreateManualLinkClickTag('http://www2.panasonic.com/webapp/wcs/stores/servlet/PNAEndecaSearchCmd/?cm_sp=Homepage%20Support-_-Get%20Support%20Light%20Box-_-Product%20Search', 'Product%20Search');
	    document.supportSearch.submit();
	}
	else
	{
	    var sTerm = document.mlSearchbarform.Ntt.value
        sTerm = sTerm.replace(/^\s+|\s+$/g, '');
        document.mlSearchbarform.Ntt.value = sTerm;
        if (sTerm == "" || sTerm == "enter your model # or keyword") {
	        alert('Please enter a search term and try your search again.');
	        return false;
        }
        cmCreateManualLinkClickTag('http://www2.panasonic.com/webapp/wcs/stores/servlet/PNAEndecaSearchCmd/?cm_sp=Homepage%20Support-_-Model%20Locator%20Light%20Box-_-Product%20Search', 'Product%20Search');
        document.mlSearchbarform.submit();
	}
}

function openwindow(url,w,h) {
	window.open(url,"mywindow","location=0,menubar=0,resizable=0, scrollbar=0, width="+w+",height="+h+"");
}



function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
var SupportBoxTop = (function(){
	return{
		setup:function(){
			xb.addEvent($('support-top'),'click',function(e){
				e = (e||window.event);
				SupportBoxTop.show();
				if(e&&(typeof e.preventDefault)=='function') e.preventDefault();
				e.returnValue = false;
				return false;
			},true);
			xb.addEvent($('support-bubble-top-link'),'click',function(){
				SupportBoxTop.hide();
			},false);
			xb.addEvent($('support-bubble-top-link'),'mouseover',function(){
				addClass($('support-bubble-top-link'),'supportTopHighlight');
			},false);
			xb.addEvent($('support-bubble-top-link'),'mouseout',function(){
				removeClass($('support-bubble-top-link'),'supportTopHighlight');
			},false);
			xb.addEvent($('support_bubble_top'),'mouseenter',function(){
				xb.addEvent($('support_bubble_top'),'mouseleave',function(){
					SupportBoxTop.hide();
				},false);
			},false);
			xb.addEvent($('support_bubble_top'), 'mouseleave', function(){
				SupportBoxTop.hide();
			}, false);
		},
		show:function(){
			$('support_bubble_top').style.visibility = 'visible';
			$('support_bubble_top').style.display = 'block';
			$('iframe_top_bg').style.visibility = 'visible';
			$('support_bubble_top').style.zIndex = 999;
			$('iframe_top_bg').style.zIndex = 998;
			$('iframe_top_bg').style.background = "#900";
			$('iframe_top_bg').style.left = "539px";
			$('iframe_top_bg').style.top = "29px";
			$('iframe_top_bg').style.height = "68px";
			
			return false;
		},
		hide:function(){
			$('support_bubble_top').style.visibility = 'hidden';
			$('iframe_top_bg').style.visibility = 'hidden';
			return false;
		}
	}
})();


var BusinessBoxTop = (function(){
	return{
		setup:function(){
			xb.addEvent($('business-top'),'click',function(e){
				e = (e||window.event);
				BusinessBoxTop.show();
				if(e&&(typeof e.preventDefault)=='function') e.preventDefault();
				e.returnValue = false;
				return false;
			},true);
			xb.addEvent($('business-bubble-top-link'),'click',function(){
				BusinessBoxTop.hide();
			},false);
			xb.addEvent($('business-bubble-top-link'),'mouseover',function(){
				addClass($('business-bubble-top-link'),'supportTopHighlight');
			},false);
			xb.addEvent($('business-bubble-top-link'),'mouseout',function(){
				removeClass($('business-bubble-top-link'),'supportTopHighlight');
			},false);
			xb.addEvent($('business_bubble_top'),'mouseenter',function(){
				xb.addEvent($('business_bubble_top'),'mouseleave',function(){
					BusinessBoxTop.hide();
				},false);
			},false);
			xb.addEvent($('support_bubble_top'), 'mouseleave', function(){
				BusinessBoxTop.hide();
			}, false);
		},
		show:function(){
			$('business_bubble_top').style.visibility = 'visible';
			$('business_bubble_top').style.display = 'block';
			$('iframe_top_bg').style.visibility = 'visible';
			$('business_bubble_top').style.zIndex = 999;
			$('iframe_top_bg').style.zIndex = 998;
			$('iframe_top_bg').style.background = "#900";
			$('iframe_top_bg').style.left = "448px";
			$('iframe_top_bg').style.top = "45px";
			$('iframe_top_bg').style.height = "286px";
			return false;
		},
		hide:function(){
			$('business_bubble_top').style.visibility = 'hidden';
			$('business_bubble_top').style.display = 'none';
			$('iframe_top_bg').style.visibility = 'hidden';
			return false;
		}
	}
})();

/*
   This is an override for the addEvent function
   If this method is not used. the mouseleave event is not recognized in firefox
*/
var xb =
{
	evtHash: [],

	ieGetUniqueID: function(_elem)
	{
		if (_elem === window) { return 'theWindow'; }
		else if (_elem === document) { return 'theDocument'; }
		else { return _elem.uniqueID; }
	},

	addEvent: function(_elem, _evtName, _fn, _useCapture)
	{
		if (typeof _elem.addEventListener != 'undefined')
		{
			if (_evtName == 'mouseenter')
				{ _elem.addEventListener('mouseover', xb.mouseEnter(_fn), _useCapture); }
			else if (_evtName == 'mouseleave')
				{ _elem.addEventListener('mouseout', xb.mouseEnter(_fn), _useCapture); }
			else
				{ _elem.addEventListener(_evtName, _fn, _useCapture); }
		}
		else if (typeof _elem.attachEvent != 'undefined')
		{
			var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) + '::evt_' + _evtName + '::fn_' + _fn + '}';
			var f = xb.evtHash[key];
			if (typeof f != 'undefined')
				{ return; }

			f = function()
			{
				_fn.call(_elem);
			};

			xb.evtHash[key] = f;
			_elem.attachEvent('on' + _evtName, f);

			// attach unload event to the window to clean up possibly IE memory leaks
			window.attachEvent('onunload', function()
			{
				_elem.detachEvent('on' + _evtName, f);
			});

			key = null;
			//f = null;   /* DON'T null this out, or we won't be able to detach it */
		}
		else
			{ _elem['on' + _evtName] = _fn; }
	},

	removeEvent: function(_elem, _evtName, _fn, _useCapture)
	{
		if (typeof _elem.removeEventListener != 'undefined')
			{ _elem.removeEventListener(_evtName, _fn, _useCapture); }
		else if (typeof _elem.detachEvent != 'undefined')
		{
			var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) + '::evt' + _evtName + '::fn_' + _fn + '}';
			var f = xb.evtHash[key];
			if (typeof f != 'undefined')
			{
				_elem.detachEvent('on' + _evtName, f);
				delete xb.evtHash[key];
			}

			key = null;
			//f = null;   /* DON'T null this out, or we won't be able to detach it */
		}
	},

	mouseEnter: function(_pFn)
	{
		return function(_evt)
		{
			var relTarget = _evt.relatedTarget;
			if (this == relTarget || xb.isAChildOf(this, relTarget))
				{ return; }

			_pFn.call(this, _evt);
		}
	},

	isAChildOf: function(_parent, _child)
	{
		if (_parent == _child) { return false };

		while (_child && _child != _parent)
			{ _child = _child.parentNode; }

		return _child == _parent;
	}
};

// JS LIBRARY-INDEPENDANT UTILITY FUNCTIONS FOR CLASS MANIPULATION
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

// INIT
xb.addEvent(window,'load',function(){
	SupportBoxTop.setup();
	BusinessBoxTop.setup();
},false);
