// NOTE
// DON'T edit any of this HitBox stuff!

//<!--WEBSIDESTORY CODE HBX2.0 (Universal)-->
//<!--COPYRIGHT 1997-2005 WEBSIDESTORY,INC. ALL RIGHTS RESERVED. U.S.PATENT No. 6,393,479B1. MORE INFO:http://websidestory.com/privacy-->
var _hbEC = 0;
var _hbE = [];
function _hbEvent(a,b)
{
	b=_hbE[_hbEC++] = {};
	b._N=a;
	b._C=0;
	return b;
}

var hbx=_hbEvent("pv");
hbx.vpc="HBX0200u";
hbx.gn="ehg-space.hitbox.com";

//BEGIN EDITABLE SECTION
//CONFIGURATION VARIABLES
hbx.acct="DM540820MHAD";//ACCOUNT NUMBER(S)
hbx.pn="PUT+PAGE+NAME+HERE";//PAGE NAME(S)
hbx.mlc="CONTENT+CATEGORY";//MULTI-LEVEL CONTENT CATEGORY
hbx.pndef="title";//DEFAULT PAGE NAME
hbx.ctdef="full";//DEFAULT CONTENT CATEGORY

//OPTIONAL PAGE VARIABLES
//ACTION SETTINGS
hbx.fv="";//FORM VALIDATION MINIMUM ELEMENTS OR SUBMIT FUNCTION NAME
hbx.lt="none";//LINK TRACKING
hbx.dlf="n";//DOWNLOAD FILTER
hbx.dft="n";//DOWNLOAD FILE NAMING
hbx.elf="n";//EXIT LINK FILTER

//SEGMENTS AND FUNNELS
hbx.seg="";//VISITOR SEGMENTATION
hbx.fnl="";//FUNNELS

//CAMPAIGNS
hbx.cmp="";//CAMPAIGN ID
hbx.cmpn="";//CAMPAIGN ID IN QUERY
hbx.dcmp="";//DYNAMIC CAMPAIGN ID
hbx.dcmpn="";//DYNAMIC CAMPAIGN ID IN QUERY
hbx.dcmpe="";//DYNAMIC CAMPAIGN EXPIRATION
hbx.dcmpre="";//DYNAMIC CAMPAIGN RESPONSE EXPIRATION
hbx.hra="";//RESPONSE ATTRIBUTE
hbx.hqsr="";//RESPONSE ATTRIBUTE IN REFERRAL QUERY
hbx.hqsp="";//RESPONSE ATTRIBUTE IN QUERY
hbx.hlt="";//LEAD TRACKING
hbx.hla="";//LEAD ATTRIBUTE
hbx.gp="";//CAMPAIGN GOAL
hbx.gpn="";//CAMPAIGN GOAL IN QUERY
hbx.hcn="";//CONVERSION ATTRIBUTE
hbx.hcv="";//CONVERSION VALUE
hbx.cp="null";//LEGACY CAMPAIGN
hbx.cpd="";//CAMPAIGN DOMAIN

//CUSTOM VARIABLES
hbx.ci="";//CUSTOMER ID
hbx.hc1="";//CUSTOM 1
hbx.hc2="";//CUSTOM 2
hbx.hc3="";//CUSTOM 3
hbx.hc4="";//CUSTOM 4
hbx.hrf="";//CUSTOM REFERRER
hbx.pec="";//ERROR CODES


var GEEKLOGIK={};

