// 2.4 FUNCTIONALITEIT

function setImgClass(){	
	$('#content img').each(function(index) {
		if($(this).css('float') == "left"){
			$(this).addClass('img_left');
		}
		if($(this).css('float') == "right"){
			$(this).addClass('img_right');
		}
	});
}

$(document).ready ( function(){
	
	setImgClass();
	
});


$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li span").click(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});



// OUD - 2.3 - MAAR WELLICHT NOG WEL GEBRUIKT VANAF HIER

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
	//alert(func);
}


function showHideDiv(which)
{
	document.getElementById(which).style.display = (document.getElementById(which).style.display == "block") ? "none" : "block";
}



function checkEmpty(formname,fields){
	empty=false;
	flds=fields.split(",");
	//alert(velden);
	for(i=0; i<flds.length; i++){
		//alert(flds[i]);
		if(document[formname][flds[i]].value==""){
			alert('U bent vergeten het veld ' + flds[i] + ' vergeten in te vullen of aan te vinken');
			empty=true;
			document[formname][flds[i]].focus();
			break;
		}
		
	}
}

addLoadEvent(function(){ attachFormHandlers(); });

function attachFormHandlers()
{
  // Ensure we're working with a 'relatively' standards 
  // compliant browser
  if (document.getElementsByTagName)
  {
    var objForm = document.getElementsByTagName('form');

    for (var iCounter=0; iCounter<objForm.length; iCounter++)
		objForm[iCounter].onsubmit = function(){return checkForm(this);}
		
  }
}
function checkForm(objForm)
{
  var arClass, bValid;
  var objField = objForm.getElementsByTagName('*');

  for (var iFieldCounter=0; iFieldCounter<objField.length; iFieldCounter++)
  {	
  	// Allow for multiple values being assigned to the class attribute
    arClass = objField[iFieldCounter].className.split(' ');
    for (var iClassCounter=0; iClassCounter<arClass.length; iClassCounter++)
    {
      switch (arClass[iClassCounter])
      {
        case 'string':
           bValid = isString(objField[iFieldCounter].value.replace(/^\s*|\s*$/g, ''));
		   break;
        case 'number' :
           bValid = isNumber(objField[iFieldCounter].value);
           break;
        case 'stringornumber' :
           bValid = isStringOrNumber(objField[iFieldCounter].value);
           break;
        case 'email' :
           bValid = isEmail(objField[iFieldCounter].value);
           break;
        case 'wantone' :
           bValid = checkChecks(objField[iFieldCounter].name);
           break;
        default:
           bValid = true;
      }

      if (bValid == false)
      {
        // If this field is invalid, leave the testing early,
        // and alert the visitor to this error
        if(objField[iFieldCounter].getAttribute('alt')!=undefined){
			alert(objField[iFieldCounter].getAttribute('alt'));
		}else{
			alert('Er lijkt geen goede waarde ingevuld te zijn in het veld ' + objField[iFieldCounter].name );
		}
        if(objField[iFieldCounter].getAttribute('type') == "text"){ //menno: afrolmenu's enzo proberen te selecten breekt het script!
        	objField[iFieldCounter].select();
		}
        objField[iFieldCounter].focus();
        return false;
      }
    }
  }
  return true;
}

function checkChecks(name) {
	var x=document.getElementsByName(name);
    for (i=0; i < x.length; i++) {
		if (x[i].checked) {
			return true;
		}
	}
	return false;
}

function isString(strValue)
{
  return (typeof strValue == 'string' && strValue != '' && isNaN(strValue));
}

function isStringOrNumber(strValue)
{
  return ((typeof strValue == 'string' && strValue != '' && isNaN(strValue)) || (!isNaN(strValue) && strValue != ''));
}

function isNumber(strValue)
{
  return (!isNaN(strValue) && strValue != '');
}

function isEmail(strValue)
{
  var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;

  return (strValue != '' && objRE.test(strValue));
}

// END FORM VALIDATION
