function doAsyncRequestEx(method, url, data,holder) {
  var httpObj;
  var browser = navigator.appName;
  if(browser.indexOf("Microsoft") > -1)
    httpObj = new ActiveXObject("Microsoft.XMLHTTP");
  else
    httpObj = new XMLHttpRequest();
  httpObj.open(method, url, true);
  httpObj.onreadystatechange = function() {
    if(httpObj.readyState == 4){
       if (httpObj.status == 200 || httpObj.status == 0)
       {
          var contenttype = httpObj.getResponseHeader('Content-Type');
          if (contenttype.indexOf('xml') > -1) {
             //func(httpObj.responseXML);
          } else {
             //func(httpObj.responseText);
			//ensureVisible(true,holder);
            document.getElementById(holder).innerHTML=httpObj.responseText;
          }
       }else{
          //ensureVisible(false,holder);
       }
    }else if(httpObj.readyState == 1 || httpObj.readyState == 2 || httpObj.readyState == 3){
        document.getElementById(holder).innerHTML="<img src=images/indicator_tiny_red.gif border=0/> Please wait...";
    }
  };
  
  if (data.length > 0) {
    httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  }
 httpObj.send(data);
}

function addsurname(memid){
       var divholder=document.getElementById("surname-holder");
       var data=document.getElementById("add-surname").value;
       if(data.length>2){
            var rooturl="http://"+window.location.hostname;
            var url=rooturl+"/universal-ajax-handler.php";
            var newdata="mem_id="+memid+"&section=surname&surnames="+escape(data);
            
            doAsyncRequestEx('POST',url,newdata,'surname-holder');
       }
    }
function lookupancestors(page,memid){
	   if(page==0){
			page=1;
	   }
	   		var lendata=document.getElementById("lookup-data").value;
			lendata=lendata.length;
	   		if(lendata>2){
				var data=document.getElementById("lookup-data").value;
				var rooturl="http://"+window.location.hostname;
				var url=rooturl+"/universal-ajax-tree-handler.php";
				var newdata="section=ancestors&lookup="+escape(data)+'&page='+page+"&memid="+memid;
				
				doAsyncRequestEx('POST',url,newdata,'ancestor-holder');
				document.getElementById("ancestor-holder").style.visibility="visible";
			}
    }
	
function ensureVisible(blnVisible,holder){
    
    if(blnVisible){
        document.getElementById(holder).style.visibility="visible";
    }else{
        document.getElementById(holder).style.visibility="hidden";
    }
}

function doEditSurname(memid,result){
	
	var rooturl="http://"+window.location.hostname;
	var url=rooturl+"/universal-ajax-handler.php";
	var newdata="section=editsurname&mem_id="+memid;
	
	doAsyncRequestEx('POST',url,newdata,result);
}

function doDeleteSurname(memid,surname,result){
	
	var rooturl="http://"+window.location.hostname;
	var url=rooturl+"/universal-ajax-handler.php";
	var newdata="section=deletesurname&surname="+surname+"&mem_id="+memid;
	
	doAsyncRequestEx('POST',url,newdata,result);
}

function doEditCity(memid,result,status){
	var rooturl="http://"+window.location.hostname;
	var url=rooturl+"/universal-ajax-handler.php";
	var newdata="section=editcity&mem_id="+memid+"&status="+status+"&result1="+result;
		
	doAsyncRequestEx('POST',url,newdata,result);
}

function doDeleteCity(memid,entryid,result,table,status){
	var trg_table="";
	if(table=="mc"){
		trg_table="members_clubs"
	}else{
		trg_table="geo_data"
	}
	
	var rooturl="http://"+window.location.hostname;
	var url=rooturl+"/universal-ajax-handler.php";
	var newdata="section=deletecity&entryid="+entryid+"&mem_id="+memid+"&trgtable="+trg_table+"&status="+status+"&result1="+result;
	
	doAsyncRequestEx('POST',url,newdata,result);
}

function doAddSurnameV2(){
    try{
    $("surname-holder").update("<img src='/images/indicator_tiny_red.gif' />")
    $("surname-holder").show()
    
    var url = "http://" + location.hostname + "/ajax_json.php"
    var onComplete = function(resp,json){
        $("surname-holder").update(resp.responseText)
    }
    var params = $H({
        "surname"       :$("add-surname").value,
        "handler"       :"surnames",
        "action"        :"add"
    })
    new Ajax.Request(
        url,
        {
            'method':'post',
            'parameters':params,
            'onSuccess':onComplete
        }
    )
    }catch(e){}
    return false
}
