// opens pop-up window
function openWindow(url, name, width, height) {
	var newwidth = width + 50;
	var newheight = height + 50;
	var features = "scrollbars,resizable,width=" + newwidth + ",height=" + newheight;
  popupWin = window.open(url, name, features);
}
function decision(message, url){
  if(confirm(message)) location.href = url;
}
function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=415,height=300,left = 362,top = 234');");
}
function rusure(page,id,tabtype){
	question = confirm("Are you sure you want to do this?")
	if (question !="0"){
		top.location = page+"?disableid="+id+"&tabtype="+tabtype;
	}
}
function sure(page,id,tabtype){
	question = confirm("Are you sure you want to delete this "+tabtype+"?")
	if (question !="0"){
		top.location = page+"?delete="+id;
	}
}
function navBar ( tableCellRef, menFlag, color ) {
  var c = color;
	if ( menFlag ) {
  	tableCellRef.style.backgroundColor = c;
		tableCellRef.style.borderColor = 'black';
		tableCellRef.style.cursor = 'hand';
  } else {
		tableCellRef.style.backgroundColor = c;
		tableCellRef.style.borderColor = 'efefef';
		tableCellRef.style.cursor = 'hand';
	}
}
function show(showid,type) {
  var showid = showid;
  var type = type;
	obj = document.getElementById(showid);
  if (obj.style.display==type || obj.style.display=='') obj.style.display="none";
  else { 
     obj.style.display = '';
     obj.style.display = type;
  }
}
function show2(showid,type,theselect) {
  var showid = showid;
  var type = type;
	obj = document.getElementById(showid); 
  if (obj.style.display==type) obj.style.display="none";
  else { 
    if (theselect.options[theselect.selectedIndex].value=="Yes") {
     obj.style.display = "block";
    }
  }
}
function showhide(showid,num) {
  var showid = showid;
  var num = num;
  obj = document.getElementById(showid);
  obj.style.display = "block";
  if (num==1) {
    obj = document.getElementById('zipcodesearch');
    obj.style.display="none";
    obj = document.getElementById('streetsearch');
    obj.style.display="none";
  }
  else if (num==2) {
    obj = document.getElementById('basicsearch');
    obj.style.display="none";
    obj = document.getElementById('streetsearch');
    obj.style.display="none";
  }
  else if (num==3) {
    obj = document.getElementById('basicsearch');
    obj.style.display="none";
    obj = document.getElementById('zipcodesearch');
    obj.style.display="none";
  }
}

function navBar1 ( tableCellRef, menFlag, navStyle ) {
	if ( menFlag ) {
		switch ( navStyle ) {
			case 1:
			  tableCellRef.style.cursor = 'pointer';
				tableCellRef.style.backgroundColor = '#1B4C64';
				tableCellRef.style.borderColor = 'black';
		}
	} else {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.backgroundColor = '#92B3C3';
				tableCellRef.style.borderColor = 'efefef';
		}
	}
}
var req;
function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();
  req.onreadystatechange = processReqChange;
  req.open("GET", url, true);
  req.send(null);
  // branch for IE/Windows ActiveX version
 } else if (window.ActiveXObject) {
  req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
   req.onreadystatechange = processReqChange;
   req.open("GET", url, true);
   req.send();
  }
 }
}
function processReqChange() {
// only if req shows "complete"
 if (req.readyState == 4) {
 // only if "OK"
  if (req.status == 200) {
  // ...processing statements go here...
   response  = req.responseXML.documentElement;
   method    = response.getElementsByTagName('method')[0].firstChild.data;
   result    = response.getElementsByTagName('result')[0].firstChild.data;
   eval(method + '(\'\', result)');
  } else {
   alert("There was a problem retrieving the XML data:\n" + req.statusText);
  }
 }
}

function checkName(input, response) {
if (response != ''){ 
 // Response mode
 message   = document.getElementById('nameCheckFailed');
 message2   = document.getElementById('nameCheckFailed2');
 if (response == 1){
  message.className = 'error';
  message2.className = 'error';
 }else{
  message.className = 'hidden';
  message2.className = 'hidden';
 }
}else{
 // Input mode
 url  = 
  'http://monkeyhomes.com/xml/checkusername.php?q=' + input;
   loadXMLDoc(url);
 }
}

var form='frmSample' //Give the form name here

function SetChecked(val,chkName) {
dml=document.forms[form];
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements[i].name==chkName) {
dml.elements[i].checked=val;
}
}
}

function ValidateForm(dml,chkName){
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1)) return true
}
alert("Please select at least one record to be deleted")
return false;
}


//////////////////////////
///////////////////////////////////////
var req;
function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();
  req.onreadystatechange = processReqChange;
  req.open("GET", url, true);
  req.send(null);
  // branch for IE/Windows ActiveX version
 } else if (window.ActiveXObject) {
  req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
   req.onreadystatechange = processReqChange;
   req.open("GET", url, true);
   req.send();
  }
 }
}
function processReqChange() {
// only if req shows "complete"
 if (req.readyState == 4) {
 // only if "OK"
  if (req.status == 200) {
  // ...processing statements go here...
   response  = req.responseXML.documentElement;
   method    = response.getElementsByTagName('method')[0].firstChild.data;
   result    = response.getElementsByTagName('result')[0].firstChild.data;
   boxval    = response.getElementsByTagName('boxval')[0].firstChild.data;
   eval(method + '(\'\', result,\'\',\'\',boxval)');
  } else {
   alert("There was a problem retrieving the XML data:\n" + req.statusText);
  }
 }
}
function activate(table,response,field,val,boxval,bitfield) {
  temp = 'box'+eval(boxval);
  message = document.getElementById(temp);
if (response != ''){
 // Response mode
 if (response == 1){
  message.src = '/imgs/chk_off.gif';
  message.value = 1;
 }else if (response==0) {
  message.src = '/imgs/chk_on.gif';
  message.value = 0;
 }
}else{
 // Input mode
activeval = message.value;

 url  = 'http://monkeyhomes.com/xml/activate.php?table='+table+'&activeval='+activeval+'&field='+field+'&val='+val+'&boxval='+boxval+'&bitfield='+bitfield;
   loadXMLDoc(url);
 }
}