/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function showSub(submenu) {
  document.body.style.cursor = 'default';
  if(submenu)
    {	
      if(document.getElementById('nav' + submenu).style.display == 'none') {   
        document.getElementById('nav' + submenu).style.display = 'block';
	  document.getElementById('char' + submenu).innerHTML = '-';
        } 
	else {
        document.getElementById('nav' + submenu).style.display = 'none'; 
        document.getElementById('char' + submenu).innerHTML = '+';
   	  }
    }
  deleteCookie(submenu);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function showRandom() {
var textstrings = new Array(
	  "<img src=\"res/banner01.jpg\" border=\"0\" width=\"604\" height=\"238\">"
	  ,"<img src=\"res/banner02.jpg\" border=\"0\" width=\"604\" height=\"238\">"
	  ,"<img src=\"res/banner03.jpg\" border=\"0\" width=\"604\" height=\"238\">"
	  ,"<img src=\"res/banner04.jpg\" border=\"0\" width=\"604\" height=\"238\">"
	);
    var l = textstrings.length;
    var randomnr = Math.round((l-1) * Math.random());
    document.write(textstrings[randomnr]);
}

function staticNav() {
document.write('<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">');
document.write('<tr><td height=\"16\" colspan=\"7\"></td></tr>');
document.write('<tr>');
document.write('<td width=\"10\">&nbsp;</td>');
document.write('<td><a href=\"Roterra.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav1\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav1\",\"res/tulip_nav_btn1b.jpg\",\"\",1); window.status=\"Roterra\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Rottera\"><img src=\"res/tulip_nav_btn1.jpg\" width=\"100\" height=\"75\" border=\"0\"></a></td>');
document.write('<td><a href=\"Multiterra.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav2\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav2\",\"res/tulip_nav_btn2b.jpg\",\"\",1); window.status=\"Multiterra\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Multiterra\"><img src=\"res/tulip_nav_btn2.jpg\" width=\"100\" height=\"75\" border=\"0\"></a></td>');
document.write('<td><a href=\"Multidisc.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav3\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav3\",\"res/tulip_nav_btn3b.jpg\",\"\",1); window.status=\"Multidisc\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Multidisc\"><img src=\"res/tulip_nav_btn3.jpg\" width=\"100\" height=\"75\" border=\"0\"></a></td>');
document.write('<td><a href=\"Rotarytiller.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav4\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav4\",\"res/tulip_nav_btn4b.jpg\",\"\",1); window.status=\"Rotarytiller\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Rotarytiller\"><img src=\"res/tulip_nav_btn4.jpg\" width=\"100\" height=\"75\" border=\"0\"></a></td>');
document.write('<td><a href=\"Polymat.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav5\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav5\",\"res/tulip_nav_btn5b.jpg\",\"\",1); window.status=\"Polymat\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Polymat\"><img src=\"res/tulip_nav_btn5.jpg\" width=\"100\" height=\"75\" border=\"0\"></a></td>');
document.write('<td><a href=\"Centerliner.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav6\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav6\",\"res/tulip_nav_btn6b.jpg\",\"\",1); window.status=\"Centerliner\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Centerliner\"><img src=\"res/tulip_nav_btn6.jpg\" width=\"100\" height=\"75\" border=\"0\"></a></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width=\"10\">&nbsp;</td>');
document.write('<td><a href=\"Roterra.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav1\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav1\",\"res/tulip_nav_btn1b.jpg\",\"\",1); window.status=\"Roterra\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Rottera\"><img name=\"nav1\" src=\"res/tulip_nav_btn1a.jpg\" width=\"100\" height=\"16\" border=\"0\"></a></td>');
document.write('<td><a href=\"Multiterra.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav2\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav2\",\"res/tulip_nav_btn2b.jpg\",\"\",1); window.status=\"Multiterra\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Multiterra\"><img name=\"nav2\" src=\"res/tulip_nav_btn2a.jpg\" width=\"100\" height=\"16\" border=\"0\"></a></td>');
document.write('<td><a href=\"Multidisc.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav3\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav3\",\"res/tulip_nav_btn3b.jpg\",\"\",1); window.status=\"Multidisc\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Multidisc\"><img name=\"nav3\" src=\"res/tulip_nav_btn3a.jpg\" width=\"100\" height=\"16\" border=\"0\"></a></td>');
document.write('<td><a href=\"Rotarytiller.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav4\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav4\",\"res/tulip_nav_btn4b.jpg\",\"\",1); window.status=\"Rotarytiller\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Rotarytiller\"><img name=\"nav4\" src=\"res/tulip_nav_btn4a.jpg\" width=\"100\" height=\"16\" border=\"0\"></a></td>');
document.write('<td><a href=\"Polymat.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav5\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav5\",\"res/tulip_nav_btn5b.jpg\",\"\",1); window.status=\"Polymat\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Polymat\"><img name=\"nav5\" src=\"res/tulip_nav_btn5a.jpg\" width=\"100\" height=\"16\" border=\"0\"></a></td>');
document.write('<td><a href=\"Centerliner.htm\" onClick=\'MM_nbGroup(\"down\",\"group1\",\"nav6\",\"\",1)\' onMouseOver=\'MM_nbGroup(\"over\",\"nav6\",\"res/tulip_nav_btn6b.jpg\",\"\",1); window.status=\"Centerliner\"; return true;\' onMouseOut=\'MM_nbGroup(\"out\"); window.status=\"\"; return true;\' title=\"Centerliner\"><img name=\"nav6\" src=\"res/tulip_nav_btn6a.jpg\" width=\"100\" height=\"16\" border=\"0\"></a></td>');
document.write('</tr>');
document.write('</table>');
}

function showRandomHome() {
var textstrings = new Array(
	  "<img src=\"res/home_banner_01.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
	  ,"<img src=\"res/home_banner_02.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
	  ,"<img src=\"res/home_banner_03.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
	  ,"<img src=\"res/home_banner_04.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
	  ,"<img src=\"res/home_banner_05.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
	  ,"<img src=\"res/home_banner_06.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
  	  ,"<img src=\"res/home_banner_07.jpg\" style=\"border:1px solid #000000;\" width=\"270\" height=\"180\">"
	);
    var l = textstrings.length;
    var randomnr = Math.round((l-1) * Math.random());
    document.write(textstrings[randomnr]);
}

/*database calculation*/
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 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 calctotal() {
	sErrors = '';
	var vCount = 1;
	var vTotal = 0;	
	for(var i=0; i<document.forms["calcform"].length; i++) {
		if(document.forms["calcform"].elements[i].type.indexOf("checkbox") != -1) /*&& document.forms["calcform"].elements[i].checked == 'true') */{		     
			{
			
			var vChecked = 'false';
			vChecked = document.forms["calcform"].elements[i].checked;
			//sErrors = sErrors + '\n- ' + document.forms["calcform"].elements[i].value;




			if(vChecked == false && document.getElementById("row" + parseInt(i+1)))
				{
				  document.getElementById("row" + parseInt(i + 1)).className = "row";
				}
			if(vChecked == false && document.getElementById("row" + parseInt(i+1) + "DL"))
				{
				  document.getElementById("row" + parseInt(i + 1) + "DL").onmouseover = function onmouseover()
				    {
          			      this.className = "rowDL";
          			    }
				  document.getElementById("row" + parseInt(i + 1) + "DL").onmouseout = function onmouseout()
				    {
          			      this.className = "rowADL";
          			    }
				}




			if(vChecked == true && document.getElementById("row" + parseInt(i+1)))
				{
				  document.getElementById("row" + parseInt(i + 1)).className = "rowCHK";
				  var vCheckInt = parseInt(document.forms["calcform"].elements[i].value);				  
			 	  if(!isNaN(vCheckInt)) vTotal += vCheckInt;						
				}
			if(vChecked == true && document.getElementById("row" + parseInt(i+1) + "DL"))
				{
				  document.getElementById("row" + parseInt(i + 1) + "DL").onmouseover = function onmouseover()
				    {
          			      this.className = "rowDL";
          			    }
				  document.getElementById("row" + parseInt(i + 1) + "DL").onmouseout = function onmouseout()
				    {
          			      this.className = "rowCHKDL";
          			    }
				  var vCheckInt = parseInt(document.forms["calcform"].elements[i].value);				  
			 	  if(!isNaN(vCheckInt)) vTotal += vCheckInt;						
				}



			document.getElementById('total1').innerHTML =  round_decimals(parseFloat(vTotal), 2).replace(".", ",");
			document.getElementById('total2').innerHTML =  round_decimals(parseFloat(vTotal * 0.19), 2).replace(".", ",");	
			}			
		}
	}
  return false;
}

function CheckEmailValidation(checkString)
	{
	  var newstr = "";
	  var at = false;
	  var dot = false;

	  if (checkString.value == "")
		{
 		  at = true;
		} 
	if (checkString.indexOf("@") != -1)
		{
		  at = true;
		} 
	if (checkString.indexOf(".") != -1)
		{
		  dot = true;
		}

	for (var i = 0; i < checkString.length; i++)
		{
		  ch = checkString.substring(i, i + 1)

		  if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == "@") || (ch == ".") || (ch == "_") || (ch == "-") || (ch >= "0" && ch <= "9"))
			{
			  newstr += ch;
		                if (ch == "@")
				{
		              	  at=true;
		             		}
		                if (ch == ".")
				{
		              	  dot=true;
		              	}
			}
		}

	if ((at != true) && (dot != true) || (at == true) && (dot != true) || (at != true) && (dot == true))
		{
		  alert ("Het gegeven e-mail adres is ongeldig.");
		  document.forms[0].email.focus();
		  return false;
		}
	else return true;
}

function submitform() {
	sErrors = '';
	for(var i=0; i<document.forms["neosense_formulier"].length; i++) {
		if(document.forms["neosense_formulier"].elements[i].name.indexOf("*") != -1 && document.forms["neosense_formulier"].elements[i].value == '') {			
			sErrors = sErrors + '\n- ' + document.forms["neosense_formulier"].elements[i].name.replace("*", '');
		}
		else if(document.forms["neosense_formulier"].elements[i].name.replace("*", '') == 'emailadres') {
			CheckEmailValidation(document.forms["neosense_formulier"].elements[i].value);
		}
	}
	if(sErrors == '') document.forms["neosense_formulier"].submit();
	else {
	sErrors = 'De volgende veld(en) zijn verplicht om in te vullen:    \n' + sErrors;
	alert(sErrors);
	return false;
	}
}