var _ua = navigator.userAgent.toUpperCase();
var _mac = (_ua.indexOf("MAC") != -1) ? true : false;
var _o = (_ua.indexOf("OPERA") != -1) ? true : false;
var _ie = ((document.all&&!_o) ? true : false);



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');
var nav_selected = null, nav_cur = null;
var nav_selected2 = null, nav_cur2 = null;
var __nav2_timer;







var __nav_cover = null;
function setNavBG(x, y, w, h)
{
  var bAdd = false;

	if(!__nav_cover)
	{
		bAdd = true;
		__nav_cover = document.createElement("IFRAME");
		__nav_cover.style.display = "none";
	}

	__nav_cover.style.overflow = 'hidden';
	__nav_cover.style.zIndex = 1;

	__nav_cover.style.position = "absolute";
	__nav_cover.style.left = x + 'px';
	__nav_cover.style.top = y + 'px';
	__nav_cover.style.width = w + 'px';
	__nav_cover.style.height = h + 'px';

	__nav_cover.style.display = "block";


	if(bAdd)
	{
		document.getElementById('nav2').appendChild(__nav_cover);
	}
}
function hideNavBG()
{
	if(__nav_cover)
	{
		__nav_cover.style.display = 'none';
	}
}









function init_nav()
{
  var oNav, oDiv, oLI, oUL, oA, i, j, k, k1, l, t, o, m, n, a;

	o = document.getElementById('page-title');
	if(o)
	{
//		o.onclick = function(){window.location = "/";};
	}




	oNav = document.getElementById('nav2');
	if(oNav)
	{
		oLI = oNav.getElementsByTagName('LI');
		if(oLI)
		{
			l = oLI.length;
			for(j=0; j<l; j++)
			{
				oA = oLI[j].getElementsByTagName('A');
				if(oA)
				{

					if(oLI[j].parentNode.parentNode.id == 'nav2') // && oLI[j].id != 'current'
					{
						oLI[j].setAttribute('nav_id', j);

						if(oLI[j].id == 'current')
						{
							oLI[j].setAttribute('current', '1');
							nav_cur2 = oLI[j];
						}


						oLI[j].onmouseover = function ()
						{
							if(__nav2_timer)
							{
								clearTimeout(__nav2_timer);
								__nav2_timer = null;
							}

							if(nav_cur2 && nav_cur2 != this)
							{
								nav_cur2.setAttribute('is_hover', '0');
								hideNav2();
							}

							this.setAttribute('is_hover', '1');


							if(this.id != 'current2')
							{
								this.id = 'current2';
								nav_cur2 = this;
							}


							if(_ie)
							{
								var i,o,k,t;
								k = this.childNodes.length;
								for(i=0;i<k;i++)
								{
									o = this.childNodes[i];
									t = o.tagName + '';
									if(t.toUpperCase() == 'UL')
									{
										o.style.zIndex = 999;
										setNavBG(o.offsetLeft, o.offsetTop, o.clientWidth, o.clientHeight);
									}
								}
							}
						}

						oLI[j].onmouseout = function ()
						{
							if(nav_cur2)
							{
								nav_cur2.setAttribute('is_hover', '0');
								__nav2_timer = setTimeout("hideNav2()", 100);
							}
						}
					}
				
				}
			}
		}
	}


	o = document.forms.header_questions.question;
	o.onchange = function(){
		window.location = 'http://'+ window.location.host + this.options[this.selectedIndex].value;
	}


	oNav = document.getElementById('resultsBox');
	if(oNav)
	{
		a = oNav.getElementsByTagName('TR');
		k = a.length;
		for(i=1; i<k; i++)
		{
			o = a[i];
			o.setAttribute('uid', o.id);

			o.onmouseover = function(){
				this.id = 'current';
			}
			o.onmouseout = function(){
				this.id = '';
			}

			o.onclick = function(){
				var f = document.forms.search_3;
				window.location = 'installations-results-details.php?search_type='+f.search_type.value+'&search_location='+f.search_location.value+'&perpage='+f.perpage.value+'&uid=' + this.getAttribute('uid');
			}
		}
	}




	a = document.getElementsByTagName('A');
	k = a.length;
	for(i=0; i<k; i++)
	{
		o = a[i];

		if(o.className.toLowerCase() == 'glossary')
		{
			o.setAttribute('_title', o.title);
			o.title = '';

			o.onmouseover = tooltip_show;
			o.onmouseout = tooltip_hide;
			o.onmousemove = tooltip_move;
		}
	}
}



function hideNav2()
{
	if(nav_cur2)
	{
		if(nav_cur2.getAttribute('is_hover') != '1')
		{
			hideNavBG();

			if(nav_cur2.getAttribute('current') == '1')
			{
				nav_cur2.id = 'current';
			}else{
				nav_cur2.id = '';
			}

			nav_cur2 = null;
		}
	}
}







addHook('OnWindowLoad', 'init_nav');


















