var loc_val = new Array();
var loc_id = new Array();
var loc_id1 = new Array();
var loc_ct = 0;
var timeLeft = 30; 

function select_loc_id(val) 
{      
    if(loc_id1.length > 0)
    {
        loc_id1=[]; 
    }
    
	var v='';  
	loc_val.splice(val, 1); 
	loc_id.splice(val, 1);  
	 
	if(loc_val.length > 0)
	{
	   var res = loc_id.join(",");  
	   $("#locations_val").val(res);  
	
	  for (var i = 0, len = loc_val.length; i < len; i++) 
		v += '<a  href=javascript:void(0) onclick=select_loc_id("'+i+'") >'+loc_val[i]+' X </a>';   
		
		$("#locality_placed").html(v);   
	    loc_ct--;
	}
	else alert("At least one job preference required");
}


function Addlocation(name,val)  
{ 
    new_name =   name.replace(new RegExp("%20", "g"), ' ');     
    new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');  
    
    loc_val.push(new_name); 
	///loc_id.push(val); 
	loc_id.push(val.toString());
    loc_ct++;
}

function myFunction() 
{ 
    $("#update_profile_msg").html("");
	$("#update_profile_error").html("");
	$("#change_pwd_error").html("");
	$("#add_mob_form").closest('form').find("input[type=text], textarea").val("");
	$("#verifiedemail_frm").closest('form').find("input[type=text], textarea").val("");
	$("#add_email_form").closest('form').find("input[type=text], textarea").val("");
	$("#changepwd_frm").closest('form').find("input[type=password], textarea").val("");
}

function checkProfile()
{
    alert("Kindly update your profile");
}

function clear_errMsg()
{ 
    $("#participant_prog_frm").validate().resetForm(); 
    $("#participant_prog_error").html("");   
} 

function select_job_role(value)
{
    var role_val = [];
    var check_res='';
    
    if(loc_id1.length > 0)
    {
        loc_id1=[]; 
    }
    
    $(':checkbox:checked').each(function(i){
          role_val[i] = $(this).val();
          loc_id1.push($(this).val());
    });
    
    check_res = loc_id1.join(",");  
    $("#locations_val").val(check_res); 
    
    document.getElementById('abc').style.display = "none";
    
    $.ajax({	
		type: "POST",
		url: URL+"/all-ajax/job.php", 
		data: {select_job_rolePrefered:1,val:check_res},
		beforeSend: function(){ 
		},
		success: function(data)
		{ 
		    var obj = jQuery.parseJSON(data);  
			if(obj==null || obj=='null')
			{ 
				
			}else
			{ 
			    rolePrefered='';
			    for(i=0;i<obj.length;i++)
			    {
			        rolePrefered+='<a href=javascript:void(0) value="'+obj[i].id+'" onclick=select_loc_id("'+obj[i].id+'") >'+obj[i].name+' X </a>';
			    }
			    $("#locality_placed").html(rolePrefered); 
			}    
		}
    });
}

function get_age(val)
{
   if(val < 18)
   {
       alert("Age should be atleast 18 years old");
       $("#age").val('');
   }
}  

function select_role_post_job(name,val,originId) 
{   
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#job-category").val(new_name);
	$("#job-category-sugeetion-ajax").hide(400);    
	$("#job-category").next().slideUp();
	$("#job_cat_val").val(val);
 
	
    if(loc_id.indexOf(val) < 0)
    {
 	var v='';
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#select-sub-locations").val(new_name);
	$("#job-loction-sugeetion-ajax").hide(400);    
	$("#select-sub-locations").next().slideUp();  
	 
	
	loc_val.push(new_name); 
	loc_id.push(val);  
	var res = loc_id.join(",");   
	$("#locations_val").val(res);  
	
	for (var i = 0, len = loc_val.length; i < len; i++) 
		v += '<a  href=javascript:void(0) onclick=select_loc_id("'+i+'")  >'+loc_val[i]+' X </a>';
	 
	
	$("#locality_placed").html(v);
	$("#job-category").next().slideUp();
	$("#job-category").val(''); 
	 
	loc_ct++;  
	 
    }
    else
	{
	    $("#select-sub-locations").next().slideUp();
	    $("#job-loction-sugeetion-ajax").hide(); 
	    $("#job-category").val('');
		alert("Role already added!");
	}
}

