function checkit() {
//$reg_is', '$s_reg_find', '$a_b_fname', '$a_b_mname', '$a_b_lname', '$a_a_fname', '$a_a_mname', '$a_a_lname', '$s_dob', '$s_year', '$s_month', '$s_day', '$a_gender', '$city', '$county', '$hospital', NULL,'$timeofbirth', '$agency', '$bm_fname', '$bm_mname', '$bm_maiden', '$bm_lname', '$bm_dob', '$bm_year', '$bm_month', '$bm_day', '$bm_age', '$bf_fname', '$bf_mname', '$bf_lname', '$bf_dob', '$bf_year', '$bf_month', '$bf_day', '$bf_age', '$additional_info', '$reg_fname', '$reg_lname', '$reg_email', '$reg_password', '$reg_address', '$reg_address2', '$reg_city', '$reg_state', '$reg_zip', '$reg_phone', '$reg_cellphone', '$reg_otherphone','$reg_website','$reg_website2

var reg_fname = document.getElementById("reg_fname").value;
var reg_lname = document.getElementById("reg_lname").value;

var reg_email = document.getElementById("reg_email").value;
var reg_emailc = document.getElementById("reg_emailc").value;
var reg_password = document.getElementById("reg_password").value;
var reg_passwordc = document.getElementById("reg_passwordc").value;

var reg_phone = document.getElementById("reg_phone").value;
var reg_cellphone = document.getElementById("reg_cellphone").value;
var reg_otherphone = document.getElementById("reg_otherphone").value;

 if ((reg_phone=='') && (reg_cellphone=='') && (reg_otherphone=='')) {
    alert ('Please provide at least one phone number.');
    return false;
	}
 if (reg_fname=='') { alert ('Please enter your first name.'); return false; }
 if (reg_lname=='') { alert ('Please enter your last name.'); return false; }
 if (reg_email=='') { alert ('Please enter your email address.'); return false; }
 if (reg_email!=reg_emailc) { alert('Your email address did not match the confirmation box'); return false; }
 if (reg_password=='') { alert ('Please enter a password.'); return false; }
 if (reg_password!=reg_passwordc) { alert('Your password did not match the confirmation box'); return false; }

return true;
}

function checkstate() {
var selectedState = document.getElementById("state").value;
if (selectedState=='') {
alert ('Please select a State.');
return false;
}
else return true;
}

function closemsg(){
document.getElementById("matchmsg").innerHTML = ''
return
}

function relationshipbox(){
document.getElementById("relationshipform").style.display = 'block';
}

/* AJAX */
var xmlHttp
var xmlHttp2

function getCity(str){ 
// function getCity(co,st){ 
    document.getElementById("city").value=''
    document.getElementById("citydiv").innerHTML = ''
var state = null
var county = null
var city = null
state = document.getElementById("state").value
county = document.getElementById("county").value
//if (county=="") document.getElementById("city").value=""
//city = document.getElementById("city").value
//alert (state + " " + county)
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="/getcity.php"
if (county=="") { url=url+"?s="+state+"&co=0&c=0.1" }
else { url=url+"?co="+str+"&c=0&g=" }
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangedCity
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}
function getCounty(str){ 
    var selectedstate = document.getElementById("state").value
    document.getElementById("county").value=''
    //document.getElementById("city").value=''
    //document.getElementById("citydiv").innerHTML = ''
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="/getcity.php"
    url=url+"?s="+selectedstate+"&c="+str+"&co=0"
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangedCounty
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}
function getCounties(){
    document.getElementById("county").value=''
/*
var city = null
city = document.getElementById("city")
if (city!=null)
*/
    document.getElementById("city").value=''
    document.getElementById("citydiv").innerHTML = ''
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="/getcity.php"
    url=url+"?c=all&co=all"
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangedCounty
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function getStateCountiesCities(str){ 
    document.getElementById("county").value=''
    document.getElementById("city").value=''
    //document.getElementById("citydiv").innerHTML = ''
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="/getcity.php"
    url=url+"?s="+str+"&co=0"
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangedCounty
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

    getStateCities(str)
}

function getStateCities(str){
//alert('getstatecities::: ' + str)
    document.getElementById("city").value=''
//document.getElementById("citydiv").innerHTML='123'
    xmlHttp2=GetXmlHttpObject()
    if (xmlHttp2==null) {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="/getcity.php"
    url=url+"?s="+str+"&co=0&g=ci"
    url=url+"&sid="+Math.random()
    xmlHttp2.onreadystatechange=stateChangedCity2
    xmlHttp2.open("GET",url,true)
    xmlHttp2.send(null)
}

function stateChangedCity(){ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
document.getElementById("citydiv").innerHTML=xmlHttp.responseText 
 }
}
function stateChangedCity2(){ 
if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete"){ 
document.getElementById("citydiv").innerHTML=xmlHttp2.responseText 
 }
}
function stateChangedCounty(){ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	if (document.getElementById("county")){
		if (document.getElementById("county").value=='') {
		document.getElementById("countydiv").innerHTML=xmlHttp.responseText 
		}
	}
	else document.getElementById("countydiv").innerHTML=xmlHttp.responseText
 } 
}

