/*  page and server configuration and state management parameters 
File:			cdw_pagestate.js
Author:			Corti Designworks LLC
Use:			TischlerBise Site 
Purpose:		Contains the site configuration control parameters that may be edited 
				when migrating the site to partner locations, or promoting the site 
				from developent to staging to production

datetime: 20050307.15:30				
				
Mods:		
*/

/*************** begin SECTION: PageState ****************************
	The "pagestate" js object hold several content variable that change on a per-page basis
	These default values (to avoid nulls) are superceded in script on each html page
*/
var oCDW_pagestate				= new Object; 		

oCDW_pagestate.pageimage 		= "placeholder.jpg"; 					// value is only a placeholder
oCDW_pagestate.pagename 		= "TischlerBise";							// value is only a placeholder
oCDW_pagestate.sectionname 		= "TischlerBise";				            // value is only a placeholder
oCDW_pagestate.sectionimage 	= "placeholder.jpg";					// value is only a placeholder
// end SECTION: PageState


/*************** begin SECTION: Dynamic URL creation *************************
*/
oCDW_pagestate.mainimageprefix			= "../images/";
oCDW_pagestate.commontopimageprefix 	= "../images/common/";	// location of top area images
oCDW_pagestate.corpsite_prefix			= "/corporate/pages/";



//	Server names
oCDW_pagestate.tbserver_corpstaging_name 			= "http://www.tischlerbise.com";
oCDW_pagestate.tbserver_corpproduction_name 		= "http://www.tischlerbise.com";

//
oCDW_pagestate.tbserver_corpstaging_prefix 		= oCDW_pagestate.tbserver_corpstaging_name 	+ oCDW_pagestate.corpsite_prefix;
oCDW_pagestate.tbserver_corpproduction_prefix 		= oCDW_pagestate.tbserver_corpproduction_name 	+ oCDW_pagestate.corpsite_prefix;


oCDW_pagestate.investorserver_stagingprefix 			= "";
oCDW_pagestate.investorserver_productionprefix 			= "";


/********************************************************************************
*																				*
*			Note, setting you MUST HAVE set CORRECTLY are:				*
*																				*
*	a) 	oCDW_pagestate.remoteserver	= "YES"										*
*																				*
*	b) 	oCDW_pagestate.operationalsetting 	= "STAGING"   or					*
*											= "PRODUCTION"  appropriately 		*
*																				*
*	c) 	oCDW_pagestate.localserverfilesonly_override	= "NO"					*
*																				*
*	d)	oCDW_pagestate.extname 			= ".asp"									*
*																				*
*	This is done by swaping which lines are active vs. commented.				*																				*																				*
*********************************************************************************
*/

oCDW_pagestate.isremoteserver					= "NO";  
// oCDW_pagestate.isremoteserver					= "YES";  	

// oCDW_pagestate.operationalsetting 		= "PRODUCTION";		// 
oCDW_pagestate.operationalsetting	 		= "STAGING";		// development or staging

/************************  end of Note ************************************/


if (oCDW_pagestate.isremoteserver == "YES") {					
	if (oCDW_pagestate.operationalsetting == "PRODUCTION") {
			oCDW_pagestate.tbserver_name		= oCDW_pagestate.tbserver_corpproduction_name;
			oCDW_pagestate.tbserver_prefix		= oCDW_pagestate.tbserver_corpproduction_prefix;
			oCDW_pagestate.investorserver_prefix 	= oCDW_pagestate.investorserver_productionprefix;
			//
		} else {
			oCDW_pagestate.tbserver_name		= oCDW_pagestate.tbserver_corpstaging_name;
			oCDW_pagestate.tbserver_prefix		= oCDW_pagestate.tbserver_corpstaging_prefix;
			oCDW_pagestate.investorserver_prefix 	= oCDW_pagestate.investorserver_stagingprefix;
		} 
}
	
if (oCDW_pagestate.isremoteserver == "NO") {					
	if (oCDW_pagestate.operationalsetting == "PRODUCTION") {
			oCDW_pagestate.tbserver_name		= oCDW_pagestate.tbserver_corpproduction_name;
			oCDW_pagestate.tbserver_prefix		= "./";
			oCDW_pagestate.investorserver_prefix 	= oCDW_pagestate.investorserver_productionprefix;
			//
		} else {
			oCDW_pagestate.tbserver_name		= oCDW_pagestate.tbserver_corpstaging_name;
			oCDW_pagestate.tbserver_prefix		= "./";
			oCDW_pagestate.investorserver_prefix 	= oCDW_pagestate.investorserver_stagingprefix;
		}
}	
// end SECTION: Dynamic URL creation

