function advance_editor(obj_self,obj_id)
{
	var obj=document.getElementById(obj_id);
	//for default is hide
	if(obj.style.display=="" || obj.style.display=="none")
	{//to show
		obj.style.display="block";
		obj_self.innerHTML="hide";
	}
	else
	{
		obj.style.display="none";
		obj_self.innerHTML="Add pictures and video to your post";
	}
	/*
	//for default is show
	if(obj.style.display=="" || obj.style.display=="block")
	{
		obj.style.display="none";
		obj_self.innerHTML="... more";
	}
	else
	{//to show
		obj.style.display="block";
		obj_self.innerHTML=" hide";
	}
	*/
}
function pager_submit(page_num)
{
alert(document.forms[1].name);	
}
function poor_selector(obj,new_url)
{
window.location.href='admin.php?option=Poor%20Taste&amp;sort='+obj.options[obj.selectedIndex].value;
}
//type 1 is for topic pager (reverse pager) 0 is for reply pager
function goto_page(page_url,obj_id,tail,ttp,type)
{
	document.getElementById(obj_id)
	var pg_n=document.getElementById(obj_id).value;
	if (type)	pg_n=ttp-pg_n+1
	page_url+=(pg_n+".html"+tail);
	window.location.href=page_url;
}
function goto_page_admin(page_url,obj_id,ipp)
{
	document.getElementById(obj_id)
	var pg_n=document.getElementById(obj_id).value;
	page_url+=("&page="+pg_n+"&ipp="+ipp);
	window.location.href=page_url;
}
//for select item per page
function select_ipp(page_url,obj)
{
	page_url+=("&ipp="+obj.options[obj.selectedIndex].value);
	window.location.href=page_url;
}
//for select min signup times for protential spammers
function select_mst(page_url,obj)
{
	page_url+=("&count="+obj.options[obj.selectedIndex].value);
	window.location.href=page_url;
}
//for selector 
function goto_page_v2(page_url,obj,tail)
{
	page_url+=obj.options[obj.selectedIndex].value+".html"+tail;
	window.location.href=page_url;
}
function day_filler(day_id,month_id,year_id)
		{
			
			var day=document.getElementsByName(day_id)[0];
			var month=document.getElementsByName(month_id)[0];
			var year=document.getElementsByName(year_id)[0];
			//in javascript Jan is 0	
			var days=32-new Date(year.options[year.selectedIndex].value,month.options[month.selectedIndex].value-1 , 32).getDate();
			var selected_day=day.selectedIndex;
			//alert(selected_day);
			if (day.length>1)
			{//clear the existing list			
				//remove from the last to the first
				for (i=day.length;i>=0;i--)
					 day.remove(i)
			}	
			for (i=1;i<=days;i++)
			{//add new ones
				var add_day=document.createElement('option');
				add_day.text=i;
				add_day.value=i;
				try
				{
					day.add(add_day,null) //standards
				}
				catch (ex)
				{
					day.add(add_day) //only for IE
				}


			}
			//set the selection back
			if (selected_day<day.length) 
				day.selectedIndex=selected_day;
		}
function checkRadioButton(radio_name,btn_name)
{
			var radio=document.getElementsByName(radio_name);
			for (var i=0;i<radio.length;i++)
			{
				if (radio[i].value==btn_name) radio[i].checked=true;
			}
			//alternative document.report.elements[button_name][1].checked = true; 
}
	//generate the domain or doctor list
function nav_control(ul_id)
{
	
	var img_name="img_"+ul_id;
	var ul=document.getElementById(ul_id);
	var img=document.getElementsByName(img_name)[0];

	nav_sub_control(ul,img);

}
function nav_sub_control(ob_ul,ob_img)
{
	if (ob_ul)
	{
		if (ob_ul.style.display=="block")
		{
			ob_img.src="../image/cat_close.gif";
			ob_ul.style.display="none";			
		}
		else 
		{
			ob_img.src="../image/cat_open.png";
			ob_ul.style.display="block";		
		}		

	}	
}
//select/unselect all the posts by user
function select_all(form_name,cur_check,chk_key)
{
	var all_elements=document.getElementsByName(form_name)[0];

	var cur_status=document.getElementsByName(cur_check)[0].checked;
	for (var i=0;i<all_elements.length;i++)
	{
	
		if (all_elements.elements[i].name.indexOf(chk_key)!=-1 && all_elements.elements[i].type=='checkbox')
		{
			all_elements.elements[i].checked=cur_status;
		}		
	}

}
//Javascript for txtEditor
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//scripts for javascrpt
function InitToolbarButtons() {
  var kids = document.getElementsByTagName('DIV');

  for (var i=0; i < kids.length; i++) {
    if (kids[i].className == "imagebutton") {
      kids[i].onmouseover = tbmouseover;
      kids[i].onmouseout = tbmouseout;
      kids[i].onmousedown = tbmousedown;
      kids[i].onmouseup = tbmouseup;
      kids[i].onclick = tbclick;
    }
  }
}

function tbmousedown(e)
{
  var evt = e ? e : window.event; 

  this.firstChild.style.left = 2;
  this.firstChild.style.top = 2;
  this.style.border="inset 2px";//changeable
  if (evt.returnValue) {
    evt.returnValue = false;
  } else if (evt.preventDefault) {
    evt.preventDefault( );
  } else {
    return false;
  }
}

function tbmouseup()
{
  this.firstChild.style.left = 1;
  this.firstChild.style.top = 1;
  this.style.border="outset 2px";
}

function tbmouseout()
{
  this.style.border="solid 2px #889F83";
}

