function getparam( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function isEODBrowser() {
	var client = getparam("client");
	if (client === "eodbrowser") {
		return true;
	} else {
		return false;
	}
}

function eodBrowserSetup() {
	$("#default-subheader").hide();
	//$(".default-project-actions").hide();
	setupDefaultActions();
	
	
	$("div[projects] img").hover(function() {
		$(this).css("cursor", "pointer");
	});
	
	$("div[projects] img").click(function() { 
		var projectsString = $(this).parents("div[projects]").attr('projects');
		var eodidVal = $(this).parents("div[eodid]").attr('eodid');
		document.title = 'installprojects='+projectsString;
		$.get("/", { t: "y", client: "eodbrowser", eodid: eodidVal } );
		this.src = 'resources/images/installed.gif';
		$(this).unbind("click");
		$(this).hover(function() {
			$(this).css("cursor", "default");
		});
	});
}

function defaultBrowserSetup() {
	$("#eodbrowser-subheader").hide();
	$(".eodbrowser-project-actions").hide();
	
	setupDefaultActions();
}

function setupDefaultActions() {
    $("div[projects]").each(function() {
        var projects = $(this).attr("projects");
        
        $(this).find("a[source]").each(function () {
            var srcHref = "http://www.examplesondemand.com/cgi-bin/viewvc.cgi/" + $(this).attr("source");
            $(this).attr( { href: srcHref } );
            $(this).click(function() {
                $.get("/", { t: "y", viewsource: projects } );
            });
        });
        
        $(this).find("a[discuss]").each(function() {
            var discussHref = $(this).attr("discuss");
            $(this).attr( { href: discussHref, target: "_blank" } );
            $(this).click(function() {
                $.get("/", { t: "y", discuss: projects } );
            });
        });
    });
}

$(document).ready(function () {
	if (isEODBrowser()) {
		$("a#me-link").removeAttr("href");
		$("a#eod-link").removeAttr("href");
	} else {
		$(".project").css( { width: "800px" } );
	}
	$(".toplinks").find("a").each(function() {
		if (isEODBrowser()) {
			$(this).attr("href", $(this).attr("href") + "?client=eodbrowser");
		}		
	});
	
	//$(".project tr:not(.name-row) td").css( { "padding-left": "10px", "padding-right": "10px" } );
});
