// JavaScript Document
function toggle_display(id) {
	var disp = document.getElementById(id).style.display;
	if (disp == 'none') {
		disp = 'block';	
	} else {
		disp = 'none';
	}
}
function validate_required(field)
{
	with (field)
	{
		if (value==null||value=="")
		{
			return false;
		} else {
			field.focus();
			return true;
		}
	}
}
function validate_expression(field, expr)
{
	var ex = '';
	switch (expr) {
		case 'alpha':
			ex = /^[a-zA-Z ]+$/;
			break;
		case 'number':
			ex  = /^[0-9]+$/;
			break;
		case 'alphanum':		
			ex = /^[0-9a-zA-Z ]+$/;
			break;
		case 'email':
			ex = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;	
			break;
		default: // alpha
			ex = /^[a-zA-Z ]+$/;
			break;
	}

	var val = field.value.replace(/ /,'');
	if (val.match(ex)) {
		return true;	
	} else {
		field.focus();
		return false;
	}
}

function compare_values(field_a, field_b) {
	if (field_a.value == field_b.value) {
		return true;
	} else {
		field_a.focus();
		return false;
	}
}

function confirm_delete(obj_name, id, page) {
	if (confirm("Are you sure you want to delete " + obj_name + "?")) {
		window.location.href = page + "?id=" + id + "&action=remove";
	}
}

function detect_ie() {
	var ver = 0;
	var msg = '';
	var ua = navigator.userAgent;
	var av = navigator.appVersion;
	if (ua != null)
	{
		if (ua.indexOf("MSIE") != -1)
		{
			if (av.indexOf("MSIE")!=-1){
				var temp=av.split("MSIE");
				ver=parseFloat(temp[1]);
			}
		}
	}
	return ver;
}

function swapClass(elem, val) {
	document.getElementById(elem).className = val;
}

function gotoPest() {
	var ddl = document.getElementById('ddlPests');
	var idx = ddl.selectedIndex;
	if(idx != 0) {
		var val = ddl.options[idx].value;
		window.location = '/pests/' + val + '.html';
	}
}

window.onload = function() {
	MM_preloadImages('./assets/images/filigree.gif',
	'./assets/images/bgContent.gif',
	'./assets/images/bgBody.gif',
	'./assets/images/logoEcoWise.gif',
	'./assets/images/logoCritterControl.gif',
	'./assets/images/btnShort.gif',
	'./assets/images/btnLong.gif',
	'./assets/images/btnShortOn.gif',
	'./assets/images/btnLongOn.gif');
}

/* BEGIN PRELOAD IMAGES FUNCTIONS */
function MM_swapImgRestore()
{
  var i;
  if(document.MM_sr) for(i=0; i < document.MM_sr.length; i++)
    if(document.MM_sr[i] && document.MM_sr[i].oSrc)
	  document.MM_sr[i].src = document.MM_sr[i].oSrc;
}

function MM_preloadImages()
{
  var i,j;

  if(!document.MM_p) document.MM_p = new Array();

  for(i = 0, j = document.MM_p.length; i < MM_preloadImages.arguments.length; i++) if(MM_preloadImages.arguments[i].indexOf("#") != 0)
  {
    document.MM_p[j] = new Image;
    document.MM_p[j].src = MM_preloadImages.arguments[i];
    j++;
  }
}

function MM_swapImage(o, m)
{
  var x = document.getElementById(o);
  document.MM_sr = new Array;
  if(x)
  {
    document.MM_sr[0] = x;
    x.oSrc = x.src;
    x.src = m;
  }
}

function MM_swapImages(o, m)
{
  var x,i,j;
  document.MM_sr = new Array;
  if(o.length != m.length) return;
  for(i = 0, j = 0; i < o.length; i++)
  {
    x = document.getElementById(o[i]);
    if(x)
    {
      document.MM_sr[j] = x;
      x.oSrc = x.src;
      x.src = m[i];
	  j++;
    }
  }
}
/* END PRELOAD IMAGES FUNCTIONS */

/* BEGIN DROP-DOWN MENU */
function loadPests(list) {
	var ids = new Array(list);
	//alert('loadPests');
	for(var i = 0; i < ids.length; i++)
	{
	   var sfEls = document.getElementById(ids[i]).getElementsByTagName("LI");
	   for (var i = 0; i < sfEls.length; i++) {
		   sfEls[i].onmouseover = function() {
			   if(!this.oldClassName)
				   this.oldClassName = this.className.replace(new RegExp("\\bsfhover\\b"), "");
			   this.className += " sfhover";
		   }
		   sfEls[i].onmouseout = sfEls[i].onclick = function() {
			   this.className = this.oldClassName;
		   }
	   }
	}
}
/* END DROP-DOWN MENU */


window.onload = function () {
	if(doPests)
		loadPests(list);
}