// Quickwords //

//quickwordArrayStart//
window.quickwordarray = new Array("3fm", "4happyfeet", "9292", "abacus", "abn", "acasa", "adsense", "adwords", "aegee", "ah", "alembic", "alles", "alpha", "analytics", "anime", "arago", "arm", "arriba", "asa", "astatine", "asterion", "atak", "audentis", "autoblog", "autoweek", "babelfish", "bata", "bbpilot", "bernoulli", "bieb", "bier", "blackboard", "bladmuziek", "boek", "boekenbestelsysteem", "bol", "break", "breakdance", "brunger", "buienradar", "cabezota", "campuswiki", "catan", "cbr", "cineast", "cinestar", "cit", "concept", "connexion", "daedalus", "dance", "dc", "debitel", "dhc", "dimensie", "diok", "download", "dumpert", "dweilorkest", "dz", "ebay", "eetlijst", "enschedelink", "ep", "esn", "espacenet", "euros", "facebook", "fct", "fiets", "filemeldingen", "filmtotaal", "fitness", "flabber", "flex", "flickr", "flitsservice", "fok", "foto", "foton", "fzr", "geenstijl", "girotel", "gmail", "goederen", "got", "goudengids", "gratiz", "groente", "harambee", "harambix", "hardboard", "hi", "hotmail", "hth", "htmlhandleiding", "hyves", "iapc", "ib", "imdb", "ing", "inloopuren", "integralen", "inter-actief", "interglot", "io", "iptv", "isaac", "jaggle", "javascript", "jumpforce", "kamernet", "kapper", "keuken", "kick-in", "knmi", "knvb", "kronos", "lannensucks", "lastfm", "ldap", "linearecta", "lotp", "ludica", "mail", "majorminor", "map24", "maps", "marktplaats", "master", "mastermovies", "mathworld", "mb", "me", "messedup", "miniclip", "mobiel", "mycampus", "myspace", "nesecc", "newton", "nieuws", "norderney", "nos", "notebookservice", "nrc", "ns", "nsc", "nu", "ondertitels", "ov", "pandemonium", "paradoks", "picarta", "pineut", "pinkpop", "piranha", "pk", "plattegrond", "portal", "postbank", "postcode", "printer", "provandale", "psy", "psycinfo", "pubmed", "rabobank", "radio", "radiofm", "regenradar", "roosterel", "roosterio", "roostertg", "roostertn", "roostertnb1", "roostertnb2", "roostertnb3", "roostertw", "roosterwb", "route", "rsk", "rtvoost", "samenvatting", "schoolsite", "scintilla", "scopus", "select31", "shop", "shot", "sidn", "simyo", "sirius", "skeuvel", "slagvaardig", "slamfm", "sns", "snt", "software", "solarteam", "spel", "spele", "sport", "ssre", "stores", "stress", "stubiba", "studentunion", "studieboeken", "studielink", "studs", "swing", "sxc", "tast", "taste", "teagames", "telefoongids", "telegraaf", "teletekst", "teletop", "telfort", "testnet", "tg", "thuisbezorgd", "tnw", "toernooi", "torrents", "tost", "tradedoubler", "translate", "tsac", "tubantia", "tvgids", "tweakers", "twente", "twents", "twitter", "ub", "uitzendinggemist", "ut", "utflex", "utnieuws", "utwentemail", "vakgericht", "vandale", "vb", "vcd", "vertalen", "vgst", "vi", "video", "videos", "vist", "vkv", "vodafone", "voetbalzone", "volkskrant", "voorlichting", "vvdrienerlo", "w3schools", "wazig", "wb", "weer", "whap", "wikipedia", "wikipedia-engels", "wk2010", "woordenboek", "wowarmory", "xoun", "youtube", "zwemmen")
//quickwordArrayEnd//

