/*
The SoftAd Group
Copyright (c) 2000-2004 The SoftAd Group, Inc.  All rights reserved
*/
// To use this object the following files must be also included.
// CNCommon.js
// [en-us.js] -or- [de-de.js] -or- [es-es.js] -or- [fr-fr.js] for message constants

// -------------------------------------------------------------------------------
// File name        : CNCommon.js
// -------------------------------------------------------------------------------
// Author           : Scott Pennington
// Created on       : June, 2003
// 
// This file contains very Generic Functions that should not be in one object will
// be used by all objects.  
// Generic Javascript Library for ChannelNet processing
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------
// Copyright (c) 2004 The SoftAd Group, Inc.


// -------------------------------------------------------------------------------
// Function         : isEmpty(s)
// -------------------------------------------------------------------------------
// Author           : Scott Pennington
// Created on       : June 23, 2003
// 
// This takes a variable and checks to see if it has a length or is null if either
// is true it returns true... meaning it is empty.
//
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// s				variable	Checks the object to see if it is null or has a Length
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------
function isEmpty(s){return ((s == null) || (s.length == 0))}

// for variables used in place of text alerts (i.e. CNVALIDERROR2), see en-us.js, de-de.js, etc.

var REGEXP_ANYVALUE_REQUIRED = '^.+$';
var REGEXP_FIRSTNAME_REQUIRED = '^[a-zA-Z ]+$';
var REGEXP_FIRSTNAME_OPTIONAL = '^[a-zA-Z ]*$';
var REGEXP_INITIAL_REQUIRED = '^[a-zA-Z]$';
var REGEXP_INITIAL_OPTIONAL = '^[a-zA-Z]?$';
var REGEXP_LASTNAME_REQUIRED = '^[a-zA-Z \\.\\-,\']+$';
var REGEXP_LASTNAME_OPTIONAL = '^[a-zA-Z \\.\\-,\']*$';
var REGEXP_CITY_REQUIRED = '^[a-zA-Z \\.\\-,\']+$';
var REGEXP_CITY_OPTIONAL = '^[a-zA-Z \\.\\-,\']*$';
var REGEXP_PHONENUMBER_REQUIRED = '^[\\w()\\-. +]{1,20}$';
var REGEXP_PHONENUMBER_OPTIONAL = '^[\\w()\\-. +]{0,20}$';
var REGEXP_POSTALCODE_REQUIRED = '^[\\w \\-\\.]{1,13}$';
var REGEXP_POSTALCODE_OPTIONAL = '^[\\w \\-\\.]{0,13}$';
var REGEXP_EMAIL_REQUIRED = '^(.+@.+\\.[a-zA-Z]+)$';
var REGEXP_EMAIL_OPTIONAL = '^(.+@.+\\.[a-zA-Z]+)?$';
var REGEXP_STATE_REQUIRED = '^[A-Za-z]{2,2}$';

var gPreviousFieldName;		// string name of the field which was previously validated
var gImgs = new Array();		// array of the images on a page which are highlighted on a mouseover
var wasSubmitted = false;	// boolean used to determine if the page has already been submitted

// -------------------------------------------------------------------------------
// Function         : handleCNError(strErrMsg)
// -------------------------------------------------------------------------------
// This function displays a ChannelNet Error message
// -------------------------------------------------------------------------------
// Returns a boolean.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME           TYPE      DESCRIPTION
// strErrMsg      string    The text to display for the error
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function handleCNError(strErrMsg) {
    var strEntireMsg = CNVALIDERROR0 + '\n' + '\n';
    
    if(strErrMsg) {
		strEntireMsg += strErrMsg;
	}
	
    alert(strEntireMsg);
}

