///For TRIM White Spaces////////////////////////
  function trim(str) 
       { 
	    return str.replace(/^\s*|\s*$/g,"");
      }
	  
///////////Email
function isAValidEmail( emailField )
{ 
   // var emailregex=/^[\w]+\+?\w*@[\w]+\.[\w.]+\w$/; 
   var emailregex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    var match=emailField.match( emailregex ); 
    if ( !match ) 
    { 
       return false; 
    }
    else
    {
       return true; 
    }
}

function isPhoneNumber(s) 
{

     // Check for correct phone number
	 var validPhoneDigits = '0123456789()-+';
	 var phoneLength = s.length;
	 
	for(var i=0; i < phoneLength; i++)
	 {
	   if(validPhoneDigits.indexOf(s.substr(i,1)) == '-1')
		{
		  var returnvar = false;
		  break;
		}
		else
		{
		  var returnvar = true;
		} 
		
	 }
	 return returnvar;
}
 
	  
function ContactValid()
{
	
 if(trim(document.theform.send_to.value) == "")
    {
	   alert("Please select send to.");
	   document.theform.send_to.focus();
	   return false;
	}	
 if(trim(document.theform.name.value) == "")
    {
	   alert("Please enter name.");
	   document.theform.name.focus();
	   return false;
	}
	
  if(trim(document.theform.email.value) == "")
    {
	   alert("Please enter email");
	   document.theform.email.focus();
	   return false;
	}	
  if(!isAValidEmail(document.theform.email.value))	
    {
	   alert("Please enter valid email address.");
	   document.theform.email.focus();
	   return false;
	}
  if(trim(document.theform.phone.value) == "")	
    {
	   alert("Please enter phone.");
	   document.theform.phone.focus();
	   return false;
	}  	
  if(!isPhoneNumber(document.theform.phone.value))
  	{
	   alert("Please enter valid phone.");
	   document.theform.phone.focus();
	   return false;
	}	
  if(trim(document.theform.private_key.value) == "")	
    {
	   alert("Please enter the text shown in picture.");
	   document.theform.private_key.focus();
	   return false;
	}	
	
   return true;
} 

function ContactValid1()
{
if(trim(document.theform.send_to.value) == "")
    {
	   alert("Please select send to.");
	   document.theform.send_to.focus();
	   return false;
	}	 

if(trim(document.theform.name1.value) == "")
    {
	   alert("Please enter name.");
	   document.theform.name1.focus();
	   return false;
	}
	
  if(trim(document.theform.email1.value) == "")
    {
	   alert("Please enter email");
	   document.theform.email1.focus();
	   return false;
	}	
  if(!isAValidEmail(document.theform.email1.value))	
    {
	   alert("Please enter valid email address.");
	   document.theform.email1.focus();
	   return false;
	}
  if(trim(document.theform.phone1.value) == "")	
    {
	   alert("Please enter phone.");
	   document.theform.phone1.focus();
	   return false;
	}  	
  if(!isPhoneNumber(document.theform.phone1.value))
  	{
	   alert("Please enter valid phone.");
	   document.theform.phone1.focus();
	   return false;
	}
 if(trim(document.theform.town.value) == "")
  	{
	   alert("Please enter the town.");
	   document.theform.town.focus();
	   return false;
	}	
			
  if(trim(document.theform.weight1.value) == "")
    {
	   alert("Please enter weight.");
	   document.theform.weight1.focus();
	   return false;
	}
  if(isNaN(document.theform.weight1.value))
    {
	   alert("Please enter weight in numeric.");
	   document.theform.weight1.focus();
	   return false;
	}	
  if(trim(document.theform.height1.value) == "")
    {
	   alert("Please enter height.");
	   document.theform.height1.focus();
	   return false;
	}	
  if(trim(document.theform.age1.value) == "")
    {
	   alert("Please enter age.");
	   document.theform.age1.focus();
	   return false;
	}
  if(trim(document.theform.HearAboutUs.value) == "")
  	{
	   alert("Please select how did you hear about us.");
	   document.theform.HearAboutUs.focus();
	   return false;	
	}	
  if((trim(document.theform.HearAboutUs.value) != 'Google') && (trim(document.theform.OtherVal.value) == "please specify" || trim(document.theform.OtherVal.value) == ""))
  {
  	 alert("Please specify.");
	 document.theform.OtherVal.focus();
	 return false;
  }			
  if(trim(document.theform.private_key1.value) == "")	
    {
	   alert("Please enter the text shown in picture.");
	   document.theform.private_key1.focus();
	   return false;
	}	
	
   return true;
} 


