
/*************************************************************************************
* Javascript library for CJA website
* REQUIRES:
*   YUI libraries:
*   http://localhost/YUI/build/cookie/cookie-min.js
*   http://localhost/YUI/build/yahoo/yahoo-min.js
**************************************************************************************/

/**************************************************************************************
* Generic base-class methods and properties for all CJA website pages (.html and .aspx)
***************************************************************************************/



// DEFINE PAGE-WIDE VARIABLES

var CJA_currHref = location.href;
var PG_currHref = location.href;
var CJAlogin = "";
var CJAuname = '';
var CJAuid = 0;
var CJAroles = '';
var ServerName = window.location.hostname;


// FORCE SSL CONNECTION 

ForceSSL();

// -----------------------------------------------------------------------
// Load JS libraries with dynamic hostname paths depending on server used
// (runs each time the page containing this include file is loaded)
// -----------------------------------------------------------------------
 AddDynamicJSLibs_CJA();


 // ----------------------------------------------------------
 // Returns "localhost" if server is NOT CJAMARKETING.COM,
 // otherwise, returns "WWW.PLANGEN.COM".
 // (used to force links to Plangen.com from CJAMARKETING.COM)
 // (e.g. PGContent application path from CJAMarketing.com)
 // ----------------------------------------------------------

 function LocalHostOrPGServerNameIfCJA() {
     if (window.location.hostname.toUpperCase().indexOf('CJAMARKETING.COM') == -1) {
        return 'localhost';
     }
    else {
        return 'www.PlanGen.com';
     }
 }

// --------------------------------------------------
// Force SSL connection protocol
// --------------------------------------------------

function ForceSSL(){
    var url = document.location.href.toString().toLowerCase();
    if (url.indexOf("localhost") == -1) {
        if (url.indexOf("https://www.cjamarketing.com") == -1) {
            // force www
            if (url.indexOf("www.cjamarketing.com") == -1) {
                url = url.replace("cjamarketing.com", "www.cjamarketing.com");
            }
            // force ssl
            if (url.indexOf("http:") != -1) {
                url = url.replace("http:", "https:");
            }
            document.location = url;
        }
      }
      else {
          if (url.indexOf("http:") != -1) {
              url = url.replace("http:", "https:");
              document.location = url;
          }
    }
    

}

// --------------------------------------------------
//  Standard page-level initialization for CJA pages
// --------------------------------------------------
function InitCJAPage() {
    cjaloginOK();
    secureContent();
}

// --------------------------------------------------
// Get cookie values into local JS vars
// --------------------------------------------------
function getCJACookies() {
    CJAuid = YAHOO.util.Cookie.get("CJAuid");
    CJAuname = YAHOO.util.Cookie.get("CJAuname");
    CJAroles = YAHOO.util.Cookie.get("CJAroles"); 
    CJAlogin = YAHOO.util.Cookie.get("PGloggedin");
}

// ----------------------------------------------------------
// cjaloginOK()
// Tests for login cookie, setting DIV to the logged-in name
// or "not logged in/" if no login is detected.
// Requires each page to have a DIV element named "username" 
// ----------------------------------------------------------
function cjaloginOK() {
    getCJACookies();
    var u = document.getElementById('username');
    if (u != null) {
        if (CJAlogin == 'OK'){
            var logoutTXT = '<br><a href="" onclick="CJALogout();">[log out...]</a>';
            u.innerHTML = 'Welcome ' + CJAuname + logoutTXT;
            hide('agent_loginIMG');
        }
        else {
            u.innerHTML = '';
        } 
    }
}

// ----------------------------------------------------------
// Log User Out
// ----------------------------------------------------------
function CJALogout(){
    YAHOO.util.Cookie.remove("PGloggedin",{path: "/"});
    YAHOO.util.Cookie.remove("CJAuid",{path: "/"});
    YAHOO.util.Cookie.remove("CJAuname",{path: "/"});
    YAHOO.util.Cookie.remove("CJAroles",{path: "/"});
    CJAlogin = null;
    CJAuid = null;
    CJAuname = null;
    CJAroles = null;
    document.location = document.location;
}


