/*'*****************************************************************************
'Reviewed by Neelabh 
' July 2005
'this file contains  the code for all functions being used to validate the values
'this file calls some other functions defined in file named:: js.js
'*******************************************************************************
*/
var num="";
function ltrim(str)
{
     var whitespace = new String(" \t\n\r");
     var s = new String(str);
     if (whitespace.indexOf(s.charAt(0)) != -1) {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
           j++;
        s = s.substring(j, i);
     }
     return s;
}
function doDateCheck(from, to) 
{
	if (Date.parse(from) <= Date.parse(to))
	{
		return true;
	}
	else 
	{
		if (from == "" || to == "") 
			return false;
		else 
			return false;
	}
}


function rtrim(str)
{
     var whitespace = new String(" \t\n\r");
     var s = new String(str);
     if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
        var i = s.length - 1;       // Get length of string
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
           i--;
        s = s.substring(0, i+1);
     }
     return s;
}


function trim(str)
{
     return rtrim(ltrim(str));
}

function checklogo()
{
alert('Please select from Browse button only');
return false;
}

function rightString(fullString) 
{
   if (fullString.length <= 4) 
   {
      return "";
   } 
   else 
   {
     return (fullString.substring(fullString.length-4, fullString.length));
   }
}  

function checkzip()
{
	if (document.firstzip.zipcode.value=="")
	{
		alert('Please enter the zip code');
		document.firstzip.zipcode.focus();
		return false;
	}
	if ((document.firstzip.zipcode.value)!="" && isZip(document.firstzip.zipcode.value)==false)
	{
		alert('Invalid Zip Code');
		document.firstzip.zipcode.focus();
		return false;
	}
}	
	

function validSearch()
{
    var curdate=new Date();
	if(document.hit_result.start.value=="")
    {
		alert('Please select start date');
		document.hit_result.start.focus();
		return false;
	}
	if(doDateCheck(document.hit_result.start.value,curdate)==false)
    {
     alert("Start date must be less than current date");
     return false;                   
    }
    if(document.hit_result.end.value=="")
    {
		alert('Please select end date');
		document.hit_result.end.focus();
		return false;
	}
		
	if(doDateCheck(document.hit_result.end.value,curdate)==false)
    {
     alert("End date must be less than current date");
     return false;                   
    }
	if (doDateCheck(document.hit_result.start.value,document.hit_result.end.value)==false)
	{
   	  alert("Please select a valid Date Interval. Start Date must be less than End Date");
      return false;                   
    }
	if(trim(document.hit_result.zipcode.value)=="")
    {
		alert('Please enter zipcode.');
		document.hit_result.zipcode.focus();
		return false;
	}
	if(trim(document.hit_result.distance.value)=="")
	{
	  	alert('Please enter distance.');
		document.hit_result.distance.focus();
		return false;
	}
    if(isNumeric(document.hit_result.distance.value)==false)
	{
	  	alert('Please enter numeric values only');
		document.hit_result.distance.focus();
		return false;
	}
}	

