function selectAllU(list)
{
	for (i = 0; i < list.length; i++)
	{
		list.options[i].selected = true;		
	}
}

function addOptionU(list,list_item)
{
	var opt = document.createElement("option");
	opt.text = list_item.value;
	opt.value = list_item.value;
	
	list_item.value = ""
	
	list.options.add(opt);
}

function clearField(field)
{
	field.value = "";	
}


// Universal version of the function
function deleteTasksU(list)
{
	var i;

	for(i=list.options.length-1;i>=0;i--)
	{
		if(list.options[i].selected)
		{
			list.remove(i);
		}
	}
	
}

function editFriends(div_id)
{
	
	
}

function hideDisplay(content_id)
{
	content_id.style.display = content_id.style.display == "none" ? "block" : "none";
}

function addOption(list_name,option_value,clear_field)
{
	var list = document.getElementById(list_name);
	var new_option = document.createElement("option");
		
	new_option.text = option_value;
	new_option.value = option_value;
	
	document.getElementById(clear_field).value = "";
	
	list.options.add(new_option);
}

function addTasks()
{
	var opt = document.createElement("option");
	opt.text = document.getElementById("newTask").value;
	opt.value = document.getElementById("newTask").value;
	
	document.getElementById("newTask").value = ""; // Emptying the value
	
    document.forms.Project.elements['pList[]'].options.add(opt);	
}

function selectAll()
{
	for (i = 0; document.forms.Project.elements['pList[]'].options.length > i; i++)
	{
		document.forms.Project.elements['pList[]'].options[i].selected = true;
	}
}

function deleteTasks()
{
	var i;

	for(i=document.getElementById("pList[]").options.length-1;i>=0;i--)
	{
		if(document.getElementById("pList[]").options[i].selected)
		{
			document.getElementById("pList[]").remove(i);
		}
	}
	
}

function addItemSelectBox(str_value,select_list)
{
	var textInput = document.getElementById(str_value);
	
	var NewOption = document.createElement("option");
	//var SelectList = document.getElementById(select_list);
	
	NewOption.value = textInput.value;
	NewOption.text = textInput.value;
	
	//SelectList.options.add(NewOption);

	select_list.options.add(NewOption);
}

// Remove items from a list of things.
function clearSelectBoxItems(selectbox)
{
	var i;

	for(i=selectbox.options.length-1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}

function SelectType(str_value)
{
   var mod_div = document.getElementById("contentarea");

   var project_div = document.getElementById("ProjectNew");
   var picture_div = document.getElementById("PictureNew");
   var download_div = document.getElementById("DownloadNew");
   var friend_div = document.getElementById("FriendNew");
   var blog_div = document.getElementById("BlogNew");

	switch (str_value)
	{
		case "Project":
			project_div.style.display = 'block';
			picture_div.style.display = 'none';
			download_div.style.display = 'none';
			friend_div.style.display = 'none';
			blog_div.style.display = 'none';
		break;
		
		case "Blog":
			project_div.style.display = 'none';
			picture_div.style.display = 'none';
			download_div.style.display = 'none';
			friend_div.style.display = 'none';
			blog_div.style.display = 'block';
		break;
		
		case "Friend":
			project_div.style.display = 'none';
			picture_div.style.display = 'none';
			download_div.style.display = 'none';
			friend_div.style.display = 'block';
			blog_div.style.display = 'none';
		break;
		
		case "Picture":
			project_div.style.display = 'none';
			picture_div.style.display = 'block';
			download_div.style.display = 'none';
			friend_div.style.display = 'none';
			blog_div.style.display = 'none';
		break;
		
		case "Download":
			project_div.style.display = 'none';
			picture_div.style.display = 'none';
			download_div.style.display = 'block';
			friend_div.style.display = 'none';
			blog_div.style.display = 'none';
		break;
	}

}

// Simple JavaScript that toggles two different items that are placed into the argument

function ToggleTwo(elementOne, elementTwo)
{
	var EditDiv = document.getElementById(elementOne);
	var NewDiv = document.getElementById(elementTwo);
	
	EditDiv = EditDiv.style.display == "none" ? "block" : "none";
	NewDiv = EditDiv.style.display == "block" ? "none" : "block";
}

// Used for the photo script on the website.

function ResizeImage(imageId)
{
	var image = document.getElementById(imageId);
	
	if (image.width > 440)
	{
		image.width = 440;	
	}
}

// Comment Form Counting
function CountLetters(value)
{
	var color = "green";
	
	var letterCount = value.length;
	
	if (letterCount < 300)
	{
		color = "green";
		document.getElementById("SubmitComment").disabled = false;
	}
	else
	{
		letterCount = "300+";
		color = "red";
		
		document.getElementById("SubmitComment").disabled = true;
	}
	
	document.getElementById("countletters").innerHTML = "<span class=\"text\" style=\"color:" + color + "; font-family: verdana; font-size: 14px; font-weight: bold;\">" + letterCount + "</span>";

}

function ColourBackground(tableId)
{
	var column = document.getElementById(tableId);
	
	
	column = column.style.backgroundColor == "white" ? "#e3e3e3" : "white";

}

// For pinging websites in the download section
function CheckConnection(divID,mirror,download)
{
	
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp2=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp2.onreadystatechange=function()
  {
  
  if (xmlhttp2.readyState==1)
  {
  	document.getElementById(divID).innerHTML = "<img src=\"searching.gif\" border=\"0\" />";
  }

	
  if (xmlhttp2.readyState==4 && xmlhttp2.status==200 || xmlhttp2.readyState == "complete")
    {
	//alert(xmlhttp.responseText);
    document.getElementById(divID).innerHTML = xmlhttp2.responseText;
	//alert("ReadyState:" + xmlhttp.readyState + " Status:"+xmlhttp.status + " Response text: " + xmlhttp.responseText);
    }
	
  }

xmlhttp2.open("GET","http://lucshelton.com/checkcon.php?id=" + download + "&m=" + mirror,true);
xmlhttp2.send();
}

// Boot up the twitter script
function LoadTwitter()
{
		
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	
	
	
	xmlhttp.onreadystatechange=function()
	  {
	  
	  if (xmlhttp.readyState==1)
	  {
		document.getElementById("TwitterDiv").innerHTML="<img src=\"searching.gif\" />";
	  }
	
		
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		//alert(xmlhttp.responseText);
		document.getElementById("TwitterDiv").innerHTML=xmlhttp.responseText;
		//alert("ReadyState:" + xmlhttp.readyState + " Status:"+xmlhttp.status + " Response text: " + xmlhttp.responseText);
		}
		
	  }
	
	xmlhttp.open("GET","http://lucshelton.com/twitter_back.php",true);
	xmlhttp.send();	
}