// ----------------------------------------------------------
// Hide content link(s) from users not logged-in
// ----------------------------------------------------------
function secureContent() {
    hide('Img1');
    try {
        if (CJAlogin) {
            if (CJAlogin == "OK" && CJAuid != '0') {
                show('Img1');
            }
            else {
                hide('Img1');
            }
        }
    }
    catch (err) {
        hide('Img1');
    }
}


// ---------------------------------------------------------------------------------------
// Dynamically manufacture paths to javascript libraries for the current server 
// Inserts new <script> elements into the head section of the HTML document substituting
// the hostname (servername) as a path element to the include file.
// ---------------------------------------------------------------------------------------
function AddDynamicJSLibs_CJA()
{
    // define common objects
    var url = document.location.href.toString().toLowerCase();
    var h = window.location.hostname;
    var head = document.getElementsByTagName('head')[0];

    // -- force WWW.CJAMARKETING.COM
    if (h.indexOf("www.cjamarketing.com") == -1) {
        h = url.replace("cjamarketing.com", "www.cjamarketing.com");
    }

    // GreyBox style CSS (must go in HEAD section)
    var csslink = document.createElement('link');
    csslink.type = 'text/css';
    //csslink.href = 'https://' + h + '/greybox/gb_styles.css';
    csslink.href = '/greybox/gb_styles.css';
    csslink.rel = 'stylesheet';
    head.appendChild(csslink);        
}

// ------------------------------------------------------------------------------
// Writes out the dynamic path to the greybox root directory for current server
// ------------------------------------------------------------------------------
function GreyBoxRootPath(){
    // GreyBox support files (must go in BODY section, NOT HEAD!)
    var h = window.location.hostname;
    document.write("<script type='text/javascript'>");
    document.write('var GB_ROOT_DIR = "' + 'https://' + h + '/greybox/";');
    document.write("<\/sc" + "ript>");
}

// -----------------------------------------------------------------------------
// Writes out the dynamic path to the login hover window for the current server
// Image link version.
// (note single quotes are escaped with "\" character)
// -----------------------------------------------------------------------------
function LoginLinkImage(){
    var h = window.location.hostname;
    document.write('<A id="agent_loginIMG" onclick=');
    document.write('\'return GB_showCenter("CJA:",this.href,400,550,InitCJAPage);\' ');
    document.write('href=\'https://' + h + '/cjawebapp/login_hover.aspx');
    //document.write('?&amp;CSS=https%3a%2f%2f' + h + '%2fPG%2fsites%2fCJA%2fportal.css\'>');
    document.write('?&amp;CSS=https%3a%2f%2f' + 'www.plangen.com' + '%2fPG%2fsites%2fCJA%2fportal.css\'>');
    document.write('<img src="images/agent_login.jpg" width="221" height="38" border="0" /></a>');
}


// -----------------------------------------------------------------------------------
// Writes out the dynamic path to the login hover window for the current server
// Text link version
// Optional parameter for hyperlink CSS style name e.g. "LoginLinkText('footerlink');"
// (note single quotes are escaped with "\" character)
// -----------------------------------------------------------------------------------
function LoginLinkText(cssname){
    var h = window.location.hostname;
    document.write('<A ');
    if (cssname != null) {
        document.write('class=\'' + cssname + '\' ');
    }
    document.write('id="agent_loginTXT" onclick=');
    document.write('\'return GB_showCenter("CJA:",this.href,400,400,cjaloginOK);\' ');
    document.write('href=\'https://' + h + '/cjawebapp/login_hover.aspx');
    //document.write('?&amp;CSS=https%3a%2f%2f' + h + '%2fPG%2fsites%2fCJA%2fportal.css\'>');
    document.write('?&amp;CSS=https%3a%2f%2f' + 'www.plangen.com' + '%2fPG%2fsites%2fCJA%2fportal.css\'>');
    document.write('Agent Login</a>');
}

