/*CheckForm V1.04*/

var NCheckField='';
var MasErField= new Array();
var TextError='';
var Separator="\n";

function CheckForm(){	this.CheckEmail= function(email){		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 		return filter.test(email);		}

    /* CheckDate1 yyyy-mm-dd*/
	this.CheckDate1= function(email){
		var filter  = /^[0-9]{4}(-)[0-9]{2}(-)[0-9]{2}$/;
 		return filter.test(email);
		}
    /* CheckDate2  dd.mm.yyyy*/
	this.CheckDate2= function(email){
		var filter  = /^[0-9]{2}(\.)[0-9]{2}(\.)[0-9]{4}$/;
 		return filter.test(email);
		}


	this.CheckEmpty= function(x){		var filter  = /\S/;
 		return filter.test(x);		}

	this.Check0= function(x){		return x!=0;		}
	this.CheckEqual= function(x,y){		return x==y;		}

	this.CheckInt= function(x){
		var filter  = /^\d+$/;
 		return filter.test(x);
		}

	this.CheckFloat= function(x){
		var filter  = /^(\d+)(\.?)(\d*)$/;
 		return filter.test(x);
		}

	this.Check_checkbox=function(obj){		return obj.checked;		}

	this.Check_radio=function(obj){		var l=obj.length;
		var z=false;
		for(var i=0;i<l;i++){            if (obj[i].checked) z=true;			}
		return z;
		}

    /*CheckForm*/
	this.CheckFORM=function(mas,isFocus){        var l=mas.length;
        for(var i=0;i<l;i++){
            if (mas[i][1]==null) {alert("Error field "+i);return false;}
        	switch(mas[i][0]){        		case 'CheckDate1':
        			r=this.CheckDate1(mas[i][1].value);
        		break;
        		case 'CheckDate2':
        			r=this.CheckDate2(mas[i][1].value);
        		break;        		case 'CheckEmail':
        			r=this.CheckEmail(mas[i][1].value);
        		break;
        		case 'CheckEmpty':
        			r=this.CheckEmpty(mas[i][1].value);
        		break;
        		case 'Check0':
        			r=this.Check0(mas[i][1].value);
        		break;
        		case 'CheckEqual':
        			if (mas[i][3]==null) {alert("Error field "+i);return false;}
        			r=this.CheckEqual(mas[i][1].value,mas[i][3].value);
        		break;
        		case 'CheckInt':
        			r=this.CheckInt(mas[i][1].value);
        		break;
        		case 'CheckFloat':
        			r=this.CheckFloat(mas[i][1].value);
        		break;
        		case 'Check_checkbox':
        			r=this.Check_checkbox(mas[i][1]);
        		break;
        		case 'Check_radio':
        			r=this.Check_radio(mas[i][1]);
        		break;
        	}

        	if (!r){        		if (isFocus && mas[i][0]!='Check_radio') mas[i][1].focus();        		if (mas[i][2]!='') alert(mas[i][2]);
        		 NCheckField=i;
        		return false;        	}        }
    return true;	}
    /**/


    /*CheckForm ALL*/
	this.CheckFORMAll=function(mas){		var T=true;
        var l=mas.length;
        for(var i=0;i<l;i++){
            if (mas[i][1]==null) {alert("Error field "+i);return false;}
        	switch(mas[i][0]){        		case 'CheckDate1':
        			r=this.CheckDate1(mas[i][1].value);
        		break;
        		case 'CheckDate2':
        			r=this.CheckDate2(mas[i][1].value);
        		break;
        		case 'CheckEmail':
        			r=this.CheckEmail(mas[i][1].value);
        		break;
        		case 'CheckEmpty':
        			r=this.CheckEmpty(mas[i][1].value);
        		break;
        		case 'Check0':
        			r=this.Check0(mas[i][1].value);
        		break;
        		case 'CheckEqual':
        			if (mas[i][3]==null) {alert("Error field "+i);return false;}
        			r=this.CheckEqual(mas[i][1].value,mas[i][3].value);
        		break;
        		case 'CheckInt':
        			r=this.CheckInt(mas[i][1].value);
        		break;
        		case 'CheckFloat':
        			r=this.CheckFloat(mas[i][1].value);
        		break;
        		case 'Check_checkbox':
        			r=this.Check_checkbox(mas[i][1]);
        		break;
        		case 'Check_radio':
        			r=this.Check_radio(mas[i][1]);
        		break;
        	}


        	if (!r) {        		T=false;        		MasErField[i]=1;
        		if (mas[i][2]!='') TextError+=mas[i][2]+Separator;
        	}
        	else{        	 	MasErField[i]=0
        	}
        }/*for*/
	return T;
	}
    /**/
}