/****************** begin SECTION: Web Server Technology Control Variables **********************************

	.localserverfilesonly_override	- 	Forces top drop down menu items to link only to
										local pages on whatever the local server is.
										
										Value must be YES or NO.

	.extname	Contains various file name extensions, dynamically added to basic file names, 
				depending on web server type.  MUST be edited when migrating the script 
				between server types
*/	

oCDW_pagestate.localserverfilesonly_override	= "NO"			// normal - staging or production operation 
// oCDW_pagestate.localserverfilesonly_override	= "YES"			// for CDW test only at local CDW or TischlerBise servers


// oCDW_pagestate.extname 			= "";   		// use for AOL
// oCDW_pagestate.extname 			= ".jsp";   	// use for Java/JSP, like WebSphere
oCDW_pagestate.extname 			= ".asp";   		// use for Microsoft IIS/ASP

// end SECTION: Web Server Technology Control Variables 

/**************** begin SECTION: define global js functions *********************************** 
*/

// For debug - syntactic definition blanks
 function maxHREF(pagefilename) {}
 function maxOPTION(pagefilename) {}
 function maxHostedSiteHREF(pagefilename) {}
 function ccbnHREF(pagefilename) {}
// 

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function jumptoselectListURL( selectList ) { 
	// purpose:		for an html drop down select list that jumps to another page when user picks item
	// parameters:	selectList 	- always use "this", see below
	// requires:	URL in value parameter of list item
	// example:		<select name="prodList" id="prodList" onchange="jumptoselectListURL( this )">
	//				<option selected value="#">-Select Product-</option>

	//
	var newIndex = selectList.selectedIndex; 
	var theurl = "";
	if ( newIndex == 0 ) {	// noop if its the first item "-select product-"
		theurl = theurl; 
	} else { 
		theurl = selectList.options[ newIndex ].value; 
		if (theurl != "") {window.location.href = theurl; }
	}
}

 
function maxHREF(pagefilename) {		
	//  purpose:	Needed to generate HTML & URLs that match several environments 

	//				Creates html <a href..> tag with URL values for tb hosted pages 
	// parameters:	maxpagefilename		- tb page name, without file extension
	var sTemp 	= "";
	var sHREF 	= "";
	if (pagefilename == '') {	// if there's no name passed, stay in same place
		sTemp = "#";
	} else {
		sTemp = oCDW_pagestate.tbserver_prefix + pagefilename + oCDW_pagestate.extname;
	}
	sHREF 	= '<a href="' + sTemp + '">';
	document.write(sHREF);
}
 
function maxOPTION(pagefilename) {   	
	
	//				Creates html <option..> tag with URL values appropriate to hosting server
	// parameters:	maxpagefilename		- tb page name, without file extension
	var sTemp 	= "";
	var sHREF 	= "";
	if (pagefilename == '') {	// if there's no name passed, stay in same place
		sTemp = "#";
	} else {
		sTemp = oCDW_pagestate.tbserver_prefix + pagefilename + oCDW_pagestate.extname;
	}
	sHREF 	= '<option value="' + sTemp + '">';
	document.write(sHREF);
}
 

function maxHostedSiteHREF(pagefilename) {	
 
	//				Creates HREF tag link to other hosted sites
	var sTemp 	= "";
	var sHREF 	= "";
	if (pagefilename == '') {	// if there's no name passed, stay in same place
		sTemp = "#";
	} else {
		sTemp = oCDW_pagestate.tbserver_name + '/' + pagefilename;
	}
	sHREF 	= '<a href="' + sTemp + '">';
	document.write(sHREF);
}

function ccbnHREF(ccbnpagefilename, maxpagefilename) {	


	
	// 				maxpagefilename		- tb page name, without file extension
	var sTemp 	= "";
	var sHREF 	= "";
	if ((ccbnpagefilename == '')||(maxpagefilename == '')) {	// if there's no name passed, stay in same place
		sTemp = "#";
	} else {
		if (oCDW_pagestate.localserverfilesonly_override == "YES") {
			sTemp = oCDW_pagestate.maximusserver_prefix + maxpagefilename + oCDW_pagestate.extname;	// CDW test only
		} else {
			sTemp = oCDW_pagestate.investorserver_prefix + ccbnpagefilename;
		}
	}
	sHREF 	= '<a href="' + sTemp + '">';
	document.write(sHREF);
}


function popupWinFeatures(url,w,h,menu) {
	// sample call ... href="javascript:printpopup1('x.html',700,500,1)"
	//
	x = Math.floor((screen.width - w) / 2);
	y = Math.floor((screen.height - h) / 2);        
	now = new Date();
	features = "screenx="+x+",screeny="+y+",left="+x+",top="+y+",width="+w+",height="+h+",location=no,resizable=yes"+",directories=no,status=no,scrollbars=yes";
	if (menu != null) {
		//features += ",menubar=yes,toolbar=yes,scrollbars=yes";
		features += ",menubar=yes,toolbar=yes";
	} else {
		//features += ",menubar=no,toolbar=no,scrollbars=no"; 
		features += ",menubar=no,toolbar=no"; 
	}
	window.open(url,"newwin",features);
}


