		/* Thanks for reading our source
		** --------------------------------------------------------------------------
		** File                    :   rlClientObjects.js
		** Version                 :   1.00
		** Copyright               :   (c) 2002-2003 comgate, switzerland
		** Author                  :   Rene Leupold
		** Created                 :   05.11.2002
		** Interpreter/Compiler    :   Javascript 1.5
		** --------------------------------------------------------------------------
		*/
		
	        function CrlClientFunctions()
		{
			this._checkRegExp = function()
			{
		         var chkReg = new RegExp("abc");
		         var bRegExp = false;
		         if(chkReg.test("abc") == true)
		         {
		             bRegExp = true;
		         }
		         return(bRegExp);
			}
			this._checkValidInput = function(csValue,csRegExp)
			{
		 		var search = new RegExp(csRegExp);
		 		var result = csValue.match(search);
		 		return result;
			}
			this.isValidText = function(csValue)
			{
				//(csValue.length > 0) ? return true:return false;
				if(csValue.length > 0)
					return true;
				else
					return false;
			}
			this.isValidTime = function(csValue)
			{
				var reg = "^([2][0-3]|[0-1]?[0-9])[\.:\/]?([0-5][0-9])[\.:\/]?([0-5]?[0-9]?)$";
				if(this._checkRegExp)
				{
				    return this._checkValidInput(csValue,reg);
				}
			}
			this.isValidDate = function(csValue)
			{
				//var dt = new CrlDateConverter();
				//todo: prüfung Abhängig von der gewünschten Form (german, iso)
				return true;// dt.checkDate(csValue,"german");
			}
			this.isValidInt = function(csValue)
			{
				var reg = "^([-|+])?([0-9]+)([-|+])?$";	
				if(this._checkRegExp)
				{
					return this._checkValidInput(csValue,reg);
				}	
			}
			
			this.isValidDouble = function(csValue)
			{
				var reg = "^([-|+]?)([0-9]*[\.|\,]?[0-9]+)([-|+])?$";
				if(this._checkRegExp)
				{
					return this._checkValidInput(csValue,reg);
				}
			}
			
			this.isValidMail = function(csValue)
			{
				//regexp arbeitet nicht 100%ig.
				if(csValue.lastIndexOf(".")<0)
					return false;
				else
					if(csValue.substring(csValue.lastIndexOf("."),csValue.length) < 2) return false;

				//var reg = "^([a-zA-Z0-9\-\.\_]+)([@]{1})([a-zA-Z0-9\-\.]+)([.]{1})([a-zA-Z]{2,4})$";
				var reg = "^([a-zA-Z0-9\-\.\_]+)(\@)([a-zA-Z0-9][a-zA-Z0-9._-]*\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\.[a-zA-Z]{2,5}$";
				if(this._checkRegExp)
				{
					return this._checkValidInput(csValue,reg);
				}
			}
			this.isValidUrl = function(csValue)
			{
				var reg = "(http://|https://|ftp://|ftps://)([a-zA-Z0-9\-\.]+)(\.)([a-zA-Z]{2,4})$";
				if(this._checkRegExp)
				{
					return this._checkValidInput(csValue,reg);
				}
			}
			this.isValidCustom = function(csValue,csRegExp)
			{
				if(this._checkRegExp)
				{

					return this._checkValidInput(csValue,csRegExp);
				}
			}
			this.isValidEqual = function(csValue,csField)
			{
				if(csValue == csField)
				{
					return true;
				}
				else
				{
					return false;
				}
				return false;
			}		
		
		    this.checkSelectState = function(pElem, minSel, maxSel,bRequire)
		    {
		       var count = 0;
		       var i=0;
		       var bOk = true;

		       if(pElem.multiple)
		       {
		           for(i=0;i<pElem.length;i++)
		           {
		               if(pElem.options[i].selected == true)
		               {
		                   if(pElem.options[i].value != "-1")
		                      count ++;
		               }
		           }
		           if(minSel > count || maxSel < count)
		           {
		               if(!bRequire && count == 0)
		                  bOk = true;
		               else
		                  bOk = false;
		           }
		           else
		           {
						bOk = true;
		           }
		       }
		       else
		       {
		           if(bRequire)
		           {
		               if(pElem.value != "-1")
		               {
		                   bOk = true;
		               }
		               else
		               {
		                   bOk = false;
		               }
		           }
		       }
			   return bOk;
		    }
			this.checkCheckedState = function(pElem, minSel, maxSel,bRequire)
			{
		       var count = 0;
		       var i=0;
		       var bOk = true;
		
		       if(pElem[pElem.length-1].type == "checkbox")
		       {
		           for(i=0;i<pElem.length;i++)
		           {
		               if(pElem[i].checked == true)
		               {
		                      count ++;
		               }
		           }
		           if(minSel > count || maxSel < count)
		           {
		               if(!bRequire && count == 0)
		                  bOk =  true;
		               else
		                  bOk =  false;
		           }
		           else
		           {
		               bOk =  true;
		           }
		       }
		       else
		       {
		           if(bRequire)
		           {
		              for(i=0;i<pElem.length;i++)
		              {
		                 if(pElem[i].checked == true)
		                 {
		                    return true;
		                    break;
		                 }
		              }
		              bOk =  false;
		           }
		       }
		       return bOk;		
			}		
	 	}	
		
		function CrlCheckUserInput()
		{
		    this.LABELPREFIX = "lbl_";
		    this.m_RequireColor = "#ff0000";
		    this.m_chkInput =  new CrlClientFunctions();
			this.m_FormName = "0";
			this.m_ErrorText = "";
			this.m_ErrorNode = "";
			this.m_bFocus = false;
			this.m_FocusField = "";
			this.m_bInputOk = true;
	
			this.__construct = function()
			{
				this.m_bFocus = false;
				this.m_FocusField = "";
				this.m_bInputOk = true;
				this.m_ErrorNode="";
			}
			this.setErrorText = function(csError)
			{
				this.m_ErrorText = csError;
			}
			this.setRequireColor = function(csColor)
			{
			    this.m_RequireColor = csColor;
			}
			this.setLabelPrefix = function(csPrefix)
			{
				this.LABELPREFIX = csPrefix;
			}
			this.setFormName = function(csName)
			{
				this.m_FormName = csName;
			}
			this.checkInputElement = function(csType,csElementName, csErrorDesc, bRequire,extParam)
			{
				var hr = true;
				var Value = "";

				if(document.forms[this.m_FormName].elements[csElementName])
					Value = document.forms[this.m_FormName].elements[csElementName].value;
				else
					bRequire = false;

                                if( Value != "" ) bRequire = true;

				if(bRequire)
				{
				
					switch(csType.toLowerCase())
					{
						case "text":
						     hr = this.m_chkInput.isValidText(Value);
						break;
						case "mail":
						     hr = this.m_chkInput.isValidMail(Value);
						break;
						case "date":
						     //hr = this.m_chkInput.isValidDate(Value);
						break;
						case "time":
						     hr = this.m_chkInput.isValidTime(Value);
						break;
						case "decimal":
						     hr = this.m_chkInput.isValidDouble(Value);
						break;
						case "number":
						     hr = this.m_chkInput.isValidInt(Value);
						break;
						case "url":
							hr = this.m_chkInput.isValidUrl(Value);
						break;
						case "custom":

							hr = this.m_chkInput.isValidCustom(Value,extParam);
						break;
					    case "equal":
							hr = this.m_chkInput.isValidEqual(Value,document.forms[this.m_FormName].elements[extParam].value);
						break;
					}

					if(!hr)
					{
						this.m_ErrorNode += csErrorDesc + "\n";
						this.m_bInputOk = false;
						if(!this.m_bFocus)
		                {
		                   this.m_bFocus = true;
			               this.m_FocusField = document.forms[this.m_FormName].elements[csElementName];
		                }
		
					}
					else
					{
					    if(this.m_bInputOk) this.m_bInputOk = true;
					}
					this._setElementStyles(csElementName,bRequire,hr);
				}
				else
				{
				    if(Value.length > 0) this.checkInputElement(csType,csElementName,csErrorDesc,true);
				}
			}
		
			this.checkSelectState = function(csElementName, csErrorDesc, minSel, maxSel,bRequire)
			{
				var hr = true;
				
				hr = this.m_chkInput.checkSelectState(document.forms[this.m_FormName].elements[csElementName],minSel,maxSel,bRequire);
				if(!hr)
				{
					this.m_ErrorNode += csErrorDesc + "\n";
					this.m_bInputOk = false;
					if(!this.m_bFocus)
	                {
	                   this.m_bFocus = true;
		               this.m_FocusField = document.forms[this.m_FormName].elements[csElementName];
	                }
				}
				else
				{
				    if(this.m_bInputOk) this.m_bInputOk = true;
				}
				this._setElementStyles(csElementName,bRequire,hr);		
			}
		
			this.checkCheckedState = function(csElementName, csErrorDesc, minSel, maxSel,bRequire)
			{
				var hr = true;
				
				hr = this.m_chkInput.checkCheckedState(document.forms[this.m_FormName].elements[csElementName],minSel,maxSel,bRequire);
				if(!hr)
				{
					this.m_ErrorNode += csErrorDesc + "\n";
					this.m_bInputOk = false;
					if(!this.m_bFocus)
	                {
	                   this.m_bFocus = true;
		               this.m_FocusField = document.forms[this.m_FormName].elements[csElementName];
	                }
				}
				else
				{
				    if(this.m_bInputOk) this.m_bInputOk = true;
				}
				this._setElementStyles(csElementName,bRequire,hr);		
			}
				
			this._setElementStyles = function(ElementName, bRequire,result)
			{
			    if(document.getElementById)
			    {
		        	var id = document.getElementsByName(ElementName)[0].id;
		        	//alert(id);
	            	if(id)
		        	{
		            	if(bRequire && !result)
		            	{
		               		document.getElementById(id).style.borderColor = this.m_RequireColor;
	                   		if(document.getElementById(this.LABELPREFIX + id))
		               		{
		                  		document.getElementById(this.LABELPREFIX + id).style.color = this.m_RequireColor;
		               		}
	                	}
	                	else
	                	{
	                   	//remove attributes
	                   		document.getElementById(id).removeAttribute("style");
	                   		if(document.getElementById(this.LABELPREFIX + id))
	                   		{
	                       		document.getElementById(this.LABELPREFIX + id).removeAttribute("style");
	                   		}
	                	}
	            	}    
		        }
			}
			this.isInputCorrect = function()
			{
			    return this.m_bInputOk;
			}
			this.getErrorMessage = function()
			{
			    if(this.m_bFocus) 
				{
					this.m_FocusField.focus();
					if(this.m_FocusField.select) this.m_FocusField.select();
				}
			    return this.m_ErrorText + "\n" + this.m_ErrorNode;;
				
			}
		}
		
		function CrlClientStyles()
		{

		    this.setElementStyle = function(border, backgroundColor)
		    {
				var csStyle = "<style type=\"text/css\">\n";
				csStyle += "textarea, input, select {\n";
				if(border.length > 0) csStyle += "border:" + border;
				csStyle += "background-color:" + backgroundColor + ";\n}\n";
				csStyle += "</style>\n";		
		        if (document.getElementById)
		        {
					//todo: bessere Lösung finden
		            document.write(csStyle);
		        }
		    }
		    
		    this.changeElementStyle = function(refElement, border, backgroundColor)
		    {
		        if (document.getElementById)
		        {
					if(border.length == 0 && backgroundColor.length == 0)
					{
						refElement.removeAttribute("style");
					}
					else
					{
						if(border.length > 0) refElement.style.border=border;
						refElement.style.backgroundColor=backgroundColor;
					}
				}
		    }
		    this.cES = function(refElement, border, backgroundColor)
		    {
		        this.changeElementStyle(refElement, border, backgroundColor);
		    }
		}
		
		function CrlAssistant()
		{/*(c) 2002-2003 renegadexxatgmx.net */
			this.m_csPicture = "";
			this.LABELPREFIX = "lbl_";
			this.ASSISTANTID = "rlAssistant";
			
			this.setLabelPrefix = function(csLabel)
			{
				this.LABELPREFIX = csLabel;
			}
			this.setAssistantId = function(csID)
			{
				this.ASSISTANTID = csID;
			}
			this.setAssistantPicture = function(csPicture)
			{
				this.m_csPicture = csPicture;
			}
			this.showAssistant = function(pElement)
			{
			     if(document.getElementById)
			     {
			     	if(pElement.id)
			     	{
			          strAssistant = document.getElementById(this.LABELPREFIX + pElement.id).getAttribute("title");
                                  if(strAssistant == null) strAssistant = "";
			          if(document.getElementById(this.ASSISTANTID))
					  {
						 document.getElementById(this.ASSISTANTID).innerHTML = this.drawAssistant(strAssistant);
					  }
					}
			     }
				 window.status = strAssistant;
			}
			this.drawAssistant = function(csInfo)
			{
                             if( csInfo == "" ) return csInfo;
			     var assHTML = "<p class=\"infoAssi\">";
			     assHTML += "";
			     if(this.m_csPicture.length > 0)
			     {
			     	assHTML += "<img class=\"assipic\" src=\"" + this.m_csPicture + "\" alt=\"Assistant\" />";
			     }
 			     assHTML += "<span>"
 			     assHTML += csInfo;
				 assHTML += "</span><br style=\"clear:both;\" />&nbsp;</p>";
			     return assHTML;
			}
                        this.showInformation = function(Text)
                        {
                              if( document.getElementById(this.ASSISTANTID) )
                              {
                                   document.getElementById(this.ASSISTANTID).innerHTML = this.drawAssistant(Text);
                              }
                        }
			this.hideAssistant = function()
			{
		    	if(document.getElementById) 
		    	{
					if(document.getElementById(this.ASSISTANTID))
					{
		    			document.getElementById(this.ASSISTANTID).innerHTML = "<p>&nbsp;</p>";
					}
				}
				window.status = "";
		    }
		}
