function handleDivTag(divtag){
   var divtag;
   return divtag;
}

function createRequestObject() {
	var req;
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("There was a problem creating the XMLHttpRequest object");
	}
	return req;
}
////
function special_case(more) {
	http_rr = createRequestObject();
	divhandler_rr = new handleDivTag(null);
	sendRequest_rr(more,"rr_files");
}
var http_rr = createRequestObject();
var divhandler_rr = new handleDivTag(null);
function sendRequest_rr(more,divtag) {
	if (divtag  == "rr_files") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_rr.open("get", "rr_ajax.php?"+more);
		//alert(more);
		http_rr.onreadystatechange = handleResponse_rr;
		divhandler_rr.divtag = divtag;
		http_rr.send(null);
	}
}
function handleResponse_rr() {
	//alert("in handle: "+http_account.status);
	if(http_rr.readyState == 4 && http_rr.status == 200){
		// Text returned FROM PHP script
		var response = http_rr.responseText;
		if(response) document.getElementById(divhandler_rr.divtag).innerHTML = response;
	}
}
///
var http_account = createRequestObject();
var divhandler_account = new handleDivTag(null);

function sendRequest_account(more,divtag) {
	try {
	if (divtag  == "ajax_account") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "manage_profile.php?"+more);
	}
	if (divtag  == "committee_workspace") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "committee_ajax.php?"+more);
	}
	if (divtag  == "invest_workspace") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "committee_ajax.php?"+more);
	}
	if (divtag  == "committee") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "committee_ajax.php?"+more);
	}
	if (divtag  == "output_search") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "profile_search.php?"+more);
	}
	
	if (divtag  == "output_search_result") {
		document.getElementById(divtag).innerHTML = "Searching...";
		http_account.open("get", "search_member_profile.php?"+more);
	}
	if (divtag  == "career_center") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "career_center_ajax.php?"+more);
	}
	if (divtag  == "career_center_public") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "career_center_public_ajax.php?"+more);
	}
	if (divtag  == "pac_in_out") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "pac_in_out_ajax.php?"+more);
	}
	if (divtag  == "member_event") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "member_event_ajax.php?"+more);
	}
	if (divtag  == "rr") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "/rr_ajax.php?"+more);
		//alert(more);
	}
	if (divtag  == "rr_public") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "/rr_ajax_public.php?"+more);
		//alert(more);
	}
	if (divtag  == "rr_files") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "rr_ajax.php?"+more);
		//alert(more);
	}
	if (divtag == "forgot_password") {
		document.getElementById(divtag).innerHTML = "Loading...";
		http_account.open("get", "forgot.php?"+more);
	}
	//alert(divtag);
	http_account.onreadystatechange = handleResponse_account;
	divhandler_account.divtag = divtag;
	http_account.send(null);
	}
	catch(e){
		alert(divtag+" - "+more+"\n"+e);	
	}
}

function handleResponse_account() {
	//alert("in handle: "+http_account.status);
	if(http_account.readyState == 4 && http_account.status == 200){
		// Text returned FROM PHP script
		var response = http_account.responseText;
		if(response) document.getElementById(divhandler_account.divtag).innerHTML = response;
	}
}
//
function delete_user(id) {
	sendRequest_account("action=delete_user&user_id="+id,"ajax_account");
}
function remove_user(id) {
	var agree = confirm("Are you sure?");
	if (agree) sendRequest_account("action=remove_user&user_id="+id,"ajax_account");
}
function delete_blog(id, c_id) {
	sendRequest_account("action=delete_blog&blog_id="+id+"&committee_id="+c_id,"committee_workspace");	
}
function delete_meeting(id, c_id) {
	sendRequest_account("action=delete_meeting&meeting_id="+id+"&committee_id="+c_id,"committee_workspace");
}
function update_meeting(id, c_id) {
	sendRequest_account("action=update_meeting&meeting_id="+id+"&committee_id="+c_id,"committee_workspace");
}
function delete_interaction(id, c_id) {
	sendRequest_account("action=delete_interaction&interaction_id="+id+"&committee_id="+c_id,"committee_workspace");
}
function delete_invest_interaction(id) {
	sendRequest_account("action=delete_investment_interaction&interaction_id="+id,"invest_workspace");
}
function del() {
	var agree = confirm("Are you sure?");
	if (agree) return true;
	else return false;
}
function start_upload() {
	document.getElementById("upload_file").value = "Upload in process ...";
	document.getElementById("upload_file").disabled = true;
	return true;
}

