/********************************************
Disclaimer Script

This is the script for the disclaimer.  Any time there is a link, use the function openLink(URL)
to open that link with the disclaimer.  Just pass in the URL into the function and the link will be opened.  Be aware that sometimes the link will not work if the page
linked to uses frames.  This is due to how that page's javascript uses it's frame page, it will
access the wrong frame page.  Most links will be fine though.

Example: openLink("www.blizzard.com");   (opens blizzard's home page)
*********************************************/
var newwin;
/***************************************************
openLink:  This is the function that needs to be called in the HTML.  Just enter in the 
           URL and the function will take care of the rest.  openLink will open a window
           and create a frame page and copy the script function reportBadLink
           to that frame page.  This had to be done to make it work in netscape.  The
           frames are then created.
***************************************************/
function openLink(url)
{
	var HTML = "";
	var element;
	var referringURL = top.Main.location.href;
	var outsideURL = "none";
	var str = new String(url);
	if(str.indexOf("http:\/\/") != 0 && str.indexOf("https:\/\/") != 0)
		outsideURL = "http:\/\/" + url;
	else outsideURL = url;
	newwin = window.open("","newwin","height=600,width=800,resizable,toolbar,scrollbars=no");
	newwin.moveTo(100,100);
	newwin.focus();
	newwin.onresize=changeIframe;
	newwin.onload=changeIframe;
	
	if(navigator.userAgent.indexOf("Safari") != -1)
	{
		HTML += '<HTML><HEAD><TITLE>Outside Link</TITLE>\n'
		HTML += '<SCRIPT language="JavaScript">' + reportBadLink + changeIframe + setresize + '</SCRIPT>\n';
		HTML += '<STYLE TYPE="text/css">\n';
		HTML += '.style1{ font-weight: bold; text-decoration: none; color: #000000; font-size: 10pt;}\n';
		HTML += '.style1:hover{ text-decoration: none; color: #3729e7; font-size: 10pt; font-family: ariel;}\n';
		HTML += '.disclaimer{ text-decoration: none; color: #350697; font-size: 12pt;}\n';
		HTML += '.background {background-image: url("/is/cid/html/Warning02.jpg"); background-repeat: no-repeat;background-position: top center;}\n';
		HTML += '</STYLE> ';
		HTML += '</HEAD>\n ';
		HTML += '</HEAD> ';
		HTML += '<BODY BGCOLOR="#ffffff" CLASS="background"><BR>\n';
		HTML += '<TABLE ALIGN="center" CELLSPACING="0" CELLPADDING="0" BORDER="0"> \n';
		HTML += '<TR><TD COLSPAN="2" ALIGN="center" HEIGHT="25" WIDTH="300"><B></B></TD>\n';
		HTML += '</TR><TR><TD><A CLASS="style1" HREF="#" ONCLICK="top.window.opener.returnToCourse(top.window);"><FONT \n';
		HTML += 'SIZE="-2">RETURN TO COURSE</FONT></A></TD> \n';
		HTML += '<TD ALIGN="right"><A HREF="#" CLASS="style1" \n';
		HTML += 'ONCLICK="top.reportBadLink(top.window,\'' + outsideURL + '\',\'' + referringURL + '\',\'' + top.RS6000 + '\');return false;"><FONT SIZE="-2">REPORT BAD \n';
		HTML += 'LINK</FONT></A></TD> \n';
		HTML += '</TR>\n';
		HTML += '</TABLE>\n';
		HTML += '<CENTER><IFRAME ID="link" HEIGHT="450" WIDTH="785" BORDER="0" VSPACE="0" HSPACE="0"></IFRAME></CENTER></BODY></HTML>\n';
	}
	
	else
	{
		HTML += '<HTML><HEAD><TITLE>Outside Link</TITLE>';
		HTML += '<SCRIPT language="JavaScript">' + reportBadLink + '</SCRIPT>';
		HTML += '</HEAD>\n ';
		HTML += '<FRAMESET ROWS="75,*" FRAMEBORDER="0" FRAMESPACING="0" BORDER="0">\n';
		HTML += '<FRAME SRC="about:blank" ID="nav" NAME="nav" MARGINWIDTH="0" MARGINHEIGHT="0" \n';
		HTML += 'SCROLLING="AUTO">\n';
		HTML += '<FRAME SRC="about:blank" ID="link" NAME="link" MARGINWIDTH="0" MARGINHEIGHT="0" \n';
		HTML += 'SCROLLING="AUTO">\n';
		HTML += ' </FRAMESET> \n';
		HTML += '</HTML>\n';
	}

	newwin.document.writeln(HTML);

	var body = "";
	if(!document.all && navigator.userAgent.indexOf("Safari") == -1) var a = window.open("","","width=100,height=100"); /* This takes care of a 
netscape error, netscape won't let you access the frames on the page without opening another window 
first */
	if(navigator.userAgent.indexOf("Safari") == -1)
	{
		newwin.window.nav.document.open();
		body += '<HTML><HEAD>';
		body += '<TITLE>top</TITLE>';
		body += '<STYLE TYPE="text/css">';
		body += '.style1{ font-weight: bold; text-decoration: none; color: #000000; font-size: 10pt;}';
		body += '.style1:hover{ text-decoration: none; color: #3729e7; font-size: 10pt; font-family: ariel;}';
		body += '.disclaimer{ text-decoration: none; color: #350697; font-size: 12pt;}';
		body += '.background {background-image: url("/is/cid/html/Warning02.jpg"); background-repeat: no-repeat;background-position: center;}';
		body += '</STYLE> ';
		body += '</HEAD> ';
		body += '<BODY BGCOLOR="#ffffff" CLASS="background"> <BR> ';
		body += '<TABLE ALIGN="center" CELLSPACING="0" CELLPADDING="0" BORDER="0"> ';
		body += '<TR><TD COLSPAN="2" ALIGN="center" HEIGHT="25" WIDTH="300"><B></B></TD>';
		body += '</TR><TR><TD><A CLASS="style1" HREF="#" ONCLICK="top.window.opener.returnToCourse(top.window);"><FONT ';
		body += 'SIZE="-2">RETURN TO COURSE</FONT></A></TD> ';
		body += '<TD ALIGN="right"><A HREF="#" CLASS="style1" ';
		body += 'ONCLICK="top.reportBadLink(top.window,\'' + outsideURL + '\',\'' + referringURL + '\',\'' + top.RS6000 + '\');return false;"><FONT SIZE="-2">REPORT BAD ';
		body += 'LINK</FONT></A></TD> ';
		body += '</TR>';
		body += '</TABLE>';
		body += '</BODY></HTML>';
		newwin.nav.document.writeln(body);
	}
	if(document.all || document.layers) newwin.link.location = outsideURL;
	else newwin.document.getElementById("link").src = outsideURL;
	if(!document.all && navigator.userAgent.indexOf("Safari") == -1)  a.close();
	//setresize(newwin);
	newwin.onresize=changeIframe;
}

