var xmlhttp;

function setExtraFields() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	el=document.getElementById('tdTypeID');
	x=response.getElementsByTagName("types");
	el.innerHTML = x[0].firstChild.data;
	el=document.getElementById('rowType');
	el.style.display='block';

	x=response.getElementsByTagName("resolutions");
	txt = x[0].firstChild.data;
	if (txt != "hide")
	{
		el=document.getElementById('tdResolutionID');
		el.innerHTML = txt;
		el=document.getElementById('rowRes');
		el.style.display='block';
	}

	x=response.getElementsByTagName("color");
	txt = x[0].firstChild.data;
	if (txt != "hide")
	{
		el=document.getElementById('rowColor');
		el.style.display='block';
	}

	x=response.getElementsByTagName("bitrate");
	txt = x[0].firstChild.data;
	if (txt != "hide")
	{
		el.innerHTML = txt;
		el=document.getElementById('rowBitrate');
		el.style.display='block';
	}

  }
}


function getExtraFields(pID) {

	el=document.getElementById('rowRes');
	el.style.display='none';
	el=document.getElementById('rowColor');
	el.style.display='none';
	el=document.getElementById('rowBitrate');
	el.style.display='none';
	el=document.getElementById('rowType');
	el.style.display='none';

	url = "index.php?n=Files&o=get_extra_fields&id=" + pID;

	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest();
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=setExtraFields;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
}


function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
      return true;
    }
    else
    {
      alert("Problem retrieving XML data");
    }
  }
}

function loadProjects(pID) {

//	el=document.getElementById('rowType');
//	el.style.display='none';

	url = "index.php?n=Ajax&o=getProjects&id=" + pID;

	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest();
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=updateProjects;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
}

function updateProjects (){
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	x=response.getElementsByTagName("Options");
	txt = x[0].firstChild.data;
	arr = txt.split("||");
//	alert(arr.length);
	el=document.getElementById('ProjectID');
	for (i=el.length; i>	0 ; i-- )
	{
		el.remove(i-1);
	}
	for (i=0; i<arr.length; i++)
	{
		fld = arr[i].split("^^^");
		option = document.createElement('option');
		option.text = fld[1];
		option.value = fld[0];
		try
		{
			el.options.add(option, null);	
		}
		catch (e)
		{
			el.options.add(option);
		}
		

	}

//	el.
//	alert(el.options);
//	el.innerHTML = "<select>txt</s";
  }
}

function addCommunity() {
	el=document.getElementById('CommunityID');
	el3=document.getElementById('Selected');
	option = document.createElement('option');
	option.text = el.options[el.selectedIndex].text;
	option.value = el.options[el.selectedIndex].value;
		try
		{
			el3.options.add(option, null);	
			el.options.remove(el.selectedIndex);
		}
		catch (e)
		{
			el3.options.add(option);
			el.options.remove(el.selectedIndex);
		}
}

function remCommunity() {
	el3=document.getElementById('Selected');
	option = document.createElement('option');
	option.text = el3.options[el3.selectedIndex].text;
	option.value = el3.options[el3.selectedIndex].value;

	try
	{
		el3.options.remove(el3.selectedIndex);	
		el3.selectedIndex = 0;

		try
		{
			el.options.add(option, null);	
		}
		catch (e2)
		{
			el.options.add(option);
		}

	}
	catch (e)
	{
		;
	}
}

function addRight() {
	el=document.getElementById('SectionID');
	el3=document.getElementById('Selected2');
	option = document.createElement('option');
	option.text = el.options[el.selectedIndex].text;
	option.value = el.options[el.selectedIndex].value;
		try
		{
			el3.options.add(option, null);	
			el.options.remove(el.selectedIndex);
		}
		catch (e)
		{
			el3.options.add(option);
			el.options.remove(el.selectedIndex);
		}
}

function remRight() {
	el=document.getElementById('SectionID');
	el3=document.getElementById('Selected2');
	option = document.createElement('option');
	option.text = el3.options[el3.selectedIndex].text;
	option.value = el3.options[el3.selectedIndex].value;

	try
	{
		el3.options.remove(el3.selectedIndex);	
		el3.selectedIndex = 0;

		try
		{
			el.options.add(option, null);	
		}
		catch (e2)
		{
			el.options.add(option);
		}

	}
	catch (e)
	{
		;
	}
}


function selectAll(elem) {
	el3=document.getElementById(elem);
	for (i=0; i<el3.options.length;i++ )
	{
		el3.options[i].selected = true;
	}
}
