/*
 * Conservative9.js
 *
 * Copyright (c) 2009 Inform Techonologies Inc.
 */

var dnLogin = 
{
	SessionHost: "",
	Data:
	{
		email: "",
		username: ""
	},
	Gravatar:
	{
		requestUrl: "http://www.gravatar.com/avatar.php",
		defaultSize: "40",
		getUrl: function(email, size)
		{
			if(size < 1) size=dnLogin.Gravatar.defaultSize
			//&default=http%3a%2f%2f"+dnLogin.SessionHost+"%2fimages%2fgravatar-none.jpg
			return dnLogin.Gravatar.requestUrl + "?gravatar_id=" +  $.md5(email) + "&d=monsterid&size=" + size;
		},
		getImageTag: function(email, size)
		{
			return "<img src=\"" + dnLogin.Gravatar.getUrl(email, size) + "\" width=\"" + size + "\"/>";
		}
	},
	Eid: 
	{
		loginBox : "#drift_login",
		logoutBox : "#drift_logout",
		loginForms : "#drift_login_form",
		loginForms_login : "#drift_login_form_login",
		loginForms_register : "#drift_login_form_register",
		loginForms_forgot : "#drift_login_form_forgot",
		loginForms_reset : "#drift_login_form_reset",
		loginForms_loading : "#drift_login_form_loading",
        loginForms_openid : "#drift_login_form_openid_login"
	},
	init: function()
	{
		$(dnLogin.Eid.loginBox).hide();
		$(dnLogin.Eid.loginForms).hide();
		dnLogin.hide_all_div();

		if(this.Data.username.length > 0) 
		{
			$(dnLogin.Eid.loginBox).hide();
			$(dnLogin.Eid.logoutBox).show();
            if ( dnLogin.Data.username.length > 50)
                short_username = dnLogin.Data.username.substring(0, 49) + "..."
            else
                short_username = dnLogin.Data.username
			$("#drift_login_info_as").html("<a href=\"#\">"+short_username+"</a>");
		}
		else 
		{
			$(dnLogin.Eid.loginBox).show();
			$(dnLogin.Eid.logoutBox).hide();
		}
	},
	onclick_login_buttom: function()
	{
		$(dnLogin.Eid.loginForms).show('normal');
		this.find_pos_loginform()
		dnLogin.onclick_login_show();
	},
	onclick_loginBox_close: function()
	{
		$(dnLogin.Eid.loginForms).hide('normal');
	},
	onclick_login_show: function()
	{
		dnLogin.hide_all_div();
		dnLogin.hide_all_err();
		$(dnLogin.Eid.loginForms_login).show();
		if(!$.browser.safari)
		{
			$("#login-username").select();
			$("#login-username").focus();
		}
	},
	onclick_register_show: function()
	{
		dnLogin.hide_all_div();
		$(dnLogin.Eid.loginForms_register).show();
		if(!$.browser.safari)
		{
			$("#create-username").select();
			$("#create-username").focus();
		}
	},
	onclick_forgot_show: function()
	{
		dnLogin.hide_all_div();
		$(dnLogin.Eid.loginForms_forgot).show();
		if(!$.browser.safari)
		{
			$("#forgot-username").select();
			$("#forgot-username").focus();
		}
	},
	onclick_reset_show: function()
	{
		dnLogin.hide_all_div();
		$(dnLogin.Eid.loginForms_reset).show();
		if(!$.browser.safari)
		{
			$("#reset-username").select();
			$("#reset-username").focus();
		}
	},
    onclick_openid_show: function()
	{
		dnLogin.hide_all_div();
		$(dnLogin.Eid.loginForms_openid).show();
		if(!$.browser.safari)
		{
			$("#reset-username").select();
			$("#reset-username").focus();
		}
	},    
	hide_all_div: function()
	{
		$(dnLogin.Eid.loginForms_login).hide();
		$(dnLogin.Eid.loginForms_register).hide();
		$(dnLogin.Eid.loginForms_forgot).hide();
		$(dnLogin.Eid.loginForms_reset).hide();
		$(dnLogin.Eid.loginForms_loading).hide();
        $(dnLogin.Eid.loginForms_openid).hide();
	},
	hide_all_err:function()
	{
		$(".login_error").hide();
	},
	onkeypress_login: function(e)
	{
		if(typeof window.event!="undefined"){
			e=window.event;//code for IE
		}
		if(e.keyCode==13 || e.charCode == 13) { this.submit_login(); return false; }
	},
	onkeypress_register: function(e)
	{
		if(e.keyCode == 13) { this.submit_register(); return false;}
	},
	onkeypress_forgot: function(e)
	{
		if(e.keyCode == 13) { this.submit_forgot(); return false;}
	},
	onkeypress_reset: function(e)
	{
		if(e.keyCode == 13) { this.submit_reset(); return false;}
	},
	submit_login: function()
	{
		dnLogin.hide_all_err();

		var get_username = this.trim($("#login-username").val());
		var get_pass = this.trim($("#login-password").val());

		if(!this.check_username(get_username))
		{
			$("#error-login-username-format").show();
			return false;
		}
		if (get_pass.length < 4)
		{
			$("#error-login-password-format").show();
			return false;
		};

		//submitting
		$(dnLogin.Eid.loginForms_login).hide();
		$(dnLogin.Eid.loginForms_loading).show();

		$.ajax({
			type: "POST",
			url: "/member/login",
			data: { username:get_username, passwd:get_pass },
			dataType: "xml",
			success: function(xml) { 
				dnLogin.callback_login(xml); 
			}
		});
		return false;
	},
    submit_openid_login: function()
	{
		dnLogin.hide_all_err();

		var get_username = this.trim($("#login-username").val());

		if(!this.check_username(get_username))
		{
			$("#error-login-username-format").show();
			return false;
		}

		//submitting
		$(dnLogin.Eid.loginForms_login).hide();
		$(dnLogin.Eid.loginForms_loading).show();

		$.ajax({
			type: "POST",
			url: "/openid/",
			data: { openid_url:get_username },
			dataType: "xml",
			success: function(xml) { 
				dnLogin.callback_login(xml); 
			}
		});
		return false;
	},
    
	submit_logout: function()
	{
		var redirect = dnLogin.get_redirect_url(window.location.href)
		//alert("a: " + redirect)
		var a = "/auth/logout/?redirect=" + redirect;
		window.location = a;
	},
	
	submit_logout_article: function()
	{
		var redirect = dnLogin.get_redirect_url(window.location.href)
		//alert(redirect)
		var a = "/auth/logout_article/?redirect=" + redirect;
		
		//a = dnLogin.urlencode(a)
		window.location = a;
	},
	
	submit_register: function()
	{
		this.hide_all_err();

		var get_username = this.trim($("#create-username").val());
		var get_email = this.trim($("#create-email").val());
		var get_pass =  this.trim($("#create-password").val());
		var get_pass_confirm = this.trim($("#create-password-repeat").val());
		
		if(!this.check_username(get_username))
		{
			$("#error-create-username-format").show();
			return false;
		}
		if (get_pass.length < 4)
		{
			$("#error-create-password-format").show();
			return false;
		};
		if (get_pass != get_pass_confirm)
		{
			$("#error-create-password-match").show();
			return false;
		};
		if(!this.check_emailaddr(get_email))
		{
			$("#error-create-email-format").show();
			return false;
		};

		//submitting
		$(dnLogin.Eid.loginForms_register).hide();
		$(dnLogin.Eid.loginForms_loading).show();

		$.ajax({
			type: "POST",
			url: "/member/create",
			data: { username: get_username , passwd: get_pass, email: get_email },
			dataType: "xml",
			success: function(xml) { 
				dnLogin.callback_register(xml, get_username); 
			}
		});
		return false;
	},
	submit_forgot: function()
	{
		this.hide_all_err();
		var get_username = this.trim($("#forgot-username").val());	
		var get_email = this.trim($("#forgot-email").val());	
		if (get_username.length < 2)
		{
			$("#error-forgot-username").show();
			return false;
		}
		if(!this.check_emailaddr(get_email))
		{
			$("#error-forgot-email-format").show();
			return false;
		}
		//submitting
		$(dnLogin.Eid.loginForms_forgot).hide();
		$(dnLogin.Eid.loginForms_loading).show();

		$.ajax({
			type: "POST",
			url: "/member/forgot",
			data: {  username: get_username, email: get_email},
			dataType: "xml",
			success: function(xml) { 
				dnLogin.callback_forgot(xml);
			}
		});
		return false;
	},
	submit_reset: function()
	{
		this.hide_all_err();

		var get_username = this.trim($("#reset-username").val());
		var get_current_pass =  this.trim($("#reset-current-password").val());
		var get_pass =  this.trim($("#reset-new-password").val());
		var get_pass_confirm = this.trim($("#reset-new-password-repeat").val());
		
		if (get_pass.length < 4)
		{
			$("#error-reset-password-format").show();
			return false;
		};
		if (get_pass != get_pass_confirm)
		{
			$("#error-reset-password-match").show();
			return false;
		};

		//submitting
		$(dnLogin.Eid.loginForms_reset).hide();
		$(dnLogin.Eid.loginForms_loading).show();

		$.ajax({
			type: "POST",
			url: "/member/reset",
			data: { username: get_username , passwd: get_current_pass, new_passwd: get_pass },
			dataType: "xml",
			success: function(xml) { 
				dnLogin.callback_reset(xml); 
			}
		});
		return false;
	},
	callback_login: function(data)
	{
		var obj = dnLogin.parse_login_response(data);

		if(obj.result) //login
		{
			var a = "http://"+dnLogin.SessionHost+"/auth/savesession/"+obj.username+"/?redirect="+dnLogin.get_redirect_url(window.location.href);
			window.location = a;
		}
		else
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();

			$("#error-login-server").html(obj.err_msg); //show error
			$("#error-login-server").show();
			dnLogin.Data.username = '';
			dnLogin.Data.email = '';
			$(dnLogin.Eid.loginForms_login).show();
			//dnLogin.hide_login_show_comment_box(false);
		}
		return false;
	},
	callback_register: function(data, get_username)
	{
		var obj = dnLogin.parse_login_response(data);

		if(obj.result) //login
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();
			$(dnLogin.Eid.loginForms_login).show();
			alert(get_username);
			$("#reset-username").val(get_username);
		}
		else
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();

			$("#error-create-server").html(obj.err_msg); //show error
			$("#error-create-server").show();
			$(dnLogin.Eid.loginForms_register).show();
		}
	},
	callback_forgot: function(data)
	{
		var obj = dnLogin.parse_login_response(data);

		if(obj.result) //reset
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();

			$("#error-reset-input").show();
			$(dnLogin.Eid.loginForms_reset).show();
		}
		else
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();

			$("#error-forgot-server").html(obj.err_msg); //show error
			$("#error-forgot-server").show();
			$(dnLogin.Eid.loginForms_forgot).show();
		}
	},
	callback_reset: function(data)
	{
		var obj = dnLogin.parse_login_response(data);

		if(obj.result) //login
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();

			$(dnLogin.Eid.loginForms_login).show();
		}
		else
		{
			dnLogin.hide_all_div();
			dnLogin.hide_all_err();

			$("#error-reset-server").html(obj.err_msg); //show error
			$("#error-reset-server").show();
			$(dnLogin.Eid.loginForms_reset).show();
		}
	},
	parse_login_response: function(data)
	{
		var d = new Object();
		d.result = true;
		d.username = "";
		d.email = "";
		d.err_msg = "Response type is wrong. [Error #51001]";
		
		var result = $(data).find('result').text();

		if(typeof result == 'undefined')
		{
			d.result=false;
			return d;
		}
		else if(result == "true")
		{
			d.result=true;
			d.username =$(data).find('username').text();
			d.email = $(data).find('email').text();
		}
		else if(result == "false")
		{
			d.result=false;
			d.err_msg =$(data).find('err_msg').text();
		}
		else
		{
			d.result=false;
			d.err_msg = "Response type (result) is wrong. [Error #51002]";
		}
		return d;
	},
	hide_login_show_comment_box: function(result)
	{
		if(result)
		{
			dnLogin.hide_all_div();
			$(dnLogin.Eid.loginForms).hide();
			$(dnLogin.Eid.loginBox).hide();
		}
		else //fail 
		{
			$(dnLogin.Eid.loginForms_login).show();
		}
	},
	check_emailaddr: function(email)
	{
		if (!email.match(/^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/))
		{
			return false;
		}
		return true;
	},
	check_username: function(username)
	{
		if (!username.match(/^([\da-zA-Z_])+$/))
		{
			return false;
		}
		return true;
	},
	trim: function(str)
	{
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	},
	get_redirect_url: function(url)
	{
		var idx = url.indexOf('?');
		if(idx > 0)
		{
			url = url.substring(0, idx);
		}
		
		return dnLogin.urlencode(url);

	},
	urlencode: function(str)
	{
		//20090904 return str.replace(/\//g, '%2F');
		return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40').replace(/\%/g, '%25');
	},
	find_pos_loginform: function()
	{
		var pos = $(dnLogin.Eid.loginBox).position();
		$(dnLogin.Eid.loginForms).css('top', pos.top+'px');
		if(pos.left > 400)
		{
			$(dnLogin.Eid.loginForms).css('left', (pos.left - 220 - 40)+'px');		
		}
		else
		{
			$(dnLogin.Eid.loginForms).css('left', (pos.left + 70)+'px');		
		}
	}
}
var dnComment = 
{
	Data:
	{
		email: "",
		username: "",
		content: "",
		gravataSize: 25
	},
	Eid: 
	{
		commentBox : "#comment_input_box",
		loginBox : "#comment_login",
		loginForms : "#comment_login_form",

		commentContentBox: "#comment_list_all",
		commentContentBox_None: "#comment_list_none",

		commentData_content_type: "#id_content_type",
		commentData_object_pk: "#id_object_pk",
		commentData_content_type: "#id_timestamp",
		commentData_security_hash: "#id_security_hash"
	},
	init: function()
	{
		this.Data.content = "";
		$(dnComment.Eid.commentBox).hide();
		$(dnComment.Eid.loginBox).hide();
		$(dnComment.Eid.loginForms).hide();
		$("#comment_text").val('');

		if(this.Data.username.length > 0) 
		{
			$(dnComment.Eid.commentBox).show();
			this.update_login_name();
		}
		else $(dnComment.Eid.loginBox).show();

		//show msg if no comment saved
		dnComment.display_comment_content();
		//show delete icon for comment
		dnComment.display_comment_delete();
	},
	update_login_name: function()
	{
		if(dnComment.Data.username.length > 0)
		{
            if ( dnComment.Data.username.length > 45)
                short_username = dnComment.Data.username.substring(0, 44) + "..."
            else
                short_username = dnComment.Data.username
			$("#comment_login_info_as").html(short_username);
		}
	},
	hide_all_err:function()
	{
		$(".comment_error").hide();
	},
	submit_logout: function()
	{
		dnLogin.submit_logout();
	},
	
	/*20090904 article*/
	submit_logout_article: function()
	{
		dnLogin.submit_logout_article();
	},

	///////////////     Comment        ///////////////////////
	onclick_comment_add: function()
	{
		var get_text = $("#comment_text").val();
		
		if (dnComment.Data.username.length < 2)
		{
			$("#error-comment_userid").show();
			return false;
		}
		if (get_text.length < 2)
		{
			$("#error-comment_text").show();
			$("#comment_text").focus();
			return false;
		};
		var comment_data = dnComment.comment_check_data();
		if(typeof comment_data == 'undefined' || comment_data.content_type=="" || comment_data.object_pk == "" || comment_data.timestamp=="" || comment_data.security_hash=="")
		{
			alert("You can't submit comment. Please contact site administrator.");
			return false;
		}

		///////// submit start ///////////
		//save comment data
		dnComment.Data.content = get_text;
		dnComment.comment_submit_loading_msg(true);

		$.ajax({
			type: "POST",
			url: "/comments/post/",
			data: { email:dnComment.Data.email, comment: dnComment.Data.content, name:dnComment.Data.username, content_type: comment_data.content_type, object_pk: comment_data.object_pk, timestamp:comment_data.timestamp, security_hash:comment_data.security_hash },
			dataType: "xml",
			success: function(xml) { 
				dnComment.callback_comment_add(xml);
			}
		});

		return false;
	},
	onclick_comment_delete: function(id)
	{
		get_id = function(gid)
		{
			if(gid.length > 19)
 				return gid.substr(19);
			return ""
		}
		var gid = get_id(id);
		if(gid.length < 1) 
		{
			alert('You must submit comment id.');
			return false;
		}
		var c = confirm('Are you sure you want to delete this comment?');
		if (c && id != null)
		{
			var comment_data = dnComment.comment_check_data();
			$.ajax({
				type: "POST",
				url: "/comments/delete/"+gid+"/"+dnComment.Data.email+"/",
				data: { content_type: comment_data.content_type, object_pk: comment_data.object_pk, timestamp:comment_data.timestamp, security_hash:comment_data.security_hash },
				dataType: "xml",
				success: function(xml) { 
					dnComment.callback_comment_delete(xml, id);
				}
			});
		}
		return false;
	},
	callback_comment_delete: function(xml, id)
	{
		dnComment.hide_all_err();
		var obj = dnComment.parse_comment_response(xml);

		if(obj.result && id.length > 0)
		{
			$("#"+id).hide('normal');
			$("#"+id).remove();
			dnComment.display_comment_content();
		}
		else
		{
			alert(obj.msg);	
		}
	},
	callback_comment_add: function(content)
	{
		dnComment.hide_all_err();
		dnComment.comment_submit_loading_msg(false);

		var obj = dnComment.parse_comment_response(content);
		if(obj.result && obj.id != "0")
		{
			//get get_id
			$("#comment_text").val('');

			var body = "<li id=\"comment_content_id_"+obj.id+"\"><div class=\"comment_list\"><div class=\"comment_content\">"+
						dnComment.Data.content + "</div><div class=\"comment_cid\">"+
						"<div id=\"comment_gravatar\" style=\"margin-right:2px;\">" + dnLogin.Gravatar.getImageTag(dnComment.Data.email, dnComment.Data.gravataSize) + "</div>"+
						"<div id=\"comment_userinfo\"><h4>"+dnComment.Data.username + "</h4><h5 style=\"display:none;\">"+dnComment.Data.username + "</h5><span class=\"comment_date\">" + 
						obj.msg + "</span></div><div class=\"comment_delete\"><a onclick=\"dnComment.onclick_comment_delete('comment_content_id_"+obj.id+"'); return false;\" href=\"#\" title=\"Delete a comment\">&nbsp;&nbsp;&nbsp;&nbsp;</a></div></div></div></li>"+
						$("#comment_list_all").html();
			
			$(dnComment.Eid.commentContentBox).html(body);
			dnComment.display_comment_content();
		}
		else
		{
			alert(obj.msg);	
		}
		dnComment.Data.content = "";
	},
	parse_comment_response: function(data)
	{
		var d = new Object();
		d.result=true;
		d.msg = "Wrong request type";
		d.id = "0";
		var result = $(data).find('result').text();

		if(typeof result == 'undefined')
		{
			return d;
		}
		else if(result == "true")
		{
			d.result=true;
			if($(data).find('submit_date'))
			{
				d.msg =$(data).find('submit_date').text();
			}
			else if($(data).find('err_msg'))
			{
				d.msg =$(data).find('err_msg').text();
			}
			if($(data).find('id'))
			{
				d.id =$(data).find('id').text();
			}
		}
		else if(result == "false")
		{
			d.result=false;
			d.msg =$(data).find('err_msg').text();
		}
		else
		{
			d.result=false;
			d.msg = "Unknown error. [Error #10002]";
		}
		return d;
	},
	comment_check_data: function()
	{
		var cmt_data = new Object();
		cmt_data.content_type = $("#id_content_type").val();
		cmt_data.object_pk = $("#id_object_pk").val();
		cmt_data.timestamp = $("#id_timestamp").val();
		cmt_data.security_hash = $("#id_security_hash").val();
		return cmt_data;
	},

	comment_submit_loading_msg: function(issubmit)
	{
		var id  = $(".comment_btn");
		if(typeof id != 'undefined')
		{
			if(issubmit)
			{
				id.val('submitting...');
				id.attr('style', 'cursor:wait;width:100px;');
			}
			else
			{
				id.val('add comment');
				id.attr("style", "cursor:pointer;width:100px;");
			}
		}
	},

	display_comment_content: function()
	{
		if($(dnComment.Eid.commentContentBox).html().length > 30)
		{
			$(dnComment.Eid.commentContentBox_None).hide('normal');
			$(dnComment.Eid.commentContentBox).show('normal');
		}
		else
		{
			$(dnComment.Eid.commentContentBox).hide();
			$(dnComment.Eid.commentContentBox_None).show('normal');
		}
	},
	display_comment_delete: function()
	{
		if($(dnComment.Eid.commentContentBox).html().length > 30)
		{
			$(dnComment.Eid.commentContentBox).find("li").each( 
				function(i) 
				{ 
					var id = $(this);
					// set id
					var get_id=id.attr("id");
					var cid = id.find(".comment_cid");
					if(typeof cid != "undefined")
					{
						/* gravata */
						var get_gravatar_id=cid.find("#comment_gravatar");
						if(typeof get_gravatar_id != "undefined" && typeof dnLogin != "undefined")
						{
							var email = cid.find("#comment_email").val();
							get_gravatar_id.html(dnLogin.Gravatar.getImageTag(email, dnComment.Data.gravataSize));
						}

						/* delete button */
						if(dnComment.Data.username.length > 0)
						{
							var uname = cid.find("h5").html();
							if(uname == dnComment.Data.username)
							{
								cid.append("<div class=\"comment_delete\"><a onclick=\"dnComment.onclick_comment_delete('"+get_id+"'); return false;\" href=\"#\" title=\"Delete a comment\">&nbsp;&nbsp;&nbsp;&nbsp;</a></div>");
							}
						}
					}
				} 
			);
		};
	}
	///////////////// Other /////////////////////
}
var dnForum = 
{
	pageType: "forum_list",
	init: function()
	{
		this.hide_all_err();
		if(this.pageType=="post_list")
		{
			this.add_post_list_func();
		}
	},
	add_post_list_func: function()
	{
		if(typeof dnLogin == "undefined" || dnLogin.Data.username.length < 1) return;

		$("#post_list_box").find(".postfunc").each( 
			function(i) 
			{ 
				var id = $(this);
				// set id
				var author = id.attr("author");
				var forum_id = id.attr("forum_id");
				var post_id = id.attr("post_id");
				if(typeof author != "undefined" && author == dnLogin.Data.username && forum_id > 0 && post_id > 0)
				{
					/* edit link */
					id.append("| <a href=\"/forums/edit_post/"+forum_id+"/"+post_id+"/\">Edit this post</a>");
				}
			} 
		);			
	},
	onclick_check_login: function(func, redir)
	{
		if(typeof dnLogin != "undefined")
		{
			if(dnLogin.Data.username.length > 1 && redir.length > 1)
			{
				if(func=='reply') window.location = redir;
				else if(func=='reply_quote') window.location = redir;
				else if(func=='add_topic') window.location = redir;
				else $("#error_forum_default").show();
			}
			else
			{
				$("#forum_error_msg").show();
				if(func=='reply' || func=='reply_quote' || func=='add_topic') $("#error_forum_login").show();
				else $("#error_forum_default").show();
			}
		}
		else
		{
			$("#forum_error_msg").show();
			$("#error_forum_default").show();
		}
		return false;
	},
	onclick_forum_add: function()
	{
		if(typeof dnLogin != "undefined")
		{
			if(dnLogin.Data.username.length > 1)
			{
				window.location = "/forums/add_forum";
			}
			else
			{
				$("#forum_error_msg").show();
				$("#error_forum_login").show();
			}
		}
		else
		{
			$("#forum_error_msg").show();
			$("#error_forum_default").show();
		}
		return false;
	},
	hide_all_err:function()
	{
		$("#forum_error_msg").hide();
		$(".forum_error").hide();
	}
}

