(function (){
    uri=Drupal.settings.basePath+"ws/pureviewsws.php";
    uri1=Drupal.settings.basePath+"node/732";
	uri2=Drupal.settings.basePath+"node/755";
    _done=0;
     b_arr= new Array();
     var uniqueId='';
     var emailId='';
}());

$(document).ready(function() {
   $('#edit-submit').click(function() {
  
     var companyName = $("input#edit-submitted-company-name").val();
		//alert (companyName);
        var city = $("input#edit-submitted-city").val();
        var state = $("input#edit-submitted-state").val();
     
          $("#city_state_name").html(city+","+state);
        
        if (companyName == "") {
            $("#edit-submitted-company-name").addClass('requiredFieldName');
            $("input#edit-submitted-company-name").focus();
            return false;
        }
        else {
            $("#edit-submitted-company-name").removeClass('requiredFieldName');
        }

        if (city == "") {
            $("#edit-submitted-city").addClass('requiredFieldCity');
            $("input#edit-submitted-city").focus();
            return false;
        }
        else {
            $("#edit-submitted-city").removeClass('requiredFieldCity');
        }


        if (state == "") {
            $("#edit-submitted-state").addClass('requiredFieldState');
            $("input#edit-submitted-state").focus();
            return false;
        }
        else {
            $("#edit-submitted-state").removeClass('requiredFieldState');
        }

        emailId = $("input#edit-submitted-email").val();
        var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        var emaiCheck = true;

        if (emailId == "") {
            $("#edit-submitted-email").addClass('requiredFieldName');
            $("input#edit-submitted-email").focus();
            emaiCheck = false;
            return false;
        }else if( !emailReg.test( emailId ) ){
            $("#edit-submitted-email").addClass('requiredFieldName');
            $("input#edit-submitted-email").focus();
            emaiCheck = false;
            return false;
        }
        else{
            //Google API , have origin-access restrictions and don't support localhost requests'
            /*
       *Be specific, Here We need space after comma for each address element i.e. street_adress, City, State
       *street_adress will be separated by space
      */
	 
            uniqueId=uniqueIdGenerator(emailId);
            saveUserDataFunctions(uniqueId,'save',emailId);  

            var _businessAddress=companyName +", "+ city + ", " + state;
			
            var _businessLocationWithZip =  geoCodeLocation(_businessAddress ,"xml" );         //geoCodeLocation returns "lattitude,longitude | zip"

			
            var _businessLocation=_businessLocationWithZip.split(',')            
            var _businessLocationGoogle= _businessLocation[0]+","+_businessLocation[1];       
     

            var lat_long = _businessLocationWithZip.split(',');
            var _latitude=lat_long[0];
			
            var _longitude = lat_long[1];
			var location = geoCodeLocation(state,"xml" );
                        var loc_arr =  location.split(',');        
                        var country_name=loc_arr[2];
                        var country_code= getCountryCode(country_name);     

            $('.new-inner').css("display","none");
            $('.text-inner').css("display","none");
            $('#banner').css("display","none");
			 $('#searchdata').css("display","block");
            $('#progress_container').css("display","block");
			//$('#selected_progress_container').css("display","block");
            $('.botttom').css("display","none");
            $('.join-us').css("display","none");

            
            // http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=3N0Bh8bV34Gr9ThQgeCwICBkaf9ly6iM.ZLKA9AXijbAw3UvHhKVKe3wcL7a2i9qTQpCpmLk&listing_id=32669999&query=* 
var set=0;			
         getYahooReviews(companyName,_latitude,_longitude,_businessAddress,set);   //Done 
         
               
           getYelpReviews(companyName,_latitude, _longitude, 10, 10);   //Done
		   
            var g= getGoogleReviews(_businessLocationGoogle,companyName); 

			//Done but "type=food" here is hardcode and it create problem when query is not related to thier type 
           getCityGridReviews(companyName,_latitude,_longitude,10,"food"," ");

           getBingReviews(companyName,country_code,_latitude, _longitude,10);
		   
		
          /*var vvv = $('#business-list-container').html();
			  alert("here>>>"+vvv);
			  if(vvv ==""){
			 $('#iop').html(' <a class="button4" href="#"> </a>');
			   $('.desc-test').css("display","none");
				} */
       /*      alert(companyName);
           
        */ //Done
		
		// var $vvv = $('#ffff').html();
			 // alert($vvv);
// if($vvv == "No Results Found"){
	 // alert("123");	
		// $("#iop").hide();						
	// }
		
		
          
        }
		

  });

   });

function getCountryCode(countryname)
{
var countryCode='';
$.ajax({ 
         cache: false,
         type:'POST',
         async:false,
         url: uri,
         data:{
               method:"getCountryCode",
               countryname:countryname
              },
         success: function(msg)
              {
                $(msg).find("Response").each(function()
                                            {
                                             countryCode=$(this).find("CountryCode").text();
 					     //alert(countryCode);	       
                                            });
              }
});
return countryCode;
}



function uniqueIdGenerator(email)
{
var uniqueId='';
$.ajax({ 
         cache: false,
         type:'POST',
         async:false,
         url: uri,
         data:{
               method:"uniqueIdGenerator",
               emailId:email
              },
         success: function(msg)
              {
                $(msg).find("Response").each(function()
                                            {
                                             uniqueId=$(this).find("UniqueId").text();
 					     //alert(uniqueId);	       
                                            });
              }
});
return uniqueId;
}

function saveUserDataFunctions(userId,mode,emailId)
{   
     $.ajax ({
        cache: false,
        type:'POST',
        async:false, 
        url:uri,
        data:{
            method:"UserDataFunctions",
            user_id:userId,
            mode:mode,
            email_id:emailId
             },
        beforeSend:function(){  },
        success: function(msg)
             {
                $(msg).find("Response").each(function()
	              {
			$(this).find("Status").each(function()
		           {
                              if($(this).find("Code").text() === '1')
                                 {
                                     //alert($(this).find("Message").text());
                                 }
                           });
                      });
              },              
         complete:function() {   }
              });
}

function updateUserDataFunctions(userId,mode,selected_b_name,selected_b_address,yahoo_rating,yahoo_review_count,yahoo_review_url,
                                   google_rating,google_review_count,google_review_url,
                                   citygrid_rating,citygrid_review_count,citygrid_review_url,
 				   yelp_rating,yelp_review_count,yelp_review_url,
				   bing_rating,bing_review_count,bing_review_url,yahoo_map,yahoo_address,yahoo_city,yahoo_state,yahoo_phone,
				   city_address,city_city,city_state,city_phone,yelp_address,yelp_city,yelp_state,yelp_phone)
{   
     $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        async:false, 
        data:{
            method:"UserDataFunctions",
            user_id:userId,
            mode:mode,
            business_name:selected_b_name,
            business_address:selected_b_address,
            yahoo_rating:yahoo_rating,
            yahoo_review_count:yahoo_review_count,
            yahoo_review_url:yahoo_review_url,
            google_rating:google_rating,
            google_review_count:google_review_count,
            google_review_url:google_review_url,
            citygrid_rating:citygrid_rating,
            citygrid_review_count:citygrid_review_count,
            citygrid_review_url:citygrid_review_url,
            yelp_rating:yelp_rating,
            yelp_review_count:yelp_review_count,
            yelp_review_url:yelp_review_url,
            bing_rating:bing_rating,
            bing_review_count:bing_review_count,
            bing_review_url:bing_review_url,
			yahoo_map:yahoo_map,	
			yahoo_address:yahoo_address	,
			yahoo_city:yahoo_city,	
			yahoo_state:yahoo_state	,
			yahoo_phone:yahoo_phone	,
			city_address:city_address,	
			city_city:city_city	,
			city_state:city_state	,
			city_phone:city_phone,	
			yelp_address:yelp_address,
			yelp_city:yelp_city,
			yelp_state:yelp_state,
			yelp_phone:yelp_phone			
             },
        beforeSend:function(){  },
        success: function(msg)
             {
                $(msg).find("Response").each(function()
	              {
			$(this).find("Status").each(function()
		           {
                              if($(this).find("Code").text() === '1')
                                 {
                                    // alert($(this).find("Message").text());
                                 }
                           });
                      });
              },              
         complete:function() {   }
              });
}


var complete_addressyahoo =new Array();
var complete_addresstitle =new Array();
var list=1;
// For Yahoo
//function getYahooReviews(query,zip)
function getYahooReviews(companyName,_latitude,_longitude,_businessAddress,set)
{  
//alert (companyName+_latitude+_longitude+_businessAddress+set);
    var yahoo_response = '';
	var yahoo_response2 = '';
    var percentage=0;
    var count=1;
	var i=0;
	var total=0;
	var titl=0;
	var check=0;
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method:"getYahooReviews",
            query:companyName,
            latitude:_latitude,
            longitude:_longitude,
            results:'3' 
             },

        beforeSend:function(){
            
          $("#yahoo-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            });
        },
        success: function(msg){
		//alert("============> success");
		check=90;

            setInterval(function() {
               
                if(percentage<95){
                    percentage +=10;
                    $("#yahoo-progress").progressBar(percentage);
                }

            }, 100);
           $(msg).find("reviewsResponse").each(function(){
             
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
				check=78;
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {
                        $(this).parent().find("yahooreviews").each(function()
                        {
						total=list;
						i =complete_addressyahoo.length;
						titl=complete_addresstitle.length;
                            $(this).find("ResultSet").each(function()
                            {
							if(set==8)
					{
					 

  yahoo_response2 +='<div class="tleft">';
					}
                                 yahoo_response +='<div class=yahoo-results>';
                                if($(this).attr('totalResultsReturned')>0){
								
                                   
                   
                 $(this).find("Result").each(function(){
			                  
                  
				//var obj_y= new Object();            //Code for uniqueness logic
 
				           var listing_id=$(this).attr("id");  

                                	   var bus_name = $(this).find("Title").text();
                                           var address = $(this).find("Address").text();
                                           var city = $(this).find("City").text();
                                           var state = $(this).find("State").text();
                                           var complete_address=address+", "+city+", "+state;
										    //complete_addressyahoo[i]=complete_address;
											//alert(complete_addressyahoo[i]);
				           var lat = $(this).find("Latitude").text();
                                           var lng = $(this).find("Longitude").text(); 

										   var dd=complete_address;
				   var j=0;
				   var k=0;
				  // alert(dd);
				  
                   for (j=0;j<complete_addressyahoo.length;j++)
                     {
					 //alert(complete_addressyahoo[j]);
					 //if(complete_addressyahoo[j] == dd){k=dd; alert(k);}
					 }
                                           
                                   $(this).find("Rating").each(function(){
                                            
                                            var rating = $(this).find("TotalRatings").text();
                                          	//alert("Yahooo Rating is "+rating);				
                                            
                                        var _class = 'left';
                                        if(count%2==0){
                                            _class = 'right';
                                        }
		
				 /*      obj_y.bus_name=bus_name;                                //Code for uniqueness logic
                                       obj_y.complete_address=complete_address;
                                       obj_y.lat= lat;
                                       obj_y.lng= lng;
                                       obj_y.rating= rating;
				       
					b_arr.push(obj_y);*/
					if(k == 0)
			{
			complete_addressyahoo[i]=complete_address;
			complete_addresstitle[i]=bus_name;
			
                                           
                                           yahoo_response +='<div class = "result-business result-business-'+count+' local_'+_class+'">';

                                           yahoo_response += "<div class = 'radio-container'>";
                                           yahoo_response += "<input type ='radio' name = 'yahoo-result-cb-' value="+count+">";   //'yahoo-result-cb-"+count+"'
                                           yahoo_response +="</input>";
                                           yahoo_response +="</div>";

                                           yahoo_response += '<div id="yahoo-result-cb-bname-'+count+'" class = "name name-'+count+'">';
                                           yahoo_response +=bus_name;
                                           yahoo_response +="</div>";

                                           yahoo_response +='<div id="yahoo-result-cb-cadd-'+count+'"  class = "address address-'+count+'">';
                                           yahoo_response +=complete_address;
                                           yahoo_response +="</div>";

                                           yahoo_response += '<input  id="yahoo-result-cb-rating-'+count+'" type=hidden class = "rating rating-'+count+' " value="'+rating+'">';
                                           yahoo_response +="</input>";

                                           yahoo_response += '<input  id="yahoo-result-cb-lati-'+count+'" type=hidden class = "lat  lat-'+count+' " value="'+lat+'">';
                                           yahoo_response +="</input>";

                                           yahoo_response += '<input  id="yahoo-result-cb-lng-'+count+'" type=hidden class = "lng  lng-'+count+' " value="'+lng+'">';
                                           yahoo_response +="</input>";

     					   yahoo_response += '<input id="yahoo-result-cb-listing-'+count+'" type=hidden class = "listing listing-'+count+'" value="'+listing_id+'">';
                                           yahoo_response +="</input>";	




			                   yahoo_response +="</div>";
							   
							   if(set==8)
			                     {
								yahoo_response2 +=' <div class="box"><img src="/sites/all/themes/leadform/images/'+(total)+'.gif" align="middle" class="area_num" />';
					//alert(complete_addresstitle[j]);
					// alert(complete_addressyahoo[j]);
					 var _class = 'left';
                                        if((j+1)%2==0){
                                            _class = 'right';
                                        }
										
					 yahoo_response2 +='<p class = "pad_left">';
					//yelp_response1 +='<input type="hidden" id="idd" value="id'+j+'">';
					yahoo_response2 +='<div id="selectedbusiness'+total+'"><a class="linka" href="#" onclick ="cal_next('+total+');">';
					yahoo_response2 += '<div id="yahoo-result-cb-bn-'+total+'" >';
                                           yahoo_response2 +=bus_name;
                                           yahoo_response2 +="</div>";
										   yahoo_response2 +='</a></div>';
					 yahoo_response2 +='<div id="yahoo-result-cb-cadds-'+total+'" style="margin-left:23px;" class = "address address-'+total+'">';
                                           yahoo_response2 +=complete_address;
                                           yahoo_response2 +="</div>";
					 yahoo_response2 +="</p>";
					 yahoo_response2 +="</div>";
			
                                total++;
								 list++;
								 
								 }
								 
                                         
                                           count ++;i++;
										   }

                                            
                                                                        });
                                     
                                    });
									 $('.desc-test1').empty();
									
                                }else {
                                    $('.desc-test').empty();
									 $('.next-button').empty();
									 $('#iop').html(' <a class="button4" href="#"> </a>');
									
                                   // yahoo_response += "No results are found, please refine your search.</br>";    //if Results not found 
                                    
                                }
                                
                                $("#banner").css("display","none");
                                $("#blue_outer").css("display","none");
                                $("#ser-business-box").css("display","none");
                                $("#progress_container").css("display","none");
                                  $("#selected_progress_container").css("display","none");
                                yahoo_response +="</div>";
                                
								if(set==8)
			                     {
								 yahoo_response2 +="</div>";
					//yahoo_response2 +='<div class="tright"><img height="283" width="303" alt="map" src="/sites/all/themes/leadform/images/map.jpg"></div>';
					
			                          $("#business-iop").append(yahoo_response2);
			                    }
			                  else
			                    {
								
			                    $("#business-list-container").append(yahoo_response);
			                    }

                            });
                        });

                    }
				  
                });
				
            });
			 
			 
			
			  
	

        },
		
        error:function() {
      //  alert("UNABLE_TO_LOCATE_ADDRESS");
		
			
								
		
        },
        complete:function() {
            // _done = _done +_1;
            $("#yahoo-progress").progressBar(100);
            $('#yahoo-right-arraw').css("display","block");
            $("#progress_container").css("display","none");
			$("#selected_progress_container").css("display","none");
           
			if(set==8)
			{
			$("#business-iop").css("display","block");
			}
			else
			{
			$("#business-list-page").css("display","block");
			}
            //alert("I m in yahoo");
	    //alert(b_arr.length); 


        }
		
    });
	 
	//alert(complete_addressyahoo.length);
	return check;
}

