﻿function getElementsByClass(searchClass,node,tag) 
{
	var classElements = new Array();
	
	if ( node == null )
		node = document;
		
	if ( tag == null )
		tag = '*';
		
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	
	for (i = 0, j = 0; i < elsLen; i++) 
	{
		if ( pattern.test(els[i].className) ) 
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function OpenPics(url, iwidth, iheight){
	window.open(url,"afbeelding","width="+iwidth+",height="+iheight+",left=125,top=100");
}

function OpenLocatieTools(i)
{
    winloc = window.open('locatietools.aspx?i='+ i, 'locatietools', 'width=600, height=500')
}
function submitform(sButtonName)
{
//onkeydown="submitform('')"
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
    {
        event.returnValue=false;
        event.cancel = true; 

        var eleButton = document.getElementById(sButtonName)
        eleButton.click();
        //return false;
    } 
    else {
        return true;
    }
}


function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. dd/mm/yyyy or dd-mm-yyyy or dd.mm.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}

    var intDay = parseInt(arrayDate[0],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 1)
        return true; //found in lookup table, good date
    }

    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}

/*
function CheckBoxValidatorEvaluateIsValid(val)
{
    var control = document.getElementById(val.controltovalidate);
    var mustBeChecked = Boolean(val.mustBeChecked);

    return control.checked == mustBeChecked;
}
*/
function CheckBoxValidatorEvaluateIsValid(val)
{
    var control = document.getElementById(val.controltovalidate);
    var minimumNumberOfSelectedCheckBoxes = 1 //parseInt(val.minimumNumberOfSelectedCheckBoxes);

    var selectedItemCount = 0;
    var liIndex = 0;
    var currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    while (currentListItem != null)
    {
        if (currentListItem.checked) selectedItemCount++;
        liIndex++;
        currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    }

    return selectedItemCount >= minimumNumberOfSelectedCheckBoxes;
}

function showhide_domains(number)
{
	if (document.getElementById('active-domains'))
	{
		var li = document.getElementById('active-domains').getElementsByTagName('li');
		var i = li.length
		if (document.getElementById('active-domains').className=='show_few_items')
		{
			document.getElementById('active-domains').className = 'show_all_items';
			while (i--)	if (i>=number) li[i].style.display = 'none';
			document.getElementById('showhide_domains').innerHTML = '<span>' + txtShowdomains  + '</span>';
		}
		else
		{
			document.getElementById('active-domains').className = 'show_few_items';
			while (i--)	li[i].style.display = 'block';
			document.getElementById('showhide_domains').innerHTML = '<span>' + txtHidedomains + '</span>';
		}
		Rounded("a#showhide_domains","transparent","#767774");
	}
}

function initNyroModalPopups() {
    //$("a.fotoboek").nyroModal({ width: 740, height: 531 });
    $("a.fotoboek").click(function(){ $.nyroModalManual({ url: $(this).attr('href'), height: '531', width: '740' }); return false; });

    $.fn.nyroModal.settings.showBackground = function(elts, settings, callback) {
        elts.bg.css({ opacity: 0, background: '#000' }).fadeTo(500, 0.65, callback);
    }
}

$(document).ready(function() {
    initNyroModalPopups();
    $('span.datum').css('width', $('span.datum .wrapper').width() + 9 + 'px')
});
