$(document).ready(function() {

    $('#caseCodeSearch').click(function() {
	// Perform the ajax request to lookup the given case code
	    caseCodeSearch();
		return false;
    });
	
});

function caseCodeSearch() {
	var siteURL = $('#siteURL').val();
	if ($('#caseCodeSearchText').val() != "CASE Code") {
	
		var userName = ($('#userName').val() != "") ? $('#userName').val() : "not logged in";
	    $.get(siteURL + "x308.xml", {
	    
	        CaseCode: $('#caseCodeSearchText').val(),
	        Referer: escape(window.location),
	        User: userName
	    },
	    function(data) {
	        // Empty string == case code not found
	        if (data.length == 0) {
	            alert('Case Code not found');
	        }
	        else {
		
		        // Otherwise, redirect to the page for the given case code
	            window.location = data;
	        }
	    });
	}
    return false;
}
        
