function spawnWindowBase( a_name, a_url, a_features, a_replace ) {
    // var newWindow = window.open( a_url, a_name, a_features, a_replace );
    // newWindow.focus();
    window.open( a_url, a_name, a_features, a_replace ).focus();
}


function spawnWindow( a_name, a_url, a_width, a_height, a_chrome) {
    var l_features = "";
    if ( ( a_width == null ) || ( a_height == null ) ) {
        l_features = "top=0,left=0,scrollbars,width=641,height=500";
    } else {
        var l_features = "top=0,left=0,";
        if ( a_chrome && document.layers ) {
            /* adjust for Netscape Navigator chrome size */
            l_features += "menubar,toolbar,location,status,scrollbars,resizable," +
                          "width=" + (a_width - 12) + ",height=" + (a_height - 215);
        } else if ( a_chrome && !document.layers ) {
            /* adjust for Internet Explorer chrome size */
            l_features += "menubar,toolbar,location,status,scrollbars,resizable," +
                          "width=" + (a_width - 12) + ",height=" + (a_height - 165);
        } else {
            if ( !document.layers ) {
                /* account for scrollbar width in IE */
                a_width += 16;
            }
            l_features += "scrollbars," + "width=" + a_width + ",height=" + a_height;
        }
    }
    spawnWindowBase( a_name, a_url, l_features, false );
}
//==================================================
//spawnWindowPos
// This function is identical to 'spawnWindowPos' but it also includes
// x and y position values. These allow the caller to specify the window's location
function spawnWindowPos( a_name, a_url, a_width, a_height, a_x, a_y,  a_chrome) {
    var l_features = "";

    if ( ( a_width == null ) || ( a_height == null ) ) {
        l_features = "top=" + a_x +",left=" + a_y +",scrollbars,width=641,height=500";
    } else {
        var l_features = "top=" + a_x +",left=" + a_y +",";
        if ( a_chrome && document.layers ) {
            /* adjust for Netscape Navigator chrome size */
            l_features += "menubar,toolbar,status,scrollbars,resizable," +
            "width=" + (a_width - 12) + ",height=" + (a_height - 215);
        } else if ( a_chrome && !document.layers ) {
            /* adjust for Internet Explorer chrome size */
            l_features +=  "menubar,toolbar,status,scrollbars,resizable," +
            "width=" + (a_width - 12) + ",height=" + (a_height - 165);
        } else {
            if ( !document.layers ) {
                /* account for scrollbar width in IE */
                a_width += 16;
            }
           //ORIG l_features += "scrollbars," + "width=" + a_width + ",height=" + a_height;
                  l_features +=  "menubar,toolbar,status,scrollbars,resizable," +
                  "width=" + a_width + ",height=" + a_height;

        }
    }
    spawnWindowBase( a_name, a_url, l_features, false );
}



function spawnAssetWindow( url ) {
    var width = getWidth( 400 );
    var height = 450;
    var features = "scrollbars,top=65,left=170,width=" + width + ",height=" + height;


//added by Valley :protection for teacher supplements
	resultind=(url.indexOf("Supplements"));
	if(resultind!=-1)
	{
     checkTeacherValidation( url,'Teaching Supplements' );
	}
	else
	{
     spawnWindowBase( 'assetlist', url, features, true );
	}

}
/*

function spawnGlossaryWindow( isbn, word ) {

    var url = "/servlets/ob.ViewBook?VIEW=glossary&ISBN=" + isbn;
    if ( word != "" ) {
        url += "&WORD=" + word;
    }
    var width = getWidth( 675 );
    var height = 500;
    var features = "scrollbars,top=0,left=0,width=" + width + ",height=" + height;
    spawnWindowBase( 'assetlist', url, features, false );
*/