window.quickwords = function(quickword){
	http = false
	for (l = 0; l < quickwordarray.length; l++) {
  	if (quickword==quickwordarray[l]){
    	window.location="quickwordwebsite.php?quickword="+quickwordarray[l]
			http = true
		}
	}
	if (quickword=="help"){
		document.getElementById("quickwordniet").innerHTML  = "<span style=\"position:absolute;top:10px;\">Typ een woord en kom op de site terecht, dat<br> is quickwords!<p>Bv: met het quickword \"ov\" ga je naar de<br> website http://www.9292ov.nl</span>"
  	document.getElementById('quickwordniet2').style.display='block';
		http = true
	}
	if (http==false){
  	document.getElementById("quickwordniet").innerHTML  = "Het quickword \""+quickword+"\" bestaat niet.<br>&nbsp;<br><a href='javascript: quickwordtoevoegenedit(\""+quickword+"\")'>\""+quickword+"\" als quickword toevoegen</a>"
		document.getElementById('quickwordniet2').style.display='block';
		document.quickwords.quickword.value="";
		document.quickwords.quickword.blur();
	}
}

window.quickwordtoevoegen = function(){
	quickwordfound = false
	quickword = document.quickwordtoe.nieuwQuickword.value
	website = document.quickwordtoe.website.value
	divspatie = ""
	divquickword = ""
	divwebsite = ""
	divquickwordfound = ""
	divwebsitefound = ""
	for (l = 0; l < quickwordarray.length; l++) {
  	if (quickword==quickwordarray[l]){
			quickwordfound = true
		}
	}
	if(quickword.match(" ")){
	  divspatie  = "Een quickword mag geen spaties bevatten!<br>"
	}
	if ((!quickwordfound)&&(quickword!="")&&(website!="")&&(website!="http://")&&(divspatie=="")){
  	window.location="quickwordtoevoegen.php?quickword="+quickword+"&website="+website+""
	}else{
	  if (quickword==""){
  		divquickword  = "Er is geen quickword ingevuld!<br>"
		}
	  if ((website=="")||(website=="http://")){
  		divwebsite  = "Er is geen website ingevuld!<br>"
		}
		if (quickwordfound){
  		divquickwordfound  = "Het quickword \""+quickword+"\" is al in gebruik!<br>"
		}
		document.getElementById("quickwordtoeniet").innerHTML = "&nbsp;<br>" + divspatie + divquickword + divquickwordfound + divwebsite 
		document.getElementById('quickwordtoeniet2').style.display='block';
	}
}

window.quickwordtoevoegenedit = function(quickword){
	hide('quickwordstandaard');
	hide('quickwordniet2');
	show('quickwordtoevoegenedit');
	if (quickword)
	  document.quickwordtoe.nieuwQuickword.value = quickword;
	document.quickwordtoe.nieuwQuickword.focus();
	setBlokken();
}

window.quickwordterug = function(){
  show('quickwordstandaard');
  hide('quickwordtoevoegenedit');
	hide('quickwordniet2');
	document.quickwords.quickword.focus();
	setBlokken();
}



window.theOptions = quickwordarray;


window.ignoreCase = true;  //Ignore upper and lower cases
window.matchAnywhere = false; //Match pattern anywhere is string
window.matchTextBoxWidth = true; //False uses CSS value in div.spanTextDropdown
window.theVisibleTime = 0;
window.ShowNoMatchMessage = true;//Show Matching Data Message
window.noMatchingDataMessage = "Geen quickword gevonden";
window.useTimeout = false; //false uses onblur

window.addHandler = function(){
    document.quickwords.quickword.onkeyup = GiveOptions;
  	document.quickwords.quickword.onblur = StartTimeout;
    if(navigator.userAgent.toLowerCase().indexOf("opera") != -1)
  	  document.quickwords.quickword.onkeypress = GiveOptions; //Fix for Opera!
}

window.current_oTextboxvalue = "";

window.regExFlags = "";
if(ignoreCase) window.regExFlags = "i";
  window.regExAny = "";
