function hideIt(elem){
	document.getElementById(elem).style.display = 'none';
}

function showIt(elem){
    document.getElementById(elem).style.display = 'block';
}

function flipIt(elem){
	var current=document.getElementById(elem).style.display;
	if(current=="none"){
		showIt(elem);
	}else{
		hideIt(elem);
	}
}

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

//This function will lookup any highlighted text as a definition under the google website.
var text = "";
var fValue = "";
function getActiveText(e) { 
	text = (document.all) ? document.selection.createRange().text : document.getSelection();
	if(fValue == ""){
		if(text.length > 3 && text.length < 20){
			var answer = confirm('Would you like to define or lookup: '+text+'?');
			if(answer){
				text=text.trim();
				var ipPattern = new RegExp(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
				if(!ipPattern.test(text)){
					var link = 'http://www.google.com/search?hl=en&lr=&q=define%3A';
					myRef2 = window.open(link+text,'','right=50,top=50,width=640,height=480,toolbar=0,resizable=1');
				}else{
					var link = 'http://www.ip2location.com/free.asp?ipaddresses=';
					myRef2 = window.open(link+text,'','right=50,top=50,width=800,height=480,toolbar=0,resizable=1');
				}
			}
		}
	}
	return true;
}

//this script sets focus so that we don't use the lookup word feature
function fieldFocus(way) {
	if(way == "focus"){
		fValue = "focused";
	}
	if(way == "blur"){
		fValue = "";
	}
}

//output all elements and forms in a page
function formOut() {
	var theForm = document.forms[0];
	for(i=0; i<theForm.elements.length; i++){
		var alertText = ""
		alertText += "Form Name: " + theForm.name + "\n"
		alertText += "Element Type: " + theForm.elements[i].type + "\n"
		alertText += "Element Name: " + theForm.elements[i].name + "\n"
		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "button" || theForm.elements[i].type == "hidden"){
			alertText += "Element Value: " + theForm.elements[i].value + "\n"
		}
		else if(theForm.elements[i].type == "checkbox"){
			alertText += "Element Checked? " + theForm.elements[i].checked + "\n"
		}
		else if(theForm.elements[i].type == "select-one"){
			alertText += "Selected Option's Text: " + theForm.elements[i].options[theForm.elements[i].selectedIndex].text + "\n"
		}
		alert(alertText)
	}
}

//functions for drag n drop list
var itemInfo="";
function startDrag(info) {
	window.event.dataTransfer.setData("Text", info);
	window.event.dataTransfer.effectAllowed = "copy";
}

function drop(out,elem,opt) {
	window.event.returnValue = false;                           
	window.event.dataTransfer.dropEffect = "copy";              
	addValue(window.event.dataTransfer.getData("Text"),out,elem,opt);
}

function showDragCursor() {
	window.event.returnValue = false;
	window.event.dataTransfer.dropEffect = "copy";
}