function spawnGlossaryWindow( isbn, word ) {
    var url = "";
    var loc = new String( window.location );
    if ( loc.indexOf( "ViewBook" ) >= 0 ) {
        url = "/servlets/ob.ViewBook?VIEW=glossary&ISBN=" + isbn;
    } else {
        url = "/Controller?ACTION=POST&JSP=textbook.jsp&MANAGER=TEXTBOOK&OPERATION=book&VIEW=glossary&ISBN=" + isbn;
    }
    if ( word != "" ) {
        url = url + "&WORD=" + word;
    } else {
        url = url + "&LETTER=A";
    }
    var width = getWidth( 675 );
    var height = 500;
    var features = "scrollbars,top=0,left=0,width=" + width + ",height=" + height;
    spawnWindowBase( 'assetlist', url, features, false );
}



function spawnDictionaryWindow( isbn, word ) {
    var url = "/servlets/ob/DictionaryServlet?VIEW=dictionary&ISBN=" + isbn;
    //var url = "/servlet/dictionary?VIEW=dictionary&ISBN=" + isbn;

    if ( word != "" ) {
        url += "&WORD=" + word;
    }
    var width = getWidth( 675 );
    var height = 500;
    var features = "scrollbars,top=0,left=0,width=" + width + ",height=" + height;
    spawnWindowBase( 'dictionary', url, features, false );
}

function spawnTweWindow( url ) {
	 //Anil:Changes made for getting in the tweURL
     checkTeacherValidation( url,'Teacher Edition' );
	 //Anil: Changes over
}

/**Begin Anil : Validation provided for the guest student users for not using Teachers Edition part.
This form calls a TeacherValidation Servlet which validates the password on the server and returns
the Error response or opens the TWE window.

dt : 1/19/01
*/

function checkTeacherValidation( tweUrl,whichlink ) {

	var page = window.open("","Validation","top=50,left=0,width=598,height=373");
	var validdoc = page.document;

	var htm = "<html><head><title>McGraw-Hill Teacher Validation</title></head>\n";
	    htm += "<body bgcolor='#FFFFFF' marginwidth='0' marginheight='0' topmargin='0' leftmargin='	0'>\n";
		htm += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>\n";
		htm += "<tr bgcolor='FFFFCC'>\n";
		htm += "<td><img border='0' height='25' width='1' src='../../images/shim.gif'></td>\n";
		htm +="</tr>\n";
		htm +="<tr>\n";
		htm +="<td bgcolor='#999966'><img border='0' height='1' width='1' src='../../images/shim.gif'></td>\n";
		htm +="</tr>\n";
		htm +="<tr>\n";
		htm +="<td bgcolor='#CCCC99'><img border='0' height='5' width='1' src='../../images/shim.gif'></td>\n";
		htm +="</tr>\n";
		htm +="<tr>\n";
		htm +="<td bgcolor='#999966'><img border='0' height='1' width='1' src='../../images/shim.gif'></td>\n";
		htm +="</tr>\n";
		htm +="</table>\n";

		htm +="<table cellpadding='0' cellspacing='0' border='0' width='100%'>\n";
		htm +="<form name='validation' method='Post' action='/servlets/ob.TeacherValidation'>\n";
		htm +="<tr>\n";
		htm +="<td valign='top'><img border='0' height='180' width='42' src='../../images/reg_par_popsquares.gif'></td>\n";
		htm +="<td valign='top'>\n";
		htm +="<table>\n";
		htm +="<tr><td>&nbsp;</td></tr>\n";
		htm +="<tr>\n";
		htm +="<td>&nbsp;</td>\n";
		htm +="<td><font size='2' face='Verdana, arial'>\n";
		htm +="<p>In order to discourage students from accessing the "+ whichlink +" of this book during this free trial period, a password is required. To obtain a password, please contact your McGraw-Hill sales representatives. Or, you may obtain a password by faxing your request (on school stationary) to The McGraw-Hill Learning Network (614) 430-6350. Please include your name, your school's postal address, and e-mail address with your address with your request.</p>\n";
		htm +="</font>\n";
		htm +="</td>\n";
		htm +="</tr>\n";
		htm +="<tr>\n";
		htm +="<td>&nbsp;</td>\n";
		htm +="<td>\n";
		htm +="<font size='2' face='Verdana, arial'><b>Enter Password</b></font>\n";
		htm +="<input type='password' name='password' size='10'>\n";
		htm +="<input type='hidden' name='tweUrl' value='" + tweUrl + "'>\n";
		htm +="<input border='0' alt='Go' src='../../images/glb_nav_go_white.gif' type='image'>\n";
		htm +="</td>\n";
		htm +="</tr>\n";
		htm +="</table>\n";
		htm +="</td>\n";
		htm +="</tr>\n";
		htm +="</table>\n";
		htm +="</form><body><html>\n";

	validdoc.writeln( htm );
	validdoc.close();
}
/**End Anil*/

