
function adhoc_themer(el) {
	var dd = el.form.parentNode.getElementsByTagName('dd')[0];
	var bgc = el.options[ el.selectedIndex ].title.split('|')[0];
	var col = el.options[ el.selectedIndex ].title.split('|')[1];
	dd.style.backgroundColor = bgc;
	dd.style.color = col;
}

function approveit(el) {
	el.parentNode.className = '';
	document.getElementById('tempdd').className='';
	el.parentNode.removeChild(el);
	return false;
}
function deleteit(el) {
	el = el.parentNode;
	if( confirm( 'Sure to DELETE article?\n' + el.getElementsByTagName('a')[1 + ('not-approved'==el.className)].innerHTML )) {
		var list = el.parentNode.getElementsByTagName('dt');
		var pos = 0;
		for( i = 0; i < list.length; i++ ) {
			if( list[i] == el ) { pos = i; }
		}
		list = el.parentNode.getElementsByTagName('dd');
		$( list[pos] ).hide('slow');
		$( el ).hide('slow');
		setTimeout( function() {
				el.parentNode.removeChild( list[pos] );
				el.parentNode.removeChild( el );
			}, 1000 );
	}
	return false;
}
function activateSDR()
{
	el = document.getElementById("sdr");
	if (el.className=='inactive') {
		el.className = "active";
	} else {
		el.className = "inactive";
	}
}

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.help = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;
		var title;
	/* END CONFIG */		
	$("a.help").hover(function(e){											  
		title = this.title;
		this.title = "";
		$("body").append("<div id='help' class='help'><p>"+ title +"</p><!--[if lte IE 6.5]><iframe></iframe><![endif]--></div>");
		$("div#help")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    	},
	function(){
		this.title = title;		
		$("#help").remove();//fadeOut("fast");
    });	
	$("a.help").mousemove(function(e){
		$("div#help")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	help();
	$("tr.toggler").toggleEvent();
	var count;
});

jQuery.fn.vcenter = function () {
	this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	// this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	return this;
}
function popup_toggle(toggle, popup) {
	//document.getElementById(popup).style.display = toggle ? 'block' : 'none';
	if( toggle ) {
		$('#'+popup).vcenter();
		$('#'+popup).fadeIn()
	} else {
		$('#'+popup).fadeOut('slow')
	}
	return false;
}
function send_to_friend() {
	document.getElementById('send-to-friend').getElementsByTagName('form')[0].uri.value = document.location.href;
	popup_toggle(true, 'send-to-friend');
}

/* validation */
function is_filled(v) { return 0 < v.replace(/\s+$/, '').length; }
function is_email(v) {
	return (
		   4 < v.length
		&& 1 < v.indexOf(     '@' )
		&& 3 < v.lastIndexOf( '.' )
		&&     v.lastIndexOf( '.' ) < (v.length - 1)
		)
		? true
		: false
		;
}
// ====================
// = PROFILE TOGGLING =
// ====================

jQuery.fn.toggleEvent = function() {

	return this.each(function(){
		var caller = this;
		var pref = "tr."+caller.id;
		$(caller).click(function (event) {	
			if ($(caller).hasClass("inactive"))
			{
				$(caller).removeClass("inactive");
				$("tr."+caller.id+" td input").attr("checked","checked");
				if($(pref).hasClass("hidden")){$(pref).removeClass("hidden");}
				if($(pref).hasClass("inactive")){$(pref).removeClass("inactive");}
				$("tr#"+caller.id+" td input").attr("checked","checked"); 
			} else
			{
				$(caller).addClass("inactive");
				$("tr."+caller.id+" td input").removeAttr("checked");
				$(pref).addClass("hidden");
				$("tr#"+caller.id+" td input").removeAttr("checked");
			}
		})
	})
}