// This functions changes value of input field (id) when link is clicked
function changeValue(id, input) {
    	newValue = document.getElementById(id);
	newValue.value = input;
}







var xmlHttp
var divUpdate
var ClickDoesWhat = 'edit';
var inputFieldToChange

function showResult(str , search_type , divID , clickDoes , changeInputID , keycode){

keycode = keycode || 'x';


divUpdate = divID;
ClickDoesWhat = clickDoes;
inputFieldToChange = changeInputID;

if (str.length == 0) { 
	document.getElementById(divUpdate).innerHTML="";
	//document.getElementById(divUpdate).style.border="0px";
	document.getElementById(divUpdate).style.backgroundColor="#ffffff";
	return
}

if (str.length > 0) {
document.getElementById(divUpdate).style.display="block";
document.getElementById(divUpdate).style.border="1px solid #aaaaaa";
document.getElementById(divUpdate).style.backgroundColor="#ffffff";
}

if (str.length > 2 && keycode == 40){
	//alert('down arrow!');
	//document.getElementById(divID).focus();
	//return
}

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null){
	alert ("Browser does not support HTTP Request")
	return
} 

if (ClickDoesWhat == 'addSocial'){
var url = "/includes/ajax_social_network.php" + "?q="+str+"&search_type=" + search_type +"&div_update="+ divUpdate +  "&click_does="+ ClickDoesWhat + "&click_does_variable="+ inputFieldToChange + "&sid="+Math.random()
} else if (ClickDoesWhat == 'comment_rating'){
var url = "/includes/ajax_comments.php" + "?search_type=" + search_type +"&div_update="+ divUpdate +  "&click_does="+ ClickDoesWhat + "&click_does_variable="+ inputFieldToChange + "&sid="+Math.random()
} else {
var url = "/includes/ajax_search.php" + "?q="+str+"&search_type=" + search_type +"&div_update="+ divUpdate +  "&click_does="+ ClickDoesWhat + "&click_does_variable="+ inputFieldToChange + "&sid="+Math.random()
}

xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}







function edit_leg_office( leg_staff_people_id , district_office_id , leg_staff_title , divID) {
divUpdate = divID;
document.getElementById(divUpdate).innerHTML="";
document.getElementById(divUpdate).style.background = 'none';

//document.getElementById(divUpdate).style.padding = "0.25em";
//document.getElementById(divUpdate).style.backgroundColor="#ff9966";

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/ajax_leg_office_edit.php" + "?leg_staff_people_id=" + leg_staff_people_id +"&district_office_id=" + district_office_id + "&leg_staff_title=" + leg_staff_title + "&divUpdate=" + divID;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}




function leg_staff_add( people_id , district_office_id , leg_staff_title , divID) {

divUpdate = divID;
document.getElementById(divUpdate).innerHTML="";
document.getElementById(divUpdate).style.background = 'none';

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/ajax_leg_office_edit.php" + "?add_people_id=" + people_id +"&district_office_id=" + district_office_id + "&leg_staff_title=" + leg_staff_title + "&divUpdate=" + divID
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}



function social_network( people_id , social_network_id , link , divID) {

divUpdate = divID;
document.getElementById(divUpdate).innerHTML="";
document.getElementById(divUpdate).style.background = 'none';

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/ajax_social_network.php" + "?add_people_id=" + people_id + "&social_network_id=" + social_network_id + "&link=" + link +"&divUpdate=" + divID
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}






function change_div_id(x) {
document.getElementById('leg_staffer_add').id="leg_staffer_" + x;
document.getElementById("change_block_" + x).style.display = 'none';
}



function leg_staff_remove( leg_staff_people_id , district_office_id , leg_staff_title , divID) {
divUpdate = divID;
document.getElementById(divUpdate).innerHTML="";
document.getElementById(divUpdate).style.background = 'none';

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/ajax_leg_office_edit.php" + "?leg_staff_people_id=" + leg_staff_people_id +"&district_office_id=" + district_office_id + "&leg_staff_title=" + leg_staff_title + "&divUpdate=" + divID + "&remove=" + leg_staff_people_id
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}













function rate_story(news_id , news_relevance_value , divID, member_id , viewer) {
divUpdate = divID;

document.getElementById(divUpdate).style.padding = "0.25em";
document.getElementById(divUpdate).style.backgroundColor="#ff9966";

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/ajax_news_rate.php" + "?news_id="+ news_id +"&news_relevance_value="+ news_relevance_value + "&member_id="+ member_id + "&viewer="+ viewer + "&sid="+Math.random()
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}





function people_news_restrict(news_id , people_id , divID, member_id , viewer) {
divUpdate = divID;

document.getElementById(divUpdate).style.padding = "0.25em";
document.getElementById(divUpdate).style.backgroundColor="#ff9966";

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/ajax_people_news_restirict.php" + "?news_id="+ news_id +"&people_id="+ people_id + "&member_id="+ member_id + "&viewer="+ viewer + "&sid="+Math.random()
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}










function replace_div(str , url_to_use, divID)
{

divUpdate = divID;

if (str.length==0)
 { 
 document.getElementById(divUpdate).innerHTML="";
 document.getElementById(divUpdate).style.border="0px";
 return
 }

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null) {
	alert ("Browser does not support HTTP Request")
	return
} 

var url = url_to_use + "?" + str + "&sid="+Math.random();

xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}












// ---------------------------------
// MEMBER CLIENT FUNCTION
function member_client_task( task , client_id , member_id , divID , confirmRequired) {
divUpdate = divID;

var is_confirm = 0;

if(confirmRequired == 0){
	is_confirm = 1;
} else {
var confirm_check = confirm("Are you sure you want to delete this?");
if(confirm_check){
	is_confirm = 1;
} else {
	is_confirm = 0;
}
}

if(is_confirm == 1){
xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "/includes/member_clients_ajax.php" + "?task=" + escape(task) + "&client_id=" +  escape(client_id) + "&member_id="+ escape(member_id) + "&sid="+Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
}
// END Member client tasks
// ---------------------------------




function stateChanged() { 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
    document.getElementById(divUpdate).innerHTML = xmlHttp.responseText;
    //document.getElementById(divUpdate).style.border="1px solid #A5ACB2";
    }

if (xmlHttp.readyState >= 1 && xmlHttp.readyState <= 3) { 
    document.getElementById(divUpdate).innerHTML= '<img src="http://www.totalcapitol.com/dingbats/refresh-animated.gif" height="16 width="16"> &nbsp; Processing ...';
    //document.getElementById(divUpdate).style.border="1px solid #A5ACB2";
    }

}


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;
}