function clientvalidate()
{
   if(trim(document.theform.group.value) == "")
      {
	    alert("Please select a group name.");
		
	  
	  
	  }
}

function NewsletterValid()
{
 if(trim(document.theform.fname.value) == "")
    {
	   alert("Please enter first name.");
	   document.theform.fname.focus();
	   return false;
	}
  
   if(trim(document.theform.lname.value) == "")
    {
	   alert("Please enter last name.");
	   document.theform.lname.focus();
	   return false;
	}	
	
  if(trim(document.theform.email.value) == "")
    {
	   alert("Please enter email");
	   document.theform.email.focus();
	   return false;
	}	
  if(!isAValidEmail(document.theform.email.value))	
    {
	   alert("Please enter valid email address.");
	   document.theform.email.focus();
	   return false;
	}
   if((trim(document.theform.phone.value)!= "") && (!isPhoneNumber(document.theform.phone.value)))
     { 
	   alert("Please enter valid phone number.");
	   document.theform.phone.focus();
	   return false;
	 }			
  if(trim(document.theform.private_key.value) == "")	
    {
	   alert("Please enter the text shown in picture.");
	   document.theform.private_key.focus();
	   return false;
	}	
   return true;
}

function RegisterValidation()
{
   if(trim(document.theform.first_name.value)=="")
		 {
			alert("Please enter first name.");
			document.theform.first_name.focus();
			return false;
		 }
   if(trim(document.theform.last_name.value)=="")
		 {
			alert("Please enter last name.");
			document.theform.last_name.focus();
			return false;
		 }		 
   if(trim(document.theform.address1.value)=="")
		{
			alert("Please enter address1.");
			document.theform.address1.focus();
			return false;
		}
			
		   
     if(trim(document.theform.city.value)=="")
		 {
			alert("Please enter city/town.");
			document.theform.city.focus();
			return false;
		 }	
	 if(trim(document.theform.state.value)=="")
		 {
			alert("Please enter state.");
			document.theform.state.focus();
			return false;
		 }	
	if(trim(document.theform.zipcode.value)=="")
		 {
			alert("Please enter zip code.");
			document.theform.zipcode.focus();
			return false;
		 }
	if(trim(document.theform.country.value)=="")
		 {
			alert("Please select country.");
			document.theform.country.focus();
			return false;
		 }	
	if(trim(document.theform.phone.value)=="")
		 {
			alert("Please enter phone.");
			document.theform.phone.focus();
			return false;
		 }		 	 	 	 	
	
	if(!isPhoneNumber(document.theform.phone.value))
		 {
			alert("Please enter valid phone number.");
			document.theform.phone.focus();
			return false;
		 }	
	 
		 
	if(trim(document.theform.username.value)=="")
		 {
			alert("Please enter username.");
			document.theform.username.focus();
			return false;
		 }
		 
	var user_len = document.theform.username.value.length;
	if((user_len < 5) || (user_len > 15))
	     {
			alert("Username length should be between 5 to 15 characters.");
			document.theform.username.focus();
			return false;
		 }		  
	    	 
	if(trim(document.theform.password.value)=="")
		 {
			alert("Please enter password.");
			document.theform.password.focus();
			return false;
		 }
		 
	var pass_len = document.theform.password.value.length;
	if((pass_len < 5) || (pass_len > 15))
	     {
			alert("Password length should be between 5 to 15 characters.");
			document.theform.password.focus();
			return false;
		 }		 
	if(trim(document.theform.conf_password.value)=="")
		 {
			alert("Please enter confirm password.");
			document.theform.conf_password.focus();
			return false;
		 }
		 
	var cpass_len = document.theform.conf_password.value.length;
	if((cpass_len < 5) || (cpass_len > 15))
	     {
			alert("Confirm password length should be between 5 to 15 characters.");
			document.theform.conf_password.focus();
			return false;
		 }	 
	if(trim(document.theform.conf_password.value) != trim(document.theform.password.value))
	   {
	     	alert("Password and confirm password do not match.");
			document.theform.password.focus();
			return false;	   
	   }	 
	if(trim(document.theform.email.value)=="")
		 {
			alert("Please enter email");
			document.theform.email.focus();
			return false;
		 }
		 
	var emal = document.theform.email.value;	 
	if(!isAValidEmail( emal ))
	    {
		  alert("Please enter valid client email.");
		  document.theform.email.focus();
		  return false;				
		
		}	
	     return true;	
 }