$(document).ready(function(){   
    
    $("#job-category").click(function()
    {
			$(this).next().slideDown();
			job_cat_set = 0;
	}); 
		
	
	$("#job-category").keyup(function() 
	{
		var job_loc_val="";
		var job_str="";
		//if($("#locations_val").val()!="")
		{
    	    job_loc_val = $("#locations_val").val();
    	    job_str = job_loc_val.split(",");
		}
	
	    if(job_str.length < 10)
	    {
    		$("#job-sub-category").hide();
    		$("#job-sub-category").html('');
    		$("#job_cat_val").val('');
    		$.ajax({	
    			type: "POST",
    			url: URL+"/all-ajax/job.php", 
    			data: {select_job_categoryProfile:1,keyword:$(this).val()},
    			beforeSend: function(){ 
    			},
    			success: function(data)
    			{  
    				var obj = jQuery.parseJSON(data);  
    				if(obj==null || obj=='null')
    				{  
    					$("#job-category-sugeetion").hide(); 
    					$("#job-category-sugeetion-ajax").hide();
    					//$("#job-role-ul").show();		
    				}else
    				{  	
    					source_first_name = obj[0].name; 
    					source_list = '<ul class="menu-box">'; 
    					
    					for(i=0;i<obj.length;i++)			  
    					source_list +='<a href="javascript:void(0)"><li onclick=select_role_post_job("'+encodeURIComponent(obj[i].catName)+'","'+obj[i].id+'","'+obj[i].originId+'") >'+obj[i].name+'</li></a>' 
    					
    					source_list +='</ul>';   
    					 
    					$("#job-category-sugeetion-ajax").show();
    					$("#job-category-sugeetion-ajax").html(source_list);
                        $("#job-category-sugeetion").hide();					
    				}   
    				
    			}
    		}); 
	    }
	    else
	    {
	        alert("You can add job preferences upto 10");
	        $("#job-sub-category").hide();
    		$("#job-sub-category").html('');
    		$("#job_cat_val").val('');
    		
    		$("#job-category").val('');
	    }
	});	
		
    /*$("#job-category").keyup(function() 
	{  
		//$("#job-role-ul").hide();
		$("#job-sub-category").hide();
		$("#job-sub-category").html('');
		$("#job_cat_val").val('');
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/job.php", 
			data: {select_job_categoryProfile:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{  
				
				var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{  
					$("#job-category-sugeetion").hide(); 
					$("#job-category-sugeetion-ajax").hide();
					//$("#job-role-ul").show();		
				}else
				{  	
					source_first_name = obj[0].name; 
					source_list = '<ul class="menu-box-2">'; 
					
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"  ><li onclick=select_role_post_job("'+encodeURIComponent(obj[i].catName)+'","'+obj[i].id+'","'+obj[i].originId+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';   
					 
					$("#job-category-sugeetion-ajax").show();
					$("#job-category-sugeetion-ajax").html(source_list);
                    $("#job-category-sugeetion").hide();					
				}   
				
			}
		}); 
	});*******/
	
	$("#city_next").hide();
	$("#profile_location_next").hide();
	
	$("#submit_participant_prog").off().on('click',function(e) 
	{   
	   clear_errMsg(); 
	   var isChecked = $("#activate_participant").is(":checked");
       if (isChecked)
  	   {
    		$.ajax({	
    			type: "POST",
    			url: URL+"/custom_function/EmailConfigure.php", 
    			data: {submit_participent_prog:1,activate_participent:$("#activate_participant").val()},
    			beforeSend: function(){ 
    			    $('#submit_participant_prog').addClass('disableloginbtn');
    			},
    			success: function(data)
    			{   
    			    $('#submit_participant_prog').removeClass('disableloginbtn'); 
    				if(data==1)
    				{
    				    $("#participant_prog").modal('hide'); 
    					window.location.href = URL+"/ReferralProgram/all-referralAds.php"; 
    				}
    			}
    		  }); 	
  	   }
  	   else 
       {    
          clear_errMsg();   
          $("#participant_prog_error").html("Please select terms and conditions");
       }
	});

    $(".changepassword_box").click(function()
	{
		$("#update_profile_msg").html("");
		$("#changepassword").modal({
		show: 'true',
		backdrop: 'static',
		keyboard:false
		});
		
		$("#new_pwd").removeClass('fa fa-eye');
		$("#new_pwd").addClass('fa fa-eye-slash');
		
		$("#show_confirm_pwd").removeClass('fa fa-eye');
		$("#show_confirm_pwd").addClass('fa fa-eye-slash');
		
	});
	
	$("#new_pwd").click(function() 
	{
    	if($(this).hasClass('fa fa-eye-slash'))
    	{           
    		$(this).removeClass('fa fa-eye-slash');
    		$(this).addClass('fa fa-eye');
    		$('#newpassword').attr('type','text');          
    	}
    	else
    	{ 
    	  $(this).removeClass('fa fa-eye');  
    	  $(this).addClass('fa fa-eye-slash');  
    	  $('#newpassword').attr('type','password');
    	}
    });
    
    $("#show_confirm_pwd").click(function() 
	{
    	if($(this).hasClass('fa fa-eye-slash'))
    	{           
    		$(this).removeClass('fa fa-eye-slash');
    		$(this).addClass('fa fa-eye');
    		$('#confirmpassword').attr('type','text');          
    	}
    	else
    	{ 
    	  $(this).removeClass('fa fa-eye');  
    	  $(this).addClass('fa fa-eye-slash');  
    	  $('#confirmpassword').attr('type','password');
    	}
    });
	
	
	$("#profile_city_search").click(function(){ 
			$(this).next().slideDown();    
	});
	
	$("#profile_location").click(function(){ 
			$(this).next().slideDown();
	});

	 
	$("body").click(function(e) 
	{  	    
		if ( e.target.id == "profile_city_search" || $(e.target).parents("#city-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#profile_city_search").next().slideUp();
			$("#city-ajax").hide(400); 
		}

		if ( e.target.id == "city_next" || $(e.target).parents("#profile_city_search").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			//$("#select-sub-locations").next().slideUp();
		}
		
		
		if ( e.target.id == "profile_location" || $(e.target).parents("#profile_location-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#profile_location").next().slideUp();
			$("#profile_location-ajax").hide(400); 
		}

		if ( e.target.id == "profile_location_next" || $(e.target).parents("#profile_location").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			//$("#select-sub-locations").next().slideUp();
		}
		
		
		if ( e.target.id == "job-category" || $(e.target).parents("#job-category-sugeetion-ajax").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			$("#job-category").next().slideUp();
			$("#job-category-sugeetion-ajax").hide(400);
		} 
		
		if ( e.target.id == "job-category-sugeetion" || $(e.target).parents("#job-category").size() ) 
		{ 
			 //alert("Inside div");   
		} else 
		{    
			
			//$("#select-sub-locations").next().slideUp();
			 
		}
		
	});	
		
	
	$("#profile_city_search").keyup(function() 
	{     
		$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {select_city:1,keyword:$(this).val()},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
			   var obj = jQuery.parseJSON(data);  
				if(obj==null || obj=='null')
				{   
			        $("#city-ajax").hide();
					$("#city_next").hide();
			        $("#profile_city_search").val('No record found');		 					
				}else
				{  	 
					source_list = '<ul class="menu-box">';  
					for(i=0;i<obj.length;i++)			  
					source_list +='<a href="javascript:void(0)"><li onclick=select_city("'+encodeURIComponent(obj[i].name)+'","'+obj[i].id+'") >'+obj[i].name+'</li></a>' 
					
					source_list +='</ul>';  
					$("#city-ajax").show();
					$("#city-ajax").html(source_list);
                    $("#city_next").hide(); 					
				}				
			}
		}); 
	});     
	 
	$("#get_main_mobnum").keyup(function(e) 
	{
	    set = 0;
		phone = 0;
		details = $(this).val(); 
		
		if (/^[0-9]{10}$/.test(+details)) 
		{ 
			set = 1; 
			phone = 1;
		}
	    
	    if(set==1)
        {
            $.ajax({	
			type: "POST",
			//url: URL+"/all-ajax/MyDetails.php", 
			url: URL+"/custom_function/EmailConfigure.php", 
			data: {mainmobnum_OTP_verified:1,ph:details},
			beforeSend: function(){ 
			},
			success: function(data)
			{ 
			    if((data==0) && (phone==1))
			    {
    				$("#verify-mobile-models").modal({
    				show: 'true',
    				backdrop: 'static',
    				keyboard:true
    				}); 
    				
    				var timeLeft = 30;
    				var elem = document.getElementById('profile_mobile_div');
    				var timerId = setInterval(countdown2, 1000);
    				function countdown2() {
    				  $("#profile_mobile_div").show();
    				  if (timeLeft == 0) {
    				   clearTimeout(timerId);
    				   $("#profile_mobile_otp").show();
    				   $("#profile_mobile_div").hide();
    				  }
    				  else {				
    					elem.innerHTML = timeLeft + ' seconds remaining';
    					timeLeft--;	                				
    				  }			  
    				}
    				e.preventDefault();
			     }
			     else if(data==1 && phone==1)
			     {
			        alert("Mobile no already exits");
			        $("#get_main_mobnum").val("");
			        e.preventDefault();	
			     }
			  }
			});
        }
        e.preventDefault();	
	});    
	 
	
	$("#Add_More_Mobile").click(function(e) 
	{   
		$("#Add_More_Mobile_PopUp").modal({
			show: 'true',
			backdrop: 'static',
			keyboard:true
			}); 
	});
	
	$("#Add_More_Email").click(function(e) 
	{    
		$("#Add_More_Email_Popup").modal({
			show: 'true',
			backdrop: 'static',
			keyboard:true
		}); 
	});
	
	$("#change_password").click(function(e) 
	{   
		$("#Change_Password_PopUp").modal({
			show: 'true',
			backdrop: 'static',
			keyboard:true
			});   
	});


     jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-z\-_\s]+$/i.test(value);
      }, "Use letters & (_,-) only"); 
				
	
	jQuery.validator.addMethod("lettersonlyAddress", function(value, element) {
        return this.optional(element) || /^[a-z\.-_\s]+$/i.test(value);
      }, "Use letters & (_,-.) only"); 
		
					
				
	
    $("#userprofilefrm").validate({ 
			
			errorElement:'div',
			rules:{
		    UserName:{
				required: true,
				maxlength: 25,
				minlength: 3,
				lettersonly:true 
				}, 
			email:{
				required: true,
				email: true,
                remote: URL+"/MyDetails/value_check.php"				
				},  
		    main_ph:{
                    required:true,
				    number:true,
				    minlength:10,
				    maxlength:10,
                    remote: URL+"/MyDetails/value_check.php"						
                },  
            age:{
				required: true,
				number:true,
                maxlength:2,				
				},
				
		    profile_city_search:{
				required: true							
				},
				
			location:{
				required: true							
				},
				
			gender:{
				required: true							
				},
				
			address:{
				 required:true,
				 minlength:10,
                 maxlength:100,
                 lettersonlyAddress:true
				}/*,
				
				user_type:{
				required: true							
				}*/
			},
			messages:{	
     		UserName:{
				 required:"Please enter your name" 
				},   
			email:{
				 required:"Please enter valid Email Id",
                 remote: "This email is already registered"				 
				}, 
			   main_ph:{
				required:"Please enter an Mobile No",	
				minlength : "Please enter minimum 10 digits",
				maxlength : "Max 10 digits are allowed",
                remote: "This number is already registered"				
			   },            
			  age:{
				required:"Please enter an age",	
                maxlength : "Max 2 digits are allowed",				
			   },
			   
			   profile_city_search:{
				required:"Please select city"				 				
			   },
			   
			   location:{
				required:"Please select location"				 				
			   },
			   
			   gender:{
				required:"Please select gender"				 				
			   },
			   
			   address:{					
                  required:"Please Enter an address",
				  minlength : "Please Enter minimum 10 characters address",
                  maxlength : "Max 100 characters are allowed"				  
				}/*,
				
				user_type:{
				required:"Please select user type"				 				
			   }*/
            } 			  
		});

        $("#changepwd_frm").validate({ 
			
			errorElement:'div',
			rules:{ 
			/*oldpassword:{
				required: true							
				},	*/	 
				
		    newpassword:{
				required: true,
				 minlength:5,
				 maxlength:30
				},

            confirmpassword:{
				required: true,
				minlength:5,
				 maxlength:30
				}				
			},
			messages:{	
     			/*oldpassword:{
				 required:"Please enter old password"			 						
				},	*/	
			   
			   newpassword:{
				required:"Please enter new password",
				minlength : "Please enter minimum 5 characters password",
				maxlength : "Max 30 characters are allowed"  
			   },
			   
			   confirmpassword:{
				required:"Please enter confirm password",
				minlength : "Please enter minimum 5 characters password",
				maxlength : "Max 30 characters are allowed" 
			   }			                			   
            } 				
      });  

	  
	   $("#add_email_form").validate({ 
			
			errorElement:'div',
			rules:{ 
			   add_more_email:{
				required: true,
				email: true  
				}		
			},
			messages:{	
     			add_more_email:{
				 required:"Please Enter  Email",
				 email: "Please enter valid email"
				}	                			   
            } 				
        }); 
		
		$("#add_email_form" ).submit(function(event) 
		{
			if ($('#add_email_form').valid()) 
			{    
					event.preventDefault();    
					$.ajax({	
					type: "POST",
					url: URL+"/MyDetails/value_check.php",			
					data: {add_more_email:$("#add_more_email").val()},
					beforeSend: function(){ 
					},
					success: function(data)
					{  	 
						 if(data=="true")
							location.href = URL+"/MyDetails/default.php?addEmail="+$("#add_more_email").val();  
						 else
						 {
							 alert("Email is already exist");
							 $("#add_more_email").val('');
						 }
					}
					});        
					 
			}  
		});

        $("#edit_email_form").validate({ 
			
			errorElement:'div',
			rules:{ 
			   edit_more_email:{
				required: true,
				email: true  
				}		
			},
			messages:{	
     			edit_more_email:{
				 required:"Please Enter  Email",
				 email: "Please enter valid email"
				}	                			   
            } 				
        });		
		
		$("#edit_email_form" ).submit(function(event) 
		{
			if ($('#edit_email_form').valid()) 
			{    
					event.preventDefault();    
					$.ajax({	
					type: "POST",
					url: URL+"/MyDetails/value_check.php",			
					data: {edit_more_email:+$("#edit_more_email").val(),more_emailid_hidden:+$("#more_emailid_hidden").val()},
					beforeSend: function(){ 
					},
					success: function(data)
					{  	 
						 if(data=="true")
					     {
							location.href = URL+"/MyDetails/default.php?edit_more_email="+$("#edit_more_email").val() +'&'+ "edit_more_emailid="+$("#edit_more_emailid").val()+'&'+ "more_emailid_hidden="+$("#more_emailid_hidden").val();  
						 }
						 else
						 {
							 alert("Email is already exist");
							 $("#edit_more_email").val('');
						 }
					}
					});        
					 
			}  
		});	
		
		
       
        $("#add_mob_form").validate({ 
			
			errorElement:'div',
			rules:{ 
			   add_more_mob:{
				required: true,
				number: true,
				maxlength:10,
				minlength:10  
                //remote: 
				}		
			},
			messages:{	
     			add_more_mob:{
				 required:"Please Enter Mobile No",
				 maxlength: "You can enter maximum 10 digits",
				 minlength:  "Please enter minimum 10 digits"
                 //remote: "This no. is already exist!"				 
				}	                			   
            } 				
        }); 
		
		$("#profile_resend_otp").click(function(e)
		{
			$("#profile_resend_otp").hide();
			$.ajax({	
			type: "POST",
			url: URL+"/all-ajax/MyDetails.php", 
			data: {check_resend_otp:1},
			beforeSend: function(){ 
			},
			success: function(data)
			{   
			    alert("OTP sent!"); 
				var timeLeft = 30;
				var elem = document.getElementById('profile_some_div');
				var timerId = setInterval(countdown1, 1000);
				function countdown1() {
				  $("#profile_some_div").show();
				  if (timeLeft == 0) {
				   clearTimeout(timerId);
				   $("#profile_resend_otp").show();
				   $("#profile_some_div").hide();
				  }
				  else {				
					elem.innerHTML = timeLeft + ' seconds remaining';
					timeLeft--;	                				
				  }			  
				}		
			}
		   }); 	
		});
		
		$("#profile_resend_otp").hide();
		$("#add_mob_form" ).submit(function(event) 
		{
			if ($('#add_mob_form').valid()) 
			{    
					event.preventDefault();    
					$.ajax({	
					type: "POST",
					url: URL+"/MyDetails/value_check.php",			
					data: {add_more_mob:+$("#add_more_mob").val()},
					beforeSend: function(){ 
					},
					success: function(data)
					{  	 
						 if(data=="true")
						 {
							$("#Add_More_Mobile_PopUp").modal('hide'); 
							$.ajax({	
							type: "POST",
							//url: URL+"/all-ajax/MyDetails.php",
							url: URL+"/custom_function/EmailConfigure.php",
							data: {verified_mobile_for_otp:1,ph:$("#add_more_mob").val()},
							beforeSend: function(){ 
							},
							success: function(data)
							{  	 
							    $("#entered_opt_for_mobile").attr("placeholder", "Enter OTP sent to "+$("#add_more_mob").val());
								
								$("#verify-mobile-model").modal({
								show: 'true',
								backdrop: 'static',
								keyboard:true
								}); 
								
								var timeLeft = 30;
								var elem = document.getElementById('profile_some_div');
								var timerId = setInterval(countdown2, 1000);
								function countdown2() {
								  $("#profile_some_div").show();
								  if (timeLeft == 0) {
								   clearTimeout(timerId);
								   $("#profile_resend_otp").show();
								   $("#profile_some_div").hide();
								  }
								  else {				
									elem.innerHTML = timeLeft + ' seconds remaining';
									timeLeft--;	                				
								  }			  
								}								
							}
							});         
							 
						 }else
						 {
							 alert("No is already exist");
							 $("#add_more_mob").val('');
						 }
					}
					});        
					 
			}  
		});	 

        $("#edit_mob_form").validate({ 
			
			errorElement:'div',
			rules:{ 
			   edit_more_mob:{
				required: true,
				number: true,
				maxlength:10,
				minlength:10  
                //remote: 
				}		
			},
			messages:{	
     			edit_more_mob:{
				 required:"Please Enter Mobile No",
				 maxlength: "You can enter maximum 10 digits",
				 minlength:  "Please enter minimum 10 digits"
                 //remote: "This no. is already exist!"				 
				}	                			   
            } 				
        });		
		
		$("#profile_mobile_otp").hide();
		$("#edit_mob_form").submit(function(event) 
		{
			if ($('#edit_mob_form').valid()) 
			{    
					event.preventDefault();    
					$.ajax({	
					type: "POST",
					url: URL+"/MyDetails/value_check.php",			
					data: {edit_more_mob:+$("#edit_more_mob").val(),edit_more_mob_id:+$("#edit_more_mob_id").val(),more_mobid_hidden:+$("#more_mobid_hidden").val()},
					beforeSend: function(){ 
					},
					success: function(data)
					{  	
                        if(data=="true")
						{
							$("#Edit_More_Mobile_PopUp").modal('hide'); 
							$.ajax({	
							type: "POST",
							url: URL+"/all-ajax/MyDetails.php", 
							data: {verified_mobile_for_OTP:1,ph:$("#edit_more_mob").val(),id:$("#more_mobid_hidden").val(),val:$("#edit_more_mob_id").val()},
							beforeSend: function(){ 
							},
							success: function(data)
							{  	 
								$("#verify-mobile-models").modal({
								show: 'true',
								backdrop: 'static',
								keyboard:true
								}); 
								
								var timeLeft = 30;
								var elem = document.getElementById('profile_mobile_div');
								var timerId = setInterval(countdown2, 1000);
								function countdown2() {
								  $("#profile_mobile_div").show();
								  if (timeLeft == 0) {
								   clearTimeout(timerId);
								   $("#profile_mobile_otp").show();
								   $("#profile_mobile_div").hide();
								  }
								  else {				
									elem.innerHTML = timeLeft + ' seconds remaining';
									timeLeft--;	                				
								  }			  
								}
								
							}
							});     							 
						}
						else
						{
							alert("No is already exist");
							$("#edit_more_mob").val('');
						}
					}
					});        
					 
			}  
		});
		
		
		$("#submit_mob_otp").click(function()
		{   
			$.ajax({	
				type: "POST",
				url: URL+"/all-ajax/MyDetails.php", 
				data: {varify_mobile:1,entered_opt_for_mobile:$("#entered_opt_for_mobile").val()},
				beforeSend: function(){ 
				},
				success: function(data)
				{   
					if(data==1)
					{
						alert("Mobile no successfully verified!");
						location.reload();
					}
					else
						alert("Wrong OTP!!! Please enter correct OTP");
				}
			  }); 		
		});
		
		$("#submit_mob_OTP").click(function()
		{   
			$.ajax({	
				type: "POST",
				url: URL+"/all-ajax/MyDetails.php", 
				data: {varify_mobiles:1,entered_OTP_for_mobile:$("#entered_OTP_for_mobile").val()},
				beforeSend: function(){ 
				},
				success: function(data)
				{   
					if(data==1)
					{
						alert("Mobile no successfully verified!");
						location.reload();
					}
					else
						alert("Wrong OTP!!! Please enter correct OTP");
				}
			  }); 		
		});	
		
	
		$("#changepwd_frm").submit(function( event )  // on click on this id...we will do folowwings
		{ 		   
			if($('#changepwd_frm').valid())  
			{ 		        
			   //if(($("#password_letter").hasClass("correct")) && ($("#password_capital").hasClass("correct")) && ($("#password_number").hasClass("correct")) && ($("#password_length").hasClass("correct")) && ($("#password_special_character").hasClass("correct")) ) 
		       { 
                    clear_profile_error_msg();
                    var formData = $('#changepwd_frm').serialize();  // i have taken all form in serialized format here...
                    $.ajax({	
                    type: "POST",
                    //url: URL+"/all-ajax/MyDetails.php", 
                    url: URL+"/custom_function/EmailConfigure.php", 
                    data: {user_changepwd_formData:1,formData:formData},	
                    		beforeSend: function(){
                    			//$("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
                    		},
                    	  success: function(val)
                    	  {  		
                            if(val==0)
                            {
                                $("#password_message").hide();
                                $("#oldpassword").val('');
                                $("#newpassword").val('');
                                $("#confirmpassword").val('');
                    			$("#change_pwd_success").html("Your password has been changed successfully");//Password Updated Successfully!!!
                    		  
                            }
                    		else if(val==1)
                    		{
                    		    $("#password_message").hide();	
								$("#newpassword").val('');
                                $("#confirmpassword").val('');								
                    			$("#change_pwd_error").html("Password pattern not match"); 
                    		}
                    		else if(val==2)
                    		{
                    		    $("#password_message").hide();
                                $("#newpassword").val('');
                                $("#confirmpassword").val('');								
                    			$("#change_pwd_error").html("Password not match"); 
                    		}
                    		else if(val==3)
                    		{
                    		    $("#password_message").hide();
                                $("#newpassword").val('');
                                $("#confirmpassword").val('');								
                    			$("#change_pwd_error").html("Incorrect Old Password");	
                    		}
                    	 }  
                    });  
		       }
		       /*else
        	   {
				   if(($("#newpassword").val()=='') && ($("#confirmpassword").val()==''))
				   {
					   $("#password_message").hide();
				   }
				   else if(($("#password_letter").hasClass("invalid")) || ($("#password_capital").hasClass("invalid")) || ($("#password_number").hasClass("invalid")) || ($("#password_length").hasClass("invalid")) || ($("#password_special_character").hasClass("invalid"))) 
				   {
						$("#password_message").show();
						event.preventDefault();
				   }
				   
        	   }*/	 
			}
			event.preventDefault();  // this is help to prevent from submit
		});
		
		
		$("#userprofilefrm").off().submit(function(e)  // on click on this id...we will do folowwings
		{ 		   
			if($('#userprofilefrm').valid())  
			{ 
			    var formData = $('#userprofilefrm').serialize();  // i have taken all form in serialized format here...
			    ///if($("#user_type").val()==1)
			    ///{
			       $.ajax({	
    				type: "POST",
    				url: URL+"/all-ajax/MyDetails.php", 
    				data: {update_profile_formData:1,formData:formData},	
        					beforeSend: function(){
        					    $('#update_profile').addClass('disableloginbtn');
        						//$("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
        					},
        				  success: function(val)
        				  {  		
        				    $('#update_profile').removeClass('disableloginbtn'); 
        				    if(val==1)
        				    {
        				        alert("Your profile updated successfully");
        				        window.location.href = URL+"/MyDetails/"; 
        				    }
        					else if(val==0)
        					{
        						alert("Profile not updated");
        						//event.preventDefault();  // this is help to prevent from submit
        					}
        					 e.preventDefault();
        				 }  
    				});
			   /* }
			    else if($("#user_type").val()==2)
			    {
    			    if( ($("#locations_val").val()!='') || ($("#job_cat_val").val()!='') )
    			    {
        				$.ajax({	
        				type: "POST",
        				url: URL+"/all-ajax/MyDetails.php", 
        				data: {update_profile_formData:1,formData:formData},	
            					beforeSend: function(){
            					    $('#update_profile').addClass('disableloginbtn');
            						//$("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
            					},
            				  success: function(val)
            				  {  		
            				    $('#update_profile').removeClass('disableloginbtn'); 
            				    if(val==1)
            				    {
            				        alert("Your profile updated successfully");
            				        window.location.href = URL+"/MyDetails/"; 
            				    }
            					else if(val==0)
            					{
            						alert("Profile not successfully");
            						//event.preventDefault();  // this is help to prevent from submit
            					}
            					 e.preventDefault();
            				 }  
        				});    
    			    }
    			    else
    			    {
    			        $("#job-category").val("");
    			        $('#update_profile').removeClass('disableloginbtn'); 
    			        alert("At least one job preference required");
                        e.preventDefault();
    			    }
			    }*/
			}
			e.preventDefault();
		});
	
}); 	     



