/**
 *
 *coValidator
 *
 */
CO.Validator = Class.create({
    initialize: function(input_html)
    {
        this.input_html = input_html;
        this.error_object = undefined;
    }
});

CO.Validator.prototype.getHTMLElement=function()
{
    return this.input_html; 
}

CO.blurMyChildren=function(parent_node)
{
	if(parent_node.blur != undefined)
	   parent_node.blur();
 
	//if (BrowserDetect.browser != "Explorer")
	//		return;
			
	if(typeof parent_node.onblur == "function")
	{
	  parent_node.onblur();
	}
	for (var child_nr = 0; child_nr < parent_node.childNodes.length; child_nr++)
	{
		CO.blurMyChildren(parent_node.childNodes[child_nr]);
	}
}

CO.Validator.prototype.removeError=function()
{
    if(this.error_object != undefined)
    {
        CO.msg.remove(this.error_object);
        this.error_object = undefined;
        
        var error_symbol = gVC.getErrorSymbol(this.input_html.id);
      
        if (error_symbol != undefined) 
        {
            gVC.setErrorSymbol(this.input_html.id, undefined);
            error_symbol.parentNode.removeChild(error_symbol);
        }
    }    
}

CO.Validator.prototype.addError=function(error_string)
{
    this.error_object = this.input_html.addError(error_string);
    if(gVC.getErrorSymbol(this.input_html.id) == undefined)
    {
         var error_symbol = CO.msg.getErrorSymbol(error_string);
         gVC.setErrorSymbol(this.input_html.id, error_symbol);
         this.input_html.insert({after:error_symbol});
         error_symbol.focus();
         CO.Page.fixMasks();
    }
}

CO.Validator.prototype.getHtmlInputId=function()
{
    
    return this.input_html.id;
}


//Christoph!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CO.ValidatorContainer = Class.create(
                                    {
  									  initialize: function() 
  										    		{
    													this.mask_container = new Object();
                                                        this.html_input_container = new Object();					
  													}
  									});
                                    
       
CO.ValidatorContainer.prototype.validateMask=function(mask_id)                          
{
    var validator_array = this.getValidatorsForMaskId(mask_id);
    var status = true;
    
    for (var i=0; i < validator_array.length; i++)
    {
        //alert(validator_array[i]);
        if (validator_array[i].validate() == false )
            status=false;
    }
    return status;
}
                                    
CO.ValidatorContainer.prototype.getMaskIdForHTMLElement=function(input_html)
{
    
    var parent_node = input_html.parentNode;
    
    while(parent_node != undefined)
    {
        if(parent_node.tagName == "FORM")
        {
            return parent_node.id;
        }
        
        parent_node = parent_node.parentNode;
    }
    
    
    return undefined;
}

CO.ValidatorContainer.prototype.removeValidatorsForHTMLIDs=function(html_id_array)
{
    var val_container;
    var vals_of_html_object;
    var mask_id;
    var html_id;
    
    for (var i=0; i < html_id_array.length; i++)
    {
        html_id = html_id_array[i];
        val_container = this.html_input_container[html_id];
        
        //if an html-object is registered for this id
        if(val_container != undefined)
        {
            //all validators of this html-object
            vals_of_html_object = val_container.validator_array;
            //removing all errors
            for( var j=0; j < vals_of_html_object.length ; j++)
            {
                vals_of_html_object[j].removeError();
            }
            
            mask_id = this.getMaskIdForHTMLElement($(html_id));
            
            if (this.mask_container[mask_id] != undefined) 
            {
                this.mask_container[mask_id][html_id] = undefined;
            }
            
            this.html_input_container[html_id] = undefined;
        }
    }
    
    
}



CO.ValidatorContainer.prototype.removeAllErrors=function()
{
    var validator_array = this.getAllValidators();
    
    for( var i=0; i < validator_array.length ; i++)
    {
        validator_array[i].removeError();
    }
}




