function pChangeClass(elem, newstyle) {
  elem.className = newstyle;
  elem.value = "";
}

function pAddCSSRule(selector, rule) {
  if (document.all)
    document.styleSheets[document.styleSheets.length - 1].addRule(selector, rule);
  else if (document.getElementById)
    document.styleSheets[document.styleSheets.length - 1].insertRule(selector + '{ ' + rule + ' } ',
                document.styleSheets[document.styleSheets.length - 1].cssRules.length);
}

function pRemoveCSSRule(selector) {
    var iSheets = document.styleSheets.length;
    var iRules = document.styleSheets[iSheets-1].rules.length;
    document.styleSheets[iSheets-1].removeRule(iRules - 1);
}


//Specify spectrum of different font sizes:
var szs = new Array( '0.2em','0.6em','0.7em','1.0em','1.2em','1.5em','2.0em','2.8em');
var sz = 2;

function pChangeFontSize(trgt, inc) {
        if (!document.getElementById) return;
        var d = document,cEl = null,i,j,cTags;

        sz += inc;
        if ( sz < 0 ) sz = 0;
        if ( sz > 7 ) sz = 7;

        if ( !( cEl = d.getElementById( trgt ) ) ) {
                cEl = d.getElementsByTagName( trgt );
                for ( j = 0 ; j < cEl.length ; j++ ) cEl[ j ].style.fontSize = szs[ sz ];
        }
        return false;
}

function pRandomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = 'id';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


function pCountOnWidget(widget) {
	if (widget.id == '')
	  widget.id = pRandomString();
	pCountOnWidget_(widget.id, widget.value, 0);
}


function pCountOnWidget_(widgetid, value, secs)	{
	widget = document.getElementById(widgetid);
	widget.value = value + ' ' + secs;
//	command = 'pCountOnWidget_(\"' + widgetid + '\", \"' + value + '\", ' + (secs + 1) + ')';
//	setTimeout(command, 1000);

        if (secs <= 15 ) {
          command = 'pCountOnWidget_(\"' + widgetid + '\", \"' + value + '\", ' + (secs + 1) + ')';
          setTimeout(command, 1000);
        }
        else {
          widget = document.getElementById(widgetid);
          widget.value = value + '...';
          widget.disabled=false;
        }

}

function toggleDivWithImage(divname, imgname) {
  theimage = document.getElementById(imgname)
  thediv = document.getElementById(divname);
  disp= thediv.style.display;

  if (disp == '') {
    thediv.style.display = 'none';
    theimage.src = '/projecta/images/expand.gif';
  }
  else {
    thediv.style.display = '';
    theimage.src = '/projecta/images/collapse.gif';
  }
}

function toggleDiv(divname) {
   
  thediv = document.getElementById(divname);
  disp = thediv.style.display;

  
  if (disp == '') {
    thediv.style.display = 'none';
  }
  else {
    thediv.style.display = '';
  }
}

function toggleDivContent(divname, str1, str2) {
	   
	  thediv = document.getElementById(divname);
	  content = thediv.innerHTML;

	  
	  if (content == str1) {
	    thediv.innerHTML = str2;
	  }
	  else {
	    thediv.innerHTML = str1;
	  }
	}

