height_menu_open = new Array();


sfHover = function() {
	var sfEls = document.getElementById("table").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
		
function close_div(div) {

	document.getElementById(div).style.overflow = 'hidden';
	close_recursive(div,0,null);
}
function close_recursive(div,recursive,function_at_end){
	
	//div_interval = div+'interval';
	div_opener_new(div);
	div_interval = get_opener_div_interval(div);
	
	if(div_interval == null || recursive == 1) {
		//alert("close recursive");
		var the_div = document.getElementById(div);
	
		var the_height = the_div.offsetHeight;
		var height = the_height;
		height_opener_div = get_opener_div_height(div);
		
		if(height_opener_div==0||height_opener_div==null) {
			set_opener_div_height(div,height);
		}
		
		//IMPORTANT THIS NEEDS TO BE 2 OTHERWISE INFINATE LOOP
		if(height > 2) {
			change = height / 4;
			the_div.style.height = height - change + 'px';
			//alert(the_div.style.height);
			
			/*header_tag = document.getElementById(div+'_header');
			if(header_tag!=null && header_tag.className!='underline_title_no_margin') {
				alert(header_tag.style.marginBottom);
				alert(header_tag.className);
				if(header_tag.style.marginBottom>0||header_tag.style.marginBottom=='') {
					alert("here");
					//header_tag.style.marginBottom = header_tag.style.marginBottom -1+'px';
				}
				else {
					header_tag.style.marginBottom = 'underline_title';
				}
			}*/
			
			div_interval = setTimeout('close_recursive(\''+div+'\',1,'+function_at_end+')',1);
			set_opener_div_interval(div,div_interval);
		}
		else {
		
			set_opener_div_interval(div,null);
			if(function_at_end!=null) {
				function_at_end(div);
			}
			the_div.style.height = "0px";
			/*header_tag = document.getElementById(div+'_header');
			if(header_tag!=null && header_tag.className!='') {
				header_tag.className = '';
			}*/
			
			
		
		}
	}
	else {
		
	}
}
function open_close_header_margin(div_title,open) {
	//open = true open to 10px
	//open = false close to 10px
	
	div = document.getElementById(div_title);
	
	if(open=true) {
		margin_to = 10;
	}
	else {
		margin_to = 0;
	}
	
	margin_bot = div.style.marginBottom;
	//alert(margin_bot);
	if(margin_bot==margin_to) {
		//done
		if(margin_to == 0) {
			div.className = 'underline_title_no_margin';
		}
		else {
			div.className = 'underline_title';
		}
		
	}
	else {
		if(margin_bot > margin_to) {
		//close
			div.style.marginBottom = margin_bot -1;
		}
		else {
			//open
			div.style.marginBottom = margin_bot +1;
		}
		setTimeout('open_close_header_margin(\''+div_title+'\','+open+')',1);
	}
	
	
	//if(div.style.marginBottom
}


function open_recursive(div,recursive,function_at_end) {
	/*IF YOUR ARE EXPERIENCING PROBLEMS THEN YOU MAY NEED TO SPECIFY A WIDTH TO HELP
		THIS WILL HAPPEN IN ELEMENTS THAT REQUIRE THE OUTER ELEMENT TO GIVE THE WIDTH.
	*/
	div_opener_new(div);
	div_interval = get_opener_div_interval(div);
	
	
	
	if(div_interval == null || recursive == 1) {
		var the_div = document.getElementById(div);
		
		div_height = get_opener_div_height(div);
		if(div_height == null || div_height == 0) {
			div_height = getHeight(the_div);
			set_opener_div_height(div,div_height);
		}
		header_tag = document.getElementById(div+'_header');
		/*if(header_tag!=null && header_tag.className!='underline_title') {
			//open_close_header_margin(div+'_header',false);
			header_tag.className = 'underline_title';
		}*/
	
		
		
		
		
		
		
		
		
		var the_height = the_div.style.height;
		if(the_height!='') {
			height = the_height.replace(/px/gi,"").valueOf();
			height = parseFloat(the_height);
		}
		else {
			height = the_height;
		}
		if(height == 0 || height == '') {
			height = 1;
		}
		//alert(div_height);
		change = height + (div_height-height) / 4;
		//ok ie is SHIT and can't do maths so hence this line is here
		diff = 1;
		if(navigator.appName=="Microsoft Internet Explorer") {
			diff = 3;
		}
		
		if(height<div_height && (change<(div_height-diff))) {
			new_height = change;
			
			the_div.style.display = "block";
			the_div.style.height = new_height + 'px';
			
			div_interval = setTimeout('open_recursive(\''+div+'\',1,'+function_at_end+')',1);
			set_opener_div_interval(div,div_interval);
			
		}
		else {
		
			//clearInterval(get_opener_div_interval(div));
			set_opener_div_interval(div,null);
			if(function_at_end!=null) {
				
			
				function_at_end(div);
			}
			
		}
	}
	else {
		
	}
	
	
}
function getHeight(el) {
	var s = el.style;
	var v = s.visibility;
	var p = s.position;
	var d = s.display;
	sh = s.height;
	elh = el.height;
	elw = el.width;
	el.width = el.offsetWidth;
	s.visibility = "hidden";
	s.position = "absolute";
	s.display = "block";
	s.height = "auto";
	el.height = "auto";
	var h = (parseInt(s.height)>0)? s.height: el.offsetHeight;
	el.width = elw;
	s.display = d;
	s.position = p;
	s.visibility = v;
	s.height = sh;
	el.height = elh;
	return h;
}
function getWidth(el) {
	var s = el.style;
	var v = s.visibility;
	var p = s.position;
	var d = s.display;
	sh = s.height;
	elh = el.height;
	elw = el.width;
	el.width = el.offsetWidth;
	s.visibility = "hidden";
	s.position = "absolute";
	s.display = "block";
	s.height = "auto";
	s.width = "auto";
	el.height = "auto";
	var w = (parseInt(s.width)>0)? s.width: el.offsetWidth;
	el.width = elw;
	s.display = d;
	s.position = p;
	s.visibility = v;
	s.height = sh;
	el.height = elh;
	return w;
}


function get_opener_div_interval(div) {
	for(var i=0;i<height_menu_open.length;i++) {
		if(height_menu_open[i].div_name==div) {
			return height_menu_open[i].div_interval;
		}
	}
	return 0;
}
function set_opener_div_interval(div,interval) {
	for(var i=0;i<height_menu_open.length;i++) {
		if(height_menu_open[i].div_name==div) {
			height_menu_open[i].div_interval = interval;
		}
	}
	return null;
}


function get_opener_div_height(div) {
	for(var i=0;i<height_menu_open.length;i++) {
		if(height_menu_open[i].div_name==div) {
			return height_menu_open[i].div_height;
		}
	}
	return null;
}
function set_opener_div_height(div,height) {
	for(var i=0;i<height_menu_open.length;i++) {
		if(height_menu_open[i].div_name==div) {
			height_menu_open[i].div_height = height;
		}
	}
	return null;
}



function div_opener_exists(div) {
	
	for(var i=0;i<height_menu_open;i++) {
		
		if(height_menu_open[i].div_name==div) {
			return true;
		}
	}
	return false;
}
function div_opener_new(div) {
	if(!div_opener_exists(div)) {
		div_object = new Object();
		div_object.div_name = div;
		div_object.div_interval = null;
		height_menu_open.push(div_object);
	}
}



function subnav_control(div){
	//div = 'subnav_block';
	action = document.getElementById(div+'_control').className;
	div_height = get_opener_div_height(div);
	if(action == 'subnav_control_close'){
		close_recursive(div,0,subnav_control_close);
	}
	else if(action == 'subnav_control_open') {
		open_recursive(div,0,subnav_control_open);
	}
}
function subnav_control_open(div) {
	if(document.getElementById(div+'_control')!=null) {
		document.getElementById(div+'_control').className = 'subnav_control_close';
		var d = new Date();
		var time = d.getTime();
		var url= SITEURL + "/libs/ajax/ajax_navbar_status.php?timestamp="+time;
		
		params = "navbar_status=1";
		xmlHttp_navbar = GetXmlHttpObject(null);//fails on safari 1
		xmlHttp_navbar.open("POST", url , true);
		
		
		xmlHttp_navbar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp_navbar.setRequestHeader("Content-length", params.length);
		xmlHttp_navbar.setRequestHeader("Connection", "close");
		xmlHttp_navbar.send(params);
	
		
		
	}
}
function subnav_control_close(div) {
	if(document.getElementById(div+'_control')!=null) {
		document.getElementById(div+'_control').className = 'subnav_control_open';
		var d = new Date();
		var time = d.getTime();
		var url= SITEURL + "/libs/ajax/ajax_navbar_status.php?timestamp="+time;
		
		params = "navbar_status=0";
		xmlHttp_navbar = GetXmlHttpObject(null);//fails on safari 1
		xmlHttp_navbar.open("POST", url , true);
		
		
		xmlHttp_navbar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp_navbar.setRequestHeader("Content-length", params.length);
		xmlHttp_navbar.setRequestHeader("Connection", "close");
		xmlHttp_navbar.send(params);
		
	}
}





function portfolio_control() {
	port = document.getElementById('portfolio_control_ele');
	//alert(port.className);
	//alert(document.getElementById('userbar_content_id'));
	if(port.className == "subnav_control_close") {
		//ok then hide
		//alert("here");
		close_recursive('userbar_content_id',0,portfolio_control_close);
	}
	else {	
		open_recursive('userbar_content_id',0,portfolio_control_open);
	}
}
function portfolio_control_close() {
	document.getElementById('portfolio_control_ele').className = 'subnav_control_open';
	var d = new Date();
	var time = d.getTime();
	var url= SITEURL + "/libs/ajax/ajax_userbar_status.php?timestamp="+time;
	
	params = "userbar_status=0";
	xmlHttp_portfolio = GetXmlHttpObject(null);//fails on safari 1
	xmlHttp_portfolio.open("POST", url , true);
	
	
	xmlHttp_portfolio.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_portfolio.setRequestHeader("Content-length", params.length);
	xmlHttp_portfolio.setRequestHeader("Connection", "close");
	xmlHttp_portfolio.send(params);
	
	
}
function portfolio_control_open() {
	document.getElementById('portfolio_control_ele').className = 'subnav_control_close';
	
	var d = new Date();
	var time = d.getTime();
	var url= SITEURL + "/libs/ajax/ajax_userbar_status.php?timestamp="+time;
	
	params = "userbar_status=1";
	xmlHttp_portfolio = GetXmlHttpObject(null);//fails on safari 1
	xmlHttp_portfolio.open("POST", url , true);
	
	
	xmlHttp_portfolio.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_portfolio.setRequestHeader("Content-length", params.length);
	xmlHttp_portfolio.setRequestHeader("Connection", "close");
	xmlHttp_portfolio.send(params);
	
	
	
}


//
// FUNCTION TO CLEAR A TEXTBOX OF A CERTAIN VALUE ON FOCUS
// ASSIGN THE NAME AS AN ID ATTRIBUTE ON THE ELEMENT
//
function clear_text(textbox,initValue){
	var currentText = document.getElementById(textbox).value;
	if(currentText == initValue){
		document.getElementById(textbox).value = '';
	}
}


function ShowHide()
{
  // CROSS-BROWSER, GENERIC
  // Hide or show the object - the method used depends on the user's browser.

  // First parameter: name of object to show/hide
  // Second parameter: whether to hide, show or reverse the current status of the object.
  //   Values are: 'hidden', 'visible', 'reverse'
  //   Second param is optional if a third parameter is not supplied. When left out, the
  //   second param defaults to 'reverse'
  // Third parameter: if to affect surrounding content - 'reflow' or 'fixed'
  //   Defaults to 'reflow'
  //   When 'reflow', content below the object moves up or down depending on whether
  //   the object is visible or not. This uses (for W3C) the display style property.
  //   When 'fixed', showing or hiding the object does not affect other parts of the
  //   page. This uses (for W3C) the visibility style propery.
  
  // E.g. ShowHide('divLayer1') or ShowHide('divLayer1','visible') or
  // ShowHide('divLayer1','reverse','chkBox1')

  // Get arguments
  Args = ShowHide.arguments;

  // If the first argument doesn't exist, leave function
  if(Args.length>0) Args = new Array(Args[0], Args[1], Args[2]);
  else return false;

  switch (Args[1])
  {
    case 'hidden':
      // If the second argument is 'hidden', hide the object using the method appropriate to the browser
      if(Args[2] == 'fixed')
      {
      // Use the visibility property
        if(document.getElementById) document.getElementById(Args[0]).style.visibility = 'hidden';
        else if(document.all[Args[0]]) document.all[Args[0]].style.visibility = "hidden";
        else if(document.layers) document.layers[Args[0]].visibility = "hide";
        else return false;
				
				return true;
      }
      else
      {  
        // Use the display property 
        if(document.getElementById) {document.getElementById(Args[0]).style.display = 'none';}
        else if(document.all[Args[0]]) document.all[Args[0]].style.display = "none";
        else if(document.layers) document.layers[Args[0]].visibility = "hide";
        else return false;
				
				return true;
      }
      break;
    case 'visible':
      // If the second argument is 'visible', hide the object using the method appropriate to the browser
      if(Args[2] == 'fixed')
      {  
        if(document.getElementById) document.getElementById(Args[0]).style.visibility = 'visible';
        else if(document.all[Args[0]]) document.all[Args[0]].style.visibility = "visible";
        else if(document.layers) document.layers[Args[0]].visibility = "show";
        else return false;
				
				return true;
      }
      else
      {
        if(document.getElementById) document.getElementById(Args[0]).style.display = 'block';
        else if(document.all[Args[0]]) document.all[Args[0]].style.display = "block";
        else if(document.layers) document.layers[Args[0]].visibility = "show";
        else return false;    
				
				return true;
      }
      break;
    default:
      // Else if the object is current visible set to hidden else set to visible
   
      if(document.getElementById)
      {
        // Use getElementByID method for IE5+ and NS6+ (W3C standard)
        if(Args[2] == 'fixed')
        {
          if(document.getElementById(Args[0]).style.visibility == 'visible') document.getElementById(Args[0]).style.visibility = 'hidden';
          else document.getElementById(Args[0]).style.visibility = 'visible';
					
					return true;
        }
        else
        {
          if(document.getElementById(Args[0]).style.display == 'block') document.getElementById(Args[0]).style.display = 'none';
          else document.getElementById(Args[0]).style.display = 'block';
        
					return true;
				}

      }
      else 
      {
        if(document.all[Args[0]])
        {
          if(Args[2] == 'fixed')
          {
            // Use document.all method for older IE
            if(document.all[Args[0]].style.visibility == 'visible') document.all[Args[0]].style.visibility = 'hidden';
            else document.all[Args[0]].style.visibility = 'visible';
						return true;
          }
          else
          {
            if(document.all[Args[0]].style.display == 'block') document.all[Args[0]].style.display = 'none';
            else document.all[Args[0]].style.display = 'block';    
						return true;
          }
        }
        else 
        {
          // Try to use NS4 layers
          if(document.layers[Args[0]])
          {
            if(document.layers[Args[0]].visibility = "show") document.layers[Args[0]].visibility = "hide";
            else document.layers[Args[0]].visibility = "show";
						return true;
          }
          else
          {
            // Give up
            return false;
          }  // give up
        }  // NS
      }  // IE4
    }
		return;// end of Switch
  }
	
	
function GetXmlHttpObject(handler){ 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0){
		xmlHttp=new XMLHttpRequest();
		xmlHttp.onload=handler
		xmlHttp.onerror=handler
		return xmlHttp;
	}
	if (navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP"
		} try	{ 
			objXmlHttp=new ActiveXObject(strName);
			if(handler == null) {
				handler = function() {}
			}
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp;
		} catch(e) {
			
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}

function save_site_mood() {
	close_recursive('mysitemood_box',0,null);
	site_mood_close();
	
	value = document.getElementById('sliderValue2').value;
	var d = new Date();
	var time = d.getTime();
	var url= SITEURL + "/libs/ajax/ajax_site_mood.php?timestamp="+time;
	
	params = "mood_value="+value;
	xmlHttp_site_mood = GetXmlHttpObject(null);//fails on safari 1
	xmlHttp_site_mood.open("POST", url , true);
	
	
	xmlHttp_site_mood.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_site_mood.setRequestHeader("Content-length", params.length);
	xmlHttp_site_mood.setRequestHeader("Connection", "close");
	xmlHttp_site_mood.send(params);
}
function site_mood_close() {
	document.getElementById('site_mood_setting_div').innerHTML = '';
}

function quick_links_open_end(div) {
	var classname = document.getElementById('quick_links_div_scroll').className;
	document.getElementById('quick_links_div_scroll').className = classname+" quick_links_div_overflow";
}
function quick_links_close_end(div) {
	var classname = document.getElementById('quick_links_div_scroll').className;
	var objRE = new RegExp("quick_links_div_overflow");
	classname = classname.replace(objRE, "");
	document.getElementById('quick_links_div_scroll').className = classname;
	
}

function quick_links_folder_open(id) {
	var id_folder = "quick_folder_"+id;
	the_link = document.getElementById(id_folder);
	if(the_link.className.match('hover')==null && the_link.className.match('folder')!=null) {
		the_link.className=the_link.className+" hover";
	}
	
	
	id_list = 'quick_links_'+id;
	document.getElementById(id_list).style.display = 'block';
}
function quick_links_folder_close() {
	//get the lists in the other div id quick_link_sub
	children = document.getElementById('quick_link_sub').getElementsByTagName('ul');
	for(i=0;i<children.length;i++) {		
		child = document.getElementById(children[i].id);
		child.style.display = 'none';
		//children[i].style.display = 'none';
	}
	children = document.getElementById('quick_links_folder').getElementsByTagName('a');
	for(i=0;i<children.length;i++) {
		//alert(children[i].id);
		if(children[i].id!='') {
			child = document.getElementById(children[i].id);
			currentClass = child.className;
			child.className = currentClass.replace("hover","");
		}
		//children[i].style.display = 'none';
	}
}
function display_white_box(id) {
	div_id = document.getElementById('white_box_'+id);
	div_id.style.visibility = 'visible';
	
	//alert(document.documentElement.clientWidth);
	//alert(document.body.clientHeight);
	
	div_id.style.width = (document.documentElement.clientWidth) + "px";
	div_id.style.height = (document.body.clientHeight) + "px";
	
	//alert(div_id.style.width);
	//alert(div_id.style.height);
	
	div_id.style.display = "block";
	//alert(div_id.style.filter);

	if(div_id.style.filter!=null) {
		//ie fix
		div_id.style.filter = "alpha(opacity=60);";
		
		//fix tor ie6 still shows dropdowns when there is a whitebox
		//alert(navigator.appName);
		//alert(navigator.appVersion);
		if(navigator.appName=="Microsoft Internet Explorer" && parseFloat(navigator.appVersion) == "4") {
			select_elements = document.getElementsByTagName("select");
			for(i=0;i<select_elements.length;i++) {
				select_elements[i].disabled = true;
			}
		}
		//alert(div_id.style.filter);
	}
	div_id.style.zIndex = 10;
	
	var ScrollTop = document.body.scrollTop;

	if (ScrollTop == 0) {
    if (window.pageYOffset){
      ScrollTop = window.pageYOffset;
		}
    else {
      ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	
	
	div_content = document.getElementById('white_box_content_'+id);
	//width = div_content.offsetWidth;

	width =	getWidth(div_content);
	height = getHeight(div_content);
		
	div_content.style.left = ((document.documentElement.clientWidth/2) - (width/2))+"px";
	div_content.style.top = ScrollTop+((document.documentElement.clientHeight/2) - (height/2))+"px";
	div_content.style.width = width+"px";
	div_content.style.visibility = 'visible';	
	//ie6 fixes 
	if(div_content.style.filter!=null) {
		if(navigator.appName=="Microsoft Internet Explorer" && parseFloat(navigator.appVersion) == "4") {
			select_elements = div_content.getElementsByTagName("select");
			//alert(select_elements.length);
			for(i=0;i<select_elements.length;i++) {
				select_elements[i].disabled = false;
			}
		}
		div_content.style.filter = "alpha(opacity=100);";
		div_content.style.background = '#FFFFFF none';
		//div_content.style.background = '';
	}
	
	//div_content.style.display = "block";
}
function close_white_box(id) {
	div_id = document.getElementById('white_box_'+id);
	div_id.style.visibility = 'hidden';
	
	div_id.style.width ="0px";
	div_id.style.height = "3000px";
	div_id.style.display = "block";
	if(div_id.style.filter!=null && navigator.appName!="Opera") {
		div_id.style.removeAttribute('filter');
		div_id.style.filter = null;
		if(navigator.appName=="Microsoft Internet Explorer" && parseFloat(navigator.appVersion) == "4") {
			select_elements = document.getElementsByTagName("select");
			for(i=0;i<select_elements.length;i++) {
				select_elements[i].disabled = false;
			}
		}
		
		
	}
	
	
	div_content = document.getElementById('white_box_content_'+id);
	
	div_content.style.visibility = 'hidden';	
}

function quick_links_load() {
	document.getElementById("quick_link_name").value = document.title;
	document.getElementById("quick_link_link").value = window.location.href;
}	
// CONTROL THE DEFAULT TEXT IN A TEXT FIELD

function text_field_control(id,stringval,status){
	if(status == 0){
		if (document.getElementById(id).value == ''){
			document.getElementById(id).value = stringval;
		}
	}
	else if(status == 1){
		if (document.getElementById(id).value == stringval){
			document.getElementById(id).value = '';
		}
	}
}

// GET  SELECTED TEXT
function get_selected_text_textarea(txtarea){
	txtarea = document.getElementById(txtarea);
	if(document.selection) {
		txtarea.focus();
		
		sel = document.selection.createRange();
		
		sl = sel.text;
	}
	else {
		var sl = (txtarea.value).substring(txtarea.selectionStart,txtarea.selectionEnd);
	}
	//alert(sl);
	return sl;
} 

//insert comment code text
function insert_comment_link(textarea_id) {
	
	
	link_href = document.getElementById(textarea_id+'_insert_link_comment_link').value;
	link_text = document.getElementById(textarea_id+'_insert_link_comment_text').value;
	
	link_code = '[link='+link_href+']'+link_text+'[/link]';
	//alert("here");
	if(link_text!='') {	
		if(document.getElementById(textarea_id+'_comment_selected_text_end').value>0) {
			comment_content_val = document.getElementById(textarea_id).value;
			comment_content_val_start = comment_content_val.substr(0,document.getElementById(textarea_id+'_comment_selected_text_start').value);
			comment_content_val_end = comment_content_val.substr(document.getElementById(textarea_id+'_comment_selected_text_end').value,comment_content_val.length);
			
			document.getElementById(textarea_id).value = comment_content_val_start + link_code + comment_content_val_end;
			
			//alert(document.getElementById('comment_selected_text_start').value);
			//alert(link_code.length);
			//alert((document.getElementById('comment_selected_text_start').value*1)+link_code.length);
			
			setCaretTo(document.getElementById(textarea_id),(document.getElementById(textarea_id+'_comment_selected_text_start').value*1)+link_code.length);
			
		}
		else {
			//alert("here");
			insertcode(link_code,textarea_id,'1','');
		}
	}
	close_white_box('comment_add_link_white_box');
}
//open comment link white box
function comment_open_link_whitebox(textarea_id) {
	//alert(get_selected_text_textarea('comment_content'));
	document.getElementById(textarea_id+'_insert_link_comment_link').value = '';
	document.getElementById(textarea_id+'_insert_link_comment_text').value = get_selected_text_textarea(textarea_id);
	
	document.getElementById(textarea_id+'_comment_selected_text_start').value = '0';
	document.getElementById(textarea_id+'_comment_selected_text_end').value = '0';
	txtarea = document.getElementById(textarea_id);
	//alert(txtarea);
	//alert(navigator.appName);
	if( document.selection && navigator.appName!="Opera"){
	// The current selection
		var range = document.selection.createRange();
		// We'll use this as a 'dummy'
		var stored_range = range.duplicate();
		//alert("here");
		//alert(stored_range);
		// Select all text
		stored_range.moveToElementText(txtarea);
		//alert("here");
		// Now move 'dummy' end point to end point of original range
		stored_range.setEndPoint( 'EndToEnd', range );
		// Now we can calculate start and end points
		txtarea.selectionStart = stored_range.text.length - range.text.length;
		txtarea.selectionEnd = txtarea.selectionStart + range.text.length;
	
		document.getElementById(textarea_id+'_comment_selected_text_start').value = txtarea.selectionStart;
		document.getElementById(textarea_id+'_comment_selected_text_end').value = txtarea.selectionEnd;
	}

	else {
		document.getElementById(textarea_id+'_comment_selected_text_start').value = txtarea.selectionStart;
		document.getElementById(textarea_id+'_comment_selected_text_end').value = txtarea.selectionEnd;
	}
	
}


function insertcode(tag,text_field,smiley,quote_text) {
  var txt = document.getElementById(text_field);
	
	//going to use smiley trigger for the links now on the comments
	//so I can just pass in the tags and job done!
	
	if(smiley==0) {
		tag_open = "["+tag+"]";
		tag_close = "[/"+tag+"]";
	}
	else {
		tag_open = tag;
		tag_close = "";
	}
	if(tag=='link') {
		var url = prompt("Please enter the url", "http://");
		if(url!=null) {
			var tag_open = "[link=" + url + "]";
			var tag_close = "[/link]";
			
		}
		else {
			return;
		}
	}
	
	//bug in opera where opera thinks it's windows
	if(document.selection && navigator.appName!="Opera") {
		txt.focus();
		
		sel = document.selection.createRange();
		
		//ie7 fix
		if(quote_text==null) {
			quote_text = '';
		}
		
		if(sel.text == '' && tag == 'link') {
			insert_text = 'link';
		}
		else if(quote_text!='' && tag == 'quote') {
			insert_text = quote_text;
		}	
		else {
			insert_text = sel.text;
		}
		
		
		
		rangeCopy = sel.duplicate();
		rangeCopy.moveToElementText(txt);
		// Now move 'dummy' end point to end point of original range
		rangeCopy.setEndPoint( 'EndToEnd', sel);
		start = rangeCopy.text.length - insert_text.length;
		setCaretTo(txt,start);
		
		
		
		if(quote_text!='') {
			sel.text = '' + tag_open + '' + quote_text +  tag_close;
		}
		else {
			sel.text = '' + tag_open + '' + insert_text +  tag_close;
		}
		
		//right don't have description as the name of the textarea god help me!
		
	} 
	else if(txt.selectionStart || txt.selectionStart == '0') {	
		
		insert_text = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
		if(insert_text=="" && tag == 'link') {
			insert_text = 'link';
			
		}
		else if(quote_text!='' && tag == 'quote') {
			insert_text = quote_text;
		}	
		text_length = txt.selectionStart+tag_open.length+insert_text.length +tag_close.length;
		
		
		txt.value = (txt.value).substring(0, txt.selectionStart) + ""+tag_open+"" + insert_text + ""+tag_close+"" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		setCaretTo(txt,text_length);
	} 
	else {
		txt.value = tag_open + quote_text + tag_close + '';
	}
	
	return;
}


function setCaretTo(obj, pos) { 
    if(obj.createTextRange) { 
        /* Create a TextRange, set the internal pointer to
           a specified position and show the cursor at this
           position
        */ 
        var range = obj.createTextRange(); 
        range.move("character", pos); 
        range.select(); 
    } else if(obj.selectionStart) { 
        /* Gecko is a little bit shorter on that. Simply
           focus the element and set the selection to a
           specified position
        */ 
        obj.focus(); 
        obj.setSelectionRange(pos, pos); 
    } 
}

function comment_edit_show(comment_id,hide) {
	//right we need to do the show hide for the edit button
	link_id = 'comment_edit_link_'+comment_id;
	link = document.getElementById(link_id);
	if(hide == 0) {
		comment_edit_show(comment_id,1);
		ShowHide('comment_edit_'+comment_id);
	}
	if(hide == 1) {
		ShowHide('comment_edit_'+comment_id,'hidden');
	}
}


function comment_delete_show(comment_id,hide) {
	//right we need to do the show hide for the edit button
	link_id = 'comment_delete_link_'+comment_id;
	link = document.getElementById(link_id);
	
	
	
	if(hide == 0) {
		comment_edit_show(comment_id,1);
		ShowHide('comment_delete_'+comment_id);
		
	}
	if(hide == 1) {
		ShowHide('comment_delete_'+comment_id,'hidden');
	}
}

function notifications_reset(object_type,object_id) {
	var d = new Date();
	var time = d.getTime();
	var url= SITEURL + "/libs/ajax/ajax_notification_reset.php?timestamp="+time;
	
	params = "object_type="+object_type+"&object_id="+object_id;
	xmlHttp_comment_notifyreset = GetXmlHttpObject(notification_reset_helper);//fails on safari 1
	xmlHttp_comment_notifyreset.open("POST", url , true);
	
	
	xmlHttp_comment_notifyreset.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_comment_notifyreset.setRequestHeader("Content-length", params.length);
	xmlHttp_comment_notifyreset.setRequestHeader("Connection", "close");
	xmlHttp_comment_notifyreset.send(params);
}


function notification_reset_helper() {
	if (xmlHttp_comment_notifyreset.readyState==4 || xmlHttp_comment_notifyreset.readyState=="complete") {
		response = xmlHttp_comment_notifyreset.responseText;
		document.getElementById('comments_notification').innerHTML = response;
		
	}
}
//MODERATOR POST
function comment_moderator_link(comment_id) {
	var d = new Date();
	var time = d.getTime();
	var url= SITEURL + "/libs/ajax/ajax_moderator_comment.php?timestamp="+time;
	
	params = "comment_id="+comment_id;
	xmlHttp_comment_moderator = GetXmlHttpObject(comment_moderator_link_helper);//fails on safari 1
	xmlHttp_comment_moderator.open("POST", url , true);
	
	
	xmlHttp_comment_moderator.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_comment_moderator.setRequestHeader("Content-length", params.length);
	xmlHttp_comment_moderator.setRequestHeader("Connection", "close");
	xmlHttp_comment_moderator.send(params);
}

function comment_moderator_link_helper() {
	if (xmlHttp_comment_moderator.readyState==4 || xmlHttp_comment_moderator.readyState=="complete") {
		response = xmlHttp_comment_moderator.responseText;
		split = response.split('[SPLIT]');
		//have we a comment id
		if(split[1]>0) {
			classname = document.getElementById('comment_outer_box_'+split[1]).className;
			if(split[0]=="0") {
				//normal post 
				document.getElementById('comment_moderator_link_'+split[1]).innerHTML = 'Moderator Post';
				document.getElementById('comment_moderator_flag_'+split[1]).innerHTML = '';
				
				
				var objRE = new RegExp("box_yellow");
				classname = classname.replace(objRE, "");
				if(classname=="") {
					classname = 'box';
				}				
			}
			else {
				//moderator post
				document.getElementById('comment_moderator_link_'+split[1]).innerHTML = 'Un-Mark Moderator Post';
				document.getElementById('comment_moderator_flag_'+split[1]).innerHTML = '<strong>MODERATOR POST</strong>';
				
				classname = document.getElementById('comment_outer_box_'+split[1]).className;
				classname = classname + " box_yellow";
			}
			
			document.getElementById('comment_outer_box_'+split[1]).className = classname;
			
		}
		
	}
}
function KeyCheck(e){
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
	 return KeyID;
}
function return_do_function(event,function_name) {
	keyid = KeyCheck(event);
	if(keyid == 13) {
		//return is pressed
		function_name();
	}
}
function add_to_favourites(urlAddress,title) { 
	if(title =='') {
		title = document.title;
	}
	
	
	
	//bad massage hidden at the moment to non supported browsers only displays to IE and FF
	badmessage_1 = "Your browser doesn't support bookmark popups.\rPlease use the linknand press Command + D to Bookmark the page";
	
	if (window.sidebar) { // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, urlAddress,"");	
	} 
	else if (window.external) {
		//alert(urlAddress);
		//alert(title);
		nav = navigator.appName;
		//alert(nav);
		if(nav=="Netscape") {
			//google chrome
			alert(badmessage_1);
		}
		else {
		
			window.external.AddFavorite(urlAddress,title);
		}
		
	}
	 else if(window.opera){ //Opera
		 var a = document.createElement("A");
     a.rel = "sidebar";
     a.target = "_search";
     a.title = title;
     a.href = urlAddress;
     a.click();
   }
	else {
		nav = navigator.appName;
		if(nav=="Netscape") {
			alert(badmessage_1);
		}
		else {
			alert("Your browser doesn't support bookmark popups.\r\nPlease use the link and bookmark this page through your browser");
		}
		
		return true;
	}
} 

//CLOSING THE UPGRADE BROWSER MESSAGE
function ie6_msg_close() {
	var name = 'ie6_msg';
	var div = document.getElementById(name);
	
	if(div!=null) {
		var url= SITEURL + "/libs/ajax/ie6_msg_close.php";
		
		params = "msg=0";
		xmlHttp_navbar = GetXmlHttpObject(null);//fails on safari 1
		xmlHttp_navbar.open("POST", url , true);
				
		xmlHttp_navbar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp_navbar.setRequestHeader("Content-length", params.length);
		xmlHttp_navbar.setRequestHeader("Connection", "close");
		xmlHttp_navbar.send(params);		
		close_div(name);
	}
}