function validatedietitian()
{
	/*if (trim(document.newdietitian.dname.value)=="")
	{
		alert('Please enter Practitioner Name');
		document.newdietitian.dname.focus();
		return false;
	}
	if (isChar(document.newdietitian.dname.value)==false)
	{
		alert('special characters are not allowed');
		document.newdietitian.dname.focus();
		return false;
	}
	
	if (document.newdietitian.cname.value!="" && isChar(document.newdietitian.cname.value)==false)
	{
		alert('special characters are not allowed');
		document.newdietitian.cname.focus();
		return false;
	}
	
	if (trim(document.newdietitian.address1.value)!="" && (document.newdietitian.address1.value.match('"')))
	{
		alert('double qoutes are not allowed');
		document.newdietitian.address1.focus();
		return false;
	}
	if (trim(document.newdietitian.address2.value)!="" && (document.newdietitian.address2.value.match('"')))
	{
		alert('double qoutes are not allowed');
		document.newdietitian.address2.focus();
		return false;
	}
	
	if (document.newdietitian.city.value!="" && isChar(document.newdietitian.city.value)==false)
	{
		alert('special characters are not allowed');
		document.newdietitian.city.focus();
		return false;
	}*/
	/*if (trim(document.newdietitian.state.value)=="select state")
	{
		alert('Please select State');
		document.newdietitian.state.focus();
		return false;
	}*/
	/*if (trim(document.newdietitian.zip.value)=="")
	{
		alert('Please enter Zip Code');
		document.newdietitian.zip.focus();
		return false;
	}
	if (isZip(document.newdietitian.zip.value)==false)
	{
		alert('Invalid Zip Code');
		document.newdietitian.zip.focus();
		return false;
	}*/
	
	/*if (document.newdietitian.telephone.value!="" && isNumeric(document.newdietitian.telephone.value)==false)
	{
		alert('Please enter numeric values only');
		document.newdietitian.telephone.focus();
		return false;
	}
	/*if (document.newdietitian.email.value!="" && isEmail(document.newdietitian.email.value)==false)
	{
		alert('Please enter valid E-mail address');
		document.newdietitian.email.focus();
		return false;
	}
	if (document.newdietitian.website.value!="" && isURL(document.newdietitian.website.value)==false)
	{
		alert('Please enter correct site link');
		document.newdietitian.website.focus();
		return false;
	}*/
	
	
	if(document.newdietitian.photo!="")
	{
		     var ext=rightString(document.newdietitian.photo.value);
			 if (ext.length==4)
			 {	
			     if((ext.toLowerCase()!= ".gif") && (ext.toLowerCase()!= ".jpg")) 
				 {
				    alert("Invalid Logo Image type");
					document.newdietitian.photo.focus() ;
		   		     return false;       
				 }
				 
				
			}           
	}
	if(document.newdietitian.offer!="")
	{	var ext=rightString(document.newdietitian.offer.value);
			 if (ext.length==4)
			 {
			     if((ext.toLowerCase()!= ".gif") && (ext.toLowerCase()!= ".jpg")) 
				 {
				    alert("Invalid Logo Image type");
					 document.newdietitian.offer.focus() ;
		   		     return false;       
				 }
				
			}           
	}
			
}

function dietitianrequest()
{
	if (trim(document.newpatient.name.value)=="")
	{
		alert('Please enter Practitioner Name');
		document.newpatient.name.focus();
		return false;
	}
	if (isChar(document.newpatient.name.value)==false)
	{
		alert('special characters are not allowed');
		document.newpatient.name.focus();
		return false;
	}
	
	if (trim(document.newpatient.address1.value)=="")
	{
		alert('Please enter Address');
		document.newpatient.address1.focus();
		return false;
	}
	if (trim(document.newpatient.address1.value)!="" && (document.newpatient.address1.value.match('"')))
	{
		alert('double qoutes are not allowed');
		document.newpatient.address1.focus();
		return false;
	}
	if (trim(document.newpatient.address2.value)!="" && (document.newpatient.address2.value.match('"')))
	{
		alert('double qoutes are not allowed');
		document.newpatient.address2.focus();
		return false;
	}
	if (trim(document.newpatient.city.value)=="")
	{
		alert('Please enter City');
		document.newpatient.city.focus();
		return false;
	}
	if (isChar(document.newpatient.city.value)==false)
	{
		alert('special characters are not allowed');
		document.newpatient.city.focus();
		return false;
	}
	if (trim(document.newpatient.state.value)=="select state")
	{
		alert('Please select State');
		document.newpatient.state.focus();
		return false;
	}
	if (trim(document.newpatient.zipcode.value)=="")
	{
		alert('Please enter Zip Code');
		document.newpatient.zipcode.focus();
		return false;
	}
	if (isZip(document.newpatient.zipcode.value)==false)
	{
		alert('Invalid Zip Code');
		document.newpatient.zipcode.focus();
		return false;
	}
	if (trim(document.newpatient.telephone.value)=="")
	{
		alert('Please enter Telephone number');
		document.newpatient.telephone.focus();
		return false;
	}
	if (isNumeric(document.newpatient.telephone.value)==false)
	{
		alert('Please enter numeric values only');
		document.newpatient.telephone.focus();
		return false;
	}
	if (isEmail(document.newpatient.email.value)==false)
	{
		alert('Please enter valid E-mail address');
		document.newpatient.email.focus();
		return false;
	}

}