// -----------------------------------
// Writes out standard CJA page footer
// -----------------------------------
function WriteCJAFooter(){
    var h = window.location.hostname;
    document.write('<a href="index.html" class="footerlink">Home</a> | ');
    LoginLinkText('footerlink');
    document.write(' | ');
    document.write('<A class="footerlink" onclick=');
    document.write('\'return GB_showCenter("PlanGen:",this.href,600,900,cjaloginOK);\' ');
    //document.write('href=\'https://' + h + '/cjawebapp/electronicRFP.aspx' + '\'>');
    //document.write('Request Proposal</a> | ');
    document.write('<a href="contact_us.html" class="footerlink">Contact Us</a> | ');
    document.write('<a href="sitemap.html" class="footerlink">Sitemap</a>');
}

// -----------------------------------
// Generate IFRAME tag for contact map
// -----------------------------------

function WriteContactMapIframe(){
    var h = window.location.hostname;
    document.write('<iframe src="https://' + h + '/cjawebapp/CJAMap.aspx" width="560" height="450" frameborder="0"><p>Your browser does not support iframes</p></iframe>');
    //document.write('<iframe src="http://' + h + '/cjawebapp/CJAMap.html" width="560" height="450" frameborder="0"><p>Your browser does not support iframes</p></iframe>');

}

// ---------------------------------------
// Redirects current page to the referrer
// and opens a new window for the RFP form
// Used on the request_proposal.html page
// ---------------------------------------
function RedirectToRFP(){
    var origin = document.referrer;
    var h = window.location.hostname;
    var x = 'https://' + h + '/cjawebapp/electronicRFP.aspx';
    
    
   // return GB_showCenter("PlanGen:",x,500,600,document.location=document.referrer);
    
}

// -----------------------------------------------------------------------------
// Writes out the dynamic path to the login hover window for the current server
// Image link version.
// (note single quotes are escaped with "\" character)
// -----------------------------------------------------------------------------
function RFPLinkImage(){
    //var h = window.location.hostname;
    //document.write('<A onclick=');
    //document.write('\'return GB_showCenter("PlanGen:",this.href,600,900,cjaloginOK);\' ');
    //document.write('href=\'https://' + h + '/cjawebapp/electronicRFP.aspx' + '\'>');
    //document.write('<img src="images/request_proposal.jpg" width="221" height="38" border="0" /></a>');
}


/**************************************************************************************
* END Generic base-class methods and properties for all CJA website pages
***************************************************************************************/





function GetSystemDate(){
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	return (month + "/" + day + "/" + year);
}

function GetSystemTime(){
    var retVal;
	var currentTime = new Date();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	if (minutes < 10){
		minutes = '0' + minutes;
	}
	retVal = (hours + ":" + minutes);
	if (seconds < 10){
		seconds = '0' + seconds;
	}
	retVal = retVal + ':' + seconds;
	if(hours > 11){
		retVal = retVal + ' PM';
	} else {
		retVal = retVal + ' AM';
	}
	return retVal;
}

/*******************************************
* COOKIE UTILITIES
********************************************/

function listCookiesString() {
    var theCookies = document.cookie.split(';');
    var aString = '';
    for (var i = 1 ; i <= theCookies.length; i++) {
        aString += i + ' ' + theCookies[i-1] + "\n";
    }
    return aString;
}

function get_cookies_array() {
    var cookies = { };
    if (document.cookie && document.cookie != '') {
        var split = document.cookie.split(';');
        for (var i = 0; i < split.length; i++) {
            var name_value = split[i].split("=");
            name_value[0] = name_value[0].replace(/^ /, '');
            cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
        }
    }
    return cookies;
}

function getCookiesAsString() {
    var retVal = '';
    var cookies = get_cookies_array();
    for(var name in cookies) {
      retVal = name + " : " + cookies[name] + "/m" ;
    }
    return retVal
}

function documentWriteCookies() {
    var retVal = '';
    var cookies = get_cookies_array();
    for(var name in cookies) {
      document.write(name + " : " + cookies[name] + "<br>");
    }
}




