
function disable(obj) {
	obj.disabled = true;
}

function menu_h(obj) {
	obj.bgColor = 'white';
	obj.style.color = '#df0024';
}

function menu_n(obj) {
	obj.bgColor = '';
	obj.style.color = '';
}

function navi(to_where) {
	if (to_where.indexOf('.php') != -1) {
		// Navigate to url
		window.location = to_where;
	} else {
		// Submenus
		table_submenu = document.getElementById('sub_menu');
		if (table_submenu != null) {
			table_submenu.style.display = 'block';
			
			submenu_content = document.getElementById('sub_menu_content');
			
			if (to_where == 'whoson') {
				sub_nav_txt = '<a href="whoson.php">Всички Потребители</a> | <a href="whoson.php?Friends=yes">Моите Приятели</a>';
				
				spaces = 70;
				
			} else if (to_where == 'story') {
				sub_nav_txt = '<a href="story.php">Всички</a> | ' + 
											'<a href="story.php?CatID=2">Влюбих се</a> | ' +
											'<a href="story.php?CatID=9">Здраве</a> | ' +
											'<a href="story.php?CatID=1">Изневяра</a> | ' +
											'<a href="story.php?CatID=3">Интимно</a> | ' +
											'<a href="story.php?CatID=8">Послания</a> | ' +
											'<a href="story.php?CatID=7">Проблеми</a> | ' +
											'<a href="story.php?CatID=5">Ревност</a> | ' +
											'<a href="story.php?CatID=6">Самота</a> | ' +
											'<a href="story.php?CatID=4">Споделено</a> | ' +
											'<a href="story_submit.php"><b>Изпрати История</b></a>';
											
				spaces = 3;
											
			} else if (to_where == 'myaccount') {
				sub_nav_txt = '<a href="myaccount.php">Акаунт</a> | ' + 
											'<a href="myprofile.php">Профил</a> | ' +
											'<a href="mygallery.php">Снимки</a> | ' +
											'<a href="myvideo.php">Видео</a> | ' +
											'<a href="mynotify.php">Известия</a> | ' +
											'<a href="myfriends.php">Приятели</a> | ' +
											'<a href="myplus.php">priateliПЛЮС</a> | ' +
											'<a href="myerase.php">Изтриване</a>';
											
				spaces = 30;
											
			} else if (to_where == 'search') {
				sub_nav_txt = '<a href="search.php?Force=simple">Опростено Търсене</a> | ' + 
											'<a href="search.php?Force=adv">Разширено Търсене</a> | ' +
											'<a href="search.php?Force=byname">Търсене по Име</a> | ' +
											'<a href="search.php?Force=bytemplate">Моето Търсене</a>';
				spaces = 40;

			}
			
			padding_spaces = '';
			
			for (z = 0; z < spaces; z++) {
				padding_spaces = padding_spaces + '&nbsp;';
			}
			
			
			submenu_content.innerHTML = padding_spaces + sub_nav_txt;
		}
		// Then navigate to url
		//window.location = to_where + '.php';		
		
	}

}


function pic_view(pic,winh,winw) {
  var w_h = screen.height - 100;
  var w_w = screen.width  - 25;
  
  if (winh + 20 < w_h) w_h = winh + 20;
  if (winw + 20 < w_w) w_w = winw + 20;
    
  window.open(pic,
              "PIC_VIEW",
              "toolbar=no,height=" + w_h + ",width=" + w_w);
}

function open_profile(id) {
	window.open('profile.php?'+id,'_parent');
}

function change_status() {
  var f = document.form_status;
  f.submit();
}


/*****************************************************************************************************************************************/

/*** Mailcounter ***/
var msgs_count = null;
var friends_count = null;

/*** Mailcheck, friendcheck and usercheck loops ***/
function showOnlineChecks() {
  var myajax = ajaxpack.ajaxobj;
  if (myajax.readyState == 4) {
    if (myajax.status == 200 || window.location.href.indexOf("http") == -1) {
      var split_info = myajax.responseText.split(',');
      var div_msgs = document.getElementById('div_msgs');
      var div_online = document.getElementById('div_online');
			// Abort if some div is null
			if (div_msgs == null || div_online == null) {
				return;
			}
			
      // Output number of new msgs.
      if (split_info[0] > 0) {
        var msg_str_new; msg_str_new = (split_info[0] == 1) ? 'ново' : 'нови';
        var msg_str_msg; msg_str_msg = (split_info[0] == 1) ? 'е'    : 'я';
        div_msgs.style.color = 'red';
        div_msgs.innerHTML = split_info[0] + ' ' + msg_str_new + ' съобщени' + msg_str_msg;
        // Do sound notification.
        var sound_obj = '<object type="application/x-shockwave-flash" data="emff.swf?src=music/newmsg' + split_info[3] + '.mp3&amp;autostart=yes&amp;streaming=yes" width="0" height="0"> ' +
                        ' <param name="movie" value="emff.swf?src=music/newmsg' + split_info[3] + '.mp3&amp;autostart=yes&amp;streaming=yes" /> ' +
                        ' <param name="autostart" value="yes" /> ' +
                        ' <param name="streaming" value="yes" /> ' +
                        '</object>';
        var div_sound_alert = document.getElementById('div_sound_alert');
        if (msgs_count === null) {
          msgs_count = split_info[0];
        }        
        if (split_info[0] > msgs_count) {
          if (split_info[3] > 0) {
            div_sound_alert.innerHTML = sound_obj;
          }         
          msgs_count = split_info[0];
        }        
      } else {
        div_msgs.style.color = 'black';
        div_msgs.innerHTML = 'Няма съобщения';
        msgs_count = 0;
      }
      // Audible signal for friend online/offline.
      if (friends_count === null) {
        friends_count = split_info[2];
      }
      if (split_info[2] > friends_count) {
        //alert('came online');
        friends_count = split_info[2];
      }
      if (split_info[2] < friends_count) {
        //alert('went offline');
        friends_count = split_info[2];
      }
      var str_friends; str_friends = (split_info[2] == 1) ? 'приятел' : 'приятели';
      div_online.innerHTML = split_info[1] + ' онлайн / ' + split_info[2] + ' ' + str_friends;      
    }
  }
}
function loopChecks() {
  ajaxpack.getAjaxRequest("ajax.php","Command=OnlineChecks",showOnlineChecks,"txt");
  setTimeout("loopChecks()",30000);
}

// Initial mail check.
function updateMailsCount() {
  var myajax = ajaxpack.ajaxobj;
  if (myajax.readyState == 4) {
    if (myajax.status == 200 || window.location.href.indexOf("http") == -1) {
      var split_info = myajax.responseText.split(',');
      msgs_count = split_info[0];
    }
  } 
}
function mailCheck() {
  if (document.getElementById("div_msgs") !== null) {
    ajaxpack.getAjaxRequest("ajax.php","Command=OnlineChecks",updateMailsCount,"txt");
  }
}

function jsOnloadRoutines() {
  if (document.getElementById("div_msgs") !== null) {
    loopChecks();
  }
}

/*****************************************************************************************************************************/

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}




