var maandLengtes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var base = '';
function getPos(element_id){
	var positions = new Array();
	var element = document.getElementById(element_id);
	if (element != null){
		positions["x"] = element.style.left;
		positions["y"] = element.style.top;
	}
	return positions;
}

function buildDays(dag_id, maand_id, jaar_id){
	var dag_element = document.getElementById(dag_id);
	var maand_element = document.getElementById(maand_id);
	var jaar_element = document.getElementById(jaar_id);
	if (dag_element != null && maand_element != null && jaar_element != null){
		dag = 1;
		if (dag_element.options.length > 0){
			var dag = parseFloat(dag_element.options[dag_element.selectedIndex].value);
		}
		var maand = parseFloat(maand_element.options[maand_element.selectedIndex].value);
		var jaar = parseFloat(jaar_element.options[jaar_element.selectedIndex].value);
		var dagen = maandLengtes[(maand-1)];
		if(maand == 2 && isLeap(jaar)){
			dagen = 29;
		}
		dag_element.options.length = 0;
		var found = false;
		for(i = 1; i <= dagen; i++){
			var option = document.createElement("OPTION");
			var optionText = i;
			if (optionText < 10){
				optionText = "0"+optionText;
			}
			option.text = optionText;
			option.value = i;
			if (i == dag){
				option.selected = true;
				found = true;
			} else if(i == dagen && !found){
				option.selected = true;
			}
			dag_element.options.add(option);
		}
	}
}

function isLeap(jaar){
	if (jaar % 400 == 0){
		return true;
	} else if (jaar % 100 == 0){
		return false;
	} else if (jaar % 4 == 0){
		return true;
	} else {
		return false;
	}
}

function moveTo(elementId, x, y){
	var element = document.getElementById(elementId);
	if(element != null){
		element.style.position = "absolute";
		element.style.left = x;
		element.style.top = y;
	}
}

function isText(string){
	string = string.toLowerCase();
	var l = string.length;
	var allowed = "abcdefghijklmnopqrstuvwxyz";
	var valid = true;
	for(i = 0; i < string.length; i++){
		var letter = string.charAt(i);
		if(!allowed.indexOf(letter)){
			valid = false;
		}
	}
	return valid;
}

function isNumeric(number){
	var string = number+"";
	string = string.toLowerCase();
	var allowed = "0123456789";
	var valid = true;
	for(i = 0; i < string.length; i++){
		var nr = string.charAt(i);
		if(!allowed.indexOf(nr)){
			valid = false;
		}
	}
	return valid;
}

function isPhone(number){
	var string = number+"";
	string = string.toLowerCase();
	string.replace("-", "");
	string.replace(" ", "");
	if(isNumeric(string)){
		
	} else {
		return false;
	}
}

function isLength(string, length){
	if(string.length == length){
		return true;
	} else {
		return false;
	}
}

function isEmpty(string){
	if(string.length == 0){
		return true;
	} else {
		return false;
	}
}

function resizeWindow(w,h){
	window.resizeTo(w,h);
}

function clearText(e){
	if(e.value == 'Zoeken op trefwoord...') {
		e.value = '';
		e.style.fontSize = '9pt'; 
	}
}

function fillEmpty(e){
	if(e.value == ''){
		e.style.fontSize = '8pt';
		e.value = 'Zoeken op trefwoord...';
	}
}

function loadFloatbox(filename) {
	var a = document.getElementById('floatboxLink');
	if(a == null){
		a = document.createElement('a');
		a.setAttribute('class', 'floatbox');
		document.body.appendChild(a);
	}
	var url = base+'/uploadedfiles/'+filename;
	a.setAttribute('href', url);
	
	fb.start(a);
}

function hide(el){
	var e = document.getElementById(el);
	if(e){
		e.style.display='none';
	}
}

var time;

function switchColor(e) {
	if(e) {
		if(e.style.background == '#000000' || e.style.background == '') {
			e.style.background = '#444452';
		}else {
			e.style.background = '#000000';
		}
	}
}

function switchTextinput(e) {
	if(e) {
		if(e.style.border == '#afafaf 1px solid' || e.style.border == '') {
			e.style.border = '#cc0000 1px solid';
		}else {
			e.style.border = '#afafaf 1px solid';
		}
	}
}

function hover(id) {
	var mainleft = document.getElementById('menuitem_left_'+id+'');
	var mainright = document.getElementById('menuitem_right_'+id+'');
	if(mainleft && mainright) {
		mainleft.src = base+'/images/bg_menuitem_left_hover.png';
		mainright.src = base+'/images/bg_menuitem_right_hover.png';
	}
}

function hoverout(id) {
	var mainleft = document.getElementById('menuitem_left_'+id+'');
	var mainright = document.getElementById('menuitem_right_'+id+'');
	if(mainleft && mainright) {
		mainleft.src = base+'/images/bg_menuitem_left.png';
		mainright.src = base+'/images/bg_menuitem_right.png';
	}
}

function clearTextNewsletter(e){
	if(e.value == 'Uw E-mailadres') {
		e.value = '';
	}
}
function fillTextNewsletter(e){
	if(e.value == ''){
		e.value = 'Uw E-mailadres';
	}
}


function switchPasswordInput(e) {
	if(e) {
		if(e.id == 'passwordText') {
			var p = document.getElementById('passwordPassword'); 
			e.style.display = 'none';
			if(p) {
				p.style.display = 'block';
				p.focus();
			}
		}else {
			if(e.value == '') {
				var p = document.getElementById('passwordText');
				e.style.display = 'none';
				p.style.display = 'block';
			}			
		}
	}
}

function switchInput(e) {
	if(e) {
		if(e.value == 'Uw E-mailadres') {
			e.value = '';
		}else {
			if(e.value == '') {
				e.value = 'Uw E-mailadres';
			}
		}
	}
}

var sliderTweets = {};
sliderTweets.moving = false;
function slideTweets() {
	//if(sliderTweets.contr == false) { Geen controls aanwezig		
		setTimeout(function() {
			slideTweetsNext();
			slideTweets();
		}, 4000);
	//}else {
	//	setTimeout(function() {
	//		slideTweets();
	//	}, 4000);
	//}
}

function slideTweetsNext() {
	if(sliderTweets.moving == false) {
		sliderTweets.moving = true;
		var firstpost = $('#listAvTweets').children().first();
		var height = parseFloat(firstpost.height()+10); // 10 == padding
		var clone = firstpost.clone();
		clone.insertAfter($('#listAvTweets').children().last());
		$('#listAvTweets').animate({
			top:-height
		}, 400, 'swing', function() {
			firstpost.remove();
			$(this).css({
				top:0
			});
			sliderTweets.moving = false;
		});
	}
}

function slideTweetsPrev() {
	if(sliderTweets.moving == false) {
		sliderTweets.moving = true;
		var lastpost = $('#listAvTweets').children().last();
		var height = parseFloat(lastpost.height()+10); // 10 == padding
		var clone = lastpost.clone();
		clone.insertBefore($('#listAvTweets').children().first());
		$('#listAvTweets').css({
			top:-height
		});
		$('#listAvTweets').animate({
			top:0
		}, 400, 'swing', function() {
			lastpost.remove();
			sliderTweets.moving = false;
		});
	}
}