// -------------------------------------------------------------------------------
// Function         : validate(formElement, regExpText, errorMsg)
// -------------------------------------------------------------------------------
// This function validates the data entered into a form element using regular
// expressions and returns an user specified error if the value of the element
// doesn't match the regular expression.
// -------------------------------------------------------------------------------
// Returns true if the form element passes validation and false if it doesn't.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formElement	element		Then form element which will have its value validated.
// regExpText	string		The regular expression to validate the element with.
// errorMsg		string		The message to display if the value of the form
//							element isn't valid.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function validate(formElement, regExpText, errorMsg){
	var regExpObj = new RegExp(regExpText,'');
	var bReturn = true;
	if (!errorMsg) {
		errorMsg = '';
	}	
	if (gPreviousFieldName!=formElement.name) {
		// checks to see if the field value matches the regular expression
		var elementValue = (formElement.type == 'select-one' ? formElement.options[formElement.selectedIndex].value : formElement.value);
		if (!regExpObj.test(Trim(elementValue))) {

			// displays an error message
			handleCNError(CNVALIDERROR1 + '\n' + CNINVALIDVALUEERROR + '\n' + errorMsg);

			// selects the field value
			if (formElement.focus) {
				formElement.focus();
			}
			if(formElement.select) {
				formElement.select();
			}
		
			gPreviousFieldName = formElement.name;
			bReturn = false;
		} else {
			bReturn = true;
		}
	}
	return bReturn;
}


// -------------------------------------------------------------------------------
// Function         : concatFields(formElement)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function takes the values of textboxes which have identical names
// and concatenates the values which are separated by a bar(|)
// the the resulting values is stored in a hidden field.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formElement	element		The form element which calls this function.  It should
//							always be this.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function concatFields(formElement) {

	var elementIndex;
	var concatValue = '';
	var elementName = formElement.name;
	
	// loops through all of the elements that have the same name as the
	// one that called this function
	
	for(elementIndex=0;elementIndex<formElement.form.elements[elementName].length;elementIndex++) {
		
		if (formElement.form.elements[elementName][elementIndex].value!=null && formElement.form.elements[elementName][elementIndex].value!="") {
			// concatenates the values
			concatValue = concatValue + formElement.form.elements[elementName][elementIndex].value + '|';
		}
	}
	
	// removes the last bar(|)
	concatValue = concatValue.substring(0,concatValue.length-1);
	
	// takes the underscore off of the name
	elementName = elementName.substring(1,elementName.length);
	
	// stores the value a hidden field of the same name
	formElement.form.elements[elementName].value = concatValue;

}



// -------------------------------------------------------------------------------
// Function         : focusOnFirstField()
// -------------------------------------------------------------------------------
// This function gives focus to the first form element which can receive focus on
// a page.  If the field can be selected then it is.
// -------------------------------------------------------------------------------
// Returns true if focus is set to the first field and false if it isn't.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function focusOnFirstField() {

	var formIndex;
	var numOfForms = document.forms.length;
	var elementIndex;
	var bReturn;

	for(formIndex=0; formIndex < numOfForms; formIndex++) {

		var currentForm = document.forms[formIndex];
		var formLength = currentForm.length;
		
		for(elementIndex=0; elementIndex < formLength; elementIndex++) {

			var currentElement = currentForm.elements[elementIndex];
			var elementType = currentElement.type;
			
			// finds the first element which accepts focus
			if (elementType=="text" || elementType=="textarea" || elementType=="password" || elementType=="file" || elementType == "select-one") {
				
				if(currentElement.focus && !currentElement.disabled && !isElementHidden(currentElement)) {
					currentElement.focus();
					if (currentElement.select) {
						currentElement.select();
					}
					bReturn = true;
					break;
				}
			}
		}	
	}
	
	return bReturn;
}

function isElementHidden(currentElement) {
	var hidden = false;
	if(currentElement) {
		currentNode = currentElement.parentNode;
		while(currentNode) {
			if((currentNode.visibility && currentNode.visibility == 'hide') || (currentNode.style && (currentNode.style.visibility && currentNode.style.visibility == 'hidden') || (currentNode.style.display && currentNode.style.display == 'none'))) {
				hidden = true;
				break;
			}
			if(currentNode.tagName && currentNode.tagName.toUpperCase() == "HTML") break;
			currentNode = currentNode.parentNode;
		}
	}
	return hidden;		
}