//
// begin: printing support functions
//
//		This is a strictly client side JavaScript page print operation that uses
// 		the DOM structure inherent to the web site, and eliminates images etc.
// 		The invoking link is of the following form
// <a href="javascript: void 0" onclick="javascript: printThisPage(); return false;">Print this page</a>
//
var printhtml	= "";
var printURL	= location.href;
var printpgheadlinearea	= "";
var printpgbodyarea		= "";

function printCleanContent(originalContent){
	// Purpose: erases html content not appropriate for printing (includes, images etc)
	//
	// <TAG[^>]*>(.*?)<\/TAG> = Note: generalized regex for reasing a tag and its contained content
	//
	oC	= originalContent;
	var toBeDeletedRegEx		= new Array;
		toBeDeletedRegEx[0]		= /<!--([^>])*-->/i;		// erase comments, because of SSI includes
		toBeDeletedRegEx[1]		= /<img([^>])*>/i;			// erase images
		toBeDeletedRegEx[2]		= /<DIV id=leftrulearea[^>]*>(.*?)<\/DIV>/i;	
		toBeDeletedRegEx[3]		= /<DIV id=rightrulearea[^>]*>(.*?)<\/DIV>/i;	
		toBeDeletedRegEx[4]		= /<DIV class=verticalrule[^>]*>(.*?)<\/DIV>/i;	

	
	var toBeReplacedWith		= "";

	for (var i = 0; i < toBeDeletedRegEx.length; i++){
		var newContent		= "";
		while(toBeDeletedRegEx[i].test(oC)){
			var oM = "";
			var matchResult = oC.match(toBeDeletedRegEx[i]);
			if (matchResult != null){
				oM = matchResult[0];
			}else{
				oM = "none matched";
			}
			newContent	= oC.replace(toBeDeletedRegEx[i], toBeReplacedWith);
			oC			= newContent;
		}
	}
	return oC;
}

function printGetContent(){

// alert("see if pgbodyarea object exists ... " + document.getElementById('pgbodyarea'));

	if (document.getElementById('pgheadlinearea')){
		var pgheadline		= document.getElementById('pgheadlinearea').innerHTML;
	}
	if (document.getElementById('pgbodyarea')){
		var pgbody			= document.getElementById('pgbodyarea').innerHTML;
	}
	tempContent			= "";
	
	tempContent			= printCleanContent(pgheadline);
	pgheadline			= tempContent;
	
	tempContent			= printCleanContent(pgbody);
	pgbody				= tempContent;
	
	if (pgheadline) {printpgheadlinearea = pgheadline}else{printpgheadlinearea = ""};
	if (pgbody) {printpgbodyarea = pgbody}else{printpgbodyarea = ""};
}

function printBuildContent(){
	printhtml		= "<html><HEAD><TITLE>" +
	oCDW_pagestate.pagename +
	"</TITLE>" +
	"<meta http-equiv='Pragma' content='no-cache'>" +
	"<meta http-equiv='Expires' content='0'>" +
	"<meta http-equiv='Refresh' content='1800'>" +
	"<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>" +
	"<link rel='stylesheet' href='../css/tb_3col.css' type='text/css'>" +
	"<scr" + "ipt language=JavaScript1.2 src='../scripts/cdw_pagestate.js' type=text/javascript></SCR" + "IPT>" +
	"</HEAD>" +
	"<body bgcolor='#FFFFFF' link='#666699' vlink='#666699' alink='#666699'>" +
	// Corporate web site title
	"<span class='intpageheader'>TischlerBise Web Site<br><br></span>" +
	// Page Title
	"<SPAN class='intpageheader'><A href='" +
	location.href +
	"' class='intpageheader'>" +
	oCDW_pagestate.pagename +
	"</A></SPAN><br><br>" +
	// URL label
	"<span class='bodycopy'>To print this page, select <b>File</b> then <b>Print</b> from your browser</span><br>" +
	"<span class='verd8ptregular'>URL: " +
	printURL +
	"</span><hr><br>" +
	// Main content headline and body
	printpgheadlinearea +
	"<br><br>" +
	printpgbodyarea +
	"</body></html>" ;
}

function printPopup3(){
	printGetContent();
	printBuildContent();
//	alert(printhtml);
	document.open("","","").document.write(printhtml);
	document.close;
}

function printThisPage(){printPopup3()}
//
// end: printing support functions

// end SECTION: define global js functions

/*
*/