function toupcase(id)
{
	var _obj = document.getElementById(id);
	_obj.value = _obj.value.toUpperCase();
}



function validateBrochures(total_boxes)
{
	var valid = false;
	
	if (total_boxes >0){
		for ( i=0 ; i < total_boxes ; i++ ){
			if(document.getElementById("brochure" +i).checked)
			{
				document.getElementById('brochureErr').innerHTML = '';
				return true;
			}
	
		}
		
		if (!valid)
		{
			document.getElementById('brochureErr').innerHTML = 'U bent vergeten een brochure aan te vinken.';
		}
	}
	return valid;
}

function validateInput(_domain)
{
    if (_domain =="be")
        //BE
        stringInput = "Voornaam,Achternaam,adresBE,huisnummerBE,postcodeBE,email";
    else
        //NL
        stringInput = "Voornaam,Achternaam,huisnummer,postcode,email";
    

    var boolValid = true;
    var myArray = stringInput.split(",");
    
    for(x in myArray)
    {
        var field = document.getElementById(myArray[x]);
		
        if(field.value =="")
        {
			if(myArray[x] == "email")
			{
				if(document.getElementById('newsletter').checked) 
				{
		            field.className = 'errorInput';
		            boolValid = false;
				}
				else
					field.className = '';
			}
			else
			{
		            field.className = 'errorInput';
        		    boolValid = false;
			}
        }
        else
        {
            field.className = '';
    
            if (myArray[x] == "email")
            {    
				if(document.getElementById('newsletter').checked) 
				{
					if(!validateEmail(field))
    	                boolValid= false;
				}
            }
			else if(myArray[x] == "postcodeBE")
			{
				//alert(document.getElementById('postcodeBE').value.length);
				
				if(document.getElementById('postcodeBE').value.length <= 3)
				{
					field.className = 'errorInput';
					boolValid = false;		
				}
				
			}
			/*
            else if(myArray[x] == "cityBE") //check city Belgie        
            {
                if (document.getElementById('hdnCityBE').value == "")
                {
                    field.className = 'errorInput';
                    boolValid = false;
                }
                else
                {
                    field.className = '';
                    boolValid = true;
                }
            }
			*/
        }
    }
 return boolValid;
}

function validateEmail(obj)
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value) != true)
	{  obj.className = 'errorInput';
	   return false;
    }
    else
    {   obj.className = '';
        return true;
     }   
    
}

function validatePostcodeBE(id)
{
    
	var boolNum = false;
    var tb = document.getElementById(id).value;
    
	if(tb.length == 4)
	{
		boolNum = IsNumeric(tb);
		if (boolNum)
		{	
			//postcodeCheckBE(tb);
			document.getElementById('postcodeMessageBE').innerHTML = '';
		}
		else
			document.getElementById('postcodeMessageBE').innerHTML = 'postcode is onbekend';			
	}
}


function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function noSpace(e, id)
{
	var keycode;
	
	if(window.event) // IE
	{
	keycode = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keycode = e.which;
	}

	if(keycode == 32)
		document.getElementById(id).value =  removeSpaces(document.getElementById(id).value);
	
}

