/*the base image directory location*/
var base = "/images/";

// switch an image by changing the src name from 'off' to 'on' and vice versa
function toggleImage(obj) {
	// The image is currently in the OFF state
	if (obj.src.indexOf('_off.') < 0)
	{
		obj.src = obj.src.replace('_on.', '_off.');
	}
	// The image is currently in the ON state
	else
	{
		obj.src = obj.src.replace('_off.', '_on.');
	}
}

// switch an image with an ID
function switchImage(thisId,thisImageSlice) {
	//is the text "_off" inside this btn?
	if (document.getElementById(thisId).src.indexOf('_off.') < 0)
	{
		thisImg=base+thisImageSlice+thisId+'_off.gif';
	}
	else
	{
		thisImg=base+thisImageSlice+thisId+'_on.gif';
	}
	//set the image
	document.getElementById(thisId).src=thisImg;
}

// toggle the text inside a form on/off
function toggleFormText(thisId, thisText) {
	//alert(document.getElementById(thisId).value + ',' + thisText);
	if (document.getElementById(thisId).value == thisText)
	{
		document.getElementById(thisId).value='';
	}
	else if (document.getElementById(thisId).value == '')
	{
		document.getElementById(thisId).value=thisText;
	}
}

/*********
returns true if the phone number is valid, false otherwise
Valid:
(343) 234-3432
2342342342
234-242-2342
*********/
function isPhoneValid(phone_number) {
	valid = true;

	if (thisDOM.value.search(/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/) == -1)
	{
		valid = false;
	}

	return valid;
}

/**** HIGHLIGHTING!!! ****/
function bodyHighlight (imgId, replacer) {
	afterImgId=base+replacer;
	document.getElementById(imgId).src = afterImgId;
}

function showLoginWindow() {
	$('html, body').animate({
		scrollTop: $("body").offset().top }, 500);
	$("#loginOverlay").fadeIn();
}

function showAccountOverlay() {
	$('html, body').animate({
		scrollTop: $("body").offset().top }, 500);
    $("#createAccountOverlay").fadeIn();
}

function showContactOverlay() {
	$('html, body').animate({
		scrollTop: $("#content").offset().top }, 500);
      $("#contactProfileOverlay").fadeIn();
}

function hideContactOverlay() {
    $("#contactProfileOverlay").fadeOut();
}

function AnimateScroll(thisNode) {
	$('html, body').animate({
		scrollTop: $(thisNode).offset().top }, 500);
}

function setGender(gender) {
	thisURL = '/Procedure/SetGender/' + gender;
	$.ajax({
		url: thisURL,
		success: function(data) {
		}
	})
}

