// ######################### Form Validation Functions #############################

// Validates any form to determine if required fields are empty
// This function checks for a hidden input field that has the required field name ending with '_required'
//  located within the form.  If found, false is returned and the message alert box displays the value of the 
//  hidden field as an error message.
//  For Example: Required Input Field: <input type="text" name="fullName" />
//  Required hidden field with error message value: <input type="hidden" name="fullName_required" value="Your Full Name is Required" />

function isValidRequired(myForm) {
	var isValid=true;
	var msg = "";
	
	for (var j=0; j<(myForm.elements.length); j++) {
		var indx = myForm.elements[j].name.indexOf('_required');
											
    	if (indx > 0) {
			var fieldname=myForm.elements[j].name.substring(0,indx);
			if ((myForm.elements[fieldname].type == 'text') || (myForm.elements[fieldname].type == 'textarea')) {
				if (myForm.elements[fieldname].value.length == 0) {
					if (msg == "") {
						msg = myForm.elements[j].value;
					} else {
						msg = msg + '\n\n' + myForm.elements[j].value;
					}
				myForm.elements[fieldname].focus();
	            }
			} else if (myForm.elements[fieldname].type == 'checkbox') {
				if (isValidCheckBox(myForm.elements[fieldname]) == false) {
					if (msg == "") {
						msg = myForm.elements[j].value;
					} else {
						msg = msg + '\n\n' + myForm.elements[j].value;
					}
				}
				myForm.elements[fieldname].focus();
			} else if (myForm.elements[fieldname].type == 'radio') {
				if (isValidRadioButton (myForm.elements[fieldname]) == false) {
					if (msg == "") {
						msg = myForm.elements[j].value;
					} else {
						msg = msg + '\n\n' + myForm.elements[j].value;
					}
				}
				myForm.elements[fieldname].focus();
			} else if (myForm.elements[fieldname].type == 'select') {
				if (isValidSelect (myForm.elements[fieldname]) == false) {
					if (msg == "") {
						msg = myForm.elements[j].value;
					} else {
						msg = msg + '\n\n' + myForm.elements[j].value;
					}
				}
				myForm.elements[fieldname].focus();
			}
        }
	}
	if (msg != "") {
		alert(msg);
		isValid = false;
	}
	return isValid;
}

// Checks whether a required checkbox has been checked

function isValidCheckBox(checkBoxName) {
	var isValid = true;
	if(checkBoxName.checked == false) {
		isValid = false;
	} 
	return isValid;
}

// Checks whether a required radio group button has been selected

function isValidRadioButton(radioGroup) {
	var isValid = false;
	for (var i=0; i < radioGroup.length; i++) {
		if (radioGroup[i].checked) {
			isValid = true;
		} 
	}
	return isValid;
}

// Checks whether a required select box has been selected

function isValidSelect(selectBox) {
	var isValid = true;

	if(selectBox.value == null || selectBox.value.length == 0) {
		isValid = false; 
	}
	 
	return isValid;
}


// Validates an email address for proper form
				
function isValidEmail(s) {
	var Count;
	var s2;
	var isValid=true;

	// empty or blank email
	if (s.value == "") isValid=false;

	// email with whitespace
	if (s.indexOf(' ') != -1) isValid=false;

	// email without @
	if (s.indexOf('@') == -1) isValid=false;

	// email with @ as the 1st char
	if (s.indexOf('@') == 0) isValid=false;

	// email with @ as the last char
	if ((s.indexOf('@')+1) == s.length) isValid=false;

	// email without .
	if (s.indexOf('.') == -1) isValid=false;

	// email with . as the 1st char
	if (s.indexOf('.') == 0) isValid=false;

	// email with . as the last char
	if ((s.indexOf('.')+1) == s.length) isValid=false;

	// Now look for the first . after the first @
	// s2 = string after the first @
	s2=s.substring(s.indexOf('@')+1,s.length);

	// email without a dot after the first @
	if (s2.indexOf('.') == -1) isValid=false;

	// email dot right after the first @
	if (s2.indexOf('.') == 0) isValid=false;

	return isValid;
}

