/***
Used for the Tour System
***/

// check the browser version
var ua = navigator.userAgent.toLowerCase();
var nn4 = document.layers ? 1:0;
var nn6 = (document.getElementById && (ua.indexOf('netscape') != -1)) ? 1:0;
var dom = document.getElementById ? 1:0;
var ie = (ua.indexOf('msie') != -1) ? 1:0;
var ie4 = (document.all && !document.getElementById) ? 1:0;
var mac = (ua.indexOf('mac') != -1) ? 1:0;


var agt = navigator.userAgent.toLowerCase();
var ie_mac = agt.indexOf("mac")!=-1 && document.all ? 1 : 0;
var clip_rate = 1; //speed of setTimout on wipe
var stop = 763;      //counter for wipe stop
var clipping = false; //is the layer clipping
var lyr = null;
var timer = null;     //timer for setTimeout

if ((customerService) || (pricingAndLicensing)) {
	noTransitionImage = true;
} else {
	noTransitionImage = false;
}

function checkForIEorNN () {
	if ((document.layers) || (ie4)) {
		document.location.href = "../upgrade.html";
	}	
}
checkForIEorNN ();

// make an object reference to a layer
// for cross browser dhtml
function lyrobj(this_lyr) {
	if (document.all && !document.getElementById) return document.all[this_lyr].style; 
	else if (document.getElementById) return document.getElementById(this_lyr).style;
}

page_layers = new Array();
page_layers = ["file", "toc", "oTransContainer"];

animation_layers = new Array();
if (screenArray[tour_group]['largeImg3'][pageNum]) {
	animation_layers = ["screen1", "screen2", "screen3"];
} else if (screenArray[tour_group]['largeImg2'][pageNum]) {
	animation_layers = ["screen1", "screen2"];
} else {
	animation_layers = ["screen1"];
}
freeTrialOff = new Image();
freeTrialOn = new Image();
freeTrialOff.src = "../../media/tours/mout_30_day_trial.gif";
freeTrialOn.src = "../../media/tours/mover_30_day_trial.gif";

nextOff = new Image();
nextOn = new Image();
backOff = new Image();
backOn = new Image();

nextOff.src = "../../media/tours/mout_next.gif";
nextOn.src = "../../media/tours/mover_next.gif";
backOff.src = "../../media/tours/mout_back.gif";
backOn.src = "../../media/tours/mover_back.gif";

function rollOver(imgName,imgAction)
{
	document[imgName].src = eval(imgName+imgAction+".src");
}

function changeImages() {
	  if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
		  document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
		}
	  }
}

// return current clip values
function clip_values(this_lyr,which) 
{
	var strip = this_lyr.clip.split("rect(")[1].split(")")[0];
	if (navigator.appName == "Netscape")
	{		
		var clipv = strip.split(",");		
	}
	else
	{
		var clipv = strip.split("px");
	}
	
	if (which=="t") return parseInt(clipv[0]);
	if (which=="r") return parseInt(clipv[1]);
	if (which=="b") return parseInt(clipv[2]);
	if (which=="l") return parseInt(clipv[3]);
}



// just clip a layer
function clip_lyr(this_lyr,t,r,b,l) {
if (ie_mac) return;
if (clipping) stop_clip();
var clip_this = lyrobj(this_lyr);
	clip_this.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}



// wipe the layer
function wipe_lyr(this_lyr,t,r,b,l) {
if (ie_mac) return;
var clip_this = lyrobj(this_lyr);
new_lyr = this_lyr;
new_t = t;
new_r = r;
new_b = b;
new_l = l;

	if (clip_values(clip_this,'r') >= stop) var clip_end = true;
	
	if (clipping) stop_clip();
	clipping = true;
	
	clip_this.clip = "rect("+(this.clip_values(clip_this,'t')+t)+"px "+(this.clip_values(clip_this,'r')+r)+"px "+Number(this.clip_values(clip_this,'b')+b)+"px "+Number(this.clip_values(clip_this,'l')+l)+"px)";
	if (clip_end != true) {
		timer = setTimeout("wipe_lyr(new_lyr,new_t,new_r,new_b,new_l)",clip_rate);
	} else { 
		stop_clip();
		return;
	}	
}


