/*
var arCONSUMER = [[0,1,'the air you breathe',0,0,'airyoubreathe.aspx'],
                  [0,1,'FAQs',0,0,'FAQs.aspx'],
                  [0,1,'faucets/fixtures',0,0,'faucets.aspx'],
                  [0,1,'in-floor heating',0,0,'infloorheat.aspx'],
                  [0,1,'nate patch',0,0,'natepatch.aspx'],
                  [0,1,'preventative maintenance',0,0,'preventative.aspx'],
                  [0,1,'proper humidity',0,0,'properhumidity.aspx'],
                  [0,1,'summer heat',0,0,'summerheat.aspx'],
                  [0,1,'testimonials',0,0,'testimonials.aspx']]; 
var arSERVICES = [[2,1,'service department',0,1,'services.aspx'],
                  [3,1,'sales & service',0,1,'salesservice.aspx'],
                  [4,3,'commercial',1,0,'commercial.aspx'],
                  [5,3,'electrical',1,0,'electrical.aspx'],
                  [6,3,'heating',1,0,'heating.aspx'],
                  [7,3,'hours',1,0,'hours.aspx'],
                  [8,2,'parts',1,0,'parts.aspx'],
                  [9,2,'plumbing',1,0,'plumbing.aspx'],
                  [10,2,'sheetmetal',1,0,'sheetmetal.aspx'],
                  [11,2,'showroom',1,0,'showroom.aspx']];*/
var arABOUT    = [[0,1,'history',0,0,'history.aspx'],
                  [0,1,'principles',0,0,'principles.aspx'],
                  [0,1,'welcome',0,0,'welcome.aspx']];
var arCONTRACTORS = [[0,1,'commercial',0,0,'commercialcontract.aspx'],
                     [0,1,'remodelers',0,0,'remodelers.aspx'],
                     [0,1,'residential',0,0,'residentialbuilders.aspx']];               
                  