function isPhoneNumber(s) {
	if (s == "") {
		return (true);
	} else {
		if (regExpSupported()) {
			// var re = /^1?s*-?s*(?s*[0-9]{3}s*)?s*-?s*[0-9]{3}s*-?s*[0-9]{4}$/;
			return re.test(s);
	
		} else {
			for (var i = 0; i < s.length; i++) {
				if (((s.charAt(i) < '0') || (s.charAt(i) > '9')) && (s.charAt(i) != '-') && (s.charAt(i) != '(') && (s.charAt(i) != ')')) return (false);
			}
		return (true);
		}
	}
}
	
function isZipCode(s) {
	if (EmptyString(s)) {
		return (false);
	} else {
		if (isValidUSZipCode(s) || isValidCanadianPostalCode(s)) {
			return (true);
		} else {
		return (false);
		}
	}
}
	
function isValidUSZipCode(s) {
	if ((s.length != 5) && (s.length != 10)) {
		return (false);
	} else {
		if (regExpSupported()) {
			var re = /^[0-9]{5}(-[0-9]{4})?$/;
			return re.test(s);
		} else {
			for (var i = 0; i < s.length; i++) {
				if ((s.charAt(i) < '0') || (s.charAt(i) > '9')) {
					if (s.charAt(i) == '-') {
						if (i != 5)
							return (false);
						} else {
						return (false);
						}
				}
			}
			return (true);
		}
	}
}
	
function isValidCanadianPostalCode(s) {
	if ((s.length != 6) && (s.length != 7)) {
		return (false);
	} else {
		if (regExpSupported()) {
			var re = /^[a-z|A-Z]{1}\d{1}[a-z|A-Z]{1}\-?\d{1}[a-z|A-Z]{1}\d{1}$/;
			return re.test(s);
		} else {
			for (var i = 0; i < s.length; i++) {
				if ((s.charAt(i) < '0') || (s.charAt(i) > '9')) {
					if (s.charAt(i) == '-') {
						if (i != 3)
						return (false);
					} else {
						if ((i != 0) && (i != 2)) {
							if (s.charAt(3) == '-') {
								if ((i != 5) || ((s.charAt(i) < 'A') || ((s.charAt(i) > 'Z') && ((s.charAt(i) < 'a') || (s.charAt(i) > 'z')))))
									return (false);
								} else {
									if ((i != 4) || ((s.charAt(i) < 'A') || ((s.charAt(i) > 'Z') && ((s.charAt(i) < 'a') || (s.charAt(i) > 'z')))))
										return (false);
							}							    
						} else {
							if ((s.charAt(i) < 'A') || ((s.charAt(i) > 'Z') && ((s.charAt(i) < 'a') || (s.charAt(i) > 'z'))))
							return (false);
						}
					}
				} else {
					if (s.charAt(3) == '-') {
						if ((i != 1) && (i != 4) && (i != 6))
							return (false);
						} else {
							 if ((i != 1) && (i != 3) && (i != 5))
								return (false);
						}	
					}
				}
				return (true);
		}
	}
}
	
