/* admin validations start */
function validateAdmin(obj)
{
	with(document.frmlogin)
	{
		if(Trim(username.value)==""){
		alert("Please specify the username.");
		username.focus();
		return false;
		}
		if(Trim(password.value) == "" )
		{
			alert("Please enter the password!");
			password.focus();
			return false;
		}
	}
	return true;
}
function validatePwd()
{
	with(document.frmPassword)
	{
		if(Trim(oldPassword.value) == "" )
		{
			alert("Please enter the old password!");
			oldPassword.focus();
			return false;
		}
		if(Trim(newPassword.value) == "" )
		{
			alert("Please enter the new password!");
			newPassword.focus();
			return false;
		}
		if(Trim(newPassword.value).length < 6  )
		{
			alert("New password should have minimum 6 characters!");
			newPassword.value = "";
			newPassword.focus();
			return false;
		}
		if(Trim(confirmPassword.value) == "" )
		{
			alert("Please enter the confirm password!");
			confirmPassword.focus();
			return false;
		}
		if(Trim(confirmPassword.value) != Trim(newPassword.value) )
		{
			alert("Password not matched!");
			confirmPassword.value = "";
			confirmPassword.focus();
			return false;
		}
	}
return true;
}
function validate_add_hospitals_Login()
{
	with(document.frmadd_consultants_Login)
	{
		
		if(Trim(username.value) == "" )
		{
			alert("Please enter username!");
			username.focus();
			return false;
		}
		if(Trim(password.value) == "" )
		{
			alert("Please enter the password!");
			password.focus();
			return false;
		}
		if(Trim(password.value).length < 6  )
		{
			alert("Password should have minimum 6 characters!");
			password.value = "";
			password.focus();
			return false;
		}
		if(Trim(confirmPassword.value) == "" )
		{
			alert("Please enter the confirm password!");
			confirmPassword.focus();
			return false;
		}
		if(Trim(confirmPassword.value) != Trim(password.value) )
		{
			alert("Password not matched!");
			confirmPassword.value = "";
			confirmPassword.focus();
			return false;
		}
			
	}
return true;
}

function validate_add_consultants_Login()
{
	with(document.frmadd_consultants_Login)
	{
		if(Trim(name.value) == "" )
		{
			alert("Please enter name!");
			name.focus();
			return false;
		}
		if(Trim(username.value) == "" )
		{
			alert("Please enter username!");
			username.focus();
			return false;
		}
		if(Trim(password.value) == "" )
		{
			alert("Please enter the password!");
			password.focus();
			return false;
		}
		if(Trim(password.value).length < 6  )
		{
			alert("Password should have minimum 6 characters!");
			password.value = "";
			password.focus();
			return false;
		}
		if(Trim(confirmPassword.value) == "" )
		{
			alert("Please enter the confirm password!");
			confirmPassword.focus();
			return false;
		}
		if(Trim(confirmPassword.value) != Trim(password.value) )
		{
			alert("Password not matched!");
			confirmPassword.value = "";
			confirmPassword.focus();
			return false;
		}
		if(Trim(department.value)=="")
		{
			alert("Please select the User type.");
			department.focus();
			return false;
		} 

	}
return true;
}


function validatefrmadd_appts()
{
	with(document.frmadd_appts)
	{
		if(Trim(hospital_name.value) == "" )
		{
			alert("Please enter hospital name!");
			hospital_name.focus();
			return false;
		}
		if(Trim(hr.value) == "" )
		{
			alert("Please provide proper appointment time!");
			hr.focus();
			return false;
		}
		if(Trim(min.value) == "" )
		{
			alert("Please provide proper appointment time!");
			min.focus();
			return false;
		}
		if(Trim(am_pm.value) == "" )
		{
			alert("Please provide proper appointment time!");
			am_pm.focus();
			return false;
		}
		if(Trim(typ_surgery.value) == "" )
		{
			alert("Please enter the Surgery type!");
			typ_surgery.focus();
			return false;
		}
		
		if(Trim(tech_name.value)=="0")
		{
			alert("Please select the technician name.");
			tech_name.focus();
			return false;
		} 
	}
return true;
}
function validate_contact()
{
	with(document.frmcontact)
	{
		if(Trim(name.value) == "" )
		{
			alert("Please enter name!");
			name.focus();
			return false;
		}
		 if(Trim(email.value)=="")
		{
		alert("Please specify the email Address.");
		email.focus();
		return false;
		}
	  if(!echeck(Trim(email.value)))
		{
			email.focus();
			return false;
		}
		if(Trim(message.value) == "" )
		{
			alert("Please provide message!");
			message.focus();
			return false;
		}
	
	}
return true;
}

