var theseTooltips = {
    addTooltips: function() {
        $("div#tooltip").remove();
        $content = "<div id='tooltip'><p>" + $theTitle + "</p></div>";
        $("body").append($content);
        $(document).mousemove(function(e){
            $top = e.pageY + 20;
            $left = e.pageX + 20;
            $('#tooltip').css({top: $top, left: $left});
        }); 
    }
};
var cookieHelp = {
    cookieAlternates: function($list_text) {
        if ($.cookie("school_type") && $list_text == "type") {
            $s = $.cookie("school_type");
        } else if ($list_text == "type") {
            $s = $('#type_list select#type_select').val();
        } else if ($.cookie("prof_type") && $list_text == "profession") {
            $s = $.cookie("prof_type");
            if ($.cookie("spec_type")) {
                $ss = $.cookie("spec_type");
            }
        } else if ($list_text == "profession") {
            $s = $('#program_type_index_select').val();
        }
    }
};
var insertAd = {
  bannerAd: function() {
    //create string for js ads
	var m3_u = (location.protocol=='https:'?'https://ads.studentdoctor.net/sponsortrack/www/delivery/ajs.php':'http://ads.studentdoctor.net/sponsortrack/www/delivery/ajs.php');
    var m3_r = Math.floor(Math.random()*99999999999);  
	$srctext = "<scr"+"ipt type='text/javascript' src='"+m3_u+"?zoneid=91&amp;cb="+m3_r;
	
	if (!document.MAX_used) {
		document.MAX_used = ',';
	}
	if (document.MAX_used != ',') {
	    $srctext += "&amp;exclude=" + document.MAX_used;
	}
	$srctext += "&amp;loc=" + escape(window.location);
	if (document.referrer) {
		$srctext += "&amp;referer=" + escape(document.referrer);
	}
	if (document.context) {
		$srctext += "&context=" + escape(document.context);
	}
	if (document.mmm_fo) {
	    $srctext += "&amp;mmm_fo=1";
	}
	$srctext += "'></scr"+"ipt>";
  }  
};