CO.ValidatorContainer.prototype.addValidators=function(new_validators, type, mask_id)
{
   var new_val;
   var html_element;
   
   for (var i=0; i< new_validators.length; i++)
   {
       html_element = $(new_validators[i]);
       new_val = eval("new CO."+type+"(html_element)");
       
       this.add(new_val, mask_id);
   } 
    
}                                 
CO.ValidatorContainer.prototype.addGroup=function(new_validator_group, mask_id)
{
    var input_html_elements = new_validator_group.getHTMLElements();
    var validators;
    var html_input_id;
    
    if(mask_id == undefined)
    {
        mask_id = this.getMaskIdForHTMLElement(input_html_elements[0]);
    }
    
    if (mask_id == undefined)
    {
        mask_id = this.getMaskIdForHTMLElement(new_validator.getHTMLElement());
    } 
    
    for (var i = 0; i < input_html_elements.length; i++) 
    {
        html_input_id = input_html_elements[i].id;
        
        if (this.mask_container[mask_id] == undefined) 
        {
            this.mask_container[mask_id] = new Object();
        }
        
        if (this.mask_container[mask_id][html_input_id] == undefined) 
        {
            var html_input_object = new Object();
            html_input_object.validator_type_array = new Object();
            html_input_object.validator_array = new Array();
            html_input_object.alert_anchor = undefined;
            
            this.mask_container[mask_id][html_input_id] = html_input_object;
            this.html_input_container[html_input_id] = html_input_object;
        }
        
        if (this.mask_container[mask_id][html_input_id].validator_type_array[new_validator_group.type] != undefined) 
        {
            return false;
        }
        
        this.mask_container[mask_id][html_input_id].validator_array.push(new_validator_group);
        this.mask_container[mask_id][html_input_id].validator_type_array[new_validator_group.type] = 1;
        
    }
    return true;
}


CO.ValidatorContainer.prototype.add=function(new_validator, mask_id)
{
    var validators;
    var html_input_id = new_validator.getHtmlInputId();
    
    if (mask_id == undefined)
    {
        mask_id = this.getMaskIdForHTMLElement(new_validator.getHTMLElement());
    } 
    
    
    if(this.mask_container[mask_id] == undefined)
    {
        this.mask_container[mask_id] = new Object();
    }
    
    if(this.mask_container[mask_id][html_input_id] == undefined)
    {
        var html_input_object = new Object();
        html_input_object.validator_type_array = new Object();
        html_input_object.validator_array = new Array();
        html_input_object.alert_anchor = undefined;
    
        this.mask_container[mask_id][html_input_id] = html_input_object;
        this.html_input_container[html_input_id] = html_input_object;
    }
    
    if(this.mask_container[mask_id][html_input_id].validator_type_array[new_validator.type] != undefined )
    {
        return false;
    }
    
    this.mask_container[mask_id][html_input_id].validator_array.push(new_validator);
    this.mask_container[mask_id][html_input_id].validator_type_array[new_validator.type]=1;
    return true;
}

CO.ValidatorContainer.prototype.getErrorSymbol=function(input_html_id)
{
    return this.html_input_container[input_html_id].alert_anchor;
}

CO.ValidatorContainer.prototype.setErrorSymbol=function(input_html_id, error_symbol)
{
    this.html_input_container[input_html_id].alert_anchor = error_symbol;
}

CO.ValidatorContainer.prototype.getValidatorsForMaskId=function(mask_id)
{
    var validators = new Array();
    
    for (var html_input_id in this.mask_container[mask_id])
    {   
        validators = validators.concat(this.mask_container[mask_id][html_input_id].validator_array);
    }

    
    return validators;
}

CO.ValidatorContainer.prototype.getAllValidators=function(mask_id)
{
    var validators = new Array();
    
    for (var mask_id in this.mask_container)
    {   
        for (var html_input_id in this.mask_container[mask_id])
        {   
            validators = validators.concat(this.mask_container[mask_id][html_input_id].validator_array);
        }
    }
    
    return validators;
    
}

CO.ValidatorContainer.prototype.getValidatorsForMaskIdAndHTMLId=function(mask_id, html_input_id)
{
    return this.mask_container[mask_id][html_input_id].validator_array;
}

CO.ValidatorContainer.prototype.getValidatorsForHTMLId=function(html_input_id)
{
    return this.html_input_container[html_input_id].validator_array;
}

CO.ValidatorContainer.prototype.validate=function(html_input_id)
{
    var validators = this.getValidatorsForHTMLId(html_input_id);

    
    for (var i = 0; i < validators.length; i++) {
        if(typeof validators[i].validate !="function")
        {
            alert(validators[i].type);
        }
        
        if (validators[i].validate() == false) 
        {
            return;
        }
    }
}


