$(document).ready(function() {
    /*  */
	$(".mandatory").append("<span><span>*</span></span>");
	$("span>span").css('color','red','underline');
    $("#uploadedImage").hide();
    var imagePath=$("#SITE_URL").val()+"images/calendar.gif";
    
	photoUpload();
    
    $("#dob").datepicker({changeMonth: true,changeYear: true,yearRange:'-80:+10',showOn: 'button', buttonImage: imagePath, buttonImageOnly: true,buttonText: 'Select date', maxDate: 'y m d',dateFormat: 'dd-mm-yy'}); 
    
        $("#docreg").validate({
            
            rules:{
                phone:{
                	number:true
                },
                mobile:{
                	number:true
                },
                email:{
						required:true,
					    email:true,
					    remote:"index.php?act=checkemail"	
				},
                cpwd:{
                        equalTo:"#pwd"
                },
                cpwd:{
                    equalTo:"#pwd"
                },
                 security_code:{
                        required:true,
                        remote:"index.php?act=captcha_verification"   
                    }   
        },
        messages:{
        
            fname:"Please enter your first name",
            lname:"Please enter your last name",
            dob:"please select your date of birth",
            mobile:{
            	required: "Please enter your mobile number",
                number: "please enter only numbers"
            },
            phone:{
            	
                number: "please enter only numbers"
            },
            pwd:
            {
            	required: "Please enter password",
                minlength: "password should be of minimum 6 characters"
            },
            
            specialization:"Please select the specialization",
            cpwd:{
                      required: "Please enter comfirm password",
                      equalTo:"Password mismatch"
                },
			email:{
				required:"Please enter your email id",
				email:"Please enter a valid email id",
				remote:"This email id already exists"
			},
			 security_code:{
				remote:"Please enter currect security_code"
			},
            address:"Please enter the address",
            city:"Please select the city",
            state:"Please select the state",
            locations: "Please select the location",
            description: "Please enter your description"
        }   
            
            });
            
 
  
  $("#state").change(function (){ 
			var state=$("#state").val();
			var options = '';
				options += '<option value="">Select</option>';
			if(state == ""){
				$("select#city").html(options);
				$("select#locations").html(options);
				return;
			}
			var postdata = "stateId="+state;
			
		 	$.ajax({
			    url: 'index.php?act=getcity',
			    type: 'POST',  
			    data: postdata,
			    dataType: 'json',
			    error: function(){
			       // alert('Error loading data document');
			    },
			    success: function(data){

			    if(data){
			    	
				      for (var i = 0; i < data.length; i++) {
				       options += '<option value="' + data[i].id + '">' + data[i].city_name + '</option>';
				      }
     				 $("select#city").html(options);
					}
			    }
			});
	});
			      	
$("#city").change(function(){
			var city=$("#city").val();
			var options = '';
				options += '<option value="">Select</option>';
			if(city == ""){
				$("select#locations").html(options);
				return;
			}
			var postdata = "cityId="+city;
		 	$.ajax({
			    url: 'index.php?act=getlocation',
			    type: 'POST',
			    data: postdata,
			    dataType: 'json',
			    error: function(){
			       // alert('Error loading data document');
			    },
			    success: function(data){
			      if(data){
			    	
			    	 var options = '';
				      for (var i = 0; i < data.length; i++) {
				        options += '<option value="' + data[i].id + '">' + data[i].location_name + '</option>';
				      }
     			 $("select#locations").html(options);
					}
			    }
			});
		});
        
 });
 
 function photoUpload(){
 	$("#doctorPhoto").change(function(){
	  	var doc=$("#doctorPhoto").val();
	  	var dotPlace=doc.indexOf(".");
	  	var docph=doc.split(".");
	  	/*
	  	 * 
	  	 * to retrieve the extension of image file i am writing this for loop
	  	 * some file names may have more than one "."(dot) to get the last array element 
	  	 * i am writing this for loop
	  	 *
	  	 *  kalyan 18-09-09
	  	 */
	  	for(var i=0;i<docph.length;i++){}
	  	var ext=i-1;
	  	docph[ext]=docph[ext].toLowerCase();	  	
	  	if( docph[ext] == "jpg" || docph[ext] == "gif" || docph[ext] == "png"){
	  		$('#doctorUploadPhoto').removeAttr('disabled');
	  	}else{
	  		$('#doctorUploadPhoto').attr('disabled', true);
	  	}
	});
 }
 
 function isNumberKey(evt)
{
       var charCode = (evt.which) ? evt.which : event.keyCode;
      
       if (charCode > 31 && (charCode < 48 || charCode > 57))
          return false;

       return true;

}
 
	 $("#doctorPhoto").validate({
		rules: {
	 	},
	 	messages:{
	 				doctorPhoto: {
		 						accept: "Please select jpg files only"
	 				}
		}
	 });

