re = /^(file|http):\/\/\S+\.(nl|nu|be|de|fr|uk|tk|com|net|org|info|biz|ws|us|tv|cc|eu|pl)/i

function CheckURL(url) {

 if (re.test(url)) {
  return true;
 }
 else {
  return false;
 }
}


function trim(s)
{ 
	while (s.substring(0,1)==' ') 	s=s.substring(1,s.length);
	while (s.substring(s.length-1,s.length)==' ')	s=s.substring(0,s.length-1);
	return s;
}

function getFieldValue(objField)
{
	if (objField)
	{
		if (objField.value)
		{
			// non-radiobutton, or one radiobutton (checked or not)
			return objField.value;
		}
		else
		{
			if (objField.type=='select-one')
			{
				return objField.options[objField.selectedIndex].value;
			}
			else
			{
				// assume multiple radiobuttons (only of checked one)
				var i;
				for (i=0; i<objField.length; i++)
					if (objField[i].checked)
						return objField[i].value;
			}
		}
	}

	//default return value
	return('');
}


function getRadioCheckResult(objField, blnRequired, strVerplichtBericht, strFormatBericht, strFormat)
{
	if (blnRequired && (getFieldValue(objField)==''))
		return strVerplichtBericht + '\n';
	else
		if (strFormat=='')
			return '';
		else
			if (strFormat.test(getFieldValue(objField)))
				return '';
			else
				return strFormatBericht + '\n';
}

function getTextfieldCheckResult(objField, blnRequired, strVerplichtBericht, strFormatBericht, strFormat)
{
	if (objField.value=='')
		if (!blnRequired)
			return '';
		else
			return strVerplichtBericht + '\n';
	else
		if (strFormat=='')
			return '';
		else
		{
			if (strFormat.test(trim(objField.value)))
				return '';
			else
				return strFormatBericht + '\n';
				}
}

function isUnsignedInteger(s) {
  return (s.toString().search(/^[0-9]+$/) == 0);
}

function isStrUnsignedMoney(s) {
  return (s.search(/[0-9]+,[0-9]{2}$/)==0);
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}


function returnStrExBTW(s,BTW) {
  var prijs = s.replace(",",".");

  if (BTW == 'H') {
    prijs = prijs / 1.19;
  } else {
    prijs = prijs / 1.06;
  }

  prijs = round_decimals(prijs,2);

  prijs = prijs.replace(".",",");

  return prijs;
}