// -------------------------------------------------------------------------------
// Function         : canDelete()
// -------------------------------------------------------------------------------
// This function prompts the user to make sure that they want to delete the
// selected item.
// -------------------------------------------------------------------------------
// Returns true if the value of any form element has change, false otherwise
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function canDelete() {

	// prompts the user to confirm deletion
	if (confirm(CNDELETEPROMPT)) {
		return true;
	} else {
		return false;
	}
}

// -------------------------------------------------------------------------------
// Function         : imagesToSwap(plainImage, highlightedImage)
// -------------------------------------------------------------------------------
// This function creates two images: a plain one and one that is highlighted on a
// mouseover event.
// -------------------------------------------------------------------------------
// Returns true if the gImgs array exist, false otherwise
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// plainImage       string		The name of the original image.
// highlightedImage	string		The name of the image to use when the onmouseover
//								event occurs.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function imagesToSwap(plainImage, highlightedImage) {	
	var bReturn = false;	
	if(this) {		
		bReturn = true;		
		this.plain = new Image();
		this.plain.src = plainImage;
	
		this.highlighted = new Image();
		this.highlighted.src = highlightedImage;
	}
	return bReturn;
}

// -------------------------------------------------------------------------------
// Function         : preloadImages(imagesArray)
// -------------------------------------------------------------------------------
// This function preload images into memory which will be used for mouseover
// events.
// -------------------------------------------------------------------------------
// Returns true if there are images to load and there is an gImgs array,
//     false otherwise
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// imagesArray		array		This is an array of the names of all of the images
//								which will be highlighted by mouseover events. 
//								This array contains only the original (plain)
//								 images.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/06/2001   Chad Peck   Created

function preloadImages(imagesArray){

	var imgIndex;
	var highlightedImage;
	var bReturn = false;

	if (imagesArray && gImgs) {		
		bReturn = true;		
		var arrayLength = imagesArray.length;		
		for(imgIndex=0; imgIndex<arrayLength; imgIndex++) {	
			highlightedImage = imagesArray[imgIndex];
			highlightedImage = highlightedImage.substring(0,highlightedImage.lastIndexOf('.')) + '-m' + highlightedImage.substring(highlightedImage.lastIndexOf('.'),highlightedImage.length);
			
			gImgs[gImgs.length] = new imagesToSwap(imagesArray[imgIndex],highlightedImage);			
		}
	}	
	return bReturn;
}

// -------------------------------------------------------------------------------
// Function         : highlightImage(imgSource)
// -------------------------------------------------------------------------------
// This function changes the src of an Image whenever a mouseover event fires.
// -------------------------------------------------------------------------------
// Returns true if the image is in the array, false otherwise
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// imgSource		img			This is the image object in the HTML which will
//								have its src replaced.  imgSource should always be
//								referenced with this.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME			DESCRIPTION
// 02/06/2001   Chad Peck		Created
// 08/05/2003	Ken Wimberley	Updated

function highlightImage(imgSource){

	var bReturn = false;	
	if(gImgs && gImgs.length > 0) {
		
		// loops through the gImgs array to find the image
		for(i=0;i<gImgs.length;i++) {
		if (imgSource.src.toUpperCase()==gImgs[i].plain.src.toUpperCase()) {
				imgSource.src=gImgs[i].highlighted.src;
				bReturn = true;
				break;
			}
		}
	}	
	return bReturn;
}

// -------------------------------------------------------------------------------
// Function         : unhighlightImage(imgSource)
// -------------------------------------------------------------------------------
// This function changes the src of an Image back to the plain version whenever
// a mouseover event fires.
// -------------------------------------------------------------------------------
// Returns true if the image is in the array, false otherwise
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME				TYPE        DESCRIPTION
// imgSource		img			This is the image object in the HTML which will
//								have its src replaced.  imgSource should always be
//								referenced with this.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME			DESCRIPTION
// 02/06/2001   Chad Peck		Created
// 08/05/2003	Ken Wimberley	Updated