var getCookies = function(){
  var pairs = document.cookie.split(";");
  var cookies = {};
  for (var i=0; i<pairs.length; i++){
    var pair = pairs[i].split("=");
    cookies[pair[0]] = unescape(pair[1]);
  }
  return cookies;
}

/*******************************************
* END COOKIE UTILITIES
********************************************/

function PGreloadPage(){
    //  This version of the refresh function for browsers that support JavaScript version 1.
    //  The argument to the location.reload function determines
    //  if the browser should retrieve the document from the
    //  web-server.  In our example all we need to do is cause
    //  the JavaScript block in the document body to be
    //  re-evaluated.  If we needed to pull the document from
    //  the web-server again (such as where the document contents
    //  change dynamically) we would pass the argument as 'true'.
    //  NOTE: this will cause a page to reexecute its last operation (such as calculate or search)
    //  so it may not be appropriate as a simple page re-reader (see PGreReadPage() for that)
	window.top.location.reload(true); 
}

function PGreReadPage(){
	document.location = document.location;
}

function alertForRecalc(){
	// after a short delay (often needed for popup windows to disappear), tell user to recalculate.
	setTimeout("alert('External data may have changed. Please save/recalculate now for best results')", 500);
}

// Checks/Unchecks all checkboxes of specified ASP ID in form according to checked state passed in
function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) {
	re = new RegExp(':' + aspCheckBoxID + '$')  //asp-generated control name starts with a colon
	for(i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i]
		if (elm.type == 'checkbox') {
			if (re.test(elm.name)) {
            elm.checked = checkVal
            }
		}
	}
}

// Examines checkboxes of specified ASP ID in form, returning bool if any are checked
function AreAnyCheckBoxXChecked(aspCheckBoxID) {
	re = new RegExp(':' + aspCheckBoxID + '$')  //asp-generated control name starts with a colon
	for(i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i]
		if (elm.type == 'checkbox') {
			if (re.test(elm.name)) {
				if (elm.checked == true){ return true; }
			}
		}
	}
}

// Examines checkboxes of specified ASP ID in form, returning bool if any are unchecked
function AreAnyCheckBoxXUnChecked(aspCheckBoxID) {
	re = new RegExp(':' + aspCheckBoxID + '$')  //asp-generated control name starts with a colon
	for(i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i]
		if (elm.type == 'checkbox') {
			if (re.test(elm.name)) {
				if (elm.checked == false){ return true; }
			}
		}
	}
}

/*------------------------------------------------*/
/*------------CUSTOM YUI METHODS------------------*/
/*------------------------------------------------*/

// Function to parse URL String for #tabID and set index of tab object to it if it exists
function PG_YUI_parseURLForTabSetting(tabObj){
        var url = location.href.split('#');
        if (url[1]) {
        //We have a hash
        var tabHash = url[1];
        var tabs = tabObj.get('tabs');
        for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].get('href') == '#' + tabHash) {
                tabObj.set('activeIndex', i);
                break;
            }
        }
    }
}

/*------------------------------------------------*/
/*---------CUSTOM GREYBOX METHODS-----------------*/
/*------------------------------------------------*/

// NOTE: some "PG_xxx" variables are created server-side by UtilityLibrary.GetJSPathVars();

function greyBoxClose(){
    GB_hide();
}

function greyBoxCloseThenRecalc(){
  GB_hide();
  clickObj('updateButton');
}


function greyBoxCloseThenHome(cmd){
  GB_hide();
  var c = '';
  if (cmd != null){
	c = "?cmd=" + cmd;
  }
  location.href=PG_fullAppPath + 'default.aspx' + c;
}

function greyBoxCloseThenRefresh(){
  GB_hide();
  location.href=location.href;
}

function greyBoxCloseThenRedirect(url) {
  GB_hide();
  location.href=url;
} 

function greyBoxCloseThenClickObj(object) {
	GB_hide();
	if (document.getElementById)
	{
		document.getElementById(object).click();
	}
	else if (document.all)
	{
		document.all[object].click();
	}
}

