//common.js

function concatObject(obj) {
	str='';
	for(prop in obj) {
		if (obj[prop] && typeof(obj[prop]) != 'object'  && typeof(obj[prop]) != 'function' && prop != 'innerHTML' && prop !='outerHTML' && prop !='outerText'  && prop !='textContent' && prop !='text' && prop !='innerText')
			
			str+=prop + " : "+ obj[prop]+ " :" + typeof(obj[prop]) + "\n";
	}
	return(str);
}
String.prototype.trim = function () {
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

String.prototype.padDigits = function(totalDigits) {
	var n = this;
	n = n.toString(); 
	var pd = ''; 
	if (totalDigits > n.length) 
	{ 
		for (i=0; i < (totalDigits-n.length); i++) 
		{ 
			pd += '0'; 
		} 
	} 
	return pd + n.toString(); 
} 

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 addPTag2(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 addPTag (el,tag) { 
  	if (el.setSelectionRange) {
		if (el.selectionStart == el.selectionEnd) return;
 		el.value = el.value.substring(0,el.selectionStart) + 
			"[" + tag + "]" + 
			el.value.substring(el.selectionStart,el.selectionEnd) + 
			"[/" + tag + "]" +
			el.value.substring(el.selectionEnd,el.value.length);
  	} else {
        var selectedText = document.selection.createRange().text; 
         
        if (selectedText != "") { 
            var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]"; 
            document.selection.createRange().text = newText; 
        } 
	}
}

var PROMPT_STOPPED=0;
var PROMPT_PLAYING=1;

var promptState=PROMPT_STOPPED;
var lastTop=0;
var pauseCounter=0;
var speed=2;
var fsize=parseInt(getStyle($('prompter'),'fontSize'));
var ftimer=0;
var timerID=0;
var externControllerWindow = null;