function tbmouseover()
{
  this.style.border="outset 2px";
}

 
//use to get the top offset of the passed node
function getOffsetTop(elm) {

  var mOffsetTop = elm.offsetTop;
  var mOffsetParent = elm.offsetParent;

  while(mOffsetParent){
    mOffsetTop += mOffsetParent.offsetTop;
    mOffsetParent = mOffsetParent.offsetParent;
  }
 
  return mOffsetTop;
}
//use to get the left offset of the passed node
function getOffsetLeft(elm) {

  var mOffsetLeft = elm.offsetLeft;
  var mOffsetParent = elm.offsetParent;

  while(mOffsetParent){
    mOffsetLeft += mOffsetParent.offsetLeft;
    mOffsetParent = mOffsetParent.offsetParent;
  }
 
  return mOffsetLeft;
}

function tbclick()
{

  if ((this.id == "red" || this.id == "blue" || this.id == "black" || this.id == "green")) {
	document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand("forecolor", false, this.id);
  }
  else {
    document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand(this.id, false, null);
  }
}

function Select(selectname)
{
  var cursel = document.getElementById(selectname).selectedIndex;
  /* First one is always a label */
  if (cursel != 0) {
    var selected = document.getElementById(selectname).options[cursel].value;
    document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand(selectname, false, selected);
    document.getElementById(selectname).selectedIndex = 0;
  }
  document.getElementById("forum_txteditor_edit").contentWindow.focus();
}

function dismisscolorpalette()
{
  document.getElementById("colorpalette").style.visibility="hidden";
}

function Start() 
{
	if (document.getElementById('forum_txteditor_edit'))
	{
	  document.getElementById('forum_txteditor_edit').contentWindow.document.designMode = "on";
	  try 
	  {
		document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand("undo", false, null);
	  } 
	  catch (e) 
	  {
		alert("This editor is not supported on your version of explorer.");
	  }
	  InitToolbarButtons();
	}
}
function viewsource(source)
{
  var html;
  if (source) {
	if (document.addEventListener)
	{
		html = document.createTextNode(document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML);
		document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML = "";
		//the importNode only works for O not IE and F
	   // html = document.getElementById('forum_txteditor_edit').contentWindow.document.importNode(html,false);
		document.getElementById('forum_txteditor_edit').contentWindow.document.body.appendChild(html);
		//document.getElementById("toolbar1").style.visibility="hidden";
	}
	else if (document.attachEvent) 
	{
	 	iHTML = document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML;
		document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerText = iHTML;
	}

    document.getElementById("toolbar2").style.visibility="hidden";

  } else {
  	if (document.addEventListener)
	{
		html = document.getElementById('forum_txteditor_edit').contentWindow.document.body.ownerDocument.createRange();
		html.selectNodeContents(document.getElementById('forum_txteditor_edit').contentWindow.document.body);
		document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML = html.toString();
	}
	else if (document.attachEvent) 
	{
		iText = document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerText;
		document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML = iText;
	}

    //document.getElementById("toolbar1").style.visibility="visible";
    document.getElementById("toolbar2").style.visibility="visible";  
  }
}
//used for transfering content on the iframe to a textarea
//works but find a better solution which is to add overflow:hidden to the td
function fire(form_name,frame_name)
{
	var max_len=24;
	var cur_form=document.getElementById(form_name);	
	var input_frame=document.getElementById(frame_name);	
	var new_textarea=document.createElement('textarea');
	new_textarea.name="reply";
	if (document.getElementById('source_flag').checked)
	{
		document.getElementById('source_flag').checked=false;
		viewsource(false);
	}

	new_textarea.value= document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML;
	new_textarea.style.display="none";
	cur_form.appendChild(new_textarea);
}
//used for transfering content on the iframe to a textarea
//works but find a better solution which is to add overflow:hidden to the td
function fire_v2(form_name,frame_name)
{
	var max_len=24;
	var cur_form=document.getElementById(form_name);	
	var input_frame=document.getElementById(frame_name);	
	var new_textarea=document.createElement('textarea');
	new_textarea.name="reply";
	if (document.getElementById('source_flag').checked)
	{
		document.getElementById('source_flag').checked=false;
		viewsource(false);
	}
		//alert(document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerText);
		//new_textarea.value= document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerText;
var str=document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerText.split(" ");
var new_str="";
var count=0;
var flag=0;
for (i=0; i<str.length; i++)
{
	if (count=Math.floor(str[i].length/(max_len+0.1)))
	{
		flag=1;
		for(i1=1;i1<=count;i1++)
			str[i]=str[i].slice(0,(i1*max_len+i1-1))+" "+str[i].slice((i1*max_len+i1-1));
	}
	new_str+=(str[i]+" ");
	//if (str[i].length>)
	//str[i].slice
}

if (flag)
	new_textarea.value=new_str;
else 
	new_textarea.value= document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML;
			//alert(document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML);
//alert(new_textarea.value);
//new_textarea.value= document.getElementById('forum_txteditor_edit').contentWindow.document.body.innerHTML;

	new_textarea.style.display="none";
	cur_form.appendChild(new_textarea);
//	return false;
}
function alert_mesg($mesg,$new_url)
{
	if (window.confirm($mesg))
		this.location.href=$new_url;
}
//for fill 
function fill_up(source_id,iframe_name)
{
	if (window.frames[iframe_name])
	{
		window.frames[iframe_name].document.open();
		window.frames[iframe_name].document.write(document.getElementById(source_id).value);
		window.frames[iframe_name].document.close();
		  if (document.addEventListener)
		  {
			  //document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand("styleWithCSS", false , true);
			  try 
			  { 
				 document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand( 'styleWithCSS', false, false ) ; 
			  } 
			  catch (e) 
			  { 
				 document.getElementById('forum_txteditor_edit').contentWindow.document.execCommand( 'useCSS', false, true ) ; 
			  }
		  }
	}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//End of Javascript for txtEditor
