function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function addfav(){
	var bookmarkurl = window.location.href;
	var bookmarktitle = document.title;
	if (document.all) {
		 if (window.external) {
			window.external.AddFavorite(bookmarkurl,bookmarktitle);
		 } else { 
			alert("Sorry! Your browser doesn't support this function.");
		 }
	} else { 
			alert("Sorry! Your browser doesn't support this function.");
		 }
}
function addBookmark() { 
	var bookmarkurl = window.location.href;
	var bookmarktitle = document.title;
	if (window.sidebar) { 
		window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
	} else if( document.all ) { 
		window.external.AddFavorite( bookmarkurl, bookmarktitle); 
	} else if( window.opera && window.print ) { 
		return true; 
	} else { 
		alert("Sorry! Your browser doesn't support this function.");
	}
} 
function formatTime(rawdatetime)
{
   var dt     = new Date(rawdatetime);
   var hour   = dt.getHours();
   var minute = dt.getMinutes();
   var second = dt.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
}
function formatDate(rawdatetime) {
	var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

	var dt = new Date(rawdatetime);

	var fmtDate = dt.getDate();
	var fmtDay = dt.getDay();
	var fmtMonth = dt.getMonth();
	var fmtMonthName = months[fmtMonth];
	var fmtYear = dt.getFullYear();
	var fmtTime = formatTime(rawdatetime);

	var currentDT = new Date();

	var currentDate = currentDT.getDate();
	var currentDay = currentDT.getDay();
	var currentMonth = currentDT.getMonth();
	var currentMonthName = months[fmtMonth];
	var currentYear = currentDT.getFullYear();
	var currentTime = formatTime(currentDT);

	if ((fmtDate == currentDate) && (fmtMonth == currentMonth) && (fmtYear == currentYear)) {
		var dateStr = "Today, " + fmtTime;
	} else if ((fmtDate == currentDate-1) && (fmtMonth == currentMonth) && (fmtYear == currentYear)) {
		var dateStr = "Yesterday, " + fmtTime;
	} else {
		var dateStr = Left(days[fmtDay],3) + ", " + Left(fmtMonthName,3) + " " + fmtDate + ", " + fmtYear + " " + fmtTime;
	}
	document.write(dateStr);
}

function cntrPopWin(popUrl, popWidth, popHeight) {
	pop_left = 0;
	pop_top = 0;
	popName = "cntrWin";
	scrCenter_x = screen.width/2;
	scrCenter_y = screen.height/2;
	if ((popWidth == "") || (popWidth == undefined)) {
		popWidth = 650;
		popHeight = 550;
		resize = "yes";
	} else {
		resize = "no";
//		alert(popWidth);
	}
		pop_left = scrCenter_x - (popWidth/2);
		pop_top = scrCenter_y - (popHeight/2) - 30;
	popupWin = window.open(popUrl, popName, 'width=' + popWidth + ',height=' + popHeight + ',left=' + pop_left + ',top=' + pop_top + ',scrollbars=yes,resizable='+resize);
}

function timeDiff(timeIn) {
	date1 = new Date(timeIn);
	date2 = new Date();
	timediff  = new Date();

	timediff = Math.abs(date1.getTime() - date2.getTime());

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24));
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60));
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60));
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000);
	timediff -= secs * 1000;

	output = "";
	if (weeks > 0) {
		if (weeks == 1) {
			output = output + weeks + " week ";
		} else {
			output = output + weeks + " weeks ";
		}
	}
	if (days > 0) {
		if (days == 1) {
			output = output + days + " day ";
		} else {
			output = output + days + " days ";
		}
	}
	if (hours > 0) {
		if (hours == 1) {
			output = output + hours + " hr ";
		} else {
			output = output + hours + " hrs ";
		}
	}
	if (mins > 0) {
		if (mins == 1) {
			output = output + mins + " min ";
		} else {
			output = output + mins + " mins ";
		}
	}
	if (secs > 0) {
		if (secs == 1) {
			output = output + secs + " sec ";
		} else {
			output = output + secs + " secs ";
		}
	}
	output = output + "ago";
	return output;
}

function expop(whichsection){
  if (whichsection == "*") {
	var e = document.getElementsByTagName('body')[0];
  } else {
	var e = document.getElementById(whichsection);
  }
  if (e){
	var a=e.getElementsByTagName('a');
	for (var i=0;i<a.length;i++){
	if (a[i].getAttribute('href') != null && a[i].getAttribute('href').indexOf("://") >= 0 && a[i].getAttribute('href').toUpperCase().indexOf(document.domain.toUpperCase()) == -1){
	//	a[i].className+=a[i].className?' outlink':'outlink';
		a[i].title+=' (opens in new window)';
		a[i].onclick=function(){newWin=window.open(this.href,'exWin');if(window.focus){newWin.focus()} return false;}
//      a[i].onkeypress=function(){newWin=window.open(this.href,'exWin');if(window.focus){newWin.focus()} return false;}
	  }
	}
  }
}

function playLesson(sku, id, foldername, movieCode){
	size = 'Large';
	if ((size == "Large") || (size == "large") ){
		winwidth=800;
		winheight=600+50;
	}
	else{
		winwidth=640;
		winheight=480+50;
	}
	wposx=0;
	wposy=0;
	file =  'http://www.vtc.com/modules/members/lessonPlayEnc.php?size=' + size + '&foldername=' + foldername + '&sku=' + sku + '&id=' + id  + '&movieCode=' + movieCode ;
	popupWin = window.open(file, "vtcplayer", "status=no,resizable=no,toolbar=no,scrollbars=no,screenX=" + wposx + ",screenY=0,left=" + wposx + ",top=" + wposy + ",width=" + winwidth + ",height=" + winheight);
	popupWin.focus();
}