//FIXXXMEEEE
var gVC = new CO.ValidatorContainer();
//*****************************************************************************************
// OneOfGroup Validator
//*****************************************************************************************
CO.Validator.oneOfGroupValidators = new Array(); //Merkt sich die Gruppen fÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¼r newOneOfGroup
CO.Validator.elementCnt = new Array();



CO.Validator.newOneOfGroup = function(pGroup, pId)
{
    if (!this.oneOfGroupValidators[pGroup]) 
    {
        this.oneOfGroupValidators[pGroup] = new Object();
        this.elementCnt[pGroup] = 0;
    }
    this.elementCnt[pGroup]++;
    this.oneOfGroupValidators[pGroup][this.elementCnt[pGroup]] = pId;
}



CO.Validator.validateOneOfGroup = function()
{
    var vGroup = this.input_html.co.oneOfGroup.mGroup
    var raiseError = true;
    if (this.oneOfGroupValidators[vGroup]) 
    {
        for (var vCnt = 1; vCnt <= this.elementCnt[vGroup]; vCnt++) 
        {
            if ($F(this.oneOfGroupValidators[vGroup][vCnt]) != '') 
            {
                raiseError = false;
                break;
            }
        }
    }
    else 
        alert("newOnOfGroup: Gruppe nicht gefunden: " + vGroup);
    if (raiseError) 
    {
        var vText = new CO.Text("$coValidator_oneofgroup_befÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â¼llt")
        var vNodes = '';
        for (var vCnt = 1; vCnt <= CO.Validator.elementCnt[vGroup]; vCnt++) 
        {
            vNodes += $(CO.Validator.oneOfGroupValidators[vGroup][vCnt]).getName() + ', ';
        }
        vNodes = vNodes.slice(0, vNodes.length - 2);
        this.input_html.addError(vText.replace("FIELDS", vNodes).get());
        
    }
    else 
    {
        for (var vCnt = 1; vCnt <= CO.Validator.elementCnt[vGroup]; vCnt++) 
        {
            try 
            {
                if ($(CO.Validator.oneOfGroupValidators[vGroup][vCnt]).co.msgs.size() != 0) 
                    $(CO.Validator.oneOfGroupValidators[vGroup][vCnt]).validate();
            } 
            catch (e) 
            {
                null;
            }
        }
        
    }
}

CO.RequiredValidator = Class.create(CO.Validator
                                   ,{
  									  initialize: function($super,input_html) 
  										    		{
                                                        $super(input_html);
                                                        this.type="RequiredValidator";
  													}
  									});
                                    
                                    
CO.NOfMValidator = Class.create({
  									  initialize: function(input_html_elements, group, min, max) 
  										    		{
                                                        this.type="NOfMValidator";
                                                        this.input_html_elements = input_html_elements;
                                                        this.group = group;
                                                        this.min = min;
                                                        this.max = max;
                                                        this.error_object = undefined;
                                                        this.setFieldNameList();
                                                        
                                                        
                                                        if(min === undefined)
                                                        {
                                                            this.group_type = 'MaxV'; //MaxValidator 
                                                        }
                                                        
                                                        if(max === undefined)
                                                        {
                                                            this.group_type = 'MinV'; //MinValidator 
                                                        }
                                                        
                                                        if((min != undefined) && (max != undefined))
                                                        {
                                                            this.group_type = 'NofM'; //NofMValidator
                                                        }
                                                        
                                                        if((min === undefined) && (max === undefined))
                                                        {
                                                           throw(new Error(1, "Either min or max has to be set !"));  
                                                        }
  													}
  									});
                                    
                                    
CO.NOfMValidator.prototype.addError=function(error_string)
{
    // we write only one message
    this.error_object = this.input_html_elements[0].addError(error_string);
    
    //.. but create many errorsymbols
    for (var i = 0; i < this.input_html_elements.length; i++) 
    {
        if (gVC.getErrorSymbol(this.input_html_elements[i].id) == undefined) 
        {
            var error_symbol = CO.msg.getErrorSymbol(error_string);
            gVC.setErrorSymbol(this.input_html_elements[i].id, error_symbol);
            this.input_html_elements[i].insert({
                after: error_symbol
            });
            
            if (i == 0) 
            {
                error_symbol.focus(); //we just focus the first one 
            }
        }
    }
}