function listOpenSelectors()
{
  var i, j, a, k, ca;
	ca = new Array();
	a = (getCookie('borrego-nav-sel') + '').split('|');
//alert('GET: '+getCookie('nav-sel'));

	k = a.length;
	for(i=0; i<k; i++)
	{
		j = a[i] * 1;
		if(j>0)
{
		ca[j] = 1;
}
	}
	return ca;
}


function storeListSelectors(ca)
{
var v, t = '';
	for(v in ca)
	{
		if(ca[v] == 1 && v != 'undefined')
		{
			t += (t==''?'':'|') + v;
		}
	}
//alert('SET: '+t);
	setCookie('borrego-nav-sel', t, 1);
}












function FORM_validate_search(o)
{
	var ret = true;
return true;
	if(o['search_type'].value == '')
	{
		ret = false;
		alert('Please pick installation type');
		return ret;
	}

	if(o['search_location'].value == '')
	{
		ret = false;
		alert('Please choose county');
		return ret;
	}

	return ret;
}






if (parseInt(navigator.appVersion) >= 4)
{
	if (navigator.appName == "Netscape")
	{
        try {
			document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
		}catch(e){}
	}
}






var __tooltip_box = null;

function tooltip_show(e)
{
	var bAdd = false;

	if(!__tooltip_box)
	{
		bAdd = true;
		__tooltip_box = document.createElement("DIV");
		__tooltip_box.className = 'tooltip_box';
	}
	__tooltip_box.style.display = "none";

	var title = this.getAttribute('_title');

	if(bAdd)
	{
		document.body.appendChild(__tooltip_box);
	}


	if(title.length > 0)
	{
		__tooltip_box.innerHTML = title;
		tooltip_move(e);
		__tooltip_box.style.position = "absolute";
		__tooltip_box.style.display = "block";
		__tooltip_box.style.zIndex = 999;
	}

}



function tooltip_move(e)
{
	var x, y;
	x = (window.event ? window.event.clientX : (e ? (e.pageX ? e.pageX : 0) : 0));
	y = (window.event ? window.event.clientY + document.body.scrollTop : (e ? (e.pageY ? e.pageY : 0) : 0));

	if(__tooltip_box)
	{
		__tooltip_box.style.left = (x + 20) + 'px';
		__tooltip_box.style.top = (y - __tooltip_box.scrollHeight / 2 + 20) + 'px';
	}
}


function tooltip_hide(e)
{
	if(__tooltip_box)
	{
		__tooltip_box.style.display = "none";
		__tooltip_box.innerHTML = '';
	}
}








var __FORMS = ['contact', 'quote'];
__FORMS.contact = {
	'first_name': ['First Name', 'text'],
	'email': ['E-Mail', 'email']
};
__FORMS.quote = {
	'first_name': ['First Name', 'text'],
	'last_name': ['Last Name', 'text'],
	'telephone': ['Telephone', 'phone', true],
	'email': ['E-Mail', 'email'],
	'address1': ['Address 1', 'text'],
	'address2': ['Address 2', 'text'],
	'city': ['City', 'text'],
	'zip': ['Zip', 'zip']
};


var __bgcolor = "#FEC398";

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)
                        	{
					oFORM[f].style.backgroundColor = __bgcolor;
					alert('Field "' + fName + '" is required');
					return false;
                        	}
				oFORM[f].style.backgroundColor = '';
                        	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))
                        	{
					oFORM[f].style.backgroundColor = __bgcolor;
					alert('Field "' + fName + '" is required');
					return false;
                        	}
				oFORM[f].style.backgroundColor = '';
                        	break;

			case 'email':
			        try {
					v = trim(oFORM[f].value);
				}catch(e){
					alert('Required field "' + fName + '" not found in form "' + formName + '"');
					return false;
				}
                        	if(!v)
                        	{
					oFORM[f].style.backgroundColor = __bgcolor;
					alert('Field "' + fName + '" is required');
					return false;
                        	}
                        	if(v.indexOf('@') < 0)
                        	{
					oFORM[f].style.backgroundColor = __bgcolor;
					alert('Field "' + fName + '" is not a valid e-mail address');
					return false;
                        	}
				oFORM[f].style.backgroundColor = '';
                        	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])
                        	{
					oFORM[f].style.backgroundColor = __bgcolor;
					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))
                        	{
					oFORM[f].style.backgroundColor = __bgcolor;
					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");
					}
                        	}
				oFORM[f].style.backgroundColor = '';
                        	break;
		}
	}
}catch(e){
	alert('Error happened: ' + (e.description ? e.description : e));
	return false;
}
	return true;
}








if(typeof sIFR == "function")
{
	if(hasFlash)
	{
		sIFR.replaceElement(named({sSelector:"#body h1", sFlashSrc:"/web-common/swf/h1.swf", sColor:"#333333", sBgColor:"#FFFFFF", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0", sWmode: 'transparent'}));
	}
}



