function friend_request(friend_id, action) {
	if (typeof action=="undefined") 
		action = 'add';
	$.get("/rpc/friend_request.php", { friend_id: friend_id, action: action }, function() { 
		if (action == 'remove') { window.location.reload(); }
	});
	if($("#add_to_friends").size() > 0) {
		$("#add_to_friends").css({ background: "none", color: "#0050A0" });
		$("#add_to_friends").html("Friend Request Sent!");
	}
	else {
		$("#add_to_friends"+friend_id).css({ background: "none", color: "#0050A0" });
		$("#add_to_friends"+friend_id).html("Friend Request Sent!");
	}
}

function add_favorite_dog(dog_id) {
	$.get("/rpc/add_favorite_dog.php", { dog: dog_id });
	$("#add_favorite").html('<span class="favorite">Favorite Dog</span>');
}

function comment_on(image_id, image_path) {
	// Add new form element if one doesn't already exist.
	if($("#comment_image_id_1").length) {
		$("#comment_image_id_1").attr("value", image_id);
		$("#comment_image_1").attr("src", image_path);
		$("#comment_image_id_2").attr("value", image_id);
		$("#comment_image_2").attr("src", image_path);
	} else { 
		$("#comment_form_1").append('<input type="hidden" value="'+image_id+'" name="comment_image_id" id="comment_image_id_1" />');
		$("#comment_form_2").append('<input type="hidden" value="'+image_id+'" name="comment_image_id" id="comment_image_id_2" />');
		$("#comment_box_1").before('<img src="'+image_path+'" id="comment_image_1" />');
		$("#comment_box_2").before('<img src="'+image_path+'" id="comment_image_2" />');

		$("#comment_form_1").css("margin", "0px 0px 0px 0px");
		$("#comment_form_2").css("margin", "0px 0px 0px 0px");
		$("#comment_box_1").css("width", "345px");
		$("#comment_box_2").css("width", "345px");
	}

	document.location = '#comment_form';
}

function set_user_action(action) {
	$.get("/rpc/set_user_action.php", { action: action });
}

function getHotkeysAds(targetParamValue) {
    // set the width and height of the iframe
    document.getElementById("hotkeysAds").width = 740;
    document.getElementById("hotkeysAds").height = 1000;

    // host serving ads
    var adHost = "http://js.hotkeys.com/ads";

    // set the hotkeys top category param
    adHost += "?";
    adHost += "hotkeysDomainName=\"dailypuppy.com\"";
    adHost += "&";
    adHost += "HotKeysTopCategory=" + targetParamValue;
    adHost += "&";
    adHost += "includeRelatedSearches=no";
    adHost += "&";
    adHost += "fontFamily=Georgia";
    adHost += "&";
    adHost += "listingTitleFontSize=12";
    adHost += "&";
    adHost += "listingDescFontSize=10";
    adHost += "&";
    adHost += "bodyWidth=740";
    adHost += "&";
    adHost += "titleFontColor=333333";
    adHost += "&";
    adHost += "relatedSearchesHeaderShading=FFFFCC" ;
    adHost += "&";
    adHost += "listingWWWUrlLinkColor=5F7957";
    adHost += "&";
    adHost += "backgroundColor=FFFFFF";
    adHost += "&";
    adHost += "listingTitleLinkColor=0050A0";
    adHost += "&";
    adHost += "listingDescColor=000000";
    adHost += "&";
    adHost += "relatedSearchesLinkColor=5F7957";


    // fetch the ads
    document.getElementById("hotkeysAds").src = adHost;

	// Tryin to modify thier HTML
	// var iframe_body = document.getElementById("hotkeysAds").contentWindow.document.getElementsByTagName('body')[0];
	// printd(iframe_body);
	//iframe_body.innerHTML = "";
}

