



  function toggleMyDisplayInline(objid) {
  if (document.getElementById) {
    // this is the way the standards work
    if (document.getElementById(objid).style.display=="none") {
      document.getElementById(objid).style.display='inline';
    } else {
      document.getElementById(objid).style.display="none";
    }
  } else if (document.all) {
    // this is the way old msie versions work
    if (document.all[objid].style.display=="none") {
      var style2 = document.all[objid].style.display='inline';
    } else {
      var style2 = document.all[objid].style.display="none";
    }
  } else if (document.layers) {
    // this is the way nn4 works
    if (document.layers[objid].style.display=="none") {
      var style2 = document.layers[objid].style.display='inline';
    } else {
      var style2 = document.layers[objid].style.display="none";
    }
  }

}



function in_array(needle, haystack) {
	var n = haystack.length;
	for (var i=0; i<n; i++) {
		if (haystack[i]==needle) {
			return true;
		}
	}
	return false;
}


function getMatchCount(site_id, myMethod) {
  //make sure some p_i and p_o and p_v exists
  //if there is only on p_i then
  var cbf = document.criteria_builder_form;
  if (cbf.p_i.value && cbf.p_o.value && cbf.p_v.value) {
    if (document.getElementById('currentCriteriaCounter').value == 0) {
      document.getElementById('crit_build_header').innerHTML = 'Your Screening Criteria (0 matches)';
    } else {
      var urlmatchCount = './match_count_ajax.php?p_site_id='+escape(site_id)+'&p_i[]='+escape(cbf.p_i.value)+'&p_o[]='+escape(cbf.p_o.value)+'&p_v[]='+escape(cbf.p_v.value);

      var http = getHTTPObject(); // We create the HTTP Object
      http.open("GET", urlmatchCount, true);
      http.onreadystatechange=function() {
        if (http.readyState==4) document.getElementById('crit_build_header').innerHTML = http.responseText;
      }
      http.send(null);
    }
  } else if (cbf.p_i.length == cbf.p_i.length && cbf.p_i.length == cbf.p_i.length && cbf.p_i.length > 0) {
    //alert('this is a good even array of items');

    var pi_link_string = '';
    var po_link_string = '';
    var pv_link_string = '';
    for (counter = 0; counter < cbf.p_i.length; counter++) {
      pi_link_string = pi_link_string.concat('&p_i[]='+escape(cbf.p_i[counter].value));   }
    for (counter = 0; counter < cbf.p_o.length; counter++) {
      po_link_string = po_link_string.concat('&p_o[]='+escape(cbf.p_o[counter].value));   }
    for (counter = 0; counter < cbf.p_v.length; counter++) {
      pv_link_string = pv_link_string.concat('&p_v[]='+escape(cbf.p_v[counter].value));   }
    var urlmatchCount = './match_count_ajax.php?p_site_id='+escape(site_id)+pi_link_string+po_link_string+pv_link_string;

    var http = getHTTPObject(); // We create the HTTP Object
    http.open("GET", urlmatchCount, true);
    http.onreadystatechange=function() {
      if (http.readyState==4) {
	      document.getElementById('crit_build_header').innerHTML = http.responseText;
	      //alert(http.responseText);
	    }
    }

    http.send(null);


  } else {
    //alert('all messed up 3');
  }
}


function showUpdateCriteria() {
  document.getElementById('crit_build_header').innerHTML = 'Your Screening Criteria (<span style="background-color:#f00; color:#fff">Updating...</span>)';
}

function hide_post(p_gid) {
  if (document.getElementById) {
    // this is the way the standards work
    if (document.getElementById(p_gid).style.display=="none") {
      document.getElementById(p_gid).style.display='';
    } else {
      document.getElementById(p_gid).style.display="none";
    }
  } else if (document.all) {
    // this is the way old msie versions work
    if (document.all[p_gid].style.display=="none") {
      var style2 = document.all[p_gid].style.display='';
    } else {
      var style2 = document.all[p_gid].style.display="none";
    }
  } else if (document.layers) {
    // this is the way nn4 works
    if (document.layers[p_gid].style.display=="none") {
      var style2 = document.layers[p_gid].style.display='';
    } else {
      var style2 = document.layers[p_gid].style.display="none";
    }
  }

}

function hidediv(id) {
  //safe function to hide an element with a specified id
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'none';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'none';
    }
    else { // IE 4
      document.all.id.style.display = 'none';
    }
  }
}

function showdiv(id) {
  //safe function to show an element with a specified id

  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'block';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'block';
    }
    else { // IE 4
      document.all.id.style.display = 'block';
    }
  }
}

		var oldCatLink = "categoryList";
  function showCategory(theval33a, sid) {
		var cat_help_text = "";
		if( document.cat_form) {
    	cat_help_text = eval("document.cat_form." + 'cat_help_'+theval33a + ".value");
		}
		var catLink = "cat_link_" + theval33a;
		eval('document.getElementById("' + catLink + '")').style.backgroundColor = '#35813a';
		eval('document.getElementById("' + catLink + '")').style.color = '#fff';
		eval('document.getElementById("' + oldCatLink + '")').style.backgroundColor = '#fff';
		eval('document.getElementById("' + oldCatLink + '")').style.color = '#000';
		oldCatLink = catLink;
		if(document.getElementById('criteria')) {
    	document.getElementById('criteria').innerHTML = '<span style="background-color:red; color: white; padding: 0 4px 0 4px;">Loading...</div>'; }
    setTimeout("updateCriteriaList('" + theval33a + "', '" + cat_help_text + "', '" + sid + "')",0);
  }
	var oldTable = "";
  function updateCriteriaList(cat_id, cat_help_text, sid) {
		if (cat_help_text != '') {
	    var http = getHTTPObject(); // We create the HTTP Object
	    http.open("GET", 'criteria_list.php?cat_id=' + escape(cat_id)+'&cat_help='+escape(cat_help_text)+'&sid='+escape(sid), true);
	    http.onreadystatechange=function() {
	      if (http.readyState==4) document.getElementById('criteria').innerHTML = http.responseText;
	    }
	    http.send(null);
		}
		else {
		
			var table = 'table' + cat_id;
			
			if (oldTable == "") {
				oldTable = table;
			}
			//alert (oldTable);
			eval('document.getElementById("' + oldTable + '")').style.visibility = 'hidden';
			eval('document.getElementById("' + oldTable + '")').style.position = 'absolute';
			
			eval('document.getElementById("' + table + '")').style.visibility = 'visible';
			eval('document.getElementById("' + table + '")').style.position = 'relative';
			
			oldTable = table;
		}
  }


  function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
  }


