
var submitted = 0;
/*
if (document.images) { // preload global images, like top nav background image
	img000 = new Image();
   	img000.src = "/images/navPulldownBKGD_03.gif";
   	img001 = new Image();
   	img001.src = "/images/navTopTierBKGD.gif";
   	img002 = new Image();
   	img002.src = "/images/logo_genius3.gif";
}
*/
function OneClick() {
	submitted++;
	if (submitted < 2) {
	   DisplayDiv('divMessagePopUp','120px','200px');
	   setTimeout("reset_count()", 3*1000 );   
   }
}

function VidClick(vid) {
	submitted++;
	if (submitted < 2) {
	   DisplayDiv('divVideoPop_Up_' + vid,'120px','200px');
	   setTimeout("reset_count()", 3*1000 );   
	}
}


function reset_count() {
	submitted = 0;
	return;
}

function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)	{
		var 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;
}

// call onLoad() on all pages
function eraseCookie(name){
	createCookie(name,"",-1);
}

// called in the trial sign up pages including specials, promos, etc
// ONLY for signup page
function passThroughQueryArgs() {
        if ( document.location.search.length > 1) {
            urlTail = document.location.search;  
            createCookie( 'mgCameFromAd', urlTail, 120);
        } else if ( readCookie('mgCameFromAd') ) {
            urlTail = readCookie('mgCameFromAd');
        } else {
            urlTail = "";
        }
        
        if (urlTail.charAt(0) != "?") {
           eraseCookie('mgCameFromAd');
           urlTail = "";
        }
		 
		// the || '' protects against encoding a 'null' value
		var mgReferrerURL = encodeURIComponent( readCookie( 'mgReferrerURL' ) || '');
		var mgLandingURL = encodeURIComponent( readCookie( 'mgLandingURL' ) || '');
		var leadSource = readCookie( 'mgLeadsource' ) || '';
		if( leadSource!='' ) leadSource += '&';
		leadSource += '__utmz=' + readCookie( '__utmz') || ''; // the urchin tracking main cookie
		var mgLeadsource = encodeURIComponent( leadSource );
		var newTail = "mgReferrerURL="+mgReferrerURL + 
					  "&mgLandingURL="+mgLandingURL +
					  "&mgLeadsource="+mgLeadsource;
		if( urlTail=='' ){
			urlTail = "?" + newTail;
		} else {
			urlTail = urlTail + "&" + newTail;
		}
        theSuFrame = top.frames['mgRegister'];
        theSuFrame.location.href = "http://www.salesgenius.com/beta/signup.php" + urlTail;
        return true;
    }


function setOriginCookie()  {
	if ( document.location.search != "")    {
    	var urlTail = document.location.search;
    	createCookie( 'mgCameFromAd', urlTail, 120);
    }
	
	// detect whether this is the landing page (ie domain is different from current)
	// and if it IS a landing page, then record the referer and the landing and if
	// there is an incoming GET parameter named 'mgFrom' record that also
	// These are picked up by app/beta/signup.php => passThroughQueryArgs()
	var referrer = document.referrer;
	var location = window.location.href;
	var domain = window.location.protocol + '//' + window.location.host;
	var lead = document.location.search;
	/* 
	// activate this code if you JUST want the parameter value for parameter "leadsource" to be recorded
	// otherwise, the whole urlTail will be recorded
	var re = /[&]*leadsource=([^&]+)/;
	var myArray = new Array();
	myArray = re.exec(lead);
	if( myArray && myArray.length==2 )
		lead = myArray[1];
	else
		lead = '';
	*/
	// The check now is:
	// record referer & landingPage if this is the first time they enter the site
	// if the enter again LATER, usually leave the pre-existing cookies except if 
	// they come in via another email campaign, etc. then use the latest campaignID
	if( referrer.indexOf(domain)!=0 && (readCookie('mgLandingURL')==null || lead!='') ) {
		//alert( "You are just entering the site\nreferer=" + referrer + "\nlanding="+location + "\nleadsource=" + lead);
		//session cookies only
		createCookie( 'mgReferrerURL', referrer );
		createCookie( 'mgLandingURL', location );
		createCookie( 'mgLeadsource', lead );
	}
}

// fixed size window opener (SalesGenius page)
function newWindow(filename){
	window.open(filename,'ViewLarger','width=580,height=450', 'scrollbars=0, resizable=1, titlebar=0');
}

// customizable size window opener - optional settings for chrome
function myNewWin(filename, width, height){
  	// re-size window for creative offer
  	// total avail window size is *outer parameter* -> subtract title bar and chrome sizes to find *viewable area* of the window 
  	//var titleBar = 38;
  	//var sideChrome = 7;
  	var img_width = width; // enter the image width
  	var img_height = height;  // enter the image height
  	var window_width = img_width; // + sideChrome;
  	var window_height = img_height; // + titleBar;
  
  	// positioning
  	//moveTo(pos_left, pos_top); // current window
  	var top = 5; // position window with ScreenX, Y (Nav only); top, left (IE only)
  	var left = 5;
  
  	// correct for browser/SP2 cut-off
  	//var isMSIE = window.navigator.userAgent.indexOf("MSIE");
  	//if( isMSIE  && window.navigator.userAgent.indexOf("SV1") > isMSIE ){
	//	window_height += 30; }
	window.open(filename,'myWindow','width=' + window_width + ',' + 'height=' + window_height + ',' + 'scrollbars=1, resizable=1, titlebar=0, location=0, copyhistory=1, screenX='+ top + ', screenY=' + left + ', top='+ top + ', left=' + left);
}