function download_file(file_name, committee_id) {
	if (file_name != "" && committee_id !="") {
		window.location='/download.php?committee_id='+committee_id+'&filename='+file_name;
	}
}
function download_file_rr(rr_file_id, public) {
	if (rr_file_id != "") {
		if (public != 'Yes') {
			window.location='/download_rr.php?rr_file_id='+rr_file_id;
		} else {
			alert("You have to log in"+"\n"+"to download this file...");
		}
	}
}
function delete_file_rr(rr_file_id,rr_id) {
	if (rr_file_id != "") {
		var agree = confirm("Are you sure?");
		if (agree) {
			//return true;
			//sendRequest_rr(,"rr_files");
			special_case("action=rr_file_delete&rr_file_id="+rr_file_id+"&rr_id="+rr_id);
		}
		else {
			return false;
		}
	}
}
function indi_search_get() {
	var more="";
	if (document.getElementById("firm_id").selectedIndex != 0) more = "firm_id="+document.getElementById("firm_id").options[document.getElementById("firm_id").selectedIndex].value;
	/*if (document.getElementById("join").value != "") {
		if (more != "") more +="&";	
			more += "join="+document.getElementById("join").value;
	}
	if (document.getElementById("job").value != "") {
		if (more != "") more +="&";	
			more += "job="+document.getElementById("job").value;
	}*/
	if (more != "") {
		more += "&action=indi_search";
		sendRequest_account(more,"output_search_result");
	}
	else {
		alert("What are you looking for?");
	}
}

function firm_search_get() {
	var form = document.getElementById("firm_search").elements;
	var len = form.length;
	//alert(len);
	var more = "";
	for(var i=0; i<len; i++) {
		var field = document.getElementById("firm_search").elements[i];
		if (field.type == "select-multiple" || field.type == "select-single") {
			var r = new Array();
			for (var k = 0; k < field.options.length; k++) {
				if (field.options[k].selected) {
					if (field.options[k].value != "") r[r.length] = field.options[k].value;
				}
			}
			if (r.length>0) {
				more +=field.name+"="+r+"&";
			}
		}
		else if (field.type != "button") {
			if (field.value != "") {
				more +=field.name+"="+field.value+"&";
			}
		}
	}
	//alert("more:"+more);
	if (more != "") {
		more += "action=firm_search";
		sendRequest_account(more, "output_search_result");
	}
	else {
		alert("What are you trying to search?");	
	}
}

function delete_job(id) {
	sendRequest_account("action=delete&type=job&job_id="+id, "career_center");
}
function delete_resume(id) {
	sendRequest_account("action=delete&type=resume&resume_id="+id, "career_center");
}
function delete_rr(id, more) {
	sendRequest_account("action=rr_delete&rr_id="+id+"&"+more, "rr");
}
function reg_event(id, price, j) {
	var name = "reg_form_"+id;
	var table = "table_"+id;
	var guest = "guest_"+id;
	//alert(document.getElementById(table).checked);//document.getElementById(table).checked == false
	if (price == "0.00" && document.getElementById(guest).value=='1') {
		//do ajax
		//alert(document.getElementById(guest).value);
		if (j=="yes") sendRequest_account("action=rsvp&rsvp=yes&join=yes&event_id="+id,"member_event")
		else sendRequest_account("action=rsvp&rsvp=yes&event_id="+id,"member_event")
	}
	else {
		document.forms[name].submit();	
	}
}
function get_email() {
	var email = document.getElementById("femail").value;
	if (email != "") sendRequest_account("email="+email,"forgot_password")
	else alert("please, enter your email.");
}
function check_type() {
	//validate name, email, password:
	var proceed = false;
	if ((document.getElementById('first_name') && document.getElementById('first_name').value.trim() != "") || (document.getElementById('last_name') && document.getElementById('las_name').value.trim() != ""))  {
		proceed = true;
	}
	if (document.getElementById('email') &&  document.getElementById('email').value.trim() != "" && proceed) proceed = true;
	else proceed = false;
	
	if (document.getElementById('password') &&  document.getElementById('password').value.trim() != "" && proceed) proceed = true;
	else proceed = false;
	//alert(allow);
	if (!proceed) {
		alert("First Name, Last Name, Email and Password shouldn't be empty.");
		return false;	
	}
	if (document.getElementById("contact_status_id")) {
		if (allow == "No") {
			if (status == after_status) return true;
			if (status != "" && status != 1 && after_status == 1) {
				alert("Only 2 Active Contacts allowed.");
				return false;
			}
			if (status != "" && after_status != 1) return true; 
		}
		else {
			return true;	
		}
	}
	else {
		return true;	
	}
}
function get_value(obj) {
	if (status == "") status = obj.value;	
}
function get_after(obj) {
	after_status = obj.value;
}
var status = "";
var after_status = "";
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}