/**
 * @author Jayster
 */

/**
 * Swaps image so that it looks like animation
 * @param imageName accepts image name
 * @param location is the element that is being changed
 */
function SwapImage(imageName, location) {
 	var pic1 = new Image();
	pic1.src = imageName;
	document.getElementById(location).src = pic1.src;
}
 
function OpenWindow(location) {
 	window.open(location,"prof","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=420,height=400,top=100,left=30");
}
 
function ValidateForm(formType) {
 	switch (formType) {
		case "add":
			if (document.getElementById("articleName").value == "") {
				alert("Please enter an article name.");
				return false;
			}
			else 
				return true;
			break;
		default:
			break;
	}
}
 
function ExternalLinks(){
 	if (!document.getElementsByTagName) 
 		return;
 	var anchors = document.getElementsByTagName("a");
 	for (var i = 0; i < anchors.length; i++) {
 		var anchor = anchors[i];
 		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "nofollow")) 
 			anchor.target = "_blank";
 	}
}
 
function ShowBrowseButton(x) {
	if (x == true) {
		document.getElementById("quickAndDirtyContent").style.display = "none";
		document.getElementById("uploadContent").style.display = "block";
	}
	else {
		document.getElementById("quickAndDirtyContent").style.display = "block";
		document.getElementById("uploadContent").style.display = "none";
	}
}
 
 window.onload = ExternalLinks;
 
 // ***********  AJAX OBJECTS  *******************
// Get the HTTP Object
function getHTTPObject(){
	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
}
 
// Change the value of the outputText field
function setOutput(){
	if(httpObject.readyState == 4){
		document.getElementById('functionContent').innerHTML = httpObject.responseText;
	}
}
 
// Implement business logic
function doWork(theURL){
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", theURL, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutput;
	}
}

var httpObject = null;
// ************  END AJAX OBJECTS ****************

