/**
 * @author kmorton
 */
function qstring( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}	

// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
     strTarget, // The substring you want to replace
     strSubString // The string you want to replace in.
     ){
     var strText = this;
     var intIndexOfMatch = strText.indexOf( strTarget );
      
     // Keep looping while an instance of the target string
     // still exists in the string.
     while (intIndexOfMatch != -1){
     // Relace out the current instance.
     strText = strText.replace( strTarget, strSubString )
      
     // Get the index of any next matching substring.
     intIndexOfMatch = strText.indexOf( strTarget );
     }
      
     // Return the updated string with ALL the target strings
     // replaced out with the new substring.
     return( strText );
    }	
	
function toggleDesc(descEl,caller,strs) {
	if(strs == null)
		strs = {less:"&lt;&lt; Less", more:"More &gt;&gt;"};
	if (caller.innerHTML.toLowerCase().indexOf(new String("More").toLowerCase())>-1) {
		descEl.style.height='';
		caller.innerHTML = strs.less;
	} else {
		descEl.style.height='85px';
		caller.innerHTML = strs.more;		
	}
}

function toggleDescNew(caller, strs){
	if(strs == null)
		strs = {less:"&lt;&lt; Less", more:"More &gt;&gt;"};
	var descTruncated = document.getElementById('desc_truncated');
	var descFull = document.getElementById('desc_full');
	
	if (descTruncated.style.display == 'none'){
		descTruncated.style.display = 'block';
		descFull.style.display = 'none';
		caller.innerHTML = strs.more;
	} else {
		descTruncated.style.display = 'none';
		descFull.style.display = 'block';
		caller.innerHTML = strs.less;
	}
}

/* function:    jscss - modify a given objects styles.
 * Parameters:  a = action (swap, add, remove or check)
 * 		        o = object on which to perform the action
 *              c1 = first class to be used
 *              c2 = (optional) second class to be used
 */
function jscss(a,o,c1,c2) {
  switch (a){
    case 'swap':
      o.className=!jscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){ o.className += o.className ?(' '+c1):c1}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}

