
       $(document).ready(function(){
          if($("#search_city").val()!="undefined")
          {
          var city=$("#search_city").val();
          var location=$("#search_location").val();
          
            $("#"+city).attr("selected","selected");  
            getLocationSelectedSearch(city,location);
            
            
            
          }                               
            $('#searchopt').hide();
              $('.modalloginerr').hide();  
              setTimeout("askForLocation();",2000);    
                if($("#searchopt").val()=="")
                 {
                      $("#searchopt").val(1);
                      
                 }
                 if($("#searchopt").val()=='1')
                 {
                 $("#tab2").removeClass("selected"); 
                  $("#tab3").removeClass("selected");      
                  $("#tab1").addClass("selected");  
                  settext1();
                 }
                 else if($("#searchopt").val()=='2')
                 {
                 
                 $("#tab1").removeClass("selected"); 
                  $("#tab3").removeClass("selected");      
                  $("#tab2").addClass("selected");    
                  settext2(); 
                 }
                  else if($("#searchopt").val()=='3')
                 {
                  $("#tab1").removeClass("selected"); 
                  $("#tab2").removeClass("selected");      
                  $("#tab3").addClass("selected");  
                   settext3();   
                 } 
                 
                                   
         $("#login-image").click(function()
     {
        
                $.post(sitePath+"login.php",
                {username:$("#user").val(),password:$("#password").val()},
                function(data){
                    
                     var data= data.split(",");
                       
                    if(data[0] == "ok")
                    {
               
                         window.location.reload();   
                     }
                     
                    else if(data=='false')
                    {
                    
                     
                 $("#backgroundPopup").css({
                        "opacity": "0.7"
                    });
                    $("#backgroundPopup").fadeIn("slow");
               $('.modalloginerr').fadeIn("slow");
               $(".modalheader").html('Login unsuccessful');
               $('#myspan').html('Probably the username or password wasnt right.Please try again.');
               var windowWidth = document.documentElement.clientWidth;
                var windowHeight = document.documentElement.clientHeight;
                var popupHeight = $(".modalloginerr").height();
                var popupWidth = $(".modalloginerr").width();
                //centering
                $(".modalloginerr").css({
                    "position": "absolute",
                    "top": windowHeight/3-popupHeight/3,
                    "left": windowWidth/2-popupWidth/2
                });
 
                    }
                   
                },
                "text");
        return false;
     });                  
       
    $("#place").unbind().autocomplete(
             
                sitePath+"autocomplete.php",
                {
                minChars: 1,
                delay: 400,
                matchCase: 0,
                matchSubset: 1,
                matchContains: 0,
                cacheLength: 1,
                mustMatch: 0,
                selectFirst: true,
                selectOnly: true,
                maxItemsToShow: 11,
                autoFill: true       
        
                    
                     
                }
            );
                
           
        });
           function closefunc()
           {
           $("#backgroundPopup").fadeOut("slow");
           $('.modalloginerr').fadeOut("slow");
           }
       
        function setSearchOptions(idElement){
    /* Total Tabs above the input field (in this case there are 3 tabs: web, images, videos) */
    tot_tab = 3;
    tab = document.getElementById('tab'+idElement);
    search_option = document.getElementById('searchopt');
    for(var i=1; i<=3; i++){
        if(i==idElement){
           // tab.setAttribute("class","selected");
           tab.className = "selected";
            search_option.value=idElement;
        } else {
            document.getElementById('tab'+i).className = "";
        }
    }
}
function askForLocation()
{
   var emptylocation=$("#emptylocation").val();
   if(emptylocation=='yes')
   {
              $("#backgroundPopup").css({
                 "opacity": "0.7"
            });
        $("#backgroundPopup").fadeIn("slow");
               $('.modallocationform').fadeIn("slow");
               
             
               var windowWidth = document.documentElement.clientWidth;
                var windowHeight = document.documentElement.clientHeight;
                var popupHeight = $(".modallocationform").height();
                var popupWidth = $(".modallocationform").width();
                //centering
                $(".modallocationform").css({
                    "position": "absolute",
                    "top": windowHeight/3-popupHeight/3,
                    "left": windowWidth/2-popupWidth/2
                });
             
   }
}

