function openScript(url, width, height) {
        var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=yes,status=yes' );
}

function popupImage(url, width, height) {
        var Win = window.open(url,"popupImage",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
}

clckcnt = 0;
function clckcntr() {
clckcnt++;
if(clckcnt > 1) {
    if(clckcnt > 2) { return false; }
    alert('Processing...\n\n' + '     Thank you for your patience.');
    return false;}
return true;}

function confirmOpenScript(text, url, width, height) {
input_box=confirm(text);
if (input_box==true) { 
openScript(url, width, height);
}
}   

function alertOpenScript(text, url, width, height) {
alert(text);
openScript(url, width, height);
}   

function getSelection(ta)
  { var bits = [ta.value,'','','']; 
    if(document.selection)
      { var vs = '#$%^%$#';
        var tr=document.selection.createRange()
        if(tr.parentElement()!=ta) return null;
        bits[2] = tr.text;
        tr.text = vs;
        fb = ta.value.split(vs);
        tr.moveStart('character',-vs.length);
        tr.text = bits[2];
        bits[1] = fb[0];
        bits[3] = fb[1];
      }
    else
      { if(ta.selectionStart == ta.selectionEnd) return null;
        bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
      }
     return bits;
  }

function matchPTags(str)
  { str = ' ' + str + ' ';
    ot = str.split(/\[[B|U|I].*?\]/i);
    ct = str.split(/\[\/[B|U|I].*?\]/i);
    return ot.length==ct.length;
  }

function addPTag(ta,pTag)
  { bits = getSelection(ta);
    if(bits)
      { if(!matchPTags(bits[2]))
          { alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
            return;
          }
        ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
      }
  }

function formatShortcuts(e)  {
	var ctrlMod = (window.event)? window.event.ctrlKey : e.ctrlKey;
	var key = (window.event)? window.event.keyCode : e.which;
	key = String.fromCharCode(key).toLowerCase();
	
	if(ctrlMod && key == 'b') {
		addPTag(document.getElementById('text'),'B');	
		return false;
	}
	if(ctrlMod && key == 'i') {
		addPTag(document.getElementById('text'),'I');	
		return false;
	}
	if(ctrlMod && key == 'u') {
		addPTag(document.getElementById('text'),'U');	
		return false;
	}
	if(ctrlMod && key == 'g') {
		addPTag(document.getElementById('text'),'IMG');	
		return false;
	}
	if(ctrlMod && key == 'l') {
		addPTag(document.getElementById('text'),'URL');	
		return false;
	}
	if(ctrlMod && key == 'q') {
		addPTag(document.getElementById('text'),'QUOTE');	
		return false;
	}
	if(ctrlMod && key == 's') {
		addPTag(document.getElementById('text'),'S');	
		return false;
	}

	return true;
}

////////////// Show/Hide elements //////////////////////////

var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)	{
	  if (document.getElementById)	{    	// DOM level 1 browsers: IE 5+, NN 6+
	  	this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	  }
	  else if (document.all)	{  			// IE 4
		this.obj = document.all[name];
		this.style = document.all[name].style;
	  }
	  else if (document.layers)  { 			// NN 4
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	  }
}

// this function makes the element visible
function showElement(visiblechunk) {
		if (!DHTML){
		 alert ('Sorry, your browser can\'t support DHTML!');
		 return;
		}
		var displayedElem = new getObj(visiblechunk);
		
		displayedElem.style.visibility = 'visible';
		displayedElem.style.display = 'block';
	}
	
// this function makes the element invisible	
function hideElement(invisiblechunk) {
		if (!DHTML){
		 alert ('Sorry, your browser can\'t support DHTML!');
		 return;
		}
	
		var hiddenElem = new getObj(invisiblechunk);
		
		hiddenElem.style.visibility = 'hidden';
		hiddenElem.style.display = 'none';
	}
		