CO.NOfMValidator.prototype.removeError=function()
{
    var error_symbol;
    
    if(this.error_object != undefined)
    {
        CO.msg.remove(this.error_object);
        this.error_object = undefined;
        
        for (var i = 0; i < this.input_html_elements.length; i++) 
        {
            error_symbol = gVC.getErrorSymbol(this.input_html_elements[i].id);
            
            if (error_symbol != undefined) 
            {
                gVC.setErrorSymbol(this.input_html_elements[i].id, undefined);
                error_symbol.parentNode.removeChild(error_symbol);
            }
        }
    }    
}


CO.NOfMValidator.prototype.getHTMLElements=function()
{
    return this.input_html_elements;
}


CO.NOfMValidator.prototype.setFieldNameList=function()
{
    var field_name_list = "";
    
    for (var i=0; i < this.input_html_elements.length; i++)
    {
        field_name_list += ", "+ this.input_html_elements[i].getName();
    }
    
    //" ," will be cutted
    this.field_name_list = field_name_list.substr(2);
}

CO.NOfMValidator.prototype.validate = function()
{
    this.removeError();

    switch(this.group_type)
    {    
        case "MinV" : return this.validateMin();
        case "MaxV" : return this.validateMax();
        case "NofM" : return this.validateMinMax();
    }    
} 


CO.NOfMValidator.prototype.validateMin = function()
{
    var vText = Text.NofMMin.replace("MIN", this.min).replace("FIELDLIST", this.field_name_list).get();
    var counter = this.getNumberOfFilledFields();
    
    if (counter < this.min) 
    {
        this.addError(vText);
        return false;
    }    
    return true;
}

CO.NOfMValidator.prototype.validateMax = function()
{
    var vText = Text.NofMMax.replace("MAX", this.max).replace("FIELDLIST", this.field_name_list).get();
    var counter = this.getNumberOfFilledFields();
    
    if (counter > this.max) 
    {
        this.addError(vText);
        return false;
    }    
    return true;
}


CO.NOfMValidator.prototype.validateMinMax = function()
{
    var vText = Text.NofMMinMax.replace("MIN", this.min)
                        .replace("MAX", this.max)
                        .replace("FIELDLIST", this.field_name_list).get();
    
    var counter = this.getNumberOfFilledFields();
    
    if ((counter < this.min)||(counter > this.max))
    {
        this.addError(vText);
        return false;
    }    
    return true;
}
                           
                                    
CO.NOfMValidator.prototype.getNumberOfFilledFields=function()
{
    var counter=0;
    
    for(var i=0; i < this.input_html_elements.length; i++)
    {
        if (nvl(this.input_html_elements[i].value,"") != "") 
        {
            counter++;
        }
        
    }
    
    return counter;
}

CO.RequiredValidator.prototype.validate = function()
{
    //pNode = $(pNode);
    this.removeError();
    
    var vText = Text.Pflichtfeld.replace("NAME", this.input_html.getName()).get();

    if (nvl(this.input_html.value,"") == "") 
    {
        this.addError(vText);
        return false;
    }
  
    return true;
}


CO.DateValidator = Class.create(CO.Validator
                               ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="DateValidator";						
  													}
  								});
								
CO.DateValidator.prototype.convertToDate = function(pDate, pFormat)
{
    var vDayString = pDate.substr(pFormat.toUpperCase().indexOf("DD"), 2);
    var vMonthString = pDate.substr(pFormat.toUpperCase().indexOf("MM"), 2);
    var vYearString = pDate.substr(pFormat.toUpperCase().indexOf("YYYY"), 4);
        
    return ( new Date(vYearString, vMonthString, vDayString) );
}								

