﻿//Calculate all input fields matched by the selector specified and return the total           
function calculate(selector)
{               
    var total = 0;
    
    //Get all the input fields you need add up
    var allInputs = $(selector);
    
    //Loop over the input fields and calculate the total amount
    for( var i = 0, n = allInputs.length;  i < n;  ++i ) {
        if (allInputs[i].value != '')
        {
            total = total + parseInt(allInputs[i].value);
        }
    }
    
    //return the value
    return total;
}

//Calculate all input fields matched by the selector specified and return the total           
function getNumberOfRooms(selector)
{               
    var total = 0;
    
    //Get all the input fields you need add up
    var allInputs = $(selector);
    
    //Loop over the input fields and calculate the total amount
    for( var i = 0, n = allInputs.length;  i < n;  ++i ) {
        value = parseInt(allInputs[i].value);
        if (parseInt(allInputs[i].value) != 0 && allInputs[i].value != '')
        {
            total = total + 1;
        }
    }
    
    //return the value
    return total;
}

function calculatemultiple(selectors)
{    
    var total = 0;
    
    for( var i = 0, n = selectors.length;  i < n;  ++i ) {
        if ($("#" + selectors[i]).val() != '')
        {
            total = total + parseInt($("#" + selectors[i]).val());
        }
    }
    return total;
}

function openPopupWindow(url, title, w, h)
{
    window.open(url,title, "menubar=no,width=" + w + ",height=" + h + ",toolbar=no");    
}

function ismaxlength(obj, mlength){
    if (obj.getAttribute && obj.value.length>mlength)
            obj.value=obj.value.substring(0,mlength)
}
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}


//TEMP FUNCTIONS, Can be removed if live
function checkscript() {
    alert("De website zal nu met de zoekwaarden de juiste resultaten weergeven in de overzichtslijst.");
    return true;
}