$(document).ready(function() {
    
    //focus in login input
    $("#focus_on").focus();
	
	//zebra stripe results on admin index pages and school reports pages
	$('ul.list_results').children('li:odd').css('background-color', '#EEE');
	
	//zebra stripe results on school reports pages
	$('#zebra1').children('tbody').children('tr:odd').css('background-color', '#EEE');
	$('#zebra2').children('tbody').children('tr:odd').css('background-color', '#EEE');
	$('#zebra3').children('li:odd').css('background-color', '#EEE');
	$('#zebra4').children('li:odd').css('background-color', '#EEE');	
	
	//zebra stripe results on survey take survey page
	$('#take_survey').children('.questions_in_survey').children('.form_sets:odd').css('background-color', '#EEE');
	$('#take_survey').children('.questions_in_survey').children('.form_sets:odd').css('border', '1px #C6C6C6 solid');
	
	//expand and collapse on admin manage questions pages
	$('ul.question_questions').hide();
	$('ul.question_questions').siblings('h3').addClass('add_button');
	$('ul.question_questions').siblings('h3').addClass('qClosed');
	$('div.question_categories h3')
	 	.filter('.add_button')
		.find('span.question_category_name')
		.before('<span class="expand_button"> + </span><span class="collapse_button"> -- </span>');
	$('div.question_categories h3 span.collapse_button').hide();
	$('div.question_categories h3.add_button').css('cursor', 'pointer');
	$('div.question_categories h3.qClosed').live("click", function() {
		$(this).addClass('qOpen');
		$(this).removeClass('qClosed');
		$(this).siblings('ul.question_questions').show();
		$(this).children('span.expand_button').toggle();
		$(this).children('span.collapse_button').toggle();
		});
	$('div.question_categories h3.qOpen').live("click", function() {
		$(this).addClass('qClosed');
		$(this).removeClass('qOpen');
		$(this).siblings('ul.question_questions').hide();
		$(this).children('span.expand_button').toggle();
		$(this).children('span.collapse_button').toggle();
		});
		
	//edit pick list answer values on create/edit questions pages
	if (($("#question select.question_type").val() == "pick") || ($("#question select.question_type").val() == "multi")) {
		$("#question div.pick_values").show();
	} else {
		$("#question div.pick_values").hide();
	}
	$("#question select.question_type").change(function() {
		if ((this.value == "pick") || (this.value == "multi")) {
			$("#question div.pick_values").show();
		} else {
			$("#question div.pick_values").hide();
		}
	});
	$("#question input.answer_submit").live("click", function() {
		var $sort_me = $("#question input.answer_value").val();		
		if (!$sort_me) {
  			return false;
		}		
		$("#sortable").append("<li><img src='/schools/assets/images/scroll_icon_white.png' alt='sort icon' /><img src='/schools/assets/images/delete_icon_white.png' class='delete_sort' alt='delete icon' />" + $sort_me + "</li>");
		$current_value = $(this).parents().siblings("input.answer_hidden").val();
		if ($(this).parents().siblings("input.answer_hidden").val()) {
			$next_value = $current_value + "|" + $sort_me;
			$(this).parents().siblings("input.answer_hidden").val($next_value);
		} else {
			$(this).parents().siblings("input.answer_hidden").val($sort_me);
		}		
		$("#question input.answer_value").val("");
		return false;			
	});
	$("#sortable").sortable({
		stop: function(event, ui) {
			$answers = new Array();
			$list_items = $("#sortable li");
			jQuery.each($list_items, function() {
				$answers.push($(this).text());
				});
			$(this).parents().siblings("input.answer_hidden").attr("value", $answers.join("|"));
			}
		});
		
	//delete action for pick list on create and edit questions pages
	$('#question img.delete_sort').live("click", function() {
		$del_value = $(this).parents('li').text();
		$(this).parents('li').remove();
		$answers = new Array();
		$list_items = $("#sortable li");
		jQuery.each($list_items, function() {
			if ($(this).text() != $del_value) {
				$answers.push($(this).text());
			}
		});
		$("#question input.answer_hidden").attr("value", $answers.join("|"));
	});
	
	//edit slider max and min answer values on create/edit questions pages
	if ($("#question select.question_type").val() == "slider") {
		$("#question div.scale_values").show();
	} else {
		$("#question div.scale_values").hide();
	}
	$("#question select.question_type").change(function() {
		if (this.value == "slider") {
			$("#question div.scale_values").show();
		} else {
			$("#question div.scale_values").hide();
		}
	});	
	
	//remove slider or pick list html when the other is selected on edit questions page
	$('#question input.submit').click(function () {
		if ($("#question select.question_type").val() == "slider") {
			$("#question div.pick_values").remove();
		} else if ($("#question select.question_type").val() == "pick" || $("#question select.question_type").val() == "multi") {
			$("#question div.scale_values").remove();
		}
		return true;
	});
	
	//add all categories on admin create/edit survey pages	
	$('div.survey_questions').siblings('h3').addClass('add_button');
	$('div.survey_categories h3')
		.filter('.add_button')
		.after('<p class="survey_button">include entire category</p>');
	$('p.survey_button').live('click', function() {
		$(this).siblings('div.survey_questions').show();
		$(this).siblings('div.survey_questions').children('input').attr('checked', 'yes');
		$(this).siblings('h3').children('span.expand_button').hide();
		$(this).siblings('h3').children('span.collapse_button').show();
		});
	
	//expand and collapse on admin create/edit survey pages
	$('div.survey_questions').hide();
	$('div.survey_categories h3')
	 	.filter('.add_button')
		.find('span.survey_category_name')
		.before('<span class="expand_button"> + </span><span class="collapse_button"> -- </span>');
	$('div.survey_categories h3 span.collapse_button').hide();
	$('div.survey_categories h3.add_button').css('cursor', 'pointer');
	$('div.survey_categories h3.add_button').click(function() {
		$(this).siblings('div.survey_questions').toggle();
		$(this).children('span.expand_button').toggle();
		$(this).children('span.collapse_button').toggle();
		});
		
	//expand and collapse categories on school reports pages
	$('body.school_report h3.report_category').siblings('div.question').hide();
	$('body.school_report h3.report_category_if:first').siblings('div.question').show();
	$('body.school_report h3.report_category')
		.find('span.report_category_heading')
		.before('<span class="expand_button"> + </span><span class="collapse_button"> -- </span>');
	$('body.school_report h3.report_category span.collapse_button').hide();
	$('body.school_report h3.report_category_if:first span.expand_button').hide();
	$('body.school_report h3.report_category_if:first span.collapse_button').show();
	$('body.school_report h3.report_category').css('cursor', 'pointer');
	$('body.school_report h3.report_category').click(function() {
		$(this).siblings('div.question').toggle('slow');
		$(this).children('span.expand_button').toggle();
		$(this).children('span.collapse_button').toggle();
		});
		
	//expand and collapse categories on compare reports pages
	$('body.compare_report h3.report_category').siblings('div.question').hide();
	$('body.compare_report h3.report_category')
		.find('span.report_category_heading')
		.before('<span class="expand_button"> + </span><span class="collapse_button"> -- </span>');
	$('body.compare_report h3.report_category span.collapse_button').hide();
	$('body.compare_report h3.report_category').css('cursor', 'pointer');
	$('body.compare_report h3.report_category').click(function() {
		$category_name = $(this).children('span.report_category_heading').text();
		$('body.compare_report  span:contains(' + $category_name + ')').parents('h3.report_category').siblings('div.question').toggle('slow');
		$('span:contains(' + $category_name + ')').siblings('span.expand_button').toggle();
		$('span:contains(' + $category_name + ')').siblings('span.collapse_button').toggle();
		});
		
	//expand and collapse comment questions on school reports pages
	$comment_div = $('body.school_report div.question_response_comment').siblings('div.question_response:has(:not("p.no_responses"))');
	$comment_div.hide();
	$comment_div.siblings('div.question_response_comment').find('span.question_response_comment_heading')
    	.after('<span class="expand_button"> show comments </span><span class="collapse_button"> hide comments </span>');
    $comment_div.siblings('div.question_response_comment').children('span.collapse_button').hide();
    $comment_div.siblings('div.question_response_comment').css('cursor', 'pointer');
	$comment_div.siblings('div.question_response_comment').click(function() {
    	$(this).siblings('div.question_response').toggle('slow');
    	$(this).children('span.expand_button').toggle();
    	$(this).children('span.collapse_button').toggle();
    });
    
    //expand and collapse categories on flag details pages
	$('body.admin_flags h3.report_category').siblings('div.question').hide();
	$('body.admin_flags div.flagged_response').siblings('div.question').show();
	$('body.admin_flags div.flagged_response').show();
	$('body.admin_flags h3.report_category')
		.find('span.report_category_heading')
		.before('<span class="expand_button"> + </span><span class="collapse_button"> -- </span>');
	$('body.admin_flags h3.report_category span.collapse_button').hide();
	$('body.admin_flags div.flagged_response').siblings('h3.report_category').children('span.expand_button').hide();
	$('body.admin_flags div.flagged_response').siblings('h3.report_category').children('span.collapse_button').show();
	$('body.admin_flags h3.report_category').css('cursor', 'pointer');
	$('body.admin_flags h3.report_category').click(function() {
		$(this).siblings('div.question').toggle('slow');
		$(this).children('span.expand_button').toggle();
		$(this).children('span.collapse_button').toggle();
		});

	//create sliders on survey take survey page
	$('#take_survey').children('.questions_in_survey').children('.form_sets').children('div.slider').empty();
	$('#take_survey').children('.questions_in_survey').children('.form_sets').children('p.slider_high').show();
	$('#take_survey').children('.questions_in_survey').children('.form_sets').children('p.slider_low').show();
	$('#take_survey').children('.questions_in_survey').children('.form_sets').children('p.amount').show();
	$('#take_survey').children('.questions_in_survey').children('.form_sets').children('div.slider').each(function() {
		$(this).slider({value: $(this).siblings('p.amount').text(), min: 0, max: 10, step: 1, range: 'min', slide: function (event, ui) {
			$(this).siblings('p.amount').text(ui.value);
			$(this).siblings('input.slider_hidden').val(ui.value);
			}});
		});

	//create confirm boxes for all links out of survey page
	$('body.survey_survey').find('a').not('.ui-slider-handle').click(function() {
		$confirm_leave = confirm('Have you saved your work before leaving the page?');
		if ($confirm_leave != true) {
			return false;
		}
	});
		
	//have notices fade out
	$('p.notice_plain').addClass('notice').removeClass('notice_plain');
	$('p.notice').fadeOut(6000);
	
	//combine survey type and survey school dropdowns into one page
	$("#type_survey input.submit_hide").remove();
	$('#type_survey').attr('action', '/schools/survey/survey_response');
	$p = new Array();
	$p = $("input[name='application_id']").val();	
//	$('#type_survey #type_select').siblings("input[name='application_id']").after("<div class='inserted' />");
	$("#type_survey select#type_select").change(function() {
		$q = this.value;
	    $(this).siblings('div.inserted').load("/schools/survey/school #insert_into", {'application_id':$p, 'type':$q});
	});	
	
	//cookies for combined pages
	var $list_text = "";
	var $ss = "";
	if ($('.content form').attr("id") == "type_list") {
	    $lists = $("#type_list");
	    $lists.attr('action', '/schools/schools/compare_check');
	    $list_text = "type";
	    typeLists.typeArrays();
	    $lists.children("input.submit_hide").remove();	
	    $lists.children('select').after("<div class='inserted' />");
	}
	if ($('.content form').attr("id") == "program_type_index") {
	    $list_text = "profession";
	}
    if (document.location.search) {
	    $browser_search = document.location.search;
	    $search_terms = $browser_search.slice(1);
	    $all_search_terms = $search_terms.split("&");
	    $search_split = new Array(2);
	    if ($all_search_terms.length > 1) {
	        for (var i in $all_search_terms) {
	            $search_split[i] = $all_search_terms[i].split("=");
	        }
	    } else {
	        $search_split[0] = $search_terms.split("=");
	    }
	    if ($search_split[0][0] == "view") {
	        $s = 0;
	        for(var i in $school_array) {
	            if ($search_split[0][1] == $school_array[i]) {
	                $s = i;
	                $.cookie("school_type", $s);
	            }
	        }
	        if ($s == 0) {
	            cookieHelp.cookieAlternates($list_text);
	        }  
    	} else if ($search_split[0][0] == "prof") {
    	    $.cookie("prof_type", $search_split[0][1]);
    	    $s = $search_split[0][1];
    	    if ($search_split[1]) {
    	        $.cookie("spec_type", $search_split[1][1]);
    	        if (isNaN($search_split[1][1])) {
    	            typeLists.specArrays();
    	            for (var i in $spec_array) {
    	                if ($search_split[1][1] == $spec_array[i]) {
    	                    $ss = i;
    	                    $.cookie("spec_type", $search_split[1][1]);
    	                }
    	            }
    	        } else {
    	            $ss = $search_split[1][1];
    	        }
    	    } else {
    	       cookieHelp.cookieAlternates($list_text); 
    	    }   	    
    	} else {
    	    cookieHelp.cookieAlternates($list_text);
    	}
	} else {
	    cookieHelp.cookieAlternates($list_text);
	}
	if ($list_text == "type") { 
        $lists.children('select#type_select').val($s);
        $('div.inserted').load("/schools/schools/type_list #insert_into", {'type':$s}, function() {});
    }
    if ($list_text == "profession") {
        $('#program_type_index_select').val($s);
    }   
	$("#type_list select#type_select").change(function() {
		$r = this.value;
		$.cookie("school_type", $r);
		for(var i in $school_array) {
	        if ($r == i) {
	            $t = $school_array[i];
	        }
	    }
		$url = document.location.protocol + "//" + document.location.hostname + "/schools/?view=" + $t;
		window.location = $url;
    });
    $('#program_type_index_select').change(function() {
		$r = this.value;
		$.cookie("prof_type", $r);
		$url = document.location.protocol + "//" + document.location.hostname + "/schools/programs?prof=" + $r;
		window.location = $url;
    });
    $('#program_type_specialty_select').live("change", function() {
        $r = $("#program_type_index_select").val();
        $rr = this.value;
        $.cookie("prof_type", $r);
        if (isNaN($rr)) {
           typeLists.specArrays();
           for (var i in $spec_array) {
               if ($rr == i) {
                   $.cookie("spec_type", $spec_array[i]);
                   $rr = $spec_array[i];
               }
           }
        } else {
            $.cookie("spec_type", $rr);
        }
		$url = document.location.protocol + "//" + document.location.hostname + "/schools/programs?prof=" + $r + "&spec=" + $rr;
		window.location = $url;
    });
	
	//combine program type into above dropdowns on new surveys
    $("#type_survey select#survey_specialty").live("change", function() {
        $("div.inserted_two").remove();
        $h = this.value;
        $j = $("input[name='program_type_id']").val();
        $k = $("input[name='survey_id']").val();
        $('div.inserted').after("<div class='inserted_two' />");
        $('div.inserted_two').load("/schools/survey/program #insert_into_two", {'application_id':$p, 'program_type_id':$j, 'survey_id':$k, 'specialty':$h}); 
    });
	
	//combine program type, specialty dropdowns, and results into one page
	$("#program_type_index input.submit_hide").remove();
    $("#program_type_index").attr("action", "/schools/programs/type_list");
    $("#program_type_index_select").after("<div class='inserted_a' />");
    $("#program_type_index").after("<div class='inserted_b' />");
    $q = $("#program_type_index select#program_type_index_select").val();
    $("#program_type_index_select").siblings("div.inserted_a").load("/schools/programs/specialty #insert_into_a", {"program_type":$q}, function() {
        //read from cookies
        if ($list_text == "profession") {
            $('#program_type_index_select').val($s);
            if ($ss) {
                $('#program_type_specialty_select').val($ss);
                $v = $ss;
            } else {
                if ($.cookie("spec_type")) {
                    $ss = $.cookie("spec_type");
                    if (isNaN($ss)) {
                        typeLists.specArrays(); 
                        for (i in $spec_array) {
                            if ($ss == $spec_array[i]) {
                                $ss = i;
                            }
                        }
                    }
                    $('#program_type_specialty_select').val($ss);
                    $v = $ss;
                } else {
                    $v = $("#program_specialty_default").attr("value");
                }
            }
        }               
        $z = $("#dual_types").val();
        //continue with results load
        $("div.inserted_b").load("/schools/programs/type_list #insert_into_b", {"specialty":$v, "dual_types":$z}, function() {
            //sort table on programs type_list page
	        $("#zebra1.sortTable").tablesorter({
	           headers: {
	               5: { sorter: false }
	           },
	           sortList: [[0,0]]
	        });
	        $("#zebra1.sortFullTable").tablesorter({
	            headers: {
	                6: { sorter: false }
	            },
	           sortList: [[0,0]]
	        });
        });
    });
    $("#program_type_index select#program_type_index_select").change(function() {
        $("div#insert_into_b").remove();
        $r = this.value;
        $(this).siblings("div.inserted_a").load("/schools/programs/specialty #insert_into_a", {"program_type":$r}, function() {
            $u = $("#program_specialty_default").val();
            $z = $("#dual_types").val();
            $("div.inserted_b").load("/schools/programs/type_list #insert_into_b", {"specialty":$u, "dual_types":$z}, function() {
                //sort table on programs type_list page
	            $("#zebra1.sortTable").tablesorter({
	                headers: {
	                    5: { sorter: false }
	                },
	                sortList: [[0,0]]
	            });
	            $("#zebra1.sortFullTable").tablesorter({
	                headers: {
	                    6: { sorter: false }
	                },
	                sortList: [[0,0]]
	            });
            });
        });

    });
    $("select#program_type_specialty_select").live("change", function() {
        $t = this.value;
        $z = $("#dual_types").val();
        $("div.inserted_b").load("/schools/programs/type_list #insert_into_b", {"specialty":$t, "dual_types":$z}, function() {
            //sort table on programs type_list page
	        $("#zebra1.sortTable").tablesorter({
	            headers: {
	                5: { sorter: false }
	            },
	            sortList: [[0,0]] 
	        });
	        $("#zebra1.sortFullTable").tablesorter({
	            headers: {
	                6: { sorter: false }
	            },
	            sortList: [[0,0]]
            });
        }); 
    });
    
    //combine program type and specialty into one page in admin programs create
	$('#program_listing').attr('action', '/schools/admin/programs/finish_listing');
	$("#program_listing select[name='type_id']").parents("div.form_sets").after("<div class='inserted' />");
	$("#program_listing select[name='type_id']").live("change", function() {
	    $a = $("#program_listing select[name='location']").val();
	    $b = $("#program_listing select[name='identifying_org']").val();
	    $c = $("#program_listing input[name='identifying_number']").val();
		$q = this.value;
	    $(this).parents("div.form_sets").siblings('div.inserted').load("/schools/admin/programs/listing_specialty #insert_into", {'type_id':$q, 'location':$a, 'identifying_org':$b, 'identifying_number':$c});
	});
		
    //combine program type and specialty into one page in admin programs edit
	$('#program_edit').attr('action', '/schools/admin/programs/finish_edit');
	$("#program_edit select[name='program_type']").parents("div.form_sets").after("<div class='inserted_2' />").after("<div class='inserted' />");
	$edit_program_id = $("#program_edit input[name='program_id']").val();
	$edit_program_type = $("#program_edit select[name='program_type']").val();
	$("#program_edit").children("div.inserted").load("/schools/admin/programs/edit_specialty #insert_into", {'program_type':$edit_program_type, 'program_id':$edit_program_id}, function() {
	    $edit_program_specialty = $("#program_edit select[name='specialty_id']").val();
	    $("div.inserted_2").load("/schools/admin/programs/edit_info #insert_into_2", {'program_id':$edit_program_id, 'specialty_id':$edit_program_specialty});
	});
	$("#program_edit select[name='program_type']").live("change", function() {
		$q = this.value;
	    $(this).parents("div.form_sets").siblings('div.inserted').load("/schools/admin/programs/edit_specialty #insert_into", {'program_type':$q, 'program_id':$edit_program_id}, function() {
	        $edit_program_specialty = $("#program_edit select[name='specialty_id']").val();
	        $("div.inserted_2").load("/schools/admin/programs/edit_info #insert_into_2", {'program_id':$edit_program_id, 'specialty_id':$edit_program_specialty});	        
	    });
	});	

		
	//confirm box for school deactivate
	$("body.school_admin a.deactivate_me").click(function() {
	    if (confirm("Are you sure? Existing data will be kept, but there is no option to reactivate this school.")) {
	        return true;
	    } else {
	        return false;
	    };
	});
	
	//modal for report this form
	$('a.report_inline, a.report_all').live("click", function() {
	   $report_url = $(this).attr("href") + " #modal";
	   $dialog = $('<div></div>')
	       .load($report_url)
		   .dialog({
		       autoOpen: false,
		       title: "Report content",
			   width: 600,
			   modal: true
		   }); 
        $dialog.dialog('open');
        return false;
	});
	$('a.modal_cancel').live("click", function() {
	    $dialog.dialog("close");
        $("#modal").remove();
	    return false;
	});
	$("#modal input.submit").live("click", function() {  
	    $url = document.location.protocol + "//" + document.location.hostname + $("#report_this_modal").attr("action");
	    $.ajax({
	      url: $url, 
	      type: 'POST',
          data: $("#report_this_modal").serialize(),  
            complete: function() {
                //called when complete
            },
            success: function() {  
                $('div.content h1').after("<p class='notice'>Report has been added.</p>");
                $('p.notice').css('position', 'fixed').fadeOut(6000);
                $("#modal").remove();
            },
            error: function() {
                alert("Error creating report");
            }
        });	
        $dialog.dialog("close");
	    return false;         
	});
	
	//modal for hotel display page
	$('a.in_line_hotel').live("click", function() {
	   $hotel_url = $(this).attr("href") + " #modal";
	   $dialog = $('<div></div>')
	       .load($hotel_url, function() {
	           $("#modal a.remove_for_modal").remove();
	       })
		   .dialog({
		       autoOpen: false,
		       title: "Hotel Details",
			   width: 600,
			   modal: true
		   }); 
        $dialog.dialog("open");
        return false;
	});
	
	//load tooltips
    $(".ttp").live("mouseenter", function() {
	    $theTitle = $(this).attr("aTitle");
	    theseTooltips.addTooltips($theTitle); 
	}).live("mouseleave", function() {
	    $("div#tooltip").remove();	    
	});
	
	//load datepicker
	$("body.survey_survey .question_date, body.admin_dates .question_date").datepicker({ changeYear: true, changeMonth: true });
	
	//load predictive text option for hotel field in survey
	$("#hotel_input").live("keyup", function() {
	    $like = $(this).val();
        $school_id = $('#school_id').val();
        $program_location_id = $('#program_location_id').val();
        if ($school_id > 0) {
            $hotel_type_id = $school_id;
            $hotel_type = "school_id";
        } else if ($program_location_id > 0) {
            $hotel_type_id = $program_location_id;
            $hotel_type = "program_location_id";
        }
	    $.ajax({
	        url: document.location.protocol + "//" + document.location.hostname + '/schools/admin/hotels/listing/' + $hotel_type_id + "/" + $like + "/" + $hotel_type,
	        datatype: 'json',  
            complete: function() {
            },
            success: function(resp) {
//                alert(resp);
                $add_options = "";
                $("div.hidden_options").remove();
                $all_hotels = jQuery.parseJSON(resp);
                $add_options = "<div class='hidden_options'><ul>";
                for(var key in $all_hotels) {
                    $add_options += "<li class='hotel_id'><a href='' id='hotel_id_" + key + "'>" + $all_hotels[key] + "</a></li>";
                }
                $add_options += "</ul></div>";
                $("#hotel_input").after($add_options);
                $(".hidden_options").parents().addClass("ie_css_fix");
            },
            error: function() {
            }
        });	   
	});
	
	//handle behavior of links in hotels predictive text
	$("li.hotel_id").live("click", function() {
	    $id_string = $(this).children("a").attr("id").slice(9);
	    $name_string = $(this).children("a").html();
	    $("input.temp_hotel_id").remove();
        $("#school_id").before("<input type='hidden' class='temp_hotel_id' name='hotel_id' value='" + $id_string + "' />");
        $("#hotel_input").val($name_string);
        $("div.hidden_options").remove();
	    return false;	    
	});
	
	
});