CO.DateValidator.prototype.validate = function()
{
    this.removeError();
    var vValue = this.input_html.value;
    
	if (nvl(vValue, "") == "") {
        return true;
    }
    var vDateVal = new Date(vValue);
    
    var vFormat = {
        mMin: null,
        mMax: null,
        mFormat: null
    };
    
    vFormat = Object.extend(vFormat, this.input_html.co.dateFormat);
    
    var vForm = String(vFormat.mFormat);
    
    if ((vForm.length) != vValue.length) 
    {
        this.addError(Text.DatumsFormatUngueltig.get());
        return false;
    }
    
    var day = vValue.substr(vForm.toUpperCase().indexOf("DD"), 2);
    var month = vValue.substr(vForm.toUpperCase().indexOf("MM"), 2);
    var year = vValue.substr(vForm.toUpperCase().indexOf("YYYY"), 4);
    
    if (isNaN(day) || isNaN(month) || isNaN(year)) 
    {
        this.addError(Text.DatumUngueltig.get());
        return false;
    }
    
    if (!this.IsValidDate(day, month, year)) 
    {
        this.addError(Text.DatumUngueltig.get());
        return false;
    }
    
    
    //Ist Datum zu klein
    if (vFormat.mMin != null) 
    {
        var vMinDate = this.convertToDate(vFormat.mMin, vFormat.mFormat);
        
        if (vDateVal < vMinDate) 
        {
			var vText = Text.DatumZuKlein.replace("DATUM", vMinDate).get();
            this.addError(vText);
            return false;
        }
    }
    
    //Ist Datum zu groÃƒÆ’Ã†â€™Ãƒâ€ Ã¢â‚¬â„¢ÃƒÆ’Ã¢â‚¬Â¦Ãƒâ€šÃ‚Â¸?
    if (vFormat.mMax != null) 
    {
        var vMaxDate = this.convertToDate(vFormat.mMax, vFormat.mFormat);
        
        if (vDateVal > vMaxDate) 
        {
			var vText = Text.DatumZuGross.replace("DATUM", vMaxDate).get();
            this.addError(vText);
            return false;
        }
    }
    
    return true;
    
    
}


CO.DateValidator.prototype.IsValidDate = function(Day, Mn, Yr)
{
    var DateVal = nvl(Mn, 1) + "/" + nvl(Day, 1) + "/" + nvl(Yr, 2000);
    var dt = new Date(DateVal);
    
    /*
     Javascript Dates are a little too forgiving and will change the date to a reasonable
     guess if it's invalid. We'll use this to our advantage by creating the date object
     and then comparing it to the details we put it. If the Date object is different,
     then it must have been an invalid date to start with...
     */
    if (dt.getDate() != Day) 
    {
        return false;
    }
    else 
        if ((dt.getMonth() + 1) != Mn) //this is for the purpose JavaScript starts the month from 0
        {
            return false;
        }
        
        else 
            if (dt.getFullYear() != Yr) 
                return false;
    
    this.removeError();
    return true;
}

CO.StringValidator = Class.create(CO.Validator
                                 ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="StringValidator";						
  													}
  								 } );

CO.StringValidator.prototype.validate = function()
{
    this.removeError();
    var vValue = this.input_html.value;
    
        var vFormat = {
        mMinLen: null,
        mMaxLen: null,
        mJSRegEx: null,
        mPLSQLRegEx: null
    };
    
    vFormat = Object.extend(vFormat, this.input_html.co.stringFormat);

    //alert("validation started...: "+vValue+" "+vFormat.mJSRegEx);    
    //alert(vFormat.mMaxLen+' '+vFormat.mMinLen+' '+vFormat.mJSRegEx);
    
	if (nvl(vValue, "") == "") 
    {
        return true;
    }
    if ((nvl(vFormat.mMaxLen, 0) != 0) && (vValue.length > vFormat.mMaxLen)) 
    {
        this.addError(Text.StringZuLang.get());
        //vText = new CO.Text("^stringzulang");
        //this.addError(vText);                
        return false;
    }
    
    if ((nvl(vFormat.mMinLen, 0) != 0) && (vValue.length < vFormat.mMinLen)) 
    {        
        this.addError(Text.StringZuKurz.get());
        //vText = new CO.Text("^stringzukurz");
        this.addError(vText);        
        return false;
    }
    
    if ((nvl(vFormat.mJSRegEx, "") != "") && (!vValue.match(vFormat.mJSRegEx))) 
    {      
        //vText = new CO.Text("^falsches_format");
        //this.addError(vText);
        this.addError(Text.StringFalschesFormat.get());
        return false;
    }
    
    return true;
}

CO.EmailValidator = Class.create(CO.Validator
                                ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="EmailValidator";						
  													}
  								 });

CO.EmailValidator.prototype.validate = function()
{
    var vValue = this.input_html.value;
    
    this.removeError();
	if (nvl(vValue, "") == "") 
    {
        return true;
    }
    
    if (!vValue.match(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)) 
    {
        this.addError(Text.EmailUngueltig.get());
        return false;
    }
    
    return true;
}


CO.URLValidator = Class.create(CO.Validator
                              ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="URLValidator";						
  													}
  							   });

