function checkloginform(frm)
{
 var frmCheck = true;
 if (frm.username.value == ''){
	alert('Vul een gebruikersnaam in');
	frmCheck = false;
 }
 if (frm.password.value == ''){
	alert('Vul een wachtwoord in');
	frmCheck = false;
 } 
 if (frmCheck == true){
	frm.submit();
 }
};
function ShowCharsLeft(form0) {
	
		maxLength = 80;
		if (form0.msg.value.length > maxLength) {
			form0.msg.value = form0.msg.value.substring(0,maxLength)
			charleft = 0
		} else {
			charleft = maxLength - form0.msg.value.length
		}
		form0.charsleft.value = charleft
	
}
function showImageNotFound(objImg)
{
	objImg.src = 'images/garfieldnieuw2.jpg';
}
function showFileNotFound(intWidth, intHeight, objImg)
{
	objImg.width = intWidth;
	objImg.height= intHeight;
	objImg.src = 'images/garfieldthumb.jpg';
}
function showNewImage(value, userid)
{
	if(value.length == 0)
	{
		value =  'images/garfieldnieuw2.jpg';
	}
	var objImg = document.getElementById('userimg');
	objImg.src = 'images/username/' + userid + '/' + value;
}
function checkActForm(frm)
{
	var blnCheck = true;
	var errMsg='';	
	if (isEmpty(frm, 'act_name')){
		blnCheck =false;
		errMsg += 'Naam activiteit is leeg.\n';
	} 
	if (isEmpty(frm, 'act_plaats')){
		blnCheck =false;
		errMsg += 'Plaats activiteit is leeg.\n';
	}
	if (isEmpty(frm, 'reaction')){
		blnCheck =false;
		errMsg += 'Veld omschrijving is leeg.\n';
	}
	var day = frm.elements['act_tijd_day'].value;
	var month = frm.elements['act_tijd_month'].value;
	var year = frm.elements['act_tijd_year'].value;	
	var hour = frm.elements['act_tijd_hour'].value;	
	var minutes = frm.elements['act_tijd_minutes'].value;	
	
	if(! isDate(day,month,year))
	{
		blnCheck =false;
		errMsg += 'Datum activiteit is ongeldig.\n';
	} else {
		if(parseInt(hour, 10) <= 23 && parseInt(hour, 10) >= 0 && parseInt(minutes, 10) <= 59 && parseInt(minutes, 10) >= 0)
		{
			frm.elements['act_tijd'].value = year + '-' + month + '-' + day + ' ' + hour + ':' + minutes;
		} else {
			blnCheck =false;
			errMsg += 'Tijd activiteit is ongeldig.\n';
		}
	}
	day = frm.elements['dtmstart_day'].value;
	month = frm.elements['dtmstart_month'].value;
	year = frm.elements['dtmstart_year'].value;	
	if(! isDate(day,month,year))
	{
		blnCheck =false;
		errMsg += 'Startdatum activiteit is ongeldig.\n';
	} else {
		frm.elements['dtmstart'].value = year + '-' + month + '-' + day;
	}
	if (blnCheck)
	{
		frm.submit();
	} else {
		errMsg='Er zijn fouten gevonden:\n\n' + errMsg;
		alert(errMsg);
	}
}

