var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days
var swfversion = deconcept.SWFObjectUtil.getPlayerVersion();
var noflash = deconcept.util.getRequestParameter("noflash");
var printerfriendly = deconcept.util.getRequestParameter("printerfriendly");
var flash = deconcept.util.getRequestParameter("flash");
if (flash=='yes') eraseCookie('flash');
if (flash=='no'||readCookie('flash')=='no') {createCookie('flash','no',1); noflash=1;}
var minFlashVersion = 8;

if (document.getElementById && (swfversion['major'] >= minFlashVersion) && noflash=='' && printerfriendly=='') {
	document.writeln("<STYLE>.divFlash{display:block;}.divHtml{display:none;}</"+"STYLE>");
}

window.onload = function(){init();}

var flashVer = swfversion['major'];
//var hasFlash = detectFlash(flashVer, 7);

var stats = "browser_name="+ navigator.appName +"&width="+screen.width+"&height="+screen.height+"&flash_version="+flashVer;

function init() {
}

var swfId = 0;

function drawFlash(file, width, height, vars, elements, param) {
	//alert("file["+file+"]\nwidth["+width+"]\nheight["+height+"]\nvars["+vars+"]\nelements["+elements+"]\nparam["+param+"]")

	var varsArray     = new Array();
	var elementsArray = new Array();
	var paramArray    = new Array();

	if (vars)     varsArray     = vars.split("&");
	if (elements) elementsArray = elements.split("&");
	if (param)    paramArray    = param.split("&");

	swfId++;
	var so = new SWFObject(file, "swf"+swfId, width, height, minFlashVersion);
	so.addParam('allowScriptAccess', 'sameDomain');
	so.addParam('wmode', 'transparent');
	so.addParam('scale', 'noscale');
	so.addParam("bgcolor", '#FFFFFF');

	for (var i=0; i<elementsArray.length; i++) {
		tmp = elementsArray[i].split("=");
		if (tmp[1] && tmp[0].toLowerCase()!="id") so.addParam(tmp[0],tmp[1]);
	}
	/*
	for (var i=0; i<paramArray.length; i++) {
		tmp = paramArray[i].split("=");
		if (tmp[1]) so.addVariable(tmp[0],tmp[1]);
	}
	*/
	for (var i=0; i<varsArray.length; i++) {
		tmp = varsArray[i].split("=");
		if (tmp[1]) so.addVariable(tmp[0],tmp[1]);
	}
	so.write("");
}

function popup(pageToLoad, winName, width, height) {

	windowName = (Math.round((Math.random()*99999)+1));
	xposition=0; yposition=0;
	isOpen = false;
	redirectPage = pageToLoad;
	
	if (parseInt(navigator.appVersion) >= 4){
		xposition = (screen.width - width) / 2;
		yposition = 0;//(screen.height - height) / 2;
	}
	
	args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=0," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=0,screeny=0,left=0,top=0";           
	popup[windowName] = window.open(pageToLoad,"popup_win",args);
	
	//call window that checks if the pop up actually opened.
	callWindow()
	
}
	
function callWindow() {
	//wait 2 seconds and call a function in the pop up window.
	setTimeout('theCaller()', 2000);
	//wait 4 seconds and call a local function that handles logic if pop up doesn't exist.
	setTimeout('windowCheck()', 3000);
}

function theCaller() {
	try {
		popup[windowName].checkIfOpen()
	} 
	catch(errorObject) {
		windowCheck()
	}
}

function windowCheck() {
 	if (isOpen) {
 		//window.location = 'http://elrond.innovasium.com/kylemore/forefront/thankyou.cfm';
	} 
	else {
		//nothing opened, they must have a pop up stopeper so lets redirect them to a warning page or the page that was suppose to open in the pop up.
		window.location = '/kylemore/forefront/nopopup.cfm';
	}
}

function openFlashSite() {
//add width detection to this function
	//alert('forefront.cfm?'+stats);
 	popup('forefront.cfm?'+stats,'EFC', screen.width-10, screen.height-70);
	//window.location = 'forefront.cfm?'+stats;
}

function openFlashPage(directory, id) {
//add width detection to this function
	//Salert('forefront.cfm?'+id);
 	//popup('forefront/forefront.cfm?topic_'+id+'&'+stats,'EFC','850','615');
	window.location = 'forefront/forefront.cfm?topic_'+id+'&'+stats;
}

/* ==================== */

function createCookie(name,value,days) {
	var expires="", date=new Date();
	if (days) {
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires="; expires="+date.toGMTString();
	}
	document.cookie=name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ=name+"=", ca=document.cookie.split(';'), c="";
	for(var i=0;i < ca.length;i++) {
		c = ca[i];
		while (c.charAt(0)==' ') c=c.substring(1,c.length);
		if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {createCookie(name,"",-1);}