// JavaScript Document

function removespecialchar(frm,fld) {
   //  var vl=eval("document." + frm + "." + fld + ".value")
	// alert(vl + "vl")
	      
	
          var iChars = "~!@#$%^&*()+=-[]\\\';,./{}|:<>?";
        for (var i = 0; i < eval("document." + frm + "." + fld + ".value").length; i++) {
                if (iChars.indexOf(eval("document." + frm + "." + fld + ".value").charAt(i)) != -1) {
                    return false;
				}
          }
	
	
}


function removespecialchar_omit_singliequote(frm,fld) {
   //  var vl=eval("document." + frm + "." + fld + ".value")
	// alert(vl + "vl")
	      
	
          var iChars = "~!@#$%^&*()+=[]\\;-/{}|:<>?";
        for (var i = 0; i < eval("document." + frm + "." + fld + ".value").length; i++) {
                if (iChars.indexOf(eval("document." + frm + "." + fld + ".value").charAt(i)) != -1) {
                    return false;
				}
          }
		  
}



function removespecialchar_email(frm,fld) {
   //  var vl=eval("document." + frm + "." + fld + ".value")
	// alert(vl + "vl")
	      
	
          var iChars = "~!#$%^&*()+=[]\\\';,/{}|:<>?";
        for (var i = 0; i < eval("document." + frm + "." + fld + ".value").length; i++) {
                if (iChars.indexOf(eval("document." + frm + "." + fld + ".value").charAt(i)) != -1) {
                    return false;
				}
          }
		  
}

function loginvalidation()
{
	if(document.memlogin.memuser.value=="")
	{
		alert("Please enter username")
		document.memlogin.memuser.focus();
		return false
	}
		
	
	
	if(removespecialchar("memlogin","memuser")==false)
	{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.memlogin.memuser.focus();
		return false
	}

	
	if(document.memlogin.mempass.value=="")
	{
		alert("Please enter password")
		document.memlogin.mempass.focus();
		return false
	}
	
	if(removespecialchar("memlogin","mempass")==false)
	{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.memlogin.mempass.focus();
		return false
	}
	
	return true
	
}

function forgotpass_validation(){

		if(document.forgotpass.username.value!=""){
		
				if(removespecialchar("forgotpass","username")==false)
				{
					alert ("The box has special characters. \nThese are not allowed.\n");
					document.forgotpass.username.focus();
					return false
				}
				
		}
	
	return true
	
}



function searchpage(frmname,fld)
{
	var fldvalue=eval("document." + frmname + "." + fld + ".value")
	
	if(fldvalue!="")
	{
		if(removespecialchar(frmname,fld)==false)
		{
		alert ("The box has special characters. \nThese are not allowed.\n");
		eval("document." + frmname + "." + fld + ".focus()");
		return false
		}
	}

	return true

}



function qform(frmname,fld)
{

	

	var fldvalue=eval("document." + frmname + "." + fld + ".value")
	
	if(fldvalue!="")
	{
		if(removespecialchar_omit_singliequote(frmname,fld)==false)
		{
		alert ("The box has special characters. \nThese are not allowed.\n");
		eval("document." + frmname + "." + fld + ".focus()");
		return false
		}
	}


	return true

}



function contactfrm()
{
	
	if(document.contactform.name.value=="")
	{
		alert("Please enter name")	
		document.contactform.name.focus();
		return false
	}
	
	if(document.contactform.name.value!="")
	{
		if(removespecialchar('contactform','name')==false)
		{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.contactform.name.focus();
		return false
		}
	}
	
	
	
	if(document.contactform.email.value=="" || document.contactform.email.value.indexOf("@")==-1 || document.contactform.email.value.indexOf(".")==-1)
	{
		alert("Please enter valid email")	
		document.contactform.email.focus();
		return false
	}
	
	
	if(document.contactform.email.value!="")
	{
		if(removespecialchar_email('contactform','email')==false)
		{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.contactform.email.focus();
		return false
		}
	}
	

	
	
	if(document.contactform.comments.value=="")
	{
		alert("Please enter comments")	
		document.contactform.comments.focus();
		return false
	}
	
	if(document.contactform.comments.value!="")
	{
		if(removespecialchar_omit_singliequote('contactform','comments')==false)
		{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.contactform.comments.focus();
		return false
		}
		
	}
		
	  
return true

}



	function mailtofriend()
	{
	
		
		if(document.emailtofriend.fname.value==""){
		alert("Please enter friend name")
		document.emailtofriend.fname.focus()
		return false
		}
		
		if(document.emailtofriend.fname.value!=""){
			
				if(removespecialchar('emailtofriend','fname')==false)
				{
				alert ("The box has special characters. \nThese are not allowed.\n");
				document.emailtofriend.fname.focus();
				return false
				}
		}
		
		
		
		if(document.emailtofriend.email.value=="" || document.emailtofriend.email.value.indexOf("@")==-1 || document.emailtofriend.email.value.indexOf(".")==-1){
		alert("Please enter friend email. Ex:xxx@xxx.xxx")
		document.emailtofriend.email.focus()
		return false
		}
		
		
		if(document.emailtofriend.email.value!="")
		{
		  if(removespecialchar_email('emailtofriend','email')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.emailtofriend.email.focus();
			return false
			}	
			
	    }
		
		
		if(document.emailtofriend.personalmessage.value!="")
		{
			
					if(removespecialchar_omit_singliequote('emailtofriend','personalmessage')==false)
					{
						alert ("The box has special characters. \nThese are not allowed.\n");
						document.emailtofriend.personalmessage.focus();
						return false
						
					}
			
			
		}
		
						
		if(document.emailtofriend.yourname.value==""){
		alert("Please enter your name")
		document.emailtofriend.yourname.focus()
		return false
		}
		
		
		if(document.emailtofriend.yourname.value!=""){
						
				if(removespecialchar('emailtofriend','yourname')==false)
				{
				alert ("The box has special characters. \nThese are not allowed.\n");
				document.emailtofriend.yourname.focus();
				return false
				}
		}
						
		
		if(document.emailtofriend.youremail.value=="" || document.emailtofriend.youremail.value==-1 || document.emailtofriend.youremail.value==-1){
		alert("Please enter your email. Ex:xxx@xxx.xxx")
		document.emailtofriend.youremail.focus()
		return false
		}
		
		if(document.emailtofriend.youremail.value!="")
		{
			if(removespecialchar_email('emailtofriend','youremail')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.emailtofriend.youremail.focus();
			return false
			}	
			
	    }
				
				
	return true
}