function geoCodeLocation(address,format){
    
	address=address.replace(" ","+");
  
  
   
    var _location = ""; //_location will be "lat,long | zip"
    var latitude = "";
    var longitude = "";
    var country = "";
    $.ajax ({
        cache: false,
        async:false,
        type:'POST',
        url:uri,
        data:{
            method:"getlatlong",
            address:address
        },

        beforeSend:function(){
          
        },
        success: function(msg){

		
            $(msg).find("locationResponse").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {
                        latitude = $(this).parent().find("latitude").text();
						
                        longitude = $(this).parent().find("longitude").text();
                        country = $(this).parent().find("country").text(); 
						
						
						
                    }
                });
            });

        },
        error:function() {
        //alert("UNABLE_TO_LOCATE_ADDRESS");
        },
        complete:function() {
		
			


        }

    });
    _location = latitude+','+longitude+','+country;
	
    return _location;
}


// For Google
function getGoogleReviews(address,query,set)   //type
{
//alert(address+query+type);
    var percentage=0;
    var count = 1;
    var i=0;
	var total=0;
	var google_response1='';
	
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
      //  async:true, 
        data:{
            method: "getGoogleReviews",
            query:query,
            loc:address,
            //type:type,
            radius:'7500'
            //format:"xml" //google API return XML/JSON both, Let it be XML format.

        },
        beforeSend:function(){
             
            $("#google-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
        success: function(msg){
              setInterval(function() {

                if(percentage<95){
                    percentage +=10;
                    $("#google-progress").progressBar(percentage);
                }

            }, 100);
            $(msg).find("reviewsResponse").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {

                        var google_response = "";
                        $(this).parent().find("googlereviews").each(function()
                        {
						i =complete_addressyahoo.length;
						total=list;
                            $(this).find("PlaceSearchResponse").each(function()
                            {
                                if($(this).find("status").text() =='OK'){
								if(set==8)
					{
					 

  google_response1 +='<div class="tleft">';
					}
                                    google_response +='<div class=google-results>';
 					
                                    $(this).find("result").each(function(){
				
			             //   var obj_g= new Object();

                                        var bus_name = $(this).find("name").text();
                                        var rating = $(this).find("rating").text();
                                        var vicinity = $(this).find("vicinity").text();
										  var refrences = $(this).find("reference").text();
                                        var lat;var lng;
                                        $(this).find("geometry").each(function(){
                                              $(this).find("location").each(function(){
           				          lat = $(this).find("lat").text();
                                                  lng = $(this).find("lng").text();   
                                            					      });
                                        					});

                                     
									 var dd=vicinity;
				   var j=0;
				   var k=0;
				  // alert(dd);
				  
                   for (j=0;j<complete_addressyahoo.length;j++)
                     {
					 //alert(complete_addressyahoo[j]);
					// if(complete_addressyahoo[j] == dd){k=dd; alert(k);}
					 }
                                      
                                        var _class = 'left';
                                        if(count%2==0){
                                            _class = 'right';
                                        }

				    /*   obj_g.bus_name=bus_name;
                                       obj_g.complete_address=vicinity;
                                       obj_g.lat= lat;
                                       obj_g.lng= lng;
                                       obj_g.rating= rating;
				       
					b_arr.push(obj_g); */
			if(k == 0)
			{
			complete_addressyahoo[i]=vicinity;
			complete_addresstitle[i]=bus_name;
			
                                            
                                        google_response +='<div class = "result-business result-business-'+count+' local_'+_class+'">';

                                        google_response += "<div class = 'radio-container'>";
                                        google_response += "<input type ='radio' name = 'google-result-cb-' value="+count+">";
                                        google_response +="</input>";
                                        google_response +="</div>";

                                        google_response += '<div id="google-result-cb-bname-'+count+'" class = "name name-'+count+'">';
                                        google_response +=bus_name;
                                        google_response +="</div>";

                                        google_response += '<div id="google-result-cb-cadd-'+count+'" class = "address address-'+count+'">';
                                        google_response +=vicinity;
                                        google_response +="</div>";

                                        google_response += '<input id="google-result-cb-rating-'+count+'" type=hidden class = "rating rating-'+count+' " value="'+rating+'">';
                                        google_response +="</input>";

                                        google_response += '<input id="google-result-cb-lati-'+count+'" type=hidden class = "lat  lat-'+count+' " value="'+lat+'">';
                                        google_response +="</input>";

                                        google_response += '<input id="google-result-cb-lng-'+count+'" type=hidden class = "lng  lng-'+count+' " value="'+lng+'">';
                                        google_response +="</input>";
										    google_response += '<input id="google-result-cb-listing-'+count+'" type=hidden class = "listing  listing-'+count+' " value="'+refrences+'">';
                                        google_response +="</input>";

                                        google_response +="</div>";
										 if(set==8)
			                     {
								google_response1 +=' <div class="box"><img src="/sites/all/themes/leadform/images/'+(total)+'.gif" align="middle" class="area_num" />';
					//alert(complete_addresstitle[j]);
					// alert(complete_addressyahoo[j]);
					 var _class = 'left';
                                        if((j+1)%2==0){
                                            _class = 'right';
                                        }
										
					 google_response1 +='<p class = "pad_left">';
					//yelp_response1 +='<input type="hidden" id="idd" value="id'+j+'">';
					google_response1 +='<div id="selectedbusiness'+total+'"><a class="linka" href="#" onclick ="cal_next('+total+');">';
					google_response1 += '<div id="yahoo-result-cb-bn-'+total+'" >';
                                           google_response1 +=bus_name;
                                           google_response1 +="</div>";
										   google_response1 +='</a></div>';
					 google_response1 +='<div id="yahoo-result-cb-cadds-'+total+'" style="margin-left:23px;" class = "address address-'+total+'">';
                                           google_response1 +=vicinity;
                                           google_response1 +="</div>";
					 google_response1 +="</p>";
					 google_response1 +="</div>";
			
                                total++;
								 list++;
								 
								 }
                                           
                                        count ++;
										i++;
										}
                                    });
                                    google_response +="</div>";
									$('.desc-test1').empty();
                                }
                                else {
                                   $('.desc-test').empty();
								    //$('.next-button').empty();
                                    //go= "No results are found, please refine your search.</br>";
                                    
                                }
                                
                                $("#banner").css("display","none");
                                $("#blue_outer").css("display","none");
                                $("#ser-business-box").css("display","none");
                                $("#progress_container").css("display","none");
								 $("#selected_progress_container").css("display","none");

                                // var t='<p style="font-size:27px;" id="pp">Local Businesses Found('+list+')</p>';
		   // var t1='<p style="font-size:27px;" id="pp">Local Businesses Found('+list+')</p>';
		   //$("#business-iop").html(t);   
                                //$("#business-list-container").append(google_response);
								
								
								if(set==8)
			                     {
			                         google_response1 +="</div>";
					//google_response1 +='<div class="tright"><img height="283" width="303" alt="map" src="/sites/all/themes/leadform/images/map.jpg"></div>';
					
			                          $("#business-iop").append(google_response1);
			                    }
			                  else
			                    {
			                    $("#business-list-container").append(google_response);
			                    }
								
								
								
								
                            });
                        });

                        
                    }
                });
            });
			
			
			
		

        },
        complete:function() {
            //_done = _done +_1;
            $("#google-progress").progressBar(100);
            $('#google-right-arraw').css("display","block");
            $("#progress_container").css("display","none");
			 $("#selected_progress_container").css("display","none");
            if(set==8)
			{
			$("#business-iop").css("display","block");
			}
			else
			{
			$("#business-list-page").css("display","block");
			}
                     



					 }
    });
	
	
	
	
								
	
	
	return i;
	
	
	
}


