String.prototype.trim = function() {
		a = this.replace(/^\s+/, '');
		return a.replace(/\s+$/, '');
	};

function validate_form(){

    var msg 			= '' ;
    //var focusField 		= '' ;
    var firstname               = document.getElementById('firstname').value ;
    var lastname		= document.getElementById('lastname').value ;
    var organization            = document.getElementById('organization').value ;
    var designation		= document.getElementById('designation').value ;
    var username 		= document.getElementById('username').value ;
    var password    		= document.getElementById('password').value ;
    var passwordconfirm		= document.getElementById('passwordconfirm').value ;
    var email 		        = document.getElementById('email').value ;
    var telephone 		= document.getElementById('telephone').value ;
    var find    		= document.getElementById('find').value ;
    var findans 		= document.getElementById('findans').value ;
    var verification            = document.getElementById('verification').value ;
   // var checkbox		= document.frmregistration.agreeterms.checked ;
    var illegalChars = /\W/;

    if ('' == firstname) {
            msg = lang[250]['short'] + '<br>' ;
            //focusField = 'firstname' ;
    }


    if ('' == lastname) {
            msg = msg + lang[251]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'lastname' ;
            }*/
    }

     if ('' == organization) {
            msg = msg + lang[252]['short'] + '<br>' ;
            /* if ('' == focusField) {
                focusField = 'organization' ;
             }*/
    }

    if ('' == designation) {
            msg = msg + lang[253]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'designation' ;
            }*/
    }

    if ('' == username) {
            msg = msg + lang[254]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'username' ;
            }*/
    }
     else if ((username.length < 3) || (username.length > 50)) {
        msg = msg + lang[265]['short'] + '<br>' ;
        /*if ('' == focusField) {
            focusField = 'username' ;
        }*/
    }
   else if (isProper(username) == false) {

       msg = msg + lang[266]['short'] +  '<br>';
      // focusField='username';
    }

     if ('' == password) {
            msg = msg + lang[255]['short'] + '<br>' ;
            /*if ('' == focusField) {
                    focusField = 'password' ;
            }*/
    }

     if ('' == passwordconfirm) {
            msg = msg + lang[256]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'passwordconfirm' ;
            }*/
    }

    if(password !='' && passwordconfirm !='' ){
        if(password != passwordconfirm){
            msg = msg + lang[257]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'password' ;
            }*/
            document.getElementById('password').value = "";
            document.getElementById('passwordconfirm').value = "";
        } else if(password.length < 6){
                msg = msg + lang[267]['short'] + '<br>' ;
            /*if ('' == focusField) {
                    focusField = 'password' ;
            }*/
            document.getElementById('password').value = "";
            document.getElementById('passwordconfirm').value = "";

        }
    }

   var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if(email==''){
        msg = msg + lang[258]['short'] + '<br>' ;
            /*if ('' == focusField) {
                    focusField = 'email' ;
            }  */
   }else   if (!(filter.test(email))) {
            msg = msg + lang[259]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'email' ;
            }*/
   }


    if ('' == telephone) {
            msg = msg + lang[260]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'telephone' ;
            }*/
    }

    if ('' == find) {
            msg = msg + lang[261]['short'] + '<br>' ;
    }

     if((find =='reseller')||(find=='searchengine')||(find =='tradeshow')||(find=='others')){
                if ('' == findans) {
                                msg = msg + lang[262]['short'] + '<br>' ;
                }
     }

     if ('' == verification) {
            msg = msg + lang[264]['short'] + '<br>' ;
           /* if ('' == focusField) {
                    focusField = 'verification' ;
            }*/
    }

   /*  if(checkbox == false){
             msg = msg + lang[263]['short'] + '<br>' ;
     }
    */

    if ('' != msg) {
        $.prompt(msg);
        /*switch (focusField)
        {
                case 'firstname':
                        document.getElementById('firstname').select();
                        document.getElementById('firstname').focus();
                        break;

                case 'lastname':
                        document.getElementById('lastname').select();
                        document.getElementById('lastname').focus();
                        break;

                case 'username':
                        document.getElementById('username').select();
                        document.getElementById('username').focus();
                        break;

                case 'email':
                        document.getElementById('email').select();
                        document.getElementById('email').focus();
                        break;

                case 'organization':
                        document.getElementById('organization').select();
                        document.getElementById('organization').focus();
                        break;

                case 'designation':
                        document.getElementById('designation').select();
                        document.getElementById('designation').focus();
                        break;

                case 'password':
                        document.getElementById('password').select();
                        document.getElementById('password').focus();
                        break;

                case 'passwordconfirm':
                        document.getElementById('passwordconfirm').select();
                        document.getElementById('passwordconfirm').focus();
                        break;

                case 'telephone':
                        document.getElementById('telephone').select();
                        document.getElementById('telephone').focus();
                        break;

                case 'findans':
                        document.getElementById('findans').select();
                        document.getElementById('findans').focus();
                        break;

                case 'verification':
                        document.getElementById('verification').select();
                        document.getElementById('verification').focus();
                        break;
        }*/

        return false ;
    }

    return true ;

}

function isProper(string) {
   if (!string) return false;
   var iChars = "*|,\":<>[]{}`\';()@&$#%+=~ ";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
}

function Previous(prev) {
	window.location.href=prev;
}
