// JavaScript Document
	//validate the group form input, make sure some fields should be required
// this is shared by groups, network, profile, inbox
	function v_group_form()
	{
		var project_form = document.getElementById("create_group");
		var project_form_inputs = project_form.getElementsByTagName("input");
        var radioChoose = false;
		if(document.getElementById("group_name").value == '')
		{
			alert("The group_name is required.");
			document.getElementById("group_name").focus();
			return false;
		}else if(document.getElementById("group_name").value.length > 45)
		{
			alert("The group_name should not be more than 45 characters.");
			document.getElementById("group_name").focus();
			return false;
		}
		if(document.getElementById("group_summary").value == '')
		{
			alert("The group_summary is required.");
			document.getElementById("group_summary").focus();
			return false;
		}else if(document.getElementById("group_summary").value.length > 75)
		{
			alert("The group_summary should not be more than 75 characters.");
			document.getElementById("group_name").focus();
			return false;
		}
		if(document.getElementById("group_website").value.length > 150)
		{
			alert("The group_website should not be more than 150 characters.");
            document.getElementById("group_website").focus();
			return false;
		}
		if(document.getElementById("group_detail").value.length > 255)
		{
			alert("The group_summary should not be more than 255 characters.");
			document.getElementById("group_summary").focus();
			return false;
		}

	   for(var i=0; i<project_form_inputs.length; i++)
		{
			if( project_form_inputs[i].type == "radio" )
			{
				if(project_form_inputs[i].checked == true)
				{
					radioChoose = true;
				}
			}
		}
		if(radioChoose == false)
		{
		alert("Please choose who can participate in this project");
		document.getElementById('par_error_anchor').focus();
		return false;
		}
		if(document.getElementById("agreement").checked == false)
		{
		   alert("The group_agreement is required");
		   document.getElementById('agreement').focus();
		   return false;
		}
}

	//validate the discus form input, make sure topic and description should be required
    function v_discus_form()
	{

		if(document.getElementById("disc_topic").value == '')
		{
			alert("The disc_topic is required.");
			document.getElementById("disc_topic").focus();
			return false;
		}else if(document.getElementById("disc_topic").value.length > 75)
		{
			alert("The disc_topic should not be more than 75 characters.");
			document.getElementById("disc_topic").focus();
			return false;
		}
		if(document.getElementById("disc_desc").value.length > 255)
		{
			alert("The disc_desc should not be more than 255 characters.");
            document.getElementById("disc_desc").focus();
			return false;
		}
}

//validate the discus_comments form input, make sure comment should be required
    function v_discus_comments_form()
	{

		if(document.getElementById("editor").value == '')
		{
			alert("The comment is required.");
			document.getElementById("editor").focus();
			return false;
		}
}

//ajax read debate info
function read_group( postdata,stype)
{
    var postData = postdata;
	//var postData = "index=0&stype=recent";
	var stype = stype;
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/network/read_groups.php', callback, postData);
}

function read_msg(postdata,stype)
{

    var postData = postdata;
	//var postData = "index=0&stype=recent";
   //alert('postdata:' + postData);
	var Ex = YAHOO.namespace('example');
	var handleSuccess = function(o){
//alert(o.responseText);
		var rText = o.responseText.split("<!");
			debates1 = new Array();
			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}
			Ex.content1.innerHTML = '<p>'+debates1.join('</p><p>')+'</p>';
		}
	var handleFailure = function(o){
		alert("Error: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/network/inbox_msg.php?X=1&act='+stype, callback, postData);
}

//ajax get a list of my connections
function read_connections(postdata,stype)
{
    var postData = postdata;
	var stype = stype;
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/network/x_connections.php', callback, postData);
}

//ajax get a list of xxx's connections
function read_user_connections(postdata,stype,usr)
{
    var postData = postdata;
	//var postData = "index=0&stype=recent";
	var stype = stype;
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
//alert(o.responseText);
		var rText = o.responseText.split("<!");
			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/network/view_profile.php?act=connections&stype=connections&acct='+usr + '&x=1', callback, postData);
}

function read_responses( postdata,stype)
{
    var postData = postdata;
	//var postData = "index=0&stype=recent";
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/network/x_connections.php', callback, postData);
}

function read_invitations( postdata,stype)
{
    var postData = postdata;
	//var postData = "index=0&stype=recent";
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/network/x_connections.php', callback, postData);
}
	
//ajax read discussions from group discussions
	
function read_group_discus(group_id,postdata,stype)
{
	var postData = postdata;
	//var postData = "index=0&stype=recent";
//alert('1');
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
//alert(o.responseText);
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
      var request = YAHOO.util.Connect.asyncRequest('POST', '/network/group_discuss.php?X=1&gid=' + group_id, callback, postData);
}

//ajax read discussions from help discussions
function read_help_discus(postdata,stype)
{
	var postData = postdata;
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
//alert(o.responseText);
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
      var request = YAHOO.util.Connect.asyncRequest('POST', '/help/help_discuss.php?X=1', callback, postData);
}

function read_group_members(group_id,postdata,stype)
{
	var postData = postdata;
	//var postData = "index=0&stype=recent";
//alert('1');
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
//alert(o.responseText);
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
      var request = YAHOO.util.Connect.asyncRequest('POST', '/network/group_member.php?X=1&gid=' + group_id, callback, postData);
}

function read_profile( postdata,stype)
{
	var postData = postdata;
	//var postData = "index=0&stype=recent";
	var stype = stype;
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
      var request = YAHOO.util.Connect.asyncRequest('POST', '/network/read_profile.php', callback, postData);
}
	//ajax read debate info from match profile
function read_match_profile( postdata,stype)
{
	var postData = postdata;
	//var postData = "index=0&stype=recent";
	var stype = stype;
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
      var request = YAHOO.util.Connect.asyncRequest('POST', '/network/read_match_profile.php', callback, postData);
}
	
function read_natwork_analysis( postdata,stype)
{
	var postData = postdata;
	//var postData = "index=0&stype=recent";
	var stype = stype;
	//alert(stype);
	var Ex = YAHOO.namespace('example');

	var handleSuccess = function(o){
		//do some things
		var rText = o.responseText.split("<!");

			debates1 = new Array();

			for(i=0; i<rText.length; i++)
			{
				if(rText[i])
				{
					debates1.push(rText[i]);
				}
			}

			Ex.content1.innerHTML = '<li><p>'+debates1.join('</p></li><li><p>')+'</p></li>';
		}

	var handleFailure = function(o){
		alert("Submission failed: " + o.status);
	}

	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
      var request = YAHOO.util.Connect.asyncRequest('POST', '/network/read_analysis_members.php', callback, postData);
}
	