function checkLogForm(frm)
{
	var blnCheck = true;
	var errMsg='';	
	if (isEmpty(frm, 'log_title')){
		blnCheck =false;
		errMsg += 'Titel is leeg.\n';
	} 	
	if (isEmpty(frm, 'reaction')){
		blnCheck =false;
		errMsg += 'Tekst is leeg.\n';
	}	
	if (blnCheck)
	{
		frm.submit();
	} else {
		errMsg='Er zijn fouten gevonden:\n\n' + errMsg;
		alert(errMsg);
	}
}
function checkUser(frm)
{
	var blnCheck = true;
	var errMsg='';
	if(frm.elements['password1'].value.length > 0)
	{
		if(frm.elements['password1'].value != frm.elements['password2'].value)
		{
			blnCheck =false;
			errMsg += 'Wachtwoord 1 is ongelijk aan wachtwoord 2.\n';
		} else {		
			frm.elements['password'].value = frm.elements['password1'].value;			
		}
	}
	if (isEmpty(frm, 'email')){
		blnCheck =false;
		errMsg += 'Veld email is leeg.\n';
	} else{
		if (!checkMail(frm.elements['email'].value)){
			blnCheck =false;
			errMsg += 'Emailadres is niet geldig.\n';
		}
	}
	if (isEmpty(frm, 'firstname')){
		blnCheck =false;
		errMsg += 'Veld voornaam is leeg.\n';
	}
	if (isEmpty(frm, 'lastname')){
		blnCheck =false;
		errMsg += 'Veld achternaam is leeg.\n';
	}
	var day = frm.elements['dateofbirth_day'].value;
	var month = frm.elements['dateofbirth_month'].value;
	var year = frm.elements['dateofbirth_year'].value;	
	if(! isDate(day,month,year))
	{
		blnCheck =false;
		errMsg += 'Geboortedatum is ongeldig.\n';
	} else {		
		if(year < 1900 || year > 2000)
		{
			blnCheck =false;
			errMsg += 'Geboortedatum is ongeldig.\n';
		}else{			
			frm.elements['dateofbirth'].value=  year + '-' + month + '-' + day;			
		}
	}	
	if (blnCheck)
	{
		frm.submit();
	} else {
		errMsg='Er zijn fouten gevonden:\n\n' + errMsg;
		alert(errMsg);
	}
}
function checkUserAdmin(frm, action)
{
	var blnCheck = true;
	var errMsg='';
	if (isEmpty(frm, 'username')){
		blnCheck =false;
		errMsg += 'Veld gebruikersnaam is leeg.\n';
	}
	if(frm.elements['password1'].value.length > 0)
	{
		if(frm.elements['password1'].value != frm.elements['password2'].value)
		{
			blnCheck =false;
			errMsg += 'Wachtwoord 1 is ongelijk aan wachtwoord 2.\n';
		} else {		
			frm.elements['password'].value = frm.elements['password1'].value;			
		}
	}
	if (isEmpty(frm, 'password')){
		blnCheck =false;
		errMsg += 'Veld wachtwoord is leeg.\n';
	}
	if (isEmpty(frm, 'email')){
		blnCheck =false;
		errMsg += 'Veld email is leeg.\n';
	} else{
		if (!checkMail(frm.elements['email'].value)){
			blnCheck =false;
			errMsg += 'Emailadres is niet geldig.\n';
		}
	}
	if (isEmpty(frm, 'firstname')){
		blnCheck =false;
		errMsg += 'Veld voornaam is leeg.\n';
	}
	if (isEmpty(frm, 'lastname')){
		blnCheck =false;
		errMsg += 'Veld achternaam is leeg.\n';
	}
	var day = frm.elements['dateofbirth_day'].value;
	var month = frm.elements['dateofbirth_month'].value;
	var year = frm.elements['dateofbirth_year'].value;	
	if(! isDate(day,month,year))
	{
		blnCheck =false;
		errMsg += 'Geboortedatum is ongeldig.\n';
	} else {		
		if(year < 1900 || year > 2000)
		{
			blnCheck =false;
			errMsg += 'Geboortedatum is ongeldig.\n';
		}else{			
			frm.elements['dateofbirth'].value=  year + '-' + month + '-' + day;			
		}
	}	
	if (blnCheck)
	{
		frm.action.value = action;
		checkUserName(frm.elements['userid'].value, frm.elements['username'].value);		
	} else {
		errMsg='Er zijn fouten gevonden:\n\n' + errMsg;
		alert(errMsg);
	}
}

function checkUserName(userid, username)
{
	var msgins = new AJAXInteraction('ajax.aspx', getUserCheck);
	msgins.doPost('action=checkusername&userid=' + userid + '&username=' + username);		
}

function getUserCheck(response) {	

	if(response == 'true')
	{
		document.forms['formuser'].submit();		
	}else {
		alert('Gebruikersnaam bestaat al.');
	}; 
}
function checkNewbie(frm, action)
{
	var blnCheck = true;
	var errMsg='';
	if (isEmpty(frm, 'firstname')){
		blnCheck =false;
		errMsg += 'Veld voornaam is leeg.\n';
	}
	if (isEmpty(frm, 'lastname')){
		blnCheck =false;
		errMsg += 'Veld achternaam is leeg.\n';
	}
	
	if (isEmpty(frm, 'email')){
		blnCheck =false;
		errMsg += 'Veld email is leeg.\n';
	} else{
		if (!checkMail(frm.elements['email'].value)){
			blnCheck =false;
			errMsg += 'Emailadres is niet geldig.\n';
		}
	}	
	
	if (blnCheck)
	{	
		frm.action.value = action;
		frm.submit();
	} else {
		errMsg='Er zijn fouten gevonden:\n\n' + errMsg;
		alert(errMsg);
	}
}

