// JavaScript Document
var isSafari = /WebKit/i.test(navigator.userAgent);
var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
var isGecko = (navigator.userAgent.toLowerCase().indexOf('gecko') != -1);
// Detect if the browser is isIE or not.
// If it is not isIE, we assume that the browser is NS.
var isIE = (navigator.appVersion.toLowerCase().indexOf('msie 6.0') != -1);
var isIE7 = (navigator.appVersion.toLowerCase().indexOf('msie 7.0') != -1);
var isFF2 = ((navigator.userAgent.toLowerCase().indexOf('gecko') != -1)&&(navigator.appVersion.toLowerCase().indexOf('5.0') != -1)&&(navigator.appVersion.toLowerCase().indexOf('webkit') == -1));
var isMac = (navigator.platform.toLowerCase().indexOf("mac") != -1);

var videoDTO = new Array();
function loadPlayer(){}
function loadSlider(){}
function isUrl(s) {
	var regexp = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?[\w._-]+(:[0-9]+)?(\/[\w#!:.?+=&%@!\/-]*)*$/;
	return regexp.test(s);
}

function containsProtocol(s) {
	var regexp = /(ftp|http|https):\/\//;
	return regexp.test(s);
}


/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	}
	
/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = $("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				//init(); // call the onload handler
			}
		};
/*@end @*/
	