// load when document is done
$(document).ready(function(){
	// STANDARD FUNCTION: update a piece of the site with a click
	$(".updateNode").live("click", function(event) {
		event.preventDefault();
		var updateURL = $(this).attr('href');
		var updateNode = $(this).attr('updateNode');
		$.get(updateURL, function(data) {
			$(updateNode).html(data);
		});
	});

	// ADD TO DOCTOR RESULTS FUNCTION: append data to the interior of a node
	$(".appendDoctorResults").live("click", function(event) {
		event.preventDefault();
		var updateURL = $(this).attr('href');
		var updateNode = $(this).attr('updateNode');
		var slideDownNode = '#doctorResults' + $(this).attr('nextUniqueNode');
		var buttonToRemove = '#show10MoreDoctors'+ $(this).attr('thisUniqueNode');
		$.get(updateURL, function(data) {
			$(updateNode).append(data);
			$(slideDownNode).delay(100).slideDown(600);
			$(buttonToRemove).delay(90).remove();
		});
	});

	// STANDARD FUNCTION: SAVE A FORM AND DO NOTHING ELSE
	$(".SaveFormOnly").live('submit', function(event){
		event.preventDefault();
		var id = '#'+$(this).attr('id');
		var postURL = $(this).attr('action');
		// HERE WE CREATE THE CHECKBOX STRING TO BE SERIALIZED
		previousName = ""; // set this to blank
		currentList = "";
		additionalSerializeString = "";
		// find any checkboxes with a unique name and add them to a list
		$("input[type='checkbox']:checked").each(function() {
			// on each loop through, check if the previousname = thisName... if it does then we add it to it's own array
			thisName = $(this).attr('name');
			if (previousName === thisName && previousName != "") {
				currentList = $(this).val() + "," + currentList
			}
			// this is a new list, let's add it to additionalSerializeString (but not the first pass thru)
			else if (previousName.length > 0){
				additionalSerializeString = additionalSerializeString + "&" + thisName + "=" + currentList;
				currentList = $(this).val();
			}
			// first time through the list
			else {
				currentList = $(this).val();
			}
			previousName = thisName;
		});
		// if there is a currentList on the last loop through still, let's add it to additionalSerializeString
		if (currentList.length > 0) {
			additionalSerializeString = additionalSerializeString + "&" + thisName + "=" + currentList;
		}
		
		$.post(
			postURL,
			$(id).serialize() + additionalSerializeString,
			function(data){
		});
	});

	// STANDARD FUNCTION: SAVE A FORM AND UPDATE A NODE
	$(".SaveFormUpdateNode").live('submit', function(event){
		event.preventDefault();
		var id = '#'+$('.SaveFormUpdateNode').attr('id');
		var postURL = $('.SaveFormUpdateNode').attr('action');
		var updateNode = $('.SaveFormUpdateNode').attr('updateNode');
		var redirectURL = $('.SaveFormUpdateNode').attr('redirectURL');
		// HERE WE CREATE THE CHECKBOX STRING TO BE SERIALIZED
		previousName = ""; // set this to blank
		currentList = "";
		additionalSerializeString = "";
		// find any checkboxes with a unique name and add them to a list
		$("input[type='checkbox']:checked").each(function() {
			// on each loop through, check if the previousname = thisName... if it does then we add it to it's own array
			thisName = $(this).attr('name');
			if (previousName === thisName && previousName != "") {
				currentList = $(this).val() + "," + currentList
			}
			// this is a new list, let's add it to additionalSerializeString (but not the first pass thru)
			else if (previousName.length > 0){
				additionalSerializeString = additionalSerializeString + "&" + thisName + "=" + currentList;
				currentList = $(this).val();
			}
			// first time through the list
			else {
				currentList = $(this).val();
			}
			previousName = thisName;
		});
		// if there is a currentList on the last loop through still, let's add it to additionalSerializeString
		if (currentList.length > 0) {
			additionalSerializeString = additionalSerializeString + "&" + thisName + "=" + currentList;
		}
		
		$.post(
			postURL,
			$(id).serialize() + additionalSerializeString,
			function(data){
				if (data.length > 0) {
					if ($('#FormErrorArea').length > 0) {
						$('#FormErrorArea').html(data);
					}
					else
					{
						$(updateNode).html(data);
					}
				}
				else {
					window.location.href = redirectURL;
				}
		});
	});

	/**** OVERLAY FADE IN / OUT (Login Box)*****/

   //Adjust height of overlay to fill screen when page loads
   $("#loginOverlay").css("height", $(document).height());

   //When the link that triggers the message is clicked fade in overlay/msgbox
   $(".loginLink").live('click', function(event){
		event.preventDefault();
		hideContactOverlay(); // hide the contact box
		showLoginWindow();
   });

   //When the message box is closed, fade out
   $(".loginOverlayClose").live('click', function(event){
		event.preventDefault();
		$("#loginOverlay").fadeOut();
   });

	/**** OVERLAY FADE IN / OUT (Create Account Box)*****/

   //Adjust height of overlay to fill screen when page loads
   $("#createAccountOverlay").css("height", $(document).height());
   //When the link that triggers the message is clicked fade in overlay/msgbox
   $(".createAccountLink").live("click", function(){
		hideContactOverlay(); // hide the contact box
		showAccountOverlay();
		return false;
   });
	//When the message box is closed, fade out
   $(".createAccountClose").live("click", function(){
      $("#createAccountOverlay").fadeOut();
      return false;
   });

	/**** OVERLAY FADE IN / OUT (Contact Doctor / Practice Box)*****/

   //Adjust height of overlay to fill screen when page loads
   $("#contactProfileOverlay").css("height", $("#contentBg").height());
   $("#contactProfileOverlay").css("top", $("#contentBg").position().top);
   //When the link that triggers the message is clicked fade in overlay/msgbox
   $(".contactProfileLink").live('click', function(){
		showContactOverlay();
		$("#patientDetailsOverlay").fadeOut();
		return false;
   });
   //When the message box is closed, fade out
   $(".closeContact").live('click', function(){
		hideContactOverlay();
		return false;
   });

	/**** OVERLAY FADE IN / OUT (Patient Details)*****/

   //Adjust height of overlay to fill screen when page loads
   $("#patientDetailsOverlay").css("top", $("#contentBg").position().top);
   //When the link that triggers the message is clicked fade in overlay/msgbox
   $(".patientDetailsLink").live('click', function(){
		imageId = $(this).attr('imageid');
		tagId = $('#idProcedureTag').val();
		limit = $(this).attr('l');
		limitstart = $(this).attr('ls');
		practiceId = $(this).attr('practiceid');

		// get a list of practice IDs if they exist
		if ($('#practiceIdList').length > 0) {
			practiceIdList = $('#practiceIdList').val();
		}
		else {
			practiceIdList = "0";
		}

		if (!tagId) {
			tagId = $(this).attr('idproceduretag');
		}
		displayType = $(this).attr('displaytype');
		loadURL = "/Practice/GetGalleryImage/" + imageId + "/" + practiceId + "/" + tagId + "/" + displayType + "/" + limit + "/" + limitstart + "/" + practiceIdList + "/" + CreateGalleryFilterString();
		$('#patientDetailsOverlay').load(loadURL, function(data){
			//$("#disclaimerOverlay").fadeIn();
			//$("#disclaimerOverlay").css("top", $("#disclaimer").position().top);
			$("#patientDetailsOverlay").fadeIn();
			$("#patientDetailsOverlay").css("height", $("#contentBg").height());
			AnimateScroll('#patientDetailsOverlay');
		});
		window.location.hash = imageId;
		return false;
   });
   //When the message box is closed, fade out
   $(".closePatientDetails").live('click', function(){
      $("#patientDetailsOverlay").fadeOut();
      //$("#disclaimerOverlay").fadeOut();
      return false;
   });
/*
   $(".patientDetailsContactDoctorLink").click(function(){
   	  $("#patientDetailsOverlay").fadeOut();
   	  $("#disclaimerOverlay").fadeOut();
   	  $("#contactProfileOverlay").fadeIn();
   	  return false;
   });
*/
	/* ANIMATING THE GALLERY IMAGES FOR DOCTORS */
	function setScrollPage() {
		$("#otherSets div#imageScroll").stop(true, true); // .stop is used to make any currently running animation jump to its final state.
		leftValue = $("#otherSets div#imageScroll").css('margin-left');
		leftValue = leftValue.replace('px','');
		return Math.abs(leftValue/453)+1;
	}
	// animate previous images
	$('.previousSet').live('click', function(){
		thisScrollPage = setScrollPage();
		//alert(thisScrollPage);
		if (thisScrollPage != 1) {
			scrollAmount = (thisScrollPage-2) * -453; 
			$("#otherSets div#imageScroll").animate({marginLeft: scrollAmount}, 500);
			//alert(scrollAmount);
		}
		// we're at the left most one, let's load up the previous 12 items
		else {
			splitURL = loadURL.split("/");
			// take the last item in the split (7 in the array -- limitstart) and subtract the 2nd to the last item (6 in the array -- limit) to it
			newLimitStart = parseFloat(splitURL[8]) - parseFloat(splitURL[7]);
			// if the newLimitStart is > 0 AND this is the first scrollable page (#1), let's load the images
			if (newLimitStart >= 0 && thisScrollPage >= 1) {
				loadURL = "/Gallery/GetScrollableImages/" + splitURL[3] + "/" + splitURL[4] + "/" + splitURL[5] + "/" + splitURL[6] + "/" + splitURL[7] + "/" + newLimitStart + "/" + thisScrollPage;
				thisScrollPage = 6; // gotta reset this so we know we're on the last image in the scrollable pages
				$('#imageHolder').load(loadURL, function(data){});
			}
		}
		return false;
	})
	// animate next images
	$('.nextSet').live('click', function(){
		// count the number of pages
		scrollablePages = ($('#imageScroll img').length)/2;
		thisScrollPage = setScrollPage();
		// don't keep scrolling if we're on the last image
		if (thisScrollPage < scrollablePages) {
			scrollAmount = thisScrollPage * -453;
			$("#otherSets div#imageScroll").animate({marginLeft: scrollAmount}, 500);
		}
		// we're at the right most images, load up the next 12
		else {
			splitURL = loadURL.split("/");
			// take the last item in the split (7 in the array -- limitstart) and subtract the 2nd to the last item (6 in the array -- limit) to it
			newLimitStart = parseFloat(splitURL[8]) + parseFloat(splitURL[7]);
			// if the newLimitStart is > 0 AND this is the last scrollable page (#6), let's load the images
			if (newLimitStart > 0 && thisScrollPage == 6) {
				loadURL = "/Gallery/GetScrollableImages/" + splitURL[3] + "/" + splitURL[4] + "/" + splitURL[5] + "/" + splitURL[6] + "/" + splitURL[7] + "/" + newLimitStart + "/" + thisScrollPage;
				thisScrollPage = 1; // gotta reset this so we know we're on the first image in the scrollable pages
				$('#imageHolder').load(loadURL, function(data){});
			}
		}
		return false;	
	})
	/**** OVERLAY FADE IN / OUT (Real Stories)*****/

   //Adjust height of overlay to fill screen when page loads
   $("#realStoriesOverlay").css("height", $(document).height());
   //When the link that triggers the message is clicked fade in overlay/msgbox
   $(".realStoriesContactLink").click(function(){
      $("#realStoriesOverlay").fadeIn();
      return false;
   });
   //When the message box is closed, fade out
   $(".closeRealStories").live('click', function(){
      $("#realStoriesOverlay").fadeOut();
      return false;
   });

	/**** FILTER RESULTS BOX ***/

	$(".filterResults").live('click', function(event) {
		event.preventDefault();
		$("#filterBox").slideToggle();
	});
	$(".updateBox").live('click', function(event) {
		//event.preventDefault();
		//$("#filterBox").slideUp();
	});
	
	/**** GALLERY SHOW BOX ****/

	$(".galleryShowLink").live('click', function(event) {
		event.preventDefault();
		thisURL = $(this).attr('ajaxhref') + '/' + CreateGalleryFilterString();

		$.get(thisURL,
			function(data){
				AnimateScroll('#galleryThumbs');
				$('#galleryThumbs').html(data).delay(100).slideDown(600);
				$("#galleryLanding").delay(110).slideUp();
			});
	});
	$(".galleryHideLink").live('click', function(event) {
		event.preventDefault();
		$('#galleryThumbs').slideUp(600);
		$("#galleryLanding").slideDown();
	})

	/**** DoctorSearch Box ****/
	
	$(".findDoctorLink").live('click', function(event) {
		event.preventDefault();
		$("#subDoctorSearchBox").slideToggle();
	});
	$(".findDoctorLinkSidebar").live('click', function(event) {
		event.preventDefault();
		$("#subDoctorSearchBox").css("margin-top", "12px");
		$("#subDoctorSearchBox").css("margin-left", "-70px");
		$("#subDoctorSearchBox").slideToggle();
	});
	
	$(".findDoctorLinkTop").live('click', function(event) {
		event.preventDefault();
		$("#doctorSearchBox").slideDown("fast");
	});
	$(".doctorSearchBoxClose").live('click', function(event) {
		event.preventDefault();
		$("#doctorSearchBox").slideUp("fast");
		$("#subDoctorSearchBox").slideUp("fast");
		$("#cityStateZipAutocomplete").css('display','none');
	});
	
	/**** AD COLLAPSE / EXPAND ***/

	$("#adTrigger").live('click', function(event) {
		event.preventDefault();
		$("#topAdExpandedBg").slideToggle();
	});
	
	/**** Click for Phone Number Switching ****/

	$(".clickForPhone").click(function(event) {
		$(".clickForPhone").html('<p id="phoneBtnSwitch">310-555-1234</p>');
	});

	// Small Body Chart Switching (Home Page)
	
	$(".tabSwitchSmallFemale").live('click', function(event) {
		event.preventDefault();
		document.getElementById('bodysmallFemale').style.display = 'block';
		document.getElementById('bodysmallMale').style.display = 'none';
		document.getElementById('bodysmallBtnFemale').src = base + 'btn_bodysmall_female_on.gif'
		document.getElementById('bodysmallBtnMale').src = base + 'btn_bodysmall_male_off.gif'
		setGender('f');
	});	
	$(".tabSwitchSmallMale").live('click', function(event) {
		event.preventDefault();
		document.getElementById('bodysmallFemale').style.display = 'none';
		document.getElementById('bodysmallMale').style.display = 'block';
		document.getElementById('bodysmallBtnFemale').src = '/images/btn_bodysmall_female_off.gif'
		document.getElementById('bodysmallBtnMale').src = '/images/btn_bodysmall_male_on.gif'
		setGender('m');
	});
	
	// Large Body Chart Switching (Gallery)
	
	$(".tabSwitchLargeFemale").live('click', function(event) {
		event.preventDefault();
		$('#bodylargeMale').hide();
		$('#bodylargeFemale').show();
		document.getElementById('bodylargeBtnFemale').src = base + 'btn_bodylarge_female_on.gif'
		document.getElementById('bodylargeBtnMale').src = base + 'btn_bodylarge_male_off.gif'
		document.getElementById('bodylargeMenuFemale').style.display = 'block';
		document.getElementById('bodylargeMenuMale').style.display = 'none';			
		setGender('f');
	});
	$(".tabSwitchLargeMale").live('click', function(event) {
		event.preventDefault();
		$('#bodylargeFemale').hide();
		$('#bodylargeMale').show();
		document.getElementById('bodylargeBtnFemale').src = '/images/btn_bodylarge_female_off.gif'
		document.getElementById('bodylargeBtnMale').src = '/images/btn_bodylarge_male_on.gif'
		document.getElementById('bodylargeMenuFemale').style.display = 'none';
		document.getElementById('bodylargeMenuMale').style.display = 'block';	
		setGender('m');
	});

	/**** SELECTIVE SLIDEDOWN FOR PATIENT TESTIMONIALS ****/

	$('.testimonialHdr a').live('click', function(){
		parentDiv = $(this).parents(".patientTestimonial");
		innerDiv = $(parentDiv).find(".testimonialBody");
		$(innerDiv).slideToggle(400);
		return false;
	});
	
	// TRACK A LINK
	$('.TrackLink').live('click', function(event){
		var thisLinkType = $(this).attr('LinkType');
		var thisURL = $(this).attr('href');
		var thisHttpReferer = window.location.pathname;
		var thisPageTitle = $('title').html();
		var thisidProfilePractice = $('#idProfilePractice').val();
		$.post("/Practice/TrackLink", { LinkType: thisLinkType, URL: thisURL, HttpReferer: thisHttpReferer, PageTitle: thisPageTitle, idProfilePractice: thisidProfilePractice},
			function(data){});
	});
	
	//Text Size Up & Down
	var originalFontSize = $('.resizableText').css('font-size');
	//Up
	$('.textSizeUp').live('click', function(){
		var currentFontSize = $('.resizableText').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum + 3;
		$('.resizableText').css('font-size', newFontSize);
	});
	//Down
	$('.textSizeDown').live('click', function(){
		var currentFontSize = $('.resizableText').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum - 3;
		$('.resizableText').css('font-size', newFontSize);
	});		
});