function validatePostcodeNL(id, huisnrId)
{
	var boolNum = false;
    var boolAlp = false;
    var tb = document.getElementById(id).value;
	var Huisnr = document.getElementById(huisnrId).value;     
	
	if (tb.length == 6)
	{
		//==check if huisnummer and postcode are filled in
		if (Huisnr != "")
		{
		
			var num = tb.substring(0,4);
		    var alp = tb.substring(4);
    
    		boolNum = IsNumeric(num);
		    boolAlp = IsNumeric(alp);
    
		
			if(boolNum && boolAlp)
			{
				document.getElementById('postcodeMessage').innerHTML = 'postcode is onbekend';
			}
			else
			  {  //postcode check
				  
				postcodeCheck(tb, Huisnr);
				document.getElementById('postcodeMessage').innerHTML = '';
			} 
		}
	}
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


/* ajax */
function GetXmlHttpObject()
	{ 
		var objXMLHttp=null
		
		if (window.XMLHttpRequest)
		{
			objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	
		return objXMLHttp
	}
	
	
	function postcodeCheck(_postcode, _nummer)
	{
		xmlHttp=GetXmlHttpObject();
	    if (xmlHttp==null)
		{
		   alert ("Browser does not support HTTP Request")
		    return
		} 
		
		sendRequest(_postcode, _nummer)
		
	}
	
				
	function sendRequest(_postcode, _nummer)
	{
	    var url = "/_Formulieren/nl/includes/postcodeCheck.asp"
		url=url+"?postcode=" +_postcode
		url=url+"&nummer=" +_nummer
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
	
	function stateChanged() 
	{ 
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var _returnValue = xmlHttp.responseText;
			var ary = _returnValue.split("|");
			
			document.getElementById("adresNL").value=ary[0];
			document.getElementById("cityNL").value=ary[1];
		}	 
	} 
	
	
	
/*BE*/
function checkKey(e)
{
    var cursorKeys ="9;16;17;18;19;20;226;46;37;38;39;40;32;33;34;35;36;45;";
    var unicode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	//var unicode= e.keyCode? e.keyCode : e.charCode;
  
    if (cursorKeys.indexOf(unicode+";") == -1 || unicode == 8)
        return true;
    else
    //{
    //    alert("x: " +unicode);
        return false;
    //}
}

function showiFrame(e, _keyword)
{
    if (checkKey(e))
    {
        if(_keyword.length >= 1) 
        {
            
            if(document.getElementById('iframeCities')== null)
            {
                if (_keyword.length == 1)
                { 
                    ifrm = document.createElement("IFRAME");
                    ifrm.setAttribute("id", "iframeCities");
                    ifrm.setAttribute("src", "cities.asp?keyword=" +_keyword);
					ifrm.style.width = 274+"px";
                    ifrm.style.height = 100+"px";
               
                    document.getElementById('diviFrame').appendChild(ifrm);
                    document.getElementById('diviFrame').style.display = 'block';
                }
            } 
            else
            {
                document.getElementById('iframeCities').src= "cities.asp?keyword=" +_keyword;
                document.getElementById('diviFrame').style.display = 'block';
            }   
        }
        else if(_keyword.length == 0)
        {
            if(document.getElementById('iframeCities')!= null)
            {
                document.getElementById('iframeCities').src= "cities.asp?keyword=" +_keyword;
                document.getElementById('diviFrame').style.display = 'block';
            }
        }
    }
}


	function postcodeCheckBE(_postcode)
	{
		xmlHttp=GetXmlHttpObject();
	    if (xmlHttp==null)
		{
		   alert ("Browser does not support HTTP Request")
		    return
		} 

	sendRequestBE(_postcode)
	}
	
				
	function sendRequestBE(_postcode)
	{
	    var url = "/_Formulieren/nl/includes/citiesBE.asp"
		url=url+"?postcode=" +_postcode
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChangeBE
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
	
	function stateChangeBE() 
	{ 
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			//var _returnValue = xmlHttp.responseText;
			//var ary = _returnValue.split("|");
			
			document.getElementById("cityBE").value= xmlHttp.responseText;
		}	 
	} 


	/* noordeuropa en eilandenreis */

	function showMagazine(_param)
	{
		var mySpan = document.getElementById("spanMagazine");
		//if(_param.toLowerCase() == "tijdschrift of magazine")
		if(_param ==282)
		{
			mySpan.style.display='inline';
		}
		else
		{
			mySpan.style.display = 'none';
		}
	}
	
	function showMagazineResForm(_param)
	{
		var mySpan = document.getElementById("spanMagazine");
		if(_param.toLowerCase() == "tijdschrift of magazine")
		{
			mySpan.style.display='inline';
		}
		else
		{
			mySpan.style.display = 'none';
		}
	}
	
	function onlyDigits(evt) {

	        evt = (evt) ? evt : window.event
	        var charCode = (evt.which) ? evt.which : evt.keyCode
	        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
	            status = "This field accepts numbers only."
	            return false
	        }
	        status = ""
	        return true

    }

    function IsNumeric(strString) {
        var strValidChars = "0123456789\n";
        var strChar;
        var blnResult = true;

        if (strString.length == 0) return false;
        for (z = 0; z < strString.length && blnResult == true; z++) {
            strChar = strString.charAt(z);
            if (strValidChars.indexOf(strChar) == -1) {
                blnResult = false;
            }
        }
        return blnResult;
    }

