// <blogde> added by dl
function F() {
	return document.forms[0];
}
// </blogde>

// <blogde> added by fw

//Default browsercheck

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}

//With nested layers for netscape, this function hides the layer if it's visible and visa versa
function showHide(div,nest){
	bw=new checkBrowser()
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	//obj = document.getElementById(div).style;

	//if(obj.visibility=='visible' || obj.visibility=='show') obj.visibility='hidden'
	//else obj.visibility='visible'

	if(obj.display=='block' || obj.display=='block') obj.display='none'
	else obj.display='block'
}
//Shows the div
function show(div,nest){
	bw=new checkBrowser()
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='visible'
}

function showBlock(div,nest){
	bw=new checkBrowser()
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='block'
}

//Hides the div
function hideBlock(div,nest){
	bw=new checkBrowser()
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='none'
}

function hide(div,nest){
	bw=new checkBrowser()
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='hidden'
}

function switchSelection(value)
{
	if (value=='friends') {
		showBlock('friends_div');
	} else {
		hideBlock('friends_div');
	}
}

function checkAll(grp_id, checked) {
	setStatusFriends();
	grpDiv = document.getElementById(grp_id);
	elements = grpDiv.getElementsByTagName('input');
	for (i=0; i < elements.length; i++) {
		elements[i].checked=checked;
	}
	checkGroups();
}

function checkAll2(grp_id, checked) {
	grpDiv = document.getElementById(grp_id);
	elements = grpDiv.getElementsByTagName('input');
	for (i=0; i < elements.length; i++) {
		elements[i].checked=checked;
	}
	checkGroups();
}


function checkAll3(grp_id, checked) {
	grpDiv = document.getElementById(grp_id);
	elements = grpDiv.getElementsByTagName('input');
	for (i=0; i < elements.length; i++) {
		elements[i].checked=checked;
	}
}

function openGroup(grp_id, link_elem, img_dir) {
	showHide(grp_id);
	// change icon for link_elem
	if (link_elem == '') {
		link_elem = document.getElementById('plusminus_' + grp_id.split('_')[1]);
	}
	elements = link_elem.getElementsByTagName('img');
	if (elements.length>0) {
		if (elements[0].src==img_dir+'icon_minus.gif') {
			elements[0].src=img_dir+'icon_plus.gif';
			return false;
		} else {
			elements[0].src=img_dir+'icon_minus.gif';
			return true;
		}
	}
}

function setStatusFriends() {
	friendsSelect = document.getElementById('friendsSelected');
	if (friendsSelect) {
		friendsSelect.checked=true;
	}
}

// <blogde> added by ms
function checkGroup(grp_id) {
	var grp = document.getElementById('fgrp_' + grp_id);
	var elements = grp.getElementsByTagName('input');
	var i=0;
	var count = 0;
	if (elements) {
		for (i=0; i<elements.length; i++) {
			if (elements[i].checked) {
				count++;
			}
		}
		if (count == elements.length) {
			document.getElementById('chk_' + grp_id).checked = true;
		} else {
			document.getElementById('chk_' + grp_id).checked = false;
		}
		return true;
	}
	else return false;
}

function checkGroups() {
	var i=0;
	var grps = document.getElementById('fgrps');
	var elements = grps.getElementsByTagName('div');
	for (i=0; i<elements.length; i++) {
		id = elements[i].id.split('_');
		checkGroup(id[1]);
	}
}

function checkFriend(id, checked) {
	var i=0;
	var friends = document.getElementsByName('selectedFriends[#' + id + '#]');
	for (i=0; i<friends.length; i++) {
		friends[i].checked = checked;
	}
}

function checkFriends(grp_id, checked) {
	var i=0;
	var grp = document.getElementById('fgrp_' + grp_id);
	var elements = grp.getElementsByTagName('input');
	if (elements) {
		for (i=0; i < elements.length; i++) {
			var parts = elements[i].name.split('#');
			checkFriend(parts[1],checked);
		}
	}	
	checkGroups();
}

function checkBodylist(form) {
	if (typeof document.uploadform != 'undefined' && document.getElementById('privacy_friends').checked != true) { return true; }
	else if (typeof document.edit != 'undefined') {
		for (i=0; i < document.edit.item_privacy.length; i++) {
			if (document.edit.item_privacy[i].checked == true && document.edit.item_privacy[i].value != '1') {
				return true;
			}
		}
	}
	else if (typeof document.post != 'undefined') {
		for (i=0; i < document.post.post_status.length; i++) {
			if (document.post.post_status[i].checked == true && document.post.post_status[i].value != 'friends') {
				return true;
			}
		}
	}
	var count_checked = 0;
	var bodylist = document.getElementById('fgrps');
	var elements = bodylist.getElementsByTagName('input');
	if (elements) {
		for (i=0; i < elements.length; i++) {
			if (elements[i].checked == 1) { count_checked++; }
		}
	}
	if (count_checked == 0) {
		alert(bl_nofriend);
		return false;
	}
	else {
		return true;
	}
}