var dnGetMedia = 
{
	getVideos: function(subject) 
	{
		$.ajax({
			type: "POST",
			url: "/getmedia/youtube/"+subject,
			dataType: "html",
			success: function(html) { 
				dnGetMedia.callback_youtube(html); 
			}
		});
	},
	get5MinVideos: function(subject)
	{
		$.ajax({
			type: "POST",
			url: "/getmedia/5min/"+subject,
			dataType: "html",
			success: function(html) { 
				dnGetMedia.callback_5min(html); 
			}
		});
	},
    getTwitter: function(subject) 
	{
		$.ajax({
			type: "POST",
			url: "/getmedia/twitter/"+subject,
			dataType: "html",
			success: function(html) { 
				dnGetMedia.callback_twitter(html); 
			}
		});
	},
	getOneriot: function(subject) 
    {
        
        $.ajax({
            type: "POST",
            url: "/getmedia/oneriot/"+subject,
            dataType: "html",
            success: function(html) { 
                            dnGetMedia.callback_oneriot(html); 
            }
        });
    },

	getPhotos: function(subject) 
	{
		$.ajax({
			type: "POST",
			url: "/getmedia/flickr/"+subject,
			dataType: "html",
			success: function(html) { 
				dnGetMedia.callback_flickr(html); 
			}
		});
	},	
	getPhotos_one_row: function(subject) 
	{
		$.ajax({
			type: "POST",
			url: "/getmedia/flickr_search_company/"+subject,
			dataType: "html",
			success: function(html) { 
				dnGetMedia.callback_main_flickr(html); 
			}
		});
	},	
	callback_5min: function(data)
	{
		document.getElementById('5min').innerHTML = data;
	},
	callback_youtube: function(data)
	{
		document.getElementById('youtube').innerHTML = data;
	},
    callback_twitter: function(data)
	{
		document.getElementById('twitter').innerHTML = data;
	},
	callback_flickr: function(data)
	{
		document.getElementById('flickr').innerHTML = data;
	},
	callback_main_flickr: function(data)
	{
		document.getElementById('main_flickr').innerHTML = data;
	},
	callback_oneriot: function(data)
    {
        document.getElementById('oneriot').innerHTML = data;
    }
}