// customizable size window opener - optional settings for chrome
function winThreeQuarters(filename, scrolls, loc, titleb){  
  	var window_width = screen.width*.75;
  	var window_height = screen.height*.75;  

  	// positioning
  	var top = 10; // position window with ScreenX, Y (Nav only); top, left (IE only)
  	var left = 10;
  
	window.open(filename,'myWindow2','width=' + window_width + ',' + 'height=' + window_height + ',' + 'scrollbars=' + scrolls + ', resizable=1, titlebar=' + titleb + ', location=' + loc + ', copyhistory=1, screenX='+ top + ', screenY=' + left + ', top='+ top + ', left=' + left);
}

// begin script for demo windows	
// launches window as specific size with/out toolbars, etc.

//function openDemoWindow() {
//	newWindow=window.open('/media/launch_demo.html' , 'newwindow' , 'toolbar=0, menubar=0, locationbar=0, personalbar=0, statusbar=0, scrollbars=0, resizable=1, width=950, height=630');
//}

// demo launch - all demos, takes type
function openDemoWindow(type) {
	switch (type){
	case "interactive":
		newWindow=window.open('/media/launch_interactive.html' , 'newwindow' , 'toolbar=0, menubar=0, locationbar=0, personalbar=0, statusbar=0, scrollbars=0, resizable=1, width=980, height=600');
	break
	default: // no arg or other - launch salesGenius main demo
		newWindow=window.open('/media/launch_demo.html' , 'newwindow' , 'toolbar=0, menubar=0, locationbar=0, personalbar=0, statusbar=0, scrollbars=0, resizable=1, width=940, height=630');
	}	
}

function openNewWindow() { // legacy left for cache - 12/06
	openDemoWindow();
}
// end script for demo windows

// protect e-mail addresses from harvesting programs
function writeEmailLink( user, domain, optionalDisplayLink ){
	if( !optionalDisplayLink ) optionalDisplayLink = user + "&#64;" + domain;
	document.write( "<a href='mailto" + ":" + user + "%40" + domain + "'>" + optionalDisplayLink + "</a>" );
}

function switchagenda(navChoice){
	for (var i = 0;i < 6; i++){
		if (i != navChoice)	{
			if (document.getElementById('agenda-set-' + i))	{			
				document.getElementById('agenda-set-' + i).style.display = 'none';
				//document.getElementById(i + '-agenda-display').style.color = '#000000';
				document.getElementById('agenda-display-'+i).style.color = '#000000';
			}
		}
		if (i == navChoice)	{
			//document.getElementById(i + '-agenda-display').style.color = '#ffffff';
			document.getElementById('agenda-display-'+i ).style.color = '#ffffff';
			Effect.Appear(document.getElementById('agenda-set-' + i));
		}
	}
}

function switchArticleImage(dstloc,dstsrc){
	document.getElementById(dstloc).src = dstsrc;
return;
}

function switchArticleHeading(dstloc,dstcnt){
	document.getElementById(dstloc).innerHTML = dstcnt;
return;	
}

function setHightlightClass(dstloc,dstclass){
	document.getElementById(dstloc).setAttribute("class", dstclass);
	//document.getElementById(dstloc).class = dstclass;
return;	
}

function setHightlightStyle(dstloc){
	document.getElementById(dstloc).style.border='1px solid red';
	//document.getElementById(dstloc).class = dstclass;
return;	
}


function clearHightlightClass(dstloc,dstclass){
	document.getElementById(dstloc).setAttribute("class", dstclass);
	//document.getElementById(dstloc).class = dstclass;
return;	
}

function clearHightlightStyle(dstloc){
	document.getElementById(dstloc).style.border='1px solid black';
	//document.getElementById(dstloc).class = dstclass;
return;	
}


function addTheHomepagePlayer(thePlayerHeight,thePlayerWidth,theMediaURL,theMediaURLiPad,theMediaImage,theSourceDiv){
	if (thePlayerHeight == '') exit();
	if (thePlayerWidth == '') exit();
	if (theMediaURL == '') exit();
	if (theMediaURL !='') theMediaURL='http://web27.streamhoster.com/sellingpower/SALES20/'+theMediaURL;
	if (theMediaURLiPad !='') theMediaURLiPad='http://web27.streamhoster.com/sellingpower/SALES20/'+theMediaURLiPad;

	if (navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPhone/i) != null){
		if (theMediaURLiPad !=''){
			theMediaURL=theMediaURLiPad;
		} else {
			document.getElementById('container').innerHTML='<div style="position:relative;left:15px;top:30%;width:90%;">We apologize for the inconvenience, this video is currently not available for playback on the iPad/iPhone</div>';
			exit();
		}
	}

	
	document.getElementById(theSourceDiv).innerHTML='';
	document.getElementById('featured_videos_playback').style.display='block';
	document.getElementById('featured_videos_playback').innerHTML='<div id="container"></div>';
	document.getElementById('featured_videos_playback').style.height=thePlayerHeight+'px';
	document.getElementById('featured_videos_playback').style.width=thePlayerWidth+'px';

	if (jwplayer != null){
		jwplayer("container").remove();
		document.getElementById('container').style.height=thePlayerHeight+'px';
		document.getElementById('container').style.width=thePlayerWidth+'px';

	}

	jwplayer("container").setup({
	flashplayer:"http://public.streamhoster.com/Resources/Flash/JWFLVMediaPlayer/mediaplayer.swf",
	file:""+theMediaURL+"",
	image:""+theMediaImage+"",
	height:""+thePlayerHeight+"",
	width:""+thePlayerWidth+"",
	scaler:"scale",
	autostart:"true",
	stretching:"uniform",
	wmode:"opaque",
	controlbar:"bottom",
	players:[ 
		{type:"html5"},
		{type:"flash",src:"http://public.streamhoster.com/Resources/Flash/JWFLVMediaPlayer/mediaplayer.swf"}
	]
	});
	return;
}

