/*--------------------------------------------------------------------
Basic Javascript Sheet - Frontoffice

Version: 2.0
Copyright: 2010, dicode® VOF - understanding internet
W: www.dicode.nl
E: info@dicode.nl
T: 0570-750680
--------------------------------------------------------------------*/

/* Global
--------------------------------------------------------------------*/

/* remove url dotted border */
$(document).ready(function() {

	$('a').bind('focus', function() {
		this.blur();
	});
	
	$('*').ifixpng();
    
    $('.eo').emptyonclick();
   
    $('img.hover').hover(function() {
        s = $(this).attr('src').replace(/\.([^.]+)$/i, '-on.$1');
        $(this).attr('src', s);
    }, function() {
        s = $(this).attr('src').replace(/-on\.([^.]+)$/i, '.$1');
        $(this).attr('src', s);
    });

	$('.popupwindow').each( function(index) {
		$(this).popupwindow({ nofollow : {
			height:768,
			width:1024,
			toolbar:1,
			scrollbars:1,
			status:1,
			resizable:1,
			left:0,
			top:0,
			center:1,
			createnew:0,
			location:1,
			menubar:1
		},
		route : {
			height:768,
			width:640,
			toolbar:0,
			scrollbars:1,
			status:0,
			resizable:0,
			left:0,
			top:0,
			center:1,
			createnew:0,
			location:0,
			menubar:0
		}
		});
	});

});

/**
 * isEmail
 *
 * Checks whether 'item' is a valid email address.
 *
 * @param item	The string to be checked for a valid email address
 */
function isEmail(item) {
	var EmailOk  = true
	var AtSym    = item.indexOf('@')
	var Period   = item.lastIndexOf('.')
	var Space    = item.indexOf(' ')
	var Length   = item.length - 1   // Array is from 0 to length-1
	
	if ((AtSym < 1) ||                   // '@' cannot be in first position
	(Period <= AtSym+1) ||               // Must be atleast one valid char btwn '@' and '.'
	(Period == Length ) ||               // Must be atleast one valid char after '.'
	(Space  != -1))                      // No empty spaces permitted
	{
	  EmailOk = false;
	}
	return EmailOk;
}


function submitNewsletter() {
	
	if( ! isEmail( $('#id_newsletter').val() ) ) {
		alert('U dient een geldig e-mailadres op te geven');
		$('#id_newsletter').focus();
	} else if( $('#id_initials').val() == "" ) {
		alert('U dient een voorletter op te geven');
		$('#id_initials').focus();
	} else if( $('#id_last').val() == "" || $('#id_last').val() == "Vul uw achternaam in" ) {
		alert('U dient een voorletter op te geven');
		$('#id_last').focus();
	} else
		$('#frmnewsletter').submit();
}

var $obj = null;
function checkFrm( $frm, $items) {
	var $list = "";
	
	$.each($items, function($index, $value) {
		if( $($.sprintf('#%s', $index)).val() == "" ) {
			$list += $.sprintf("<li>%s</li>", $value);
			if( ! $obj ) $obj = $($.sprintf('#%s', $index));
		}
	});
	
	if( $list != "" )	
		$.prompt($.sprintf('<h1>Verplichte velden</h1><p>U heeft de volgende verplichte velden niet ingevuld:</p><ul>%s</ul>', $list), {
					callback: function() {
						$obj.focus();
						$obj = null;
					}});
	else {
		if( $('input[name="detail"]', $.sprintf('#%s', $frm)).length )
			$('input[name="detail"]', $.sprintf('#%s', $frm)).val('sal123');
		$($.sprintf('#%s', $frm)).submit();
	}
}

