var dom = document.getElementById? 1 : 0;
var ie  = document.all? 1 : 0;
var ns  = document.layers? 1 : 0;

function showObject(objList){var a = objList.split(',');for(var i = 0; i < a.length; i++){show(a[i]);}}
function hideObject(objList){var a = objList.split(',');for(var i = 0; i < a.length; i++){hide(a[i]);}}
function show(obj){obj = findObj(obj);if(!obj) return;if (dom || ie){obj.style.visibility = "visible";obj.style.display = "";}else if (ns){if(document.layers[obj]){obj.visibility = "show";obj.display = "";}}}
function hide(obj){obj = findObj(obj);if(!obj) return;if (dom || ie){obj.style.visibility = "hidden";obj.style.display = "none";}else if (ns){if(document.layers[obj]){obj.visibility = "hide";obj.display = "none";}}}
function findObj(obj){var p, i, found, doc;doc = document;if(!(found = doc[obj]) && ie){found = doc.all[obj];}for (i=0; !found && i < doc.forms.length; i++){found = doc.forms[i][obj];}for(i=0; !found && ns && i < doc.layers.length; i++){found = find(obj,doc.layers[i].document);}if(!found && dom){found = document.getElementById(obj);}return found;}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function isDHTML()
{
	var DHTML = (document.getElementById || document.all || document.layers);
	return DHTML;
}


function showHide(obj_id)
{
	if (!isDHTML()) return;
	var x = new getObj(obj_id);
	var x2="show"+obj_id;
	var x3="hide"+obj_id;
	vis = x.style.display;
	if (vis == "") 
	{
		hide(obj_id);
		hide(x3);
		show(x2);
	}
	else
	{
		show(obj_id);
		show(x2);
		hide(x3);
	}
}
function HideSection(obj_id)
{
	if (!isDHTML()) return;
	if (obj_id == 'weather') {
		var x2="show"+obj_id;
		var x3="hide"+obj_id;
		var x4=obj_id+"3";
		var x5=obj_id+"2";
		Effect.BlindUp(x5);
		Effect.BlindUp(x4);
		//Effect.BlindUp(obj_id);
		//Effect.BlindUp(x3);
		
		//hide(obj_id);
		hide(x3);
		show(x2);
	}
	else {
		var x2="show"+obj_id;
		var x3="hide"+obj_id;
		Effect.BlindUp(obj_id);
		Effect.BlindUp(x3);
		hide(obj_id);
		hide(x3);
		show(x2);
	}
}
function ShowSection(obj_id)
{
	if (!isDHTML()) return;	

	if (obj_id == 'weather') {
		var x2="show"+obj_id;
		var x3="hide"+obj_id;
		var x4=obj_id+"2";
		var x5=obj_id+"3";
		Effect.BlindDown(obj_id);
		Effect.BlindDown(x3);
		Effect.BlindDown(x4);
		Effect.BlindDown(x5);
		show(obj_id);
		hide(x2);
		show(x3);
		show('weather2');
		show('weather3');
		show(x5);
	}
	else if (obj_id == 'editzipcode') {
		var x2="show"+obj_id;
		var x3="hide"+obj_id;

		//Effect.BlindDown(obj_id);
		//Effect.BlindDown(x3);
		Effect.BlindDown('editzipcode');
		Effect.BlindDown('editzipcode2');
		//show(obj_id);
		//hide(x2);
		//show(x3);
		show('editzipcode2');
		show('editzipcode');
	
	}
	else {
		var x2="show"+obj_id;
		var x3="hide"+obj_id;
		Effect.BlindDown(obj_id);
		Effect.BlindDown(x3);
		show(obj_id);
		hide(x2);
		show(x3);
	}
}
function ShowRest(obj_id, obj_id1, obj_id2)
{
	if (!isDHTML()) return;		
	//show(obj_id);
	Effect.BlindDown(obj_id);
	show(obj_id);
	hide(obj_id2);
	show(obj_id1);
	//Effect.BlindDown(obj_id1);
}
function HideRest(obj_id, obj_id1, obj_id2) {
	if (!isDHTML()) return;
	Effect.BlindUp(obj_id);
	//hide(obj_id);
	hide(obj_id1);
	show(obj_id2);
}

  var req;
  var which;

  function retrieveWeather() {
    var wZip = document.getElementById("wZipCode").value;
    // Make sure url matches to avoid cross-site errors
    var myURL="bqhome.com/";
    var searchFile="weather/getweather.cfm?";
    var searchParams="zipCode="+wZip;
    var sURL = ""+window.location;
    var nDomainIndex=sURL.indexOf("bqhome.com");
    var siteURL=sURL.substring(0,nDomainIndex);
    var aJaxSearchURL=siteURL+myURL+searchFile+searchParams;
    //alert(aJaxSearchURL);
	
	//var url = "http://www.bqhome.com/weather/getweather.cfm?zipCode="+wZip;
    var url = aJaxSearchURL;
      if (window.XMLHttpRequest) { // Non-IE browsers
        req = new XMLHttpRequest();
        req.onreadystatechange = processStateChangeWeather;
        try {
          req.open("GET", url, true);
        } catch (e) {
          alert(e);
        }
        req.send(null);
      } else if (window.ActiveXObject) { // IE
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
          req.onreadystatechange = processStateChangeWeather;
          req.open("GET", url, true);
          req.send();
        }
      }    
  }

  function processStateChangeWeather() {
    if (req.readyState == 4) { // Complete
      if (req.status == 200) { // OK response
        // We're going to get a list of all tags in the returned XML with the
        // names title, link and description.  Everything else is ignored.
        // For each that we find, we'll constuct a simple bit of HTML for
        // it and build up the HTML to display.  When we hit a title,
        // link or description element that isn't there, we're done.
        xml = req.responseText; //responseXML;
        document.getElementById("weather2").innerHTML = xml; //html;        
        i = 0;
        html = "";
		Effect.BlindUp('editzipcode2');
		//Effect.BlindUp('editzipcode');
		//hide('editzipcode2');
		//hide('editzipcode');
        //HideSection('editzipcode');
		//HideSection('editzipcode2');		
       // document.getElementById("rssData").innerHTML = xml; //html;        
      } else {
        alert("Problem: " + req.statusText);
      }
    }
  }
