
var flag=1;
function resetme()
{
	document.getElementById("contact").value="";
	document.getElementById("companyname").value="";
	document.getElementById("email").value="";
	document.getElementById("country").value="";
	document.getElementById("city").value="";
	document.getElementById("phone").value="";
	document.getElementById("url").value="";
	document.getElementById("yahooid").value="";
	document.getElementById("msnid").value="";
	document.getElementById("aolid").value="";
	document.getElementById("skypeid").value="";
	document.getElementById("chkphone").checked=false;
	document.getElementById("chkemail").checked=false;
	document.getElementById("chkmsgr").checked=false;
	document.getElementById("website").value="";
	document.getElementById("project").value="";
	document.getElementById("budget").value="";
	document.getElementById("hear").value="";
	
}

function resetform()
{
	elementForms = document.getElementById('form1');		 
		for (var intCounter = 0; intCounter < elementForms.length; intCounter++)
		{
			if(elementForms[intCounter].id =='chkphone')
			{
				//$('#communication_div').removeClass("error");

              	$('#communication_msg').html("");
				document.getElementById('chkphone').checked=false;
				document.getElementById('chkemail').checked=false;
				document.getElementById('chkmsgr').checked=false;
						
				flag1=0;
			}
			else
			{
			// $('#' + elementForms[intCounter].id + '_div').removeClass("error");

              $('#' + elementForms[intCounter].id + '_msg').html("");

             // $('#' + o.id + '_li').addClass("success");
			 
			  elementForms[intCounter].value="";
			}
			
		}
		flag=0;
		
}
function fsubmit()
{
	if(document.getElementById('contact').value=='')
	{
			 // $('#contact_div').addClass("error");

              $('#contact_msg').html('Please enter contact person');

             // $('#contact_div').removeClass("success");
			  flag=1;
	}
	if(document.getElementById('email').value=='')
	{
		      //$('#email_div').addClass("error");

              $('#email_msg').html('Please enter email');

             // $('#email_div').removeClass("success");
			  flag=1;
	}
	if(document.getElementById('website').value=='')
	{
		     // $('#website_div').addClass("error");

              $('#website_msg').html('Please enter website type(s)');

            //  $('#website_div').removeClass("success");
			  flag=1;
	}
	if(document.getElementById('project').value=='')
	{
		    //  $('#project_div').addClass("error");

              $('#project_msg').html('Please enter project description');

             // $('#project_div').removeClass("success");
			  flag=1;
	}
	if(document.getElementById('budget').value=='')
	{
		     // $('#budget_div').addClass("error");

              $('#budget_msg').html('Please select project budget');

              //$('#budget_div').removeClass("success");
			  flag=1;
	}
	
	if(!document.getElementById('chkphone').checked && !document.getElementById('chkemail').checked && !document.getElementById('chkmsgr').checked)
	{
			//$('#communication_div').addClass("error");

              $('#communication_msg').html('Check atleast one communication method');

            //  $('#communication_div').removeClass("success");
			  flag1=1;
	}
	/*else
	{
			$('#communication_div').removeClass("error");

              $('#communication_msg').html("");
			  flag1=0;
	}*/
	//alert("flag1"+flag1);
      //  alert("flag"+flag);
	if(flag==0 && flag1==0)
	{
		//alert('Form validated');	
		return true;
	}
	else
	{
		alert('Please check all the fields');
		return false;
	}
}

