function make_bold(textarea_Id) {
        bwords = prompt("Enter the words you would like in bold:","");
        if (bwords != null) {
        document.getElementById(textarea_Id).value += ' <b>'+bwords+'</b> '; 
                

        }
        document.getElementById(textarea_Id).focus();
}
function make_italics(textarea_Id) {
        iwords = prompt("Enter the words you would like in italics:","");
        if (iwords != null) {
                document.getElementById(textarea_Id).value += ' <i>'+iwords+'</i> ';
        }
        document.getElementById(textarea_Id).focus();
}
function make_link(textarea_Id) {
        alink = prompt("Enter the url of the link:", "http://");
        linktext = prompt("Enter the text to display for link:", "");
        if ((alink != null) && (alink != "http://")) {
            if (linktext != null) {
                document.getElementById(textarea_Id).value += ' <a href="'+alink+'">'+linktext+'</a> ';
            } 
        }
        document.getElementById(textarea_Id).focus();
}
function make_email_link(textarea_Id) {
        alink = prompt("enter the email adress:", "");
        if ((alink != null) && (alink != "http://")) {
                document.getElementById(textarea_Id).value += ' <a href="mailto:'+alink+'">'+alink+'</a> ';
        }
        document.getElementById(textarea_Id).focus();
}

/* function addImage(textarea_Id) { */
/* 				 */
/* 	imageWindow = window.open(path + '/includes/editor/nonieimages.php?form_id=' + formID,'edit_window','width=600,height=500,status=yes') */
/* 	if (imageWindow.opener == null) imageWindow.opener = self; */
/* } */

function get_image(path,src,w,h) {
	var outparam = null;
	if (src) {
		outparam.f_url = src;
	
		if (w) outparam.f_width=w;
		if (h) outparam.f_height=h;
	}
	
	return Dialog(path+'/includes/editor/popups/insert_image.php?basic=1', function(param) {
		if (param) eval(evalfunction);
	}, outparam);
}

function make_image(textarea_Id,param) {
	document.getElementById(textarea_Id).value += '<img src="'+param.f_url+'"'+(param.f_width? ' width="'+param.f_width+'"':'')+(param.f_height? ' height="'+param.f_height+'"':'')+'>';
}

function display_html(textarea_Id) {
    var bottom = document.getElementById(textarea_Id).value;
    bottom = bottom.replace(/\n/g, '<br />'); 
    win = window.open("", "popup", "width=400,height=300,scrollbars=yes");
    win.document.write("<p>",bottom,"</p>");
    win.document.write("<p align='center'><a href='javascript:close()'>Close Preview</a></p>");
    win.document.write(tagParaClose);
    win.document.close();
}

function confirmDelete(message)
{
return confirm(message);
}

var newWindow = null;

function open_window(the_url,window_name,height,width) { 
  if(!height || height==0) {
	  height = '500';

  }
  if(!width || width==0) {
  	width = '400';
  }
  newWindow = window.open(the_url,window_name,'scrollbars=yes,width='+width+',height='+height+',resizable=yes');
  newWindow.focus();
}

function openWin(the_url) {
	newWindow = window.open (the_url,"progress","toolbar=no,scrollbars=no,width=200,height=150,menubar=no,location=no,resizable=no");
}
function openHelpWin(the_url) {
	newWindow = window.open (the_url,"progress","toolbar=no,scrollbars=yes,width=640,height=400,menubar=no,location=no,resizable=yes");
}

function closeWin() {
    if (newWindow) newWindow.close();
	
}
function openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

var form='form1' //Give the form name here
var val=''
function SetChecked(val,chkName) {
    dml=document.forms[form];
    len = dml.elements.length;
    var i=0;
    for( i=0 ; i<len ; i++) {
        if (dml.elements[i].name==chkName) {
            dml.elements[i].checked=val;
        }
    }
}
var _w = null;
function createNew(writeText) {
  _w = window.open('',
'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width=400,height=400');
  _w.document.open();
  _w.document.write('<html><head><title>Help Window</title></head><body>');
  _w.document.write(writeText);
  _w.document.write('<br /><div align="center"><a href="javascript:self.close()">Close this window</a></div>');
  _w.document.write('</body></html>');

}
function openDir(form) { 

	var newIndex = form.URL.selectedIndex; 

	if ( newIndex != 1 ) { 
		window.location.href=form.URL.options[ newIndex ].value ; 
	} 

} 
//var colourOpeningField;
function colorPicker_callBack(strColor) {
	//document.write(colourOpeningField);
	document.getElementById(colourOpeningField).value = '#'+strColor;
	document.getElementById(colourOpeningField).focus();
}