var timer;
var miniBrowserTimer;
function showMenu(which,pid,level,stepDown) {
	var existingMenuLevel = level+1;
	var tblWidth = 150;
	hideMenu(level);
	clearTimeout(timer);
	if (!document.getElementById('divSubMenu_'+existingMenuLevel)) { //only reloadin' menu if it does not exist
		switch (which) {
		    case 'products':
		        var arMenu = arCATEGORIES;
		        var marginTop = 0;
		        break;
		    case 'contractors':
		        var arMenu = arCONTRACTORS;
		        var marginTop = 59;
		        break;
		    case 'service':
		        var arMenu = arSERVICES;
		        var marginTop = 79;
		        break;	
		 /* case 'consumer':
		        var arMenu = arCONSUMER;
		        var marginTop = 119;
		        tblWidth = 165;
		        break;	*/
		}

		var str = subIcon = menuItem = "";
		var marginLeft = 150;
			for (var m=0; m<level; m++) marginLeft += 153;
			for (var m=0; m<stepDown; m++) {
				marginTop += 20;
				if (parseInt((m+1)/2) == 1)
					marginTop += 1; //stepping is not consistent for some reason.. I think to do with the odd borders, so am compensatin'
			}

		level++;
	    
	    if (browserDetect() == 'ie')
	        transType = 'trans1';
	    else
	        transType = 'trans3';

		for (i=0; i<arMenu.length; i++) {
			if (arMenu[i][1] == pid) {

				menuItem = arMenu[i][2].toUpperCase();

				if (arMenu[i][4] != 0) {
				    if (arMenu[i][5]) {
				        onClick = 'onclick="window.location=\'' + arMenu[i][5] + '\'"';
				    }
				    else {
				        onClick = '';
				    }
				    str += '<table width="'+ tblWidth +'" border="0" cellpadding="3" cellspacing="0" onmouseover="formatTbl(this,1); showMenu(\''+which+'\','+arMenu[i][0]+','+level+','+stepDown+');" onmouseout="formatTbl(this,0);" ';
				    str += '	style="font-family:century gothic,arial;font-size:.64em;color:black;background-image:url(images/menu_bg.gif);background-repeat:no-repeat;cursor:pointer">';			
				    str += '	<tr><td width="'+ tblWidth +'" align="right" valign="top" ' + onClick + '>'+menuItem+'&nbsp;&raquo;</td></tr>';
				    str += '</table>';
				}
				else {
				    if (which == 'products') {
				        preLnk = 'http://'; onClick = 'onclick="loadBrowser(\'' + preLnk + arMenu[i][5] + '\',\''+ menuItem + '\')"';
				    }
				    else {
				        preLnk = ''; onClick = 'onclick="window.location=\'' + preLnk + arMenu[i][5] + '\'"';
				    }
				    str += '<table width="'+ tblWidth +'" ' + onClick + ' border="0" cellpadding="3" cellspacing="0" onmouseover="formatTbl(this,1); clearTimeout(timer)" onmouseout="formatTbl(this,0);" ';
				    str += '	style="font-family:century gothic,arial;font-size:.64em;color:black;background-image:url(images/menu_bg.gif);background-repeat:no-repeat;cursor:pointer">';			
				    str += '	<tr><td width="'+ tblWidth +'" align="right" valign="top">'+menuItem+'&nbsp;&nbsp;</td></tr>';
				    str += '</table>';
				}
				
				stepDown++;
			}
		}

		var tbl_pre  = '<table id="tblMenu_'+level+'" class="' + transType + '" width="'+ tblWidth +'" cellpadding="0" cellspacing="0" border="0" style="position:absolute;border-left:1px solid #CACACA;border-right:1px solid #CACACA;border-top:1px solid #CACACA;background-color:white;margin-top:'+marginTop+'px;margin-left:'+marginLeft+'px"><tr><td width="'+ tblWidth +'">';
		var tbl_post = '</td></tr></table>';
		if (str != "") {
			fillDiv(tbl_pre+str+tbl_post,level,transType);
			if (browserDetect() == 'ie') loadTrans(1,level,2);
		}
	}
}
function hideMenu(level) {
	var ni = document.getElementById('divSubMenus');
	//this is a static number... representing 8 categories deep... for this project, it is safe
	clearTimeout(timer);
	for (i=8; i>level; i--) {
		if (document.getElementById('divSubMenu_'+i))
			ni.removeChild(document.getElementById('divSubMenu_'+i));
	}
}
function fillDiv(menu,level,transType) {
	 if (!document.getElementById('divSubMenu_'+level)) {
		 var ni = document.getElementById('divSubMenus');
		 var newdiv = document.createElement('div');
		 var divIdName = 'divSubMenu_'+level;
		 newdiv.setAttribute('id',divIdName);
		 newdiv.setAttribute('class',transType);
		 newdiv.innerHTML = menu;
		 ni.appendChild(newdiv);
	}
}
function formatTbl(obj,how) {
	if (how == 1) { //on
		obj.style.color = 'white';
		obj.style.background = 'url(images/menu_bg-on.gif)';
	}
	else {
		obj.style.color = 'black';
		obj.style.background = 'url(images/menu_bg.gif)';
		timer = setTimeout("loadTrans(0,0,2)", 1000);
	}
}
function loadTrans(how,level,t) {
	if (how == 1) {
		if (t <= 3)
			setTimeout("changeTrans("+how+","+level+","+t+")",80);
	}
	else {
		if (t >= 1)
			setTimeout("changeAllTrans("+how+","+level+","+t+")", 10);
		else if (t <= 0)
			hideMenu(0);
	}
}
function changeTrans(how,level,t) {
	var obj = document.getElementById('tblMenu_'+level);
	if (obj) //makin' sure object is created before script is executed
		obj.className = "trans"+t; t++;

	loadTrans(how,level,t);
}
function changeAllTrans(how,level,t) {
	for (i=8; i>=level; i--) {
		if (document.getElementById('tblMenu_'+i))
			document.getElementById('tblMenu_'+i).className = "trans"+t;
	}
	t--;
	loadTrans(how,level,t);
}


function validateContactForm() { 
    var fname = document.getElementById('txtFName').value;
    var lname = document.getElementById('txtLName').value;
    var city = document.getElementById('txtCity').value;
    var phone = document.getElementById('txtPhone').value;
    var email = document.getElementById('txtEmail').value;
    var QorC = document.getElementById('txtQorC').value;

    var arFlds = [[fname,'txtFName'],[lname,'txtLName'],[city,'txtCity'],[phone,'txtPhone'],[email,'txtEmail'],[QorC,'txtQorC']];
    var submitForm = true;
    
    for (i=0; i<arFlds.length; i++) document.getElementById(arFlds[i][1]).style.backgroundColor = '#F7F7F7';
    
    for (i=0; i<arFlds.length; i++) {
        if (arFlds[i][0].length < 2) {
            document.getElementById(arFlds[i][1]).style.backgroundColor = '#B89696'; submitForm = false;
        }
        if (arFlds[i][1] == 'txtEmail') {
            if (!arFlds[i][0].match('@')) {
                document.getElementById(arFlds[i][1]).style.backgroundColor = '#B89696'; submitForm = false;
            }
        }
    }
    if (submitForm)
        return true;
    else
        return false;    
}