function noNumbers(s) {
	if (s == "") {
		return (true);
	} else {
		if (regExpSupported()) {
			var re = /^[a-zA-Z]+[a-zA-Z\s]*$/;
			//var re = /D/;
			return re.test(s);
		} else {
			for (var i = 0; i < s.length; i++) {
				if ((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) return (false);
			}
			return (true);
		}
	}
}	

// Uses isValidRequired function to check for required fields and isValidEmail function to check
// for valid email address format and returns result in massage box.  Parameters passed are the form and
// the field name for email address fields

function validateNewsletterForm(myForm, emailFieldReq) {
	var isValid = true;
	if (isValidRequired(myForm) == false) {
		isValid = false;
		return isValid;
	}
	if (isValidEmail(myForm.elements[emailFieldReq].value) == false) {
		alert ('Please provide a valid email address.');
		myForm.elements[emailFieldReq].select();
		myForm.elements[emailFieldReq].focus();
		return false;
	}
	return isValid;
}

function clear_text(defaultValue, textField) {
	if (textField.value == defaultValue) {
		textField.value = "";
	} else {
		textField.value = defaultValue;
	}
}
/**
 * FlashObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 */
if(typeof com=="undefined"){var com=new Object();}
if(typeof com.deconcept=="undefined"){com.deconcept=new Object();}
if(typeof com.deconcept.util=="undefined"){com.deconcept.util=new Object();}
if(typeof com.deconcept.FlashObjectUtil=="undefined"){com.deconcept.FlashObjectUtil=new Object();}
com.deconcept.FlashObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
//this.instanceof=null;
if(!document.createElement||!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=com.deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
this.useExpressInstall=_7;
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new com.deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=com.deconcept.FlashObjectUtil.getPlayerVersion(this.getAttribute("version"),_7);
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}
};
com.deconcept.FlashObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},createParamTag:function(n,v){
var p=document.createElement("param");
p.setAttribute("name",n);
p.setAttribute("value",v);
return p;
},getVariablePairs:function(){
var _19=new Array();
var key;
var _1b=this.getVariables();
for(key in _1b){_19.push(key+"="+_1b[key]);}
return _19;
},getFlashHTML:function(){
var _1c="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");
}
_1c="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_1c+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1d=this.getParams();
_1d["instanceOf"]=null;
for(var key in _1d){_1c+=[key]+"=\""+_1d[key]+"\" ";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_1c+="flashvars=\""+_1f+"\"";}
_1c+="/>";
}else{
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_1c="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_1c+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _20=this.getParams();
for(var key in _20){_1c+="<param name=\""+key+"\" value=\""+_20[key]+"\" />";}
var _22=this.getVariablePairs().join("&");
if(_22.length>0){_1c+="<param name=\"flashvars\" value=\""+_22+"\" />";
}_1c+="</object>";}
return _1c;
},write:function(_23){
if(this.useExpressInstall){
var _24=new com.deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_24)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}
}else{this.setAttribute("doExpressInstall",false);}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _23=="string")?document.getElementById(_23):_23;
if(typeof n != 'undefined'){
	n.innerHTML=this.getFlashHTML();
}else{
	document.writeln(this.getFlashHTML());
}
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}}};


function tiiVBGetFlashVersionExists() {
	var result = true;
	try {
		var dontcare = tiiVBGetFlashVersion( 3 ); 
	} catch(e) { result = false }
	
	
	return result;
}

com.deconcept.FlashObjectUtil.getPlayerVersion=function(_26,_27){
	var _28 = new com.deconcept.PlayerVersion(0,0,0);
	if ( navigator.plugins && navigator.mimeTypes.length ){
		var x = navigator.plugins["Shockwave Flash"];
		if ( x && x.description ){
			_28 = new com.deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));
		}
	} else {
		try {
			if ( ! tiiVBGetFlashVersionExists() ) {
				
				
				var axo = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" );
				for ( var i = 3; axo != null; i++ ) {
					axo = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i );
					_28 = new com.deconcept.PlayerVersion( [ i, 0, 0 ] );
				}
			} else {
				
				
				var versionStr = "";
				for ( var i = 25; i > 0 ; i-- ) {
					var tempStr = tiiVBGetFlashVersion( i );
					if ( tempStr != "" ) {
						versionStr = tempStr;
						break;
					}
				}
				if ( versionStr != "" ) {
					
					var splits = versionStr.split(" ");
					var splits2 = splits[1].split(",");
					_28 = new com.deconcept.PlayerVersion( [ splits2[0], splits2[1], splits2[2] ] );
				}
			}
		} catch(e) {}
		if (_26&&_28.major>_26.major ){return _28;}
		if ( !_26 || ((_26.minor!=0||_26.rev!=0)&&_28.major==_26.major) || _28.major != 6 || _27){
			try {
				_28 = new com.deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			} catch(e) {}
		}
	}

	
	return _28;
};

com.deconcept.PlayerVersion=function(_2c){
this.major=parseInt(_2c[0])||0;
this.minor=parseInt(_2c[1])||0;
this.rev=parseInt(_2c[2])||0;
};
com.deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}
return true;
};

com.deconcept.util={getRequestParameter:function(_2e){
var q=document.location.search||document.location.hash;
if(q){var _30=q.indexOf(_2e+"=");
var _31=(q.indexOf("&",_30)>-1)?q.indexOf("&",_30):q.length;
if(q.length>1&&_30>-1){
return q.substring(q.indexOf("=",_30)+1,_31);}}return "";
},removeChildren:function(n){
while(n.hasChildNodes()){
n.removeChild(n.firstChild);}}};
if(Array.prototype.push==null){
Array.prototype.push=function(_33){
this[this.length]=_33;
return this.length;};}

var getQueryParamValue=com.deconcept.util.getRequestParameter;
var FlashObject=com.deconcept.FlashObject;
var PlayerVersion=com.deconcept.PlayerVersion;

function tiiGetFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
				var flashFullDescriptionArray = y.split('.');
				var flashPartialDescriptionArray = flashFullDescriptionArray[0].split(' ');
				flashversion = flashPartialDescriptionArray[flashPartialDescriptionArray.length - 1];
			}
		}
	} else {
		result = false;
		for(var i = 15; i >= 3 && result != true; i--){
			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
			flashversion = i;
		}
	}
	return flashversion;
}

function tiiDetectFlash(ver) {
	if (tiiGetFlashVersion() >= ver) {
		return true;
	} else {
		return false;
	}
}

 
/*-----------------------------------------------------------------------------*/
/* MB - 10/23/07 - Brightcove Wrapper / JavaScript support functions           */
/* Function: TiiBcLcDcTracker - Called by Brightcove Flash wrapper to notify   */ 
/* DoubleClick / DART that a Lightningcast ad was served                       */
/* Requirements: adsitename i.e. &adsitename=3745.mre needs to be passed to    */
/* the BC wrapper. If no adzone is specified the default value will be used    */
/*-----------------------------------------------------------------------------*/
function TiiBcLcDcTracker (omniAdSiteName,omniAdZone) {
	var defaultFlg = 'false';
	if (omniAdZone == 'default') {  
		omniAdZone = 'video_main_bc_lightningcast';
		defaultFlg = 'true';
	}    
	var bcLCDCTmpPixel = new Image();
	bcLCDCTmpPixel.src = 'http://ad.doubleclick.net/ad/'+omniAdSiteName+'/'+omniAdZone+';sz=1x1;ord='+Math.ceil(1+1E12*Math.random());
	return 'Tracking successful - adSiteName="'+omniAdSiteName+'" ,adZone="'+omniAdZone+ '" defaultFlg="'+defaultFlg+'"'; 
}    
	         
function TiiBrightcovePlayer() {
	this.cfg = new Array();
	this.flashUrl = "/web/tii/shared/swf/BrightcoveWrapper.swf";
	this.flashUrl = "/shared/static/swf/BrightcoveWrapper.swf";
	this.bgcolor = "#ffffff";

	// Default cfg
	this.cfg["objectId"] = "bcVideoPlayer";
	this.cfg["divId"] = "";
	this.cfg["testmode"] = "";
	this.cfg["autostart"] = false;
	this.cfg["lctracking"] = "";
	this.cfg["adsitename"] = "";
	this.cfg["lcadzone"] = ""; 
	this.setParam = TiiBcSetParam;
	this.write = TiiBcWrite;
}

function TiiBcSetParam(key, value) {
	this.cfg[key] = value;
}

function TiiBcWrite() {
	var fo = new FlashObject(this.flashUrl, this.cfg["objectId"], this.cfg["width"], this.cfg["height"], 8, this.bgcolor);
	
	fo.addParam("allowScriptAccess", "always");
	fo.addParam("menu", "false");
	fo.addParam("quality", "high");
	fo.addParam("bgcolor", this.bgcolor);
	fo.addParam("loop", "false");
	fo.addParam("wmode", "opaque");

	fo.addVariable("account", this.cfg["account"]);
	fo.addVariable("channel", this.cfg["siteId"]);
	fo.addVariable("prop16", this.cfg["channel"]);

	fo.addVariable("playerwidth", this.cfg["width"]);
	fo.addVariable("playerheight", this.cfg["height"]);
	fo.addVariable("playerid", this.cfg["playerId"]);
	fo.addVariable("videoid", this.cfg["videoId"]);
	fo.addVariable("lineupid", this.cfg["lineupId"]);
	fo.addVariable("autostart", this.cfg["autostart"]);
	
	fo.addVariable("lctracking", this.cfg["lctracking"]); // MB - added 10/23/07
	fo.addVariable("adsitename", this.cfg["adsitename"]); // MB - added 10/23/07
	fo.addVariable("lcadzone", this.cfg["lcadzone"]);     // MB - added 10/23/07
	
	fo.addVariable("objectid", this.cfg["objectId"]);	
	fo.addVariable("adserverurl", this.cfg["adServerUrl"]);
	if (this.cfg["testmode"] != "") {
		fo.addVariable("testmode", this.cfg["testmode"]);	
	}
	
	fo.altTxt = "";

	if (this.cfg["divId"] != "") {
		fo.write(this.cfg["divId"]);
	} else {
		fo.write();
	}
}

 var hasBrightcove = -1;		// will be reset to 1 if the page loads a BC player

