
(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);;$j=jQuery;
jQuery.fn.outerHTML = function() {
	return $('<div>').append( this.eq(0).clone() ).html();
};
function date_m2h(d,type){
	if(d=='' || d=='0000-00-00')return '-';
	if(!type)type='date';
	date=d.replace(/([0-9]+)-([0-9]+)-([0-9]+).*/,'$3-$2-$1',d).replace(/-0/g,'-');
	var m=months[date.replace(/.*-([0-9]+)-.*/,'$1')];
	date=date.replace(/-[0-9]+-/,'-'+m+'-');
	if(type=='date')return date;
	var time=d.replace(/.* /,'');
	if(type=='time')return time;
	return time+', '+date;
}
function htmlspecialchars(str) {
	if (!str) {
		return '';
	}
	return $('<i>').text(str).html();
}
// { kaejax
function kaejax_create_functions(url,f){
	kaejax_is_loaded=1;
	for(var i=0;i<f.length;++i){
		eval('window.x_'+f[i]+'=function(){kaejax_do_call("'+f[i]+'",arguments)}');
		function_urls[f[i]]=url;
	}
}
function kaejax_do_call(func_name,args){
	var uri=function_urls[func_name];
	if(!window.kaejax_timeouts[uri]){
		window.kaejax_timeouts[uri]={t:setTimeout('kaejax_sendRequests("'+uri+'")',1),c:[],callbacks:[]};
	}
	var l=window.kaejax_timeouts[uri].c.length,v2=[];
	for(var i=0;i<args.length-1;++i){
		v2[v2.length]=args[i];
	}
	window.kaejax_timeouts[uri].c[l]={f:func_name,v:v2};
	window.kaejax_timeouts[uri].callbacks[l]=args[args.length-1];
}
function kaejax_sendRequests(uri){
	var t=window.kaejax_timeouts[uri],callbacks=window.kaejax_timeouts[uri].callbacks;
	t.callbacks=null;
	window.kaejax_timeouts[uri]=null;
	var x=new XMLHttpRequest(),post_data="kaejax="+escape(Json.toString(t)).replace(/%([89A-F][A-Z0-9])/g,'%u00$1').replace('+','%2B');
	x.open('POST',uri,true);
	x.setRequestHeader("Method","POST "+uri+" HTTP/1.1");
	x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	x.onreadystatechange=function(){
		if(x.readyState!=4)return;
		var v=eval('('+unescape(x.responseText.replace(/%/g,'%25'))+')');
		var f,p;
		for(var i=0;i<t.c.length;++i){
			var f=callbacks[i],p=[];
			p=[];
			if($.isArray(f)){
				p=f;
				f=f[0];
			}
			if(f)f(v[i],p);
		}
	}
	x.send(post_data);
}
// }
function loadScript(url){
	if($.inArray(url,loadedScripts)>-1)return 0;
	loadedScripts.push(url);
	if(kaejax_is_loaded&&/\.php/.test(url))url+=(/\?/.test(url)?'&':'?')+'kaejax_is_loaded';
	$.getScript(url);
	return 1;
}
window.ww={
	CKEDITOR:'ckeditor'
};
// { variables
var function_urls=[],loadedScripts=[],kaejax_is_loaded=0,months=['--','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var kaejax_timeouts=[];
// }
var Json = {
	toString: function(arr) {
		return $.toJSON(arr);
	}
};
$(function(){
	var el=$('.ajaxmenu')[0];
	if(!el)return;
	var id=el.id.replace(/ajaxmenu/,'');
	if(id && id=='am_top')return;
	loadScript('/j/menu.php?pageid='+pagedata.id);
});
;$(function () {
	$('#comment-form').validate({
		rules:{
			name:'required',
			email:{
				required:true,
				email:true
			},
			site:{
				url:true
			},
			comment:{
				required:true
			}
		},
		messages:{
			site:{
				url:'The URL should be in the form http://yoursite.domain'
			}
		}
	});
});
$('div.comment-editable').live('mouseover',function() {
	var id = $(this).attr('id').replace(/comment-wrapper-/,'');
	if (document.getElementById('links-'+id)!=null) {
		return;
	}
	$('div.comments- div.comments-actions').remove();
	var mysqldatetime = $(this).attr('cdate');
	var mysqldate = mysqldatetime.substring(8, 10);
	var mysqlmonth = mysqldatetime.substring(5, 7);
	var mysqlyear = mysqldatetime.substring(0, 4);
	var mysqlhour = mysqldatetime.substring(11, 13);
	var mysqlminute = mysqldatetime.substring(14, 16);
	var mysqlsecond = mysqldatetime.substring(17, 19);
	var now = new Date();
	var commentDate 
		= new Date(
			mysqlyear, mysqlmonth-1, mysqldate, 
			mysqlhour, mysqlminute, mysqlsecond
		);
	var nowInMilliseconds = Date.parse(now);
	commentDate = Date.parse(commentDate);
	var timeSinceCommentWasCreated = nowInMilliseconds-commentDate;
	var fifteenMinutes = 15*60*1000;
	var links = '<div id="links-'+id+'" class="comments-actions">';
	if (timeSinceCommentWasCreated<fifteenMinutes) {
		var comment = $(this).attr('comment');
		links+= '<a '
		links+= 'href="javascript:comments_frontend_start_edit'
		+'('+id+', \''+comment+'\');">edit</a> ';
	}
	links+= '<a href="javascript:comments_frontend_start_delete('+id+');">';
	links+= '[x]</a>';
	links+= '</div>';
	$(links).insertBefore('#comment-info-'+id);
});
$('div.comment-editable').live('mouseout',function(e) {
	var id = e.target.id;
	if(!/^comment-wrapper-[0-9]*$/.test(e.target.id)){
		return;
	}
	$("#links-"+($(this).attr('id')).replace(/comment-wrapper-/,'')).remove();
});
function comments_check_captcha() {
	if (window.comments_noCaptchas) {
		return comments_check_success({status:1});
	}
	var correct = $('#recaptcha_challenge_field').val();
	var response = $('#recaptcha_response_field').val();
	$.post(
		'/ww.plugins/comments/frontend/check-captcha.php',
		{
			"challenge":correct,
			"response":response
		},
		comments_check_success
	);
}
function comments_check_success(data) {
	if (data.status) {
		comments_insert_get_vals();
	}
	else {
		alert('The letters you provided do not match the image');
	}
}
function comments_insert_get_vals() {
	var name = $('#comments-name-input').val();
	var email = $('#comments-email-input').val();
	var site = $('#comments-site-input').val();
	var page = $('#comments-page-id').val();
	var comment = $('#comments-comment-input').val();
	comment = trim(comment);
	$.post(
		'/ww.plugins/comments/frontend/insert.php',
		{
			"name":name,
			"email":email,
			"site":site,
			"page":page,
			"comment":comment
		},
		comments_display_thank_you_message,
		"json"
	);
}
function comments_display_thank_you_message(data) {
	if (!data.status) {
		return alert(data.message);
	}
	alert(data.moderated?'Thank you - your comment has been received and will be uploaded as soon as possible':'Thank you for commenting');
	document.location=document.location.toString();
}
function comments_frontend_start_delete(id) {
	if (confirm('Are you sure you want to delete this comment?')) {
		$.post(
			'/ww.plugins/comments/frontend/delete.php',
			{
				"id":id
			},
			function(){
				document.location=document.location.toString();
			}
		);
	}
}
function comments_frontend_start_edit(id, comment) {
	$('#comment-'+id).remove();
	$(
		'<div id="comment-edit"><input type="hidden" id="id" value="'+id+'" />'
		+'<textarea id="comment-text">'+comment+'</textarea><br />'
		+'<input type="button" value="Save" '
		+'onclick="javascript:comments_edit_get_vals();" /></div>'
	)
	.insertAfter('#comment-info-'+id);
}
function comments_edit_get_vals() {
	var id = $('#id').val();
	var comment = $('#comment-text').val();
	comment = trim(comment);
	if (comment==null) {
		return alert('The comment must contain some text');
	}
	$.post(
		'/ww.plugins/comments/frontend/edit-comment.php',
		{
			"id":id,
			"comment":comment
		},
		comments_frontend_update_comment,
		"json"
	);
}
function comments_frontend_update_comment(data) {
	$('<div id="comment-'+data.id+'>'+htmlspecialchars(data.comment)+'</div>')
	.insertBefore('#comment-edit');
	$('#'+data.id).attr('comment', htmlspecialchars(data.comment));
	$('#comment-edit').remove();
}
function trim(myString) {
	return myString.replace(/^\s+|\s+$/g, '');
}
;