//for bing
function getBingReviews(query,loc,lat,lng,results,set)
{


 var percentage=0;
 var biz;
 var bing_response='';
 var bing_response1='';
 var count = 1;
 var i=0;
 var total=0;
   
 var htmlString="";
  $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
	//async:true,	
        data:{
            method: "getBingReviews",
            query:query,
            loc:loc,
            latitude:lat,
	    longitude:lng,
            count:results	
        },
        beforeSend:function(){
             
            $("#bing-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },


    success: function(msg){

                 /////////////////////////////////////////////////
	                     setInterval(function() {

                if(percentage<95){
                    percentage +=10;
                    $("#bing-progress").progressBar(percentage);
                }

            }, 100);
   
                         $(msg).find("Bingreviews").each(function()
                        {
						i =complete_addressyahoo.length;
						total=list;
                            $(this).find("SearchResponse").each(function()
                            {
							if(set==8)
					{
					 

  bing_response1 +='<div class="tleft">';
					}
				  bing_response +='<div class=bing-results>';  
                               $(this).find("Phonebook").each(function()
                                  {            
                                                                
                                           $(this).find("Results").each(function()
                                              {
                                                   
                                                $(this).find("PhonebookResult").each(function()
                                                  {
						 // var obj_b= new Object();
                                                  var bus_name=$(this).find("Business").text();
                                                  var B_Address=$(this).find("Address").text();
                                                  var B_City=$(this).find("City").text();
                                                  var B_State=$(this).find("StateOrProvince").text();
                                                  var complete_address=B_Address+','+B_City+','+B_State;
                                                  var B_Country=$(this).find("CountryOrRegion").text();
                                                  var rating=$(this).find("UserRating").text();
                                       		  var lat = $(this).find("Latitude").text();
                                                  var lng = $(this).find("Longitude").text();   		
                                                  var B_Review_Count=$(this).find("ReviewCount").text();
					 
                                                var dd=complete_address;
												
				   var j=0;
				   var k=0;
				  // alert(dd);
				  
                   for (j=0;j<complete_addressyahoo.length;j++)
                     {
					 //alert(complete_addressyahoo[j]);
					// if(complete_addressyahoo[j] == dd){k=dd; alert(k);}
					 }

											   var _class = 'left';
                                                if(count%2==0){
                                                    _class = 'right';
                                                }

				    /*   obj_b.bus_name=bus_name;
                                       obj_b.complete_address=complete_address;
                                       obj_b.lat= lat;
                                       obj_b.lng= lng;
                                       obj_b.rating= rating;
				       
					b_arr.push(obj_b);*/
					
					
					if(k == 0)
			            {
			complete_addressyahoo[i]=complete_address;
			complete_addresstitle[i]=bus_name;
			

                                                bing_response +='<div class = "result-business result-business-'+count+' local_'+_class+'">';

                                                bing_response += "<div class = 'radio-container'>";
                                                bing_response += "<input type ='radio' name = 'bing-result-cb-' value="+count+">";
                                                bing_response +="</input>";
                                                bing_response +="</div>";

                                                bing_response += '<div id="bing-result-cb-bname-'+count+'" class = "name name-'+count+'">';
                                                bing_response +=bus_name;
                                                bing_response +="</div>";

                                                bing_response += '<div id="bing-result-cb-cadd-'+count+'" class = "address address-'+count+'">';
                                                bing_response +=complete_address;
                                                bing_response +="</div>";

                                            					
                                                bing_response  += '<input id="bing-result-cb-rating-'+count+'" type=hidden class = "rating rating-'+count+' " value="'+rating+'">';
                                                bing_response  +="</input>";

                                                bing_response  += '<input id="bing-result-cb-lati-'+count+'" type=hidden class = "lat  lat-'+count+' " value="'+lat+'">';
                                                bing_response  +="</input>";

                                                bing_response  += '<input id="bing-result-cb-lng-'+count+'" type=hidden class = "lng  lng-'+count+' " value="'+lng+'">';
                                                bing_response  +="</input>";
								


                                               bing_response +="</div>";
											   
											    if(set==8)
			                     {
								bing_response1 +=' <div class="box"><img src="/sites/all/themes/leadform/images/'+(total)+'.gif" align="middle" class="area_num" />';
					//alert(complete_addresstitle[j]);
					// alert(complete_addressyahoo[j]);
					 var _class = 'left';
                                        if((j+1)%2==0){
                                            _class = 'right';
                                        }
										
					 bing_response1 +='<p class = "pad_left">';
					//yelp_response1 +='<input type="hidden" id="idd" value="id'+j+'">';
					bing_response1 +='<div id="selectedbusiness'+total+'"><a class="linka" href="#" onclick ="cal_next('+total+');">';
					bing_response1 += '<div id="yahoo-result-cb-bn-'+total+'" >';
                                           bing_response1 +=bus_name;
                                           bing_response1 +="</div>";
										   bing_response1 +='</a></div>';
					 google_response1 +='<div id="yahoo-result-cb-cadds-'+total+'" style="margin-left:23px;" class = "address address-'+total+'">';
                                           bing_response1 +=complete_address;
                                           bing_response1 +="</div>";
					 bing_response1 +="</p>";
					 bing_response1 +="</div>";
			
                              total++;
							   list++;
								 
								 }
											   

                                                count ++;
												i++;
												}

                                                                    

                                                   });
 bing_response +="</div>";

                                $("#banner").css("display","none");
                               $("#blue_outer").css("display","none");
                                $("#ser-business-box").css("display","none");
                                $("#progress_container").css("display","none");
								 $("#selected_progress_container").css("display","none");

                               // $("#business-list-page").css("display","block");
                                
								if(set==8)
			                     {
			                         bing_response1 +="</div>";
					//bing_response1 +='<div class="tright"><img height="283" width="303" alt="map" src="/sites/all/themes/leadform/images/map.jpg"></div>';
					
			                          $("#business-iop").append(bing_response1);
			                    }
			                  else
			                    {
			                    $("#business-list-container").append(bing_response);
			                    }

                                                 
                                                });
                                            
                                  });
                            });
                        });

   },
complete:function() {
  $("#bing-progress").progressBar(100);
            $('#bing-right-arraw').css("display","block");
			if(set==8)
			{
			$("#business-iop").css("display","block");
			}
			else
			{
			$("#business-list-page").css("display","block");
			}
 // $("#bing-progress").progressBar(100); 
// $('#bing-right-arraw').css("display","block");
// $("#progress_container").css("display","none");
// $("#business-list-page").css("display","block");

           //$('#userresult_report_progress').hide();
            //$('#review_report').show();
}
});    return i;
     }

function getYelpReviews(term,latitude,longitude,radius,limit,set){
   
    var percentage=0;
    var biz;
    var yelp_response='';
	 var yelp_response1='';
    var count = 1;
	var total=0;
	var i=0;
	var l=0;
	//alert(i);
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method: "getYelpReviews",
            term:term,
            lat:latitude,
            longitude:longitude,
            radius:radius,
            limit:limit

        },
       beforeSend:function(){
            $("#yelp-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
        
        success: function(msg){
        
              setInterval(function() {

                if(percentage<95){
                    percentage +=10;
                    $("#yelp-progress").progressBar(percentage);
                }

                }, 100);
                
                $(msg).find("Reviews").each(function(){ 
				i =complete_addressyahoo.length;
				total=list;
 
                $(this).find("getYelpReviews").each(function(){
               
                     yelp_response +='<div class=yelp-results>';
					if(set==8)
					{
					 

  yelp_response1 +='<div class="tleft">';
					}

                  $(this).find("businesses").children().each(function(){
				  
				  
				   //alert(complete_addressyahoo[j]);
				  //if(complete_addressyahoo[j]== dd){}
				  //else{
            		// var obj_ye= new Object();
					
                         var address=$(this).children("address1").text();
                         var city= $(this).children("city").text();
			 var state=$(this).children("state").text();
                         var complete_address=address+" "+city+', '+state;
  			 var bus_name=$(this).children("name").text();
			 var rating=$(this).children("avg_rating").text();
         		 var lat = $(this).find("latitude").text();
                         var lng = $(this).find("longitude").text();	
						 
						  var dd=address+", "+city+', '+state;
				   var j=0;
				   var k=0;
				   //alert(dd);
				   
				   var ss=dd.replace("/\s/g","");
				  // alert(ss);
                   for (j=0;j<complete_addressyahoo.length;j++)
                     {
					 
					//if(complete_addressyahoo[j] == dd){k=dd; }
					 }
                     //  alert(address+","+city+","+state+","+bus_name+","+rating);
                      
                     
                                                var _class = 'left';
                                                if(count%2==0){
                                                    _class = 'right';
                                                }

			          /*     obj_ye.bus_name=bus_name;
                                       obj_ye.complete_address=complete_address;
                                       obj_ye.lat= lat;
                                       obj_ye.lng= lng;
                                       obj_ye.rating= rating;
				       
					b_arr.push(obj_ye);*/
					if(k==0)
					{
					
					
					//alert(i);
					complete_addressyahoo[i]=complete_address;
					complete_addresstitle[i]=bus_name;
					

                                                yelp_response +='<div class = "result-business result-business-'+count+' local_'+_class+'">';

                                                yelp_response += "<div class = 'radio-container'>";
                                                yelp_response += "<input type ='radio' name = 'yelp-result-cb-' value="+count+">";
                                                yelp_response +="</input>";
                                                yelp_response +="</div>";

                                                yelp_response += '<div id="yelp-result-cb-bname-'+count+'" class = "name name-'+count+'">';
                                                yelp_response +=bus_name;
                                                yelp_response +="</div>";

                                                yelp_response += '<div id="yelp-result-cb-cadd-'+count+'" class = "address address-'+count+'">';
                                                yelp_response +=complete_address;
                                                yelp_response +="</div>";

                                                yelp_response  += '<input id="yelp-result-cb-rating-'+count+'" type=hidden class = "rating rating-'+count+' " value="'+rating+'">';
                                                yelp_response  +="</input>";

                                                yelp_response  += '<input id="yelp-result-cb-lati-'+count+'" type=hidden class = "lat  lat-'+count+' " value="'+lat+'">';
                                                yelp_response  +="</input>";

                                                yelp_response  += '<input id="yelp-result-cb-lng-'+count+'" type=hidden class = "lng  lng-'+count+' " value="'+lng+'">';
                                                yelp_response  +="</input>";


                                               yelp_response +="</div>";
											   
											   //}
											   if(set==8)
											   {
											  

					 
					yelp_response1 +=' <div class="box"><img src="/sites/all/themes/leadform/images/'+(total)+'.gif" align="middle" class="area_num" />';
					//alert(complete_addresstitle[j]);
					// alert(complete_addressyahoo[j]);
					 var _class = 'left';
                                        if((j+1)%2==0){
                                            _class = 'right';
                                        }
										
					 yelp_response1 +='<p class = "pad_left">';
					//yelp_response1 +='<input type="hidden" id="idd" value="id'+j+'">';
					yelp_response1 +='<div id="selectedbusiness'+total+'"><a class="linka" href="#" onclick ="cal_next('+total+');">';
					yelp_response1 += '<div id="yahoo-result-cb-bn-'+total+'" >';
                                           yelp_response1 +=bus_name;
                                           yelp_response1 +="</div>";
										   yelp_response1 +='</a></div>';
					 yelp_response1 +='<div id="yahoo-result-cb-cadds-'+total+'" style="margin-left:23px;" class = "address address-'+total+'">';
                                           yelp_response1 +=complete_address;
                                           yelp_response1 +="</div>";
					 yelp_response1 +="</p>";
					 yelp_response1 +="</div>";
					 total++;
					  list++;
					 //if(complete_addressyahoo[j] == dd){k=dd; alert(k);}
					 }
					  
					  

											  
											  
											  // $("#business-compare-page").css("display","none");
											  
											   

                                                count ++; 
												i++; 
												}

                                                                 

					 });
					  yelp_response +="</div>";  
                                $("#banner").css("display","none");
                               $("#blue_outer").css("display","none");
                                $("#ser-business-box").css("display","none");
                                $("#progress_container").css("display","none");
								 $("#selected_progress_container").css("display","none");

                               // $("#business-list-page").css("display","block");
								
                                yelp_response1 +="</div>";
					//yelp_response1 +='<div class="tright"><img height="283" width="303" alt="map" src="/sites/all/themes/leadform/images/map.jpg"></div>';
								if(set==8)
			                     {
								 
			                          $("#business-iop").append(yelp_response1);
			                    }
			                  else
			                    {
								
								 
											   
			                    $("#business-list-container").append(yelp_response);
			                    }

     

               







               
                });
                 });
             
             },
        complete:function() {
            
            $("#yelp-progress").progressBar(100);
            $('#yelp-right-arraw').css("display","block");
            $("#progress_container").css("display","none");
			 $("#selected_progress_container").css("display","none");
           if(set==8)
			{
			$("#business-local-list-container").css("display","none");
			$("#business-iop").css("display","block");
			}
			else
			{
			$("#business-list-page").css("display","block");
			}
         
         }
    });return i;

}

// For CityGrid