function tip(element_object, innerHTML, css) {
	// Give some functionality to the element_object
	if(element_object) {
		element_object.tip = this;

		// Create the tip box
		// Note that tip box is a property of element_object
		this.tip_box = document.createElement("div");
		this.tip_box.style.visibility = "hidden";
		this.tip_box.className = "tip " + css;

		if(typeof innerHTML == "object") {
			this.tip_box.appendChild(innerHTML);
		} else {
			this.tip_box.innerHTML = innerHTML;
		}

		document.body.appendChild(this.tip_box);
		element_object.tip_box = this.tip_box;

		// Add Event Handlers
		element_object.onmouseover = this.onmouseover;
		element_object.onmouseout = this.onmouseout;
	}
}

tip.prototype.set_position = function(e) {
    var IE = document.all?true:false;
    if (IE) {
        //pos_x = event.clientX + document.body.scrollLeft;
       // pos_y = event.clientY + document.body.scrollTop;
		pos_x = event.clientX + document.documentElement.scrollLeft; 
        pos_y = event.clientY + document.documentElement.scrollTop;
    } else {
        pos_x = e.pageX;
        pos_y = e.pageY;
    }

    this.tip_box.style.top = (pos_y + 10) + "px";
    this.tip_box.style.left = (pos_x + 10) + "px";
}

tip.prototype.onmouseover = function(e) {
    // Set position first then visible,
    // else you'll get some jumping effect
    if(this.tip_box.style.visibility == "hidden") {
        this.onmousemove = this.tip.onmousemove;
        this.tip_box.style.visibility = "visible";
        this.style.cursor = "pointer";
    }
}

tip.prototype.onmousemove = function(e) {
    this.tip.set_position(e);
}

tip.prototype.onmouseout = function(e) {
    this.tip_box.style.visibility = "hidden";
}

function dp_calendar(month, year, direction, section_id) {
	$("#hide_controls").css("z-index", 2);
	new_month = month;
	new_year = year;
	new_section_id = section_id;

	var index = String(new_section_id)+'_'+String(new_year)+'_'+String(new_month);

	if(typeof(dp_calendar_cache) == 'undefined') {
		//create cache if doesn't exist
		dp_calendar_cache = new Array();
		//cache current calendar
		dp_calendar_cache[index] = $("#puppy_calendar").html();
	}
	//figure out the month/year we want
	new_month = month + direction;
	if(new_month == 0) {
		new_year--;
		new_month = 12;
	}
	if(new_month == 13) {
		new_year++;
		new_month = 1;
	}
	
	var index = String(new_section_id)+'_'+String(new_year)+'_'+String(new_month);
	//check cache
	if(typeof(dp_calendar_cache[index]) != 'undefined') {
		$("#puppy_calendar").html(dp_calendar_cache[index]);
		$("#hide_controls").css("z-index", 0);
		setCookie('dp_month', new_month, 0, '/', '.dailypuppy.com', '');
		setCookie('dp_year', new_year, 0, '/', '.dailypuppy.com', '');
	}
	else {
		//if not in cache, get it
		$("#puppy_calendar").fadeTo(1, .5);
		$.getJSON("/rpc/get_calendar.php", { month: new_month, year: new_year, section: section_id}, dp_calendar_handler);
	}
}

function dp_calendar_handler(data) {
	//alert(new_month+':'+new_year+':'+new_section_id);
	//var new_element = $(data['html']);
	$("#puppy_calendar").html($(data['html']).html());
	var index = String(new_section_id)+'_'+String(new_year)+'_'+String(new_month);
	dp_calendar_cache[index] = $(data['html']).html();
	$("#puppy_calendar").fadeTo(1, 1);
	$("#hide_controls").css("z-index", 0);
	setCookie('dp_month', new_month, 0, '/', '.dailypuppy.com', '');
	setCookie('dp_year', new_year, 0, '/', '.dailypuppy.com', '');
}


function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function loadIFrameAd(frame_id, url)
{
	var frame = $("#"+frame_id);
	if (frame && url.length > 0) 
		frame.attr("src", url); 
}
var top_leaderboard_frame_url = "";