// city results in a drop down
$('#UserAddress').live('keyup',function(event){
	showCityStateZipAutocomplete($(this));
});
$('#UserAddressBox').live('keyup',function(event){
	showCityStateZipAutocomplete($(this));	
});
$('#UserAddressHome').live('keyup',function(event){
	//showCityStateZipAutocomplete($(this));	
});
var timeoutId;
function showCityStateZipAutocomplete(thisElement) {
	if ($(thisElement).val().length > 0) {
		if (timeoutId) { clearTimeout(timeoutId); }
		timeoutId = setTimeout(function(){
			ProcCategory="";
			if ($('#doctorCategoryHome').length > 0) {
				ProcCategory = $('#doctorCategoryHome').val();
			}
			$.post("/Practice/GetLikeCities", {UserAddress: $(thisElement).val(), ProcedureCategory: ProcCategory},
				function(data){
					if (data.length > 0) {
						// update the data
						$('#cityStateZipAutocomplete').html(data);
						// move the results div to where thisElement is
						resultsLeft = $(thisElement).offset().left;
						resultsTop = $(thisElement).offset().top + $(thisElement).height() + parseInt($(thisElement).css('padding-top')) + parseInt($(thisElement).css('padding-bottom'));
						resultsWidth = $(thisElement).width() + parseInt($(thisElement).css('padding-left')) + parseInt($(thisElement).css('padding-right'));
						//alert(resultsLeft + '-' + resultsTop + '-' + resultsWidth);
						$('#cityStateZipAutocomplete').css('left',resultsLeft);
						$('#cityStateZipAutocomplete').css('top',resultsTop);
						$('#cityStateZipAutocomplete').css('width', resultsWidth + 'px');
						$('#cityStateZipAutocomplete').slideDown('fast');
					}
					else {
						// show an error if one was found
						cmsShowError('Error encountered while searching.');
					}
				});
		},750);
	}
	else {
		$('#cityStateZipAutocomplete').slideUp('fast');
	}
}


