
var __current_shown_nav = 0;
var __nav_timeout = null;

var __homepromo_timeout = null;

var _ua = UC(navigator.userAgent);
var _mac = (_ua.indexOf("MAC") != -1) ? true : false;
var _o = (_ua.indexOf("OPERA") != -1) ? true : false;
var _ie = ((document.all&&!_o) ? true : false);

function showNav(id)
{
  var oNAV, oCELL, i, w, j, oTMP;


	if(__current_shown_nav)
	{
		clearTimeout(__nav_timeout);
		_GID('nav_id_' + __current_shown_nav).setAttribute('is_hover', '0');
		if(__current_shown_nav != id)
		{
			hideNav2(__current_shown_nav);
		}
	}
			
	oNAV = _GID('nav_id_' + id);

	oCELL = _GID('Nav' + id);

	if(!oCELL)
	{
		oTMP = document.getElementsByTagName('LI');
		for(i=0; i<oTMP.length; i++)
		{
			if(oTMP[i].getAttribute('NavId') == 'Nav' + id)
			{
				oCELL = oTMP[i];
				break;
			}
		}
	}

	if(oCELL)
	{
		oNAV.style.width = (oCELL.clientWidth ? oCELL.clientWidth : oCELL.offsetWidth) + 2 + 'px';

		w = 0;
//		w = _GID('wrapper').offsetLeft + (oCELL.getAttribute('nav_offset')-1) * 120;
		w =  (oCELL.getAttribute('nav_offset')-1) * 120;
		oNAV.style.left = w + 'px';
		oNAV.style.top = '29px';
	}

	__current_shown_nav = id;


	oNAV.setAttribute('is_hover', '1');

	oNAV.style.display = 'block';

	
		if(!_ie || _mac)
		{

	oTMP = document.getElementsByTagName('OBJECT');
	for(i=0; i<oTMP.length; i++)
	{
		if(oTMP[i].id == 'FlashItem')
		{
			oTMP[i].style.visibility = 'hidden';
		}
	}
		}
}


function hideNav(id)
{
	if(!__current_shown_nav) return;
	
	_GID('nav_id_' + id).setAttribute('is_hover', '0');

	__nav_timeout = setTimeout("hideNav2('"+id+"')", 100);
}


function hideNav2(id)
{
  var oNAV;

	oNAV = _GID('nav_id_' + id);


	if(typeof(oNAV) != 'object') return;
			

	if(oNAV.getAttribute('is_hover') == '1') return;


	oNAV.style.display = 'none';
	__current_shown_nav = false;


		if(!_ie || _mac)
		{
/*
	oTMP = document.getElementsByTagName('DIV');
	for(i=0; i<oTMP.length; i++)
	{
		if(oTMP[i].id == 'FlashBox')
		{
			oTMP[i].style.visibility = 'visible';
		}
	}
*/
	oTMP = document.getElementsByTagName('OBJECT');
	for(i=0; i<oTMP.length; i++)
	{
		if(oTMP[i].id == 'FlashItem')
		{
			oTMP[i].style.visibility = 'visible';
		}
	}
		}
}



function onResizeNav()
{
	if(__current_shown_nav)
	{
		showNav(__current_shown_nav);
	}
}


function hideNavAll()
{
	if(__current_shown_nav)
	{
	        hideNav(__current_shown_nav);
	}
}
		
		
function navInit()
{
  var i, j, k, m, id, oNAV, oSUBNAV, oCELL, fn, o, t;

        oNAV = _GID('mainNav').childNodes;

        m = 0;
	for(i=0; i<oNAV.length; i++)
	{
		oCELL = oNAV[i];

		if(UC(oNAV[i].tagName) == 'LI')
		{
			m++;
		}

		oSUBNAV = oNAV[i].childNodes;
		for(j=0; j<oSUBNAV.length; j++)
		{
			if(UC(oSUBNAV[j].tagName) == 'UL')
			{
			        k = (i*1000 + j);
			        id = 'nav_id_' + k;
				oSUBNAV[j].id = id;

				oSUBNAV[j].onmouseover = function (){showNav(this.getAttribute('nav_id'))};
				oSUBNAV[j].onmouseout = function (){hideNav(this.getAttribute('nav_id'));};
				oSUBNAV[j].setAttribute('nav_id', k);

//				oCELL.id = 'Nav' + k;
				oCELL.setAttribute('NavId', 'Nav' + k);

				oSUBNAV[j].style.left = (_GID('wrapper').offsetLeft + (m-1) * 120) + 'px';

				
				oCELL.setAttribute('nav_offset', m);

				oCELL.onmouseover = function (){showNav(this.getAttribute('nav_id'));};
				oCELL.onmouseout = function (){hideNav(this.getAttribute('nav_id'));};
				oCELL.setAttribute('nav_id', k);
			}
		}
	}
	
	
	o = _GID('iHomePromo');
	if(o)
	{
		o.setAttribute('osrc', o.getAttribute('src'));
	}

	oNAV = _GID('productList');
	if(oNAV)
	{
	        oNAV = oNAV.childNodes;
	        for(i=0; i<oNAV.length; i++)
	        {
			oSUBNAV = oNAV[i].childNodes;
			for(j=0; j<oSUBNAV.length; j++)
			{
			        o = oSUBNAV[j];
				if(UC(o.tagName) == 'A')
				{
					t = trim(o.getAttribute('over'));
					if(t && _GID('iHomePromo'))
					{
						o.onmouseover = function (){if(__homepromo_timeout) {clearTimeout(__homepromo_timeout);};_GID('iHomePromo').src = this.getAttribute('over'); _GID('iHomePromo').alt = this.innerHTML};
						o.onmouseout = function (){__homepromo_timeout = setTimeout("HomePromo()", 200);};
						o.preload_img = new Image();
						o.preload_img.src = t;
					}
				}
			}
	        }
	}
}