function ExpressionHandler()
{

	this._checkRegExp = function()
	{
	    var chkReg = new RegExp("abc");
	    var bRegExp = false;
	    if(chkReg.test("abc") == true)
            {
	          bRegExp = true;
	    }
 	    return(bRegExp);
	}
	this._checkValidInput = function(csValue,csRegExp)
	{
		var search = new RegExp(csRegExp);
		var result = csValue.match(search);
		return result;
	}
	///return bool for match
        this.checkInput = function(csValue, csRegExp)
	{
	     if( this._checkRegExp )
	     {
                 return this._checkValidInput(csValue, csRegExp);
	     }
	     else //not available
	     {
		 alert("Browser does not support Regular Expressions,\n clientside check impossible");

             }
	}
	///returns array of matches
	this.matchInput = function(csValue, csRegExp)
	{
  	    var re = new RegExp(csRegExp);
  	    var m = re.exec(csValue);
	    return m;

	}
	
}
function StringManipulator()
{
         this.makeFirstUpper = "";
         this.makeUpper = "";
         this.makeLower = "";
         this.makeWordBeginUpper = "";

         this.makeFirstUpper =     function(value)
         {
              return value.substr(0,1).toUpperCase() + value.substr(1,value.length);
         }

         this.makeWordBeginUpper = function(value)
         {
             var i = 0;
             var Words = value.split(" ");
             value = "";
             for(i = 0;i <Words.length;i++)
             {
                 Words[i] = Words[i].substr(0,1).toUpperCase() + Words[i].substr(1,Words[i].length);
                 value+= Words[i] + " ";
             }

             return value;
         }
         this.makeUpper =          function(value)
         {
              return value.toUpperCase();
         }

         this.makeLower =          function(value)
         {
              return value.toLowerCase();
         }
}		

