/* This notice must be untouched at all times.

cvs_utils.js    v. 1.01		21-01-2007

Copyright (c) 2005 Clear Voice Systems Ltd. All rights reserved.

Provides utility functions used by Caption class. functions can
be used directly by other applications

*/


// UTILITY FUNCTIONS

//
// int2time()
//
function int2time(intTime) {

  var intMinutes, intSeconds;
  var strMinutes="00", strSeconds="00";
  var strTime;

  // Calculations to convert from seconds into standard hh:mm format
	intTime=Math.floor(intTime);  
	intMinutes=Math.floor(intTime/60);
	intSeconds=(intTime%60);

	strMinutes=intMinutes;
	strSeconds=intSeconds;

	// insert leading zeros to keep in hh:mm format
	if (intSeconds < 10)
		strSeconds="0" + strSeconds;
	if (intMinutes < 10)
		strMinutes="0" + strMinutes;
		
    // create time string and return in
	strTime=strMinutes + ":" + strSeconds;

	return(strTime);
}

//
// time2int()
//
function time2int(strTime) {

  var intHrs = 0, intMin = 0, intSec = 0;
  var hasHrs = false, hasMin = false, hasSec = false;
  var len = strTime.length;
  if ( !len )
    return(-1);
  
  var colon1 = strTime.lastIndexOf(':');
  if ( colon1 != -1 ) {
    hasSec=true;
    hasMin=true;
    intSec = strTime.substring( colon1 + 1, len)*1;

    var colon2 = strTime.lastIndexOf(':', colon1 - 1);
    if ( colon2 != -1 ) {
      hasHrs=true;
      intMin = strTime.substring( colon2 + 1, colon1)*1;
      intHrs = strTime.substring( 0, colon2)*1;	
    }else
      intMin = strTime.substring( 0, colon1)*1;		
  }
  	
  else {
    hasSec=true;
    intSec = parseInt(strTime.substring( 0, len));	
  }

  if ( isNaN(intHrs) || isNaN(intMin) || isNaN(intSec) )
    return(-1);

  var intTime = intHrs*3600 + intMin*60 + intSec;
  return(intTime);
}


//
// getnodestring
//
function nodeValue(id) {
  if(document.all){
     value = id.innerText;
  } else{
     value = id.textContent;
  }
  value = stripws(value);
  return (value);
}


//
// stripws()
//
function stripws(stringval) {
//Return text string without white space
  val = stringval.match(/\S+/g);
  return (val[0]);
}