//*************************Registration form validation*************************

function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }
 
 
 function registration_validate()
	 {
	 
	 	if(document.memreg.name.value==""){
		alert("Please enter name")
		document.memreg.name.focus();
		return false
		}
		

	if(document.memreg.name.value!=""){
			
			if(removespecialchar('memreg','name')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.memreg.name.focus();
			return false
			}	
		}
		
			
		if(document.memreg.address.value==""){
		alert("Please enter clinical address")
		document.memreg.address.focus();
		return false
		}
		
	
		if(document.memreg.address.value!=""){
		
			if(removespecialchar_omit_singliequote('memreg','address')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.memreg.address.focus();
			return false
			}	
		
		}
	
		
		
		if(document.memreg.city.value==""){
		alert("Please enter city")
		document.memreg.city.focus();
		return false
		}
		
		if(document.memreg.city.value!=""){
		
			if(removespecialchar('memreg','city')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.memreg.city.focus();
			return false
			}	
		
		}
		
		
		if(document.memreg.state.options[0].selected){
		alert("Please select state")
		document.memreg.state.focus();
		return false
		}
		
		
		if(document.memreg.age.value=="" || !IsNumeric(document.memreg.age.value) || parseInt(document.memreg.age.value)<18){
		alert("Please enter age. Only numbers and above 18 years")
		document.memreg.age.focus();
		return false
		}
		
		if(document.memreg.prescribedr.value==""){
		alert("Please enter prescribed doctor")
		document.memreg.prescribedr.focus();
		return false
		}
				
			
	  if(document.memreg.prescribedr.value!=""){
		
			if(removespecialchar('memreg','prescribedr')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.memreg.prescribedr.focus();
			return false
			}	
		
		}
			
			
				
				
		if(document.memreg.pd.value==""){
		alert("Please select prescription date")
		document.memreg.pd.focus();
		return false
		}		
				
	if(document.memreg.email.value=="" || document.memreg.email.value.indexOf("@")==-1 || document.memreg.email.value.indexOf("@")==-1){
		alert("Please enter valid email. Ex:xxxx@xxxx.xxx")
		document.memreg.email.focus();
		return false
		}
		
	if(document.memreg.email.value!=""){
			
		    if(removespecialchar_email('memreg','email')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.memreg.email.focus();
			return false
			}	
			
	}
		
		
		
		if(document.memreg.phoneno.value=="" &&  document.memreg.mobileno.value==""){
		alert("Please enter phoneno or mobile.")
		document.memreg.phoneno.focus();
		return false
		}	
		
		if(document.memreg.phoneno.value!="" && document.memreg.stdcode.value=="" ){
		alert("Please enter std code")
		document.memreg.phoneno.focus();
		return false
		}		
		
		if(document.memreg.stdcode.value=="" && !IsNumeric(document.memreg.stdcode.value) ){
		alert("Please enter only numbers")
		document.memreg.stdcode.focus();
		return false
		}	
		
		if(document.memreg.stdcode.value!="" && !IsNumeric(document.memreg.stdcode.value) ){
		alert("Please enter only numbers")
		document.memreg.stdcode.focus();
		return false
		}		
		
		if(document.memreg.mobileno.value!="" && !IsNumeric(document.memreg.mobileno.value) ){
		alert("Please enter only numbers")
		document.memreg.mobileno.focus();
		return false
		}		
		
		if(document.memreg.username.value==""){
		alert("Please enter username")
		document.memreg.username.focus();
		return false
		}
		
		if(document.memreg.username.value!=""){
		
			if(removespecialchar('memreg','username')==false)
			{
			alert ("The box has special characters. \nThese are not allowed.\n");
			document.memreg.username.focus();
			return false
			}	
		
		}
		
		
		
		if(document.memreg.qd.value==""){
		alert("Please select quit date")
		document.memreg.qd.focus();
		return false
		}
		
		if(!document.memreg.agree[0].checked){
		alert("Please select agreement option")
		document.memreg.agree[0].focus();
		return false
		}
		
		return true				
	 
	 }

//************************Registration form validation*************************

//************************Admin login validation*******************************
function Adminloginvalidation()
{
	if(document.loginfrm.username.value=="")
	{
		alert("Please enter username")
		document.loginfrm.username.focus();
		return false
	}
		
	
	
	if(removespecialchar("loginfrm","username")==false)
	{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.loginfrm.username.focus();
		return false
	}

	
	if(document.loginfrm.pwd.value=="")
	{
		alert("Please enter password")
		document.loginfrm.pwd.focus();
		return false
	}
	
	if(removespecialchar("loginfrm","pwd")==false)
	{
		alert ("The box has special characters. \nThese are not allowed.\n");
		document.loginfrm.pwd.focus();
		return false
	}
	
	return true
	
}


//************************Admin login validation*******************************
