// variable forms check
function varformcheck(id)
{
	
	var args = eval('check_' + id);
	var errorMessage = 'De gemarkeerde velden zijn verplicht om in te vullen.';
	var ret = new Array();
	
	for (i=0; i<(args.length); i++)
	{
		var inputfld = $(':input[name=' + args[i] + ']',$('form#' + id));
		var inputval = $(inputfld).val();
		
		// checkboxes
		if( $('input:checkbox',$('fieldset#' + args[i],$('form#' + id))).length ){
			if( $('input:checkbox:checked',$('fieldset#' + args[i],$('form#' + id))).length )
			{
				// goed
				$('fieldset#' + args[i],$('form#' + id)).removeClass('invalid');
			} 
			else 
			{
				// fout
				$('fieldset#' + args[i],$('form#' + id)).addClass('invalid');
				ret[ret.length] = 0;
			}
		}
		
		// other inputs
		if( inputfld.length )
		{
			if( inputval == '' )
			{
				// fout
				$(inputfld).addClass('invalid');
				ret[ret.length] = 0;
			}
			else
			{
			
				// email en valid?
				if(	
					strpos(args[i],'validemail') !== false
					 && 
					(
					strpos(inputval,'@') === false
					 || 
					strpos(inputval,'.') === false
					)
				){
					// fout
					errorMessage = 'Er moet een geldig email adres worden ingevuld.';
					$(inputfld).addClass('invalid');
					ret[ret.length] = 0;
				}
				
				// goed
				$(inputfld).removeClass('invalid');
				
			}
		}
		
	}
			
	if(ret.length > 0)
	{
		$('.form_error_report',$('form#' + id)).html(errorMessage).addClass('red');
		return false;
	}
	else
	{
		return true;
	}
}

function strpos( haystack, needle, offset){
    // Finds position of first occurrence of a string within another  
    // 
    // version: 905.1314
    // discuss at: http://phpjs.org/functions/<b style="color:black;background-color:#a0ffff">strpos</b>
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // *     example 1: <b style="color:black;background-color:#a0ffff">strpos</b>('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

function strstr(haystack,needle,bool) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    var pos = 0;

    haystack += '';
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}
