// JavaScript Document


function pulse() { // keep sessions alive
	setTimeout("pulse()", 60000);
	dopulse = new ajaxObject('../inc/log.php', processResponse, 'pulse');
	dopulse.update();
}


function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}

function blurChrome(){
if(navigator.userAgent.indexOf('Chrome/') > 0)
window.parent.blur();
}

function popup(page,w,h){
  mywindow = window.open(""+page+"","pop","location=1,status=1,scrollbars=1,width="+w+",height="+h+"");
  mywindow.moveTo(0,0);
 } 

// RELOAD FORM PULLDOWN MENU TO CITIES
  
function setcity(source,city) {
	var dropdownIndex = document.getElementById(source).selectedIndex;
	var state = document.getElementById(source)[dropdownIndex].value;
	doSetCity = new ajaxObject('../inc/setcity.php', processResponse, 'city');
	doSetCity.update('state='+state+'&city='+city+'','GET');
	processWait(doSetCity,'city','<img src=\"../gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp;plaatsen laden...');
	}
	
// SHOW TIME

function formatTime() {
  now = new Date();
  hour = now.getHours();
  minutes = now.getMinutes();
  sec = now.getSeconds();
  
    if (minutes <= 9) {
      minutes = "0" + minutes; }
    if (sec <= 9) {
      sec = "0" + sec; }
    if (hour < 10) {
      hour = "0" + hour; }
    document.getElementById('showTime').innerHTML = hour + ':' + minutes + ':' + sec;

  setTimeout("formatTime()", 1000);
}

//window.onload = formatTime;

// DELETE ITEM

function delItem(what,id){
	
var answer = confirm ("U wilt dit item verwijderen?")
if (answer)
window.location = "?action=del"+ what +"&id="+ id +"";

}


// VALIDATE LOGIN
	
	function validatelogin() {
	
var theMessage = "";
var type;
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('name').value)){
theMessage = theMessage + "Gebruikersnaam invullen<br/>";
		}
		
		if(!/\S/.test(document.getElementById('pass').value)){
theMessage = theMessage + "Paswoord invullen<br/>";
		}
		
		if (theMessage == noErrors) {
			doLogin = new ajaxObject('../inc/login.php', processResponse, 'login'); // create request with url
			doLogin.update(document.getElementById('loginform'),'POST'); // start request with object (the form) and type (POST), can be left empty for GET unless there are variables after ?
			processWait(doLogin,'login','<div class=\"wait\"><img src=\"../gfx/wait.gif\" width=\"220\" height=\"19\"><br /><br />... U wordt ingelogd ...</div>'); // show and check while waiting for the form to be processed
	return true;

} else {	
		showError('errorbar',theMessage);		
return false;
}
	}
	
// RESEND LOGIN
	
	function resendloginform() {
	
var theMessage = "";
var type;
var noErrors = theMessage

			doLogin = new ajaxObject('../common.php', processResponse, 'login'); // create request with url
			doLogin.update('form=resendlogin','GET');
			processWait(doLogin,'login','<div class=\"wait\"><img src=\"../gfx/wait.gif\"><br /><br />... formulier wordt geladen ...</div>'); // show and check while waiting for the form to be processed
	}
	
// VALIDATE RESEND
	
	function validateresend() {
	
var theMessage = "";
var type;
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('name').value) && !/\S/.test(document.getElementById('email').value)){
theMessage = theMessage + "Gebruikersnaam of Email invullen<br/>";
		}
		
		
		if (theMessage == noErrors) {
			doLogin = new ajaxObject('../inc/resend.php', processResponse, 'login'); // create request with url
			doLogin.update(document.getElementById('resendloginform'),'POST'); // start request with object (the form) and type (POST), can be left empty for GET unless there are variables after ?
			processWait(doLogin,'login','<div class=\"wait\"><img src=\"../gfx/wait.gif\"><br /><br />... a.u.b. wachten ...</div>'); // show and check while waiting for the form to be processed
	return true;

} else {	
		showError('errorbar',theMessage);	
return false;
}
	}
	
	
// ERROR BAR
	
function showError(id,error){
	showstuff(id);
	document.getElementById(id).innerHTML= error;
}

// HIDE DIV
	
function hidestuff(id) {
	document.getElementById(id).style.display = "none";
	}
	
// SHOW DIV
	
function showstuff(id) {
	document.getElementById(id).style.display = "block";
	}
	
