function checkFormObj(fields,form,popUpObj)
{
    this.formValueStr = new String();
    this.popUpObj = popUpObj;
    this.valueInt = 0;
    this.minInt = 0;
    this.maxInt = 0;
    this.form = form;
    this.fields = fields;
    this.errorArr = new String();
    this.errorMessage = new String();
    this.name = new String();
    this.type = new String();
    this.min =0;
    this.max = 0
    this.error = new String(); 
    this.formValue = new String();
    checkFormObj.prototype.liveSite = liveSite;

    this.checkForm = function ()
    {      
        this.errorMessage = '';
        for(var i = 0; i < this.fields.length; i++)
        {
            this.name =this.fields[i][0];
            this.type =this.fields[i][1];
            this.min =this.fields[i][2];
            this.max =this.fields[i][3];
            this.error = this.fields[i][4]; 
            
            if(this.name =='file')
            {
                this.checkFileTypes();
            }
            else if(this.type == 'multiFile')
            {
                this.multiFile();
            }
            else if(this.form.elements[this.name]) 
            {   
                this.formValue = this.form.elements[this.name].value;
                this.formValueStr = this.formValue;
                this.valueInt = parseInt(this.formValue.length);
                this.minInt = parseInt(this.min);
                this.maxInt = parseInt(this.max);
                switch(this.type)
                {
                    case 'email':
                    this.checkEmail();        
                    break;

                    case 'multiEmail':
                    this.checkMultiEmail();        
                    break;
					
					case 'checkMultiEmailOrNull':
                    this.checkMultiEmailOrNull();        
                    break;
        
                    case 'number':
                    this.checkNumber();        
                    break;
        
                    case 'numberPhone':
                    this.checkNumberPhone();        
                    break;
        
                    case 'numberNull':
                    this.checkNumberNull();        
                    break;

                    case 'string':
                    this.checkString();        
                    break;
                    
                    case 'password':
                    this.checkPassword();        
                    break;

                    case 'boolean':
                    this.bool();        
                    break;
                    
                    case 'notNull':
                    this.notNull()
                    break;

                    case 'dateCompare':
                    this.dateCompare();
                    break;
                    
                    case 'dateCompareNotNull':
                    this.dateCompareNotNull();
                    break;

                    case 'all':
                    this.checkAll(  );        
                    break;
					
					case 'checkbox':
                    this.checkboxes();        
                    break;

                    case 'multiFile':
                    this.multiFile();        
                    break;
                }   
            }
            else if(this.typeOf(this.form.elements[this.name]) == 'array')
            {
                 this.checkBoxGroup();
            } 
        }   
        
        
        if(this.errorMessage.length > 3)
        {
           
            this.popUpObj.getPopUp(this.errorMessage); 
        }
        else
        {
            this.form.submit();
        } 
    }     
    
    this.checkFormApplay = function ()
    {      
        this.errorMessage = '';
        for(var i = 0; i < this.fields.length; i++)
        {
            this.name =this.fields[i][0];
            this.type =this.fields[i][1];
            this.min =this.fields[i][2];
            this.max =this.fields[i][3];
            this.error = this.fields[i][4]; 
            if(this.name =='file')
            {
                this.checkFileTypes();
            }
            else if(this.type == 'multiFile')
            {
                this.multiFile();
            }
            else if(this.form.elements[this.name])
            {   
                this.formValue = this.form.elements[this.name].value;
                this.formValueStr = this.formValue;
                this.valueInt = parseInt(this.formValue.length);
                this.minInt = parseInt(this.min);
                this.maxInt = parseInt(this.max);
                switch(this.type)
                {
                    case 'email':
                    this.checkEmail();        
                    break;

                    case 'multiEmail':
                    this.checkMultiEmail();        
                    break;

					case 'checkMultiEmailOrNull':
                    this.checkMultiEmailOrNull();        
                    break;
					
					case 'checkbox':
                    this.checkboxes();        
                    break;
        
                    case 'number':
                    this.checkNumber();        
                    break;
                    
                    case 'numberPhone':
                    this.checkNumberPhone();        
                    break;
        
                    case 'string':
                    this.checkString();        
                    break;
                    
                    case 'boolean':
                    this.bool();        
                    break;
          
			        case 'password':
                    this.checkPassword();        
                    break;

                    case 'notNull':
                    this.notNull()
                    break;

                    case 'dateCompare':
                    this.dateCompare();
                    break;
                    
                    case 'dateCompareNotNull':
                    this.dateCompareNotNull();
                    break;

                    case 'numberNull':
                    this.checkNumberNull();        
                    break;

                    case 'all':
                    this.checkAll(  );        
                    break;

                    case 'multiFile': 
                    this.multiFile();        
                    break;
                }   
            } 
            else if(this.typeOf(this.form.elements[this.name]) == 'array')
            {
                 this.checkBoxGroup();
            } 
  
        }
        
        if(this.errorMessage.length > 3)
        {
           
            this.popUpObj.getPopUp(this.errorMessage); 

        }
        else
        {
            return 1;
        }
    }       
    

   this.checkEmail = function()
   {
       var boolEmail = true;
       var str = new String();
       str = this.formValue;
       var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i ;
       boolEmail = re.test(str);
                                                                                                    
       if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
       {
           if(boolEmail == false)
           {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
           }
       }
       else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
       {
           if(boolEmail == false)
           {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
           }
       }
       else
       {
           this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
       }
   }
	  
	this.checkboxes = function()
    {
        for(var i = 0; i < this.form.elements.length; i++)
        {
            if(this.form.elements[i].type == 'checkbox' && this.name == this.form.elements[i].name)
            {
                var ext = this.form.elements[i].checked;
                if(ext)
                {
                    return 1;
                }
                else
                {
                    this.errorMessage = this.errorMessage + this.error+'<br/><br/>';
                }
            }
        }
        
    }

	this.checkMultiEmail = function ()
    {
        var arrayOfEmails = new Array();
        arrayOfEmails = this.formValue.split(',');
        boolEmail = true;
        for(i = 0; (i < arrayOfEmails.length )&& (boolEmail == true) ;i++)
        {                
            var str = new String();
            str = arrayOfEmails[i].toString();
            var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i ;
            boolEmail = re.test(str);                                                              
        }
        if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
        {
            if(boolEmail == false)
            {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
            }
        }
        else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
        {
            if(boolEmail == false)
            {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
            }
        }
        else
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }

    }

    this.checkAll = function()
    {
        if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
        {
            return 1;
        }
        else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
        {
            return 1;
        }
        else
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
        
    }        


    this.checkMultiEmail = function ()
    {
        var arrayOfEmails = new Array();
        arrayOfEmails = this.formValue.split(',');
        boolEmail = true;
        for(i = 0; (i < arrayOfEmails.length )&& (boolEmail == true) ;i++)
        {                
            var str = new String();
            str = arrayOfEmails[i].toString();
            var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i ;
            boolEmail = re.test(str);
        }
        if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
        {
            if(boolEmail == false)
            {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
            }
        }
        else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
        {
            if(boolEmail == false)
            {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
            }
        }
        else
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
    }

    this.checkNumber = function()
    {
       var ValidChars = "0123456789.";
       var IsNumber=true;
       var Char;
       var sText = this.formValue;

        if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
        {
            for (i = 0; i < sText.length && IsNumber == true; i++) 
            { 
                Char = sText.charAt(i); 
                if (ValidChars.indexOf(Char) == -1) 
                {
                    IsNumber = false;
                    this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
                }
            }
        }
        else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
        {
            for (i = 0; i < sText.length && IsNumber == true; i++) 
            { 
                Char = sText.charAt(i); 
                if (ValidChars.indexOf(Char) == -1) 
                {
                    IsNumber = false;
                    this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
                }
            }
        }
        else
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
    }
    
    this.checkNumberPhone = function()
    {
       var ValidChars = "0123456789.-()";
       var IsNumber=true;
       var Char;
       var sText = this.formValue;

        if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
        {
            for (i = 0; i < sText.length && IsNumber == true; i++) 
            { 
                Char = sText.charAt(i); 
                if (ValidChars.indexOf(Char) == -1) 
                {
                    IsNumber = false;
                    this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
                }
            }
        }
        else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
        {
            for (i = 0; i < sText.length && IsNumber == true; i++) 
            { 
                Char = sText.charAt(i); 
                if (ValidChars.indexOf(Char) == -1) 
                {
                    IsNumber = false;
                    this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
                }
            }
        }
        else
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
    }     
    
    this.checkNumberNull = function()
    {
       var ValidChars = "0123456789.";
       var IsNumber=true;
       var Char;
       var sText = this.formValue;

       if( sText.length > 0)
       {
         for (i = 0; i < sText.length && IsNumber == true; i++) 
          { 
              Char = sText.charAt(i); 
              if (ValidChars.indexOf(Char) == -1) 
              {
                  IsNumber = false;
                  this.errorMessage = this.errorMessage + this.error + '<br/><br/>'; 
              }
          }
       }
    }   

    this.checkString = function ()
    {
        var str = this.formValue; 
        var boolStr = true;
        var re = /[^a-zA-Z \s]/g;
        if (re.test(str))
        { 
            boolStr = false;
        }    
        
        if((this.valueInt >= this.minInt) && (this.valueInt <= this.maxInt) && (this.maxInt > 0) && (this.minInt <= this.maxInt))
        {
           if(boolStr == false)
           {
               this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
           }
        }
        else if((this.valueInt >= this.minInt) &&  (this.maxInt == 0))
        {
           if(boolStr == false)
           {
               this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
           }
        }
        else
        {
             this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
    }
    
    this.bool = function()
    {
        var varBool = false;
        if(this.formValue == true || this.formValue == 1)
        {
            varBool = true;
        }
        else
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
    }
    
    this.checkPassword = function()
    {
        if(this.formValue != this.form.elements['password2'].value)
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
    }
    
    this.notNull = function()
    {
        if(this.formValue == 0 || this.formValue == '')
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
        else
        {
            return 1;
        }
    }
    
    this.dateCompare = function()
    {
        var splitStart = new Array();
        var splitEnd = new Array();
        splitStart = this.formValue.split(':'); 
        splitEnd = this.form.elements['dateEnd'].value.split('-'); 
        var yearStart = splitStart[0]; 
        var yearEnd = splitEnd[0];
        var mounthStart= splitStart[1] ; 
        var mounthEnd = splitEnd[1];
        var dayStart = splitStart[2] ; 
        var dayEnd = splitEnd[2];
        if((this.formValue  >=  this.form.elements['dateEnd'].value) && this.formValue != '' && this.form.elements['dateEnd'].value != ''&& this.form.elements['dateEnd'].value != '0000-00-00' )
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
        else
        {
            return 1;
        }
    }
    
    this.dateCompareNotNull = function()
    {
        var splitStart = new Array();
        var splitEnd = new Array();
        splitStart = this.formValue.split(':'); 
        splitEnd = this.form.elements['dateEnd'].value.split(':'); 
        var yearStart = splitStart[0]; 
        var yearEnd = splitEnd[0];
        var mounthStart= splitStart[1] ; 
        var mounthEnd = splitEnd[1];
        var dayStart = splitStart[2] ; 
        var dayEnd = splitEnd[2];
        if((this.formValue  >=  this.form.elements['dateEnd'].value) || this.formValue == '' || this.form.elements['dateStart'].value == '' || this.form.elements['dateEnd'].value == '' || this.form.elements['dateEnd'].value == '0000-00-00' )
        {
            this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
        }
        else
        {
            return 1;
        }
    }
    
    this.multiFile = function()
    {                                          
        var errorAllow = 0;
        if(this.typeOf(this.form.elements['additionalFieldIploaded'])== 'undefined')
        {
            var isUpload = 0; 
        }
        else if(this.form.elements['additionalFieldIploaded'].value == 1)
        {
            var isUpload = 1;
        }
        else
        {
            var isUpload = 0;
        }
        if(this.typeOf(this.form.elements[this.name]) == 'array')
        {
            for(var i = 0; i < this.form.elements[this.name].length; i++)
            {
                alt = this.form.elements[this.name][i].alt; 

                if(this.form.elements[this.name][i].value == '')
                {
                    if(errorAllow == 0)
                    {
                        this.errorMessage = this.errorMessage + this.error +'<br/>('+ alt+')<br/><br/>';
                        errorAllow = 1;
                    }    
                }
                else
                {
                    var alt = this.form.elements[this.name][i].alt;
                    var ext = this.form.elements[this.name][i].value;
                    ext = ext.substr(ext.length-3,ext.length);  
                    val = alt.indexOf(ext,0);                    
                    if(val == -1)
                    {
                        if(errorAllow == 0)
                        {
                            this.errorMessage = this.errorMessage + this.error +'<br/>('+ alt+')<br/><br/>';
                            errorAllow = 1;
                        }
                    }
                    else if(this.min ==2 && ext < 3)
                    {
                        if(errorAllow == 0)
                        {
                            this.errorMessage = this.errorMessage + this.error +'<br/>('+ alt+')<br/><br/>';
                            errorAllow = 1;
                        }
                    }                
                }    
            }
        }
        else
        {
            if(typeof(this.form.elements[this.name]) != 'undefined')
            {
                alt = this.form.elements[this.name].alt; 
                if(this.form.elements[this.name].value == '')
                {
                    this.errorMessage = this.errorMessage + this.error +'<br/>('+ alt+')<br/><br/>';
                }
                else
                {
                    var alt = this.form.elements[this.name].alt;
                    var ext = this.form.elements[this.name].value;
                    ext = ext.substr(ext.length-3,ext.length);  
                    val = alt.indexOf(ext,0);                    
                    if(val == -1)
                    {
                         this.errorMessage = this.errorMessage + this.error +'<br/>('+ alt+')<br/><br/>';
                    }
                    else if(this.min ==2 && ext < 3)
                    {
                        this.errorMessage = this.errorMessage + this.error +'<br/>('+ alt+')<br/><br/>';
                    }                
                }
            }
            else if(isUpload == 0)
            {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
            }
        }
    }

    this.checkBoxGroup = function()
    {
        for(var i = 0; i < this.form.elements[this.name].length; i++)
        {
            if(this.form.elements[this.name][i].checked == false)
            {
                this.errorMessage = this.errorMessage + this.error +''+ '<br/><br/>';
                break;
            }        
        }        
    } 
    
    this.checkFileTypes = function()
    {
        for(var i = 0; i < this.form.elements.length; i++)
        {
            if(this.form.elements[i].type == 'file' )
            {
                var req = /additionalField-/;
                if (req.test(this.form.elements[i].name))
                { 
                    boolStr = 0;
                }
                else
                {
                    boolStr = 1;
                }  
                if(boolStr == 1)
                {
                    var alt = this.form.elements[i].alt;
                    var ext = this.form.elements[i].value;
                    ext = ext.substr(ext.length-3,ext.length);  
                    val = alt.indexOf(ext,0);
                    if(val == -1)
                    {
                         this.errorMessage = this.errorMessage + this.error +'-'+ this.form.elements[i].value+ '<br/><br/>';
                    }
                    else if(this.min ==2 && ext < 3)
                    {
                        this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
                    }
                }
            }
        }
    }
    
    this.checkMultiEmailOrNull = function ()
    {
        if(this.formValue != '')
        {
            var arrayOfEmails = new Array();
            arrayOfEmails = this.formValue.split(',');
            boolEmail = true;
            for(i = 0; (i < arrayOfEmails.length )&& (boolEmail == true) ;i++)
            {                
                var str = new String();
                str = arrayOfEmails[i].toString();
                var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i ;
                boolEmail = re.test(str);
            }
            
            if(boolEmail == false)
            {
                this.errorMessage = this.errorMessage + this.error + '<br/><br/>';
            }
          
        }
    }
    
    this.typeOf =function(obj) 
    {
        if( typeof(obj) == 'object') 
        {
            if (obj.length)
            {
                return 'array';
            }    
            else
            {
                return 'object';
            }    
        }
        else
        {
            return typeof(obj);
        }    
    }    
    
}
    