function getCityGridReviews(query,latitude,longitude,radius,type,listing_id,set)
{
//alert(query+latitude+longitude+radius+type,listing_id);
    var citygrid_response = '';
	var citygrid_response1= '';
    var count = 1;
    var previous_name = '';
    var listing_id = '';
    var percentage=0;
	var total=0;
	var i=0;
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
	data:{
            method:"getCityGridReviews",
	    query:query,
            listing_id:listing_id,	
            latitude:latitude,
            longitude:longitude,
            radius:radius,
            type:type
        },

        beforeSend:function(){
            //alert("BEFIRE");
            $("#citygrid-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
        success: function(msg){
              setInterval(function() {

                if(percentage<95){
                    percentage +=10;
                    $("#citygrid-progress").progressBar(percentage);
                }

            }, 100);
         $(msg).find("reviewsResponse").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {

                     //   var google_response = "";
                        $(this).parent().find("citygridreviews").each(function()
                        {
						i =complete_addressyahoo.length;
						total=list;
                            $(this).find("results").each(function()
                            {
							if(set==8)
					        {
					 

  citygrid_response1 +='<div class="tleft">';
					         }
                                   citygrid_response +='<div class=citygrid-results>';
                                if($(this).attr("total_hits") >0){
                                    $(this).find("reviews").each(function()
                                    {
                                        
                                        $(this).find("review").each(function(){

					//	 var obj_c= new Object();
                                            if(listing_id!=$(this).find("listing_id").text()){
                                                listing_id = $(this).find("listing_id").text();
                                                var bus_name = $(this).find("business_name").text();
                                                var rating = $(this).find("review_rating").text();
                                                var vicinity = $(this).find("public_id").text();
                                              
                                               var dd =vicinity;
				   var j=0;
				   var k=0;
				   //alert(dd);
				   
				   var ss=dd.replace("/\s/g","");
				  // alert(ss);
                   for (j=0;j<complete_addressyahoo.length;j++)
                     {
					 
					// if(complete_addressyahoo[j] == dd){k=dd; }
					 }
											   
											   var _class = 'left';
                                                if(count%2==0){
                                                    _class = 'right';
                                               }
					
				      /* obj_c.bus_name=bus_name;
                                       obj_c.complete_address=vicinity;
                                       obj_c.lat= '0';
                                       obj_c.lng= '0';
                                       obj_c.rating= rating;
				       
					b_arr.push(obj_c);*/
					
					if(k==0)
					{
					
					
					//alert(i);
					complete_addressyahoo[i]=vicinity;
					complete_addresstitle[i]=bus_name;

                                                citygrid_response +='<div class = "result-business result-business-'+count+' local_'+_class+'">';

                                                citygrid_response += "<div class = 'radio-container'>";
                                                citygrid_response += "<input type ='radio' name = 'citygrid-result-cb-' value="+count+">";
                                                citygrid_response +="</input>";
                                                citygrid_response +="</div>";

                                                citygrid_response += '<div id="citygrid-result-cb-bname-'+count+'" class = "name name-'+count+'">';
                                                citygrid_response +=bus_name;
                                                citygrid_response +="</div>";
                                                
					        citygrid_response += '<div id="citygrid-result-cb-cadd-'+count+'" class = "address address-'+count+'">';
                                                citygrid_response +=vicinity;
                                                citygrid_response +="</div>";

                                            					
						citygrid_response += '<input id="citygrid-result-cb-rating-'+count+'" type=hidden class = "rating rating-'+count+'" value="'+rating+'">';
                                                citygrid_response +="</input>";

						citygrid_response += '<input id="citygrid-result-cb-listing-'+count+'" type=hidden class = "listing listing-'+count+'" value="'+listing_id+'">';
                                                citygrid_response +="</input>";	
						
			
 

                                               citygrid_response +="</div>";
											   
											      if(set==8)
											   {
											  

					 
					citygrid_response1 +=' <div class="box"><img src="/sites/all/themes/leadform/images/'+(total)+'.gif" align="middle" class="area_num" />';
					//alert(complete_addresstitle[j]);
					// alert(complete_addressyahoo[j]);
					 var _class = 'left';
                                        if((j+1)%2==0){
                                            _class = 'right';
                                        }
										
					 citygrid_response1 +='<p class = "pad_left">';
					//yelp_response1 +='<input type="hidden" id="idd" value="id'+j+'">';
					citygrid_response1 +='<div id="selectedbusiness'+total+'"><a class="linka" href="#" onclick ="cal_next('+total+');">';
					citygrid_response1 += '<div id="yahoo-result-cb-bn-'+total+'" >';
                                           citygrid_response1 +=bus_name;
                                           citygrid_response1 +="</div>";
										   citygrid_response1 +='</a></div>';
					citygrid_response1 +='<div id="yahoo-result-cb-cadds-'+total+'" style="margin-left:23px;" class = "address address-'+total+'">';
                                           citygrid_response1 +=vicinity;
                                           citygrid_response1 +="</div>";
					 citygrid_response1 +="</p>";
					 citygrid_response1 +="</div>";
					 total++;
					 list++;
					 //if(complete_addressyahoo[j] == dd){k=dd; alert(k);}
					 }
					  

                                                count ++;
												i++;
												
												}

                                                
                                            }
                                        
                                        });
					citygrid_response +="</div>";
                                    });
                               $('.desc-test1').empty();
							   }
                                else {
                                    //$('.desc-test').empty();
                                   // citygrid_response += "No results are found, please refine your search.</br>";
                                //google_response += "Not Found";

                                }

                                $("#banner").css("display","none");
                               $("#blue_outer").css("display","none");
                                $("#ser-business-box").css("display","none");
                                $("#progress_container").css("display","none");
								 $("#selected_progress_container").css("display","none");

                               // $("#business-list-page").css("display","block");
                               
								if(set==8)
			                     {
			                          citygrid_response1 +="</div>";
					//citygrid_response1 +='<div class="tright"><img height="283" width="303" alt="map" src="/sites/all/themes/leadform/images/map.jpg"></div>';
					
			                          $("#business-iop").append(citygrid_response1);
			                    }
			                  else
			                    {
			                     $("#business-list-container").append(citygrid_response);
			                    }
                            });
                        });


                    }
                });
            });

        },

        complete:function() {
            //_done = _done +1;
            $("#citygrid-progress").progressBar(100);
            $('#citygrid-right-arraw').css("display","block");
			if(set==8)
			{
			$("#business-iop").css("display","block");
			}
			else
			{
			$("#business-list-page").css("display","block");
			}
   
        }
    });return i;
}

function toggle_refine_search(){
    $("#banner").css("display","block");
    $("#blue_outer").css("display","block");
    $("#ser-business-box").css("display","block");
    //$("#progress_container").css("display","block");
    $("#business-list-page").css("display","none");
	 $('#iop').html(' <a class="button4" href="#" onclick ="calculate_next();"> </a>');
}
function calculate_next(){


 
 if($('#business-list-container').text()=='')
 {
 $('.desc-test1').empty();
 $('.localb').empty();

  $('#business-list-container').html('<h2>Please click on refine your search</h2>');
  $('.next-button').empty();
 }
 else
 {
// if($('#ffff').text()=='NO Results Found')
// {
// }
// else
// {
    var cb_val = '';
    var name_val= '';
  /*  */
      $('input:radio[name=yelp-result-cb-]').each(function(){
        if ($(this).attr('checked')){
          // alert("hsds" + $(this).val());
           name_val = $(this).attr("name");
           cb_val = $(this).val();
        }
      }); 
    $('input:radio[name=yahoo-result-cb-]').each(function(){
        if ($(this).attr('checked')){
          // alert("hsds" + $(this).val());
              name_val = $(this).attr("name");
              cb_val = $(this).val();
        }
    });

     $('input:radio[name=citygrid-result-cb-]').each(function(){
        if ($(this).attr('checked')){
          // alert("hsds" + $(this).val());
	   name_val = $(this).attr("name");	
           cb_val = $(this).val();
        }
       });

     $('input:radio[name=bing-result-cb-]').each(function(){
        if ($(this).attr('checked')){
          // alert("hsds" + $(this).val());
	   name_val = $(this).attr("name");	
           cb_val = $(this).val();
        }
     });  
      
         $('input:radio[name=google-result-cb-]').each(function(){
        if ($(this).attr('checked')){
          // alert("hsds" + $(this).val());
           name_val = $(this).attr("name");
           cb_val = $(this).val();
        }
    });


      
/*


 */
 // alert(cb_val);
 // alert(name_val); 
  
    var bus_name = $("#"+name_val+"bname-"+cb_val).text();
    var address = $("#"+name_val+"cadd-"+cb_val).text();
    var rating = $("#"+name_val+"rating-"+cb_val).val();
    var lat = $("#"+name_val+"lati-"+cb_val).val();
    var lng = $("#"+name_val+"lng-"+cb_val).val();
    var listing_id = $("#"+name_val+"listing-"+cb_val).val();

 
   
 $('.selected-name').html(bus_name);
 $('.selected-address').html(address);
 $('.selected-rating').val(rating);
 $('.selected-lat').val(lat);
 $('.selected-lng').val(lng);
 $('.selected-listing_id').val(listing_id);

 $('#business-list-page').css("display","none");
    $('#selected-business-info-page').css("display","block");
}	

}

/* This stuff for private user  */
function getYahooReviewsForUser(query,zip)
{
    var TotalRatings;
    var percentage=0;
    $.ajax ({
        async:false,
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method:"getYahooReviews",
            query:query,
            loc:zip
        },

        beforeSend:function(){

            //$("#progress_container").css("display","block");
            $("#yahoo-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
        success: function(msg){

            setInterval(function() {

                if(percentage<95){
                    percentage +=10;
                    $("#yahoo-progress").progressBar(percentage);
                }

            }, 100);
            $(msg).find("reviewsResponse").each(function(){

                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {

                        var yahoo_response = "";

                        $(this).parent().find("yahooreviews").each(function()
                        {
                            $(this).find("ResultSet").each(function()
                            {
                                if($(this).attr('totalResultsReturned')>0){
                                $(this).find("Result").each(function(){

                                    $(this).find("Rating").each(function(){

                                       
                                        TotalRatings = $(this).find("TotalRatings").text();
                                        //TotalRatings=2;

                                        yahoo_response += "<div class = 'rating-static rating-" + TotalRatings *10 +"' >";
                                       
                                    });

                                });
                            }else{
                                TotalRatings=0;

                                yahoo_response += "<div class = 'rating-static rating-" + TotalRatings *10 +"' >";
                                var yahoo_response_not="Not Found";
                                $("#userYahooRating").html(yahoo_response);
                                $("#userYahooRatingNotFound").html(yahoo_response_not);

                            }
  
                            });
                        });
                     
                     $("#userYahooRating").html(yahoo_response);
                  

                   }
                });
            });

        },
        complete:function() {

            $("#yahoo-progress").progressBar(100);
            $('#yahoo-right-arraw').css("display","block");
            $('#userresult_report_progress').hide();
            $('#review_report').show();
        }
    });
    
  return TotalRatings;
}
/*This function gets the information about user business from google API and inserts it in DB*/
function getGoogleReviewsForUser(uid,address,query,type)
{  var rating;

    var percentage=0;
    var count = 1;

    $.ajax ({
        async:false,
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method: "getGoogleReviews",
            query:query,
            loc:address,
            type:type,
            radius:'500',
            format:"xml" //google API return XML/JSON both, Let it be XML format.

        },
        beforeSend:function(){
            $("#google-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
        success: function(msg){
            $(msg).find("reviewsResponse").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {


                        var google_response = "";

                        $(this).parent().find("googlereviews").each(function()
                        {
                            $(this).find("PlaceSearchResponse").each(function()
                            {
                                if($(this).find("status").text() =='OK'){
                                       google_response +='<div class=google-results>';
                                        $(this).find("result").each(function(){
                                            var bus_name = $(this).find("name").text();
                                            rating = $(this).find("rating").text();
                                           
                                            var vicinity = $(this).find("vicinity").text();
                                            var type = $(this).find("type").text();
                                            var _class = 'left';
                                            if(count%2==0){
                                                _class = 'right';
                                            }

                                            google_response +='<div class = "result-business result-business-'+count+' local_'+_class+'">';
                                            google_response += "<div class = 'rating-static rating-" + rating *10 +"' >";
                                            google_response +="</div>";
                                            google_response +="</div>";

                                             count ++;
                                        });
                                        google_response +="</div>";
                                   }
                                else {

                                rating=0;
                                var google_response_not="Not Found";
                                google_response += "<div class = 'rating-static rating-" + rating *10 +"' >";
                                $("#userGoogleRating").html(google_response);
                                $("#userGoogleRatingNotFound").html(google_response_not);

                                }


                            });
                        });
                        
                        $("#userGoogleRating").html(google_response);
                         

                    }
                });
            });

        },
          complete:function() {

            $("#google-progress").progressBar(100);
            $('#google-right-arraw').css("display","block");

            $('#userresult_report_progress').hide();
            $('#review_report').show();
			
			

        }
    });
	
	
	
	
    return rating;
}