CO.URLValidator.prototype.validate = function()
{

    var vValue = this.input_html.value;
    
    this.removeError();
    var vFormat = {
        mProtokoll: null
    };
    
    vFormat = Object.extend(vFormat, this.input_html.co.URLFormat);
    
	if (nvl(vValue, "") == "") 
    {
        return true;
    }
    
    if (nvl(vFormat.mProtokoll, "true") == "true") 
    {
        if (!vValue.match(/^(http|ftp|https)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i)) 
        {
            this.addError(Text.URLUngueltig.get());
            return false;
        }
    }
    else 
    {
        if (!vValue.match(/^\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i)) 
        {
            this.addError(Text.URLUngueltig.get());
            return false;
        }
        
    }
    
    return true;
}


CO.TelefonValidator = Class.create(CO.Validator
                                   ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="TelefonValidator";						
  													}
  							        });

CO.TelefonValidator.prototype.validate = function(){
    var vValue = this.input_html.value;
    
    this.removeError();
    if (nvl(vValue, "") == "")
    { 
        return true;
    }
    //  internationales Format laut ITU-T
    //  +, country code, network prefix without the leading 0, number, no spaces, only numerals.
    if (!vValue.match(/^\+[1-9]{1}[0-9]{7,20}$/i)) 
    {
        this.addError(Text.TelefonUngueltig.get());
        return false;
    }
    return true;
    //hier checken welches RegEx sinnvoll ist!
    //  internationales Format laut ITU-T
    //  +, country code, network prefix without the leading 0, number, no spaces, only numerals.
    //     For example, the UK number 07777123456 becomes +447777123456. 
    //     The number 44 is the country code for the UK.
    //phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
    //phoneRe = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/    Allows for an international dialing code at the start and hyphenation and spaces 
    //                                                  that are sometimes entered for international phone numbers.
}


CO.IntegerValidator = Class.create(CO.Validator
                                   ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="IntegerValidator";						
  													}
  							        });

CO.IntegerValidator.prototype.validate = function()
{
    var vValue = this.input_html.value.replace(/,/, ".");
    
	this.removeError();
	
    if (nvl(vValue, "") == "") 
    {
        return true;
    }
        
    if ( vValue.indexOf(".") != -1 ) 
    {
        this.addError(Text.NurGanzeZahl.get());
        return false;
    }
    
    var vFormat = {
        mMin: null,
        mMax: null
    };
    
    vFormat = Object.extend(vFormat, this.input_html.co.numFormat);
    
    if (isNaN(vValue)) 
    {
        this.addError(Text.ZahlUngueltig.get());
        return false;
    }
    
    if ((vFormat.mMin != null) && (vFormat.mMin > Number(vValue))) 
    {
        this.addError(Text.ZahlZuKlein.get());
        return false;
    }
    
    if ((vFormat.mMax != null) && (vFormat.mMax < Number(vValue))) 
    {
        this.addError(Text.ZahlZuGross.get());
        return false;
    }
    
    return true;
}

CO.TimeValidator = Class.create(CO.Validator
                                ,{
  									  initialize: function($super, input_html) 
  										    		{
    													$super(input_html);
                                                        this.type="TimeValidator";						
  													}
  							     });

CO.TimeValidator.prototype.validate = function()
{
    var vValue = this.input_html.value;

	this.removeError();
    if (nvl(vValue, "") == "") 
    {
        return true;
    }
    
    var vFormat = {
        mMax: null,
        mMin: null,
        mFormat: null
    };
    
    
    vFormat = Object.extend(vFormat, this.input_html.co.timeFormat);
    
    var vForm = String(vFormat.mFormat);
    
    if ((vForm.length - 2) != vValue.length) 
    {
        this.addError(Text.ZeitFormatUngueltig.get());
        return false;
    }
    
    var hour = vValue.substr(vForm.toUpperCase().indexOf("HH24"), 2);
    var minute = vValue.substr(vForm.toUpperCase().indexOf("MI") - 2, 2);
    var second = vValue.substr(vForm.toUpperCase().indexOf("SS") - 1, 2);
    
		
    if (isNaN(hour) || isNaN(minute) || isNaN(second)) 
    {   
        this.addError(Text.ZeitUngueltig.get());
        return false;
    }
    
    
	if (this.IsValidTime(hour, minute, second)) 
    {
        this.removeError();
        return true;
    }
    else {

        this.addError(Text.ZeitUngueltig.get());	
        return false;
    }
    
    return true;
}