var dnGetTags = 
{
	getTags: function() 
	{
		$.ajax({
			type: "POST",
			url: "/gettags",
			dataType: "html",
			success: function(html) { 
				dnGetTags.callback_tags(html); 
			}
		});
	},
	callback_tags: function(data)
	{
		document.getElementById('tags').innerHTML = data;
	}
}


var dnGetPage =
{
    getPage: function(page_num)
	{ 
		$.ajax({
			type: "POST",
			url: "/page/"+page_num,
 			dataType: "html",
			success: function(html) {
				dnGetPage.callback_page(html);
			}
		});
	},
	callback_page: function(data)
	{        
        //alert(data)
        data=data.replace(/&lt;/g, "<");
		data=data.replace(/&gt;/g, ">");
        data=data.replace(/&quot;/g, '"');
		document.getElementById('featured_articles').innerHTML = data;
	}
}

var dnGetTopicPage =
{
    getTopicPage: function(page_num, topic)
	{
        //alert(topic + ' : ' + page_num)
		$.ajax({
			type: "POST",
			url: "/topicpage/"+topic+"/"+page_num,
 			dataType: "html",
			success: function(html) {
				dnGetTopicPage.callback_page(html);
			}
		});
	},
	callback_page: function(data)
	{        
        //alert(data)
		data=data.replace(/&lt;/g, "<");
		data=data.replace(/&gt;/g, ">");
        data=data.replace(/&quot;/g, '"');
		document.getElementById('topic_featured_articles').innerHTML = data;
	}
}

var dnUpdateLog =
{
    updateLog: function(param)
	{
		$.ajax({
			type: "POST",
			url: "/log/?"+param,
 			dataType: "html",
			success: function(html) {
				dnUpdateLog.cb_updateLog(html);
			}
		});
	},
	cb_updateLog: function(data)
	{
		document.getElementById('log_img').innerHTML = data;
	}
}

