// ********************************************************************
// Copyright (C) 2000 NCompass Labs Inc. All rights reserved.
//
//	IMPORTANT.  Please read the legal.txt file, located in the 
//	"<Resolution Install Directory>\Server\httpexec\WBC\Internals" 
//	directory, governing the use of this internal file."
// ********************************************************************

// Define constants
var ARRAY_MONTH_NAME = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var IDS_FRAMEWORK_VIRTUAL_PATH = "/NR/System/WBC";	// also defined in CommonServer.inc
var IDS_INTLINKS_PATH = IDS_FRAMEWORK_VIRTUAL_PATH + "/Internals/PageTemplate/Authoring/Dialogs/InternalLinks/InternalLinks.asp";
var IDS_FORMPARAM_WBCACTION = "WBC_action";	// also defined in CommonServer.inc
var IDS_HTTP_PROTOCOL = "http://";	// also defined in CommonServer.inc

// Define window features (these are non-Customizable)
var IDS_WIN_INTLINKS_FEATURES = "width=350,height=400";
var IDS_WIN_TABLE_FEATURES = "width=300,height=190,resizable,scrollbars";

// Define querystring parameters - all are also defined in CommonServer.inc
var IDS_QPARAM_ACCEPT = "wbc_acceptcontent";
var IDS_QPARAM_ATTACHICON = "wbc_attachicon";
var IDS_QPARAM_DESKRES = "wbc_deskres";
var IDS_QPARAM_IMG = "wbc_img";
var IDS_QPARAM_IMGNAME = "wbc_imgname";
var IDS_QPARAM_NREMIT = "nr_emit";
var IDS_QPARAM_NUMPAGE = "wbc_numpage";
var IDS_QPARAM_PHHREF = "wbc_phhref";
var IDS_QPARAM_PHNAME = "wbc_phname";
var IDS_QPARAM_PHTYPE = "wbc_phtype";
var IDS_QPARAM_URL = "wbc_url";
var IDS_QPARAM_VIDEO = "wbc_video";
var IDS_QPARAM_WBCPURPOSE = "wbc_purpose";
var IDS_QPARAM_WBCACTION = "wbc_action";

// Define specific placeholder type variables
var IDS_PLACEHOLDER_DHTML = "dhtml"
var IDS_PLACEHOLDER_ACTIVEX = "activeX"
var IDS_NCPHNAME = "NCPHNAME"
var IDS_NCPH_ = "NCPH_" 
var IDS_PLACEHOLDER_TYPE = "placeholderType"

// Define querystring values - all are also defined in CommonServer.inc
var IDS_ACTION_APPROVE = "Approve";
var IDS_ACTION_DECLINE = "Decline"
var IDS_ACTION_SAVE = "Save";
var IDS_ACTION_SUBMIT = "Submit";
var IDS_PHTYPE_MULTIPURPOSE = "MultiPurpose";
var IDS_PHTYPE_MULTILINETEXT = "MultiLineText";
var IDS_PHTYPE_SINGLEATTACHMENT = "SingleAttachment";
var IDS_PHTYPE_SINGLEIMAGE = "SingleImage";
var IDS_PHTYPE_SINGLELINETEXT = "SingleLineText";
var IDS_PHTYPE_THINEDITIE = "ThinEditIE";
var IDS_RESTYPE_ATTACHMENT = "Attachment";
var IDS_RESTYPE_IMAGE = "Image";
var IDS_RESTYPE_VIDEO = "Video";

// Define window names
var IDS_WIN_GALLERY = "NCWin_Gallery";	// also defined in CommonServer.inc
var IDS_WIN_PREVIEW = "NCWin_Preview";	// also defined in CommonServer.inc
var IDS_WIN_PAGEPROPS_NAME = "NCWin_PageProperties";
var IDS_WIN_TABLE = "NCWin_Table";

