/*
/------------------------------------------------------\
|                    Medley V1.0                       |
|                                                      |
|   Feel free to copy, use and change this script as   |
|   long as this part remains unchanged.               |
|                                                      |
|   If you have any questions and or comments please   |
|   Author:  Ajay Lulia
|   E-mail me 'ajaylulia@hotmail.com'.                 |
|   Please check out my webpage http://www.lulia.com   |
|                                                      |
|              Last Updated: 17 July 2003              |
\------------------------------------------------------/
*/

var num_SortList = 1;  // Sorts the Left list as and when it is changed, 1=Sort


function ShiftOption(SelectInstance, ShiftTo, This)
{
   var SelectedNo = SelectInstance.selectedIndex;
   if (ShiftTo == -1)
   {
      if (SelectedNo <= 0)
      {
         SelectInstance.focus();
         return 
      }
   }
   else
   {
      if ((SelectedNo + ShiftTo) == SelectInstance.length)
      {
         SelectInstance.focus();
         return 
      }
   }
   var SelectedValue = SelectInstance.options[SelectedNo].value;
   var SelectedText = SelectInstance.options[SelectedNo].text;
   if ((! SelectedValue) ||  ((SelectedNo + ShiftTo)== SelectInstance.length)) {
      return 
   }

   var AboveValue = SelectInstance.options[SelectedNo + ShiftTo].value;
   var AboveText = SelectInstance.options[SelectedNo + ShiftTo].text;

   SelectInstance.options[(SelectInstance.selectedIndex + ShiftTo)].text = SelectedText;
   SelectInstance.options[(SelectInstance.selectedIndex + ShiftTo)].value = SelectedValue;

   SelectInstance.options[SelectInstance.selectedIndex].text = AboveText;
   SelectInstance.options[SelectInstance.selectedIndex].value = AboveValue;

   SelectInstance.options[SelectedNo + ShiftTo].selected = true;
   SelectInstance.options[SelectedNo].selected = false;
}

function MoveOptions(SourceList, TargetList, obj_Button)
{
   var SelectLength  = SourceList.length;
   var ButtonName    = obj_Button.name;
   var SelectedValue = "";
   var SelectedText  = "";
   var ListDetails = new Array();
   var ArrayCounter = 0;
   var SelectedIndex = SourceList.selectedIndex;

   for(Counter = 0; Counter < SelectLength; Counter++)
   {
      if ((ButtonName == "MoveRight") || (ButtonName == "MoveLeft"))
      {
         if (! SourceList.options[Counter].selected == true)
         {
            continue;
         }
      }
      ListDetails[ArrayCounter] = new Array(3);
      ListDetails[ArrayCounter][0] = SourceList.options[Counter].text;
      ListDetails[ArrayCounter][1] = SourceList.options[Counter].value;
      ListDetails[ArrayCounter][2] = Counter;
      ArrayCounter++;
   }

   if (ListDetails.length == 0)
   {
      alert("Selecteer eerst een item.");
      SourceList.focus();
      return false;
   }

   var SourceCounter = 0;
   for (Counter = 0; Counter < ListDetails.length; Counter++)
   {
      TargetList.options[TargetList.length] = new Option(ListDetails[Counter][0]);
      TargetList.options[TargetList.length - 1].value =  ListDetails[Counter][1];
   
      SelectLength = SourceList.length;
      for (SourceCounter = 0; SourceCounter < SelectLength; SourceCounter++)
      {
         if (SourceList.options[SourceCounter].text == ListDetails[Counter][0])
         {
            SourceList.options[SourceCounter] = null;
            break;
         }
      }
   }

   if (SourceList.length > 0)
   {
      if (SourceList.length > SelectedIndex)
         SourceList.options[SelectedIndex].selected = true;
      else
         SourceList.options[SourceList.length - 1].selected = true;
   }

   if(document.forms[0].LeftList == TargetList)
      SortLeftList(document.forms[0].LeftList);

   if (document.forms[0].RightList.options.length == 0)
   {
      document.forms[0].MoveLeft.disabled     = true;
      document.forms[0].MoveRight.disabled    = false;
   }
   else if(document.forms[0].LeftList.options.length == 0)
   {
      document.forms[0].MoveLeft.disabled     = false;
      document.forms[0].MoveRight.disabled    = true;
   }
   else if(document.forms[0].RightList.options.length == "5")
   {
      document.forms[0].MoveLeft.disabled     = false;
      document.forms[0].MoveRight.disabled    = true;
   }
   else
   {;
      document.forms[0].MoveLeft.disabled     = false;
      document.forms[0].MoveRight.disabled    = false;
   }
}