/* for Safari */
	if (isSafari) { // sniff
		var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				init(); // call the onload handler
			}
		}, 10);
	}
	function setOmniture(value,content){
		switch (value){
			case '6':
				var s=s_gi(s_account);
				s.linkTrackVars='prop6';
				s.linkTrackEvents='None';
				s.prop6 = "facebook: "+content;
				s.tl(this,'o','facebook');
			break;
			case '7':
				var s=s_gi(s_account);
				s.linkTrackVars='prop7';
				s.linkTrackEvents='None';
				s.prop7 = "digg: "+content;
				s.tl(this,'o','digg');
			break;
			case '8':
				var s=s_gi(s_account);
				s.linkTrackVars='prop8';
				s.linkTrackEvents='None';
				s.prop8 = "delicious: "+content;
				s.tl(this,'o','delicious');
			break;
			case '9':
				var s=s_gi(s_account);
				s.linkTrackVars='prop9';
				s.linkTrackEvents='None';
				s.prop9 = content;
				s.tl(this,'o','Screen Name');
			break;
			case '22':
				var s=s_gi(s_account);
				s.linkTrackVars='prop22';
				s.linkTrackEvents='None';
				s.prop22 = "Add Channel:"+content;
				s.tl(this,'o','Add Channel');
			break;
			case '23':
				var s=s_gi(s_account);
				s.linkTrackVars='prop23';
				s.linkTrackEvents='None';
				s.prop23 = "Add Video:"+content;
				s.tl(this,'o','Add Video');
			break;
			default : ;
		}
	}
	var currentPageIcon = "none";
	function whatPage(){
		if(document.body.id=="home"){
	        currentPageIcon = "nav_home";
	    }else if(document.body.id=="buzz"){
	        currentPageIcon = "nav_buzz";
	    }else if(document.body.id=="category"){
	    	if(catName.toLowerCase().indexOf('action') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('celebs') != -1){
	    		currentPageIcon = "nav_celebs";
	    	}else if(catName.toLowerCase().indexOf('educational') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('family') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('films') != -1){
	    		currentPageIcon = "none";
	    	}if(catName.toLowerCase().indexOf('food') != -1){
	    		currentPageIcon = "nav_food";
	    	}else if(catName.toLowerCase().indexOf('funny') != -1){
	    		currentPageIcon = "nav_funny";
	    	}else if(catName.toLowerCase().indexOf('health') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('living') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('music') != -1){
	    		currentPageIcon = "nav_music";
	    	}else if(catName.toLowerCase().indexOf('news') != -1){
	    		currentPageIcon = "nav_news";
	    	}else if(catName.toLowerCase().indexOf('sexy') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('sports') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('travel') != -1){
	    		currentPageIcon = "none";
	    	}else if(catName.toLowerCase().indexOf('tv') != -1){
	    		currentPageIcon = "nav_tvfaves";
	    	}else if(catName.toLowerCase().indexOf('underground') != -1){
	    		currentPageIcon = "none";
	    	}
	    }
	}
	//helper function for milToMin() -- milliseconds to minutes
	function two(x) {return ((x>9)?"":"0")+x}
	//helper function for milToMin() -- milliseconds to minutes
	function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}
			
	function milToMin(ms) {
		var sec = Math.floor(ms/1000);
		ms = ms % 1000;
		//t = three(ms)
		
		var min = Math.floor(sec/60);
		sec = sec % 60;
		t = two(sec);// + ":" + t
		
		var hr = Math.floor(min/60);
		min = min % 60;
		t = two(min) + ":" + t;
		
		var day = Math.floor(hr/60);
		hr = hr % 60;
		if (hr > 0){
			t = two(hr) + ":" + t;
		}
			//t = day + ":" + t
		if(t.charAt(0) == "0"){
			t = t.substring(1, t.length);
		}	
		return t;
	}   		
	function tooltipFollow(mydiv){
		// Simple follow the mouse script

		var divName = mydiv; // div that is to follow the mouse
		                       // (must be position:absolute)
		var offX = 10;          // X offset from mouse position
		var offY = -25;          // Y offset from mouse position
		
		function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
		function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}
		
		function follow(evt) {if (document.getElementById) {var obj = $(divName).style; obj.visibility = 'visible';
		obj.left = (parseInt(mouseX(evt))+offX) + 'px';
		obj.top = (parseInt(mouseY(evt))+offY) + 'px';}}
		document.onmousemove = follow;
	}	
	function retrieveResults(XMLHttpRequest){
		var xml = XMLHttpRequest.responseText;
		// And now, update the text on the page:
		var text = $('ten');
		text.innerHTML = xml;
		getColumns();
	}
	
	
	function submitSearch(){
		var searchString = $F('searchField');
		if (searchString == null) {
			return;
		}
		
		if(getMatureContentCookie() == null) {
			if(isRestrictedSearch(searchString)) {
				location.href="http://localhost:8080/services/mature.jsp?type=search&query=" + searchString;
				return;
			}
		}
		
		var trimValue = trim(searchString);
		if (trimValue == null || trimValue.length == 0) {
			$('searchField').value = trimValue;
			return;
		}

		trimValue = replaceAll(trimValue, "!", "");
		trimValue = replaceAll(trimValue, "\\", "");		
		trimValue = replaceAll(trimValue, "/", "");		
		trimValue = replaceAll(trimValue, "|", "");		
		trimValue = replaceAll(trimValue, "?", "");				
		trimValue = replaceAll(trimValue, "=", "");						
		trimValue = replaceAll(trimValue, "}", "");								
		trimValue = replaceAll(trimValue, "{", "");										
		trimValue = replaceAll(trimValue, "[", "");
		trimValue = replaceAll(trimValue, "]", "");				
		trimValue = replaceAll(trimValue, "(", "");				
		trimValue = replaceAll(trimValue, ")", "");				
		trimValue = replaceAll(trimValue, "+", "");
		trimValue = replaceAll(trimValue, "-", "");				
		trimValue = replaceAll(trimValue, "~", "");				
		trimValue = replaceAll(trimValue, "^", "");				
		trimValue = replaceAll(trimValue, "\"", "");						
		trimValue = replaceAll(trimValue, "-", "");								
		trimValue = replaceAll(trimValue, ":", "");										
		trimValue = replaceAll(trimValue, "<", "");										
		trimValue = replaceAll(trimValue, ">", "");										


		location.href = "http://localhost:8080/services/search.jsp?query="+escape(trimValue);
	}
	
	// Removes leading whitespaces
	function LTrim( value ) {
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	}

	// Removes ending whitespaces
	function RTrim( value ) {
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	}

	// Removes leading and ending whitespaces
	function trim( value ) {
		return LTrim(RTrim(value));
	}
		
	function entsubSearch(event) {
		if ((event && event.which == 13)||(event && event.keyCode == 13)){
			submitSearch();
			return false;
		}else{
			return true;
		}
	}
	
	/*
	 * Checks the search to see if it a search that require a user to have accepted mature content on.
	 */
	function isRestrictedSearch(str) {
		str = str.toLowerCase();
		if(verified(str, "sex"))
			return true;
		else if(verified(str, "kardashian"))
			return true;
		else if(verified(str, "tits"))
			return true;
		else if(verified(str, "porn"))
			return true;
		else if(verified(str, "boobs"))
			return true;
		else if(verified(str, "naked"))
			return true;
		else if(verified(str, "paris hilton"))
			return true;
		else if(verified(str, "booty"))
			return true;
		else if(verified(str, "latinas"))
			return true;
		else if(verified(str, "pussy"))
			return true;
		else if(verified(str, "upskirt"))
			return true;
		else if(verified(str, "ass"))
			return true;
		else if(verified(str, "hentai"))
			return true;
		else if(verified(str, "blowjob"))
			return true;
		else if(verified(str, "thong"))
			return true;
		else if(verified(str, "tits"))
			return true;
		else if(verified(str, "fuck"))
			return true;
		else 
			return false;
	}
	
	function verified(str, phrase) {
		var index = str.indexOf(phrase);
		if(index > -1) {
			if(str.length == phrase.length)
				return true;
			if(index > 0 && str.substring(index -1, index) != " ")
				return false;
			if(((index + phrase.length) < str.length)&&(str.substring((index + phrase.length), (index + phrase.length + 1)) != " "))
				return false;
			
			return true;
		}
		return false;
	}
	
	/**
 * Function for around the web functionality
 */

	function secToMin(sec) {				
		var min = Math.floor(sec/60)
		sec = sec % 60
		t = two(sec)// + ":" + t
		
		var hr = Math.floor(min/60)
		min = min % 60
		t = two(min) + ":" + t
		
		var day = Math.floor(hr/60)
		hr = hr % 60
		if (hr > 0){
			t = two(hr)// + ":" + t
		}
			//t = day + ":" + t
		if(t.charAt(0) == "0"){
			t = t.substring(1, t.length);
		}	
		return t
	}
	
		function getQueryParam(queryParam) {
		var q = location.search;
		if(q.length > 1) {
			q = q.substring(1, q.length);
		}
		else {
			q = null;
		}
		var keyValuePairs = new Array();
		if(q) {
		  if (q.indexOf("&") != -1) {
				for(var i=0; i < q.split("&").length; i++) {
					keyValuePairs[i] = q.split("&")[i];
				}
			}
			else {
			  keyValuePairs[0] = q;
			}
			for(var j=0; j < keyValuePairs.length; j++) {
				if(unescape(keyValuePairs[j].split("=")[0]) == queryParam) {
					return unescape(keyValuePairs[j].split("=")[1]);
				}			
			}
		}
	
			return null;
		}
			
	function attachHandlersToNav(){
		$("searchMagnifyingGlass").onclick = function(){
			if($F('searchField') !=""){
				submitSearch();
			}
			return false;
		};		
		window.onresize = positionDropDown;
	}	
	//-->
	function fixH(one,two) {
		if ($(one)) {
		var lh=$(one).offsetHeight;
		var rh=$(two).offsetHeight;
			if(rh>lh){
				var nh = Math.max(lh, rh);
				$(one).style.height=nh+"px";
				$(two).style.height=nh+"px";
			}
		}
	}	
	
	function checkColumns(){
		var contentHeight = $("content").offsetHeight;
		var shadowLeftHeight = $("shadowLeft").offsetHeight;
		var shadowRightHeight = $("shadowRight").offsetHeight;
		
		if((contentHeight == shadowLeftHeight)&&(contentHeight == shadowRightHeight)){
			
		}else{
			getColumns();
			setTimeout("checkColumns()", 2000);
		}
	}
		
	function replaceAll(strText, toReplace, replacement) {
		var strReplaceAll = strText;
		var intIndexOfMatch = strReplaceAll.indexOf(toReplace);
  
    // Loop over the string value replacing out each matching
	  while (intIndexOfMatch != -1){
			strReplaceAll = strReplaceAll.replace(toReplace, replacement )
		 	intIndexOfMatch = strReplaceAll.indexOf(toReplace);
 		}	
		return strReplaceAll;
	}
	
	function init(){
		// quit if this function has already been called
		if (arguments.callee.done) return;			
		// flag this function so we don't do the same thing twice
		arguments.callee.done = true;
		attachHandlersToNav();
		whatPage();
        if(document.body.id == "buzz"){
			try{
				handlePageLoad();
			}catch(e){
				
			};				
			setTimeout("registerEventHandlers()", 300);			// this function lives in the buzz.js 
			setTimeout("getColumns()", 1000);
		}else if(document.body.id == "channel" || document.body.id == "personal_channel"){
			setTimeout("getColumns()", 1000);
		}
		else if(document.body.id == "title"){
            setTimeout("getColumns()", 1000);
			fixH("featuredVideo","featuredDesc");
			setTimeout("registerEventHandlers()", 300);			// this function lives in the title.js
		}else if(document.body.id == "registration"){
			getColumns();
			retrieveEmailAddress();
		}else if(document.body.id == "registration_thanks"){
			getEmail();
		}else if(document.body.id == "upload_video"){
			signedIn();//this function is in the registration.js
		}else if(document.body.id == "upload_video_complete"){
			loadVideoInfo();//this function is in the registration.js
		}
		else if(document.body.id == "category"){
			try{
				loadPlayer();
				handlePageLoad();
			}catch(e){
				
			};
			setTimeout("getColumns()", 1000);
		} else if(document.body.id == "AftermixHome"){
		  try {
		  	setLink();
		  } catch(e) {
		      //gulp
		  }
		}
		if(isIE7 || isFF2 || isIE){
            $("searchBox").style.background="url('http://admin.brightcove.com/destination/images/search-pane.gif') no-repeat 0 5px";
		}else if(isOpera){
			try {
				$("content").style.width = "960px";
            	$("searchBox").style.background="url('http://admin.brightcove.com/destination/images/search-pane.gif') no-repeat 0 5px";
            } catch (e) {
            	//gulp
            }
		}else if(isSafari){
			try {
				//This seemed that this was causing errors so I am commenting it out for now.
				//$("content").style.width = "960px";
				$("searchBox").style.background="transparent";
			} catch (e) {
				//gulp
			}
			//$("presearch").style.paddingLeft="5px";
		}else{
			$("searchBox").style.background="url('http://admin.brightcove.com/destination/images/search-pane.gif') no-repeat 0 5px";
		}
		
		dropDownLeft = getPositionLeft($("dropdownul"));
		seeAllLeft = getPositionLeft($("lastMenuItem"));
		
		$("searchField").focus();
		
		//A callback so that page specific events for onload can occur in their pages.
		pageSpecificOnLoad();
	};
	var dropDownLeft;
	var seeAllLeft;
	var dropdownTimeout=0;
	function positionDropDown(){
		//I am putting this at the top because I want it to happen as fast as possible.
		pageSpecificOnResize()
		var a = findPos($("lastMenuItem"));
		if(a != null) {
			$("dropdownul").style.left = a[0] - 10 +"px";
			$("dropdownul").style.top = a[1] + 30 +"px";
			if (isGecko) {
				$("dropdownul").style.left = a[0]-95 + "px";
				$("dropdownul").style.top = a[1] + 30 +"px";
			}
			if (isSafari || isOpera) {
				$("dropdownul").style.left = a[0]+555 + "px";
			}
		}		
	}
	function findPos(obj) {
	if(obj == null) {
		return null;
	}
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
	function getPositionLeft(This){
		var el = This;var pL = 0;
		while(el){pL+=el.offsetLeft;el=el.offsetParent;}
		return pL;
	}

// To find the top position, add this snippet to your code:

	function getPositionTop(This){
		var el = This;var pT = 0;
		while(el){pT+=el.offsetTop;el=el.offsetParent;}
		return pT;
	}
	
	   	
   
			function textCounter(field, maxlimit, ev) {
				var ev = ev || window.event;             // gets the event in ie or ns
        		var kCode = ev.keyCode || ev.which;
				if (field.value.length > maxlimit){ 
				  field.value = field.value.substring(0, maxlimit);
					if(field.charCount)  {
						field.charCount.innerHTML = maxlimit - field.value.length;
					}
/*				
					// let people like, reload and stuff y'know??
					switch(kCode) {
            case 35:
            case 36:
            case 65:
            case 67:
            case 86:
            case 88:
            case 90:
              if(!ev.ctrlKey)
                return false;
            case 8:
            case 9:
            case 46:
              return true;
            default:
              if(kCode>32 && kCode<41)
                return true;
              else
                return false;
          }
*/
          return true;
				}
				// otherwise, update 'characters left' counter
				else {
					if(field.charCount){
						field.charCount.innerHTML = maxlimit - field.value.length;
					}
					return true;
				}
			}
function cleanString(value,maxlength) {
	// insert spaces into super-long words
  // stupid prototype was putting safari into an infinite loop
	//var newval = value.gsub(/(\S{20})(?! )/,"#{1} #{2}");
	var newval = value.replace(/(\S{20})(?! )/g,"$1 ");
	// replace dangerous characters
	newval = newval.replace(/[^a-zA-Z0-9,_ -]/g,function(c) {
			if(c == "<") return "&lt;";
			if(c == ">") return "&gt;";
			if(c == "\"") return "&quot;";
			if(c == "'") return "&#39;";
			return c;
			});
	if(maxlength && maxlength > 0) {
		return newval.substring(0,maxlength);
	} else {
		return newval;
	}
}

// this is to limit a given class of fields to n lines of text
function limitLines(classOrObj, numLines) {
  /*
  var getElementsTime;
  var t1 = new Date();
  */
  if(typeof classOrObj == typeof "foo") {
    if(!document.getElementsByClassName) {
      return;
    } else {
      var fields = document.getElementsByClassName(classOrObj);
    }
  } else {
    fields = [ classOrObj ];
  }

  /*
  var d1 = new Date();
  getElementsTime = new Date() - d1;
  */
  var testString = "MM";
  var origHTML;
  var textField = "innerHTML";
  for(var i=1; i<numLines; i++) {
    testString += "<br>MM";
  }

  // work with the text, not the html
  if(fields.length > 0) {
    if(fields[0]['innerText'])
      textField = 'innerText';
    else
      textField = 'textContent';
  } else { // no fields by that class name
    return;
  }

  // Get the appropriate height of a numLines-line element
  origHTML = fields[0].innerHTML;
  fields[0].innerHTML = testString;
  var numLinesHeight = fields[0].offsetHeight * (1 + .5/numLines); // add half a line to make no mistake
  // restore its contents
  fields[0].innerHTML = origHTML;

  // now make sure everyone plays nice with heights
  for(var i=0;i<fields.length; i++) {
    if(!fields[i][textField] || fields[i].offsetHeight <= numLinesHeight) continue;

    var prev = fields[i][textField].length, curr = Math.floor(prev/2);
    origHTML = fields[i][textField];

    // binary search for where the crux point is
    while(prev != curr) {
      fields[i][textField] = origHTML.substring(0,curr)+"...";
      var tmp = curr;
      if(fields[i].offsetHeight <= numLinesHeight) {
        curr += Math.floor(Math.abs(prev-curr)/2);
        prev = tmp;
      } else {
        curr -= Math.ceil(Math.abs(prev-curr)/2);
        prev = tmp;
      }
    }
  }
}

//function to get query args on a page as an javascript object.  Example found on mature.jsp
function getArgs() {
	var args = new Object(  );
    var query = location.search.substring(1);
   	var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
    	var pos = pairs[i].indexOf('=');
        if (pos == -1) 
        	continue;
        		
        var argname = pairs[i].substring(0,pos);
        var value = pairs[i].substring(pos+1);
        args[argname] = unescape(value);
    }
    return args;
}