function GetXmlHttpObject(){
var xmlHttp=null;
try {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e){
 //Internet Explorer
 try {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e){
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

/* *********** Results highlight **************** */
var highlightbehavior="TR" /* TD */

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if ((source.tagName=="TABLE")||(source.tagName=="TBODY"))
return
while(source.tagName!=highlightbehavior && source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.color!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
} /* backgroundColor */

function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}

function changeback(e,originalcolor){
if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
return
if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
}

function checkit() {
var reg_is = document.getElementById("reg_is").value;
var s_reg_find = document.getElementById("s_reg_find").value;
if ((reg_is=='')||(s_reg_find=='')) {
 if ((reg_is=='') && (s_reg_find=='')) alert ('Please complete the Relationship section.');
 else {
	if (reg_is=='') alert ('Please indicate in the Relationship box who you are.');
	if (s_reg_find=='') alert ('Please indicate in the Relationship box who you are searching for.');
	}
return false;
}
else return true;
}

/* ****** Process Results for Match ******* */
function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

function match(id,matchwith){
var send = "id="+id+"&matchwith="+matchwith
ajaxpack.getAjaxRequest('matchmaker.php',send,processGetPost,'txt');
}

function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
document.getElementById("matchmsg").innerHTML = myajax.responseText
else
document.getElementById("matchmsg").innerHTML = myajax.responseXML
}
}
}

function createpoststring(){
var evalue=document.getElementById("mlogin").regusername.value
var pvalue=document.getElementById("mlogin").regpassword.value
var mvalue=document.getElementById("mlogin").match.value
var poststr = "regusername=" + encodeURI(evalue) + "&regpassword=" + encodeURI(pvalue) + "&match=" + encodeURI(mvalue)
return poststr
}

function mlogin(){
//Step 3: Invoke the Ajax routine method to make the desired Ajax request.
var poststr=createpoststring() //Get contents to post and create query string first
ajaxpack.postAjaxRequest("mlogin.php", poststr, processGetPost, "txt")
}

function loginmatch(){
var poststr=createpoststring();
var success = ajaxpack.postAjaxRequest('mlogin.php', poststr, alertContents, 'xml');
return false;
}

   function alertContents() {
   var http_request=ajaxpack.ajaxobj
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            var xmlDoc = http_request.responseXML;
                        
            if (xmlDoc != '') {
            var uid = xmlDoc.getElementsByTagName('uid')[0].childNodes[0].nodeValue;

				if (uid>0) {
	                if (uid==xmlDoc.getElementsByTagName('mid')[0].childNodes[0].nodeValue) {
                        //alert('The record you clicked, #'+ xmlDoc.getElementsByTagName('mid')[0].childNodes[0].nodeValue + ', is you!');
                        document.getElementById('matchmsg').innerHTML='<div class="success">The record you clicked, #'+ xmlDoc.getElementsByTagName('mid')[0].childNodes[0].nodeValue + ', is you!</div>';
					}
                	else { ajaxpack.getAjaxRequest('matchmaker.php','id='+uid+'&matchwith='+xmlDoc.getElementsByTagName('mid')[0].childNodes[0].nodeValue, processGetPost, 'txt');
	            	//alert('make the match of id='+xmlDoc.getElementsByTagName('uid')[0].childNodes[0].nodeValue+'&matchwith='+xmlDoc.getElementsByTagName('mid')[0].childNodes[0].nodeValue);
               // alert(http_request.responseXML);
               		}
               }
               else {document.getElementById('mloginmsg').innerHTML = "Incorrect email or password.<br/>Please try again or <a href=\"register.htm?match="+ xmlDoc.getElementsByTagName('mid')[0].childNodes[0].nodeValue +"\">click here to Register</a>.<br/>Note: If you registered before Nov 2008, your password is also your email address.";}
            }
            else {alert(http_request.responseText);}
           // result = http_request.responseText;
           // document.getElementById('matchmsg').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
/*
function togglehide(tag) {
if (document.getElementById(tag).style.display != 'block')
    {document.getElementById(tag).style.display = 'none'}
else
    {document.getElementById(tag).style.display = 'block'}
return false;
}
*/