new function() {

      

    $.fn.validate = {

        init: function(o) {
		
          if(o.name == 'contact') { this.contact(o) };

          
          if(o.name == 'email') { this.email(o) };

          if(o.name == 'phone') { this.phone(o) };
		  
		  if(o.name == 'url') { this.url(o) };
		  
		  if(o.name == 'yahooid') { this.yahooid(o) };
		  
		  if(o.name == 'msnid') { this.msnid(o) };
		   
		  if(o.name == 'aolid') { this.aolid(o) };
			
		 if(o.name == 'skypeid') { this.skypeid(o) };
		 
		if(o.name == 'project') { this.project(o) };	 
		
		if(o.name == 'website') { this.website(o) };
		
		if(o.name == 'budget') {this.budget(o)};
        },

		 contact: function(o) {
         
			 if (o.value.length!=0) {
			
            doSuccess(o);

            } else {

              doError(o,'Please enter contact person');

            };

        },
       
        
		phone: function(o) {
			
		var values = " 1234567890-+()";
		var err=0;
		  for (var i=0; i < o.value.length; i++)
		  {
			if (values.indexOf(o.value.charAt(i)) < 0)
			{
			   err=1;
			}
			else
			{
				 
			};
		  }
		  if(err==0)
		  {
			  doSuccess(o);
		  }
		  else
		  {
			 doError(o,'invalid phone');  
		  };
          

           
        },
        email: function(o) {

          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

           if (o.value.match(email)) {

              doSuccess(o);

            } else {

              doError(o,'not a valid email');

            };

        },

		url: function(o) {

         var val= /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 			if(o.value!="")
			{
				if (o.value.match(val)) {

              doSuccess(o);

            } else {

              doError(o,'not a valid url');

            };
			}
			else
			{
			};

        },
		 yahooid: function(o) {

          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(o.value!="")
			{
			   if (o.value.match(email)) {
	
				  doSuccess(o);
	
				} else {
					//alert('invalid');
				  doError(o,'not a valid id');
	
				};
			}
			else
			{
			};

        },
		 msnid: function(o) {

          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(o.value!="")
			{
			   if (o.value.match(email)) {
	
				  doSuccess(o);
	
				} else {
	
				  doError(o,'not a valid id');
	
				};
			}
			else
			{
			};

        },
		 aolid: function(o) {

          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(o.value!="")
			{
			   if (o.value.match(email)) {
	
				  doSuccess(o);
	
				} else {
	
				  doError(o,'not a valid id');
	
				};
			}
			else
			{
			};

        },
		 skypeid: function(o) {

          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(o.value!="")
			{
			   if (o.value.match(email)) {
	
				  doSuccess(o);
	
				} else {
	
				  doError(o,'not a valid id');
	
				};
			}
			else
			{
			};

        },
		
		website: function(o) {
         
			 if (o.value.length!=0) {

             

            doSuccess(o);

            

            } else {

              doError(o,'Please enter type of website');

            };

        },
		project: function(o) {
         
			 if (o.value.length!=0) {

             

            doSuccess(o);

            

            } else {
			
              doError(o,'Please enter project description');

            };

        },
		budget:function(o){
			if (o.value!="") {

             

            doSuccess(o);

            

            } else {

              doError(o,'Please select project budget');

            };
		}
        

     };



     function doSuccess(o) {

             // $('#' + o.id + '_img').html('<img src="" border="0" style="float:left;" />');

             //my comment $('#' + o.id + '_div').removeClass("error");

              $('#' + o.id + '_msg').html("");

             // $('#' + o.id + '_li').addClass("success");
			  flag=0;
                            flag1=0;
			  

     }



     function doError(o,m) {

             // $('#' + o.id + '_img').html('<img src="images/exclamation.gif" border="0" style="float:left;" />');

           //my coment   $('#' + o.id + '_div').addClass("error");

              $('#' + o.id + '_msg').html(m);

              //my comment$('#' + o.id + '_div').removeClass("success");
			  flag=1;
                              flag1=1;

     }

    


};


$(document).ready(function()

{
  $("input").blur(function() {

          $(this).validate.init(this);

  });

$("select").blur(function() {

          $(this).validate.init(this);

  });

$("textarea").blur(function() {

          $(this).validate.init(this);

  });


 

  



 





  /*$("#password").keyup(function() {

          $(this).copyTo("#password_copy","value");

  });*/



  

});// JavaScript Document
