var str = ""+location.href;
var i=str.indexOf("//")+2;
var j=str.indexOf("/youtools");
var server = "http://" + str.substring(i,j);

var	AlreadyTestedUrl	= server+"/youtools/wizard/alreadytested.asp";
var	LiveWizardUrl	= server+"/youtools/wizard/live/default.asp";
var LiveILWizardUrl = server+"/youtools/wizard/liveil/default.asp";
var	LiveSLWizardUrl	= server+"/youtools/wizard/silverlight/default.asp";

var	ArchiveWizardUrl	= server+"/youtools/wizard/archive/default.asp";
var	ytLiveWindow	= server+"/youtools/ytclient/ndstudent_6_0/default.aspx";
var	ytArchiveWindow	= server+"/youtools/ytclient/ndarchive_6_0/default.aspx";
var	ytArchiveSLwindow = server + "/youtools/ytclient/ndarchive_6_0/SLdefault.aspx";
var	ytLiveSLwindow = server + "/youtools/ytclient/ndstudent_6_0/SLdefault.aspx";
   

var serverWin;

OsError			= "This presentation features technologies supported by Windows. \n" +
				  "Use Windows OS or Virtual PC software to access this presentation.";
IEError			= "This presentation features technologies not supported by the browser you are currently using.\n\n" +
				  "This presentation can be viewed only with Internet Explorer 5.0 or later.\n" +
				  "Access this page again in Internet Explorer and launch the presentation.\n\n" +
				  "Instructions: \n" +
				  "  1.  Copy the address of this page \n" +
				  "  2.  Click on the Start button and select:  Programs Internet Explorer to launch IE \n" +
				  "  3.  Paste the address into the address bar of the Internet Explorer. \n" +
				  "  4.  Launch the presentation again\n\n" +
				  "Thank you!";
MPError			= "This presentation features technologies supported by Windows Media Player 6.4 or later.\n\n" +
				  "Install the suitable Windows Media Player before attending.\n\n" +
				  "You can download a free version of the Windows Media Player from the following Microsoft site: " +
				  "http://www.microsoft.com/windows/windowsmedia/download/default.asp";



function getX() {
  return screen.availWidth;
}


function getY() {
  return screen.availHeight;
}


function checkOS() {
	if( navigator.platform != "Win32" ) {
		alert(OsError);
		return false;
	} else if( !checkBrowser() || !checkVersion() )	 {
		alert(IEError);
		return false;
	} else if( !checkMediaPlayer() ) {
		alert(MPError);
		return false;
	} 
	return true;	  
}