function vi()
{
		document.newdietitian.website.value="http://www.";
}
function vi2() 
{
		if (document.newdietitian.website.value=="http://www.")
		{
		document.newdietitian.website.value="";
		}
}

function validofficehours()
{	/**************************conditions for valid format for time*************************************************/
	/*if(document.officehours.mon_morning_from.value!="" && isTime(document.officehours.mon_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.mon_morning_from.focus();return false;
	}
	if(document.officehours.mon_morning_to.value!="" && isTime(document.officehours.mon_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.mon_morning_to.focus();return false;
	}
	if(document.officehours.mon_evening_from.value!="" && isTime(document.officehours.mon_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.mon_evening_from.focus();return false;
	}
	if(document.officehours.mon_evening_to.value!="" && isTime(document.officehours.mon_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.mon_evening_to.focus();return false;
	}
	if(document.officehours.tue_morning_from.value!="" && isTime(document.officehours.tue_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.tue_morning_from.focus();return false;
	}
	if(document.officehours.tue_morning_to.value!="" && isTime(document.officehours.tue_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.tue_morning_to.focus();return false;
	}
	if(document.officehours.tue_evening_from.value!="" && isTime(document.officehours.tue_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.tue_evening_from.focus();return false;
	}
	if(document.officehours.tue_evening_to.value!="" && isTime(document.officehours.tue_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.tue_evening_to.focus();return false;
	}
	if(document.officehours.wed_morning_from.value!="" && isTime(document.officehours.wed_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.wed_morning_from.focus();return false;
	}
	if(document.officehours.wed_morning_to.value!="" && isTime(document.officehours.wed_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.wed_morning_to.focus();return false;
	}
	if(document.officehours.wed_evening_from.value!="" && isTime(document.officehours.wed_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.wed_evening_from.focus();return false;
	}
	if(document.officehours.wed_evening_to.value!="" && isTime(document.officehours.wed_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.wed_evening_to.focus();return false;
	}
	if(document.officehours.thu_morning_from.value!="" && isTime(document.officehours.thu_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.thu_morning_from.focus();return false;
	}
	if(document.officehours.thu_morning_to.value!="" && isTime(document.officehours.thu_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.thu_morning_to.focus();return false;
	}
	if(document.officehours.thu_evening_from.value!="" && isTime(document.officehours.thu_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.thu_evening_from.focus();return false;
	}
	if(document.officehours.thu_evening_to.value!="" && isTime(document.officehours.thu_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.thu_evening_to.focus();return false;
	}
	if(document.officehours.fri_morning_from.value!="" && isTime(document.officehours.fri_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.fri_morning_from.focus();return false;
	}
	if(document.officehours.fri_morning_to.value!="" && isTime(document.officehours.fri_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.fri_morning_to.focus();return false;
	}
	if(document.officehours.fri_evening_from.value!="" && isTime(document.officehours.fri_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.fri_evening_from.focus();return false;
	}
	if(document.officehours.fri_evening_to.value!="" && isTime(document.officehours.fri_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.fri_evening_to.focus();return false;
	}
	if(document.officehours.sat_morning_from.value!="" && isTime(document.officehours.sat_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sat_morning_from.focus();return false;
	}
	if(document.officehours.sat_morning_to.value!="" && isTime(document.officehours.sat_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sat_morning_to.focus();return false;
	}
	if(document.officehours.sat_evening_from.value!="" && isTime(document.officehours.sat_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sat_evening_from.focus();return false;
	}
	if(document.officehours.sat_evening_to.value!="" && isTime(document.officehours.sat_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sat_evening_to.focus();return false;
	}
	if(document.officehours.sun_morning_from.value!="" && isTime(document.officehours.sun_morning_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sun_morning_from.focus();return false;
	}
	if(document.officehours.sun_morning_to.value!="" && isTime(document.officehours.sun_morning_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sun_morning_to.focus();return false;
	}
	if(document.officehours.sun_evening_from.value!="" && isTime(document.officehours.sun_evening_from.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sun_evening_from.focus();return false;
	}
	if(document.officehours.sun_evening_to.value!="" && isTime(document.officehours.sun_evening_to.value)==false)
	{alert("Please enter the time in correct format:   hh:mm am/pm");document.officehours.sun_evening_to.focus();return false;
	}*/
/************************************************************************************************************************************/		
/****************conditions for making either enter both the time for each shift  compulsory or left both time blank**********************************************************************/			
	/*if((document.officehours.mon_morning_from.value=="" && document.officehours.mon_morning_to.value!="") || (document.officehours.mon_morning_from.value!="" && document.officehours.mon_morning_to.value==""))
	{alert("Please enter the  morning office hours for monday");
	 return false;
	}
	if((document.officehours.tue_morning_from.value=="" && document.officehours.tue_morning_to.value!="") || (document.officehours.tue_morning_from.value!="" && document.officehours.tue_morning_to.value==""))
	{alert("Please enter the  morning office hours for Tuesday");
	 return false;
	}
	if((document.officehours.wed_morning_from.value=="" && document.officehours.wed_morning_to.value!="") || (document.officehours.wed_morning_from.value!="" && document.officehours.wed_morning_to.value==""))
	{alert("Please enter the  morning office hours for Wednesday");
	 return false;
	}
	if((document.officehours.thu_morning_from.value=="" && document.officehours.thu_morning_to.value!="") || (document.officehours.thu_morning_from.value!="" && document.officehours.thu_morning_to.value==""))
	{alert("Please enter the  morning office hours for Thursday");
	 return false;
	}
	if((document.officehours.fri_morning_from.value=="" && document.officehours.fri_morning_to.value!="") || (document.officehours.fri_morning_from.value!="" && document.officehours.fri_morning_to.value==""))
	{alert("Please enter the  morning office hours for Friday");
	 return false;
	}
	if((document.officehours.sat_morning_from.value=="" && document.officehours.sat_morning_to.value!="") || (document.officehours.sat_morning_from.value!="" && document.officehours.sat_morning_to.value==""))
	{alert("Please enter the  morning office hours for Saturday");
	 return false;
	}
	if((document.officehours.sun_morning_from.value=="" && document.officehours.sun_morning_to.value!="") || (document.officehours.sun_morning_from.value!="" && document.officehours.sun_morning_to.value==""))
	{alert("Please enter the  morning office hours for Sunday");
	 return false;
	}
	if((document.officehours.mon_evening_from.value=="" && document.officehours.mon_evening_to.value!="") || (document.officehours.mon_evening_from.value!="" && document.officehours.mon_evening_to.value==""))
	{alert("Please enter the  evening office hours for Monday");
	 return false;
	}
	if((document.officehours.tue_evening_from.value=="" && document.officehours.tue_evening_from.value!="") || (document.officehours.tue_evening_from.value!="" && document.officehours.tue_evening_from.value==""))
	{alert("Please enter the  evening office hours for Tuesday");
	 return false;
	}
	if((document.officehours.wed_evening_from.value=="" && document.officehours.wed_evening_to.value!="") || (document.officehours.wed_evening_from.value!="" && document.officehours.wed_evening_to.value==""))
	{alert("Please enter the  evening office hours for Wednesday");
	 return false;
	}
	if((document.officehours.thu_evening_from.value=="" && document.officehours.thu_evening_to.value!="") || (document.officehours.thu_evening_from.value!="" && document.officehours.thu_evening_to.value==""))
	{alert("Please enter the  evening office hours for Thursday");
	 return false;
	}
	if((document.officehours.fri_evening_from.value=="" && document.officehours.fri_evening_to.value!="") || (document.officehours.fri_evening_from.value!="" && document.officehours.fri_evening_to.value==""))
	{alert("Please enter the  evening office hours for Friday");
	 return false;
	}
	if((document.officehours.sat_evening_from.value=="" && document.officehours.sat_evening_to.value!="") || (document.officehours.sat_evening_from.value!="" && document.officehours.sat_evening_to.value==""))
	{alert("Please enter the  evening office hours for Saturday");
	 return false;
	}
	if((document.officehours.sun_evening_from.value=="" && document.officehours.sun_evening_to.value!="") || (document.officehours.sun_evening_from.value!="" && document.officehours.sun_evening_to.value==""))
	{alert("Please enter the  evening office hours for Sunday");
	 return false;
	}*/
	/*********************************************************************************************************************************/
   /****************conditions for from time can not greater than to time*************************************************************/	
	/*if(document.officehours.mon_morning_from.value!="" && (document.officehours.mon_morning_from.value>=document.officehours.mon_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.mon_morning_from.focus();
	 return false;
	}
	if(document.officehours.tue_morning_from.value!="" && (document.officehours.tue_morning_from.value>=document.officehours.tue_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.tue_morning_from.focus();
	 return false;
	}
	if(document.officehours.wed_morning_from.value!="" && (document.officehours.wed_morning_from.value>=document.officehours.wed_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.wed_morning_from.focus();
	 return false;
	}
	if(document.officehours.thu_morning_from.value!="" && (document.officehours.thu_morning_from.value>=document.officehours.thu_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.thu_morning_from.focus();
	 return false;
	}
	if(document.officehours.fri_morning_from.value!="" && (document.officehours.fri_morning_from.value>=document.officehours.fri_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.fri_morning_from.focus();
	 return false;
	}
	if(document.officehours.sat_morning_from.value!="" && (document.officehours.sat_morning_from.value>=document.officehours.sat_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.sat_morning_from.focus();
	 return false;
	}
	if(document.officehours.sun_morning_from.value!="" && (document.officehours.sun_morning_from.value>=document.officehours.sun_morning_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.sun_morning_from.focus();
	 return false;
	}
	if(document.officehours.mon_evening_from.value!="" && (document.officehours.mon_evening_from.value>=document.officehours.mon_evening_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.mon_evening_from.focus();
	 return false;
	}
	if(document.officehours.tue_evening_from.value!="" && (document.officehours.tue_evening_from.value>=document.officehours.tue_evening_from.value))
	{alert("from time can not be greater than to time");
	 document.officehours.tue_evening_from.focus();
	 return false;
	}
	if(document.officehours.wed_evening_from.value!="" && (document.officehours.wed_evening_from.value>=document.officehours.wed_evening_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.wed_evening_from.focus();
	 return false;
	}
	if(document.officehours.thu_evening_from.value!="" && (document.officehours.thu_evening_from.value>=document.officehours.thu_evening_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.thu_evening_from.focus();
	 return false;
	}
	if(document.officehours.fri_evening_from.value!="" && (document.officehours.fri_evening_from.value>=document.officehours.fri_evening_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.fri_evening_from.focus();
	 return false;
	}
	if(document.officehours.sat_evening_from.value!="" && (document.officehours.sat_evening_from.value>=document.officehours.sat_evening_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.sat_evening_from.focus();
	 return false;
	}
	if(document.officehours.sun_evening_from.value!="" && (document.officehours.sun_evening_from.value>=document.officehours.sun_evening_to.value))
	{alert("from time can not be greater than to time");
	 document.officehours.sun_evening_from.focus();
	 return false;
	}*/
	

}

function validappointment()
{
	if (trim(document.appointment.fname.value)=="")
	{
		alert('Please enter your full Name');
		document.appointment.fname.focus();
		return false;
	}
	if (isChar(document.appointment.fname.value)==false)
	{
		alert('special characters are not allowed');
		document.appointment.fname.focus();
		return false;
	}
	
	if (isEmail(document.appointment.email.value)==false)
	{
		alert('Please enter valid E-mail address');
		document.appointment.email.focus();
		return false;
	}
	if (trim(document.appointment.phone.value)=="")
	{
		alert('Please enter Telephone number');
		document.appointment.phone.focus();
		return false;
	}
	if (isNumeric(document.appointment.phone.value)==false)
	{
		alert('Please enter numeric values only');
		document.appointment.phone.focus();
		return false;
	}
	if (trim(document.appointment.bdescription.value)=="")
	{
		alert('Please enter your comments');
		document.appointment.bdescription.focus();
		return false;
	}
	
}	