function NewsletterValidation()
{
	
   if(trim(document.theform.first_name.value)=="")
		 {
			alert("Please enter first name.");
			document.theform.first_name.focus();
			return false;
		 }
   if(trim(document.theform.last_name.value)=="")
		 {
			alert("Please enter last name.");
			document.theform.last_name.focus();
			return false;
		 }		 
	if(trim(document.theform.phone.value)=="")
		 {
			alert("Please enter phone.");
			document.theform.phone.focus();
			return false;
		 }		 	 	 	 	
	
	if(!isPhoneNumber(document.theform.phone.value))
		 {
			alert("Please enter valid phone number.");
			document.theform.phone.focus();
			return false;
		 }	
	 
	if(trim(document.theform.email.value)=="")
		 {
			alert("Please enter email");
			document.theform.email.focus();
			return false;
		 }
		 
	var emal = document.theform.email.value;	 
	if(!isAValidEmail( emal ))
	    {
		  alert("Please enter valid client email.");
		  document.theform.email.focus();
		  return false;				
		
		}
   if(trim(document.theform.weight_field.value)=="")
		 {
			alert("Please select your current weight.");
			document.theform.weight_field.focus();
			return false;
		 }
        	
	     return true;	
 

}
function login_validation(){
    
    var fa= document.theform;
    
	if(trim(fa.username.value)==""){
        alert("Please enter username.");
        fa.username.focus();
        return false;
    }
    
    if(trim(fa.password.value)==""){
        alert("Please enter password.");
        fa.password.focus();
        return false;
        
    }
	   
    return true;
    
}

function Forget_validation()
{
		var fa= document.theform;
    
	if(trim(fa.username.value)==""){
        alert("Please enter username.");
        fa.username.focus();
        return false;
    }	
	  return true;
}

function Forget_validation()
{
		var fa= document.theform;
    
	if(trim(fa.username.value)==""){
        alert("Please enter username.");
        fa.username.focus();
        return false;
    }	
	  return true;
}

///Change Password Validation

  function valchgpassfrm() 
   {
		var fa= document.theform;
		
		if(trim(fa.opassword.value)==""){
			alert("Please enter old password.");
			fa.opassword.focus();
			return false;
		}
		
		if(trim(fa.npassword.value)==""){
			alert("Please enter new password.");
			fa.npassword.focus();
			return false;
			
		}
		
		if(trim(fa.cpassword.value)==""){
			alert("Please enter confirm password.");
			fa.cpassword.focus();
			return false;
			
		}
		
		if(trim(fa.cpassword.value)!=trim(fa.npassword.value)) {
			 alert("Please enter same password.");
			 fa.npassword.focus();
			 return false;	 
		}
		return true;
  }