var Plumber = new function() {
	this.fixLeaks = function() {
		if(!document.getElementsByTagName) return;
		//var tags = [ "div", "span", "object", "param" ];
		var tags = [ "object" ];
		//var props = [ "onclick", "onmouseover", "onmouseout", "onkeyup", "onkeydown", "outerHTML" ];
		var props = [ "playVideoById", "pauseVideo" ];
		var elems;
		for(var i in tags) {
			elems = document.getElementsByTagName(tags[i]);
			for(var j in elems) {
				for(var k in props) {
					elems[j][props[k]] = null;
				}
			}
		}
	}
}
if(window.onunload) {
	var oldunload = window.onunload;
	window.onunload = function() {
		oldunload();
		Plumber.fixLeaks();
	}
} else {
	window.onunload = Plumber.fixLeaks;
}

	/* for other browsers */
	window.onload = init; 

/*Events that we extent so that each page can implement their on specific functions*/

function pageSpecificOnLoad() {
	//no op intended to over written in page specific code, currently used in buzz and home page.
}

function pageSpecificOnResize() {
	//no op intended to over written in page specific code, currently used in buzz and home page.
}

//Helper function to format a number to hava commas in it
function formatNumberWithCommas(number) {
	number = '' + number;
	if (number.length > 3) {
		var mod = number.length % 3;
		var output = (mod > 0 ? (number.substring(0,mod)) : '');
		for (i=0 ; i < Math.floor(number.length / 3); i++) {
			if ((mod == 0) && (i == 0))
				output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
			else
				output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
		}
		return (output);
	}
	else 
		return number;
}