function goToPage(URL){
 /*$('.new-inner').css("display","none");
            $('.text-inner').css("display","none");
            $('#banner').css("display","none");
           
			$("#selected_progress_container").css("display","none");
            $('.botttom').css("display","none");
            $('.join-us').css("display","none"); */
			$('.new-inner').css("display","none");
            $('.text-inner').css("display","none");
            $('#banner').css("display","none");
			// $('#searchdata').css("display","block");
			 $('#searchdata').html("Generating your review report....");
			 $('#selected-business-info-page').css("display","none");
			 //$("#selected_progress_container").css("display","block");
            $('#progress_container').css("display","block");
            $('.botttom').css("display","none");
            $('.join-us').css("display","none");
 
//$('#selected_progress_container').css("display","block");
 
 //URL='http://localhost/pureviews/testimonials-0';
 
 var selected_b_name = $('.selected-name').text();
 var selected_b_address = $('.selected-address').text();
 var selected_business_rating=$('.selected-rating').val();
 var selected_lat = $('.selected-lat').val();//$('#selected_business_lat').val();
 var selected_lng = $('.selected-lng').val();//$('#selected_business_lng').val();
 var selected_listing_id = $('.selected-listing_id').val();
 
 var glatlng = selected_lat+','+selected_lng;
     		
 var getlatlng_location=geoCodeLocation(selected_b_address,"xml");

 var selected_loc_latilong=getlatlng_location.split(',');
 var selected_loc_lati=selected_loc_latilong[0];   
 var selected_loc_long=selected_loc_latilong[1];
 var selected_lat =selected_loc_latilong[0];
var selected_lng =selected_loc_latilong[1];
var glatlng = selected_lat+','+selected_lng;

 //var yelp_lati=latilong[0];
// var yelp_long=latilong[1];
//alert("lati-lng from yelp address is"+yelp_lati+"and"+yelp_long);
//alert(selected_b_name+','+selected_b_address+','+selected_business_rating+','+selected_lat+','+selected_lng);
   
 //var selected_yahoo_rating= selected_getYahooReviews(selected_b_name,selected_lat,selected_lng,selected_b_address); //Done


/*
*/                        
var selected_yahoo_rating=selected_getYahooReviews(selected_b_name,selected_listing_id,selected_lat,selected_lng);
//alert(" yahoo rating array returned by API is: " +selected_yahoo_rating);
//var selected_yahoo_rating=selected_getYahooReviews(selected_b_name,selected_listing_id); 	// final Done 
if(isNaN(selected_yahoo_rating[0]))
{
var yahoo_rating=0;
}
else
{
var yahoo_rating=selected_yahoo_rating[0];
}
var yahoo_review_count=selected_yahoo_rating[1];
var yahoo_review_url=selected_yahoo_rating[2]; 
var yahoo_map=selected_yahoo_rating[3]; 
var yahoo_address=selected_yahoo_rating[4]; 
var yahoo_city=selected_yahoo_rating[5]; 
var yahoo_state=selected_yahoo_rating[6]; 
var yahoo_phone=selected_yahoo_rating[7]; 

var send_yahoo_rating=yahoo_rating+","+yahoo_review_count+","+yahoo_review_url+","+yahoo_map+","+yahoo_address+","+yahoo_city+","+yahoo_state+","+yahoo_phone;


//alert("yahoo rating array on dashboard page" +send_yahoo_rating);

var selected_citygrid_rating = selected_getCityGridReviews(selected_b_name,selected_listing_id,selected_lat,selected_lng,10,"food");//done   selected_b_name,selected_loc_lati,selected_loc_long,'10','food',
//alert(selected_citygrid_rating);
if(isNaN(selected_citygrid_rating[0]))
{
var citygrid_rating=0;
}
else
{
var citygrid_rating=selected_citygrid_rating[0];
}
var citygrid_review_count=selected_citygrid_rating[1];
var citygrid_review_url=selected_citygrid_rating[2]; 
var city_address = selected_citygrid_rating[3]; 
var city_city = selected_citygrid_rating[4]; 
var city_state= selected_citygrid_rating[5]; 
var city_phone = selected_citygrid_rating[6]; 
//var send_citygrid_rating=citygrid_rating+","+citygrid_review_count+","+citygrid_review_url; 
var send_citygrid_rating=citygrid_rating+","+citygrid_review_count+","+citygrid_review_url+","+city_address+","+city_city+","+city_state+","+city_phone; 

var selected_bing_rating=selected_getBingReviews(selected_b_name,'en-us',selected_lat,selected_lng,'1');
if(isNaN(selected_bing_rating[0]))
{
var bing_rating=0;
}
else
{
var bing_rating=selected_bing_rating[0];
}
var bing_review_count=selected_bing_rating[1];
var bing_review_url=selected_bing_rating[2]; 
var send_bing_rating=bing_rating+","+bing_review_count+","+bing_review_url; 


var selected_google_rating = selected_getGoogleReviews(glatlng,selected_b_name,selected_listing_id);  //Google type Problem
if(isNaN(selected_google_rating[0]))
{
var google_rating=0;
}
else
{
var google_rating=selected_google_rating[0];
}
var google_review_count=selected_google_rating[1];
var google_review_url=selected_google_rating[2]; 
var send_google_rating=google_rating+","+google_review_count+","+google_review_url;

//alert(selected_b_name+','+selected_lat+','+selected_lng);


var selected_yelp_rating =selected_getYelpReviews(selected_b_name,selected_b_address);  //Done
//alert(selected_yelp_rating);
if(isNaN(selected_yelp_rating[0]))
{
var yelp_rating=0;
}
else
{
var yelp_rating=selected_yelp_rating[0];
}
var yelp_review_count=selected_yelp_rating[1];
var yelp_review_url=selected_yelp_rating[2];
var yelp_profile_pic_url=selected_yelp_rating[3]; 
var yelp_address=selected_yelp_rating[4]; 
var yelp_city=selected_yelp_rating[5]; 
var yelp_state=selected_yelp_rating[6]; 
var yelp_phone=selected_yelp_rating[7]; 
var send_yelp_rating=yelp_rating+","+yelp_review_count+","+yelp_review_url+","+yelp_profile_pic_url+","+yelp_address+","+yelp_city+","+yelp_state+","+yelp_phone;



//var send_yahoo_rating='';
//var send_yelp_rating='';



/*
//var selected_citygrid_rating =selected_getCityGridReviews(selected_listing_id);  //done
                             
if(isNaN(selected_yahoo_rating)){
send_yahoo_rating=0;
}
if(isNaN(selected_google_rating)){
selected_google_rating=0;
}
if(isNaN(selected_yelp_rating)){
selected_yelp_rating=0;
}
if(isNaN(selected_citygrid_rating)){
selected_citygrid_rating=0;
}
if(isNaN(selected_bing_rating)){
selected_bing_rating=0;
}
*/
/*
alert(send_yahoo_rating);
alert(send_yelp_rating);
alert(send_google_rating);
alert(send_citygrid_rating);
alert("wait");
*/
post(uri1, {
        uniqueid:uniqueId,
        emailid:emailId,
        business:selected_b_name,
        address:selected_b_address, 
	yahoo:send_yahoo_rating,
        yelp:send_yelp_rating,
        google:send_google_rating, 
        citygrid:send_citygrid_rating,	
        bing:send_bing_rating 
       /*
        
	 
       */
});
/*
var yelp_rating= 0;      //selected_google_rating[0];
var yelp_review_count=0; //selected_google_rating[1];
var yelp_review_url=0;   //selected_google_rating[2];

var google_rating=0; //selected_citygrid_rating[0];
var google_review_count=0;//selected_citygrid_rating[1];
var google_review_url=0; //selected_citygrid_rating[2];

var yahoo_rating=0;//selected_yelp_rating[0];
var yahoo_review_count=0;//selected_yelp_rating[1];
var yahoo_review_url=0;//selected_yelp_rating[2];


var citygrid_rating=0;//selected_bing_rating[0];
var citygrid_review_count=0;//selected_bing_rating[1];
var citygrid_review_url=0;//selected_bing_rating[2];


var bing_rating=0; //selected_citygrid_rating[0];
var bing_review_count=0;//selected_citygrid_rating[1];
var bing_review_url=0; //selected_citygrid_rating[2];
*/

//For Updating user rating related parameters in database.
 
updateUserDataFunctions(uniqueId,'update',selected_b_name,selected_b_address,yahoo_rating,yahoo_review_count,yahoo_review_url,
                                   google_rating,google_review_count,google_review_url,
                                   citygrid_rating,citygrid_review_count,citygrid_review_url,
 				   yelp_rating,yelp_review_count,yelp_review_url,
				   bing_rating,bing_review_count,bing_review_url,yahoo_map,yahoo_address,yahoo_city,yahoo_state,yahoo_phone,
				   city_address,city_city,city_state,city_phone,
				   yelp_address,yelp_city,yelp_state,yelp_phone);

}

function post(URL, PARAMS) {
	var temp=document.createElement("form");
	temp.action=URL;
	temp.method="POST";
	temp.style.display="none";
	for(var x in PARAMS) {
		var opt=document.createElement("textarea");
		opt.name=x;
		opt.value=PARAMS[x];
		temp.appendChild(opt);
	}
	document.body.appendChild(temp);
	temp.submit();
	return temp;
}

function selected_getYahooReviews(companyName,listingId,_latitude,_longitude)
//function selected_getYahooReviews(companyName,_latitude,_longitude)
{
//alert(companyName+_latitude+_longitude);
   var percentage=0;
   var yahoo_rating=0;
   var yahoo_review_count=0;
   var yahoo_review_url=0;
    var yahoo_map_url=0;
    var  ncount =1; 
	var yahoo_address=0;
	var yahoo_city=0;
	var yahoo_state=0;
	var yahoo_phone=0;
	var listing_id ="";
  // var selected_review='';
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
	async:false,
        data:{
            method:"getYahooReviews",                                             
            query:companyName,
			// listing_id:listingId,
			latitude:_latitude,
            longitude:_longitude,
            results:'1'						 //query:companyName,
		       						                 //latitude:_latitude,
           									 //longitude:_longitude,
	   									 //results:'1'	
                                                                                
        },

        beforeSend:function(){
            $("#selected-yahoo-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
        success: function(msg){

           setInterval(function() {

                if(percentage<95){
                    percentage +=10;
                    $("#selected-yahoo-progress").progressBar(percentage);
                }

            }, 100);
            
       $(msg).find("reviewsResponse").each(function(){
		//	alert("hello!");
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {

                      $(this).parent().find("yahooreviews").each(function()
                        {

                            $(this).find("ResultSet").each(function()
                            {
							//alert($(this).attr('totalResultsReturned'));
								  if($(this).attr('totalResultsReturned')>0){
								 // alert("yes");
                                $(this).find("Result").each(function(){
					
                                       yahoo_review_url=$(this).find("Url").text();
										yahoo_map_url=$(this).find("MapUrl").text();
										yahoo_address=$(this).find("Address").text();
										yahoo_city=$(this).find("City").text();
										yahoo_state=$(this).find("State").text();
										yahoo_Phone=$(this).find("Phone").text();
				
			            $(this).find("Rating").each(function(){
                                        
                                           yahoo_review_count = parseFloat($(this).find("TotalReviews").text());
										 // alert("api returned total reviews" +yahoo_review_count);
										  // yahoo_review_count =yahoo_review_count +yahoo_review_count;
                                           yahoo_rating = parseFloat($(this).find("TotalRatings").text());
										   
										   
										  // alert("yahoo rating total returned by API on dashboard page"+yahoo_rating);
                                               ncount ++;                         
                                         });
                                   });
                                   }
                            });
                        });
                                     
                  

                   }
                });
            });
                        
        },

        complete:function() {
                    //alert(TotalRatings);
		   //alert(selected_review);
                   $("#selected-google-progress").progressBar(100);
                             },
        error:function(msg) {
                //alert("Error:" + msg);
	                    }
    });
     return [yahoo_rating,yahoo_review_count,yahoo_review_url,yahoo_map_url,yahoo_address,yahoo_city,yahoo_state,yahoo_phone];
   
}
function selected_getGoogleReviews(address,query,reference)
{

   var google_rating=0.0;
   var google_review_count=0;
   var google_review_url='';
 
     $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        async:false,
        data:{
            method: "getGoogleReviews",
            query:query,
            loc:address,
			reference:reference,
         //   type:type,
            radius:'500'
             },
        beforeSend:function(){
  
        },
		
		        error:function(msg) {
               // alert("Error:" + msg);
	                    },
        success: function(msg){
           // alert("Alert under Successs");
       $(msg).find("reviewsResponse").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {
						 //   alert(" alert under status ok");
                        $(this).parent().find("googlereviews").each(function()
                        {
                            $(this).find("PlaceDetailsResponse").each(function()
                            {
                                if($(this).find("status").text() =='OK'){
                             // alert(" alert under status section");
 					
                                    $(this).find("result").each(function(){
				
                             //alert(" alert under result section");
                                        google_rating = parseFloat($(this).find("rating").text());
                                        google_review_url = $(this).find("url").text();
										var rating = $(this).find("rating").text();
									  // alert("google Rating is ==>"+google_rating+"----"+rating);
                                    	                                                                     
                                       });
					 
					
                                }
                                
                            });
                        });

                        
                    }
                });
            });

        },
        complete:function() {
		  
        }
    });
     return [google_rating,google_review_count,google_review_url]; 
  }

function selected_getYelpReviews(term,address){
   
   var percentage=0;
    var biz;
    var yelp_response='';
    var count = 1;
	var yelp_rating=0.0;
	var yelpratings;
	var yelp_review_count=0.0; 
   var yelp_review_url=0.0; 
   var yelp_city;
   var yelp_state;
   var yelp_phone;
   var yelp_address;
   var yelp_profile_pic_url='http://pureviews.com/sites/all/themes/leadform/images/right_img.png';
	//alert(i);
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
		async:false,	
        data:{
            method: "selectedgetYelpReviews",
            term:term,
			address:address
        },
       beforeSend:function(){
            $("#yelp-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
         success: function(msg){
        
          
                
                $(msg).find("Reviews").each(function(){
 
                $(this).find("selectedgetYelpReviews").each(function(){
                          
                      $(this).find("businesses").children().each(function(){
					  //alert(term);
					  var comp = $(this).children("name").text();
					 comp = comp.toString();
					 term = term.toString();
					  //alert(comp.toLowerCase() +"=="+ term.toLowerCase());
							if(comp.toLowerCase() == term.toLowerCase()){
                          yelp_rating = parseFloat($(this).children("avg_rating").text());
						 // alert("yelp_rating"+yelp_rating);
                          yelp_review_count = parseFloat($(this).children("review_count").text()); 
						  yelp_city = $(this).children("city").text()
						  yelp_state= $(this).children("state").text()
						  yelp_address= $(this).children("address1").text()
						  yelp_phone = $(this).children("phone").text()
						 // alert("yelp_review_count"+yelp_review_count);

                            if($(this).children("photo_url_small")){                                   
  			  		yelp_profile_pic_url = $(this).children("photo_url_small").text();
                                   }
                            else{
                              		yelp_profile_pic_url = 'http://pureviews.com/sites/all/themes/leadform/images/right_img.png';
                                 }
                           $(this).children("reviews").each(function(){
				$(this).children().each(function(){
				           yelp_review_url = $(this).children("url").text();  
//alert(yelp_review_url);						   
 				}); 
 				});    
							return false;
                       }         
                     });
                         
                   });
                });
},
        complete:function() {
			$("#yelp-progress").progressBar(100);
            $('#yelp-right-arraw').css("display","block");
            $('#userresult_report_progress').hide();
            $('#review_report').show();
		
        }
        });
 return [yelp_rating,yelp_review_count,yelp_review_url,yelp_profile_pic_url,yelp_address,yelp_city,yelp_state,yelp_phone];  
}