function stop_clip() {
	clearTimeout(timer);
	timer = null;
	clipping = false;
}

function ie_mac_largeImageDiv () {
	if (ie_mac) {
		var largeImageDiv = '<div id="largeImage1" style="position:absolute; left:0px; top:0px; width:0px; height:0px; z-index:2; visibility: hidden;">';
		largeImageDiv += '<table width="763" border="0" cellspacing="0" cellpadding="0">';
		largeImageDiv += '<tr bgcolor="#000000">';
		largeImageDiv += '<td align="right">';
		largeImageDiv += '<a class="white" href="javascript:hide_lyr(\'largeImage1\');"><font color="white"><b>Back to Tour</b></font>';
		largeImageDiv += '<img src="../../media/tours/btn_close2.gif" width="15" height="16" align="absmiddle" vspace="2" hspace="4" border="0"></a></td>';
		largeImageDiv += '</tr>'; 
		largeImageDiv += '<tr><td>';	
		largeImageDiv += '<a href="javascript:hide_lyr(\'largeImage1\');"><img src="../../media/tours/' + root_path + '/' + screenArray[tour_group]['largeImg1'][pageNum] +'" width=763 height=519 border=0 alt="Click to return to tour"></a>';
		largeImageDiv += '</td></tr>';
		largeImageDiv += '</table>';
		largeImageDiv += '</div>';
		if (screenArray[tour_group]['largeImg2'][pageNum]) {	
			largeImageDiv += '<div id="largeImage2" style="position:absolute; left:0px; top:0px; width:0px; height:0px; z-index:2; visibility: hidden;">';
			largeImageDiv += '<table width="763" border="0" cellspacing="0" cellpadding="0">';
			largeImageDiv += '<tr bgcolor="#000000">';
			largeImageDiv += '<td align="right">';
			largeImageDiv += '<a class="white" href="javascript:hide_lyr(\'largeImage2\');"><font color="white"><b>Back to Tour</b></font>';
			largeImageDiv += '<img src="../../media/tours/btn_close2.gif" width="15" height="16" align="absmiddle" vspace="2" hspace="4" border="0"></a></td>';
			largeImageDiv += '</tr>'; 
			largeImageDiv += '<tr><td>';	
			largeImageDiv += '<a href="javascript:hide_lyr(\'largeImage2\');"><img src="../../media/tours/' + root_path + '/' + screenArray[tour_group]['largeImg2'][pageNum] + '" width=763 height=519 border=0 alt="Click to return to tour!"></a>';
			largeImageDiv += '</td></tr>';
			largeImageDiv += '</table>';
			largeImageDiv += '</div>';
		}
		if (screenArray[tour_group]['largeImg3'][pageNum]) {
			largeImageDiv += '<div id="largeImage3" style="position:absolute; left:0px; top:0px; width:0px; height:0px; z-index:2; visibility: hidden;">';
			largeImageDiv += '<table width="763" border="0" cellspacing="0" cellpadding="0">';
			largeImageDiv += '<tr bgcolor="#000000">';
			largeImageDiv += '<td align="right">';
			largeImageDiv += '<a class="white" href="javascript:hide_lyr(\'largeImage3\');"><font color="white"><b>Back to Tour</b></font>';
			largeImageDiv += '<img src="../../media/tours/btn_close2.gif" width="15" height="16" align="absmiddle" vspace="2" hspace="4" border="0"></a></td>';
			largeImageDiv += '</tr>'; 
			largeImageDiv += '<tr><td>';	
			largeImageDiv += '<a href="javascript:hide_lyr(\'largeImage3\');"><img src="../../media/tours/' + root_path + '/' + screenArray[tour_group]['largeImg3'][pageNum] + '" width=763 height=519 border=0 alt="Click to return to tour!"></a>';
			largeImageDiv += '</td></tr>';
			largeImageDiv += '</table>';
			largeImageDiv += '</div>';

		}
		document.write(largeImageDiv);
	}
}

