// collapse script
var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

/*if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}*/

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate



////////////////
// AJAX FUNCTIES
//////////

//Step 2: Define a "callback" function to process the data returned by the Ajax request:
function processGetPost(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200){ //if request was successful or running script locally
			if (myfiletype=="txt"){
				// hier spuugt ie de uitput uit (txt)
				document.getElementById(replaceDiv).innerHTML=myajax.responseText;
				//opacity('showHide', 0, 100, 500);
			} else {
				// hier spuugt ie de uitput uit (txt)
				document.getElementById(replaceDiv).innerHTML=myajax.responseXML;
				//opacity('showHide', 0, 100, 500);
			}
		}
	}
}

// SUGGEST eigen XMLHTTP Request
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}

// START suggest

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();

function searchSuggest() {
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		var str = escape(document.getElementById('txtSearch').value);
		if(str.length>0&&str!=' '){
			searchReq.open("GET", 'getSuggest.php?search=' + str, true);
			searchReq.onreadystatechange = handleSearchSuggest; 
			searchReq.send(null);
		}
	}		
}
//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';
		var str = searchReq.responseText.split("\n");
		for(i=0; i < str.length - 1; i++) {
			//Build our element string.  This is cleaner using the DOM, but
			//IE doesn't support dynamically added attributes.
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			ss.innerHTML += suggest;
		}
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}

//Click function
function setSearch(value) {
	document.getElementById('txtSearch').value = value;
	document.getElementById('search_suggest').innerHTML = '';
}
// END suggest




//Step 2: Define a "callback" function to process the data returned by the Ajax request:
function createFotoVars(album, pagina){
	var album=album //document.getElementById("relatives").innerHTML //get value to post from a DIV
	var pagina=pagina //document.getElementById("relatives").innerHTML //get value to post from a DIV
	//var agevalue=document.getElementById("myform").agefield.value //get value to post from a form field
	var poststr = "album=" + encodeURI(album) + "&pagina=" + encodeURI(pagina);
	return poststr
}

//Step 3: Invoke the Ajax routine method to make the desired Ajax request.
function newLokatie(replaceThis){
	if((lokatie=prompt("Geef een nieuwe (nog niet bestaande!) plaatsnaam op"))){
		var poststr="newLokatie="+lokatie+"&divName="+replaceThis; //Get contents to post and create query string first
		//alert(poststr);
		replaceDiv=replaceThis;
		ajaxpack.postAjaxRequest("/admin/getLokaties.php", poststr, processGetPost, "txt")
	} else {
		//alert('toevoegen lokatie ge-annuleerd');
	}
}
function newCatLink(tmpBedrijf, idTempBedrijf, tmpCat, replaceThis){
	//alert("cat="+tmpCat+", bedrijf="+tmpBedrijf);
	var poststr="idBedrijf="+tmpBedrijf+"&idCategorie="+tmpCat+"&idTempBedrijf="+idTempBedrijf; //Get contents to post and create query string first
	replaceDiv=replaceThis;
	ajaxpack.postAjaxRequest("getCategories.php", poststr, processGetPost, "txt")
}
function delCatLink(tmpBedrijf, idTempBedrijf, tmpCat, replaceThis){
	//alert("cat="+tmpCat+", bedrijf="+tmpBedrijf);
	var poststr="idBedrijf="+tmpBedrijf+"&idCategorie="+tmpCat+"&idTempBedrijf="+idTempBedrijf+"&delMe=1"; //Get contents to post and create query string first
	replaceDiv=replaceThis;
	ajaxpack.postAjaxRequest("getCategories.php", poststr, processGetPost, "txt")
}

function load() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  }
}

function checkForm(formname) {
	naam=			formname.contactpersoon.value;
	data=			formname.cp_data.value;
	bedrijfsnaam=	formname.bedrijfsnaam.value;
	email=			formname.email.value;
	plaats=			formname.plaatsnaam.value;

	if(naam!=""&&data!=""&&bedrijsnaam!=""&&email!=""&&plaats!=""){
		return true;
	} else {
		alert("Contactpersoon-data, bedrijfsnaam, plaats en email-adres zijn noodzakelijke velden.\n\nZonder deze velden kunnen wij geen inzendingen accepteren.")
		return false;
	}
}

/// protect mail from harvest
function mailscript(host,user,title){
	url="mailto:"+user+"@"+host;
	//alert(url);
	window.location.href=url;
}


// prevent ENTER and TAB in form
function BrowserType () {
      var srchText = navigator.userAgent;
      var brwTypes = ("Opera,MSIE,Netscape,Firefox").split(',');
      for (var ix=0; ix < brwTypes.length; ix++) {
            if (srchText.toString().match(brwTypes[ix])) {
                  return brwTypes[ix];
            }
      }
      return null;
}
var brwType = BrowserType();
function doAction (evt) {
      return false;

      if (evt) {
            evt.returnValue = false;
            evt.cancelBubble = true;
      }
      else {
            alert ('Bad Event Object');
      }
}

function kH(e) {
      evt = (e) ? e : window.event;
      var type = evt.type;
      var pK = e ? e.which : window.event.keyCode;
      if (pK == 9) { pK = 13; evt.keyCode = 13; }
      if (pK == 13) {
             doAction (evt);
             return false;
      }
      if (pK == 9 || pK == 0) {
            doAction (evt);
            return  false;
      }
}

function DisableEnterAndTab ()
{
      if (!brwType) { return; }
      if (brwType == 'MSIE') {
            document.onkeypress = kH;
            document.onkeydown = kH;
      }
      else if (brwType == 'Firefox') {
            document.onkeypress = kH;
      }
      else if (brwType == 'Netscape') {
            document.onkeypress = kH;
            if (document.captureEvents) {
            document.captureEvents (Event.KEYPRESS);
            }
      }
      else {
            alert ('UnSupported Browswer');
      }
}
DisableEnterAndTab();