// For CityGrid
function selected_getCityGridReviews(query,listingId,latitude,longitude,radius,type)
//function selected_getCityGridReviews(query,latitude,longitude,radius,type,listing_id)
{
  var citygrid_rating =0.0;
	var citygrid_rating_average = 0.0;
    var citygrid_response = '';
	 var citygrid_review_count=0.0;	
    var citygrid_review_url=0.0; 
    var count = 1;
    var previous_name = '';
    var listing_id = '';
    var percentage=0;
	var i=0;
	var citygrid_city;
	var citygrid_state;
	var citygrid_address;
	var citygrid_phone;
	
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
		async:false,
	data:{
            method:"selectedgetCityGridReviews",
	    query:query,
            listing_id:listing_id,	
            latitude:latitude,
            longitude:longitude,
            radius:radius,
            type:type
        },

        beforeSend:function(){
            //alert("BEFIRE");
            $("#citygrid-progress").progressBar(percentage, {
                showText: false,
                barImage: 'sites/all/themes/leadform/images/progressbg_green.gif'
            } );
        },
           success: function(msg){
             $(msg).find("reviewsResponse").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    if($(this).find("Code").text() === '1') {

                     //   var google_response = "";
                        $(this).parent().find("citygridreviews").each(function()
                        {
                            $(this).find("results").each(function()
                            {
							//alert("yes");
                                //  citygrid_review_count=$(this).attr("total_hits");        
                                if($(this).attr("total_hits") >0){
                                    $(this).find("locations").each(function()
                                    {
                                      
                                        $(this).find("location").each(function(){
										
										//alert("here");
									//	if($(this).find("name").text() == query){//
						//alert($(this).find("review_rating").text());
												citygrid_rating += parseFloat($(this).find("rating").text());
                                                var citygrid_review_url_array = ($(this).find("profile").text()).split('?');
												 citygrid_review_count =$(this).find("user_review_count").text();  
												citygrid_review_url = $(this).find("profile").text();
												citygrid_phone = $(this).find("phone_number").text();
							//alert("count--"+citygrid_review_count);
										//	return false;
                                        //      }  
											$(this).find("address").each(function(){
												citygrid_address =  $(this).find("street").text();
												citygrid_city =  $(this).find("city").text();
												citygrid_state =  $(this).find("state").text();											
										
											});
										
                                             });                
                                                  
			                        citygrid_rating_average =  parseFloat((citygrid_rating/2)/citygrid_review_count);
                                                //citygrid_review_url_array= citygrid_review_url.split('?');
						//alert(count);
						//alert(avg_reviews_rating);                       
                                            });
                                           
		                                        }else{
												citygrid_rating_average = 0.00;
												citygrid_review_count =0.00;
												citygrid_review_url =0.00;
												                               
                                citygrid_response += "<div class = 'rating-static rating-" + citygrid_rating *10 +"' >";
                                var yahoo_response_not="Not Found";
                                $("#userCityGridRating").html(citygrid_response);
                                $("#userCityGridRatingNotFound").html(yahoo_response_not);
												
												}
						
			
                               });

					
                          });
                       }
                                
                  });
                });
             },

        complete:function() {
		    $("#citygrid-progress").progressBar(100);
            $('#citygrid-right-arraw').css("display","block");
            $('#userresult_report_progress').hide();
            $('#review_report').show();
		
		
            //_done = _done +1;
          /*  $("#selected-citygrid-progress").progressBar(100);
            $('#selected-citygrid-right-arraw').css("display","block");*/
        }
    });
	//alert("city----"+citygrid_rating_average);
	   return [citygrid_rating,citygrid_review_count,citygrid_review_url,citygrid_address,citygrid_city,citygrid_state,citygrid_phone];
}


function selected_getBingReviews(query,loc,lat,lng,results){
   
   var bing_rating=0.0;
   var bing_review_count=0.0;
   var bing_review_url=0.0;
   var bing_rating_average=0.0;

    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
	async:false,	
        data:{
            method: "getBingReviews",
	    query:query,	
            loc:loc,
	    latitude:lat,
	    longitude:lng,
            count:results  		
         },
        beforeSend:function(){
         
        },
        
        success: function(msg){
        
                      
                 $(msg).find("Bingreviews").each(function()
                        {
                            $(this).find("SearchResponse").each(function()
                            {
				
                               $(this).find("Phonebook").each(function()
                                  {            
                                                                
                                           $(this).find("Results").each(function()
                                              {
                                                  // var count=1;
                                                    $(this).find("PhonebookResult").each(function()
                                                      {
                                                             if ($(this).find("ReviewCount").text()){
																	
						              bing_review_count=$(this).find("ReviewCount").text();
                                                              bing_review_url=$(this).find("DisplayUrl").text();   
                        			               }
								else{
                                                             bing_review_count=0.0;
							     bing_review_url=0.0;											
								}
                                                            // bing_review_url=$(this).find("DisplayUrl").text();   
						             var UserRating=$(this).find("UserRating").text();
                                                             if($(this).find("UserRating").text()=='')
                                                             {
 								UserRating=0.0;
                                                             }
				                	//bing_rating += parseFloat(UserRating);
                              				
                                                        //  count++;		
                                                              bing_rating_average =(parseFloat(UserRating))/2;                                              
 
                                                      });
                                                   //bing_rating_average= parseFloat(parseFloat(bing_rating)/parseFloat(count));
					
                  
                                              });
                                   });
                            });
                        });

   },
        complete:function() {
        
        }
    });
    return [bing_rating_average,bing_review_count,bing_review_url];
}

function getReviewsFromDb(uid){


     $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method: "getReviewsFromDb",
            uid:uid
        },
        success: function(msg) {

            //find each instance of Response in xml file and wrap it in a link
            $(msg).find("Response").each(function(){
                //find each instance of Response in xml file and wrap it in a link
                $(this).find("Status").each(function()
                {
                    //XML is returning text value of code
                    var yahoo_response="";
                    var google_response="";
                    var yelp_response="";
                    var citygrid_response="";
                    var bing_response="";
                    var averageRating="";
                    if($(this).find("Code").text() === '1') {
                        $(this).parent().find("ratingResponseFromDb").each(function()
                        {
                            var yahooratings=$(this).find("yahoorating").text();
                           
                            yahoo_response += "<div class = 'rating-static rating-" + yahooratings *10 +"' >";
                            yahoo_response +="</div>";
                            $("#userYahooRating").html(yahoo_response);
                            

                            var googleratings=$(this).find("googlerating").text();
                            
                            google_response += "<div class = 'rating-static rating-" + googleratings *10 +"' >";
                            google_response +="</div>";
                            $("#userGoogleRating").html(google_response);

                            var yelpratings=$(this).find("yelprating").text();
                           
                            yelp_response += "<div class = 'rating-static rating-" + yelpratings *10 +"' >";
                            yelp_response +="</div>";
                            $("#userYelpRating").html(yelp_response);

                            var citygridratings=$(this).find("citygridrating").text();
                           
                            citygrid_response += "<div class = 'rating-static rating-" + citygridratings *10 +"' >";
                            citygrid_response +="</div>";
                            $("#userCityGridRating").html(citygrid_response);

                            var bingratings=$(this).find("bingrating").text();
                           
                            bing_response += "<div class = 'rating-static rating-" + bingratings *10 +"' >";
                            bing_response +="</div>";
                            $("#userBingRating").html(bing_response);


                            yahooratings=parseFloat(yahooratings*20) ;
                            googleratings=parseFloat(googleratings*20) ;
                            yelpratings=parseFloat(yelpratings*20) ;
                            citygridratings=parseFloat(citygridratings*20) ;
                            bingratings=parseFloat(bingratings*20) ;

                            //parseFloat("15"))

                          averageRating  =(yahooratings+googleratings+yelpratings+citygridratings+bingratings)/5;
                          $("#avg_rat").html(averageRating);
                            

                            
                        });
                    }
                });


            });
        }
    });

}

function insertAllReviewsToDb(uid,yRating,gRating){


     $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method: "insertAllReviewsToDb",
            uid:uid,
            yrating:yRating,
            grating:gRating
            
        },
        success: function(msg) {

            
        }
    });

}


/*function UEF(a)   //FUNCTION UNIQUE(ARRAY A)
{
var j=0; //J=0;
var b= new Array();    //ARRAY B;
var c= new Array();//ARRAY C;
for(var i=0;i<a.length;i++)              //FOR I=0 TO LENGTH OF ARRAY (FOR ARRAY A) 
{
            if(a[i] == 0) //IF(ARRAY A[I] == 0)
               {
                  
                  continue;//CONTINUE;
                    alert("I m in phase 1 if");
               }
            else//ELSE
               {
                   
                  b[j] = a[i]; // ARRAY B[J] = ARRAY A[I]
                  j++;  //J++
                   alert("I m in phase 1 else");
               }

    for(var k=i;k<a.length;k++)   //FOR K=I TO LENGTH OF ARRAY (FOR ARRAY A)
        {
            if(a[k] == 0)   //IF(ARRAY A[K] == 0)
                 {      
                  
                   continue; //CONTINUE;
                   alert("I m in phase 2 if");
                 }      
            else if(a[k].lat == a[i].lat && a[k].lng == a[i].lng )//ELSE IF( ARRAY A[K] == ARRAY A[I])
                 {
                   
                  c[i] = a[i];
                  a[k] = 0;
                  alert("I m in phase 2 else");
                 }
          }  //      END LOOP
}//END LOOP
alert("hello i m here");
alert(b.length);
alert(b[0].bus_name);//RETURN ARRAY B;
}*/

//function getYahooReviews(query,zip)
function getYahoomap(companyName,_latitude,_longitude,_businessAddress)
{   
//alert('here is start');
//alert(complete_addressyahoo.length);
var yahoo_response1 = '';
/* yahoo_response1 +='<p style="font-size:27px;">Local Businesses Found('+complete_addressyahoo.length+')</p>'; */
yahoo_response1 +='<p style="font-size:27px;">Local Businesses Found</p>';

  yahoo_response1 +='<div class="tleft">';
for (j=0;j<complete_addressyahoo.length;j++)
                     {
					 
					yahoo_response1 +=' <div class="box"><img src="/sites/all/themes/leadform/images/'+(j+1)+'.gif" align="middle" class="area_num" />';
					//alert(complete_addresstitle[j]);
					// alert(complete_addressyahoo[j]);
					 var _class = 'left';
                                        if((j+1)%2==0){
                                            _class = 'right';
                                        }
										
					 yahoo_response1 +='<p class = "pad_left">';
					//yahoo_response1 +='<input type="hidden" id="idd" value="id'+j+'">';
					yahoo_response1 +='<div id="selectedbusiness'+j+'"><a class="linka" href="#" onclick ="cal_next('+j+');">';
					yahoo_response1 += '<div id="yahoo-result-cb-bn-'+j+'" >';
                                           yahoo_response1 +=complete_addresstitle[j];
                                           yahoo_response1 +="</div>";
										   yahoo_response1 +='</a></div>';
					 yahoo_response1 +='<div id="yahoo-result-cb-cadds-'+j+'" style="margin-left:23px;" class = "address address-'+j+'">';
                                           yahoo_response1 +=complete_addressyahoo[j];
                                           yahoo_response1 +="</div>";
					 yahoo_response1 +="</p>";
					 yahoo_response1 +="</div>";
					 //if(complete_addressyahoo[j] == dd){k=dd; alert(k);}
					 }
					  yahoo_response1 +="</div>";
					//yahoo_response1 +='<div class="tright"><img height="283" width="303" alt="map" src="/sites/all/themes/leadform/images/map.jpg"></div>';
					   $("#business-local-list-container").append(yahoo_response1);
    
    /* var percentage=0;
    var count=1;
	var i=0;
    $.ajax ({
        cache: false,
        type:'POST',
        url:uri,
        data:{
            method:"getYahoomap",
            query:companyName,
            latitude:_latitude,
            longitude:_longitude,
            results:_businessAddress
             },

       
        success: function(msg){

            setInterval(function() {
               
                if(percentage<95){
                    percentage +=10;
                    $("#yahoo-progress").progressBar(percentage);
                }

            }, 100);
           

        },
		
		 }); //getYahooReviews(companyName,_latitude,_longitude,_businessAddress);
        complete:function() {
            
           $("#business-compare-page").css("display","block");
          
	 

        }
   */
    $("#business-compare-page").css("display","block");
}
var caladdress='';
function cal_next(id)
{
//alert('alert on the link function');
//alert(id);
//var s='';
//s='manoj kumar';

// var dd=$('.selectedbusiness').text();
 //alert(dd);
 //alert(id);
var s='';
//$("#business-iop").append(s);
s=$('#yahoo-result-cb-bn-'+id+'').text();
//alert(s);
caladdress =$('#yahoo-result-cb-cadds-'+id+'').text();

var dd='<input type="text" class="form-text required" value='+s+' size="30" id="edit-submitted-email" name="submitted[email]" maxlength="128"></input>';
$('.select_business').val(s);
var t=1;
$('.select_business1').val(t);
var p="/sites/all/themes/leadform/images/search_btn.jpg";
$('#select_business_report').html('<div style="padding-top:15px;" ><input class="select_business_report" type="image" src="/sites/all/themes/leadform/images/search_btn.jpg" /><div>');

//$("#business-iop").append(s);
//var ss=$('#selected_business_company').val();
}