function ProfileValidation()
{
	
   if(trim(document.theform.first_name.value)=="")
		 {
			alert("Please enter first name.");
			document.theform.first_name.focus();
			return false;
		 }
   if(trim(document.theform.last_name.value)=="")
		 {
			alert("Please enter last name.");
			document.theform.last_name.focus();
			return false;
		 }		 
   if(trim(document.theform.company_name.value)=="")
		 {
			alert("Please enter company name.");
			document.theform.company_name.focus();
			return false;
		 }	
   if(trim(document.theform.address1.value)=="")
		{
			alert("Please enter address1.");
			document.theform.address1.focus();
			return false;
		}
			
		   
     if(trim(document.theform.city.value)=="")
		 {
			alert("Please enter city/town.");
			document.theform.city.focus();
			return false;
		 }	
	 if(trim(document.theform.state.value)=="")
		 {
			alert("Please enter state.");
			document.theform.state.focus();
			return false;
		 }	
	if(trim(document.theform.zipcode.value)=="")
		 {
			alert("Please enter zip code.");
			document.theform.zipcode.focus();
			return false;
		 }
	
	if(trim(document.theform.country.value)=="")
		 {
			alert("Please select country.");
			document.theform.country.focus();
			return false;
		 }	
	if(trim(document.theform.phone.value)=="")
		 {
			alert("Please enter phone.");
			document.theform.phone.focus();
			return false;
		 }		 	 	 	 	
	
	if(!isPhoneNumber(document.theform.phone.value))
		 {
			alert("Please enter valid phone number.");
			document.theform.phone.focus();
			return false;
		 }	
	 
	if(trim(document.theform.email.value)=="")
		 {
			alert("Please enter email");
			document.theform.email.focus();
			return false;
		 }
		 
	var emal = document.theform.email.value;	 
	if(!isAValidEmail( emal ))
	    {
		  alert("Please enter valid client email.");
		  document.theform.email.focus();
		  return false;				
		
		}	
	     return true;	
}

function Show_Detail(valu1,valu2,valu3)
{
	document.getElementById(valu1).style.display = "";
	document.getElementById(valu2).style.display = "none";
	document.getElementById(valu3).style.display = "";;
}

function Hide_Detail(valu1,valu2,valu3)
{
	document.getElementById(valu1).style.display = "none";
	document.getElementById(valu2).style.display = "";
	document.getElementById(valu3).style.display = "none";;
}

function NewTopic(pagenm,id)
{
	location.href= pagenm+"?forum_id="+id;
}
function NewTopicPost(pagenm,id)
{
	location.href= pagenm+"?forum_id="+id+"&referer=post_forum";
}  
function NewLocation(pagenm)
{
	location.href= pagenm;	
} 

function ValidForumTopic()
{
	if(trim(document.theform.forum_cat.value) == "")
		{
			alert("Please select forum category.");
			document.theform.forum_cat.focus();
			return false;
		}
	if(trim(document.theform.topic.value) == "")
		{
			alert("Please enter forum topic.");
			document.theform.topic.focus();
			return false;
		}
	if(trim(document.theform.Description.value) == "")
		{
			alert("Please enter description.");
			document.theform.Description.focus();
			return false;
		}	
	return true;		
		
}
	    
function Confirm_Forum_Topic_Delete()
{
	if(confirm("Are you sure you want to delete this forum topic?\n Deleting forum topic will delete all the corresponding\n posts as well."))
	{
		return true;
	}
	else
	{
		return false;
	}
	
}

function Confirm_Forum_Post_Deleteed()
{
	if(confirm("Are you sure you want to delete this post?"))
	{
		return true;
	}
	else
	{
		return false;
	}	
}


function ShowContact()
  {
    if(document.theform.comment1.value.length > 500)
		{
			document.theform.comment1.value=document.theform.comment1.value.substr(0,500);
		}
		else
		{
		    document.getElementById('showcontact').innerHTML="Number of characters : "+document.theform.comment1.value.length;
		}
   }
	

function RemoveText()
{
	document.getElementById("comment12").value = "";
}

function ValidateTellaFriend()
{
 if(trim(document.theform.yourname.value) == "")
    {
	   alert("Please enter your name.");
	   document.theform.yourname.focus();
	   return false;
	}
	
  if(trim(document.theform.youremail.value) == "")
    {
	   alert("Please enter your email address.");
	   document.theform.youremail.focus();
	   return false;
	}	
  if(!isAValidEmail(document.theform.youremail.value))	
    {
	   alert("Please enter valid email address.");
	   document.theform.youremail.focus();
	   return false;
	}
	
  if(trim(document.getElementById("yfemail_0").value) == "")
    {
	   alert("Please enter your friends email address.");
	   document.getElementById("yfemail_0").focus();
	   return false;
	}	
  if(!isAValidEmail(document.getElementById("yfemail_0").value))	
    {
	   alert("Please enter valid email address.");
	   document.getElementById("yfemail_0").focus();
	   return false;
	}	 	
  if(trim(document.theform.private_key1.value) == "")	
    {
	   alert("Please enter the text shown in picture.");
	   document.theform.private_key1.focus();
	   return false;
	}
   return true;
}
	  	  