if(!matchAnywhere) window.regExAny = "^";

window.theTextBox;
window.currentValueSelected = -1;

//Function recieves input from key press on text field
window.GiveOptions = function(e){
	if(useTimeout){
	  if(iAmTiming)
		  EraseTimeout();
		StartTimeout();
	}

  var nbr = 1;

  //Grab key press event
  if(document.all){ //IE
	  nbr = event.keyCode;
    theTextBox = event.srcElement;
	}else{  //Mozilla
	  nbr = e.which;
	  theTextBox = e.target;
	}

	xElem = theTextBox;
	if(theTextBox.value.length == 0){
		HideTheBox();            
		return false;
	}

	if(nbr==13){ //Enter Key
	  GrabHighlighted();
	  xElem.blur();
	  return false;
	}else if(nbr==38){ //Up Arrow
    MoveHighlight(-1);
	  return false;
	}else if(nbr==40){  //Down Arrow
    MoveHighlight(1);
	  return false;
	}//else{}
	
	if(xElem.value.length >= current_oTextboxvalue.length)
    var theText = current_oTextboxvalue//var theText = xElem.value;
	else
	  var theText = xElem.value;

	SetElementPostion(xElem,"divOutput");
	var theMatches = new Array();
	if(theText.length > 0){
	  theMatches = MakeMatches(theText,xElem.name);           //Determine matched array elements
	  theMatches = theMatches.join().replace(/\,/gi,"");  //Turn Array into String
	  document.getElementById("divOutput").innerHTML = theMatches;  //Set the document innerHTML
	  if(theMatches.length>0){
			document.getElementById("divOutput").innerHTML = theMatches;
			document.getElementById("OptionsList_0").className="spanHighElement";  //make first item selected
			currentValueSelected = 0;
		}else{
	    currentValueSelected = -1;  //Remove any selection index
		  if(ShowNoMatchMessage)
			  document.getElementById("divOutput").innerHTML = "<span class='noMatchData'>" + noMatchingDataMessage + "</span>";
			else 
			  HideTheBox();
		}
	}
}

//Variable used to number span element ids
window.countForId = 0;
//Find all of the matches in the string
window.MakeMatches = function(xCompareStr,xElemId){
  countForId = 0;
  var matchArray = new Array()
	var regExp = new RegExp(regExAny + xCompareStr,regExFlags);  //Createregualr expressions
	for(i=0;i<theOptions.length;i++){  //Loop through options
    var theMatch = theOptions[i].match(regExp);  //try to make a match
	  if(theMatch){
	    matchArray[matchArray.length] = CreateUnderline(theOptions[i],xCompareStr,i);  //Call function to make underline/span
	  }
	}
	return matchArray
}