function cal_ne(type)
{


/*  Code for first company result */	
 $('#progress_container').css("display","block");
  $('#searchdata').html("Generating your review report....");
  $('#business-compare-page').css("display","none");

 var first_b_address = $('.selected-address').text();
 var first_selected_b_name = $('.selected-name').text();
 // var first_selected_listing_id = $('.selected_listing_id').val();
  var first_selected_listing_id ='';
 var first_getlatlng_location=geoCodeLocation(first_b_address,"xml");

 var first_selected_loc_latilong=first_getlatlng_location.split(',');
 var first_selected_loc_lati=first_selected_loc_latilong[0];   
 var first_selected_loc_long=first_selected_loc_latilong[1];
 var first_glatlng = first_selected_loc_lati+','+first_selected_loc_long;
 
 
 
		/* alert(first_b_address);
		alert(first_getlatlng_location)
		alert("ok");
		alert(caladdress); */
		
		
	var first_selected_yahoo_rating=selected_getYahooReviews(first_selected_b_name,first_selected_listing_id,first_selected_loc_lati,first_selected_loc_long);
//var selected_yahoo_rating=selected_getYahooReviews(selected_b_name,selected_listing_id); 	// final Done 
if(isNaN(first_selected_yahoo_rating[0]))
{
var first_yahoo_rating=0;
}
else
{
var first_yahoo_rating=first_selected_yahoo_rating[0];
}
var first_yahoo_review_count=first_selected_yahoo_rating[1];
var first_yahoo_review_url=first_selected_yahoo_rating[2]; 
var first_send_yahoo_rating=first_yahoo_rating+","+first_yahoo_review_count+","+first_yahoo_review_url;
//alert("First"+first_send_yahoo_rating)

var first_selected_citygrid_rating = selected_getCityGridReviews(first_selected_b_name,first_selected_listing_id,first_selected_loc_lati,first_selected_loc_long,1,"company");//done   selected_b_name,selected_loc_lati,selected_loc_long,'10','food',
if(isNaN(first_selected_citygrid_rating[0]))
{
var first_citygrid_rating=0;
}
else
{
var first_citygrid_rating=first_selected_citygrid_rating[0];
}
var first_citygrid_review_count=first_selected_citygrid_rating[1];
var first_citygrid_review_url=first_selected_citygrid_rating[2]; 
var first_send_citygrid_rating=first_citygrid_rating+","+first_citygrid_review_count+","+first_citygrid_review_url; 


var first_selected_bing_rating=selected_getBingReviews(first_selected_b_name,'en-us',first_selected_loc_lati,first_selected_loc_long,'10');
//alert("fi---"+first_selected_bing_rating)
if(isNaN(first_selected_bing_rating[0]))
{
var first_bing_rating=0;
}
else
{
var first_bing_rating=first_selected_bing_rating[0];
}
var first_bing_review_count=first_selected_bing_rating[1];
var first_bing_review_url=first_selected_bing_rating[2]; 
var first_send_bing_rating=first_bing_rating+","+first_bing_review_count+","+first_bing_review_url; 


var first_selected_google_rating = selected_getGoogleReviews(first_glatlng,first_selected_b_name);  //Google type Problem
if(isNaN(first_selected_google_rating[0]))
{
var first_google_rating=0;
}
else
{
var first_google_rating=first_selected_google_rating[0];
}
var first_google_review_count=first_selected_google_rating[1];
var first_google_review_url=first_selected_google_rating[2]; 
var first_send_google_rating=first_google_rating+","+first_google_review_count+","+first_google_review_url;

//alert(selected_b_name+','+selected_lat+','+selected_lng);


var first_selected_yelp_rating =selected_getYelpReviews(first_selected_b_name,first_b_address);  //Done
if(isNaN(first_selected_yelp_rating[0]))
{
var first_yelp_rating=0;
}
else
{
var first_yelp_rating=first_selected_yelp_rating[0];
}
var first_yelp_review_count=first_selected_yelp_rating[1];
var first_yelp_review_url=first_selected_yelp_rating[2];
var first_yelp_profile_pic_url=first_selected_yelp_rating[3]; 
var first_send_yelp_rating=first_yelp_rating+","+first_yelp_review_count+","+first_yelp_review_url+","+first_yelp_profile_pic_url;
	
		
		
		
/* End Code for first company result */		
var s=$('#selected_business_company').val();
//alert(s);
var f=$('#selected_business_company2').val();
//alert(f);
//alert(caladdress);
//goToPage('public-review-report');
var selected_b_name = s;
 var selected_b_address = caladdress;
 var selected_business_rating=$('.selected-rating').val();
 var selected_lat = $('.selected-lat').val();//$('#selected_business_lat').val();
 var selected_lng = $('.selected-lng').val();//$('#selected_business_lng').val();
 var selected_listing_id = $('.selected-listing_id').val();
 
 var glatlng = selected_lat+','+selected_lng;
     		
 var getlatlng_location=geoCodeLocation(selected_b_address,"xml");

 var selected_loc_latilong=getlatlng_location.split(',');
 var selected_loc_lati=selected_loc_latilong[0];   
 var selected_loc_long=selected_loc_latilong[1];
 var selected_lat =selected_loc_latilong[0];
var selected_lng =selected_loc_latilong[1];
var glatlng = selected_lat+','+selected_lng;
//alert(glatlng);
var selected_yahoo_rating=selected_getYahooReviews(selected_b_name,selected_listing_id,selected_lat,selected_lng);
//var selected_yahoo_rating=selected_getYahooReviews(selected_b_name,selected_listing_id); 	// final Done 
//alert(selected_yahoo_rating);
if(isNaN(selected_yahoo_rating[0]))
{
var yahoo_rating=0;
}
else
{
var yahoo_rating=selected_yahoo_rating[0];
}
var yahoo_review_count=selected_yahoo_rating[1];
var yahoo_review_url=selected_yahoo_rating[2]; 
var send_yahoo_rating=yahoo_rating+","+yahoo_review_count+","+yahoo_review_url;
//alert(send_yahoo_rating)

var selected_citygrid_rating = selected_getCityGridReviews(selected_b_name,selected_listing_id,selected_lat,selected_lng,10,"food");//done   selected_b_name,selected_loc_lati,selected_loc_long,'10','food',
//alert(selected_citygrid_rating);
if(isNaN(selected_citygrid_rating[0]))
{
var citygrid_rating=0;
}
else
{
var citygrid_rating=selected_citygrid_rating[0];
}
var citygrid_review_count=selected_citygrid_rating[1];
var citygrid_review_url=selected_citygrid_rating[2]; 
var send_citygrid_rating=citygrid_rating+","+citygrid_review_count+","+citygrid_review_url; 


var selected_bing_rating=selected_getBingReviews(selected_b_name,'en-us',selected_lat,selected_lng,'1');
if(isNaN(selected_bing_rating[0]))
{
var bing_rating=0;
}
else
{
var bing_rating=selected_bing_rating[0];
}
var bing_review_count=selected_bing_rating[1];
var bing_review_url=selected_bing_rating[2]; 
var send_bing_rating=bing_rating+","+bing_review_count+","+bing_review_url; 


var selected_google_rating = selected_getGoogleReviews(glatlng,selected_b_name);  //Google type Problem
if(isNaN(selected_google_rating[0]))
{
var google_rating=0;
}
else
{
var google_rating=selected_google_rating[0];
}
var google_review_count=selected_google_rating[1];
var google_review_url=selected_google_rating[2]; 
var send_google_rating=google_rating+","+google_review_count+","+google_review_url;

//alert(selected_b_name+','+selected_lat+','+selected_lng);


/*var selected_yelp_rating =selected_getYelpReviews(selected_b_name,selected_lat,selected_lng,1,1); */ //Done
var selected_yelp_rating =selected_getYelpReviews(selected_b_name,selected_b_address);  //Done
//alert(selected_yelp_rating);
if(isNaN(selected_yelp_rating[0]))
{
var yelp_rating=0;
}
else
{
var yelp_rating=selected_yelp_rating[0];
}
var yelp_review_count=selected_yelp_rating[1];
var yelp_review_url=selected_yelp_rating[2];
var yelp_profile_pic_url=selected_yelp_rating[3]; 
var send_yelp_rating=yelp_rating+","+yelp_review_count+","+yelp_review_url+","+yelp_profile_pic_url;


post(uri2, {
        uniqueid:'1',
        emailid:'test@test.com',
		type:type,
        first_business:first_selected_b_name,
        first_address:first_b_address, 
		first_yahoo:first_send_yahoo_rating,
        first_yelp:first_send_yelp_rating,
        first_google:first_send_google_rating, 
        first_citygrid:first_send_citygrid_rating,
		first_bing:first_send_bing_rating,
		
		business:selected_b_name,
        address:selected_b_address, 
		yahoo:send_yahoo_rating,
        yelp:send_yelp_rating,
        google:send_google_rating, 
        citygrid:send_citygrid_rating,	
        bing:send_bing_rating 
     
});
/*
var rating_yahoohtml = "<div class = 'rating-static rating-" + (Math.ceil(yahoo_rating))*10+"' >";                 
    var rating_googlehtml = "<div class = 'rating-static rating-" + (google_rating)*10+"' >";        
    var rating_yelp_html = "<div class = 'rating-static rating-" + (yelp_rating)*10+"' >";              
    var rating_citygrid_html = "<div class = 'rating-static rating-" +(Math.ceil(citygrid_rating))*10 +"' >";
    var rating_bing_html= "<div class = 'rating-static rating-" + (Math.ceil(bing_rating))*10+"' >";   
$("#business-iop").append(rating_yahoohtml);
$("#business-iop").append(rating_googlehtml);
$("#business-iop").append(rating_yelp_html);
$("#business-iop").append(rating_citygrid_html);
$("#business-iop").append(rating_bing_html);


if(yahoo_review_count == 0 && yahoo_review_url == 0)
    {
      $('#business-iop').html(" - ");
      $('#business-iop').removeAttr("href"); 
      $('#business-iop').html("Not Found");
      $('#business-iop').html("<a href="+yahoo_review_url+" target=_blank><img src="+yahoo_profile_pic_url+" class=profile_image></img></a>"); 		
    }
    else if(yahoo_review_count == 0 && yahoo_review_url != 0)
    {
      $('#business-iop').html(" - ");
	   $('#business-iop').html("View Profile"); 
      $('#business-iop').attr('href',yahoo_review_url);
      $('#business-iop').html("<a href="+yahoo_review_url+" target=_blank><img src="+yahoo_profile_pic_url+" class=profile_image></img></a>"); 
    }
    else
    {
       $('#business-iop').html("View Profile"); 
      $('#business-iop').html(yahoo_review_count+" Reviews");
      $('#business-iop').attr('href',yahoo_review_url);
   //   $('#yahoo_profile_pic').html("<img src="+yahoo_profile_pic_url+"></img>");
      $('#business-iop').html("<a href="+yahoo_review_url+" target=_blank><img src="+yahoo_profile_pic_url+" class=profile_image></img></a>");
    }


    $('#publicYelpRating').html(rating_yelp_html);
    if(yelp_review_count == 0 && yelp_review_url == 0)
    {
      $('#publicYelpTrs').html(" - ");
      $('#publicYelpRel').removeAttr("href"); 
      $('#yelpProfileStatus').html("Not Found");
      $('#yelp_profile_pic').html("<a href="+yelp_review_url+" target=_blank><img src="+yelp_profile_pic_url+" class=profile_image></img></a>");	
    }
    else if(yelp_review_count == 0 && yelp_review_url != 0)
    {
      $('#publicYelpTrs').html(" - ");
      $('#publicYelpRel').attr('href',yahoo_review_url);
      $('#yelp_profile_pic').html("<a href="+yelp_review_url+" target=_blank><img src="+yelp_profile_pic_url+" class=profile_image></img></a>");
    }
    else
    {
      $('#yelpProfileStatus').html("View Profile");
      $('#publicYelpTrs').html(yelp_review_count+" Reviews");
      $('#publicYelpRel').attr('href',yelp_review_url);
      $('#yelp_profile_pic').html("<a href="+yelp_review_url+" target=_blank><img src="+yelp_profile_pic_url+" class=profile_image></img></a>");
    }


    $('#publicGoogleRating').html(rating_googlehtml);
    if(google_review_count == 0 && google_review_url == 0)
    {
      $('#publicGoogleTrs').html(" - ");
      $('#publicGoogleRel').removeAttr("href"); 
      $('#googleProfileStatus').html("Not Found");
      $('#google_profile_pic').html("<a href="+google_review_url+" target=_blank><img src="+google_profile_pic_url+" class=profile_image></img></a>");	
    }
    else if(google_review_count == 0 && google_review_url != 0)
    {
      $('#publicGoogleTrs').html(" - ");
      $('#publicGoogleRel').attr('href',google_review_url);
      $('#google_profile_pic').html("<a href="+google_review_url+" target=_blank><img src="+google_profile_pic_url+" class=profile_image></img></a>"); 	
    }
    else
     { 
     $('#googleProfileStatus').html("View Profile");
     $('#publicGoogleTrs').html(google_review_count+" Reviews");
     $('#publicGoogleRel').attr('href',google_review_url);
    // $('#google_profile_pic').html("<img src="+google_profile_pic_url+"></img>");
      $('#google_profile_pic').html("<a href="+google_review_url+" target=_blank><img src="+google_profile_pic_url+" class=profile_image></img></a>");	
     }


    $('#publicCitysearchRating').html(rating_citygrid_html);
        if(citygrid_review_count == 0 && citygrid_review_url == 0)
    {
      $('#publicCitysearchTrs').html(" - ");
      $('#publicCitysearchRel').removeAttr("href"); 
      $('#citysearchProfileStatus').html("Not Found"); 
      $('#citysearch_profile_pic').html("<a href="+citygrid_review_url+" target=_blank><img src="+citygrid_profile_pic_url+" class=profile_image></img></a>");
    }
    else if(citygrid_review_count == 0 && citygrid_review_url != 0)
    {
      $('#publicCitysearchTrs').html(" - ");
      $('#publicCitysearchRel').attr('href',citygrid_review_url);
      $('#citysearch_profile_pic').html("<a href="+citygrid_review_url+" target=_blank><img src="+citygrid_profile_pic_url+" class=profile_image></img></a>"); 	
    }
    else
     {
    $('#citysearchProfileStatus').html("View Profile");
    $('#publicCitysearchTrs').html(citygrid_review_count+" Reviews");
    $('#publicCitysearchRel').attr('href',citygrid_review_url);
   // $('#citysearch_profile_pic').html("<img src="+citysearch_profile_pic_url+"></img>");
     $('#citysearch_profile_pic').html("<a href="+citygrid_review_url+" target=_blank><img src="+citygrid_profile_pic_url+" class=profile_image></img></a>");	
     }  



    $('#publicBingRating').html(rating_bing_html);
            if(bing_review_count == 0 && bing_review_url == 0)
    {
      $('#publicBingTrs').html(" - ");
       $('#publicBingRel').removeAttr("href");  
      $('#bingProfileStatus').html("Not Found");
       $('#bing_profile_pic').html("<a href="+bing_review_url+" target=_blank><img src="+bing_profile_pic_url+" class=profile_image></img></a>");
      
    }
    else if(bing_review_count == 0 && bing_review_url != 0)
    {
      $('#publicBingTrs').html(" - ");
      $('#publicBingRel').attr('href',bing_review_url);
      $('#bing_profile_pic').html("<a href="+bing_review_url+" target=_blank><img src="+bing_profile_pic_url+" class=profile_image></img></a>"); 
    }
    else
    {
    $('#bingProfileStatus').html("View Profile"); 
    $('#publicBingTrs').html(bing_review_count+" Reviews");
    $('#publicBingRel').attr('href',bing_review_url);
   // $('#bing_profile_pic').html("<img src="+bing_profile_pic_url+"></img>");
    $('#bing_profile_pic').html("<a href="+bing_review_url+" target=_blank><img src="+bing_profile_pic_url+" class=profile_image></img></a>");
    } 


    $('#average_all').html("<strong>"+average_score+"</strong>");*/
   
    

//For Updating user rating related parameters in database.
 /*
updateUserDataFunctions(uniqueId,'update',selected_b_name,selected_b_address,yahoo_rating,yahoo_review_count,yahoo_review_url,
                                   google_rating,google_review_count,google_review_url,
                                   citygrid_rating,citygrid_review_count,citygrid_review_url,
 				   yelp_rating,yelp_review_count,yelp_review_url,
				   bing_rating,bing_review_count,bing_review_url); */


}