function unhighlightImage(imgSource) {
	var bReturn = false;
	
	if(gImgs && gImgs.length > 0) {	
		// loops through the gImgs array to find the image
		for(i=0;i<gImgs.length;i++) {
			if (imgSource.src.toUpperCase()==gImgs[i].highlighted.src.toUpperCase()) {
				imgSource.src=gImgs[i].plain.src;
				bReturn = true;
				break;
			}
		}
	}
	return bReturn;
}

// -------------------------------------------------------------------------------
// Function         : PopupWindow (myLocation, scroll, width, height, windowName)
// -------------------------------------------------------------------------------
// This function opens a new window with no menus or toolbars using the file
// specified by myLocation.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// myLocation	string		The name of the file/URL to open in the window.
// scroll		boolean		Will scrollbars appear on the window.
// width		integer		Width of the window in pixels.
// height		integer		Height of the window in pixels.
// windowName	string		Name of the window.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 03/24/2000   Chad Peck   Created

function PopupWindow (myLocation, scroll, width, height, windowName) {
	var oWin;
	if (!windowName) {
		windowName = 'newWin';
	}
	
	if (/channelnet.aspx/i.test(myLocation)) {
		myLocation = myLocation + "&lang=" + CNLANGNAME;
	}
	
	oWin = window.open(myLocation, windowName,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=' + scroll + ',resizable=yes,width=' + width + ',height=' + height);
	oWin.focus();	
}

// -------------------------------------------------------------------------------
// Function         : getDateTicks(ctrl)
// -------------------------------------------------------------------------------
// Returns the millisecond tick equivalent for the date in the specified control.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// ctrl		element		The form element which will have its value validated.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME             DESCRIPTION
// 10/25/2000   George Pollard   Created

function getDateTicks(ctrl) {
	var regExpObj = new RegExp("^(\\d{1,2})/(\\d{1,2})/((\\d{2})|(\\d{4}))$")
	if (!regExpObj.test(ctrl.value)) 
		return 0;
	regExpObj.exec(ctrl.value);
	var month = RegExp.$1;
	var day = RegExp.$2;
	var year = RegExp.$3;
	var err = isValidDate(day,month,year);
	if (err!=null)
		return 0;
	if (day.length==1) day = "0"+day;
	if (month.length==1) month = "0"+month;
	if (year.length==2) year = "20"+year;
	//alert(day +" "+ month +" "+ year);
	return Date.UTC(year, month-1, day);
}

// -------------------------------------------------------------------------------
// Function         : validateDate(formElement, lowerBound, upperBound)
// -------------------------------------------------------------------------------
// This function validates dates entered into a form element and returns 
// an error if the value of the element is not in the correct range
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// formElement	element		The form element which will have its value validated.
// lowerBound	number		The lower bound for the date range
// upperBound	number		The upper bound for the date range
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME             DESCRIPTION
// 10/25/2000   George Pollard   Created
// 11/22/2000   George Pollard   Updated

function validateDate(formElement, lowerBound, lowerInclusive, upperBound, upperInclusive) {
	if (formElement.value == '') {
		return true;
	}
	if (validateDateFormat(formElement, false)) {
		var minutes = getDateTicks(formElement) / 60000;	// drop 1/2 min because bounds are integers
		var aboveLowerBound = (lowerInclusive ? minutes >= lowerBound : minutes > lowerBound); 
		var belowUpperBound = (upperInclusive ? minutes <= upperBound : minutes < upperBound); 
		
		if (upperBound >= lowerBound) {
			if (aboveLowerBound && belowUpperBound)
				return true;
			else {
				var sLower = (lowerInclusive ?  CNINCLUSIVE :  CNEXCLUSIVE);
				var lowerDate = minutesToDate(lowerBound);
				var sUpper = (upperInclusive ?  CNINCLUSIVE :  CNEXCLUSIVE);
				var upperDate = minutesToDate(upperBound);
				handleCNError(CNVALIDERROR2 + '\n' + CNVALIDERROR3 + '\n' + CNVALIDERROR4   + lowerDate + sLower +   CNVALIDERROR6  + upperDate + sUpper);
			}
		} else {
			if (aboveLowerBound || belowUpperBound) 
				return true;
			else {
				var sLower = (lowerInclusive ?  CNEXCLUSIVE :  CNINCLUSIVE);
				var lowerDate = minutesToDate(lowerBound);
				var sUpper = (upperInclusive ?  CNEXCLUSIVE :  CNINCLUSIVE);
				var upperDate = minutesToDate(upperBound);
				handleCNError(CNVALIDERROR2 + '\n' + CNVALIDERROR3 + '\n' + CNVALIDERROR5   + upperDate + sUpper +   CNVALIDERROR6  + lowerDate + sLower);
			}
		}
	}

	// selects the field value
	formElement.focus();
	formElement.select();
	return false;
}

// -------------------------------------------------------------------------------
// Function         : disableLinks()
// -------------------------------------------------------------------------------
// This function disables all links and forms on a page.
// -------------------------------------------------------------------------------
// Returns null
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME        DESCRIPTION
// 02/27/2001   Chad Peck   Moved from sitebuilderpublic.js

function disableLinks() {

	var linkIndex;
	var linksLength;
	var formIndex;
	var formsLength;
	
	linksLength = document.links.length;
	
	for(linkIndex=0; linkIndex < linksLength; linkIndex++) {
		var currentLink = document.links[linkIndex];
		currentLink.href = "javascript:void(0)";
		if(currentLink.onclick) {
			currentLink.onclick = "return false";
		}
	}
	
	formsLength = document.forms.length;
	
	for(formIndex=0; formIndex < formsLength; formIndex++) {
		var currentForm = document.forms[formIndex];
		currentForm.method = "get";
		currentForm.action = "javascript:void(0)";
		
		var elementLength = currentForm.elements.length;
		for(elementIndex=0; elementIndex < elementLength; elementIndex++) {
			var currentElement = currentForm.elements[elementIndex];
			if(currentElement.type != 'hidden') {
				currentElement.disabled = true;
			}
		}
	}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x&&document.getElementById) x = document.getElementById(n);
  return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) {
    if ((obj=MM_findObj(args[i]))) {
      v=args[i+2];
      if (obj.style) {
        obj=obj.style;
        v=(v=='show')?'visible':(v='hide')?'hidden':v;
      }
      obj.visibility=v;
    }
  }
}

