$(function(){

    var Dfcolor= '#888';
    var txtcolor = '#222';
    var cssObjDf =
    {
        'color' : Dfcolor
    }
    var cssObjCh =
    {
        'color' : txtcolor
    }
    $("input[alt]='text'").each
    (
        function()
        {
            var text = this['alt'] ;
            $(this).css(cssObjDf).val(text).bind("click",
                function()
                {
                    if ($(this).val() == text)
                        $(this).css(cssObjCh).val('');
                }
                ).bind("blur",
                function()
                {
                    if ($(this).val() == '')
                        $(this).css(cssObjDf).val(text);
                }
                );
        }

        );

    $(".btn-slide").click(function(){

        $("#panel").empty();

        $("#panel").slideToggle("fast",function(){

            $("#panel_content").clone().appendTo("#panel").show();
            $(this).toggleClass('open');
            if($("#panel").attr('class')!="open"){
                $("#panel").empty();
            }
        });

        $(this).toggleClass("active");

        return false;
    });

    $("#other").live('click',function(){

        $("#othercontent").slideToggle("fast");
        $(this).toggleClass("active");
        return false;
    });

    $("#viewlocation").click(function(){

        $(this).hide();

        $("#viewlocation").after($("#changeloc"));

        $("#changeloc").show();


        return false;
    });

    $("#hidelocation").click(function(){

        $("#changeloc").hide();
        $("#searchForm").after($("#changeloc"));

        $("#viewlocation").show();
        return false;

    });

	$("#btnchangeloc").click(function(){
      
        var locationadr=$("#locationadr").val();
		
        var searchkey=$("#searchkey").val();
		     if(($("#locationadr").attr('alt')== $("#locationadr").val()) || $("#locationadr").val() == null  || $("#locationadr").val() ==''){
				 return false
				 }else{
		
	        $.ajax({
            url:baseUrl+"/ajax/searchview/changelocation/locationadr/"+locationadr,
            type:'GET',
            dataType: 'json',
            success:function(data){
                if(data.status == 200){
                  localLat=parseFloat(data.latitude);
                  localLng=parseFloat(data.longitude);
                  city=data.city;
				  adress=data.adress;
		
				$('#userlocation').text(adress);
					
                    $("#hidelocation").click();               
                   if(module=='home'){
				   $('#promo_cart_v').html('<div align="center"><img src="'+$baseUrl+'/images/loading/ajax-loader.gif"></div>');
            		   $.post($baseUrl + '/home/',{ajax:true},function(data){
           	   				$('#promo_cart_v').html(data);
             				initialize();
             				InitalizeFeaturesPromos();
             				
              			});   
                	   if($('#t2').hasClass('active')){
                		   
                		   $.post($baseUrl + '/ajax/home/pointofsale/',function(data){
              	   				$('#pointofsale').html(data);
              	   			InitalizeFeaturesPos();
                				
                 			}); 
                	   }                	   
                   	}
                    if(module=='search'){
                        document.location.href = data.pagereturn
                    }
                 
                }else{
                    $('#overlay').css({
                        width:'500px',
                        height:'auto'
                    });
                   
                    $('#overlay .contentWrap').html(data.message).css({
                        padding:'20px'
                    });
                    $('#overlay').overlay(
                    {
                        expose:{
                            color: '#fff',
                            loadSpeed: 100,
                            opacity: 0.5
                        },
                        closeOnClick:false,
                        api: true
                    }
                    ).load();

                }
            },
            error:function(data){
               
    
            }

        });

			 }
        return false;
    });

/***/
	
$("#mapbtnchangeloc").live('click',function(){
      
        var locationadr=$("#maplocationadr").val().replace(/(,)/g," ");
        $.ajax({
            url:baseUrl+"/ajax/searchview/changelocation/locationadr/"+locationadr,
            type:'GET',
            dataType: 'json',
            success:function(data){
              if(data.status == 200){
						localLat=parseFloat(data.latitude);
		                localLng=parseFloat(data.longitude);
		                city=data.city;
						adress=data.adress;
							 $('#overlay .close').click();
				$('#userlocation').text(adress);
				
					$("#overlay .tooltip").hide(); 
					
					if(module=='home'){
            			
						 
					$.post($baseUrl + '/home/',{ajax:true},function(data){
           	   			
						$('#promo_cart_v').html(data);
						initialize();
	         			InitalizeFeaturesPromos();
	         			initializemaxmap();    
             			 
              			});
						   
                	   if($('#t2').hasClass('active')){
							$.post($baseUrl + '/ajax/home/pointofsale/',function(data){
							$('#pointofsale').html(data);
							InitalizeFeaturesPos();
                			
                 			}); 
							
							
                	   }                	   
                   	}
           
                 
                }else{
				
					
		 $("#overlay .tooltip").show().find('.tooltip-m-3').html($('#changeloctooltipmsg').val()+':'+data.message);
				 
				 
                }
            },
            error:function(data){
              
    
            }

        });

        return false;
    });

/***/
	
$("#searchForm input").keypress(function(e) {
  if (e.which == 13) {
	  
    $("#nearme").click();

  }
});


$("#locationadr").keypress(function(e) {
 
  if (e.which == 13) {
    
		
			    if(($("#locationadr").attr('alt')== $("#locationadr").val()) || $("#locationadr").val() == null  || $("#locationadr").val() ==''){
		 e.preventDefault();
                return false;	
		}else{
			
		 	$("#btnchangeloc").click();
			}	
  }
});

$("#nearme").live('click',function(e){

        $query=$('#searchkey').val();
		
		var ex=false;
		
		if(module=="home"){
		
		  if($('#searchkey').attr('alt')== $('#searchkey').val() || $('#searchkey').val() == null  || $('#searchkey').val() ==''){

			ex=false;         
			 
   
        }else{
		
		ex=true;  
		}
		
		}else{
		
		
		if($('#searchkey').val() == null  || $('#searchkey').val() ==''){

				var ex=false;         
			 
   
        }else{
		ex=true;  
		}
		
		
		}
    
	if(ex){
	 $("#searchForm").submit();
	
	}else{
	    
       e.preventDefault();
                return false;
	}
         
   
       
 
    });
	

function alphaNumericCheck(input){

	var regex=/^[0-9A-Za-z]+$/; 

	if(regex.test(input)){

				return true;

		} else {


		return false;

}
}
	
		

});



