
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));
}

function newPost( section_id , topic_id )
{
  var user_id = getCookie("user_id");
  if( !user_id ) {
    var answer = confirm( "Please, login before making new posts. \nPush OK to login." );
    if( answer ) {
      href = document.location.href;
      href = href.replace( "&" , "%26" );
      document.location.href = '../login.php?back=' + href;
    }
  } else {
    document.location.href = 'workshop_new_post.php?section=' + section_id+'&topic='+topic_id;
  }
}


function newReply( section_id , topic_id , post_id )
{
  var user_id = getCookie("user_id");
  if( !user_id ) {
  	var answer = confirm( "Please, login before making new replies. \nPush OK to login." );
  	if( answer ) {
  	  href = document.location.href;
  	  href = href.replace( "&" , "%26" );
  	  document.location.href = 'login.php?back=' + href;
  	}
  } else {
	document.location.href = 'workshop_new_reply.php?section=' + section_id + '&topic=' + topic_id + '&post=' + post_id;
  }
}


function hide_open3( row_name , row_img_name , row2_name )
{
  var row  = document.getElementById( row_name );
  var row2 = document.getElementById( row2_name );
  var row_img = document.getElementById( row_img_name );
	
  if( row.style.display=='' ) {
    row.style.display='none';
    row2.style.display='none';
    row_img.src = 'http://www.algebraforum.org/ForumImages/open.gif';
  } else {
    row.style.display='';
    row2.style.display='';
    row_img.src = 'http://www.algebraforum.org/ForumImages/close.gif';
  }

}


function hide_open( row_name , row_img_name )
{
  var row = document.getElementById( row_name );
  var row_img = document.getElementById( row_img_name );
	
 if( row.style.display=='' ) {
    row.style.display='none';
    row_img.src = 'http://www.algebraforum.org/ForumImages/open.gif';
  } else {
    row.style.display='';
    row_img.src = 'http://www.algebraforum.org/ForumImages/close.gif';
  }

}

function remove_post( section_id , topic_id , post_id )
{
  if( confirm( "Click OK to remove the post." ) ) {
    href = document.location.href;
    href = href.replace( "&" , "%26" );
    document.location.href = "http://www.algebraforum.org/remove_post.php?section_id=" + section_id + "&topic_id=" + topic_id + "&post_id=" + post_id + "&back=" + href;
  }
}

