function isElement( theForm , id )
{
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		if ( theForm.elements[i].id.substr( 0 , id.length ) == id )
		{
			return true;
		}
	}

	return false;	  
}

function checkChars( sText , ValidChars )
{

	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
   
}

function countSelectAmount( theForm )
{
	var m=0;
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		//alert( theForm.elements[i].type );
		if ( theForm.elements[i].type == "select-one" )
		{
			m = Number( m ) + Number( theForm.elements[i].value );
		}
	}

	return m;	  
}

function msn_send( f )
{
	if ( msn_check( f ) == true )
	{
		f.send.value=1;
		f.test.value=0;
		f.submit();
	}
}

function msn_test( f )
{

	if ( msn_check( f ) == true )
	{
		f.send.value=0;
		f.test.value=1;
		f.submit();
	}
}

function msn_check( f )
{
	var subj = f.s.value;
	var text = f.b.value;
	var email = f.e.value;
	var pass = f.p.value;

	if (
		( subj.length > 0 ) &&
		( text.length > 0 ) &&
		( email.length > 0 ) &&
		( pass.length > 0 )
	)
	{
		return true;
	}

	alert('Alle velden moeten ingevuld worden.');
	return false;
}

function getWidthAndHeight() 
{
	//alert("'" + this.name + "' is " + this.width + " by " + this.height + " pixels in size.");
	document.getElementById('imgheight').height = this.height;
	return true;
}

function loadFailure() {
    //alert("'" + this.name + "' failed to load.");
    return true;
}

function setHeight( url )
{

	var myImage = new Image();
	myImage.name = "someimg.jpg";
	myImage.onload = getWidthAndHeight;
	myImage.onerror = loadFailure;
	myImage.src = url + '/images/balk.jpg';

	//alert();
	var img = new Image;
	var h = img.height;

	//alert( 'Height: ' + h );
	document.getElementById('imgheight').height = h;
	
}

function getImageHeight( myImage ) 
{
	var y, obj;
	if (document.layers) 
	{
		var img = getImage( myImage );
		return img.height;
	} else {
		return getElementHeight( myImage );
	}
	return -1;
}


function check_gsm( mob )
{
	var i=0;
	var ret = true;

	for ( i=0 ; i < mob.length ; i++ )
	{
		var chk = mob.charAt( i );
		if (
			( isNumber( chk ) == false )
		)
		{
			ret = false;
			//alert( chk);
		}
	}

	if ( mob.length < 10 )
	{
		ret = false;
	}

	return ret;
}

function isNumber( index )
{
	var ret = false;
	if ( index == '0' )
	{
		ret = true;
	}else if ( index == '1' )
	{
		ret = true;
	}else if ( index == '2' )
	{
		ret = true;
	}else if ( index == '3' )
	{
		ret = true;
	}else if ( index == '4' )
	{
		ret = true;
	}else if ( index == '5' )
	{
		ret = true;
	}else if ( index == '6' )
	{
		ret = true;
	}else if ( index == '7' )
	{
		ret = true;
	}else if ( index == '8' )
	{
		ret = true;
	}else if ( index == '9' )
	{
		ret = true;
	}else if ( index == ',' )
	{
		ret = true;
	}else if ( index == '+' )
	{
		ret = true;
	}

	return ret;

}

function fact( verkoop_id )
{
	var str = '/showfactuur.php?v=' + verkoop_id;
	window.open(str, 'Factuur', 'scrollbars=yes,status=no,width=600,height=600'); 
}

function help(itemnr)
{
	var str = '/page/help.php?item=' + itemnr;
	window.open(str, 'HELPWin', 'scrollbars=no,status=no,width=600,height=600'); 
}

function vb(itemnr)
{
	var str = '/page/vb.php?item=' + itemnr;
	window.open(str, 'VBWin', 'scrollbars=yes,status=no,width=600,height=600'); 
}

function switchSelected( theForm , id , chkVal )
{
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		if ( theForm.elements[i].id.substr( 0 , id.length ) == id )
		{
			if ( chkVal )
			{
				theForm.elements[i].checked = true;
			}else{
				theForm.elements[i].checked = false;
			}
		}
	}	  
}

function countRadioSelected( theForm )
{
	var m=0;
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		if ( theForm.elements[i].type == "radio" )
		{
			//alert( theForm.elements[i].checked );
			if ( theForm.elements[i].checked == true )
			{
				m = m + 1;
			}
		}
	}

	return m;	  
}

function countChecked( theForm )
{
	var m=0;
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		if ( theForm.elements[i].type == "checkbox" )
		{
			if ( theForm.elements[i].checked == true )
			{
				m = m + 1;
			}
		}
	}

	return m;	  
}

function countCheckedByName( theForm , naam )
{
	var m=0;
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		if ( theForm.elements[i].type == "checkbox" )
		{
			if ( theForm.elements[i].name == naam )
			{
				if ( theForm.elements[i].checked == true )
				{
					m = m + 1;
				}
			}
		}
	}

	return m;	  
}

function setStatus( theForm , oType , bStatus )
{
//zet een object van het type oType op disabled als bStatus FALSE is

	var m=0;
	for (i=0,n=theForm.elements.length;i<n;i++)
	{
		if ( theForm.elements[i].type == oType )
		{
			var Obj = document.getElementById(theForm.elements[i].id);

			if ( bStatus == false )
			{
				Obj.disabled = true;
			}else{
				Obj.disabled = false;
			}
		}
	}
}