//Adjust height of overlay to fill screen when browser gets resized
$(window).bind("resize", function(){
   $("#loginOverlay").css("height", $(window).height());
});

//Adjust height of overlay to fill screen when browser gets resized
$(window).bind("resize", function(){
   $("#createAccountOverlay").css("height", $(window).height());
});

//Adjust height of overlay to fill screen when browser gets resized
$(window).bind("resize", function(){
   $("#contactProfileOverlay").css("height", $(window).height());
});

//Adjust height of overlay to fill screen when browser gets resized
$(window).bind("resize", function(){
   $("#realStoriesOverlay").css("height", $(window).height());
});

// check the doctor search
function verifyDoctorSearch(searchLocation) {
	address = '';
	category = '';
	if (searchLocation == 'menu') {
		address = $('#UserAddress').val();
	}
	if (searchLocation == 'sidebar') {
		address = $('#UserAddressBox').val();
	}
	if (searchLocation == 'home') {
		address = $('#UserAddressHome').val();
	}
	
	// check the category
	if ($('#doctorCategoryHome').length > 0) {
		category = $('#doctorCategoryHome').val();
	}
	
	var zipRegex = /^\d{5}([\-]\d{4})?$/;
	var cityStateRegex = /^[\w\s]+\,\s?\w+$/;
	var canadaZipRegex = /^[ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]{1}\d{1}[A-Za-z]{1} ?\-?\d{1}[A-Za-z]{1}\d{1}$/;
	if (!zipRegex.test(address) && !cityStateRegex.test(address) && !canadaZipRegex.test(address)) {
		alert('Please enter either a zip code as 5 digits (ie "90210") or a city and state (ie "Beverly Hills, CA")');
		return false;
	} else {
		//remove the comma, and replace the spaces with dashes
		addressArray = address.split(",");
		// for state/city url
		if (addressArray.length > 1) {
			address = $.trim(addressArray[1]) + '/' + $.trim(addressArray[0]);
		}
		thisURL='/doctors/' + $.trim(address) + '/' + category;
		thisURL = thisURL.replace(/\s/g,'-');
		window.document.location = thisURL;
		return false;
	}
}

