
// base.js: contains universal functions for IBS sites

/*
	function changeFormAction()
	Created 5/4/01
	Michael Hanson (con-mjh@ibsys.com)
	Replaces the form action on IA sites with a correctly
	pathed form action.
*/
WindowEnabled = true;

function changeFormAction(){
	if (typeof IS_IA != 'undefined' && IS_IA == true) {
		for (i = 0 ; i < document.forms.length ; i++) {
			var currentAction = document.forms[i].action;
			var reHTTP = /http:\/\//gi;
			var reCF = /\/cf\//gi;
			var actionHTTP = reHTTP.test(currentAction);
			var actionCF = reCF.test(currentAction);
			if (actionHTTP && actionCF){
				regReplace = /http:\/\/www/gi;
				rebuildAction = currentAction.replace(regReplace,'http://html');
				//alert(rebuildAction);
				document.forms[i].action = rebuildAction;
			}//URL is fully qualified and points at /cf/...
			else if (actionCF){
				var fullHostname = document.location.hostname;
				var reHostSplit = /\./
				var domain = fullHostname.split(reHostSplit);
				if (domain[0] == 'www') domain[0] = 'http://html';
				if (domain[0] != 'html') {
					var rebuildAction = '';
					for (j = 0 ; j < domain.length - 1; j++){
						rebuildAction += domain[j] + '.';
					}
					rebuildAction += domain[j] + currentAction;
					//alert(document.forms[i].action);
					document.forms[i].action = rebuildAction;
				}
			}//URL needs to resolve to /cf/...
		}//loop
	}//If an IA site
}//function


/*
WM_setCookie(), WM_readCookie(), WM_killCookie()
A set of functions that eases the pain of using cookies.
Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Nadav Savio Author Email: nadav@wired.com
*/
// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}
function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName && (navigator.appName == 'Netscape') && navigator.appVersion && (parseInt(navigator.appVersion) == 2))?false:true;
	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // WM_setCookie
function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
    }	
} // WM_readCookie
function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie

// WRITES BUYLINES TO PAGE
function writeBuylines(){
	// if (typeof Buylines != 'undefined') {
		// if (Buylines.length > 0) {
			// for(b=0; b != Buylines.length; b++) {
				// clickThru = Buylines[b].url;
				// clickThru = clickThru.replace(/Redirect=%2F/g, 'Redirect=http:%2F%2fwww.' + IBSsite.siteName + '%2f');
				// if (Buylines[b].text != 'BLANK') document.write ('<div class="buyline"><a class="iconed" href="' + clickThru + '">' + Buylines[b].text + '</a></div>');
			// }
		  // Buylines = null;
		// }
	// }
}

function Buyline(url,text) {
	this.text=text;
	this.url=url
}

// Create Universal IBSSite Object
dotPosition = document.location.host.indexOf('.')+1;
IBSSite = new Object();
IBSSite.domain = document.location.host.substring(dotPosition);

// EMAIL A FRIEND FUNCTIONS
function emailafriend(URL, ATTRIBUTES)
	//OPEN WINDOW JS
	// takes all attributes in direct format
{
	ATTRIBUTES = 'width=450,height=225,top=100,left=100,resizable=yes,scrollbars';
	MYURL = "http://weather.cin.ibsys.com/services/toafriend/index.cfm?page=" + window.location;
	
	if (WindowEnabled){
		child = window.open(MYURL, "spawn", ATTRIBUTES);
		child.opener = self;
		if	(navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) == '2') {
			// Do Nothing
		} else {
			child.focus();
		}
	} else {
		document.location = MYURL;
	}
}


function popUp(URL, ATTRIBUTES)
	//OPEN WINDOW JS
	// takes all attributes in direct format
{
	DEF_ATTRIB = 'width=200,height=200,top=100,left=100,resizable=yes,scrollbars';
	if (ATTRIBUTES == null) ATTRIBUTES = DEF_ATTRIB;
	if (WindowEnabled) {
		child = window.open(URL, "spawn", ATTRIBUTES);
		child.opener = self;
		if	(navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) == '2') {
		// Do Nothing
		} else {
		child.focus();
		}
	} else {
		document.location = MYURL;
	}
}
