//this script is usefull for various pages

jQuery(document).ready(function() {
		  jQuery('#menu-item-35 ul:first,#menu-item-817 ul:first,#menu-item-816 ul:first, #menu-item-1726 ul:first, #menu-item-1731 ul:first').wrap('<div class="flyOutNav wider" /> ');
		  jQuery('#menu-item-35 ul:first, #menu-item-817 ul:first, #menu-item-816 ul:first, #menu-item-1726 ul:first, #menu-item-1731 ul:first').wrap('<div class="innerFlyOut" /> ');
		  jQuery('.tN ul ul').wrap('  <div class="tertiary clearfix" /> ');		
		  jQuery('#menu-item-35 ul:first, #menu-item-817 ul:first, #menu-item-816 ul:first, #menu-item-1726 ul:first, #menu-item-1731 ul:first').addClass('secondary');
		  
		 jQuery("#s").blur(function(){  
		        if(!jQuery(this).val()) jQuery(this).val("Enter search keyword here");  
		    });  
		    jQuery("#s").focus(function(){  
		        if(jQuery(this).val() == "Enter search keyword here") jQuery(this).val("");  
		    });  
		  
		   });


 function CheckSearch(){
 	 var s = jQuery('#s').val();
 	  s=jQuery.trim(s);
 	  if(s=='0' || s=='' || s=='Enter search keyword here'){
        alert("Please enter a keyword to search");
        jQuery('#s').focus();
        return false;
    }
 }