function cal_map()
{
 $('#selected-business-info-page').css("display","none");
var companyName = $("input#edit-submitted-company-name").val();
        var city = $("input#edit-submitted-city").val();
        var state = $("input#edit-submitted-state").val();
		
		  $("#city_state_name").html(city+","+state);
        
        if (companyName == "") {
            $("#edit-submitted-company-name").addClass('requiredFieldName');
            $("input#edit-submitted-company-name").focus();
            return false;
        }
        else {
            $("#edit-submitted-company-name").removeClass('requiredFieldName');
        }

        if (city == "") {
            $("#edit-submitted-city").addClass('requiredFieldCity');
            $("input#edit-submitted-city").focus();
            return false;
        }
        else {
            $("#edit-submitted-city").removeClass('requiredFieldCity');
        }


        if (state == "") {
            $("#edit-submitted-state").addClass('requiredFieldState');
            $("input#edit-submitted-state").focus();
            return false;
        }
        else {
            $("#edit-submitted-state").removeClass('requiredFieldState');
        }

        emailId = $("input#edit-submitted-email").val();
        var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        var emaiCheck = true;

        if (emailId == "") {
            $("#edit-submitted-email").addClass('requiredFieldName');
            $("input#edit-submitted-email").focus();
            emaiCheck = false;
            return false;
        }else if( !emailReg.test( emailId ) ){
            $("#edit-submitted-email").addClass('requiredFieldName');
            $("input#edit-submitted-email").focus();
            emaiCheck = false;
            return false;
        }
        else{
            //Google API , have origin-access restrictions and don't support localhost requests'
            /*
       *Be specific, Here We need space after comma for each address element i.e. street_adress, City, State
       *street_adress will be separated by space
      */
            //uniqueId=uniqueIdGenerator(emailId);
           // saveUserDataFunctions(uniqueId,'save',emailId);  

            var _businessAddress=companyName +", "+ city + ", " + state;
            var _businessLocationWithZip =  geoCodeLocation(_businessAddress ,"xml" );         //geoCodeLocation returns "lattitude,longitude | zip"
            var _businessLocation=_businessLocationWithZip.split(',')            
            var _businessLocationGoogle= _businessLocation[0]+","+_businessLocation[1];       
     

            var lat_long = _businessLocationWithZip.split(',');
            var _latitude=lat_long[0];
            var _longitude = lat_long[1];
			var location = geoCodeLocation(state,"xml" );
                        var loc_arr =  location.split(',');        
                        var country_name=loc_arr[2];
                        var country_code= getCountryCode(country_name);     

            $('.new-inner').css("display","none");
            $('.text-inner').css("display","none");
            $('#banner').css("display","none");
            //$('#progress_container').css("display","block");
            $('.botttom').css("display","none");
            $('.join-us').css("display","none");
			
			getYahoomap(companyName,_latitude,_longitude,_businessAddress);
}
}


function cal_search()
{
//alert('cal function');
    list=1;
  $("#business-iop").html('');
  $("#business-iop").html('Local Businesses Found');
 // 
var businessname=$('#businesscat').val();  
//alert(businessname);
var cityname=$('#city-state').val();  
//alert(cityname); 
var s=$('#edit-submitted-email').val();  
//alert(s);
var state1=aCars = cityname.split(',');

var state=state1[1];
var companyName1=businessname;
uniqueId1=uniqueIdGenerator(s);
            saveUserDataFunctions(uniqueId1,'save',s);
var _businessAddress1=businessname+", "+cityname;
            var _businessLocationWithZip1 =  geoCodeLocation(_businessAddress1 ,"xml" );         //geoCodeLocation returns "lattitude,longitude | zip"
            var _businessLocation1=_businessLocationWithZip1.split(',')            
            var _businessLocationGoogle1= _businessLocation1[0]+","+_businessLocation1[1];       
     

            var lat_long1 = _businessLocationWithZip1.split(',');
            var _latitude1=lat_long1[0];
            var _longitude1 = lat_long1[1];
			var location = geoCodeLocation(state,"xml" );
                        var loc_arr =  location.split(',');        
                        var country_name=loc_arr[2];
                        var country_code1= getCountryCode(country_name);     

            $('.new-inner').css("display","none");
            $('.text-inner').css("display","none");
            $('#banner').css("display","none");
			// $('#searchdata').css("display","block");
            $('#progress_container').css("display","block");
			//$('#selected_progress_container').css("display","block");
            $('.botttom').css("display","none");
            $('.join-us').css("display","none");
			$("#business-list-page").css("display","none");
			$("#business-iop").css("display","none");
              $("#business-iop").append('');
            
            // http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=3N0Bh8bV34Gr9ThQgeCwICBkaf9ly6iM.ZLKA9AXijbAw3UvHhKVKe3wcL7a2i9qTQpCpmLk&listing_id=32669999&query=*                             
           //getYahooReviews(companyName,_latitude,_longitude,_businessAddress);   //Done 
         var set=8;
		 getYahooReviews(companyName1,_latitude1,_longitude1,_businessAddress1,set);   //Done 
               
             getYelpReviews(companyName1,_latitude1, _longitude1, 10, 10,set);   //Done
             getGoogleReviews(_businessLocationGoogle1,companyName1,set);   //Done but "type=food" here is hardcode and it create problem when query is not related to thier type 
           getCityGridReviews(companyName1,_latitude1,_longitude1,10,"food"," ",set);

           getBingReviews(companyName1,country_code1,_latitude1, _longitude1,10,set);
		
		   
		   
		  $("#business-list-page").css("display","none");
		  $("#business-iop").css("display","none");
		  // getYahoomap(companyName,_latitude,_longitude,_businessAddress);
            

}
function cal_campare(companyName,cityName,state)
{

  $("#business-iop").html('Local Businesses Found');
  list=1;
var businessname=companyName;//$('#businesscat').val();  
//alert(businessname);
var cityname=cityName+', '+state;//$('#city-state').val();  
//alert(cityname); 
var s='vsheokeen@gmail.com';//$('#edit-submitted-email').val();  
//alert(s);
var state1=aCars = cityname.split(',');

var state=state1[1];
var companyName1=businessname;
uniqueId1=uniqueIdGenerator(s);
            saveUserDataFunctions(uniqueId1,'save',s);
var _businessAddress1=businessname+", "+cityname;
            var _businessLocationWithZip1 =  geoCodeLocation(_businessAddress1 ,"xml" );         //geoCodeLocation returns "lattitude,longitude | zip"
            var _businessLocation1=_businessLocationWithZip1.split(',')            
            var _businessLocationGoogle1= _businessLocation1[0]+","+_businessLocation1[1];       
     

            var lat_long1 = _businessLocationWithZip1.split(',');
            var _latitude1=lat_long1[0];
            var _longitude1 = lat_long1[1];
			var location = geoCodeLocation(state,"xml" );
                        var loc_arr =  location.split(',');        
                        var country_name=loc_arr[2];
                        var country_code1= getCountryCode(country_name);     

            $('.new-inner').css("display","none");
            $('.text-inner').css("display","none");
            $('#banner').css("display","none");
			// $('#searchdata').css("display","block");
            $('#progress_container').css("display","block");
			//$('#selected_progress_container').css("display","block");
            $('.botttom').css("display","none");
            $('.join-us').css("display","none");
			$("#business-list-page").css("display","none");
			$("#business-iop").css("display","none");
              $("#business-iop").append('');
         var set=8;
		 getYahooReviews(companyName1,_latitude1,_longitude1,_businessAddress1,set);   //Done 
               
             getYelpReviews(companyName1,_latitude1, _longitude1, 10, 10,set);   //Done
             getGoogleReviews(_businessLocationGoogle1,companyName1,set);   //Done but "type=food" here is hardcode and it create problem when query is not related to thier type 
           getCityGridReviews(companyName1,_latitude1,_longitude1,10,"food"," ",set);

           getBingReviews(companyName1,country_code1,_latitude1, _longitude1,10,set);
		
		   
		   
		  $("#business-list-page").css("display","none");
		  $("#business-iop").css("display","none");
		  // getYahoomap(companyName,_latitude,_longitude,_businessAddress);
            

}