// ### Array Helper Functions ###

function tiiArrayContains (array, value) {
	if (array != null) {
		var al = array.length;
		for (var i = 0; i < al; i++) {
			if (array[i] == value) return true;
		}
	}
	return false;
}

// ### Key=Value; Functions ###

function tiiHashKeys(string) {
	var keys = null;
	if (string != null) {
		var hash = string.split(';');
		var hl = hash.length - 1;
		if(hl > 0){
			keys = new Array();
			for(var i = 0; i < hl; i++){
				var data = hash[i].split('=');
				keys[i] = data[0].replace(' ', '');
			}
		}
	}
	return keys;
}

function tiiHashGet(string, key) {
	var value = null;
	if (string != null) {
		var keyStart = key + '=';
		var offset = string.indexOf(keyStart);
		if (offset != -1) {
			offset += keyStart.length;
			var end = string.indexOf(';', offset);
			if (end == -1) {
				end = string.length;
			}
			value = string.substring(offset, end);
		}
	}
	return value;
}

function tiiHashSet(string, key, value) {
	var string = tiiHashDelete(string, key);
	var newValue = key + '=' + value + ';';
	if (string != null) newValue = newValue + string;
	return newValue;
}

function tiiHashDelete(string, key) {
	var oldValue = tiiHashGet(string, key);
	var newString = string;
	if (oldValue != null) {
		var search = key + '=';
		var start = string.indexOf(search);
		var offset = start + search.length;
		var end = string.indexOf(';', offset) + 1;
		if (end == -1) end = string.length;
		newString = string.slice(0,start) + string.slice(end,string.length);
		return newString;

	}
	return newString;
}

function tiiGetQueryParamValue(param) {
	var startIndex;
	var endIndex;
	var valueStart;

	var qs = document.location.search;
	var detectIndex = qs.indexOf( "?" + param + "=" );
	var detectIndex2 = qs.indexOf( "&" + param + "=" );
	var key = "&" + param + "=";
	var keylen = key.length;

	if (qs.length > 1) {
		if (detectIndex != -1) {
			startIndex = detectIndex;
		} else if (detectIndex2 != -1) {
			startIndex = detectIndex2;
		} else {
			return null;
		}

		valueStart = startIndex + keylen;

		if (qs.indexOf("&", valueStart) != -1) {
			endIndex = qs.indexOf("&", startIndex + 1)
		} else {
			endIndex = qs.length
		}

		return (qs.substring(qs.indexOf("=", startIndex) + 1, endIndex));
	}

	return null;
}

// ### Date/Time Functions ###

function tiiDateGetOffsetMinutes(minutes)	{ var today = new Date(); return today.getTime() + (60000) * minutes;}
function tiiDateGetOffsetHours(hours)		{ var today = new Date(); return today.getTime() + (3600000) * hours; }
function tiiDateGetOffsetDays(days)			{ var today = new Date(); return today.getTime() + (86400000) * days; }
function tiiDateGetOffsetWeeks(weeks)		{ var today = new Date(); return today.getTime() + (604800000) * weeks; }
function tiiDateGetOffsetMonths(months)		{ var today = new Date(); return today.getTime() + (259200000) * months; }
function tiiDateGetOffsetYears(years)		{ var today = new Date(); return today.getTime() + (31536000000) * years; }
// ### Core Cookie Functions ###

function tiiCookieExists(cookieName) {
	return tiiArrayContains(tiiCookieGet(), cookieName);
}

function tiiCookieGet(cookieName) {
	if (arguments.length == 0) {
		return tiiHashKeys(document.cookie);
	}

	var cookie = tiiHashGet(document.cookie, cookieName);
	if (cookie != null) cookie = unescape(cookie);
	return cookie;
}

function tiiCookieSet(cookieName, cookieValue, domain, path, expires, secure) {
	if (expires != null) {
		expire_date = new Date();
		expire_date.setTime(expires);
	}
	var curCookie = cookieName + '=' + escape(cookieValue)
		+ ((expires) ? '; expires=' + expire_date.toGMTString() : '')
		+ ((path) ? '; path=' + path : '')
		+ ((domain) ? '; domain=' + domain : '')
		+ ((secure) ? '; secure' : '');
	document.cookie = curCookie;
}