function greyBoxCloseWithError(msg){
    GB_hide();
    alert(msg);
}

function greyBoxCloseThenPromptForRecalc(){
	GB_hide();
	alertForRecalc();
}	

function greyBoxCloseThenExecuteJS(cmd){
  GB_hide();
  var c = '';
  if (cmd != null){
    //alert(cmd);
	eval(cmd);
  } 
}

function hi(){
	alert('hi from parent');
	//window.top.location.reload(); 
}

/*---------END CUSTOM GREYBOX METHODS--------------*/


/*------------------------------------------------*/

// Fires the click event of an object passed in
function clickObj(object) {
	if (document.getElementById)
	{
		document.getElementById(object).click();
	}
	else if (document.all)
	{
		document.all[object].click();
	}
}

/*------------------------------------------------*/
function toggleVis2(obj){
	var el = document.getElementById(obj);
	el.style.display = (el.style.display != 'none' ? 'none' : '' ); 
}

function toggleVis(object){
	if (document.getElementById)
	{
		var ele = document.getElementById(object); 
		if(ele != null){
			if (document.getElementById(object).style.visibility == 'visible'){
				hide(object);
			}
			else {
				show(object);
			}
		}
	}
	else if (document.all)
	{
		var ele = document.all[object]; 
		if(ele != null){
			if (document.all[object].style.visibility == 'visible'){
				hide(object);
			}
			else {
				show(object);
			}
		}
	}
}

/*------------------------------------------------*/

/*------------------------------------------------*/

function hideShowObj(object, display){
	if (display == true) {
		show(object);
	}
	else {
		hide(object);
	}
}

/*---------------------------------------------------------------------------------------------------*/
// NOTE: using "object.style.visibility" only hides the element...reserves space for it.
//       using "object.style.display" will remove space for the element..not just hide it.."collapsing" the display in browser
// "inline" inserts in-flow, no new line generated
// "block"  often generates a new line...not desired
/*---------------------------------------------------------------------------------------------------*/
function show(object) {
	if (document.getElementById)
	{
		var ele = document.getElementById(object); 
		if(ele != null){
				//ele.style.display = 'block';
				ele.style.display = 'inline';
			}
	}
	else if (document.all)
	{
		var ele = document.all[object]; 
		if(ele != null){
			//ele.style.display = 'block';
			ele.style.display = 'inline';
		}
	}
}

function hide(object) {
	if (document.getElementById)
	{
		var ele = document.getElementById(object); 
		if(ele != null){
			ele.style.display = 'none';
		}
	}
	else if (document.all)
	{
		var ele = document.all[object]; 
		if(ele != null){
			ele.style.display = 'none';
		}
	}
}


/*------------------------------------------------*/

function disable(object) {
	if (document.getElementById)
	{
		var ele = document.getElementById(object); 
		if(ele != null){
			//document.getElementById(object).style.visibility = 'hidden';
			ele.disabled=true;
			ele.style.backgroundColor = '#E0E0E0';
		}
	}
	else if (document.all)
	{
		var ele = document.all[object]; 
		if(ele != null){
			//document.all[object].style.visibility = 'hidden';
			ele.disabled=true;
			ele.style.backgroundColor = '#E0E0E0';
		}
	}
}

function enable(object) {
	if (document.getElementById)
	{
		var ele = document.getElementById(object); 
		if(ele != null){
			//document.getElementById(object).style.visibility = 'hidden';
			ele.disabled=false;
			ele.style.backgroundColor=''
		}
	}
	else if (document.all)
	{
		var ele = document.all[object]; 
		if(ele != null){
			//document.all[object].style.visibility = 'hidden';
			ele.disabled=false;
			ele.style.backgroundColor=''
		}
	}
}

/*------------------------------------------------*/


function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

/*------------------------------------------------*/

function getURLParameters() 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
			alert(arrParamNames[i]+" = "+ arrParamValues[i]);
		}
	}
	else
	{
		alert("No parameters.");
	}
}

/*------------------------------------------------*/