function del_addition_data(val)
{ 
	var r = confirm("Do you really want to delete phone no !");    
	if (r == true) 
	{    
			$.ajax({
			type: 'POST',
			url: URL+"/all-ajax/MyDetails.php",
			//async: false,			 
			data: {del_addition_details:1,val:val},	  
			success: function(ajaxresult){	     
					location.reload();	 	
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) { 
			alert('Error');
			}
			});  
	}	 
}  

function del_addition_email(val)
{ 
	var r = confirm("Do you really want to delete email !");    
	if (r == true) 
	{    
			$.ajax({
			type: 'POST',
			url: URL+"/all-ajax/MyDetails.php",
			//async: false,			 
			data: {del_addition_details:2,val:val},	  
			success: function(ajaxresult){	     
					location.reload();	 	
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) { 
			alert('Error');
			}
			});  
	}	 
}

function verify_mainemail(id,val,val1)
{ 
	  
	$.ajax({
	type: 'POST',
	//url: URL+"/all-ajax/MyDetails.php",
	url: URL+"/custom_function/EmailConfigure.php",
	//async: false,			 
	data: {verify_mainemail_details:1,id:id,val:val,val1:val1},	  
	success: function(data){	     
	    //location.reload();
		alert("We have sent link on your mail id to verify it kindly check your registered mail id");
	 }	
  });  		 
}  

