function listVideos(url,clause){
	object = document.getElementById('videoAdd');
	object.innerHTML = '<b>Loading...</b>';

	if(clause == 'true'){
	     var mid = 'movie_category_'; 
		 var start = url.indexOf('=');
		
		 mid +=url.substring(start+1);
		 var nodeObj = document.getElementById(mid);
		 nodeObj.style.color = 'red';
	}
 
	if (url && url.length){        
        if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
       if(clause == 'false') http_request.onreadystatechange = fillVideo;
	   if(clause == 'true') http_request.onreadystatechange = fillVideo2;
		http_request.open('GET', url, true);
        http_request.send(null);
    }
}

function showVideo(url){
	//alert("showVideo("+url+")")
	object = document.getElementById('videoDescription');
	object.innerHTML = '<b>Loading...</b>';

	if (url && url.length && url!="<b>You hav"){        
			if (window.XMLHttpRequest) {
				http_request = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			http_request.onreadystatechange = fillDescription;
			http_request.open('GET', url, true);
			http_request.send(null);
	}else{
		object.innerHTML = '<b>Select a movie from a category to the left!</b>';
		}
}

function focusInput(input)
{
	input.style.color='#aaaaaa';	
	input.style.background='#333333';
}

function blurInput(input)
{
	input.style.color='#363a3d';
	input.style.background='#777777';
}


function fillVideo() 
{
   if (http_request.readyState == 4) 
   {
	   if (http_request.status == 200) 
	   {            
            object = document.getElementById('videoAdd');
            value = 0;            
            object.innerHTML = http_request.responseText;
			object.style.height = "500px;";
			object.style.overflow = "auto";
				
	   } 
	   else 
	   {		   
		   alert('There was a problem with the request.');
	   }
   }
}

function fillVideo2() 
{
   if (http_request.readyState == 4) 
   {
	   if (http_request.status == 200) 
	   {            
            object = document.getElementById('videoAdd');
            //value = 0;            
			object.innerHTML = http_request.responseText;
			//object.style.height = "500px;";
			//object.style.overflow = "auto";
	        var mid = ' '; 
			mid +=getURLParam("movieid");
			//alert("mid="+mid+", http_request.responseText="+http_request.responseText+".");
			var start =http_request.responseText.indexOf('showVideo(');
			var end;
			var url ;
			if(mid == ' '){ 
				end = http_request.responseText.indexOf(')',start);
				url = http_request.responseText.substring(start+11,end-1);
			}
			if(mid != ' ') {
				end = http_request.responseText.indexOf('=',start);
				url = http_request.responseText.substring(start+11,end+1);
				url +=mid;
			}
			showVideo(url);
	   } 
	   else 
	   {		   
		   alert('There was a problem with the request.');
	   }
   }
}

function fillDescription() 
{
   if (http_request.readyState == 4) 
   {
	   if (http_request.status == 200) 
	   {            
            object = document.getElementById('videoDescription');
            value = 0;            
            object.innerHTML = http_request.responseText;
			//alert(http_request.responseText);
	   } 
	   else 
	   {		   
		   alert('There was a problem with the request.');
	   }
   }
}

function getURLParam(strParamName){
      var strReturn = "";
      var strHref = window.location.href;
      if ( strHref.indexOf("?") > -1 ){
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
          if (
    aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
            var aParam = aQueryString[iParam].split("=");
            strReturn = aParam[1];
            break;
          }
        }
      }
      return unescape(strReturn);
    } 