//to validate appointment form
function validateAppointment(frm){
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var fname = jQuery('#fname').val();
    var adate = jQuery('#adate').val();
    var email = jQuery('#email').val();
    var city = jQuery('#city').val();
    var state = jQuery('#state').val();
    var country = jQuery('#country').val();
    var procedure = jQuery('#procedure').val();
    var mobile_number = jQuery('#mobile_number').val();
    fname=jQuery.trim(fname);
    city=jQuery.trim(city);
	
    email=jQuery.trim(email);
    mobile_number=jQuery.trim(mobile_number);
    if(fname=='0' || fname==''){
        alert("Please enter name");
        jQuery('#fname').focus();
        return false;
    }
    
	
    if(email=='0' || email==''){
        alert("Please enter email");
        jQuery('#email').focus();
        return false;
    }
	
    if(reg.test(email) == false) {
        alert('Please enter valid email');
        jQuery('#email').focus();
        return false;
    }
	if(mobile_number!=''){
    if(isNaN(mobile_number) || mobile_number.length < 10){
        alert("Please enter valid phone number");
        jQuery('#mobile_number').focus();
        return false;
    }
    }
	
	
    if(city=='0' || city==''){
        alert("Please enter city");
        jQuery('#city').focus();
        return false;
    }
    if(country=='0' || country==''){
        alert("Please select country");
        jQuery('#country').focus();
        return false;
    }
    if(procedure=='0' || procedure==''){
        alert("Please select speciality");
        jQuery('#procedure').focus();
        return false;
    }
    if(adate=='0' || adate==''){
        alert("Please select appointment date");
        jQuery('#adate').focus();
        return false;
    }
   
}
function validateEquiry(){

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var fname = jQuery('#ename').val();
    var email = jQuery('#emailadd').val();
    var country = jQuery('#ecountry').val();
    var procedure = jQuery('#desease').val();
    var mobile_number = jQuery('#phone').val();
    fname=jQuery.trim(fname);
    email=jQuery.trim(email);
    mobile_number=jQuery.trim(mobile_number);
    if(fname=='0' || fname==''){
        alert("Please enter name");
        jQuery('#ename').focus();
        return false;
    }
    if(mobile_number=='0' || mobile_number==''){
        alert("Please enter phone");
        jQuery('#phone').focus();
        return false;
    }
    if(isNaN(mobile_number)){
        alert("Please enter valid phone");
        jQuery('#phone').focus();
        return false;
    }
    if(email=='0' || email==''){
        alert("Please enter email");
        jQuery('#email').focus();
        return false;
    }
	
    if(reg.test(email) == false) {
        alert('Please enter valid email');
        jQuery('#ename').focus();
        return false;
    }
	
    if(country=='0' || country==''){
        alert("Please select country");
        jQuery('#ecountry').focus();
        return false;
    }
    jQuery('#message').html('');
    jQuery("#loading1").show();
	
    var equirtyformdata = jQuery('#equirtyform').serialize();
    jQuery.ajax({
        url:SITE_URL+'insert_data.php',
        data:equirtyformdata,
        type:"POST",
        dataType:"json",
        success:
        function(result){
            if(result.status ==1){
                parent.document.equirtyform.reset();
                jQuery("#loading1").hide();
                jQuery("#get_connected2").hide('slow');
                jQuery("#enquiry").attr("title","show")
                jQuery('#message').html('Thank you for contacting us');
            }
        }
    });//ajax
    	
    return false;
}
//used for find a doctor
jQuery(document).ready(function() {
	jQuery('.center_dep').click(function() {
   
		var selid = jQuery(this).attr('rel');	
		if(selid!=0){
			var center_val =jQuery(this).html();
			jQuery('.center_dep').hide();		  
		   jQuery('.center_show').show();
		   jQuery('.center_selected').html(center_val);
		   jQuery('#hspeciality').val(selid);
		   
	    }
	     currentPage=1;
		   jQuery('#rec_no').val('0');
		   jQuery('#series').val('0');
		    getDoctorslist();
	});
	jQuery('.center_show').click(function() {
		jQuery('.center_dep').show();
		jQuery('.center_show').hide();
		jQuery('.center_selected').html('');	
		 var center_val =jQuery(this).html();  
		  currentPage=1;
		 jQuery('#hspeciality').val('0');
		 jQuery('#series').val('0');
		 jQuery('#rec_no').val('0');	
	    getDoctorslist()
	});
	
	//location
	jQuery('.location').live('click',function() {
	   var selid = jQuery(this).attr('rel');	
	   jQuery('.location').hide();		
	   var location_val =jQuery(this).html();
	   jQuery('.location_show').show();
	   jQuery('.location_selected').html(location_val);
	   jQuery('#hlocation').val(selid);
	   jQuery('#series').val('0'); 
	   jQuery('#rec_no').val('0');
	    currentPage=1;
	   getDoctorslist()
	});
	jQuery('.location_show').live('click',function() {
		jQuery('.location').show();
		jQuery('.location_show').hide();
		jQuery('.location_selected').html('');	
		 currentPage=1;
		 var location_val =jQuery(this).html(); 
		 jQuery('#hlocation').val('0'); 
		 jQuery('#series').val('0');
		 jQuery('#rec_no').val('0'); 	
	    getDoctorslist()
	});
	
	//gender
	jQuery('.gender').click(function() {
	 currentPage=1;
		var selid = jQuery(this).attr('rel');
		
	   jQuery('.gender').hide();		
	   var gender_val =jQuery(this).html();
	   jQuery('.gender_show').show();
	   jQuery('.gender_selected').html(gender_val);
	   jQuery('#series').val('0');
	   jQuery('#hgender').val(selid);
	    
	    getDoctorslist()
	});
	//series
	jQuery('.series a').live('click',function() {
	   var series_val =jQuery(this).html();
	   jQuery(this).addClass('active');
	   if(series_val =='ALL')
	   	series_val=0;
	   jQuery('#series').val(series_val);
	    
	    getDoctorslist()
	});
	jQuery('.gender_show').click(function() {
		 currentPage=1;
		jQuery('.gender').show();
		jQuery('.gender_show').hide();
		jQuery('.gender_selected').html('');	
		 var gender_val =jQuery(this).html(); 
		 jQuery('#hgender').val('0');
		 jQuery('#rec_no').val('0'); 	
	    getDoctorslist()
	});
});
function getDoctorslist(){
   //  jQuery(".doctorslist_show").hide();
    jQuery("#loading_search").show();
     var searchcriteria = jQuery('#doctorssearch').serialize();
	jQuery.ajax({
		url:SITE_URL+'ajax_data.php',
		type: "post",
		data: searchcriteria,
		success: function(xml) {
			jQuery(".doctorslist_show").show();
			jQuery("#loading_search").hide();
			
			totalListings = parseInt(jQuery(xml).find('listing_summary')[0].getAttribute("num_records"));
			if(totalListings==0 && hasFeatureListing)
				totalListings = 1;
			showPageNav(totalListings,parseInt(jQuery(xml).find('listing_summary')[0].getAttribute("rec_no")));
			
			//LOCATION
			if(jQuery('#hlocation').val()=='' || jQuery('#hlocation').val()==0){
				locations = jQuery(xml).find("location");
				var listloc='';
				listloc += '<li rel="0" class="location"><a href="#">All</a></li>';
				for (var i = 0; i < locations.length; i++) {
					var loc_rec= locations[i].firstChild.data.split("\t");
					listloc += '<li class="location" rel="'+ loc_rec[0] +'"><a href="#" >'+ loc_rec[1] +'</a></li>';
				}
				listloc += '<li><strong class="location_selected"></strong></li>';
	            listloc += '<li class="location_show" style="display:none;"><a href="#">Show All</a></li>';
				jQuery('#loc').html(listloc);
			}
			
			//series
			if(jQuery('#series').val()==0){
			var cusseries = jQuery(xml).find("series")[0].firstChild.data.split("\t");;
			var alphaList ='<li><a href="#" class="active alpha_select">ALL</a></li>';
			for (var k = 0; k < cusseries.length; k++) {
				var srpart = cusseries[k].split("|");
				if(parseInt(srpart[1]))
				alphaList +='<li><a class="active" href="#">'+ srpart[0] +'</a></li>';
				else
				alphaList +='<li>'+ srpart[0] +'</li>';
			}
				jQuery('.series').html(alphaList);
			}
			jQuery('#total').html(totalListings);
			//console.log(cusseries);
			
			
			listings = jQuery(xml).find("listing");
			var cur_listing_source = jQuery(xml).find("listing_source")[0].firstChild.data
			
			if(listing_source != cur_listing_source && cur_listing_source !="--") {
				listing_source = cur_listing_source;				
			}
			
			
			if(listings.length>0 || hasFeatureListing) {
				var listing_content= '';
				var listingIndex =0;
				if(currentPage==1) {
					if(hasFeatureListing) {
						var uniquePropertyWithQuote = '';
						if(uniqueProperty != '')
							uniquePropertyWithQuote = '"' + uniqueProperty + '"';
						
						listing_content = '<div style="background-color:#EFEFF4; width:914px; color:#000000;font-weight:bold;padding:3px;text-align:left;">&nbsp;&nbsp;Featured '+uniquePropertyWithQuote+' Property</div>';

						listingArray[listingIndex].copy_data(featureListing);
						listingRow = genListingRow(listingIndex,listingArray[listingIndex]);
						listing_content += listingRow;
						listingIndex++;
												
						if(uniqueProperty != '') {
							var keyword = document.searchform.keyword[document.searchform.keyword.selectedIndex].value;
							if(listings.length>0) {
								if(uniqueProperty == keyword) {
									if(listings.length>1)
										listing_content += '<div style="background-color:#EFEFF4; width:744px; color:#000000;font-weight:bold;padding:3px;text-align:left;">&nbsp;&nbsp;More result on "'+keyword+'" Properties</div>';
								} else {
									listing_content += '<div style="background-color:#EFEFF4; width:744px; color:#000000;font-weight:bold;padding:3px;text-align:left;">&nbsp;&nbsp;Search result on "'+keyword+'" Properties</div>';
								}

							} else {
								listing_content += '<div style="background-color:#EFEFF4; width:744px; color:#000000;font-weight:bold;padding:3px;text-align:left;">&nbsp;&nbsp;No listing found for "'+keyword+'" Properties</div>';
							}
						} else {
							if(listings.length>0) {
								listing_content += '<div style="background-color:#EFEFF4; width:744px; color:#000000;font-weight:bold;padding:3px;text-align:left;">&nbsp;&nbsp;Search result from your search criteria above</div>';

							} else {
								listing_content += '<div style="background-color:#EFEFF4; width:744px; color:#000000;font-weight:bold;padding:3px;text-align:left;">&nbsp;&nbsp;No listing found from your search criteria</div>';
							}
						}
					}
				}

				for (var i = 0; i < listings.length; i++) {
					var list_rec= listings[i].firstChild.data.split("\t");
					if(hasFeatureListing) {
						if(featureListing.agent_id==list_rec[2] && featureListing.property_id==list_rec[1])
							continue;
					}
					listingArray[listingIndex].docid = list_rec[0];
					listingArray[listingIndex].docname = list_rec[1];
					listingArray[listingIndex].designation = list_rec[2];
					listingArray[listingIndex].speciality = list_rec[3];
					listingArray[listingIndex].qualification = list_rec[4];
					listingArray[listingIndex].description = list_rec[5];
					listingArray[listingIndex].photo = list_rec[6];
					listingArray[listingIndex].hospitals = list_rec[7];
					listingArray[listingIndex].gender = list_rec[8];
					listingArray[listingIndex].email = list_rec[9];
					listingArray[listingIndex].document = list_rec[10];
					//console.log(listingArray);
							
					listingRow = genListingRow(listingIndex,listingArray[listingIndex]);
					listing_content += listingRow;
					listingIndex++;
				}
				totalListingsCurPage = listingIndex;
				document.getElementById("listing_content").innerHTML = listing_content;
				showFeatureListing();
			} else {
					getStyleObject('top_listing_header').visibility = 'hidden';
					getStyleObject('listing_header').visibility = 'hidden';
					getStyleObject('page_nav_bot').visibility = 'hidden';
					getStyleObject('page_nav_top').visibility = 'hidden';
					document.getElementById("listing_content").innerHTML =
						'<table><tr><td class="blktxtbld11" style="text-align:left;">'+
						'<br/><br/>No Doctors found. Please change your criteria.</b><br/><br/><br/>'+
						'<br><br><br>'+
						'</td></tr></table>';
				}
			isNewSearch = false;
				}		
				
		});
	
    	
    return false;
}

function slideSwitch() {
    var $active = jQuery('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = jQuery( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.css({opacity: 0.0});
            $active.removeClass('active last-active');
        });
}

jQuery(function() {
   setInterval( "slideSwitch()", 5000 );
   setInterval( "slideSwitch2()", 5000 );
   jQuery('.active').live('click',function(){
   	jQuery('.active').removeClass('alpha_select');
   	jQuery(this).addClass('alpha_select');
   });
   
   jQuery('.alpha_select').live('click',function(e){
	   /* commented by cva to enable click function for active elements */
   		//e.preventDefault();   
   });
});

function slideSwitch2() {
    var $active = jQuery('#slideshow2 div.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow2 div:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow2 div:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = jQuery( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.css({opacity: 0.0});
            $active.removeClass('active last-active');
        });
}