function tiiCookieSetUnescape(cookieName, cookieValue, domain, path, expires, secure) {
	if (expires != null) {
		expire_date = new Date();
		expire_date.setTime(expires);
	}
	var curCookie = cookieName + '=' + cookieValue
		+ ((expires) ? '; expires=' + expire_date.toGMTString() : '')
		+ ((path) ? '; path=' + path : '')
		+ ((domain) ? '; domain=' + domain : '')
		+ ((secure) ? '; secure' : '');
	document.cookie = curCookie;
}

function tiiCookieDelete(cookieName) {
	tiiCookieSet(cookieName, null, null, null, '', 0);
}

// ### Core Chip Functions ###
function tiiCookieChipGet(cookieName, chipName) {
	if (arguments.length == 1) {
		return tiiHashKeys(tiiCookieGet(cookieName));
	}
	return tiiHashGet(tiiCookieGet(cookieName), chipName);
}

function tiiCookieChipSet(cookieName, chipName, chipValue, domain, path, expire, secure) {
	var new_cookieValue = tiiHashSet(tiiCookieGet(cookieName), chipName, chipValue);
	tiiCookieSet(cookieName, new_cookieValue, domain, path, expire, secure);
}

function tiiCookieChipDelete(cookieName, chipName, domain, path, expire, secure) {
	var new_cookieValue = tiiHashDelete(tiiCookieGet(cookieName), chipName);
	if (new_cookieValue == null) new_cookieValue = '';
	tiiCookieSet(cookieName, new_cookieValue, domain, path, expire, secure);
}

// ### Permanent Cookie/Chip Functions ###
function tiiPermCookieChipGet(chipName) {
	return tiiCookieChipGet('tii_perm', chipName);
}

function tiiPermCookieChipSet(chipName, chipValue) {
	tiiCookieChipSet('tii_perm', chipName, chipValue, null, '/', tiiDateGetOffsetYears(2), 0);
}

function tiiPermCookieChipDelete(chipName) {
	tiiCookieChipDelete('tii_perm', chipName, null, '/', tiiDateGetOffsetYears(2), 0);
}

// ### Session Cookie/Chip Functions ###
function tiiSessCookieChipGet(chipName) {
	return tiiCookieChipGet('tii_sess', chipName);
}

function tiiSessCookieChipSet(chipName, chipValue) {
	tiiCookieChipSet('tii_sess', chipName, chipValue, null, '/', null, 0);
}

function tiiSessCookieChipDelete(chipName) {
	tiiCookieChipDelete('tii_sess', chipName, null, '/', null, 0);
}
function tiiQuigoSetEnabled(b) {
	_tiiQuigoEnabled = b;
}

function tiiQuigoIsEnabled() {
	if (typeof(_tiiQuigoEnabled) == "boolean") {
		return _tiiQuigoEnabled;
	}
	return true;
}

function tiiQuigoWriteAd(pid, placementId, zw, zh, ps) {
	if (tiiQuigoIsEnabled()) {
		qas_writeAd(placementId, pid, ps, zw, zh, 'ads.adsonar.com');
	}
}


function tii_callFunctionOnWindowLoad (functionToCall)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener ('load', functionToCall, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener ('load', functionToCall, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent ('onload', functionToCall);
  }
  else
  {
    var oldFunctionToCall = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = functionToCall;
    }
    else
    {
      window.onload = function ()
      {
        oldFunctionToCall ();
        functionToCall ();
      };
    }
  }
}


function tii_callFunctionOnElementLoad (targetId, functionToCall)
{
	var myArguments = arguments;
	tii_callFunctionOnWindowLoad (function ()
		{
			window.loaded = true;
		});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded)
	{
		var pollingInterval = setInterval (function ()
			{
				if (window.loaded)
				{
					clearInterval (pollingInterval);
				}
				targetElement = document.getElementById (targetId);
				if (targetElement != null)
				{
					clearInterval (pollingInterval);
					var argumentsTemp = new Array ();
					var argumentsTempLength = myArguments.length - 2;
					for (var i = 0; i < argumentsTempLength; i++)
					{
						argumentsTemp [i] = myArguments [i + 2];
					}		
					functionToCall.apply (this, argumentsTemp);
				}
			}, 10);
	}
}