(function(){
	GEEKLOGIK.index = null;
	GEEKLOGIK.advert = {};
	GEEKLOGIK.consts =
		{
			// platform constants
			kUnknownPlatform			: 0,
			kWebApplication				: 1,
			kDashboardWidget			: 2,
			kGoogleGadget				: 3,
			kYahooWidget				: 4,
			kBlackBerryApp				: 5,
			kVistaGadget				: 6,
			kAppleMobile				: 7,
			
			// version constants
			kUnknownVersionString		: "0.0.0",
			
			// Tracking Action Contants 
			kTrack_UnspecifiedError		: 0, // use this if you get some unknown error, and pass in any error info in the 'data'
			kTrack_Initialized			: 1,
			kTrack_Calculation			: 2,
			kTrack_marketingLinkClicked	: 3, // make sure to pass in the URL of the clicked link as the'data'
			kTrack_adDisplayed			: 4 // make sure to pass in the URL of the advertisement link as the'data'			
		};
		
	
	GEEKLOGIK.trackAction= function (inParams) 
		{
			var platform= GEEKLOGIK.platform	|| this.consts.kUnknownPlatform;
			var version	= GEEKLOGIK.version		|| this.consts.kUnknownVersionString;
			var action	= (inParams && inParams.action)		|| this.consts.kTrack_UnspecifiedError;
			var isError	= (inParams && inParams.isError)	|| false;
			var data	= (inParams && inParams.data)		|| "";
			
			var kUnknownPlatformFolder			= "unknown";
			var kWebApplicationFolder			= "web";
			var kDashboardWidgetFolder			= "dashboard";
			var kGoogleGadgetFolder				= "google";
			var kYahooWidgetFolder				= "yahoo";
			var kBlackBerryAppFolder			= "blackberry";
			var kVistaGadgetFolder				= "vista";
			var kAppleMobileFolder				= "appleMobile";
		
			var kTrack_ERRORS					= "ERROR";
			var kTrack_InitializedS				= "initialized";
			var kTrack_CalculationS				= "calculationRequest";
			var kTrack_marketingLinkClickedS	= "marketingLink"; // make sure to pass in the URL of the clicked link as the'data'
			var kTrack_adDisplayedS				= "adDisplayed"; // make sure to pass in the URL of the advertisement (if possible) link as the'data'
		
			var contentCategoryName		= "/applets/";
			var pageName = (version.length > 0) ? version : this.consts.kUnknownVersionString; // default this to the version number
			
			var kGeekLogikAppletName		= "GeekLogik/";

			contentCategoryName += kGeekLogikAppletName;
			
			// Add the request
			switch (action)
			{
				case this.consts.kTrack_Initialized:
					contentCategoryName += kTrack_InitializedS;
					break;
				case this.consts.kTrack_Calculation:
					contentCategoryName += kTrack_CalculationS;
					break;
				case this.consts.kTrack_UnspecifiedError:
					contentCategoryName += kTrack_ERRORS;
					break;
				case this.consts.kTrack_adDisplayed:
					contentCategoryName += kTrack_adDisplayedS;
					break;
				case this.consts.kTrack_marketingLinkClicked:
					contentCategoryName += kTrack_marketingLinkClickedS;
					if (data.length > 0) {
						_hbLink(data); // also try to use the _hbLink
					}
					break;
				default:		
					contentCategoryName += kTrack_ERRORS;
					break;
			}
	
			contentCategoryName += "/";
	
			// note that these are ordered for speed
			switch (platform)
			{
				case this.consts.kDashboardWidget:
					contentCategoryName += kDashboardWidgetFolder;
					break;
				case this.consts.kGoogleGadget:
					contentCategoryName += kGoogleGadgetFolder;
					break;
				case this.consts.kYahooWidget:
					contentCategoryName += kYahooWidgetFolder;
					break;
				case this.consts.kWebApplication:
					contentCategoryName += kWebApplicationFolder;
					break;
				case this.consts.kBlackBerryApp:
					contentCategoryName += kBlackBerryAppFolder;
					break;
				case this.consts.kVistaGadget:
					contentCategoryName += kVistaGadgetFolder;
					break;
				case this.consts.kAppleMobile:
					contentCategoryName += kAppleMobileFolder;
					break;
				default: //case this.consts.kUnknownPlatform:
					contentCategoryName += kUnknownPlatformFolder;
					break;
			}
			
			// If we're tracking an error, append that here
			// NOTE: for errors, the pageName actually gets set to the data and we append
			// the request type to the contentCategoryName so that we can more easily track
			if (isError === true) {
				contentCategoryName += (version.length > 0) ? ('/' + version) : this.consts.kUnknownVersionString;
				if (data.length > 0) {
					pageName = data;
				}
			}
			
			// we want to track the actual link clicked on for marketing and ticker, so fix those here
			if (action === this.consts.kTrack_marketingLinkClicked)
			{
				contentCategoryName += (version.length > 0) ? ('/' + version) : this.consts.kUnknownVersionString;
				if (data.length > 0) {
					pageName = data;
				}
			}
			
			if (_hbPageView)
			{
				_hbPageView(pageName, contentCategoryName);
			}
		};
		
	GEEKLOGIK.onCalculate = function (){
		var inp={};
		var tmp = 0;
		var answer =0;
		
		for (i=0; i < (this.params.length); i++){
			tmp = this.params[i];
			inp[tmp] = parseFloat($F(tmp));
		} 
		answer = this.equation(inp);
		this.handlers.displayAnswer(answer);
	};			
	
	GEEKLOGIK.addHandlers = function(){
		var inp={};
		var tmp = 0;
		var answer =0;
		//alert("start");
		if(this.params){
			//alert("start for");
			for (var i=0; i < (this.params.length); i++){
				tmp = $(this.params[i]);
				//alert(tmp.id);
				if( tmp.readAttribute("type") == 'text'){
					Event.observe(tmp,'keypress',GEEKLOGIK.handlers.keyPress);
				}
			} 
		//	alert("end for");
		}
		//alert("end");
		
	};
	GEEKLOGIK.removeHandlers = function(){
		var inp={};
		var tmp = 0;
		var answer =0;
		if(this.params){
			for (var i=0; i < (this.params.length); i++){
				tmp = $(this.params[i]);
				if( tmp.readAttribute("type") == 'text'){
					Event.stopObserving(tmp,'keypress',GEEKLOGIK.handlers.keyPress);
				}
			} 
		}
	};
	GEEKLOGIK.handlers = {};
		(function(){
			//Tooltip Functions  
			
			var gCurrentVar=0;
			var kcycleWidth = 310;
			var gMoreInfo=false;
			var serverUrl="http://www.space.com/snserver/geeklogik/common/";
			GEEKLOGIK.handlers.reset = function(){
				gCurrentVar=0;
					$("GLSubmitButton").setStyle({display:"block"});
				$("GLResubmitButton").setStyle({display:"none"});
			}
			
 			GEEKLOGIK.handlers.onSubmit = function(){
					//showAds();
				$("GLSubmitButton").setStyle({display:"none"});
				$("GLResubmitButton").setStyle({display:"block"});
				if(GEEKLOGIK.advert){
					GEEKLOGIK.advert.showAds();
 				}
 			}

 			GEEKLOGIK.handlers.onResubmit = function(){
				if(GEEKLOGIK.advert){
					GEEKLOGIK.advert.showAds();
 				}
			}
			GEEKLOGIK.handlers.showAds =function (){
				if(GEEKLOGIK.advert){
					if (
						(GEEKLOGIK.advert.eventsFired >= GEEKLOGIK.advert.getStartOnFrame()) &&
						( (GEEKLOGIK.advert.getMaxShows() == 0) || (GEEKLOGIK.advert.getMaxShows() > GEEKLOGIK.advert.adsShown) ) &&
						( ((GEEKLOGIK.advert.eventsFired - GEEKLOGIK.advert.getStartOnFrame()) % GEEKLOGIK.advert.getFrequency()) == 0 )
					)
					{
					
						//$("GLContent").setOpacity(0.0);
						GEEKLOGIK.trackAction({ action: GEEKLOGIK.consts.kTrack_adDisplayed, isError: false });

									
						GEEKLOGIK.advert.showAdvert();
						GEEKLOGIK.advert.adsShown += 1;
						GEEKLOGIK.advert.eventsFired += 1;
						
					}
					else{
						
						if(GEEKLOGIK.advert.adsShown < (GEEKLOGIK.advert.maxShows+1)){ 
							GEEKLOGIK.advert.eventsFired += 1;
						}
						GEEKLOGIK.advert.afterAdHide();
						
					}
				}
		
		}
			GEEKLOGIK.handlers.displayAnswer = function(answer){
				GEEKLOGIK.trackAction({ action: GEEKLOGIK.consts.kTrack_Calculation, isError: false });
				var ansElem = $("answer");
				var divAnsElem = $("ansDiv");
				
				
				if($("greater") || $("less")){
					if (answer>= 1){
						$("GLResult").innerHTML = $("greater").innerHTML;
					}
					else
					{
						$("GLResult").innerHTML = $("less").innerHTML;
					}
				}
				else
				{
					$("GLResult").innerHTML = answer.toFixed(2);
				}
				ansElem.setStyle({top: '15px'});
				divAnsElem.setStyle({display:'block'});
				Effect.Appear(ansElem, {duration:0.3 });
				new Effect.Move(ansElem,{x:0, y:-15});
				if($("stargateLogo")){
					$("stargateLogo").src = "http://www.space.com/snserver/geeklogik/common/images/stargate_logo_grad.jpg";
					
				}
				
				
			}
			function afterFadeAnswer(){
				
				var divAnsElem = $("ansDiv");
				
				if($("stargateLogo")){
					$("stargateLogo").src = "http://www.space.com/snserver/geeklogik/common/images/stargate_logo.jpg";
					
				}
				divAnsElem.setStyle({display:'none'});
			}	
			GEEKLOGIK.handlers.fadeAnswer=function(){
				
				var ansElem = $("answer");
				Effect.Fade(ansElem, {duration:0.3,  afterFinish:afterFadeAnswer});
				
			}		

			GEEKLOGIK.handlers.checkRange=function(id, min, max){
				var elem = $(id);
				value = elem.value;
	
				if(!value || value < min){
					elem.value= min;
				}
				if(value > max){
					elem.value= max;
				}
				this.inputInFocus=false;
			}
			this.alltrim = function(str) {
                return str.replace(/^\s+|\s+$/g, '');
            }
			this.validateDecimal = function(str) {
    			str = alltrim(str);
    			return /^\$?[1-9][0-9]{0,2}([, ]?[0-9]{3})*(\.[0-9]{2})?$/.test(str);
			}
			this.validateInteger = function(str) {
    			str = alltrim(str);
    			return /^\[+-]?[1-9][0-9]{0,2}([, ]?[0-9]{0,3})*$/.test(str);
			}
			this.displayError = function(elem){
				
				var errorElem = $("errorDiv");
				var header = errorElem.select('.errorHeader')[0];
				var body = errorElem.select('.errorBody')[0];
				header.update("Invalid Number Entered");
				body.update("Please enter a number using only digits from 0 to 9");
				errorElem.setStyle({"display": "block"});
			}
			
				GEEKLOGIK.handlers.keyPress=function(evt) {    
				 // for cross-browser compatibility     
				if(evt){
					var charCode = evt.which || evt.keyCode;     
					if (charCode > 31 && (charCode < 48 || charCode > 57)) {      
						Event.stop(evt);
						return false;     
						
					}
					else{
						return true; 
					}
				}
			};
			
		})();	

})();