function openColorPickerAdv(formField,path) {
	colourOpeningField = formField;
	//document.getElementById('colorPickerAdvDiv').style.visibility = 'visible';
	window.open(path+'/includes/colourpicker/colorPickerAdv.html',
'colourPicker', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width=350,height=142,screenX=400,screenY=400,top=400,left=400');
}

function closeColorPickerAdv() {
	window.colourPicker.close();
}
function changeStyle(element, value,elementStyle) {

	if (elementStyle=='backgroundImage') {
		value = 'url('+document.getElementById(value).value+')';
	} else {
		value = document.getElementById(value).value;
	}
	document.getElementById(element).style[elementStyle]=value;
}
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}


function admin_toggle() {
	var togImg=new getObj('admin_tool_button');
	if(togImg) {
		if(togImg.obj.src.indexOf('closed')==-1) {
			setStyleByClass('*','admin_tool','display','none');
			togImg.obj.src=togImg.obj.src.replace("open","closed");
			sendDiscloseStatus('admin_tool_button',1);
		} else {
			setStyleByClass('*','admin_tool','display','');
			togImg.obj.src=togImg.obj.src.replace("closed","open");
			sendDiscloseStatus('admin_tool_button',0);
		}
	}
}




// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value  (prefix of ! means 'toggle value'

function setStyleByClass(t,c,p,v){
	var elements;
	var ie = (document.all) ? true : false;
	var toggle=false;

	if(v.charAt(0)=="!"){toggle=true;v=v.substr(1);}
	var vval=v;

	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					if (toggle) {vval=((eval('node.style.'+p))!=v)?v:''}
					eval('node.style.' + p + " = '" +vval + "'");
				}
			}
		}
	}
}


// disclosee:     id of object to show/hide
// discloser_img_obj: object containing open/close string/url tag
// discloser_tag: name of tag in disclosee object (e.g: 'src', 'backgroundImage')
function disclose_it(disclosee,discloser_img_obj,discloser_tag,statusID) {
	var disclosee_o = new getObj(disclosee);

	if (disclosee_o.style.display != "none") {
		discloser_img_obj[discloser_tag] = 
			discloser_img_obj[discloser_tag].replace("open","closed");
		disclosee_o.style.display='none';
		if (statusID) {sendDiscloseStatus(statusID,1);}
	} else {
		discloser_img_obj[discloser_tag] = 
			discloser_img_obj[discloser_tag].replace("closed","open");
		disclosee_o.style.display='block';
		if (statusID) {sendDiscloseStatus(statusID,0);}
	}
}

function showhide(obj,lyr,showhide)
{
	if (showhide=='hidden') {
		clearTimeout(show_timeout);
		hide_timeout = setTimeout("showhide2('"+lyr+"','"+showhide+"')",200);
	} else {
		show_timeout = setTimeout("showhide2('"+lyr+"','"+showhide+"')",2000);
		setLyr(obj,lyr);
	}
	//over_event=0;
}
over_event=0;
function keeppopup(lyr) {
	clearTimeout(hide_timeout);

}

function killpopup(e,lyr) {

	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	//alert(reltg.nodeName+' '+tg.nodeName);
		if (reltg== tg) return;
	// Mouseout took place when mouse actually left layer
	// Handle event
		var x = new getObj(lyr);
		x.style.visibility = 'hidden';	

}
function killpopup2(e,lyr) {

	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if (reltg.id==lyr)return;
	var x = new getObj(lyr);
	x.style.visibility = 'hidden';	
}

function contains(a, b) {

  // Return true if node a contains node b.

  while (b.parentNode)
    if ((b = b.parentNode) == a)
      return true;
  return false;
}
function showhide2(lyr,showhide) {
	var x = new getObj(lyr);
	x.style.visibility = showhide;	
}
function setLyr(obj,lyr)
{
	var newX = findPosX(obj)+135;
	var newY = findPosY(obj)-0;
	//if (lyr == 'testP') newY -= 50;
	var x = new getObj(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	window.status = printstring;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = this.obj.style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
 }
}

function selectTag(field,tagText) {
	
	if (document.getElementById(field).value=='') {
		delimiter = '';	
	} else {
		delimiter = ',';
	}

	document.getElementById(field).value = document.getElementById(field).value+delimiter+' '+tagText;
}


/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  if( window.ActiveXObject && window.ScriptEngine && ScriptEngine() == 'JScript'
&& !window.opera && !navigator.__ice_version && !window.attachEvent ) {
   return null;
  }

  	try {
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  	catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  	catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  	catch (e) { xmlhttp = false; }}}
	} catch (e) {alert('testIE');} 
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          if(fnDone) {fnDone(xmlhttp);}
        }};
      xmlhttp.send(sVars);
	}
    catch(z) { return false; }
    return true;
  };
  return this;
}