function HomePromo()
{
	if(!__homepromo_timeout) return;
	
	_GID('iHomePromo').src = _GID('iHomePromo').getAttribute('osrc')
}


var __FORMS = ['formSamples', 'formContact'];
__FORMS.formSamples = {

	'first_name': ['First Name', 'text'],
	'last_name': ['Last Name', 'text'],
	'company': ['Company', 'text'],
	'address': ['Address 1', 'text'],
	'city': ['City', 'text'],
	'state': ['State', 'text'],
	'zip': ['Zip Code', 'zip'],
	'phone': ['Telephone', 'phone', false],
	'fax': ['Fax', 'phone', false],
	'email': ['E-Mail', 'email'],
	'product': ['Product', 'text']
};
__FORMS.formContact = {
	'first_name': ['First Name', 'text'],
	'last_name': ['Last Name', 'text'],
	'company': ['Company', 'text'],
	'email': ['E-Mail', 'email'],
	'phone': ['Telephone', 'phone', true],
	'contact_us': ['How would you like us to contact you?', 'text']

};




function ValidateForm(oFORM)
{
  var i, j, f, v, formName, fName, fType;
        formName = oFORM.name;
try{
	for(f in __FORMS[formName])
	{
		v = __FORMS[formName][f];
		fName = v[0];
		fType = v[1];

		switch(fType)
		{
			case 'text':
			        try {
					v = trim(oFORM[f].value);
				}catch(e){
					alert('Required field "' + fName + '" not found in form "' + formName + '"');
					return false;
				}
                        	if(!v)
                        	{
					alert('Field "' + fName + '" is required');
					return false;
                        	}
                        	break;

			case 'zip':
			        try {
					v = trim(oFORM[f].value);
				}catch(e){
					alert('Required field "' + fName + '" not found in form "' + formName + '"');
					return false;
				}
                        	if(!v || !parseInt(v))
                        	{
					alert('Field "' + fName + '" is required');
					return false;
                        	}
                        	break;

			case 'email':
			        try {
					v = trim(oFORM[f].value);
				}catch(e){
					alert('Required field "' + fName + '" not found in form "' + formName + '"');
					return false;
				}
                        	if(!v)
                        	{
					alert('Field "' + fName + '" is required');
					return false;
                        	}
                        	if(v.indexOf('@') < 0)
                        	{
					alert('Field "' + fName + '" is not a valid e-mail address');
					return false;
                        	}
                        	break;

			case 'phone':
			        try {
					v = trim(oFORM[f].value);
				}catch(e){
					alert('Required field "' + fName + '" not found in form "' + formName + '"');
					return false;
				}
                        	if(!v && __FORMS[formName][f][2])
                        	{
					alert('Field "' + fName + '" is required');
					return false;
                        	}
                        	if(v && !v.match(/^[\s-]*[\(]*[\s-]*(\d{3})[\s-]*[\)]*[\s-]*(\d{3})[\s-]*(\d{2})[\s-]*(\d{2})[\s-]*$/i))
                        	{
					alert('Field "' + fName + '" is not a valid phone number');
					return false;
                        	}else{
                        	        if(v)
                        	        {
						oFORM[f].value = v.replace(/^[\s-]*[\(]*[\s-]*(\d{3})[\s-]*[\)]*[\s-]*(\d{3})[\s-]*(\d{2})[\s-]*(\d{2})[\s-]*$/g, "($1) $2-$3$4");
					}
                        	}
                        	break;
		}
	}
}catch(e){
	alert('Error happened: ' + (e.description ? e.description : e));
	return false;
}
	return true;
}




addHook('WindowOnResize', 'onResizeNav');
addHook('DocumentOnClick', 'hideNavAll');
addHook('WindowOnLoad', 'navInit');

















var path = window.location.href.replace(/(http:\/\/[^\/]*)(.*\/)([^\/]*)/i, '$2').toLowerCase();
var page_index = window.location.href.replace(/(http:\/\/[^\/]*)(.*)/i, '$2').toLowerCase();
var indexes = new Array('', 'index.php', 'default.asp', 'default.jsp', 'index.jsp', 'index.shtml');


function init_nav()
{
  var oNav, oDiv, oLI, oUL, oA, i, j, k, k1, l, t, o, m, n, a, nid;

	nid = 'mainNav';

	oNav = document.getElementById(nid);
	if(oNav)
	{
		oLI = oNav.getElementsByTagName('LI');
		if(oLI)
		{
			l = oLI.length;
			for(j=0; j<l; j++)
			{
				oA = oLI[j].getElementsByTagName('A');
				if(oA)
				{
					k = oA.length;
					for(i=0; i<k; i++)
					{
						t = (oA[i].href + '').replace(/(http:\/\/[^\/]*)(.*)/i, '$2').toLowerCase();
						a = path.split('/');
						p = '/';
						for(n=1; n<a.length; n++)
						{
							p += a[n] + '/';
							for(m=0; m<indexes.length; m++)
							{
								if(t == p+indexes[m] || t == page_index)
								{
									oLI[j].id = 'current';
								}
							}
						}
					}
				}
			}
		}
	}
}
addHook('WindowOnLoad', 'init_nav');