
    var tempForm;
    function Ajaxform(formname){

        if(formname){
        this._form = formname;
        this.collect_data();
        }
    }
    
    $(document).ready(function(){
        $('#datepicker').datepicker({
					inline: true,
					dateFormat: 'dd-mm-yy'
				});
				
				$('#floating_timepicker').timepicker({
            showPeriod: true,
            showLeadingZero: true


        });
    });
    
    
    Ajaxform.prototype.collect_data = function(){

             var conf = 0;
             var param = "";
             for(var i = 0; i < this._form.length -1; i++){

                    if(this._form[i].value == ""){
                        if(this._form[i].getAttribute("validate") == "yes"){
                          $(this._form[i]).css("border","1px solid #ff0000");
                          $("#_"+this._form[i].name).html("Information is required");
                          conf++;
                        }else{
                         $(this._form[i]).css("border","1px solid #cc9933");
                         $("#_"+this._form[i].name).html("");
                          param += "&"+this._form[i].name+"="+this._form[i].value;
                        }

                    }else{

                         if(this._form[i].name.match("email") && this.email(this._form[i].value)){
                              $(this._form[i]).css("border","1px solid #cc9933");
                              $("#_"+this._form[i].name).html("");
                              param += "&"+this._form[i].name+"="+this._form[i].value;

                         }else if(this._form[i].name.match("website") && this.url(this._form[i].value)){
                              $(this._form[i]).css("border","1px solid #cc9933");
                              $("#_"+this._form[i].name).html("");
                              param += "&"+this._form[i].name+"="+this._form[i].value;

                          }else if(this._form[i].name.match("phone") && this.url(this._form[i].value)){
                              $(this._form[i]).css("border","1px solid #cc9933");
                              $("#_"+this._form[i].name).html("");
                              param += "&"+this._form[i].name+"="+this._form[i].value;


                          }else if(this._form[i].name.match("age") && this._form[i].value <= 13){
                              $(this._form[i]).css("border","1px solid #ff0000");
                              $("#_"+this._form[i].name).html("Minimum age of 14 years old");
                              conf++;
                              param += "&"+this._form[i].name+"="+this._form[i].value;

                          }else if(this._form[i].name.match("name") && this._form[i].value.length <= 2){
                              $(this._form[i]).css("border","1px solid #ff0000");
                              $("#_"+this._form[i].name).html("Please provide you full name");
                              conf++;
                              param += "&"+this._form[i].name+"="+this._form[i].value;

                          }else{

                              if(this._form[i].name.match("website") || this._form[i].name.match("email")){
                                 $(this._form[i]).css("border","1px solid #ff0000");
                                 $("#_"+this._form[i].name).html("Invalid Input");
                                 conf++;
                              }else{
                              $(this._form[i]).css("border","1px solid #cc9933");
                              param += "&"+this._form[i].name+"="+this._form[i].value;
                              $("#_"+this._form[i].name).html("");
                              }


                         }

                    }

             }
             
             if(conf == 0){
                this.toServer(param);
             }
   }
   
   Ajaxform.prototype.email = function(address){

      var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      return address.match(re)
   }
   
   Ajaxform.prototype.url = function(url){

      if(url.match("http://")){
      var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	    return regexp.test(url);
      }else{
      var regexp = /(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	    return regexp.test(url);
      }


   }
   
   
   
   Ajaxform.prototype.phone = function(num){

            if(isNaN(num)){
              return false;
            }


   }
   
   
   Ajaxform.prototype.toServer = function(param){


            var xmlhttp = new xmlhttprequest();
              var func = this;
              var statechanged = function(){

                     if(xmlhttp.readyState == 4 ){

                       var result = xmlhttp.responseText.split("&");
                       var move = 0;
                       for(var x = 0; x < result.length - 1; x++){

                            var g = result[x].split("=");
                            if(g[1] == "no"){
                               for(var e = 0; e < func._form.length - 1; e++){
                                  if(func._form[e].name == g[0]){
                                      $(func._form[e]).css("border","1px solid #ff0000");
                                      $("#_"+func._form[e].name).html("Invalid Input");

                                      move++;
                                  }
                               }
                            }

                       }
                      (move == 0)  ? func.clearForm() : false;
                    }


                }


      var url = "config/post_request.php";
      var params = "ajax=on&contact_process=true"+param;
      var send = new Ajax(xmlhttp,url,params,statechanged);


   }
   
   Ajaxform.prototype.clearForm = function(){

      for(var i = 0; i < this._form.length-1; i++){

          this._form[i].value = "";

      }

      var tempH = TFD("#contact_wrapper_inner").offsetHeight;
      TFD("#contact_wrapper_inner").style.height = TFD("#contact_wrapper_inner").offsetHeight + "px";
      $("#contact_form").hide();
      $("#contact_wrapper_inner").animate({"height": "300px"},2000);
      $("#success_form_text").delay(2000).fadeIn(3000);

      $("#contact_wrapper_inner").delay(27000).animate({"height": tempH+"px"},2000);
      $("#success_form_text").delay(24000).fadeOut();
      $("#contact_form").delay(30000).fadeIn(3000);

   }
   