function setresize(win)
{
	win.onresize=changeIframe;
}

function returnToCourse(win)
{
	win.close();
}

/******************************************
changeIframe: Used by Safari on macs for when the window changes size.  Safari uses an
	      iframe to load the outside link in, and it has to change size when the
	      window changes size.  This function is set as the onresize function.
******************************************/

function changeIframe()
{
	var element = newwin.document.getElementById("link");
	element.style.height = newwin.innerHeight-75;
	element.style.width = newwin.innerWidth-15;
}

/*********************************************
reportBadLink:  In the case the user clicks on "Report Bad Link", this function
                is called.  It prints out on a new new window the form needed
                to report a bad link.
*********************************************/
function reportBadLink(win,outsideURL,referringURL,RS6000)
{
  var link=outsideURL;
  var page_location=referringURL;
  var page_name=page_location.substring(page_location.lastIndexOf("/")+1,page_location.lastIndexOf("."));
  var win1 = window.open("","win1","width=800,height=600,resizable,toolbar");
  win1.document.writeln('<HTML><HEAD><TITLE>Report bad URLs</TITLE>');
  win1.document.writeln('<LINK HREF="/is/cid/course.css" REL="stylesheet"');
  win1.document.writeln('TYPE="text/css"></HEAD>');
  win1.document.writeln('<BODY BGCOLOR="FFFFFF" ONLOAD="document.FeedbackForm.Name.focus();">');
  win1.document.writeln('<CENTER><P><IMG SRC="/is/cid/imgs/comments.gif"');
  win1.document.writeln('ALT="Comments and Questions"></P>');
  win1.document.writeln('<P ALIGN="CENTER">Use this form to send comments or complaints');
  win1.document.writeln('about links in this course to BYU. Ideas on how we can make improvements ');
  win1.document.writeln('are always welcome. If you are reporting inappropriate information ');
  win1.document.writeln('contained on any linked web page or that the linked web page is inactive, ');
  win1.document.writeln('please note the nature of the problem in the area below marked ');
  win1.document.writeln('"Description of problem". Comments made on this form are recieved directly ');
  win1.document.writeln("by Independent Study's tech support team.</P>");
  win1.document.writeln('<FORM ACTION="/cgi-bin/generic.scr" METHOD="POST"');
  win1.document.writeln(' NAME="FeedbackForm">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="scriptname" VALUE="mailback">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="respurl" VALUE="is/common/comments.htm">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="required" VALUE="SSN,Barcode">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="whoto" VALUE="is_tech@con2.byu.edu">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="subject" VALUE="Link Comments">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="Browser">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="noprint" ');
  win1.document.writeln('VALUE="whoto,scriptname,respurl,required,subject,noprint">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="course" VALUE="'+RS6000+'">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="Location" SIZE="41" VALUE="'+page_name+'">');
  win1.document.writeln('<INPUT TYPE="HIDDEN" NAME="link" VALUE="'+link+'">');
  win1.document.writeln('</CENTER>');
  win1.document.writeln('<CENTER><TABLE ALIGN="CENTER" CELLPADDING="3" CELLSPACING="3" bgcolor="#dddddd" width="500">');
  win1.document.writeln('<TR><TD width="200"><b>Course number: </b></TD><TD>'+RS6000+'</TD></TR>');
  win1.document.writeln('<TR><TD><b>Page number: </b></TD><TD>'+page_name+'</TD></TR>');
  win1.document.writeln('<TR><TD><b>Link location: </b></TD><TD>'+link+'</TD></TR>');
  win1.document.writeln('<TR><TD><b>Full name:</b></TD><TD><INPUT NAME="Name" SIZE="25"></TD></TR>');
  win1.document.writeln('<TR><TD><b>E-mail address:</b></TD>');
  win1.document.writeln('<TD><INPUT NAME="E-mail" SIZE="25"></TD></TR>');
  win1.document.writeln('<TR><TD COLSPAN="2" align="center">');
  win1.document.writeln('<FONT SIZE="-1">Description of problem:</FONT><BR>');
  win1.document.writeln('<TEXTAREA NAME="comments" ROWS="4" COLS="51" WRAP="HARD"></TEXTAREA>');
  win1.document.writeln('<CENTER><INPUT TYPE="submit" VALUE="Send Message"');
  win1.document.writeln('ONCLICK="document.forms[0].Browser.value=navigator.appName+navigator.appVersion">');
  win1.document.writeln('</CENTER></TD></TR></TABLE></FORM></CENTER></BODY></HTML>');
}