function isSpecialChar(key)
{
    switch(key)
    {
    case 37:
    case 39:
    case 8:
    case 9:
    case 46:
    case 45:
       return true;
    break;
    }

    return false;
}
function checkZIP(evt)
{
  ichar = (evt.keyCode) ? evt.keyCode : evt.which

  if( isSpecialChar(ichar) ) return true;
  
  var re = new ExpressionHandler();
  if( re.checkInput(String.fromCharCode(ichar), "([0-9])" ) )
      return true;
  else //Char not allowed
  {
      as.setAssistantPicture("fileadmin/images/icon_assistant.gif");
      var info = "Eingabe des Zeichens <strong> '" + String.fromCharCode(ichar) + "' </strong> ist im PLZ - Feld nicht möglich! ";
      info += "Erlaubt sind die Ziffern 0-9.";
      as.showInformation(info);
      as.setAssistantPicture("fileadmin/images/icon_assistant.gif");
      return false;
  }

}
function checkPhoneNumber(evt)
{
  ichar = (evt.keyCode) ? evt.keyCode : evt.which
  if( isSpecialChar(ichar) ) return true;
  
  var re = new ExpressionHandler();
  if( re.checkInput(String.fromCharCode(ichar), "([0-9\\+\\-\\(\\)/ ])" ) )
      return true;
  else //Char not allowed
  {
      as.setAssistantPicture("fileadmin/images/icon_assistant.gif");
      var info = "Eingabe des Zeichens <strong> '" + String.fromCharCode(ichar) + "' </strong> ist im Telefon - Feld nicht möglich! ";
      info += "Erlaubt sind die Ziffern 0-9 sowie +-/() .";
      as.showInformation(info);
      as.setAssistantPicture("fileadmin/images/icon_assistant.gif");
      return false;
  }
}