/* admin validations end */

 function validateindex()
     {
		with (document.frmindex)
		{
			if(Trim(username.value)=="")
			{
				alert("Please specify the Username.");
				username.focus();
				return false;
			}
			
			if(Trim(password.value) == "")
			{
				alert("Please enter the password!");
				password.focus();
				return false;
			}
			var flag;
			for(i=0;i<rd_usertype.length;i++)
			{
				if(rd_usertype[i].checked==true)
				{
					flag=true;
				}
			}
			if(!flag)
			{
				alert("Please select the Login type i.e Hospital/Staff")
				return false;
			}
			
		}
		return true
     }
     
 function validate_add_blog()
     {
     with (document.frm_add_blog)
		{
			if(Trim(blog_title.value)=="")
			{
				alert("Please specify the blog title.");
				blog_title.focus();
				return false;
			}
			
			if(Trim(blog_text.value) == "")
			{
				alert("Please Specify the blog content!");
				blog_text.focus();
				return false;
			}
			
		}
		return true
     }
     
     
 function  validate_blogs_replies() 
     {
     with (document.frm_blogs_replies)
		{
			if(Trim(txtareply.value)=="")
			{
				alert("Please specify the comments.");
				txtareply.focus();
				return false;
			}
			
		}
		return true
     }
   function validatesearch(frm)
   {
   with (frm)
		{
			if(Trim(txt_search.value)=="")
			{
				alert("Please specify the search keyword.");
				txt_search.focus();
				return false;
			}
			
		}
		return true
   
   }
   
   function validateresume()
{
	
	with(document.frm_resume)
	{
		if(Trim(name.value)=="")
		{
			alert("Please specify the Name.");
			name.focus();
			return false;
		} 
		/*
		if(Trim(address1.value)=="")
		{
			alert("Please specify the address.");
			address1.focus();
			return false;
		} 
		if(Trim(city.value)=="")
		{
			alert("Please specify the city.");
			city.focus();
			return false;
		} 
		if(Trim(state.value)=="0")
		{
			alert("Please select the state.");
			state.focus();
			return false;
		} 
		if(Trim(zip.value)=="")
		{
			alert("Please specify the Zip Code");
			zip.focus();
			return false;
		}
		if(Trim(zip.value).length > 5)
		{
			alert("Zip code should not be more than 5 digits");
			zip.focus();
			return false;
		}
		if(Trim(phone1.value)=="")
		{
			alert("Please specify the Home Phone Number");
			phone1.focus();
			return false;
		}
		if(Trim(phone2.value)=="")
		{
			alert("Please specify the Phone/Cell Number");
			phone2.focus();
			return false;
		}
	  if(Trim(email_amr.value)=="")
		{
		alert("Please specify the AMR Email Address.");
		email_amr.focus();
		return false;
		}
	  if(!echeck(Trim(email_amr.value)))
		{
			email_amr.focus();
			return false;
		}
	 if(Trim(email.value)=="")
		{
		alert("Please specify the Email Address.");
		email.focus();
		return false;
		}
	  if(!echeck(Trim(email.value)))
		{
			email.focus();
			return false;
		}
		*/
	  if(Trim(department.value)=="")
		{
			alert("Please select the department.");
			department.focus();
			return false;
		} 	
	 
    }
	return true;
}


/* genral functions */     
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true
	}
function ValidateFullNumeric(myfield,e)
{
	//alert(window.event.keyCode);
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	
	else return true;
	if (((keycode>46) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}
function ValidateNumeric(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if ((keycode==32) || ((keycode>43) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}
function ValidatePhone(myfield,e)
{
 // alert(window.event.keyCode)
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if ((keycode==45) || ((keycode>47) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}
function ValidateAlpha(myfield,e)
{
	//alert(window.event.keyCode)
    var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	//if ((keycode==32) || (keycode==39) || ((keycode>43) && (keycode<48)) || ((keycode>=65) && (keycode<=90) )  || (keycode==8) || ((keycode>=97) && (keycode<=122) )) { return true; }
	if ((keycode==32) || ((keycode>43) && (keycode<48)) || ((keycode>=65) && (keycode<=90) )  || (keycode==8) || ((keycode>=97) && (keycode<=122) )) { return true; }
	else return false;
}
function ValidateAlphaNumeric(myfield,e)
{
	
	//alert(window.event.keyCode)
    var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	//if ((keycode==32) || (keycode==39) || ((keycode>43) && (keycode<58) ) || ((keycode>=64) && (keycode<=90) )  || (keycode==8) || (keycode==95) || ((keycode>=97) && (keycode<=122) )) { return true; }
	if ((keycode==32) || ((keycode>43) && (keycode<58) ) || ((keycode>=64) && (keycode<=90) )  || (keycode==8) || (keycode==95) || ((keycode>=97) && (keycode<=122) )) { return true; }
	else return false;
}
function ValidateAlphaNumeric_username(myfield,e)
{
	//alert(window.event.keyCode)
    var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	//if ((keycode==32) || (keycode==39) || ((keycode>43) && (keycode<58) ) || ((keycode>=64) && (keycode<=90) )  || (keycode==8) || (keycode==95) || ((keycode>=97) && (keycode<=122) )) { return true; }
	if ( ((keycode>43) && (keycode<58) ) || ((keycode>=64) && (keycode<=90) )  || (keycode==8) || (keycode==95) || ((keycode>=97) && (keycode<=122) )) { return true; }
	else return false;
}
function ValidateFullDecimal(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (((keycode>47) && (keycode<58) )|| (keycode==46)  || (keycode==8)) { return true; }
	else return false;
}

//-------------------------------------------------------------------
	// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