function showPane(oForm){

  var optionsLength = oForm.options.length;
  
  for(i=0; i < optionsLength; i++) {
    var currentOption = oForm.options[i];
    if(i == oForm.selectedIndex) {
      MM_showHideLayers(currentOption.value,'','show');
    } else {
      MM_showHideLayers(currentOption.value,'','hidden');
    }
  }
}

// -------------------------------------------------------------------------------
// Function         : confirmPassword(oForm)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function checks to make sure that two the values of a password field and
// a confirm password field match.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// oForm		form		Reference to a form object.  It should always be
//							by the this keyword.
// -------------------------------------------------------------------------------
// Last Updated     : August 5, 2003
// Updated by       : Ken Wimberley
// -------------------------------------------------------------------------------

function confirmPassword(oForm) {

	if (oForm.Password.value!=oForm.elements["_ConfirmPassword"].value) {
	
		oForm.Password.value="";
		oForm.elements["_ConfirmPassword"].value="";
		alert(CNREENTERPASSWORD + '\n' + CNNOTMATCH);
		return false;

	} else {
		return true;
	}
}


// -------------------------------------------------------------------------------
// Function         : confirmPassword2(oForm)
// -------------------------------------------------------------------------------
// Author           : Chad Peck
// Created on       : Friday, March 24, 2000
// 
// This function checks to make sure that two the values of a password field and
// a confirm password field match.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// oForm		form		Reference to a form object.  It should always be
//							by the this keyword.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function confirmPassword2(oForm) {

	if (oForm.NewPassword.value!=oForm.elements["_ConfirmPassword"].value) {
	
		oForm.NewPassword.value="";
		oForm.elements["_ConfirmPassword"].value="";
		alert(CNREENTERPASSWORD + '\n' + CNNOTMATCH);
		return false;

	} else {
		return true;
	}
}