function showFile(f)
{	
	// enlargement images
	var str = '<table width="763" border="0" cellspacing="0" cellpadding="0">';
	str += '<tr bgcolor="#000000">';
	str += '<td align="right">';
	str += '<a class="white" href="javascript:closeFile()"><font color="white"><b>Back to Tour</b></font>';
	str += '<img src="../../media/tours/btn_close2.gif" width="15" height="16" align="absmiddle" vspace="2" hspace="4" border="0"></a></td>';
	str += '</tr>'; 
	str += '<tr><td>';	
	str += '<a href="javascript:closeFile()"><img src="../../media/tours/' + root_path + '/' + f +'" width=763 height=519 border=0 alt="Click to return to tour"></a>';
	str += '</td></tr>';
	str += '</table>';
	
	if (navigator.appName=="Netscape")
	{
		document.getElementById("file").innerHTML = str;
		show_lyr("file");
	}
	else if (ie_mac)
	{
		if (f == screenArray[tour_group]['largeImg1'][pageNum]) {
			hide_lyr("largeImage2");
			show_lyr("largeImage1");
		} else {
			hide_lyr("largeImage1");
			show_lyr("largeImage2");
		}
	}
	else
	{
		document.getElementById("file").innerHTML = str;
		clip_lyr("file",0,0,0,0);
		show_lyr("file");
		wipe_lyr("file",0,20,14,0);
	}
}



function closeFile()
{
	document.getElementById("file").innerHTML = "";
	hide_lyr("file");	
}



// load a file into the Content Iframe
function loadPage(f)
{
	if ((String(f).indexOf(".jpg") != -1) || (String(f).indexOf(".gif") != -1))
	{
		showFile(f);
		return;
	}
}

function showStyle (idName) {
	lyrobj(idName).display = "";
}

function hideStyle (idName) {
	lyrobj(idName).display = "none";
}

// show / hide layers
function show_lyr(this_lyr) {
	lyrobj(this_lyr).visibility = "visible";
	lyrobj(this_lyr).display = "block";
}
function hide_lyr(this_lyr) {
	lyrobj(this_lyr).visibility = "hidden";
	lyrobj(this_lyr).display = "none";	
}

function hide_all_lyr() {
	for (i = 0; i < page_layers.length; i++) {
		lyrobj(page_layers[i]).visibility = "hidden";
		lyrobj(page_layers[i]).display = "none";
	}
}

animation_counter = 0;

function run_animation () {
	if (!(noTransitionImage)) {
		animation_timing = 5000;
		animationInt = setInterval("animation_code()", animation_timing);
	}
}

function stop_animation () {
	if (!noTransitionImage) {
		clearInterval(animationInt);
	}
}

function animation_code() {
	if (ie && !(ie_mac)) {
		fnToggle();
	} else {
		hide_lyr(animation_layers[animation_counter]);
		animation_counter++;
		if (animation_counter >= animation_layers.length) {
			animation_counter = 0;
		}
		show_lyr(animation_layers[animation_counter]);
	}
}

function fnToggle() {
   	oTransContainer.filters[0].Apply();
   	animation_counter++;
	if (animation_counter >= animation_layers.length) {
		animation_counter = 0;
	}
	for (i = 0; i < animation_layers.length; i++) {
		if (animation_counter == i) {
			show_lyr(animation_layers[animation_counter]);	
		} else {
			lyrobj(animation_layers[i]).visibility = "hidden";
		}
	}
   	oTransContainer.filters[0].Play();
}


function writeScreenBothScreens (tour_group, pageNum) {
	if (pricingAndLicensing) {
		writeBlankScreen();
	} else if (customerService) {
		writeCustomerServiceScreen();
	} else {
		writeScreen (screenArray[tour_group]["caption1"][pageNum], screenArray[tour_group]["smallImg1"][pageNum], screenArray[tour_group]["largeImg1"][pageNum], 1);
		if (screenArray[tour_group]['largeImg2'][pageNum]) {
			writeScreen (screenArray[tour_group]["caption2"][pageNum], screenArray[tour_group]["smallImg2"][pageNum], screenArray[tour_group]["largeImg2"][pageNum], 2);
		}
		if (screenArray[tour_group]['largeImg3'][pageNum]) {
			writeScreen (screenArray[tour_group]["caption3"][pageNum], screenArray[tour_group]["smallImg3"][pageNum], screenArray[tour_group]["largeImg3"][pageNum], 3);		
		}
	} 
}

