// JavaScript Document
var arBg=new Array();
arBg[1]='static/img/Subaru-Benelux-Subarunlbelu.jpg';
arBg[2]='static/img/VEB-Dag-van-de-Belegger.jpg';
arBg[3]='static/img/zka.jpg';
arBg[4]='static/img/Genzyme-PlexaflorApp.jpg';
arBg[5]='static/img/RTLZ-Decennium-Gala.jpg';
arBg[6]='static/img/Store-IT-Store-ITEU.jpg';
arBg[7]='static/img/JENG-TheJengOnescom.jpg';
arBg[8]='static/img/Zilveren-Kruis-Achmea-Fitter.jpg';
arBg[9]='static/img/KiesJeToekomst-KiesJeToekomstTV.jpg';
arBg[10]='static/img/jfk.jpg';

var theWindow       = $(window),
	current			= 1,
	activeBg		= 1,
	aspectRatio     = 1.77777777778;

function resizeBg() {
		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
			$(".bg"+activeBg)
				.removeClass()
				.addClass('bgheight');
		} else {
			$(".bg"+activeBg)
				.removeClass()
				.addClass('bgwidth');
		}										
}								

$(function() {  
	changeBg(current); 
	theWindow.resize(function() {
			resizeBg();
	}).trigger("resize");
	current++;
});

$(document).ready(function(){
      setInterval('nextBg()', 7000);
    });

function nextBg() {
	changeBg(current);
	current++;
	if (current>10) {current=1;}	
}

function chosenBg(nr) {
	current = nr+1;
	changeBg(nr);
}

function changeBg(nr) {
	$('.sel').removeClass('sel');
	$('.b'+nr).addClass('sel');
	$('<img id="bg" class="bg'+activeBg+'" />')
		.attr('src', arBg[nr])
		.load(function(){
			$('body').append( $(this) );
			resizeBg();
			activeBg++;
		}).fadeTo('slow', 1, function() {
			if (activeBg>2) {
				$('img').remove('.bg'+(activeBg-2));
				}
			});
	
}

var d = window.document;
var field = new Array(2);
field[0] = '';
field[1] = '';
field[2] = '';
function setFocus() {
	d.getElementById('0').focus(); 
	d.getElementById('0').select(); 
}
function clearField(fieldName) {
	if (field[fieldName] == '') {
		field[fieldName] = d.getElementById(fieldName).value;
		d.getElementById(fieldName).value = '';
	}
}
function defValue(fieldName) {
	if (d.getElementById(fieldName).value == '') {
		d.getElementById(fieldName).value = d.getElementById(fieldName).defaultValue;
		field[fieldName] = '';	
	}
}
function selectText(nr) {
	var i = d.getElementById(nr);
	if (i.value == i.defaultValue) 
	{ i.select(); }	
} 
function checkField(nr) {
	var n = d.getElementById(nr);
	if (n.value == "" || n.value == n.defaultValue) 
	{ 
		if (nr != 2 && nr != 3)
		{ d.getElementById(nr).className = "red"; }
	}
	else 
	{ d.getElementById(nr).className = "green"; }
}
function checkEmail() {
	var e = d.getElementById("1").value;
	if (e != "" && e != "Uw e-mailadres") { 
		if (echeck(e)==false) 
		{ d.getElementById("1").className = "red"; }
		else 
		{ d.getElementById("1").className = "green"; }
	}
}

function check() {
	var terug = 0;
	var n = d.getElementById("0").value; 
	if (n == "" || n == "Uw naam") 
	{ d.getElementById("0").className = "red"; terug = 1; }
	else 
	{ d.getElementById("0").className = "green"; }
	
	var e = d.getElementById("1").value;
	var t = d.getElementById("2").value; 
	if ((e == "" || e == "Uw e-mailadres" || echeck(e) == false) && (t == "" || t == "Uw telefoonnummer")) 
	{ d.getElementById("error").style.display = "block"; terug = 1; }
	else
	{ d.getElementById("error").style.display = "none"; }
	
	if (e != "" && e != "Uw e-mailadres") { 
		if (echeck(e)==false) 
		{ d.getElementById("1").className = "red"; }
		else { d.getElementById("1").className = "green"; }
	}
	
	if (t != "" && t != "Uw telefoonnummer")
	{ d.getElementById("2").className = "green"; }
	
	if (terug == 1)
	{ return; }

	d.form1.submit();	
}




function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}