function getViewportSize()
{
    var size = [0, 0];

    if (typeof window.innerWidth != 'undefined')
    {
    size = [
       window.innerWidth,
       window.innerHeight
    ];
    }
    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
    {
    size = [
       document.documentElement.clientWidth,
       document.documentElement.clientHeight
    ];
    }
    else
    {
    size = [
       document.getElementsByTagName('body')[0].clientWidth,
       document.getElementsByTagName('body')[0].clientHeight
    ];
    }

    return size;
}

/*------------------------------------------------*/

function getScrollingPosition()
{
	var position = [0, 0];

	if (typeof window.pageYOffset != 'undefined')
	{
	position = [
		window.pageXOffset,
		window.pageYOffset
	];
	}

	else if (typeof document.documentElement.scrollTop
		!= 'undefined' && document.documentElement.scrollTop > 0)
	{
	position = [
		document.documentElement.scrollLeft,
		document.documentElement.scrollTop
	];
	}

	else if (typeof document.body.scrollTop != 'undefined')
	{
	position = [
		document.body.scrollLeft,
		document.body.scrollTop
	];
	}

	 return position;
}

/*------------------------------------------------*/

function getPosition(theElement)
{
    var positionX = 0;
    var positionY = 0;
    
//    while (theElement != null)
//    {
//    positionX += theElement.offsetLeft;
//    positionY += theElement.offsetTop;
//    theElement = theElement.offsetParent;
//    }


    positionX += theElement.offsetLeft;
    positionY += theElement.offsetTop;
    //return [positionX, positionY];
    alert('element positioned at ' + positionX + ',' + positionY);
}

/*------------------------------------------------*/


/*------------------------------------------------------------------------------
*  JAVASCRIPT TRIM, LTRIM, RTRIM
*  http://www.webtoolkit.info/
* Without the second parameter, Javascript function will trim these characters:
* " " (ASCII 32 (0x20)), an ordinary space.
* "\t" (ASCII 9 (0x09)), a tab.
* "\n" (ASCII 10 (0x0A)), a new line (line feed).
* "\r" (ASCII 13 (0x0D)), a carriage return.
* "\0" (ASCII 0 (0x00)), the NUL-byte.
* "\x0B" (ASCII 11 (0x0B)), a vertical tab.
*--------------------------------------------------------------------------------*/
 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}




/*		<!-- --------------------------------------DHTML TOOLTIP CODE BLOCK-----------------------------------------
		The "<div id="dhtmltooltip"></div>" statement must come inside the <body> tag.
		The Dynamic Drive DHTML javascript script must come AFTER the <div id="dhtmltooltip"></div> tag
		--------------------------------------------------------------------------------------------------------- -->
		<div id="dhtmltooltip"></div>
		<script type="text/javascript">
*/
		/*************************************************************************************
		* Cool DHTML tooltip script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
		* This script must come after the <div id="dhtmltooltip"></div>
		**************************************************************************************/

		var offsetxpoint=40 //Customize x offset of tooltip
		var offsetypoint=20 //Customize y offset of tooltip
		var ie=document.all
		var ns6=document.getElementById && !document.all
		var enabletip=false
		if (ie||ns6)
		var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

		function ietruebody(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		}

		function ddrivetip(thetext, thecolor, thewidth){
			if (ns6||ie){
			if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
			if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
			tipobj.innerHTML=thetext
			enabletip=true
			return false
			}
		}

		function positiontip(e){
		if (enabletip){
			var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
			var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
			//Find out how close the mouse is to the corner of the window
			var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
			var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

			var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

			//if the horizontal distance isn't enough to accomodate the width of the context menu
			if (rightedge<tipobj.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
			else if (curX<leftedge)
			tipobj.style.left="5px"
		else
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px"

			//same concept with the vertical position
			if (bottomedge<tipobj.offsetHeight)
				tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
				else
				tipobj.style.top=curY+offsetypoint+"px"
				tipobj.style.visibility="visible"
			}
		}

		function hideddrivetip(){
			if (ns6||ie){
				enabletip=false
				tipobj.style.visibility="hidden"
				tipobj.style.left="-1000px"
				tipobj.style.backgroundColor=''
				tipobj.style.width=''
			}
		}

		document.onmousemove=positiontip;

/*		</script>
		<!-- --------------------------------------END DHTML TOOLTIP CODE BLOCK----------------------------------------
		The "<div id="dhtmltooltip"></div>" statement must come inside the <body> tag.
		the Dynamic Drive DHTML javascript script must come AFTER the <div id="dhtmltooltip"></div> tag
		----------------------------------------------------------------------------------------------------------- -->
*/

/*----------------------------------EMAIL VALIDATION-----------------------------------------
The script makes the following assumptions regarding what a valid email address is:
-Contains a least one character procedding the "@"
-Contains a "@" following the procedding character(s)
-Contains at least one character following the "@", followed by a dot (.), 
followed by either a two character or three character string 
(a two character country code or the standard three character US code, such as com, edu etc)
----------------------------------------------------------------------------------------------*/

function isValidEmail(obj)
{
	var obj=document.getElementById(obj);
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(obj.value))
	{
		obj.className = 'NormalTextBox';
		return true;
	}
	else
	{
		obj.className = 'FormError';
		return false;
	}
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// December 29, 2003: Added the option to specify a delimiter for
//    multiple valued input field via getInputValue(), etc.

//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
	}
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
	}