function getWidth( oldWidth ) {
    var newWidth = oldWidth;
    if ( !document.layers ) {
        /* account for scrollbar width in IE */
        newWidth += 16;
    }
    return newWidth;
}


function getHeight( oldHeight ) {
    var newHeight = 0;
    if ( document.layers ) {
        /* account for chrome height in NN */
        newHeight = oldHeight - 215;
    } else {
        /* account for chrome height in IE */
        newHeight = oldHeight - 165;
    }
    return newHeight;
}


function gotoPage( isbn, pageField, twe, sample ) {
    if ( sample ) {
        spawnErrorWindow( isbn, "gotoPage", twe );
        return false;
    }
    var page = pageField.value;
    var hasChars = ( page.toLowerCase() != page.toUpperCase() );
    var validPage = false;
    if ( hasChars ) {
        page = page.toUpperCase();
        pageField.value = page;
        validPage = ( charPages.indexOf( "|" + page + "|" ) >= 0 );
    } else {
        validPage = (page >= minPage) && (page <= maxPage) && (gapPages.indexOf("|" + page + "|") < 0);
    }

    if ( validPage ) {
        return true;
    } else {
        spawnErrorWindow( isbn, page, twe );
        return false;
    }
}


function spawnErrorWindow( isbn, page, twe ) {
    var toc;
    var winLocation = window.location.toString();
    var url = "\"http://www.mhlearningstore.com\"";
    if ( winLocation.indexOf("Controller") >= 0 ) {
        if ( page == "gotoPage" || page == "doSearch" ) {
            toc = "\"/Controller?SAMPLE=true&ACTION=POST&JSP=textbook.jsp&MANAGER=TEXTBOOK&OPERATION=book&VIEW=toc&ISBN=" + isbn +"\"";
        } else {
            toc = "\"/Controller?ACTION=GET:XSL=DYNAMIC:MANAGER=TEXTBOOK:OPERATION=book:VIEW=toc:ISBN=" + isbn + "\"";
        }
    } else {
        toc = "\"/servlets/ob.ViewBook?VIEW=toc&ISBN=" + isbn + "\"";
    }
    var win = window.open("", "error", "top=20,left=175,width=400,height=400");
    var doc = win.document;
    var html = "<html>\n<head><title>Error</title></head>\n";
    html += "<body bgcolor='#FFFFFF' marginwidth='0' marginheight='0' topmargin='0' leftmargin='0' link='#0000FF' alink='#0000FF' vlink='#9C10B5'>\n";
    html += "<img src='/ob/data_isbn/" + isbn + "/gfx/book_banner.jpg'>\n";
    html += "<table border='0' width='100%' height='60%'>\n";
    html += "<tr><td align='center' valign='middle'>\n";
    html += "   <table align='center' border='0' width='100%'>\n";
    if ( page == "gotoPage" || page == "doSearch" ) {
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This feature is not available in this preview sample.</font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To purchase this textbook, please visit the</font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:opener.location=" + url + ";window.close();'>McGraw-Hill Learning Store.</a></font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;</font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To learn more about the interactive textbooks and</font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the McGraw-Hill Learning Network, or to schedule</font></td></tr>";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a demonstration, please call your local McGraw-Hill</font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sales representative. You may also call toll-free</font></td></tr>\n";
    html += "<tr><td colspan='4'><font size='2' face='Verdana, arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(888)-393-9090.</font></td></tr></center>\n";
    } else {
    html += "    <tr><td align='center' colspan='4' style='font-size:large'>";
    html += "Sorry, page <span style='color:red; font-weight:bold'>";
    html += page + "</span> does not exist.</td></tr>\n";
    }
    //html += "    <tr><td colspan='4'>&nbsp;</td></tr>\n";
    html += "    <tr><td colspan='4'>&nbsp;</td></tr>\n";
    html += "    <tr><td width='15%'>&nbsp;</td>\n";
    html += "    <td align='center' class='NavLabel' width='*'>";
    html += "<font size='2' face='Verdana, arial'><a href='javascript:window.close();'>Return to Page</a></font></td>\n";
    if ( twe ) {
        html += "    <td align='center' width='1'></td>\n";
    } else {
        html += "    <td align='center' class='NavLabel' width='35%'>";
        html += "<a href='javascript:opener.location=" + toc + ";window.close();'>";
        html += "<font size='2' face='Verdana, arial'>Table of Contents</a></font></td>\n";
    }
    html += "    <td width='15%'>&nbsp;</td></tr>\n";
    html += "    </table>\n</td></tr></table></center>\n";
    html += "</body>\n</html>";
    doc.writeln( html );
    doc.close();

}



