﻿function SetInitials(s)
{
	var st = '';
	for (i=0; i < s.length; i++)
	{
		if (((s.charAt(i) >= 'a') && (s.charAt(i) <= 'z')) || 
			((s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z')))
		{
			st += s.charAt(i).toUpperCase() + '.';
		}
	}
	return st;
}

function FirstLetterCapital(s)
{
	var newword = 1;
	var ns = new String;
	
	for (i=0; i < s.length; i++)
	{
		if (newword)
		{
			ns += s.charAt(i).toUpperCase();
			newword = 0;
		} else
		{
			if ((s.charAt(i) == '-') || (s.charAt(i) == ' ')) newword = 1;
			
			ns += s.charAt(i).toLowerCase();
		}
	}
	return ns;
}

function GetE( elementId )
{
	return document.getElementById( elementId );
}

function ShowE( element, isVisible )
{
	if ( typeof( element ) == 'string' )
		element = GetE( element ) ;
	element.style.display = isVisible ? '' : 'none' ;
}

function SetAttribute( element, attName, attValue )
{
	if ( attValue == null || attValue.length == 0 )
		element.removeAttribute( attName, 0 ) ;
	else
		element.setAttribute( attName, attValue, 0 ) ;
}

function GetAttribute( element, attName, valueIfNull )
{
	var oAtt = element.attributes[attName] ;
	if ( oAtt == null || !oAtt.specified )
		return valueIfNull ? valueIfNull : '' ;
	var oValue ;
	if ( !( oValue = element.getAttribute( attName, 2 ) ) )
		oValue = oAtt.nodeValue ;
	if ( typeof(oValue) == 'function')
	{
		s = oValue + '';
		s = s.substr(0,s.length - 2);
		s = s.substr(23,s.length - 23);
		oValue = s;
	}
	
	return ( oValue == null ? valueIfNull : oValue ) ;
}

function IsDigit( e )
{
	e = e || event ;
	var iCode = ( e.keyCode || e.charCode ) ;
	event.returnValue = (( iCode >= 48 && iCode <= 57 ) || (iCode >= 37 && iCode <= 40) || iCode == 8 || iCode == 46) ;
	return event.returnValue ;
}

String.prototype.trim = function() 
{
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
}

String.prototype.startsWith = function( value ) 
{
	return ( this.substr( 0, value.length ) == value ) ;
}

String.prototype.remove = function( start, length )
{
	var s = '' ;
	if ( start > 0 )
		s = this.substring( 0, start ) ;

	if ( start + length < this.length )
		s += this.substring( start + length , this.length ) ;

	return s ;
}

//////////////////////////////Filter checken
function CheckReqField(_element, _validation)
{
	var filter=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

	if (_validation == 'NotEmpty')
	{
	
		if (_element.type == 'radio')
		{
			OneIsSelected = false;
			for (var x = 0; x < document.getElementsByName(_element.name).length; x++)
			{
				if (document.getElementsByName(_element.name)[x].checked)
					OneIsSelected = true;
			}
			return OneIsSelected;
		}
		else
		{
			if (_element.type == 'select-one')
				return true;
			else
				if (_element.value.trim() == '') 
					return false;
		}
	}
	
	if (_validation == 'Email' && !emailCheck(_element.value)) 
		return false;
	if (_validation == 'Numeric' && isNaN(_element.value)) 
		return false;
	
	return true;
}