SearchFilterURL = "";
thisDistance = "";
thisCategory = "-";
function filterHighlight(thisNode) {
	$(thisNode).parent('li').siblings().children('a').removeClass('searchFilterHighlight');
	$(thisNode).addClass('searchFilterHighlight');
}
function filterSetDistance(distance) {
	thisDistance = distance;
}
function filterSetCategory(category) {
	thisCategory = category;
}
function updateFilterSearch(rootString) {
	SearchFilterURL = rootString + thisCategory.toLowerCase().replace(' ','-');
	if (thisDistance.length > 0) {
		SearchFilterURL = SearchFilterURL + "/0/" + thisDistance;
	}
	window.document.location = SearchFilterURL;
}

function submitGlobalSearch() {
	searchString = $('#searchKeyword').val();
	var validRegext = /\w+.*/;
	if (!validRegext.test(searchString)) {
		alert('Please type something into the search box before searching!');
		return false;
	} else {
		//remove the comma, and replace the spaces with dashes
		thisURL='/' + $.trim(searchString.replace(' ','-'));
		window.document.location = thisURL;
		return false;
	}
}

function updatePracticeImages(idProcedureTag, idProfilePractice) {
	$.post("/Practice/UpdatePracticeImages", { idProcedureTag: idProcedureTag, idProfilePractice: idProfilePractice},
		function(data){
			$('#practiceImageResults').html(data);
			AnimateScroll('#practiceImageResults');
		});
}


