/*ajax processing*/

var request = null;

function ajaxRequest(url,method){	

	request = null;

	if(window.XMLHttpRequest){

		request = new XMLHttpRequest();

	}else if (window.ActiveXObject){

		request = new ActiveXObject("MSXML2.XMLHTTP");

	}

	sendRequest(url,method);

}



function sendRequest(url,method){

	request.onreadystatechange = function(){onResponseReady(method)};

	request.open("POST",url,true);

	request.send(null);

}



function onResponseReady(method){

	if(request.readyState==4){

		if(request.status==200){

			eval(method+'(request)');

			request = null;

		}

	}

}

/*END - ajax processing*/





/*Retrieve Media Links*/

function processMedia()

{

	ajaxRequest("media_links.php","fillMedia");

}



function fillMedia(request)

{

	if(document.getElementById('media_links_content')!=null)

		document.getElementById('media_links_content').innerHTML = request.responseText;

}



function cancelFillMedia()

{

	if(request!=null)

	{

		if(request.readyState!=0){

			request.onreadystatechange = function () {}

			request.abort();

		}

	}

}



function verifySearch()

{

	var s_type_list = document.getElementById('s_type');

	var s_form = document.getElementById('search_form');

	if(s_type_list==null)

		return false;

	if(s_form==null)

		return false;

	var s_type = s_type_list.options[s_type_list.selectedIndex];

	if(s_type.value == "members")

		s_form.action = "/member_search.php";

	else if(s_type.value == "news")

		s_form.action = "/news_search.php";

	else if(s_type.value == "events")

		s_form.action = "/event_search.php";

	else if(s_type.value == "articles")

		s_form.action = "/article_search.php";

	else if(s_type.value == "ejournals")

		s_form.action = "/ejournal_search.php";

	else

		return false;

	return true;

}



function doSearch()

{

	if(verifySearch())

	{

		document.getElementById('search_form').submit();

	}

}





function processMember(member_id)

{

	ajaxRequest("view_unapproved_member_details.php?member_id="+member_id,"fillDetails");

}



function fillDetails(request)

{

	if(document.getElementById('unapproved_member_detail')!=null)

		document.getElementById('unapproved_member_detail').innerHTML = request.responseText;

}







/*USED ON MEMBER REGISTRATION*/

function setMilisName()

{

	var milis_choice_div = document.getElementById('local_milis_choice');

	var local_milis_name = document.getElementById('local_milis_name');

	var city_list = document.getElementById('city_list');

	var selected_city = city_list.options[city_list.selectedIndex];

	var milis_id = selected_city.getAttribute('milis_id');

	var milis = selected_city.getAttribute('milis');

	if(city_list.selectedIndex==0 || milis_id==1)

	{

		milis_choice_div.style.visibility = "hidden";

		document.getElementById("join_ppiuk_milis_yes").checked = false;

		document.getElementById("join_ppiuk_milis_no").checked = true;

	}else{

		local_milis_name.innerHTML = milis;

		milis_choice_div.style.visibility = "visible";

		document.getElementById("join_local_milis_yes").checked = false;

		document.getElementById("join_local_milis_no").checked = false;

		

	}

}



function toggleReuploadBox(obj,id)

{

	var uploadBox = document.getElementById(id);

	if(obj.checked)

		uploadBox.disabled = false;

	else

		uploadBox.disabled = true;

}



function fillMemberList(request)

{

	if(document.getElementById('member_list')!=null)

		document.getElementById('member_list').innerHTML = request.responseText;

}



function pollValidate()

{

	if(document.getElementById('poll_max_choice')!=null)

		var max_choice = document.getElementById('poll_max_choice').value;

	else

		return false;	

	if(document.getElementById('poll_min_choice')!=null)

		var min_choice = document.getElementById('poll_min_choice').value;

	else

		return false;

	

	if(min_choice < 1 || max_choice < 1 || (min_choice > max_choice))

		return false;

	var id_counter = 1;

	var total_choices = 0;

	while(document.getElementById('poll_choice_'+id_counter)!=null)

	{

		var poll_choice = document.getElementById('poll_choice_'+id_counter);

		//alert(poll_choice.checked);

		if(poll_choice.checked)

			total_choices++;

		id_counter++;

	}

	if(total_choices < min_choice)

	{

		alert("Please choose at least "+min_choice+" choices");

		return false;

	}

	else if(total_choices > max_choice)

	{

		alert("Please choose not more than "+max_choice+" choices");

		return false;

	}

	return true;

}

















function testJS(){

	alert("success");

}