function TrimAll(str) {
	return LTrimAll(RTrimAll(str));
	}
//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val){return(val==null);}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val){return(parseFloat(val,10)==(val*1));}

//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
		}
	}

//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if 
//   blank and focuses
//   Modified by E.Edelstein to change backgroundColor
//-------------------------------------------------------------------
function disallowBlank(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (isBlank(getInputValue(obj))){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.style.backgroundColor = 'coral';
			obj.focus();
			}
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// disallowModify(input_object[,message[,true]])
//   Checks a form field for a value different than defaultValue. 
//   Optionally alerts and focuses
//-------------------------------------------------------------------
function disallowModify(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (getInputValue(obj)!=getInputDefaultValue(obj)){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
			}
		setInputValue(obj,getInputDefaultValue(obj));
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// commifyArray(array[,delimiter])
//   Take an array of values and turn it into a comma-separated string
//   Pass an optional second argument to specify a delimiter other than
//   comma.
//-------------------------------------------------------------------
function commifyArray(obj,delimiter){
	if (typeof(delimiter)=="undefined" || delimiter==null) {
		delimiter = ",";
		}
	var s="";
	if(obj==null||obj.length<=0){return s;}
	for(var i=0;i<obj.length;i++){
		s=s+((s=="")?"":delimiter)+obj[i].toString();
		}
	return s;
	}

//-------------------------------------------------------------------
// getSingleInputValue(input_object,use_default,delimiter)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputValue(obj,use_default,delimiter) {
	switch(obj.type){
		case 'radio': case 'checkbox': return(((use_default)?obj.defaultChecked:obj.checked)?obj.value:null);
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].value;}}
				return o[0].value;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].value:null;
		case 'select-multiple': 
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].value;
					}
				}
			return (values.length==0)?null:commifyArray(values,delimiter);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}

//-------------------------------------------------------------------
// getSingleInputText(input_object,use_default,delimiter)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputText(obj,use_default,delimiter) {
	switch(obj.type){
		case 'radio': case 'checkbox': 	return "";
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].text;}}
				return o[0].text;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].text:null;
		case 'select-multiple': 
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].text;
					}
				}
			return (values.length==0)?null:commifyArray(values,delimiter);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}