CO.TimeValidator.prototype.IsValidTime = function(hr, mi, se)
{  
    var TimeVal = "01/01/99, " + nvl(hr, 0) + ":" + nvl(mi, 0) + ":" + nvl(se, 0);
    var time = new Date(TimeVal);

	
	if ((time.getHours() != hr) || (time.getMinutes() != mi) || (time.getSeconds() != se)) 
	{   
		return false;
	}
	else 
	{
		return true;
	}
}

CO.NumberValidator = Class.create(CO.Validator
                                  ,{
  									  initialize: function($super, input_html) 
  										    		{
                                                        $super(input_html);
                                                        this.type="NumberValidator";						
  													}
  							       });

CO.NumberValidator.prototype.validate = function()
{
    //var vValue = pNode.value.replace(/,/, ".");
    this.removeError();
    var vValue = this.input_html.value.replace(/,/, ".");

    
    var vFormat = {
        mMin: null,
        mMax: null,
        mMant: null
    };
    
    vFormat = Object.extend(vFormat, this.input_html.co.numFormat);
    
	if (nvl(vValue, "") == "") 
    {
        return true;
    }
    
    if (isNaN(vValue)) 
    {
        this.addError(Text.ZahlUngueltig.get());
        return false;
    }
    
    if ((vFormat.mMin != null) && (vFormat.mMin > parseFloat(vValue))) 
    {
        this.addError(Text.ZahlZuKlein.get());
        return false;
    }
    
    if ((vFormat.mMax != null) && (vFormat.mMax < parseFloat(vValue))) 
    {
        this.addError(Text.ZahlZuGross.get());
        return false;
    }
    
    var vMantLen = vValue.substring(vValue.indexOf(".") + 1, vValue.length).length;
    
    if ((vFormat.mMant != null) && (vFormat.mMant != 0) && (vMantLen > vFormat.mMant) && vValue.match(/\./)) 
    {
        this.addError(Text.ZahlZuVieleKomma.get());
        return false;
    }
    
    return true;
}


/*
 function fixxxmeIsNumber(str) {
 for(var position=0; position<str.length; position++){
 var chr = str.charAt(position)
 if  ( (chr < "0") || (chr > "9") )
 return false;
 };
 return true;
 };
 */
/**** coMask *****/


CO.coMask = function()
{
    /*************** private ******************/
    var allowSubmit = true;
    
    function enableApplyButton()
    {
        $('MaskAction_apply').disabled = false;
    }
    
    function disapleApplyButton()
    {
        $('MaskAction_apply').disabled = true;
    }
    
    
    
    /******************************************/
    return {
    
        /*************** public *******************/
        
        allowApply: function()
        {
            allowSubmit = true;
            enableApplyButton();
        },
        
        
        checkSubmit: function()
        {
            if (allowSubmit) 
            {
                return true;
            }
            else 
            {
                return false;
            }
        },
        
        
        cancel: function()
        {
            /* FIXXME: bessere LÃƒÆ’Ã†â€™Ãƒâ€šÃ‚Â¶sung */
            allowSubmit = confirm('Wirklich abbrechen?');
            
        }
        
        
        /******************************************/
    }
}
();


/*************** helper ******************/

CO.getSelectedRadio = function(pName)
{
    for (i = 0; i < pName.length; i++) 
        if (pName[i].checked == true) 
            return pName[i].value;
    return null;
}

CO.TextArea = Class.create();

CO.TextArea.grow = function(element) 
{
  
  element.style.height = "";	
  element.style.borderBottom = "";
  
  if (element.scrollHeight > element.clientHeight)
  {
    element.style.height = element.scrollHeight+20+"px";
    element.removeClassName("taMinimized");
  }
  
  element.style.overflowX = "auto";
}

CO.TextArea.shrink = function(element)
{
  element.style.height = "";
  element.style.overflow = "hidden";
  
  if(getBrowser() == 'FF 1.5' || (getBrowser() == 'FF 2'))
  {
    if(element.defaultValue != element.value)
      element.coFire("change");
  }
  
  if (element.scrollHeight > element.clientHeight)
    element.addClassName("taMinimized");
}

CO.TextArea.markExpanded = function()
{
  $$(".taExpandable").each(
    function(element)
    {
      if (element.scrollHeight > element.clientHeight)
      {
        element.addClassName("taMinimized");
      }      
    });
}