// Define messages
var IDS_CONTENT_STRIPPED = "Invalid content or formatting was found and was stripped out when saved.\nCheck the placeholder properties for allowed content and formatting.";
var IDS_CONTENT_STRIPPED_FOR_PREVIEW = "Invalid content or formatting was found and will not be shown in the preview.\n\nThe invalid content or formatting will be removed permanently when the page is saved.\nCheck the placeholder properties for allowed content and formatting."
var IDS_DELETE_CONFIRM = "Deleting this page will remove it permanently from the system. Continue?";
var IDS_EXPIRYDATE_LESS_THAN_STARTDATE = "Expiry date must occur after start date.";
var IDS_FUNCTION_NOT_FOUND = "Function not found.";
var IDS_INVALID_COLUMNS = "Number of columns must be a number.";
var IDS_INVALID_COLUMNS_RANGE = "Number of columns must be a number greater than zero.";
var IDS_INVALID_DISP_TEXT = "Invalid display text.";
var IDS_INVALID_EXPIRY_DATE = "Invalid expiry date.";
var IDS_INVALID_NAME = "Name cannot be all blanks and cannot contain characters #, &, %, +, / and |.";
var IDS_INVALID_IMAGE_TYPE = "The selected file is not recognized as a valid image file by its file extension. Do you want to proceed?";
var IDS_INVALID_ROWS = "Number of rows must be a number.";
var IDS_INVALID_ROWS_RANGE = "Number of rows must be a number greater than zero.";
var IDS_INVALID_START_DATE = "Invalid start date.";
var IDS_INVALID_VIDEO_TYPE = "The selected file is not recognized as a valid video file by its file extension. Do you want to proceed?";
var IDS_NO_ATTACHMENT_SELECTED = "No attachment is selected.";
var IDS_NO_FILE_SELECTED = "No desktop file is selected.";
var IDS_NO_IMAGE_SELECTED = "No image is selected.";
var IDS_SWITCH_TO_LIVE_CONFIRM = "Switching to the live site will cancel any unsaved changes.  Continue?";
var IDS_WARN_BEFORE_LEAVE = "Refreshing or leaving this page will lose all unsaved changes.";
var IDS_WINDOW_OPENER_NOT_FOUND = "Launching window cannot be found.";

var IDS_TMPL_EXTRA_FORM = "The Template HTML may contain a form which conflicts with the WBC Authoring form.\n" +
							"Please mask out each of the <form> and </form> tags in the Template HTML with \<\% If Not IsAuthoringMode \%\>.\n" +
							"See WBC section in the Site Programmers Guide for details."
var IDS_TMPL_MISSING_TAGS = "The Template HTML is missing the <Head>...</Head> pair or <Body>...</Body> pair of tags.\n" +
								"Please insert them back into the Template HTML. Otherwise, WBC Authoring will not function properly.\n" +
								"See WBC section in the Site Programmers Guide for details.";

// This function checks for the existence of a function in the specified
// window. It returns the window or frame where the function is defined. 
// If no requested function is found, it will return null.

function WBC_getFuncWin(strFunc, pTargetWin) {
	if (pTargetWin) {
		if (pTargetWin.top.document == pTargetWin.self.document) {
			if (eval("pTargetWin." + strFunc) != null) {
				return pTargetWin;
			}
		} else {
			for (i=0; i < pTargetWin.top.frames.length; i++) {
				if (eval("pTargetWin.top.frames[i]." + strFunc) != null) {
					return pTargetWin.top.frames[i];
				}
			}
		}
	}
	return null;
}


// submit a form using the specified action URL
function WBC_submitForm( strFormName, strFormActionURL ) {
	document.forms[strFormName].action = strFormActionURL;
	document.forms[strFormName].submit();
}


// Preload images for rollovers. Arguments are name of all rollovering
// images to be preloaded.

function WBC_preloadImages () {
	if (document.images) {
		var arrayPreload = new Array();
		for (var i = 0; i < arguments.length; i++) {
			arrayPreload[i] = new Image;
			arrayPreload[i].src = arguments[i];
		}
	}
}