function verify_email(id,val,val1)
{ 
	  
	$.ajax({
	type: 'POST',
	//url: URL+"/all-ajax/MyDetails.php",
	url: URL+"/custom_function/EmailConfigure.php",
	//async: false,			 
	data: {verify_email_details:2,id:id,val:val,val1:val1},	  
	success: function(data){	     
	    //location.reload();
		alert("Please check the email box!!!");
	 }	
	});  		 
} 

function get_mainno(val,id)
{
	$("#edit_more_mob").val(val);	
	$("#more_mobid_hidden").val(id);
	$("#Edit_More_Mobile_PopUp").modal({
	show: 'true',
	backdrop: 'static',
	keyboard:true
	}); 
}

function get_phno1(val,val1,id)
{
	$("#edit_more_mob").val(val);
    $("#edit_more_mob_id").val(val1);
	$("#more_mobid_hidden").val(id);	
	$("#Edit_More_Mobile_PopUp").modal({
	show: 'true',
	backdrop: 'static',
	keyboard:true
	}); 
}

function get_email(val,id,val1)
{
	var val=$("#edit_more_emailid").val(val);
	var id=$("#edit_more_email").val(id); 	
	var val1=$("#more_emailid_hidden").val(val1);
	console.log(val);
	console.log(id);
	console.log(val1);
	$("#Edit_More_Email_Popup").modal({
	show: 'true',
	backdrop: 'static',
	keyboard:true
	}); 
}

