// Retrieve the value of a specific CPC parameter
function paramGet(plist, name)
{
   /* We iterate over each parameter in the string. On each iteration,
  @Var(i) is the index of the next @Bold(param)=@Italic(value) entry in the string.
  */
 var i=0;
  while(i<plist.length) {
    /* The parameter is terminated by a semi-colon or the end of the string. */
    var end = plist.indexOf(";", i), thisName, thisVal;
    if(end == -1) { end = plist.length; }
    thisName = plist.substring(i, end); 

	/* The value is separated from the name by an '='. */
	var sep = thisName.indexOf('=', 0);
	if(sep >= 0) { 
		thisVal = thisName.substring(sep+1, thisName.length);
		thisName = thisName.substring(0, sep);
	}

	/* If this is the desired name, return its value. */
    if(thisName.toUpperCase() == name.toUpperCase()) { return thisVal; }

	/* Move to the next entry. */
	i = end+1;
  }
  return null;
}

function cpcDim(desc)
{
  this.length = 2;
  if(desc == null) { this.width = this.height = 0; }
  else {
	var sep = desc.indexOf(",");
	this.width = desc.substring(0, sep);
	this.height = desc.substring(sep+1);
  }
}

function cpcEvent(ev)
{
    var sep = ev.indexOf(":", 0);
	if(sep<0) { sep = ev.length; }
	this.length = 2;
	this.type = ev.substring(0, sep); 
	this.params = ev.substring(sep+1, ev.length);
}

function cpcRev(desc)
{
	this.length = 3;
	if(desc == null) { this.major = this.minor = this.respin = 0; }
	else {
		var sep = desc.indexOf(",");
		this.major = desc.substring(0,sep);
		desc = desc.substring(sep+1);
		sep = desc.indexOf(",");
		this.minor = desc.substring(0,sep);
		this.respin = desc.substring(sep+1);
	}
}

function cpcEvent(ev)
{
    var sep = ev.indexOf(":", 0);
	if(sep<0) { sep = ev.length; }
	this.length = 2;
	this.type = ev.substring(0, sep); 
	this.params = ev.substring(sep+1, ev.length);
}