function AddToList(SourceList, TargetList, obj_Button)
{
   var SelectLength  = SourceList.length;
   var ButtonName    = obj_Button.name;
   var SelectedValue = "";
   var SelectedText  = "";
   var ListDetails = new Array();
   var ArrayCounter = 0;
   var SelectedIndex = SourceList.selectedIndex;

   for(Counter = 0; Counter < SelectLength; Counter++)
   {
      if ((ButtonName == "MoveRight") || (ButtonName == "MoveLeft"))
      {
         if (! SourceList.options[Counter].selected == true)
         {
            continue;
         }
      }
      ListDetails[ArrayCounter] = new Array(3);
      ListDetails[ArrayCounter][0] = SourceList.options[Counter].text;
      ListDetails[ArrayCounter][1] = SourceList.options[Counter].value;
      ListDetails[ArrayCounter][2] = Counter;
      ArrayCounter++;
   }

   if (ListDetails.length == 0)
   {
      alert("Selecteer eerst een item.");
      SourceList.focus();
      return false;
   }

   var SourceCounter = 0;
   for (Counter = 0; Counter < ListDetails.length; Counter++)
   {
      TargetList.options[TargetList.length] = new Option(ListDetails[Counter][0]);
      TargetList.options[TargetList.length - 1].value =  ListDetails[Counter][1];
   }
}

function RemoveFromList(SourceList)
{
   SourceList.options[SourceList.selectedIndex] = null;
}

function SortLeftList(SelectInstance)
{
   if (num_SortList == 0)
   {
	   return 
   }
   var TotalNos = SelectInstance.length;
   arr_LeftList = new Array(TotalNos - 1);

   for(Counter = 0; Counter < TotalNos; Counter++)
   {
      arr_LeftList[Counter] = new Array(2);
      arr_LeftList[Counter][0] = SelectInstance.options[Counter].text;
      arr_LeftList[Counter][1] = SelectInstance.options[Counter].value;
   }
   arr_LeftList.sort();
   for(Counter = 0; Counter < TotalNos; Counter++)
   {
      SelectInstance.options[Counter] = new Option(arr_LeftList[Counter][0]);
      SelectInstance.options[Counter].value =  arr_LeftList[Counter][1];
   }
}

function CheckFormValues(whichField) {
	if (document.getElementById("woonplaats").value=='' || document.getElementById("leeftijd").value=='') {
		alert("Gelieve tenminste de velden 'Woonplaats' en 'Leeftijd' in te vullen, bedankt!");
		return false;
	} else {
		if (document.getElementById(whichField).length!=5) {
			alert("Je top 5 is nog niet compleet!");
			return false;
		} else {
			var RightListLength = document.getElementById(whichField).length;
			var CounterB;
			for (CounterB = 0; CounterB < RightListLength; CounterB++) {
				document.getElementById(whichField).options[CounterB].selected = true;
			}
			return true;
		}
	}
}

function FinishWizard(howmuch)
{
   if (CheckFormValues(howmuch))
   {
      //document.forms[0].action = FormAction;
      document.forms[0].submit();
   } else {
      return false;
   }
}


function requestListContent(type,filterText) {
	var URL = "nieuws_bulletin_lijst.php?type="+type+"&filterText="+filterText;
 	var request = false;
	if (window.ActiveXObject) { 
		try { 
			request = new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch (e) {
			try { 
				request = new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch (e){}
		} 
	} else {
		request = new XMLHttpRequest(); 
	}
	request.open("GET", URL, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var serverResponse = request.responseText;
			document.getElementById('berichtenLijst').innerHTML = serverResponse;
		}
	}
	request.send('');
			
}