function activateAll() {
	var bodylist = document.getElementById('fgrps');
	var elements = bodylist.getElementsByTagName('input');
	if (elements) {
		for (i=0; i < elements.length; i++) {
			elements[i].checked = 1;
		}
	}
}

function deactivateAll() {
	var bodylist = document.getElementById('fgrps');
	var elements = bodylist.getElementsByTagName('input');
	if (elements) {
		for (i=0; i < elements.length; i++) {
			elements[i].checked = 0;
		}
	}
}


function colexpGroup(grp_id, link_elem, img_dir) {
	if (expanded_groups) {
		if (openGroup(grp_id, link_elem, img_dir)) {
			expanded_groups[grp_id] = true;
			grptag_session(grp_id,1) ;
		} else {
			expanded_groups[grp_id] = false;
			grptag_session(grp_id,0) ;
		}
	}
}

function grptag_session(grp_id, elem_value)
{
	new Ajax.Updater('', 'options.php', {method: 'get', parameters: 'action=setsession&grp_name=' +grp_id+ '&grp_value='+elem_value, evalScripts: true});
}

function colexpGroups() {
	if (!baseurl) return false;
	
	var i=0;
	var grps = document.getElementById('fgrps');
	var elements = grps.getElementsByTagName('div');
	for (i=0; i<elements.length; i++) {
		var element_name = elements[i].getAttribute('id');
		if (expanded_groups[element_name]) {
			openGroup(element_name, '', baseurl + '/img/icons/');
		}
	}
}
// </blogde>


