function changeep_loadurl(series_id, epNum) {
 
 try {
  
   // Moz supports changeep_xmlhttpRequest. IE uses ActiveX. 
   // browser detction is bad. object detection works for any browser
   changeep_xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
  
 }
 catch (e) {
   // browser doesn't support ajax. handle however you want
 }
 
 // the changeep_xmlhttp object triggers an event everytime the status changes
 // changeep_triggered() function handles the events


 changeep_xmlhttp.onreadystatechange = function() { changeep_triggered(series_id); }
 
 var episode_val = document.getElementById('epID'+series_id);
 var myVal = episode_val.value;
 
 var epNum = (epNum == null) ? myVal : epNum;
 
 actualurl = 'includes/change_ep.php?series_id='+series_id+'&ep_val='+epNum;

 // open takes in the HTTP method and url.
 changeep_xmlhttp.open("GET", actualurl);


 // send the request. if this is a POST request we would have
 // sent post variables: send("name=aleem&gender=male)
 // Moz is fine with just send(); but
 // IE expects a value here, hence we do send(null);
 changeep_xmlhttp.send(null);

 determineEpVisibility(series_id);
 episode_val.value = '';
 return false;
 
}

function updateEpNumByOne(series_id)
{
	var dynamicEpNum = document.getElementById("holdDynamicEpNum"+series_id);
	var dynamicEpNumVal = Number(dynamicEpNum.innerHTML);
	
	changeep_loadurl(series_id,dynamicEpNumVal);
	
	
}


function changeep_triggered(series_id)
{
  // if the readyState code is 4 (Completed)
  // and http status is 200 (OK) we go ahead and get the responseText
  // other readyState codes:
  // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive

  
  if ((changeep_xmlhttp.readyState == 4) && (changeep_xmlhttp.status == 200))
    {
    // changeep_xmlhttp.responseText object contains the response.
    document.getElementById("output"+series_id).innerHTML = changeep_xmlhttp.responseText;
	
	var dynamicEpNum = document.getElementById("holdDynamicEpNum"+series_id);
	dynamicEpNum.innerHTML = Number(changeep_xmlhttp.responseText)+1;
    }

}

function determineEpVisibility(layer_id)
{
    
    var myLayer = document.getElementById('epLayer'+layer_id);
    var visibleVal = (myLayer.style.display != "none");
    var myText = document.getElementById('epText'+layer_id);
    
    
    if (visibleVal)
			{
			//key.innerHTML = "+";
            // hide 
			myLayer.style.display = "none"; 
	 		myText.style.fontWeight = "normal";
			}
		else
			{
			//key.innerHTML = "-";
            //show 
            
			myLayer.style.display = "block";
			myText.style.fontWeight = "bold";
            document.getElementById('epID'+layer_id).focus();
			}
    
}    
