// JavaScript Document
function validate_form(){
	
	
	//validation for radio button
	 var myOption = -1;	 

      for (i=document.form1.price.length-1; i > -1; i--) {

      if (document.form1.price[i].checked) {

      myOption = i; i = -1;

       }

    }

      

      if (myOption == -1) {

           alert("You must select pricing option");

           //document.form1.price.focus();

           return false;
        }
//end of validation for radio button

     if (document.form1.title.value=="")

       {
	       alert("Please Enter the Title.");

		   document.form1.title.focus();

			return false;
	   } 			


      if (document.form1.url.value=="")

       {
	        alert("Please Enter the URL.");

		   document.form1.url.focus();

			  return false;
				
	    }
	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|http:\/\/|\/){1}([\w]+)(.[\w]+){1,4}$/
	
   //var urlRegxp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

		if(urlRegxp.test(document.form1.url.value) != true)

		{

          alert("URL appears to be incorrect.");

             document.form1.url.value= "";
			 
			 document.form1.url.focus();

		        return false;

		 }	
	
	
			
    if (document.form1.descript.value=="")

     {
	     alert("Please Enter Description.");

	     document.form1.descript.focus();

			return false;			
						
	   } 
	   if (document.form1.descript.value.length < 250)

			{

				alert("Please Enter Description min 250 char");

				document.form1.descript.focus();

				return false;

			}
								
		
	 if (document.form1.name.value=="")

       {
	         alert("Please Enter the Name.");

			 document.form1.name.focus();

				return false;
	   }
	 
	 
	 if (document.form1.email.value=="")

       {
	         alert("Please Enter the Email.");

			 document.form1.email.focus();

				return false;
	    } 
		var email_str=document.form1.email.value;

	     var filter=/^.+@.+\..{2,3}$/;

		 

	     if(!(filter.test(email_str)))	/* ******* Code to check email ******* */

	    {   

		
          alert("Email ID should be correct.");

			 document.form1.email.focus();

				return false;
		
		

	  } 

		
   
		
	 
	 if (document.form1.category.value=="")

       {
		   
		  
	        alert("Please Select Category.");

			document.form1.category.focus();

			  return false;
	   }
	   
	  
	   //validation for radio button and reciprocal URL
	   
	   
	 
	 /* if (document.form1.reciprocal.value=="")

       {
	         alert("Please Enter Reciprocal URL.");

			  document.form1.reciprocal.focus();

				return false;
	    } 			
	 
	 
	if(urlRegxp.test(form1.reciprocal.value) != true)

	  {

         alert("Reciprocal Link URL appears to be incorrect.Start with http:// or https://");
           
		   document.form1.reciprocal.value= "";
			
		   document.form1.reciprocal.focus();

		        return false;

		 }	
		 */
		if (document.form1.reciprocal.value=="")

       {
	        alert("Please Enter the Reciprocal URL.");

		   document.form1.reciprocal.focus();

			  return false;
				
	    }
	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|http:\/\/|\/){1}([\w]+)(.[\w]+){1,4}$/
	
   //var urlRegxp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

		if(urlRegxp.test(document.form1.reciprocal.value) != true)

		{

          alert("Reciprocal URL appears to be incorrect.");

             document.form1.reciprocal.value= "";
			 
			 document.form1.reciprocal.focus();

		        return false;

		 }	 
		 
		
		
		
		 if ( myOption==2){

	  

	  var theurl=document.form1.reciprocal.value;
	  
	  var tomatch = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|http:\/\/|\/){1}([\w]+)(.[\w]+){1,4}$/

      //var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
	  
	  if (document.form1.reciprocal.value==""){

          alert("Please Enter Reciprocal URL.");

		   document.form1.reciprocal.focus();

		 return false;

        } 

     else if (!(tomatch.test(theurl)))

      {

        alert("Please Enter valid Reciprocal URL");
		 document.form1.reciprocal.focus();

       return false;

     }

       

	}
		
      

     

     

	 //end of radio link and reciprocal link
	 
	  if (document.form1.txtCaptcha.value=="")

       {
	       alert("Please Enter Security Code.");

			document.form1.txtCaptcha.focus();

			  return false;
			  
	   } 			
	 
	 return true;
}


/*  javascript for text counting in textarea  */

function textCounter(descript, countfield, maxlimit) {

if (descript.value.length > maxlimit) // if too long...trim it!

descript.value = descript.value.substring(0, maxlimit);



// otherwise, update 'characters left' counter

else 

countfield.value = maxlimit - descript.value.length;

}