function get_emailid(val,id,val1)
{
	var val=$("#edit_more_emailid").val(val);
	var id=$("#edit_more_email").val(id); 	
	var val1=$("#more_emailid_hidden").val(val1);	
	console.log(val);
	console.log(id);
	console.log(val1);
	$("#Edit_More_Email_Popup").modal({
	show: 'true',
	backdrop: 'static',
	keyboard:true
	}); 
}


function  select_city(name,id)
{
	new_name =   name.replace(new RegExp("%20", "g"), ' ');     
	new_name =   new_name.replace(new RegExp("%2F", "g"), ' ');     
	$("#profile_city_search").val(new_name);
    $("#profile_city_search").next().slideUp();	
    $("#city-ajax").hide(400);	
    
    $.ajax({	
    	type: "POST",
    	url: URL+"/all-ajax/MyDetails.php", 
    	data: {select_citylocation:1,city_id:id},
    	beforeSend: function(){ 
    	},
    	success: function(data)
    	{
    	    var obj = jQuery.parseJSON(data);
			if(obj==null || obj=='null')
			{
		        //$("#profile_location").html('Not specified');	
		        locsource_list=null;
		        locsource_list='<option value="No location">Not specified</option>';
		        $("#profile_location").html(locsource_list);
			}else
			{
			    locsource_list=null;
				locsource_list='<option value="">Please Select Location</option>';
				for(i=0;i<obj.length;i++)
				locsource_list +='<option value="'+obj[i].id+'">'+obj[i].location_name+'</option>';
				
				$("#profile_location").html(locsource_list);	
			}
    	}
    });
} 

