var i0 = new Image();
var i1 = new Image();
var i2 = new Image();
var i3 = new Image();
i0.src = '/images/tabgoogle.gif';
i1.src = '/images/tabkvk.gif';
i2.src = '/images/tabtelefoongids.gif';
i3.src = '/images/tabgg.gif';

var changeTab = function (el, name) {
	var tabs =  el.parentNode;
	tabs.style.backgroundImage = 'url(/images/tab'+name+'.gif)'
	var p = nodes.parentNodeBy (el, 'name=extern')
	var n = nodes.childNodeBy (p, 'className=' + name, true)
	var google = nodes.childNodeBy (p, 'className=google', true)
	
	if (name!='google') {
		google.style.display = 'none';
	}
	
	if (changeTab.currOn) {
		changeTab.currOn.style.display = 'none';
	}
	
	if (n) {
		n.style.display = 'block';
		changeTab.currOn = n; 
	}
}

var searchGoogle = function (el) {
	var form = nodes.parentNodeBy (el, 'tagName=FORM');
	var type= 'all'
	var zoekterm = form.q.value;
	
	if (zoekterm=='') 
		return false
	
	for (var i=0; i<form.type.length; i++) {
		if(form.type[i].checked) {
			type = form.type[i].value;
			break;
		}
	}

	switch (type) {
		case 'all': 
			form.action = 'http://www.google.com/search';
			break
		
		case 'nl':
			form.hl.value='nl';
			form.meta.value = 'cr=countryNL';
			form.action = 'http://www.google.nl/search';
			break;
		
		case 'site':
			form.q.value = form.q.value + " site:haaksbergen.gemeentekompas.nl"
			form.action = 'http://www.google.com/search';
			break;
	}

	form.submit();
	form.q.value = '';
}

function emailCheck (emailStr) {
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {

return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid


return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {

return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {

return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {

return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {

return false;
}

// If we've gotten this far, everything's valid!
return true;
}

// functions for the admin popup
function changePopupTab (el) {
	var t1 = document.getElementById('beschrijvinginternet');
	var t2 = document.getElementById('beschrijvingfoldertab');
	var ta1 =  document.getElementById('textareainternet');
	var ta2 =  document.getElementById('textareafolder');
	
	var logotab =  document.getElementById('logouploaden');
	var logodiv =  document.getElementById('logodiv');
	var maxText = document.getElementById('maxText');
	
	if (el === t1) {
		t1.className='activetab';
		t1.nextSibling.className = 'activetabright'
		t1.previousSibling.className = 'activetableft'
		
		ta1.style.display = 'block';
		ta2.style.display = 'none';
		logodiv.style.display = 'none';
		maxText.style.display = 'none';
		
		t2.className='inactivetab';
		t2.nextSibling.className = 'inactivetabright'
		t2.previousSibling.className = 'inactivetableft'
		
		logotab.className = 'inactivetab';
		logotab.nextSibling.className = 'inactivetabright'
		logotab.previousSibling.className = 'inactivetableft'
	} 
	
	if(el==t2) {
		t1.className='inactivetab';
		t1.nextSibling.className = 'inactivetabright'
		t1.previousSibling.className = 'inactivetableft2'
		
		t2.className='activetab';
		t2.nextSibling.className = 'activetabright'
		t2.previousSibling.className = 'activetableft'

		ta2.style.display = 'block';
		ta1.style.display = 'none';
		logodiv.style.display = 'none';
		maxText.style.display = 'block';
		
		logotab.className = 'inactivetab';
		logotab.nextSibling.className = 'inactivetabright'
		logotab.previousSibling.className = 'inactivetableft'
	}
	
	
	if (el==logotab) {
		logotab.className = 'activetab';
		logotab.nextSibling.className = 'activetabright'
		logotab.previousSibling.className = 'activetableft'
		
		t1.className='inactivetab';
		t1.nextSibling.className = 'inactivetabright'
		t1.previousSibling.className = 'inactivetableft2'
		
		t2.className='inactivetab';
		t2.nextSibling.className = 'inactivetabright'
		t2.previousSibling.className = 'inactivetableft'
		
		ta2.style.display = 'none';
		ta1.style.display = 'none';
		logodiv.style.display = 'block';
		maxText.style.display = 'none';
	}
	
	
}

function countChar(el, se) {
	var  maxlength = document.getElementById('maxLength');
	if (el.value.length > 256 && (maxlength.checked==true)) {
		alert('U mag maximaal 256 tekens invoeren');
		el.value = el.value.substring(0,256);
		el.focus();
	} else {
		if (se)
			document.form0.submit();
	}
}

function checkGGformulier() {
	if (document.getElementById('ggwat').value == 'product of dienst')
		document.getElementById('ggwat').value = '';
	if (document.getElementById('ggwie').value == 'bedrijfsnaam')
		document.getElementById('ggwie').value = '';
}