//Helper function to format the date that was returned to us from the server, currently used in buzz and home page.
function formatDate(obj) {
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var date = new Date(obj['time']);
	return months[date.getMonth()] + " " + date.getDate();
}

 /*
  * This is a function that allows us to copy code in both FF and IE.
  */
 function copyToClipboard(elemId) {
  	var inElement = $(elemId);
  	if(isIE) {
  	 	var range = inElement.createTextRange();
   	 	if (range) {
     		range.execCommand('Copy');
     	}
  	} else {
    	var flashcopier = 'flashcopier';
    	if(!document.getElementById(flashcopier)) {
      		var divholder = document.createElement('div');
      		divholder.id = flashcopier;
      		document.body.appendChild(divholder);
    	}
    	document.getElementById(flashcopier).innerHTML = '';
    	var divinfo = '<embed src="http://admin.brightcove.com/destination/clipBoard/_clipboard.swf" FlashVars="clipboard='+escape(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    	document.getElementById(flashcopier).innerHTML = divinfo;
    }
  	copyFinished(elemId);
	}

/*
 * A callback for the copy function, this is incase a page wants to do something with the copy code.
 */
 function copyFinished(elemId) {
 	//no op;
 }
 
 /*
  *A helper function to get the args minus a value.  It will also return the args as String.
  */
  function getArgsAsString(args, arrayOfValToExtract) {
	var ret = "?";
	var extract = false;
		for(var key in args) {
			extract = false;
			for(var i = 0; i < arrayOfValToExtract.length; i++) {
				if(key == arrayOfValToExtract[i]) {
					extract = true;
					break;
				}
			}
			if(!extract) {
				ret = ret + key + "=" + args[key] + "&";
			}
		}
				
		if(ret.length > 1) {
			ret = ret.substring(0, ret.length -1);
		} else {
			ret = "";
		}
		return ret;
	}
	function errorReport(errorOutput){
		$("debugInfo").innerHTML += "<br style=\"separator\"/>" + errorOutput;
	}