// Check if a popup blocker is activated
function checkPUBlocker(theWindow) {
	if (theWindow==null)
		alert("A Popup Blocker or Personal Firewall software on your computer interfere with the webcast reception.\nConfigure your Popup Blocker and Firewall to allow traffic from the domain you-niversity.com.");
}


	// Remove all HTML tags from a given string:
	function cleanTags(original) {
		var counter=0;	// for an endless loop, just in case
		
		var tmp=original;

		if (tmp == null || tmp=="null")
			return "";
		
        // Delete all HTML tags:
		while (tmp.search(/<(?:[^>'"]*|(['"]).*?\1)*>/g) != -1 && counter<500) {
			tmp = tmp.replace( /<(?:[^>'"]*|(['"]).*?\1)*>/g, "" )
			counter++;
		}
 
		counter=0;
		// remove the dots (throws an error in the excel report)
 		while (tmp.search(/\./) != -1 && counter<500) {
			tmp = tmp.replace(/\./, "")
			counter++;
		}

		counter=0;
		// remove the question marks (throws an error in the excel report)
 		while (tmp.search(/\?/) != -1 && counter<500) {
			tmp = tmp.replace(/\?/, "")
			counter++;
		}
		
		return tmp;
	}

// attend LIVE
function attendLiveClass6_0(channel, name,  redirectUrl, saveAttendance, byPhone, AttendaceID, proxyUrl) {
		if (!saveAttendance)
			AttendaceID=-1;	// Don't debit super-users
		
		if (typeof(programId)=="undefined")
		{
			originalUrl	= "?OverThePhone=" + byPhone + "&StudentName=" + name + "&ECourseName=" + channel + "&AttendaceID=" + AttendaceID + "&affName=" + affiliateName;
		}
		else
		{
			originalUrl	= "?OverThePhone=" + byPhone + "&StudentName=" + name + "&ECourseName=" + channel + "&AttendaceID=" + AttendaceID + "&programId=" + programId + "&programName=" + cleanTags(programName) + "&userId=" + userId + "&affName=" + affiliateName + "&proxy=" + proxyUrl;
		}
		
		if(isSLplayer != null && isSLplayer != false && typeof(isSLplayer) != "undefined")
		{
			serverUrl = ytLiveSLwindow;
			//originalUrl += "&slGuid=" + slGuid + "&proxy=" + proxyUrl;
			///
			originalUrl += "&slGuid=" + slGuid;
			///
		}
		else
		{
			serverUrl = ytLiveWindow;
		}
		
		url	= serverUrl + originalUrl;

		if (channel=="colgate_course")
		  url="http://webcast.you-niversity.com/youtools/companies/colgate/colgateLiveMain.html";

		if (channel=="chh_course")
		  url="http://webcast.you-niversity.com/youtools/companies/chh/chhLiveMain.html";

		if (channel=="dotnet35_course")
		  url="http://webcast.you-niversity.com/youtools/companies/dotnet35/selaLiveMain.asp?StudentName=" + name + "&AttendaceID=" + AttendaceID + "&programId=" + programId;


		location.href=url;
}


// attend ARCHIVE
function attendArchiveClass6_0(channel, name, redirectUrl, saveAttendance, AttendaceID) {
		if (!saveAttendance)
			AttendaceID=-1;	// Don't debit super-users
		
		if (typeof(programId)=="undefined") // user comes from Preview in WC
		{
			originalUrl	= "?StudentName=" + name + "&ArchiveCode=" + channel + "&AttendaceID=" + AttendaceID + "&affName=" + name;
		}
		
		else // user comes from Conference Center
		{
			originalUrl	= "?StudentName=" + name + "&ArchiveCode=" + channel + "&AttendaceID=" + AttendaceID + "&programId=" + programId + "&programName=" + programName + "&affName=" + affiliateName;		
		}
		
		if(channel.indexOf("_") == -1) //the channel cantains guid           //(slGuid != null && slGuid != "" && typeof(slGuid) != "undefined")
		{
			serverUrl = ytArchiveSLwindow;
			//originalUrl += "&slGuid=" + slGuid;
		}
		else //the channel cantains archive id
		{
			serverUrl = ytArchiveWindow;
		}
		
		url = serverUrl + originalUrl;		
		location.href=url;
}

// Open a webcast window with a waiting page
function openWebcastWin(affId, isArchive, channelToAttend)//(affId, isArchive) {
{
	var DesieredWidth = 600;
	var DesieredHeight = 400;
				
	var ScreenWidth = screen.width;
	var ScreenHeight = screen.height;
	var nPositionX = (ScreenWidth - DesieredWidth) / 2-5;
	var nPositionY = (ScreenHeight - DesieredHeight) / 2-40;

 	var YtOpts		= "'toolbar=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes," +
					  "left=" + nPositionX + ",top=" + nPositionY + ",width="+DesieredWidth + ",height="+DesieredHeight + "'";
	
	if( serverWin == null || serverWin.closed )
	{ 
		serverWin	= window.open("/youtools/companies/attendance/waitForWebcast.asp?affiliateId="+affId + "&channel=" + channelToAttend, "webcastWin", YtOpts);
	
	}
	checkPUBlocker(serverWin);
	serverWin.focus();
	return serverWin;
}

// Redirect to Didi's page (which then redirects to the given url)
function openAlreadyTested(name, email, url) {
	if (email=="")
		email=" ";
	var theUrl = AlreadyTestedUrl + "?name=" + name + "&email=" + email + "&url="+url;
	location.replace(theUrl);
}


// Open the wizard for the LIVE lectures
function openNewWizard(userName, userEmail, nAffiliateID, isSL) {
	var fullWizard = LiveWizardUrl + "?name=" + userName + "&email=" + userEmail;
	try
	{
		if (isSL)
		{
			 fullWizard = LiveSLWizardUrl + "?name=" + userName + "&email=" + userEmail;
		}	
	}
	catch (AnyError)
	{
		//Ignore
	}

	var wWidth=750;
	var wHeight=550;
	var wTop = ((getY()-wHeight)/2);
	var wLeft = ((getX()-wWidth)/2);
	
	if (getX()<700) {
		wWidth = getX()-10;
		wHeight = getY()-30;
		wTop=0;
		wLeft=0;
	}
	
	var	opts	= 'top=' +wTop+ ',left=' +wLeft + ',status=no,scrollbars=no,resizable=yes,width=' + wWidth + ',height=' + wHeight;
    serverWin	= window.open(fullWizard, 'wizardWin', opts);
}




// Open the wizard for the LIVE lectures
function openTechSupport() {
	var wWidth=750;
	var wHeight=500;
	var wTop = ((getY()-wHeight)/2);
	var wLeft = ((getX()-wWidth)/2);
	
	if (getX()<700) {
		wWidth = getX()-10;
		wHeight = getY()-30;
		wTop=0;
		wLeft=0;
	}
	
	var	opts	= 'top=' +wTop+ ',left=' +wLeft + ',scrollbars=no,resizable=yes,width=' + wWidth + ',height=' + wHeight;
    serverWin	= window.open("http://www.you-niversity.com/mail/technicalSupport.asp", 'techsupport', opts);
}




// Open the wizard for the ARCHIVED lectures
function openYTWizard() {
	openNewWizard(); // The same as LIVE lecture. Now that's an adapter !
}


// Check browser's type
function	checkBrowser() {
	return (navigator.appName.indexOf('Netscape') < 0);
}


// Check browser's version
function	checkVersion() {
	var	v	= navigator.appVersion;
	if( navigator.appName.indexOf('Explorer') >= 0 ) {
		if( v.indexOf('MSIE 3') >= 0 || v.indexOf('MSIE 4') >= 0 )
			return false;
	}
	return true;						// No browser error
}


// Check if Media player is installed
function	checkMediaPlayer() {
	if( navigator.appName.indexOf('Explorer') >= 0 ) {
		var	objPlayer	= null;
		eval('try { objPlayer = new ActiveXObject("MediaPlayer.MediaPlayer.1"); } catch(ex) {}');
		if( objPlayer != null )
			return true;
	}
	return false;
}



// Pop up the Firewall considerations page (from requirements)
function showHelp() {
	window.open("/youtools/companies/help/youtoolsNewGui/help1.html", "newWin", "resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no");
}



// Pop up the Firewall considerations page (from requirements)
function showFirewalls() {
	window.open("/youtools/companies/help/youtoolsNewGui/help80.html", "newWin", "resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no");
}


function verifyClosing() {
	opener.event.returnValue  = "Exit the Virtual Classroom?";
	alert(2);
}