window.iAmTiming = false;
//Sets the position of the div under the text box in focus
window.SetElementPostion = function(xElement,xPosElement){
  if(document.all){ //IE
		var selectedPosX = 1;  //set defaults
		var selectedPosY = 0;
	}else{  //Mozilla
   	var selectedPosX = 1;  //set defaults
		var selectedPosY = -1;
	}
  var theElement = xElement;
	var theElemHeight = theElement.offsetHeight; //Grab textbox width
	var theElemWidth = theElement.offsetWidth; //Grab textbox height
  var coordsTheElement = getPageCoords(theElement);
	selectedPosX += coordsTheElement.x;
	selectedPosY += coordsTheElement.y;
	var coordsTheFrame = getPageCoords(document.getElementById("frame"));
	theFramePosX = coordsTheFrame.x;
	theFramePosY = coordsTheFrame.y;
	/*while(theElement != null){  //Loop through the document tree
    selectedPosX += theElement.offsetLeft;  //Grab new X Position
    selectedPosY += theElement.offsetTop;   //Grab new Y Position
    theElement = theElement.offsetParent;   //Set to next element's parent
  }
	/*var theFrame = document.getElementById("frame");
  while(theFrame != null){  //Loop through the document tree
    theFramePosX += theFrame.offsetLeft;  //Grab new X Position
    theFramePosY += theFrame.offsetTop;   //Grab new Y Position
    theFrame = theFrame.offsetParent;   //Set to next element's parent
  }*/
	//theFramePosX = 200;
	//theFramePosY = 30;

	xPosElement = document.getElementById(xPosElement);  //get element reference
  xPosElement.style.left = selectedPosX - theFramePosX;  //Set X Position
	if(matchTextBoxWidth){
	  if(document.all){ //IE
		  xPosElement.style.width = theElemWidth-2;  //Set Witdh if required
			theElemWidth2 = theElemWidth-6;
			selectSpanStart = "<span style='display:block;width:"+theElemWidth2+";' class='spanNormalElement' onmouseover='SetHighColor(this)' ";
		}else{  //Mozilla
  	  xPosElement.style.width = theElemWidth-2;  //Set Witdh if required
			theElemWidth4 = theElemWidth-6;
			selectSpanStart = "<span style='display:block;width:"+theElemWidth4+";' class='spanNormalElement' onmouseover='SetHighColor(this)' ";
		}
	}
  xPosElement.style.top = selectedPosY + theElemHeight - theFramePosY;  //Set Y position
	xPosElement.style.display = "block";  //Display Block
}

//////////////////////////////////////////////////////////
window.getPageCoords = function(element) {
	var coords = {x: 0, y: 0};
	while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	}
	return coords;
}
///////////////////////////////////////////////////////////


//Variables for create underline
window.undeStart = "<span class='spanMatchText'>";
window.undeEnd = "</span>";

//variables for span elements
window.selectSpanStart = "<span style='display:block;' class='spanNormalElement' onmouseover='SetHighColor(this)' ";
window.selectSpanEnd ="</span>";

//Function makes underline under the text
window.CreateUnderline = function(xStr,xTextMatch,xVal){
  selectSpanMid = "onclick='document.quickwords.submit()' id='OptionsList_" + countForId + "' theArrayNumber='"+ xVal +"'>"; //get click and ids
	var regExp = new RegExp(regExAny + xTextMatch,regExFlags);  //reg expression to match typed text
  var aStart = xStr.search(regExp)  //find start position of the text
  var matchedText = xStr.substring(aStart,aStart + xTextMatch.length);  //grab the matched text (need to keep formatting)
	countForId++;
	return selectSpanStart + selectSpanMid + xStr.replace(regExp,undeStart + matchedText + undeEnd) + selectSpanEnd; //return span elements
}

//function sets the textbox and hidden textbox values
window.SetText = function(xVal){
  theTextBox.value = theOptions[xVal];  //set text value

	document.getElementById("divOutput").style.display = "none";  //hide the options list
	currentValueSelected = -1;  //remove the selected index
}

//Gets value when option is clicked
window.GrabHighlighted = function(){
	if(currentValueSelected != -1){
	  xVal = document.getElementById("OptionsList_" + currentValueSelected).getAttribute("theArrayNumber"); //grab the array index of the value
	  SetText(xVal);  //set value
		document.getElementById("divOutput").style.display = "none"; //hide the options list
	}
}

//Set High color when moused over
window.SetHighColor = function(xElem){
  if(xElem)
	  currentValueSelected = xElem.id.slice(xElem.id.indexOf("_")+1,xElem.id.length); //Determine if returned full id name
	for(i=0;i<countForId;i++){ //loop through all selections
    document.getElementById('OptionsList_' + i).className = 'spanNormalElement'; //reset CSS class
	}
	document.getElementById('OptionsList_' + currentValueSelected).className = 'spanHighElement'; //Add highlight class
	xVal = document.getElementById("OptionsList_" + currentValueSelected).getAttribute("theArrayNumber"); 
	theTextBox.value = theOptions[xVal];  //set text value
	theTextBox.focus()
}