function writeBlankScreen () {
	animationInt = 0;
	screenCode = '';
	
	document.write(screenCode);
}



function writeCustomerServiceScreen () {
	animationInt = 0;
	screenCode = '<img src="../../media/tours/i_customer_support.jpg" width="274" height="326">';
	
	document.write(screenCode);
}


function writeScreen (caption, smallImg, largeImg, screenNum) {
	if (screenNum == 1) {
		screenCode = '<div id="screen1" style="position:absolute; left:0px; top:0px; width:350px; height:350px; z-index:2; visibility: visible;">';
	} else if (screenNum == 2) {
		screenCode = '<div id="screen2" style="position:absolute; left:0px; top:0px; width:350px; height:350px; z-index:2; visibility: hidden;">';				
	} else if (screenNum == 3) {
		screenCode = '<div id="screen3" style="position:absolute; left:0px; top:0px; width:350px; height:350px; z-index:2; visibility: hidden;">';				
	}
	screenCode += '    <table width="329" border="0" cellspacing="0" cellpadding="0" height="280">';
	screenCode += '     <tr>';
	screenCode += '       <td background="../../media/tours/' + root_path + '/bg_screen_grab.gif" valign="top" align="center">';
	screenCode += '         <table width="320" border="0" cellspacing="0" cellpadding="0">';
	screenCode += '           <tr>';
	screenCode += '             <td height="5"></td>';
	screenCode += '           </tr>';
	screenCode += '           <tr>';
	screenCode += '             <td><img src="../../media/tours/' + root_path + '/' + smallImg + '" width="320" height="218" vspace="5" border="0"></td>';
	screenCode += '           </tr>';
	screenCode += '           <tr>';
	screenCode += '             <td align="center" height="45"><span class="grabCaption">' + caption + '</span></td>';
	screenCode += '           </tr>';
	screenCode += '         </table>';
	screenCode += '       </td>';
	screenCode += '     </tr>';
	screenCode += '   </table>';
	screenCode += '   <span class="ver11"><a href="javascript:loadPage(\'' + largeImg + '\');"><img src="../../media/tours/ico_magnify_image_gray.gif" width="27" height="22" align="absmiddle" border="0" vspace="10"><b>Click to Enlarge</b></a></span>';
	screenCode += ' </div>';
	
	document.write(screenCode);
}

function writeTableOfContents (arrayName) {
	tableCode = '<div id="toc" style="position:absolute; left:0px; top:78px; width:365px; height:428px; z-index:2; visibility: hidden">';
	tableCode += '  <table width="365" border="0" cellspacing="0" cellpadding="0" class="tocTableBdrSolid" height="100%">';
	tableCode += '   <tr>';
	tableCode += '     <td valign="top" bgcolor="#FBFBFB">';
	tableCode += '       <table width="100%" border="0" cellspacing="0" cellpadding="4">';
	tableCode += '         <tr>';
	tableCode += '           <td align="right" height="32" valign="bottom">';
	tableCode += '            <p class="ver10"><b><a href="javascript:openCloseToc();">Close</a></b><a href="javascript:openCloseToc();"><img src="../../media/tours/btn_close2.gif" width="15" height="16" align="absmiddle" hspace="4" border="0"></a></p>';
	tableCode += '           </td>';
	tableCode += '         </tr>';
	tableCode += '       </table>';
	tableCode += '       <table border="0" cellspacing="0" cellpadding="2" width="305" align="center">';
	tableCode += '         <tr valign="bottom">';
	tableCode += '           <td height="50" colspan="2">';
	tableCode += '           <p class="tocHeader">Table of Contents</p>';
	tableCode += '           </td>';
	tableCode += '         </tr>';
	tableCode += '         <tr valign="bottom">';
	tableCode += '           <td colspan="2" height="30">';
	tableCode += '             <table width="100%" border="0" cellspacing="0" cellpadding="3" class="tocTableBdr">';
	tableCode += '               <tr>';
	tableCode += '                 <td bgcolor="#F1F0E0" class="ver11">&nbsp;&nbsp;Click on a link to jump to that screen</td>';
	tableCode += '               </tr>';
	tableCode += '             </table>';
	tableCode += '           </td>';
	tableCode += '         </tr>';
	tableCode += '         <tr>';
	tableCode += '           <td colspan="2" height="12"></td>';
	tableCode += '         </tr>';
	
	for (i = 1; i < tocLinkNameArray[arrayName].length; i++) {
		tableCode += ' <tr>';
		tableCode += '   <td align="right" valign="top" width="30">';
		tableCode += '   <p class="ver11"><b>' + i + '.</b></p>';
		tableCode += '   </td>';
		tableCode += '   <td valign="top" width="295">';
		tableCode += '  <p class="ver11"><a href="' + tocLinkArray[arrayName][i] + '">' + tocLinkNameArray[arrayName][i] + '</a></p>';
		tableCode += '   </td>';
		tableCode += ' </tr>';
	}
	
	tableCode += '</table>';
	tableCode += '</td>';
	tableCode += '</tr>';
	tableCode += '</table>';
	tableCode += '</div>';

	document.write(tableCode);
}

