// JavaScript Document
<!--

// Changes Main Button Style onMouse Event and preloads background image for mouseOver
function doNav(button, action){
	document.getElementById(button).className = "nav " + action;
}
nav_on = new Image();
nav_on.src = "images/nav_on.gif";

// Opens Privacy Policy Window
function libraryWindow(){
	window.open("?pg=privacy_policy", "privacy_policy", 'width=400px,height=209px,top=250px,left=100px');
}

// The following validates the email
String.prototype.trim=function(){
		return this.replace(/^\s*|\s*$/g,'');
}

function checkEmail(str){
	var filter=/^.+@.+\..{2,3}$/
	var parts = str.split(',');
	var validity = true;
	for (i=0;i<parts.length;i++) {
		parts[i].trim();
		if (!filter.test(parts[i])){
			validity = false;
			i = parts.length;
		}
	}
	return validity;
}


function checkIfValidEmail(theform,theitem,goodclass,badclass){
	theitem.className = (checkEmail(theitem.value)) ? goodclass:badclass;
	theform.submit.disabled = (checkEmail(theitem.value)) ? false:true;
}

// Populates Areas on Search Page
function populateArea(id){
  document.getElementById(id).selected = true;
}

// Creates and Populates Areas Table
function generateAreas(id){
  var showAreas = (document.getElementById('county').value == '') ? "hide" : "show";
  document.getElementById("area_div").className = showAreas;
  document.getElementById('champ_areas').className = "hide";
  document.getElementById('clark_areas').className = "hide";
  document.getElementById('other_areas').className = "hide";
//  var boards = new Array();
//  boards['champ'] = 'WRIST';
//  boards['clark'] = 'WRIST';
//  boards['other'] = 'DABR';
  if (showAreas != "hide") {
    document.getElementById('area_id').value = id;
    document.getElementById(id+'_areas').className = "show";
//    document.getElementById('board').value = boards[id];
//    alert(document.getElementById('board').value);
  }
}

// For email flash - Displays correct location div and makes radio button descriptions clickable
function doType(val){
  if (val == "zipcodes"){
    document.getElementById("areas_div").className = "hide";
    document.getElementById("radioAreas").checked = false;
    document.getElementById("spanAreas").className = "normal";
    document.getElementById("zipcodes_div").className = "show";
    document.getElementById("radioZipcodes").checked = true;
    document.getElementById("spanZipcodes").className = "bold";
  } else {
    document.getElementById("zipcodes_div").className = "hide";
    document.getElementById("radioZipcodes").checked = false;
    document.getElementById("spanZipcodes").className = "normal";
    document.getElementById("zipcodes").value = "separate by commas";
    document.getElementById("areas_div").className = "show";
    document.getElementById("radioAreas").checked = true;
    document.getElementById("spanAreas").className = "bold";
  }
}

/*
Browser Sniffer Script-
© Eddie Traversa (nirvana.media3.net)
To add more shock to your site, visit http://www.java-scripts.net
*/

function IEbrowserDetected() {
 	var agt=navigator.userAgent.toLowerCase();
	var agt=navigator.userAgent.toLowerCase();
  var is_major = parseInt(navigator.appVersion);
  var is_minor = parseFloat(navigator.appVersion);
  var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1));
  var is_nav2 = (is_nav && (is_major == 2));
  var is_nav3 = (is_nav && (is_major == 3));
  var is_nav4 = (is_nav && (is_major == 4));
  var is_nav4up = (is_nav && (is_major >= 4));
  var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                        (agt.indexOf("; nav") != -1)) );
  var is_nav5 = (is_nav && (is_major == 5));
  var is_nav5up = (is_nav && (is_major >= 5));
  var is_ie   = (agt.indexOf("msie") != -1);
  var is_ie3  = (is_ie && (is_major < 4));
  var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
  var is_ie4up  = (is_ie  && (is_major >= 4));
  var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
  var is_aol   = (agt.indexOf("aol") != -1);
  var is_aol3  = (is_aol && is_ie3);
  var is_aol4  = (is_aol && is_ie4);
  var is_opera = (agt.indexOf("opera") != -1);
  var is_webtv = (agt.indexOf("webtv") != -1);

  return is_ie;
/*

  if (is_nav4up) {
    return 'nav4up';
  //location.href = netscape4URL; // netscape 4+ but not NS5
  }else if (is_ie4up) { //IE4 & IE5 but returns IE4
    return 'ie4up';
  //location.href = explorer4URL;
  }else if (is_webtv) { // Web TV
    return 'webtv';//location.href = webtvURL;
  }else if (is_aol || is_aol3 || is_aol4) { //AOL
    return 'aol';//location.href = aolURL;
  }else if (is_opera) { // Opera
    return 'opera';//location.href = operaURL;
  }else if (is_ie3||is_nav3) { // 3.0 version browsers
    return 'ie3 or nav3';//location.href = version3URL;
  }else if (is_nav5up) { // Netscape 5
    return 'nav5up';//location.href = w3cURL;
  }*/
}


// For email flash - Populate areas after county is selected
function populateAreas(val){
  var usingIE = IEbrowserDetected();
  var areaSelect = document.getElementById("area");
  areaSelect.options.length=0;
  areaSelect.selectedIndex=-1;
  if(areaSelect.childNodes){
    var originalLength = areaSelect.childNodes.length;
    for(var i = 0; i<originalLength; i++){
      areaSelect.removeChild(areaSelect.childNodes[0]);
    }
  }
  optgrouptext = new Array(new Array("Urbana","Other"),new Array("North Springfield", "South Springfield", "Other"),new Array("Other Counties"));
  var optgroups = new Array();
  for(var i=0;i<optgrouptext[val].length;i++){
    var newElement = document.createElement("OPTGROUP");
    newElement.label = optgrouptext[val][i];
    optgroups.push(newElement);
  }
  for(var i = 0; i < areas[val].length; i++){
    //For Champaign County...
    area = document.createElement("OPTION");
    area.value = areas[val][i][0];
    if(usingIE){
      area.innerText = areas[val][i][1];
    } else {
      area.text = areas[val][i][1];
    }
    if(val == 0){
      if(area.value >= "300" && area.value <= "340"){
        optgroups[0].appendChild(area);
      }else{
        optgroups[1].appendChild(area);
      }
    }
    // For Clark County...
    if(val == 1){
      if(area.value >= "010" && area.value <= "060"){
        optgroups[0].appendChild(area);
      }
      if(area.value >= "070" && area.value <= "090"){
        optgroups[1].appendChild(area);
      }
      if(area.value >= "100" && area.value <= "195"){
        optgroups[2].appendChild(area);
      }
    }
    // For Other Counties...
    if(val == 2){
      optgroups[0].appendChild(area);
    }
  }
  for(var i = 0; i < optgroups.length; i++){
    areaSelect.appendChild(optgroups[i]);
  }
}

// For Useful Info - Populates Info
function populateUsefulInfo(subject,cell){

  document.getElementById('marketAnalysis').className='useful_menu';
  document.getElementById('buyersAgency').className='useful_menu';
  document.getElementById('realEstateGlossary').className='useful_menu';
  document.getElementById('mortgageInformation').className='useful_menu';
  document.getElementById('movingOutOfTown').className='useful_menu';

  cell.className='useful_menu useful_on';

  document.getElementById('useful_div').innerHTML=subject;
}
//-->