function convertString(value,type)
{

    var csMan = new StringManipulator();
	var hr="";
	switch(type)
	{
	   case 1:
		hr=csMan.makeUpper(value);
	   break;
	   case 2:
	    hr=csMan.makeFirstUpper(value);
	   break;
	   case 3:
	    hr=csMan.makeWordBeginUpper(value);
	   break;
	   case 4:
	    hr=csMan.makeLower(value);
	   break;
	   default:
	    hr=value;
	}
	return hr;
}
var rlStyle = new CrlClientStyles();
rlStyle.setElementStyle("","#ffffff");
var as = new CrlAssistant();
as.setAssistantId("Assi");
as.setAssistantPicture("fileadmin/images/icon_assistant.gif");


function initElementEvents()
{
    setLayout();
    checkMac();
    attachEvents();
    document.forms["frmContact"].elements["Text"].focus();
}
function isTextField(id)
{

    switch(id)
    {
       case "name":
       case "vorname":
       case "strasse":
       case "ort":
       case "land":
       case "Text":
            return true;
       break;
    }
    return false;

}
/*
function attachEvents()
{
      var check;
      for( var i = 0; i < document.forms["frmContact"].length; i++ )
      {
         var el = document.forms["frmContact"].elements[i];

         if(!el.type) i++;

         if( el.type == "text" || el.type == "password" || el.type == "textarea" || el.type.indexOf("select") > -1 )
         {
            el.onfocus = function() { rlStyle.cES(this,'','#EFEEE5');as.showAssistant(this); }
            if( isTextField(el.id) )
            {
               el.onblur = function() { rlStyle.cES(this,'','#fff');this.value=convertString(this.value,2);as.hideAssistant(); }
            }
            else // assign only stlyle function
               el.onblur = function() { rlStyle.cES(this,'','#fff');as.hideAssistant(); }
      
         }
      }
}
*/

function checkCachedData()
{
}
function Validate() 
{
	
	var rlCheck = new CrlCheckUserInput();
	rlCheck.setLabelPrefix("lbl_");
	rlCheck.setErrorText("Folgende Felder sind nicht korrekt ausgefüllt bzw. fehlerhaft:");
	rlCheck.setFormName("frmContact");
	rlCheck.checkInputElement('text','Text','- Mitteilung',false,"^([\\w\\s.]{10,})");
	rlCheck.checkInputElement('text','Vorname','- Vorname',false,'');
	rlCheck.checkInputElement('text','Name','- Nachname',true,'');
	rlCheck.checkInputElement('text','Strasse','- Strasse',false,'');
	rlCheck.checkInputElement('custom','PLZ','- PLZ',false,"^([0-9]{4,})$");
	rlCheck.checkInputElement('text','Ort','- Ort',false,'');
	rlCheck.checkInputElement('custom','Telefon','- Telefonnummer',true,"^([+])?([0-9 \(\)\/-]{5,})$");
	rlCheck.checkInputElement('mail','Email','- Email',true,'');
	if(!rlCheck.isInputCorrect())
	{
		alert(rlCheck.getErrorMessage());
	}
	return rlCheck.isInputCorrect();
 
}