//-------------------------------------------------------------------
// setSingleInputValue(input_object,value)
//   Utility function used by others
//-------------------------------------------------------------------
function setSingleInputValue(obj,value) {
	switch(obj.type){
		case 'radio': case 'checkbox': if(obj.value==value){obj.checked=true;return true;}else{obj.checked=false;return false;}
		case 'text': case 'hidden': case 'textarea': case 'password': obj.value=value;return true;
		case 'select-one': case 'select-multiple': 
			var o=obj.options;
			for(var i=0;i<o.length;i++){
				if(o[i].value==value){o[i].selected=true;}
				else{o[i].selected=false;}
				}
			return true;
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return false;
	}

//-------------------------------------------------------------------
// getInputValue(input_object[,delimiter])
//   Get the value of any form input field
//   Multiple-select fields are returned as comma-separated values, or
//   delmited by the optional second argument
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputValue(obj,delimiter) {
	var use_default=(arguments.length>2)?arguments[2]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputValue(obj[i],use_default,delimiter);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values,delimiter);
		}
	return getSingleInputValue(obj,use_default,delimiter);
	}

//-------------------------------------------------------------------
// getInputText(input_object[,delimiter])
//   Get the displayed text of any form input field
//   Multiple-select fields are returned as comma-separated values, or
//   delmited by the optional second argument
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputText(obj,delimiter) {
	var use_default=(arguments.length>2)?arguments[2]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputText(obj[i],use_default,delimiter);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values,delimiter);
		}
	return getSingleInputText(obj,use_default,delimiter);
	}

//-------------------------------------------------------------------
// getInputDefaultValue(input_object[,delimiter])
//   Get the default value of any form input field when it was created
//   Multiple-select fields are returned as comma-separated values, or
//   delmited by the optional second argument
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputDefaultValue(obj,delimiter){return getInputValue(obj,delimiter,true);}

//-------------------------------------------------------------------
// isChanged(input_object)
//   Returns true if input object's value has changed since it was
//   created.
//-------------------------------------------------------------------
function isChanged(obj){return(getInputValue(obj)!=getInputDefaultValue(obj));}

//-------------------------------------------------------------------
// setInputValue(obj,value)
//   Set the value of any form field. In cases where no matching value
//   is available (select, radio, etc) then no option will be selected
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function setInputValue(obj,value) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if(isArray(obj)&&(typeof(obj.type)=="undefined")){
		for(var i=0;i<obj.length;i++){setSingleInputValue(obj[i],value);}
		}
	else{setSingleInputValue(obj,value);}
	}
	
//-------------------------------------------------------------------
// isFormModified(form_object,hidden_fields,ignore_fields)
//   Check to see if anything in a form has been changed. By default
//   it will check all visible form elements and ignore all hidden 
//   fields. 
//   You can pass a comma-separated list of field names to check in
//   addition to visible fields (for hiddens, etc).
//   You can also pass a comma-separated list of field names to be
//   ignored in the check.
//-------------------------------------------------------------------
function isFormModified(theform,hidden_fields,ignore_fields){
	if(hidden_fields==null){hidden_fields="";}
	if(ignore_fields==null){ignore_fields="";}
	var hiddenFields=new Object();
	var ignoreFields=new Object();
	var i,field;
	var hidden_fields_array=hidden_fields.split(',');
	for (i=0;i<hidden_fields_array.length;i++) {
		hiddenFields[Trim(hidden_fields_array[i])]=true;
		}
	var ignore_fields_array=ignore_fields.split(',');
	for (i=0;i<ignore_fields_array.length;i++) {
		ignoreFields[Trim(ignore_fields_array[i])]=true;
		}
	for (i=0;i<theform.elements.length;i++) {
		var changed=false;
		var name=theform.elements[i].name;
		if(!isBlank(name)){
			var type=theform.elements[i].type;
			if(!ignoreFields[name]){
				if(type=="hidden"&&hiddenFields[name]){changed=isChanged(theform[name]);}
				else if(type=="hidden"){changed=false;}
				else {changed=isChanged(theform[name]);}
				}
			}
		if(changed){return true;}
		}
		return false;
	}
// ******************************************************************************************************
// *******************************END MATT KRUSE JAVASCRIPT LIBRARY**************************************
// ******************************************************************************************************

// ******************************************************************************************************
// ****************************GENERIC PLANGEN FORM VALIDATION LIBRARY***********************************
// ******************************************************************************************************
// (this library assumes standardized input field names on the form!)