//Handles the up an down arrows for moving highlight color
window.MoveHighlight = function(xDir){
  if(currentValueSelected != -1){  //make sure options exist
  	newValue = parseInt(currentValueSelected) + parseInt(xDir); //Add direction
		if(newValue >-1 && newValue <countForId){  //Make sure it stays within the bounds
		  currentValueSelected = newValue;  //set the selected index
		  SetHighColor();  //set the new CSS class
			xVal = document.getElementById("OptionsList_" + currentValueSelected).getAttribute("theArrayNumber"); 
			theTextBox.value = theOptions[xVal];  //set text value
			theTextBox.focus()
		}
	}
}

window.HideTheBox = function(){
	document.getElementById("divOutput").style.display = "none"; //hide the options list
	currentValueSelected = -1;
	iAmTiming = false;
}

window.EraseTimeout = function(){
  clearTimeout(iAmTiming);
	iAmTiming=false;
}
window.StartTimeout = function(){
	iAmTiming = setTimeout("HideTheBox()",theVisibleTime);
}





// Automatisch aanvullen!!!!!


window.isOpera = navigator.userAgent.indexOf("Opera") > -1; 
window.isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera; 
window.isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera; 

window.textboxSelect = function(oTextbox, iStart, iEnd) { 

   switch(arguments.length) { 
       case 1: 
           oTextbox.select(); 
           break; 

       case 2: 
           iEnd = oTextbox.value.length; 
           /* falls through */ 
            
       case 3:          
           if (isIE) { 
               var oRange = oTextbox.createTextRange(); 
               oRange.moveStart("character", iStart); 
               oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
               oRange.select();                                              
           } else if (isMoz){ 
               oTextbox.setSelectionRange(iStart, iEnd); 
           }                     
   } 

   oTextbox.focus(); 
} 

window.textboxReplaceSelect = function(oTextbox, sText) { 

   if (isIE) { 
       var oRange = document.selection.createRange(); 
       oRange.text = sText; 
       oRange.collapse(true); 
       oRange.select();                                 
   } else if (isMoz) {
       var iStart = oTextbox.selectionStart; 
       oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length); 
       oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length); 
   } 

   oTextbox.focus(); 
} 

window.autocompleteMatch = function(sText, arrValues) { 

   for (var i=0; i < arrValues.length; i++) { 
       if (arrValues[i].indexOf(sText) == 0) { 
           return arrValues[i]; 
       } 
   } 

   return null; 

} 

window.autocomplete2 = function(oTextbox, oEvent, arrValues) { 
	 
	/*if((oEvent.keyCode>=97)&&(oEvent.keyCode<=122)){
	  //textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); 
    var iLen = oTextbox.value.length; 
		var current_oTextboxvalue = oTextbox.value;
    var sMatch = autocompleteMatch(current_oTextboxvalue, arrValues); 

    if (sMatch != null) { 
      oTextbox.value = sMatch; 
      textboxSelect(oTextbox, iLen, oTextbox.value.length); 
    }  
  
		GiveOptions(oEvent, current_oTextboxvalue)

    return false; 
	}else{
	  var current_oTextboxvalue = oTextbox.value;
		GiveOptions(oEvent, current_oTextboxvalue)
		return true; 
	 }*/

   switch (oEvent.keyCode) { 
       case 38: //up arrow  
       case 40: //down arrow 
       case 37: //left arrow 
       case 39: //right arrow 
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock 
       case 8: //backspace  
       case 46: //delete 
           current_oTextboxvalue = oTextbox.value;
					 return true; 
           break; 

       default: 
           textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); 
           var iLen = oTextbox.value.length; 
					 current_oTextboxvalue = oTextbox.value;
           var sMatch = autocompleteMatch(current_oTextboxvalue, arrValues); 
           if (sMatch != null) { 
               oTextbox.value = sMatch; 
               textboxSelect(oTextbox, iLen, oTextbox.value.length); 
           }
					 
           return false; 
   }
} 