function forgotpassword()
{

  $('#login-replace').hide();
  $('#fgtpass').show(); 
}
function validateEmail(emailStr){
    var emailRegExp = /^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/ ;
    return emailRegExp.test(emailStr);
}
function sendmailtofgtpss(frm)
{
    if(!validateEmail($("#email").val()))
    {
            
                 $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
               $('.modalloginerr').fadeIn("slow");
               $(".modalheader").html('Invalid Email');  
                 $('#myspan').html('Please enter a valid email');   
             
               var windowWidth = document.documentElement.clientWidth;
                var windowHeight = document.documentElement.clientHeight;
                var popupHeight = $(".modalloginerr").height();
                var popupWidth = $(".modalloginerr").width();
                //centering
                $(".modalloginerr").css({
                    "position": "absolute",
                    "top": windowHeight/3-popupHeight/3,
                    "left": windowWidth/2-popupWidth/2
                });
             
    }
    else
    {
       
       $.post(sitePath+"passwords.php",
                {
                    email:$("#email").val()
                },
                function(data){
                  
                 $('#fgtpass').hide();    
               $('#login-replace').show();  
                 $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
               $('.modalloginerr').fadeIn("slow");
                $(".modalheader").html('Forgot password'); 
               if(data=='success')
               {
                    
                     $('#myspan').html('Link has been sent to your mail');   
               }
               else
               {
                   
                    $('#myspan').html('Email does not exist in database');    
               }
            
               var windowWidth = document.documentElement.clientWidth;
                var windowHeight = document.documentElement.clientHeight;
                var popupHeight = $(".modalloginerr").height();
                var popupWidth = $(".modalloginerr").width();
                //centering
                $(".modalloginerr").css({
                    "position": "absolute",
                    "top": windowHeight/3-popupHeight/3,
                    "left": windowWidth/2-popupWidth/2
                });
             
                  
                    
                },
                "text");
        return false;
    }
        
}


function cancelfgtpss()
{
     $('#fgtpass').hide();
  $('#login-replace').show();
  
}

function settext1()
{

 $("#product").val('Eg : Mobile'); 
 
  $("#product").focus(function () {
  
        if ($(this).val() == 'Eg : Mobile') {$(this).val("");}
    });
  
 
}

function settext2()
{
  $("#product").val('Eg : Rahul');  
  
  $("#product").focus(function () {
        if ($(this).val() == 'Eg : Rahul') {$(this).val('');}
    });
  
  

        
}

function settext3()
{
   $("#product").val('Eg : Startups'); 
   
    $("#product").focus(function () {
        if ($(this).val() == 'Eg : Startups') { $(this).val('') ;}
    });
 
          
}

function limitText(limitField,limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}

function getXMLHTTP() { //fuction to return the xml http object
        var xmlhttp=false;    
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)    {        
            try{            
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }
             
        return xmlhttp;
    }
   function getLocationSearch(val) 
   { 

  /* if(val=='allcities')
   {
    
     $("#select-loc").attr("disabled","disabled");
     document.getElementById('searchlocation').innerHTML='<select name="location" disabled="disabled" id="select-loc"><option value="Entire City" selected="selected">Entire City</option></select>';
   }   
   else
   {    */
      // $("#select-loc").removeAttr("disabled");        
        var strURL=sitePath+"getlocation.php?city="+val+"&type=search";
        var req = getXMLHTTP();
             
        if (req) {
                            
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                   
                    if (req.status == 200) {                        
                        document.getElementById('searchlocation').innerHTML=req.responseText;                        
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }                
            }            
            req.open("GET", strURL, true);
            req.send(null);
        } 
   }       
    //}   
    
    
     function getLocationSelectedSearch(val,loc) 
   { 

     
        var strURL=sitePath+"getlocation.php?city="+val+"&type=search&loc="+loc;
        var req = getXMLHTTP();
             
        if (req) {
                            
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                   
                    if (req.status == 200) {                        
                        document.getElementById('searchlocation').innerHTML=req.responseText;                        
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }                
            }            
            req.open("GET", strURL, true);
            req.send(null);
        } 
   }       
     function closefunction()
     {
       $("#backgroundPopup").fadeOut("slow");
           $('.modalwindow').fadeOut("slow");
     }
     
     function getLocationModal(val) {        
            
        var strURL=sitePath+"getlocation.php?city="+val+"&type=Modal";
        var req = getXMLHTTP();
             
        if (req) {
                            
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                   
                    if (req.status == 200) {                        
                        document.getElementById('modallocation').innerHTML=req.responseText;                        
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }                
            }            
            req.open("GET", strURL, true);
            req.send(null);
        }        
    }   
    
    function saveLocation()
   {
          if($("#user-locationModal").val()=="Select Your Area")
          {
             $("#modallocationerror").html("Please select a location");
          }
          else
          {
           $.post(sitePath+"check.php", {
            loc:$("#user-locationModal").val(),
            city:$("#modalcity").val(),
            type:"addloc"
        }, function(data){
            if(data=="done")
            {
               
               $(".city-loc-form").html("Thanks.Happy ollaing.");
               setTimeout("$(\"#backgroundPopup\").fadeOut(\"slow\");$('.modalwindow').fadeOut(\"slow\");",2000);
            }
            
        }, "text");
        return false;
          }   
       
   }
   function showcity()
   {
   //alert($("#search_city").val());
   }