function validateReferralForm() { 
    var fname = document.getElementById('txtFName').value;
    var lname = document.getElementById('txtLName').value;
    var adrs = document.getElementById('txtAdrs').value;
    var city = document.getElementById('txtCity').value;
    var state = document.getElementById('txtState').value;
    var zip = document.getElementById('txtZip').value;
    var phone = document.getElementById('txtPhone').value;
    var fname2 = document.getElementById('txtFName2').value;
    var lname2 = document.getElementById('txtLName2').value;
    var phone2 = document.getElementById('txtPhone2').value;
    var relationship = document.getElementById('txtRelationship').value;
    

    var arFlds = [[fname,'txtFName'],[lname,'txtLName'],[adrs, 'txtAdrs'],[city,'txtCity'],[state,'txtState'],[zip,'txtZip'],[phone,'txtPhone'],[fname2,'txtFName2'],[lname2,'txtLName2'],[phone2,'txtPhone2'],[relationship,'txtRelationship']];
    var submitForm = true;
    
    for (i=0; i<arFlds.length; i++) document.getElementById(arFlds[i][1]).style.backgroundColor = '#F7F7F7';
    
    for (i=0; i<arFlds.length; i++) {
        if (arFlds[i][0].length < 2) {
            document.getElementById(arFlds[i][1]).style.backgroundColor = '#B89696'; submitForm = false;
        }
        if (arFlds[i][1] == 'txtEmail') {
            if (!arFlds[i][0].match('@')) {
                document.getElementById(arFlds[i][1]).style.backgroundColor = '#B89696'; submitForm = false;
            }
        }
    }
    if (submitForm)
        return true;
    else
        return false;    
}

function validateNewsletterForm() { 
    var fname = document.getElementById('txtFName').value;
    var lname = document.getElementById('txtLName').value;
    var city = document.getElementById('txtCity').value;
    var email1 = document.getElementById('txtEmail1').value;
    var email2 = document.getElementById('txtEmail2').value;

    var arFlds = [[fname,'txtFName'],[lname,'txtLName'],[city,'txtCity'],[email1,'txtEmail1'],[email2,'txtEmail2']];
    var submitForm = true;
    
    for (i=0; i<arFlds.length; i++) document.getElementById(arFlds[i][1]).style.backgroundColor = '#F7F7F7';
    
    for (i=0; i<arFlds.length; i++) {
        if (arFlds[i][0].length < 2) {
            document.getElementById(arFlds[i][1]).style.backgroundColor = '#B89696'; submitForm = false;
        }
        if (arFlds[i][1] == 'txtEmail1' || arFlds[i][1] == 'txtEmail2') {
            if (!arFlds[i][0].match('@')) {
                document.getElementById(arFlds[i][1]).style.backgroundColor = '#B89696'; submitForm = false;
            }
        }
    }
    if (email1 != email2) {
        document.getElementById('txtEmail1').style.backgroundColor = '#B89696';
        document.getElementById('txtEmail2').style.backgroundColor = '#B89696';                
        submitForm = false;
    }

    if (submitForm)
        return true;
    else
        return false;    
}
function browserDetect() {
	var version = 0;
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		var temp = navigator.appVersion.split("MSIE")
		version = parseFloat(temp[1])
		if (version >= 5.5) //NON IE browser will return 0
			return 'ie';
	}
	else if(navigator.userAgent.indexOf("Firefox") != -1) {
		var versionindex = navigator.userAgent.indexOf("Firefox") + 8;
		if (parseInt(navigator.userAgent.charAt(versionindex)) >= 1)
			return 'firefox';
	}
	else if (navigator.appName == "Netscape" && parseFloat(navigator.appVersion) >= 4.7) //detect Netscape 4.7+
		return 'netscape';
	else if(navigator.userAgent.indexOf("Opera") != -1){
		var versionindex = navigator.userAgent.indexOf("Opera") + 6
		if (parseInt(navigator.userAgent.charAt(versionindex)) >= 8)
			return 'opera';
	}
	else {
		return 'unknown';
	}
}
function closeMiniBrowser() {
    document.getElementById('tblBrowserFrame').style.display = 'none';
}
function loadMiniBrowser(link,title) {
    clearTimeout(miniBrowserTimer);
    document.body.style.cursor = 'wait';
    document.getElementById('miniBrowserTitle').innerHTML = title;
    frmMiniBrowser.location.href = link;
    if (browserDetect() == 'ie') 
         var h = document.body.offsetHeight;
    else
         var h = 950;

    document.getElementById('miniBrowserTrans').height = h;
    miniBrowserTimer = setTimeout("showFrame()",500);
}

function loadBrowser(link,title) {
    window.open(link);
}
function showFrame() {
    hideMenu(0);
    document.getElementById('tblBrowserFrame').style.display = 'block'
    document.body.style.cursor = 'default';
}