// for supporting Rollover image
function WBC_changeImgSafe(imgDOM, imgSrcReplacedBy)
{
	// brace for the case that there is no image tag 
	// when people use text as link
	if (document.images[imgDOM] != null)
	{
		document.images[imgDOM].src = imgSrcReplacedBy;
	}
}

// take user to an authoring page based on the selected template URL
function WBC_createFromTmpl(strURL) {
	if (top.opener != null) {
		top.opener.top.location.href = strURL;
		top.close();
	} else {
		alert(IDS_WINDOW_OPENER_NOT_FOUND);
	}
}

//	Write date in local time
function WBC_writeUTC2Local(strDate) {
	var pDate = new Date(strDate);
	WBC_writeDate(WBC_convertUTC2Local(pDate));
}

//	Convert GMT time to local time
function WBC_convertUTC2Local(pDateUTC) {
	return new Date(pDateUTC.getTime() - pDateUTC.getTimezoneOffset() * 60 * 1000);
}

//	Write date in MMM DD YYYY, HH:MM am/pm format
function WBC_writeDate(pDate) {
	var nHours =  pDate.getHours();
	var strAmPm;
	if (nHours == 0) {
		nHours = 12;
		strAmPm = "am";
	} else if (nHours == 12) {
		strAmPm = "pm";
	} else if (nHours > 12) {
		nHours = nHours - 12;
		strAmPm = "pm";
	} else {
		strAmPm = "am";
	}
	document.write(ARRAY_MONTH_NAME[pDate.getMonth()], " ", WBC_addLeadingZero(pDate.getDate()), " ", WBC_get4DigitsYear(pDate.getYear()), ", ", WBC_addLeadingZero(nHours), ":", WBC_addLeadingZero(pDate.getMinutes()), " ", strAmPm);
}

//	Format date to MMM DD YYYY HH:MM:SS
function WBC_formatDate(pDate) {
	return (ARRAY_MONTH_NAME[pDate.getMonth()] + " " + WBC_addLeadingZero(pDate.getDate()) + " " + WBC_get4DigitsYear(pDate.getYear()) + " " + WBC_addLeadingZero(pDate.getHours()) + ":" + WBC_addLeadingZero(pDate.getMinutes()) + ":" + WBC_addLeadingZero(pDate.getSeconds()));
}

// Returns correct year for any year after 1000
function WBC_get4DigitsYear(nYear) {
	if (nYear < 1000) {
		return nYear + 1900;
	} else {
		return nYear;
	}
}

// Add leading zero to number less than 10
function WBC_addLeadingZero(nNum) {
	if (nNum < 10) {
		return "0" + nNum;
	} else {
		return nNum;
	}
}

// Checks if browser is IE
function WBC_isIE() {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return true;
	} else {
		return false;
	}
}

// Checks if browser is Netscape
function WBC_isNetscape() {
	if (navigator.appName.indexOf("Netscape") != -1) {
		return true;
	} else {
		return false;
	}
}

// Returns browser version
function WBC_getBrowserVer() {
	if (!WBC_isNetscape()) {
		var strUserAgent = navigator.userAgent;
		var nBrowserUserAgentStart = strUserAgent.indexOf("(");
		if (nBrowserUserAgentStart != -1) {
			var strBrowserUserAgent = strUserAgent.substring(nBrowserUserAgentStart)
			var nBrowserVerStart = strBrowserUserAgent.indexOf(".") - 1;
			while ( !isNaN(parseInt(strBrowserUserAgent.charAt(nBrowserVerStart))) && (nBrowserVerStart > 0)) {
				nBrowserVerStart = nBrowserVerStart - 1;
			}
			return parseInt(strBrowserUserAgent.substring(nBrowserVerStart));
		}
	}
	return parseInt(navigator.appVersion);
}

// Open a new window and focus it
function WBC_openWindowOnFocus(strURL, strWinTarget, strWinFeatures) {
	var pWindow = window.open(strURL, strWinTarget, strWinFeatures);
	pWindow.focus();
}

function WM_netscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */

  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn();