function openWindow(url)
{
	newWindow = window.open(url,'window','width=574,height=380,left=50,top=50,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
	newWindow.focus();
}


function openWindowSized(url, myTitle, myWidth, myHeight) {
	newWindow = window.open(url, myTitle, 'width = '+myWidth+', height = '+myHeight+',left=50,top=50,toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
	newWindow.focus();
}

function bdOpenWindow(url)
{
	newWindow = window.open(url,'window','width=574,height=380,left=50,top=50,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
	newWindow.focus();
}
// </blogde>

//<blogde> coded by jasvir
function OpenIcon(url) {
	var Iconwindow;
	Iconwindow=window.open(url,"Choose Icon",'height=300,width=200,left=100,top=300,screenX=100,screenY=300');
	Iconwindow.focus();

}

function CloseIcon()
{
  self.close();
}

// function used to change the icon in the document directly
function changeIcon()
{
//  opener.location.reload(true);
  Iconwindow=window.open("http://www.yahoo.com","Choose Icon",'height=300,width=200,left=100,top=300,screenX=100,screenY=300');
  doc = opener.document.getElementById('icons');
  elements = doc.getElementsByTagName('img');
  if (elements.length>0) {
    elements[0].src = '/blogde/www/jasvir/img/icons/icon_friend_1.gif';
  }
}
//</blogde> coded by jasvir

/*
 * javascript open_preview()
 * opens preview window
 *
 * @author Dami Falasinnu
 * @param form
 */
function open_preview(form)
{
	preview_window = window.open( '','','width=574,height=380,left=50,top=50,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes' );
	text = form.comment.value.replace(/\n/g, '<br />');
	preview_window.document.write(text);
	preview_window.document.write('<p><a href="javascript:window.close()">Close Window</a></p>');
	preview_window.focus();
}

function bdOpenWindowTrackback(url, form)
{
	param_tb = form.tb_id.value;
	param_code = form.code.value;
	url_new = url+'?tb_id='+param_tb+'&code='+param_code;
	newWindow = window.open(url_new,'window','width=500,height=300,left=50,top=50,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
	newWindow.focus();
}


function setFontBold(div,nest){
	bw=new checkBrowser();
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.fontWeight="bold";
}

function setFontNormal(div,nest){
	bw=new checkBrowser();
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.fontWeight="normal";
}

function textSelectToggleByName(link, targetname, snip)
{
	target = document.getElementsByName(targetname)[0];
	textSelectToggle(link, target, snip);
}

function textSelectToggle(link, target, snip)
{
	var string = target.value;
	var elements = string.split(',');
	var found = false;
	for(i=0;i<elements.length;i++)
	{
		if (elements[i] == '')
		{
			elements.splice(i,1)
		}
		else if (elements[i] == snip)
		{
			elements.splice(i,1)
			found = true;
			break;
		}
	}

	if (found == false)
	{
		elements.push(snip);
		link.style.fontSize = '14px';
		link.style.fontWeight = 'bold';
	}
	else
	{
		link.style.fontSize = '12px';
		link.style.fontWeight = 'normal';
	}

	elements.sort();
	target.value = elements.join(',');
}
// </blogde>





/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + 560000 : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


/**
 * Feeds
 *
 */

function openFeed(div_id, amount,feed_ID, post_ID, count) {

	for (i=0; i < amount; i++) {
		hideBlock('feed-detail-'+i);
		setBackgroundColor('feed-list-'+i, '#fff');
	}

	showHide('feed-detail-'+div_id);
	// #FFFFE0 yellow
	// #D8FED2 green
	setBackgroundColor('feed-list-'+div_id, '#DDFBE6');
	
	
	var p = document.getElementById('feed-list-'+count);
	if (p.className == 'item unread'){
		mark( feed_ID, post_ID, 'read', count);
	}
	
}

function openFeedAgg(div_id, amount,feed_ID, post_ID, count) {

	for (i=0; i < amount; i++) {
		hideBlock('feed-detail-'+i);
		setBackgroundColor('feed-list-'+i, '#fff');
	}

	showHide('feed-detail-'+div_id);
	// #FFFFE0 yellow
	// #D8FED2 green
	setBackgroundColor('feed-list-'+div_id, '#DDFBE6');
	
	
	var p = document.getElementById('feed-list-'+count);
	if (p.className == 'item unread'){
		markAgg( feed_ID, post_ID, 'read', count);
	}
	
}
/*
function openFeedAll(amount) {

	for (i=0; i < amount; i++) {
		showBlock('feed-detail-'+i);
		setBackgroundColor('feed-list-'+i, '#DDFBE6');
	}
}
*/

function setBackgroundColor(div,color,nest){
	bw=new checkBrowser();
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.background=color;
}

function feedOpenUnread(amount) {
	for (i=0; i < amount; i++) {
		hideBlock('feed-list-'+i);
		hideBlock('feed-detail-'+i);
		var o=document.getElementById('feed-list-'+i);
		if (cssClassActions('check',o,'unread')) {
			showBlock('feed-list-'+i);
			showBlock('feed-detail-'+i);
			setBackgroundColor('feed-list-'+i, '#DDFBE6');
			//cssClassActions('add',o,'hidden');
		}
	}
}

function feedOpenAll(amount) {

	for (i=0; i < amount; i++) {
		showBlock('feed-list-'+i);
		showBlock('feed-detail-'+i);
		setBackgroundColor('feed-list-'+i, '#DDFBE6');
	}
}

function cssClassActions(a,o,c1,c2)
{
  switch (a){
    case 'swap': // replaces class c1 with class c2 in object o
      o.className=!cssClassActions('check',o,c1)? o.className.replace(c2,c1): o.className.replace(c1,c2);
    break;
    case 'add': // adds class c1 to the object o
      if(!cssClassActions('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove': // removes class c1 from the object o
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check': // test if class c1 is already applied to object o and returns true or false
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}

/**
 * Rico
 * http://openrico.org/rico/downloads.page
 *
 */
document.getElementsByTagAndClassName = function(tagName, className) {
  if ( tagName == null )
     tagName = '*';

  var children = document.getElementsByTagName(tagName) || document.all;
  var elements = new Array();

  if ( className == null )
    return children;

  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }

  return elements;
}

function markall(feed_ID, amount) {
	
	if ( xajax_updateRssPostUser2( feed_ID,'', 'all') );
	{
		var v = document.getElementById('tags-'+feed_ID);
		var n = document.getElementById('names-'+feed_ID);

		v.title=0;
		
		var vs = document.getElementById('tag-'+feed_ID);
		var ns = document.getElementById('name-'+feed_ID);
		
		hide('viewlink');
		hide('marklink');
		cssClassActions('add',ns,'read');
		cssClassActions('add',vs,'read');
		cssClassActions('remove',v,'unread');
		cssClassActions('remove',n,'unread');	
		
		for  (var i = 0; i < amount; i++) {
			
			showBlock('feed-detail-markunread-'+i);
			hideBlock('feed-detail-markread-'+i);
				
			var o = document.getElementById('feed-detail-'+i);
			var p = document.getElementById('feed-list-'+i);
		
			cssClassActions('swap',o,o.className,'item read');
			cssClassActions('swap',p,p.className,'item read');
		}
			
	}
	
	feedOpenAll(amount);
}

function markallAgg(feedtag) {

	var feedids =  xajax_getTagFeedIds(feedtag);

	for(var i=0; i<feedids.length; i++){
		
		var feed_ID = feedids[i];
		
		if ( xajax_updateRssPostUserAgg( feed_ID,'', 'all') );
		{
			var v = document.getElementById('tags-'+feed_ID);
			var n = document.getElementById('names-'+feed_ID);
	
			v.title=0;
			
			var vs = document.getElementById('tag-'+feed_ID);
			var ns = document.getElementById('name-'+feed_ID);
			
			hide('viewlink');
			hide('marklink');
			cssClassActions('add',ns,'read');
			cssClassActions('add',vs,'read');
			cssClassActions('remove',v,'unread');
			cssClassActions('remove',n,'unread');	
			
			for  (var i = 0; i < 50; i++) {
				
				showBlock('feed-detail-markunread-'+i);
				hideBlock('feed-detail-markread-'+i);
				
				var o = document.getElementById('feed-detail-'+i);
				var p = document.getElementById('feed-list-'+i);
			
				cssClassActions('swap',o,o.className,'item read');
				cssClassActions('swap',p,p.className,'item read');
			}
				
		}
	}
	
	
}

function mark( feed_ID, post_ID, state, count) {
	
	if ( xajax_updateRssPostUser2( feed_ID, post_ID, state ) );
	{
		var v = document.getElementById('tags-'+feed_ID);
		var n = document.getElementById('names-'+feed_ID);
		if (state == 'unread')
		{ 
			//alert(v.className);
			//alert(v.title);
			showBlock('feed-detail-markread-'+count);
			hideBlock('feed-detail-markunread-'+count);
			
			if (v.title <= 0){
				
				var vs = document.getElementById('tag-'+feed_ID);
				var ns = document.getElementById('name-'+feed_ID);
				
				show('viewlink');
				show('marklink');
				cssClassActions('remove',ns,'read');
				cssClassActions('remove',vs,'read');
				cssClassActions('add',v,'unread');
				cssClassActions('add',n,'unread');
			}
			
			//alert(v.className);
			v.title++;
			//alert(v.title);
		}
		else
		{
			
			showBlock('feed-detail-markunread-'+count);
			hideBlock('feed-detail-markread-'+count);
			v.title--;
			if (v.title <= 0){
			
				var vs = document.getElementById('tag-'+feed_ID);
				var ns = document.getElementById('name-'+feed_ID);
				
				hide('viewlink');
				hide('marklink');
				cssClassActions('add',ns,'read');
				cssClassActions('add',vs,'read');
				cssClassActions('remove',v,'unread');
				cssClassActions('remove',n,'unread');	
			}
				
		}
		
		
		var o = document.getElementById('feed-detail-'+count);
		var p = document.getElementById('feed-list-'+count);
	
		cssClassActions('swap',o,o.className,'item '+state);
		cssClassActions('swap',p,p.className,'item '+state);

	}

}

function markAgg( feed_ID, post_ID, state, count) {
	
	var p = document.getElementById('view-agg');
	var unreadnum = p.title;
		
	if ( xajax_updateRssPostUserAgg( feed_ID, post_ID, state, unreadnum) );
	{
		var v = document.getElementById('tags-'+feed_ID);
		var n = document.getElementById('names-'+feed_ID);
		if (state == 'unread')
		{ 
			//alert(v.className);
			//alert(v.title);
			showBlock('feed-detail-markread-'+count);
			hideBlock('feed-detail-markunread-'+count);
			
			if (v.title <= 0){
				
				var vs = document.getElementById('tag-'+feed_ID);
				var ns = document.getElementById('name-'+feed_ID);
				
				show('viewlink');
				show('marklink');
				cssClassActions('remove',ns,'read');
				cssClassActions('remove',vs,'read');
				cssClassActions('add',v,'unread');
				cssClassActions('add',n,'unread');
			}
			
			//alert(v.className);
			v.title++;
			p.title++;
	
		}
		else
		{
			
			showBlock('feed-detail-markunread-'+count);
			hideBlock('feed-detail-markread-'+count);
			v.title--;
			p.title--;
			if (v.title <= 0){
			
				var vs = document.getElementById('tag-'+feed_ID);
				var ns = document.getElementById('name-'+feed_ID);

				cssClassActions('add',ns,'read');
				cssClassActions('add',vs,'read');
				cssClassActions('remove',v,'unread');
				cssClassActions('remove',n,'unread');	
			}
			
			if (p.title <= 0){	
							
				hide('viewlink');
				hide('marklink');
			}
		}
		
		
		var o = document.getElementById('feed-detail-'+count);
		var p = document.getElementById('feed-list-'+count);
	
		cssClassActions('swap',o,o.className,'item '+state);
		cssClassActions('swap',p,p.className,'item '+state);

	}

}