function updateDistrictImages(idProcedureTag, idDistrict) {
	$.post("/District/UpdateDistrictImages/" + idProcedureTag + "/" +  idDistrict,{},
		function(data){
			$('#practiceImageResults').html(data);
			AnimateScroll('#practiceImageResults');
		});
	$.post("/District/GetImageCount/" + idProcedureTag + "/" +  idDistrict,{},
		function(data){
			$("#count").html("");
			$("#count").html(data);
		});
}



//Modified  to render correct links for /photos/* and /photo-gallery/*
function showGalleryProcedures(idProcedureIndex, gender, procType,type, limit, limitstart) {
	updateDiv = '#' + gender + 'GalleryProcedures' + idProcedureIndex;
	displayValue = $(updateDiv).css('display');
	if (displayValue === 'none') {
		$.post("/Gallery/GetProcedures", { idProcedureIndex: idProcedureIndex, gender: gender, procType: procType, type:type,limit: limit, limitstart: limitstart},
			function(data){
				$(updateDiv).html(data).delay(100).slideDown(600);
			});
	}
	else {
		$(updateDiv).delay(100).slideUp(600);
	}
}

function getGalleryProcedures(idProcedureIndex, gender, procType,type, limit, limitstart){
	updateDiv = '#' + gender + 'GalleryProcedures' + idProcedureIndex;
	$.post("/Gallery/GetProcedures", { idProcedureIndex: idProcedureIndex, gender: gender, procType: procType, type:type,limit: limit, limitstart: limitstart},
			function(data){
				$(updateDiv).html(data).delay(100).slideDown(600);
			});

}

