//Firefox 3
is_ff3=(function x(){})[-5]=='x';
//Firefox 2
is_ff2=(function x(){})[-6]=='x';
//IE detector I posted previously
is_ie='\v'=='v';
//Safari
is_safari=/a/.__proto__=='//';
//Chrome
is_chrome=/source/.test((/a/.toString+''));
//Opera
is_opera=/^function \(/.test([].sort);


function SetCookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
function SetCookieHour(cookieName,cookieValue,nHour) {
    var today = new Date();
    var expire = new Date();
    if (nHour==null || nHour==0) nHour=1;
    expire.setTime(today.getTime() + 3600000*nHour);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function isIE () {
	return (navigator.userAgent.indexOf("MSIE")!=-1) ? true : false;
}
function isFF () {
	return (navigator.userAgent.indexOf("Firefox")!=-1) ? true : false;
}

function isdefined( variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function checkContactOblicatory (f, fieldsPrefix) {
	var error = 0;
	var emailerror = 0;


	if(!f[fieldsPrefix+'_tav'][0].checked && !f[fieldsPrefix+'_tav'][1].checked) {
		changeBg (f[fieldsPrefix+'_tav'][0]);
		changeBg (f[fieldsPrefix+'_tav'][1]);
		error = 1;
	} else {
	    changeBgTr (f[fieldsPrefix+'_tav'][0]);
	    changeBgTr (f[fieldsPrefix+'_tav'][1]);
	}

	if(f[fieldsPrefix+'_voornaam'].value == '') {
		changeBg (f[fieldsPrefix+'_voornaam']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_voornaam'])
	if(f[fieldsPrefix+'_achternaam'].value == '') {
		changeBg (f[fieldsPrefix+'_achternaam']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_achternaam'])
	if(f[fieldsPrefix+'_voorletters_1'].value == '') {
		changeBg (f[fieldsPrefix+'_voorletters_1']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_voorletters_1'])



	if(f[fieldsPrefix+'_emailadres'].value == '' || !checkEmailAddress(f[fieldsPrefix+'_emailadres'])) {
		changeBg (f[fieldsPrefix+'_emailadres']);
		emailerror = 1;
	} else changeBgTr (f[fieldsPrefix+'_emailadres'])

	if(f[fieldsPrefix+'_uw_vraag_of_reactie'].value == '') {
		changeBg (f[fieldsPrefix+'_uw_vraag_of_reactie']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_uw_vraag_of_reactie'])


	if(error || emailerror) {
		if(error && emailerror) {
			//alert(al + ' ' +emailal);
		}
		if(error && !emailerror) {
			//alert(al);
		}
		if(!error && emailerror) {
			//alert(emailal);
		}
		return;
	} else {
		f.submit();
	}
}

function checkNewsletterOblicatory(f,action,fieldsPrefix) {

	var error = 0;
	var emailerror = 0;

	if(f.melden[0].checked) {
    	if(f[fieldsPrefix+'_email'].value == '' || !checkEmailAddress(f[fieldsPrefix+'_email'])) {
    		changeBg (f[fieldsPrefix+'_email']);
    		emailerror = 1;
    	} else changeBgTr (f[fieldsPrefix+'_email'])

    	if(f[fieldsPrefix+'_name'].value == '') {
    		changeBg (f[fieldsPrefix+'_name']);
    		error = 1;
    	} else changeBgTr (f[fieldsPrefix+'_name'])

    	if(f[fieldsPrefix+'_surname'].value == '') {
    		changeBg (f[fieldsPrefix+'_surname']);
    		error = 1;
    	} else changeBgTr (f[fieldsPrefix+'_surname'])

    	if(!f[fieldsPrefix+'_sex'][0].checked && !f[fieldsPrefix+'_sex'][1].checked) {
    		changeBg (f[fieldsPrefix+'_sex'][0]);
    		changeBg (f[fieldsPrefix+'_sex'][1]);
    		error = 1;
    	} else {
    	    changeBgTr (f[fieldsPrefix+'_sex'][0]);
    	    changeBgTr (f[fieldsPrefix+'_sex'][1]);
    	}
    }
	if(f.melden[1].checked) {
    	if(f[fieldsPrefix+'_email'].value == '' || !checkEmailAddress(f[fieldsPrefix+'_email'])) {
    		changeBg (f[fieldsPrefix+'_email']);
    		emailerror = 1;
    	} else changeBgTr (f[fieldsPrefix+'_email'])
    }

	if(error || emailerror) {
		if(error && emailerror) {
			//alert(al + ' ' +emailal);
		}
		if(error && !emailerror) {
			//alert(al);
		}
		if(!error && emailerror) {
			//alert(emailal);
		}
		return;
	} else {
	    f.nbaction.value = action
		f.submit();
	}

}

function checkNewsletterForm(f) {
    var anDiv = document.getElementById ('Aanmelden');
    var afDiv = document.getElementById ('Afmelden');
    if(f.melden[0].checked) {
        anDiv.style.display = 'block';
        afDiv.style.display = 'none';
    } else if (f.melden[1].checked) {
        anDiv.style.display = 'none';
        afDiv.style.display = 'block';
    } else {
        anDiv.style.display = 'none';
        afDiv.style.display = 'none';
    }
    if(f.melden[0].checked) {
        anDiv.style.visibility = 'visible';
        afDiv.style.visibility = 'hidden';
    } else if (f.melden[1].checked) {
        anDiv.style.visibility = 'hidden';
        afDiv.style.visibility = 'visible';
    } else {
        anDiv.style.visibility = 'hidden';
        afDiv.style.visibility = 'hidden';
    }

}

function goTo (l) {
	location.href=l;
}

function changeBg (el) {
	el.style.backgroundColor = '#FFD5D5';
}
function changeBgTr (el) {
	el.style.backgroundColor = 'white';
}

function movieWindow(urlImg, title, width, height) {
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);

	var Win = window.open('',"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	Win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+title+'</title></head><body style="background-color:navy" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');

	Win.document.write('<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align=center><table bgcolor="white" style="padding:4px;border:silver 1px solid"><tr><td><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="'+urlImg+'" name="wmp" SHOWCONTROLS="1" SHOWDISPLAY="0" AutoStart="true"></embed></td></tr></table></td></tr></table>');
	Win.document.write('</body></html>');

};


function imageWindow(urlImg, title, width, height) {
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);

	var Win = window.open('',"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	Win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+title+'</title></head><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');

	Win.document.write('<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align=center><table style="padding:4px;border:silver 1px solid"><tr><td><a href="javascript:self.close();"><img src="'+urlImg+'" alt="" border="0"></a></td></tr></table></td></tr></table>');
	Win.document.write('</body></html>');

};

function win(url, title, width, height) {
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);

	var Win = window.open(url,"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );

};

function checkEmailAddress(field) {
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,4}))$)\b/gi);

	if (goodEmail){
	  return true
	} else {
    field.focus()
    field.select()
    return false
  }
}








function updateTips(t){
    if($(".validateTips"))
	   $(".validateTips").text(t).addClass("ui-state-newerror-padding-margin");
}    
function removeTips(){
    if($(".validateTips")){
        $(".validateTips").text('');
        $(".validateTips").removeClass("ui-state-newerror-padding-margin");  
    }
}
function checkLength(o, min, max, text) {
	if(o.val().length > max || o.val().length < min){
		o.addClass( "ui-state-newerror" );
		//updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
		if(text!='')updateTips(text);
		return false;
	}else{
		return true;
	}
}        
function checkRegexp(o, regexp, text){
	if(!(regexp.test( o.val()))){
		o.addClass( "ui-state-newerror" );
		if(text!='')updateTips(text);
		return false;
	}else{
		return true;
	}
}
//regexpEmail=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
regexpEmail=new RegExp(/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/);
regexp_AZ_09=new RegExp(/^([0-9a-zA-Z])+$/);
function checkTheSame(o1, o2,text) {
	if(o1.val()!= o2.val()){
		o1.addClass( "ui-state-newerror" );
		o2.addClass( "ui-state-newerror" );
		if(text!='')updateTips(text);
		return false;
	}else{
		return true;
	}
}