/* was called from spawnWindow() and for RealMedia assets */
/* currently called from htm templates */
function spawnWindowWH( a_name, a_url, a_width, a_height ) {
    l_windowWidth = a_width + 16;
    l_windowHeight = a_height;
    l_features = "top=0,left=0,scrollbars=yes,resizable=no,width=" +
                 l_windowWidth + ",height=" + l_windowHeight;
    spawnWindowBase( a_name, a_url, l_features );
}



/* was called from spawnWindow() and for RealMedia assets */
/* currently called from htm templates */
function spawnWindowWH( a_name, a_url, a_width, a_height ) {
    l_windowWidth = a_width + 16;
    l_windowHeight = a_height;
    l_features = "top=0,left=0,scrollbars=yes,resizable=no,width=" +
                 l_windowWidth + ",height=" + l_windowHeight;
    spawnWindowBase( a_name, a_url, l_features );
}

/* called from search form within book pages */
function doSearch( isbn, query, mode, sample ) {
    if ( query.length > 0 ) {
        if ( sample ) {
            spawnErrorWindow( isbn, "doSearch", false );
        } else {
            var searchURL = "/Controller?ACTION=POST&MANAGER=VSEARCH&";
            searchURL += "OPERATION=GET_" + mode.toUpperCase();
            searchURL += "_VSEARCH&JSP=" + mode.toLowerCase() + "_vsearch.jsp";
            searchURL += "&ISBN=" + isbn;
            searchURL += "&MYQUERY=" + escape( query );
            location.href = searchURL;
        }
    }
    return false;
}

/*Date :28.07.01
Anil
specifically used for the 3_5 student interface
*/
function doSearch3_5(isbn, query, mode, sample ) {
    if ( query.length > 0 ) {
        if ( sample ) {
            spawnErrorWindow( isbn, "doSearch", false );
        } else {
            var searchURL = "/Controller?ACTION=POST&MANAGER=VSEARCH&OPERATION=GET_TEACHER_VSEARCH&JSP=3_5student_vsearch.jsp";
            searchURL += "&ISBN=" + isbn;
            searchURL += "&MYQUERY=" + escape( query );
            location.href = searchURL;
        }
    }
    return false;

}