function CreateGalleryFilterString() {
	if ($('#SubjectGender').length > 0 ) {
		FilterString = $('#SubjectGender').val() + '^' + $('#SubjectAgeStart').val() + '|' + $('#SubjectAgeEnd').val() + '^' + $('#SubjectWeightStart').val() + '|' + $('#SubjectWeightEnd').val() + '^' + $('#SubjectHeightStart').val() + '|' + $('#SubjectHeightEnd').val() + "^" + $('#SubjectRace').val();
		return FilterString;		
	}
	else {
		return "";
	}
}
function FilterGalleryResults(theURL) {
	// set the age, weight, height
	FullURL = theURL + "/" + CreateGalleryFilterString(theURL);
	$('#galleryThumbs').load(FullURL);
}

$(document).ready( function(){	
		var buttons = { previous:$('#lofslidecontent45 .lof-previous') ,
						next:$('#lofslidecontent45 .lof-next') };
						
		$obj = $('#lofslidecontent45').lofJSidernews( { interval : 10000,
												direction		: 'opacitys',	
											 	easing			: 'easeInOutExpo',
												duration		: 1200,
												auto		 	: true,
												maxItemDisplay  : 4,
												navPosition     : 'horizontal', // horizontal
												navigatorHeight : 35,
												navigatorWidth  : 242,
												mainWidth:980,
												buttons			: buttons} );	

});

