var xmlHttp
var selectedItem
		
function stateChanged() { 
    if (xmlHttp.readyState==4) { 
			 document.getElementById(selectedItem).innerHTML=xmlHttp.responseText;
    }
}
function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
      xmlHttp=new XMLHttpRequest();
    } catch (e) {
      try {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    return xmlHttp;
}

function hideItem(myElement) {
  if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(myElement).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.myElement.display = 'none';
		}
		else { // IE 4
			document.all.myElement.style.display = 'none';
		}
	}
}

function displayItem(myElement) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(myElement).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.myElement.display = 'block';
		}
		else { // IE 4
			document.all.myElement.style.display = 'block';
		}
	}
}


function addContent(spID) {
				 selectedItem="inputFormOutput";
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 if ((document.inputForm.type.value!='f') && (document.inputForm.type.value!='l') && (document.inputForm.type.value!='a')) {
				 		alert ("Please select a valid content type. Refresh this page if you continue to experience difficulties.");
						return;
				 }
				 
				 if ((document.inputForm.url.value.length==0) || (document.inputForm.url.value=="http://")) {
				 		alert ("Please input a valid URL for your new content.");
						document.inputForm.url.focus();
      			document.inputForm.url.select();
						return;
				 }
				 
				 if (document.inputForm.title.value.length==0) {
				 		alert ("Please input a valid title for your new content.");
						document.inputForm.title.focus();
      			document.inputForm.title.select();
						return;
				 }
				 
				 var url="submit/add_remote_content.php";
				 var poststr = "cid=" + encodeURIComponent ( document.inputForm.channel_id[document.inputForm.channel_id.selectedIndex].value );
				 poststr = poststr + "&spid=" + encodeURIComponent ( spID );
				 poststr = poststr + "&type=" + encodeURIComponent ( document.inputForm.type.value );
				 poststr = poststr + "&url=" + encodeURIComponent ( document.inputForm.url.value );
				 poststr = poststr + "&title=" + encodeURIComponent ( document.inputForm.title.value );
				 poststr = poststr + "&category=" + encodeURIComponent ( document.inputForm.category.value );
				 if (document.inputForm.type.value=='l') {
				 		poststr = poststr + "&sub_category=" + encodeURIComponent ( document.inputForm.sub_category.value );
				 }
				 if (document.inputForm.type.value=='a') {
				 	  poststr = poststr + "&aurl=" + encodeURIComponent ( document.inputForm.aurl.value );
				 }
				 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="[...]" title="Adding content..." />';
				 
				 document.inputForm.url.value = "http://";
				 document.inputForm.title.value = "";
				 document.inputForm.category.value = "";
				 if (document.inputForm.type.value=='l') {
				 		document.inputForm.sub_category.value = "";
				 }
				 if (document.inputForm.type.value=='a') {
				 	  document.inputForm.aurl.value = "";
				 }
				 
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open('POST', url, true);
     		 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     		 xmlHttp.setRequestHeader("Content-length", poststr.length);
     		 xmlHttp.setRequestHeader("Connection", "close");
     		 xmlHttp.send(poststr);
}