function clear_profile_error_msg()
{
    $("label.error").hide();
    $(".error").removeClass("error");
    $("#change_pwd_error").html("");
	$("#change_pwd_success").html("");
}	 

/*
var myInput = document.getElementById("newpassword");
var letter = document.getElementById("password_letter");
var capital = document.getElementById("password_capital");
var number = document.getElementById("password_number");
var password_length = document.getElementById("password_length");
var special_character=document.getElementById("password_special_character");

letter.classList.add("invalid");
capital.classList.add("invalid");
number.classList.add("invalid");
password_length.classList.add("invalid");
special_character.classList.add("invalid");

document.getElementById("password_message").style.display = "none";

// When the user clicks on the password field, show the message box
myInput.onfocus = function() {
  document.getElementById("password_message").style.display = "block";
}

// When the user clicks outside of the password field, hide the message box
myInput.onblur = function() {
  document.getElementById("password_message").style.display = "none";
}

// When the user starts to type something inside the password field
myInput.onkeyup = function() {
   $("#password_message").show();	
	
  // Validate lowercase letters
  var lowerCaseLetters = /[a-z]/g;
  if(myInput.value.match(lowerCaseLetters)) {  
    letter.classList.remove("invalid");
    letter.classList.add("correct");
  } else {
    letter.classList.remove("correct");
    letter.classList.add("invalid");
  }
  
  // Validate capital letters
  var upperCaseLetters = /[A-Z]/g;
  if(myInput.value.match(upperCaseLetters)) {  
    capital.classList.remove("invalid");
    capital.classList.add("correct");
  } else {
    capital.classList.remove("correct");
    capital.classList.add("invalid");
  }

  // Validate numbers
  var numbers = /[0-9]/g;
  if(myInput.value.match(numbers)) {  
    number.classList.remove("invalid");
    number.classList.add("correct");
  } else {
    number.classList.remove("correct");
    number.classList.add("invalid");
  }
  
  // Validate length
  if(myInput.value.length >= 6) {
    password_length.classList.remove("invalid");
    password_length.classList.add("correct");
  } else {
    password_length.classList.remove("correct");
    password_length.classList.add("invalid");
  }
  
  // Validate special character
   var Spaecialcharacters = /[!@#\$%\^\&*]/g;
  if(myInput.value.match(Spaecialcharacters)) {  
    special_character.classList.remove("invalid");
    special_character.classList.add("correct");
  } else {
    special_character.classList.remove("correct");
    special_character.classList.add("invalid");
  }
  
  if((myInput.value.match(lowerCaseLetters)) && (myInput.value.match(upperCaseLetters)) && (myInput.value.match(numbers)) && (myInput.value.password_length >= 6) && (myInput.value.match(Spaecialcharacters)))
  {
	  $("#password_message").hide();
  }
  else $("#password_message").show();
   
}

*/