/* -------------------------------------------------------------------
	W_isNumeric(event)
	PURPOSE: Return field object
	INPUT  : event
	RETURNS: pointer to field
	NOTES  : 
--------------------------------------------------------------------  */		      
function W_isNumeric(e)
{
	e = (e) ? e : event;
    var charCode = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : 
        ((e.which) ? e.which : 0));
	if ( (charCode >= 48 && charCode <= 57) || (charCode == 8) || (charCode == 39) || (charCode == 37) || (charCode == 9) )
		return true;
	else
	{
		alert("Please enter numeric values only");
		return false;
	}
}  
function CheckZip()
{
  var cntry='USA';
  var obj = document.getElementById("wZipCode");
  var zip = obj.value;
  if (zip)
    {      
     	var Numeric=true;
       	if (cntry == 'USA' || cntry == 'United States')
     	{
	 		if (zip.length == 0 || zip.length < 5) {
            alert('ZIP Code must contain 5 or 9 digits');
                obj.value = obj.defaultValue;
        	    return false;	   
            }
			var i = 0;  
			var ch = '';
		 	var l = obj.value.length; 
			var s = obj.value; 
			var sx = '';

	 		for ( i = 0; i < l; i++)
	   		{
	     		ch = s.substring(i, i+1);
	     		if (ch == '-')
	       		continue;
	     		if ( ch < "0" || ch > "9" )
	       		{
		 			Numeric = false;
	       		}
	          	sx += ch;
	   		}
	 if (!Numeric) {
        alert('ZIP Code must be numeric');
        obj.value = obj.defaultValue;
	    return false;	   
     }

	 l = sx.length;

	 if (l != 5 && l != 9) {
	   alert('ZIP Code must be 5 or 9 digits long');
       obj.value = obj.defaultValue;
	    return false;	   
     }
       }
    }
  return true;
}
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
/* News RSS Functions */
var xmlRequestObj;
function retrieveNewsURL(url) {
	bSkip=true;
        if (browser == 'Netscape Navigator' || browser == 'Opera') {
               retrieveNewsURL2(url);
        } else {
	functionToCall = processStateChangeHeadlines; //processStateChangeNews; //callFunc;
	url = "http://bqhome.com/getRSS2.cfm?newsXML="+url;
	stripWS = true; //ignoreWhite;
	if (window.ActiveXObject) { // IE
            try {
                xmlRequestObj = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
			}
	xmlRequestObj.onreadystatechange = proccessXML;
	xmlRequestObj.open("GET", url, true);
	xmlRequestObj.send();
   }
}


function is_ws(nod) {
	return !(/[^\t\n\r ]/.test(nod.data));
}

function findWhiteSpace(node, nodeNo) {
	for (i=0; i<node.childNodes.length; i++) {
		if (node.childNodes[i].nodeType == 3 && is_ws(node.childNodes[i])) {
			nodesToDelete[nodesToDelete.length] = node.childNodes[i]
		}
		if (node.childNodes[i].hasChildNodes()) {
			findWhiteSpace(node.childNodes[i], i);
		}
	}
	node = node.parentNode;
	i = nodeNo;
}

function stripWhiteSpace(node) {
	nodesToDelete = Array();
	findWhiteSpace(node, 0);
	for(i=nodesToDelete.length-1;i>=0;i--) {	
		nodeRef = nodesToDelete[i];
		nodeRef.parentNode.removeChild(nodeRef)
	}
}
var resultXML;
function proccessXML() {
	if (xmlRequestObj.readyState == 4 && (xmlRequestObj.status == 200 || xmlRequestObj.status == 304)) {	
		if (browser == 'Netscape Navigator' || browser == 'Opera') {
             var XMLdoc = req.responseXML; //responseXML;
        } else {
            var XMLdoc = new ActiveXObject("Microsoft.XMLDOM");
        	var xmlLoaded=XMLdoc.loadXML(xmlRequestObj.responseText);	
        }
        
	    i = 0;
        html = "";
		RssLoop = new Array();
		currentNewsCounter=1;
		maxNewsCounter=0;
        while (i >= 0) {
          t = XMLdoc.getElementsByTagName("title")[i];
          l = XMLdoc.getElementsByTagName("link")[i];
          d = XMLdoc.getElementsByTagName("description")[i];
          if (t != null && l != null && d != null) {
            t = t.firstChild.data;
            l = l.firstChild.data;
            d = d.firstChild.data;
            //html = "<a href=\"" + l + "\"><b>" + t + "</b></a>" + d + "<br><br>";
            html = "<div id=\"rssData2\" style=\"background-color:#CCCCCC;\"><table bgcolor=\"#CCCCCC\" style='margin-left:10px;'><tr><td>"+"<a target\"_blank\" href=\"" + l + "\"><b>" + t + "</b></a></td></tr>"+"<tr><td>"+d+"</td></tr></table></div>";
			maxNewsCounter+=1;
			RssLoop[maxNewsCounter] = new addNews(html);
            i++;
          } else {
            i = -1;
          }
        } 
		hide("rssData");      
		ShowRSSNews();
	}
}
function proccessXML2() {
	if (req2.readyState == 4 && (req2.status == 200 || req2.status == 304)) {	
		if (browser == 'Netscape Navigator' || browser == 'Opera') {
             var XMLdoc = req2.responseXML; //responseXML;
        } else {
            var XMLdoc = new ActiveXObject("Microsoft.XMLDOM");
        	var xmlLoaded=XMLdoc.loadXML(xmlRequestObj.responseText);	
        }
        
	    i = 0;
        html = "";
		RssLoop = new Array();
		currentNewsCounter=1;
		maxNewsCounter=0;
        while (i >= 0) {
          t = XMLdoc.getElementsByTagName("title")[i];
          l = XMLdoc.getElementsByTagName("link")[i];
          d = XMLdoc.getElementsByTagName("description")[i];
          if (t != null && l != null && d != null) {
            t = t.firstChild.data;
            l = l.firstChild.data;
            d = d.firstChild.data;
            html = "<div id=\"rssData2\" style=\"background-color:#CCCCCC;\"><table bgcolor=\"#CCCCCC\" style='margin-left:10px;'><tr><td>"+"<a target\"_blank\" href=\"" + l + "\"><b>" + t + "</b></a></td></tr>"+"<tr><td>"+d+"</td></tr></table></div>";
			maxNewsCounter+=1;
			RssLoop[maxNewsCounter] = new addNews(html);
            i++;
          } else {
            i = -1;
          }
        } 
		hide("rssData");      
		ShowRSSNews();
	}
}
function addNews(news)
		{
			this.news 	= news;		// field name 
			return this;
		}
function ShowRSSNews()
{
	currentNewsCounter=0;
	setTimeout("waitWhile();", 50);
	return false;
}
var bSkip=false;
function waitWhile()
{
	if (bSkip) {
		bSkip=false;
		setTimeout("ShowRSSNews();", 100);
		return false;
	}
	var tmp = currentNewsCounter+1;
	currentNewsCounter+=1;;
	if (currentNewsCounter > maxNewsCounter) {
		currentNewsCounter=1;
		tmp=2;
	}
    show("rssData");
       document.getElementById("rssData").innerHTML = RssLoop[tmp].news;   
	   Effect.SlideDown("rssData2");	   
	   Rounded("div#rssData","White","#CCCCCC");
	setTimeout("waitWhile();", 14000);
	return false;
}	
function retrieveNewsURL2(url) {

    if (url != "") {      
      url = "http://bqhome.com/getRSS2.cfm?newsXML="+url; //?newsXML="+url;
      if (window.XMLHttpRequest) { // Non-IE browsers
        req2 = new XMLHttpRequest();
		req2.overrideMimeType('text/xml')
        req2.onreadystatechange = proccessXML2;
        try {
          req2.open("GET", url, true);
        } catch (e) {
          //alert(e);
        }
        req2.send(null);
      } else if (window.ActiveXObject) { // IE
            try {
                req2 = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    req2 = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        if (req2) {
          req2.onreadystatechange = processStateChangeNews;
          req2.open("GET", url, true);
          req2.send();
        }
      }
    }
  }

function processStateChangeNews() {
    if (req2.readyState == 4) { // Complete
      if (req2.status == 200) { // OK response
        if (browser == 'Netscape Navigator' || browser == 'Opera') {
             xml = req2.responseXML; //responseXML;
        } else {
            xml = resultXML;
        }
   
        i = 0;
        html = "";

        while (i >= 0) {
          t = xml.getElementsByTagName("title")[i];
          l = xml.getElementsByTagName("link")[i];
          d = xml.getElementsByTagName("description")[i];
          if (t != null && l != null && d != null) {
            t = t.firstChild.data;
            l = l.firstChild.data;
            d = d.firstChild.data;
            html += "<a href=\"" + l + "\"><b>" + t + "</b></a>" + d + "<br><br>";
            i++;
          } else {
            i = -1;
          }
        } 
        
       document.getElementById("rssData").innerHTML = html;        
      } else {
        alert("Problem: " + req.statusText +" - " +req.status);
		document.getElementById("rssData").innerHTML = "Problem: " + req.statusText;
      }
    }
  }
  
 function processStateChangeHeadlines() {
    if (req.readyState == 4) { // Complete
      if (req.status == 200) { // OK response
        if (browser == 'Netscape Navigator' || browser == 'Opera') {
             xml = req.responseXML; //responseXML;
        } else {
            xml = resultXML;
        }

        i = 0;
        html = "";

        while (i >= 0) {
          t = xml.getElementsByTagName("title")[i];
          l = xml.getElementsByTagName("link")[i];
          d = xml.getElementsByTagName("descr")[i];
          if (t != null && l != null && d != null) {
            t = t.firstChild.data;
            l = l.firstChild.data;
            d = d.firstChild.data;
            html += "<a href=\"" + l + "\"><b>" + t + "</b></a>" + d + "<br><br>";
            i++;
          } else {
            i = -1;
          }
        }         
       document.getElementById("rssData").innerHTML = html;        
      } else {
        alert("Problem: " + req.statusText +" - " +req.status);
		document.getElementById("rssData").innerHTML = "Problem: " + req.statusText;
      }
    }
  }
function showLayer(layerID) {
	Effect.BlindDown(layerID);
	show(layerID);
}
function hideLayer(layerID) {
	Effect.BlindUp(layerID);
}
function validateEmail(obj) {
var str = obj.value;
	if ( str == '' || str == ' ')  {
				return true;
	} else  {
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
			var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
			var reg1 = new RegExp(reg1str);
			var reg2 = new RegExp(reg2str);
			if (!reg1.test(str) && reg2.test(str))
			  return;  // all ok
			alert(obj.value + " is an invalid e-mail");
			obj.focus();
		return;
		}  else {
	if(str.indexOf("@") >= 0) {
		
		return true;        // all ok
	}
	alert(obj.value + " is an invalid e-mail");
	obj.focus();
	return false;
	}
  }
}
function checkPass(id2) {
	var id1=findObj("password").value;
	if ( (id1 != id2) || (id1.length < 6) )  {
			alert("Passwords do not match or are too short.");
	}
}