// this variable keeps track if the Table of Contents is open or closed
tocIsClosed = true;
//this function opens and closes the Table of Contents (toc)
function openCloseToc () {
	if (tocIsClosed) { //open
		tocIsClosed = false;
		if (!customerService) {
			stop_animation();
			hide_all_lyr();
		}
		show_lyr('toc');
	} else { //close
		tocIsClosed = true;
		hide_lyr('toc');
		if (!customerService) {
			show_lyr('oTransContainer');
			run_animation();
		}
	}
}

function writeButtons () {
	buttonCode = '<table width="763" border="0" cellspacing="0" cellpadding="0">';
	buttonCode += '  <tr>';
	buttonCode += '<td width="318" align="right" valign="top"><a href="javascript:openCloseToc();" target="_self"><img src="../../media/tours/' + root_path + '/mout_toc.gif" width="146" height="20" hspace="50" border="0"></a></td>';
	if (pageNum == 1) {
		buttonCode += '<td width="34" align="right" valign="top"><img name="back" src="../../media/tours/mnull_back.gif" width="34" height="21" border="0"></td>';
	} else {
		buttonCode += '<td width="34" align="right" valign="top"><a href="' + tocLinkArray[tour_group][pageNum - 1] + '" onMouseOver="rollOver(\'back\',\'On\');" onMouseOut="rollOver(\'back\',\'Off\');"><img name="back" src="../../media/tours/mout_back.gif" width="34" height="21" border="0"></a></td>';
	}

	buttonCode += '<td width="50" cellpadding="3" align="center" background="../../media/tours/bg_page_numbers.gif" class="pageNumbers">' + pageNum + ' of ' + (tocLinkArray[tour_group].length - 1) + '</td>';
	
	if ((tocLinkArray[tour_group].length - 1) == pageNum) {
		buttonCode += '<td width="36" valign="top" align="left"><img name="next" src="../../media/tours/mnull_next.gif" width="36" height="21" border="0"></td>';
	} else {
		buttonCode += '<td width="36" valign="top" align="left"><a href="' + tocLinkArray[tour_group][pageNum + 1] + '" onMouseOver="rollOver(\'next\',\'On\');" onMouseOut="rollOver(\'next\',\'Off\');"><img name="next" src="../../media/tours/mout_next.gif" width="36" height="21" border="0"></a></td>';
	}
	buttonCode += '<td width="325" valign="top"><a href="javascript:self.close();"><img src="../../media/tours/' + root_path + '/btn_exit_tour.gif"" width="146" height="20" hspace="50" border="0"></a></td>';
	buttonCode += '</tr>';
	buttonCode += '</table>';
	
	document.write(buttonCode);
}

function goToTrialPage () {
	self.opener.location.href = "../../ProSchTrial.aspx";
	self.opener.focus();
}