function deleteuser(userID)
{
	if (confirm('weet je het zeker?'))
	{
		location.href = 'admin.aspx?action=deleteuser&userid='+ userID;
	}
}

function deletenewbie(ID)
{
	if (confirm('weet je het zeker?'))
	{
		location.href = 'admin.aspx?action=deletenewbie&newbieid='+ ID;
	}
}
function checkMail(strValue)
{
	var email = strValue;
	var blnEmail = false;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		blnEmail = true;
	};
	return blnEmail;
}
function checkNumeric(strValue)
{
	var Numeric = strValue;
	var blnNumeric = false;
	var filter  = /^([0-9])+$/;
	if (filter.test(Numeric)) {
		blnNumeric = true;
	};
	return blnNumeric;
}
function trimspaces(strValue)
{
  strValue = this != window? this : strValue;
  return strValue.replace(/^\s+/g, '').replace(/\s+$/g, '');
};
function isEmpty(frm, variable)
{
	var chkEmpty = false;
	var strTmp = trimspaces(frm.elements[variable].value); 
	if (strTmp == ''){		
		chkEmpty = true;
	};	
	return chkEmpty;
}

function isDate(day,month,year) {
 	var today = new Date();
   
    if (!day) return false;
    if (!month) return false;
    if (!year) return false;

    var test = new Date(year,parseInt(month,10)-1,day);	    
    if ((year == y2k(test.getYear())) && ((parseInt(month,10)-1) == test.getMonth()) && (day == test.getDate()) ){
        return true;
    } else {
        return false;
	};		
};

function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode

if (unicode!=8 && unicode!=9){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}
function chkSMS(name, frm)
{
	var frmCheck = true;
	if(frm.msg.value==''){
		alert('Vul een sms in');
		frmCheck = false;
	 } else {
		if(frm.msg.value== name){
			alert('Pas als je iets te zeggen hebt, mag je een sms versturen.');
			frmCheck = false;
		}
	}
	if (frmCheck == true){
		var msg = frm.msg.value;						
		var msgins = new AJAXInteraction('ajax.aspx', setSMS);
		msgins.doPost('action=messageinsert&msg=' + escape(msg));
		frm.msg.value = name;
	}
}
function setSMS(response) {	

	document.getElementById('marqueemessage').innerHTML = response; 
}
function addSmiley(smileyName)
{
	document.form0.msg.value += " " + smileyName;
	ShowCharsLeft(document.form0)
}


function replaceMe(str, pattern, chg) {

	//var pattern = new RegExp(patstr,'ig');
	return str.replace( pattern, chg);
}

var pos = 1;


function loadAgenda()
{
  var agenda = new AJAXInteraction('ajax.aspx?action=agenda', setAgenda);
  agenda.doGet();
}
function setAgenda(response) {	
	document.getElementById('agenda').innerHTML = response; 
}
function loadMovies()
{
  var film = new AJAXInteraction('ajax.aspx?action=movies', setMovies);
  film.doGet();
}

function setMovies(response) {	
	document.getElementById('movies').innerHTML = response; 
}

function loadQuote(actid, reactid)
{
  var quote = new AJAXInteraction('ajax.aspx?action=quote&actid=' + actid + '&reactid=' + reactid, setQuote);
  quote.doGet();
}

function setQuote(response) {	
	document.getElementById('react_box').innerHTML += response; 
}

function getMessage()
{	
//	initRequest('ajax.aspx?action=message&pos=' + pos ,'marqueemessage');	
//	http.onreadystatechange = handleMessageResponse;
 //   http.send(null);    
  var msg = new AJAXInteraction('ajax.aspx?action=message&pos=' + pos , handleMessageResponse);
  msg.doGet();
}

function handleMessageResponse(response) {  
	document.getElementById('marqueemessage').innerHTML = response;    			
	if(pos >= 10)
	{
		pos = 0;
	}
	pos++;		
	clearTimeout();			
	setTimeout('getMessage()',4000);	
  
}