// -------------------------------------------------------------------------------
// Function         : checkCookiesOn(checkFlags)
// -------------------------------------------------------------------------------
// This function checks, on the client, whether cookies are enabled in the browser. 
// The function will check for Per-session cookies and/or for Stored cookies.
// A bit mask is returned indicating which types of cookies are enabled.  The  
// return value will be 0 if no cookie types are enabled; 1 if Per-session cookies 
// are enabled; 2 if Store cookies are enabled; 3 if both types are enabled.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME			TYPE        DESCRIPTION
// checkFlags	number		A bit mask indicating which type of cookie(s) to check;
//							1 indicates check Per-session cookies; 2 indicates 
//							check Stored cookies; 3 or 0 indicates check both 
//							cookie types.
// -------------------------------------------------------------------------------
// History
// -------------------------------------------------------------------------------
// DATE			NAME             DESCRIPTION
// 06/19/2000   Barry Cline		 Created
//
var PERSESSION_COOKIE_FLAG = 1;
var STORED_COOKIE_FLAG = 2;
function checkCookiesOn(checkFlags)
{
	var index;
	var enabledFlags = 0;
		
	if (checkFlags == 0)
		//If we're not asked to check anything, then, obviously, we'll check everything.
		checkFlags = PERSESSION_COOKIE_FLAG + STORED_COOKIE_FLAG;
			
	if ((checkFlags & PERSESSION_COOKIE_FLAG) != 0)
	{	
		//Check whether Per-session cookie already exists
		index = document.cookie.indexOf(perSessionCookieName + "=");
		if (index == -1)
		{
			//Issue per-session check cookie
			var perSessionCookieName = "CNPerSessionCookieCheck";
			document.cookie = perSessionCookieName + "=True";
			//Try to retrieve per-session check cookie
			index = document.cookie.indexOf(perSessionCookieName + "=");
		}
		if (index != -1)
			enabledFlags += PERSESSION_COOKIE_FLAG;
	}	
	if ((checkFlags & STORED_COOKIE_FLAG) != 0)
	{
		//Check whether SITESERVER stored cookie already extant & available
		index = document.cookie.indexOf("SITESERVER=");
		if (index == -1)
		{
			//Issue stored check cookie
			var storedCookieName = "CNStoredCookieCheck";
			var today = new Date();
			var expiration = new Date(today.getTime() + 1 * 24 * 60 * 60 * 1000);
			document.cookie = storedCookieName + 
								"=True ; path=/; expires=" + expiration.toGMTString();
			//Try to retrieve stored check cookie
			index = document.cookie.indexOf(storedCookieName + "=");
			if (index != -1)
			{
				enabledFlags += STORED_COOKIE_FLAG;
				//Delete stored check cookie
				document.cookie = storedCookieName + 
									"=; path=/; expires=Tue, 01-Jan-80 00:00:01 GMT";
			}
		}
		else
		{
			enabledFlags += STORED_COOKIE_FLAG;
		}
	}
	return enabledFlags;
}


function checkAllCookies()
{	
	var checkFlags = PERSESSION_COOKIE_FLAG + STORED_COOKIE_FLAG;
	if ((checkCookiesOn(checkFlags) & checkFlags) == checkFlags)
		return 1;
	else
		return 0;
}

function checkStoredCookie()
{	
	var checkFlags = STORED_COOKIE_FLAG;
	if ((checkCookiesOn(checkFlags) & checkFlags) == checkFlags)
		return 1;
	else
		return 0;
}

function checkPerSessionCookie()
{	
	var checkFlags = PERSESSION_COOKIE_FLAG;
	if ((checkCookiesOn(checkFlags) & checkFlags) == checkFlags)
		return 1;
	else
		return 0;
}

// This code will be executed at the top of all 
// ChannelNet XSL template-derived Web pages
if (checkStoredCookie() == 0)
	document.location.href="/_mem_bin/nocookie.asp";