function tii_addEventHandlerOnElementLoad (targetId, eventType, functionToCall, bubbleEventUpDOMTree)
{
	tii_callFunctionOnWindowLoad (function ()
		{
			window.loaded = true;
		});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded)
	{
		var pollingInterval = setInterval (function ()
			{
				if (window.loaded)
				{
					clearInterval (pollingInterval);
				}
				targetElement = document.getElementById (targetId);
				if (targetElement != null)
				{
					clearInterval (pollingInterval);
					tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree);
				}
			}, 10);
	}
}


function tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree)
{
  if (!targetElement)
  {
	  window.status = 'Warning: Tried to attach event to null object';
	  return false;
  }
  if (typeof targetElement.addEventListener != 'undefined')
  {
    targetElement.addEventListener (eventType, functionToCall, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.attachEvent != 'undefined')
  {
    targetElement.attachEvent ('on' + eventType, functionToCall);
  }
  else
  {
    eventType = 'on' + eventType;
    if (typeof targetElement [eventType] == 'function')
    {
      var oldListener = targetElement [eventType];
      targetElement [eventType] = function ()
      {
        oldListener ();
        return functionToCall ();
      }
    }
    else
    {
      targetElement [eventType] = functionToCall;
    }
  }

  return true;
}



function tii_removeEventHandler (targetElement, eventType, functionToRemove, bubbleEventUpDOMTree)
{
  if (typeof targetElement.removeEventListener != "undefined")
  {
    targetElement.removeEventListener (eventType, functionToRemove, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.detachEvent != "undefined")
  {
    targetElement.detachEvent ("on" + eventType, functionToRemove);
  }
  else
  {
    targetElement ["on" + eventType] = null;
  }
  
  return true;
}



function getDateCurrent () {
	var today = new Date()
	var monthName_List = new Date()
	var arrayMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

	monthNumber = (today.getMonth());
	monthName = arrayMonthNames[monthNumber];

	dayNumber=today.getDate();
	if(dayNumber < 10){
		dayNumber="0" + dayNumber;
	}
	var yearNumber = today.getYear();
	if(yearNumber < 1000) {
		yearNumber+=1900;
	}
	document.write(monthName + " " + dayNumber + ", " + yearNumber);
}










var macTest=(navigator.userAgent.toLowerCase().indexOf("macintosh") >= 0);

function IMArticle() {
	
	if (isInAolClient()) {
		document.location.href = "aol://9293::Here's something that may interest you from People.com: <a href='" + document.location.href + "'>" + document.location.href + "</a>";
	} else {
		document.location.href = "aim:goim?message=Here's+something+that+may+interest+you+from+People.com:+" + document.location.href;
	}
	
	return false;
}


function showCenteredPopup(name, url, features, width, height) {
	
	var top = (screen.height / 2) - height / 2;
	var left = (screen.width / 2) - width / 2;

	if (features == null || features == '') {
		features =" scrollbars=yes,toolbar=no,menubar=no,status=no,location=no";
	}

	window.open(url, name, features + ",top=" + top + ",left=" + left + ",width=" + width + ",height=" + height);

}
// Transforms the url for quiz pages to return a link to the first page of the quiz rather than an internal page
function transformURL(pageURL) {
	var tempURL = "";
	var splitURL = pageURL.split(",");
	// Split the url to pull the oid out
	var oid = splitURL[2];
	// Split the oid into its components of (package_id quiz_id question_id score_id)
	tempOid = oid.split("_");
	
	// Check if the third position is a question_id or score_id
	if (tempOid[2] != "") {
		if (tempOid[2].length > 3) {
			// Its a package so this is a question_id
			var idThree = "articleId";
		} else {
			// Its a regular article so this is a score_id
			var idThree =  "scoreId";
		}
	} else {
		var idThree =  "";
	}
	if (tempOid[3] != "") {
		// Its a package so this is a question_id
		var idFour = "scoreId";
	} else {
		var idFour =  "";
	}
	
	// If a score is present then we are inside the quiz and must pull out the id for the initial page
	// otherwise we can return the original url becuase it is the first page of the quiz.
	if (idThree == "scoreId" || idFour == "scoreId") {
		if (idThree == "scoreId") {
			tempURL = splitURL[0] + "," + splitURL[1] + "," + tempOid[0] + "," + splitURL[3];
		} else {
			tempURL = splitURL[0] + "," + splitURL[1] + "," + tempOid[0] + "_" + tempOid[1] + "," + splitURL[3];
		}
	} else {
		tempURL = pageURL
	}
	
	return tempURL;
}

function popEmailWin(pageURL,pageTitle) {
    if (!pageURL) { pageURL = document.URL; }

	if (pageURL.substring(pageURL.length-1)=="#") {
		pageURL = pageURL.substring(0, pageURL.length-1);
	}
	//Check and see if this is a quiz to get the proper page url
	if (pageURL.match('/quizzes/')) {
		pageURL  = transformURL(pageURL);
	}
	
	if (!pageTitle) { pageTitle = self.document.title; }
	if (pageTitle.indexOf('|') > 0) {
		pageTitle = pageTitle.substring(0, pageTitle.indexOf('|'));
	}
	
    var formURL   = "http://cgi.pathfinder.com/cgi-bin/mail/mailurl2friend.cgi?path=/people/emailfriend&url="  + pageURL + "&group=people&title=" + escape(pageTitle); 
	showCenteredPopup('emailpop', formURL, 'scrollbars=1', 460, 450);
    
	return false;
}

function popMediaPlayerWin(media_type, pageURL) {

	if (media_type == 'video') {
		var pageTitle = 'PeopleVideo';
	} else if (media_type == 'audio') {
		var pageTitle = 'PeopleVideo';
	}
	
	showCenteredPopup(pageTitle, pageURL, 'scrollbars=no, status=no', '735', '467');
}


function drawPuzzler(codeBase,file){
	var html='<applet code="AcrossLite" archive="alite.zip" codebase="'+codeBase+'" width="600" height="386">';
	html+='<PARAM NAME="CABBASE" VALUE="alite.cab">';
	html+='<PARAM NAME="File" VALUE="'+file+'">';
	html+='Your web browser does not support Java applets or Java is not enabled in web browser preferences.';
	html+='</applet>';
	document.write(html);
}



function rollverGrid() {
	rolloverGrid();
};

function rolloverGrid(){
	if ( document.getElementById("rolloverGrid") != null ) {
		this.container=document.getElementById("rolloverGrid");
		this.buttons=this.container.getElementsByTagName("a");
		for(var x=0;x<this.buttons.length;x++){
			this.buttons[x].onmouseover=button_select;
			this.buttons[x].onmouseout=button_deselect;
			if ( this.buttons[x].childNodes[0] != null ) {
				this.buttons[x].altText=this.buttons[x].childNodes[0].alt;
				var pinkDiv = document.createElement("div");
				pinkDiv.className = "altText";
				pinkDiv.innerHTML = this.buttons[x].altText+" <img src='http://img2.timeinc.net/people/i/_site/arrowMoreWhite.gif' width='4' height='11' />";
				this.buttons[x].appendChild(pinkDiv);
			}
		}
	}
}
function button_select(){
	var buttons = document.getElementById("rolloverGrid").getElementsByTagName("a")
	for(i=0;i<buttons.length;i++){
		buttons[i].parentNode.className=""
	}
	this.parentNode.className="on";
	return false;
}
function button_deselect(){
	this.parentNode.className="";
	return false;
}


function getRandomNumber() {
  return ( Math.floor ( Math.random ( ) * 100000 + 1 ) );
}


function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}


function iedetect(){		
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	if (version>=5.0) 
	return true;
}


function buildBrightcovePlayer (videoID) {

	var config = new Array();
	config["videoId"] = videoID;
	config["videoRef"] = null;
	config["lineupId"] = null;
	config["playerTag"] = null;
	config["autoStart"] = false;
	config["preloadBackColor"] = "#FFFFFF";
	config["width"] = 300;
	config["height"] = 320;
	if(brightcovePlayerID == ""){
		config["playerId"] = 416421276;
	}else{
		config["playerId"] = brightcovePlayerID;
	}
	createExperience(config, 8);
	
}

//set value of source a xid for ad tag
source = ""
if (tiiGetQueryParamValue("xid")!= null)
{
	source = tiiGetQueryParamValue("xid");
}


// Adding this to the site's central JavaScript library would allow us to disable Quigo across the site without flushing the entire site
tiiQuigoSetEnabled(true);



var adConfig = new TiiAdConfig("3475.peo");
adConfig.setCmSitename("cm.peo");

