
var ctNameCb = '';
var vdPathCb = '';
function getPageContent(cName, source, videoPath)
{
	videoPath = (videoPath) ? videoPath : '';
	resetMenu()
	source.className = (videoPath != '') ? 'pmenu next active' : 'pmenu active';
	source.blur();
	var action = '/content/' + cName + '.htm';
	AjaxRequestCall(action, 'r='+Math.round(Math.random()*99999), 'page-dina-content', 'get', 'getPageContentCb');
	
	ctNameCb = cName;
	vdPathCb = videoPath;
}

function getPageContentCb()
{
	if (ctNameCb == 'income_estimator')
		initBlueCalc();
	else if (ctNameCb == 'members' || ctNameCb == 'organizations' || ctNameCb == 'advertisers')
		setupZoom();
	else if (ctNameCb.indexOf('video_') != -1 && vdPathCb != '')
		loadVideo(vdPathCb);
	try { sc_Init() } catch(e) { }
}

function resetMenu()
{
	var al = document.getElementsByTagName('a');
	for (var i=0;i<al.length;i++) 
	{
		if (al[i].className && al[i].className.indexOf('pmenu') != -1)
			al[i].className = (al[i].className.indexOf('next') != -1) ? 'pmenu next' : 'pmenu';
	}
}

function loadVideo(videoURL)
{
	var _s = (window.location.protocol && window.location.protocol == "https:") ? 'https://' : 'http://';
	var t = AC_FL_RunContentIn(
		'codebase', _s + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '660',
		'height', '420',
		'src', '/media/jcplayer',
		'quality', 'high',
		'pluginspage', _s + 'www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'noScale',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'jcplayer',
		'bgcolor', '#ffffff',
		'name', 'jcplayer',
		'menu', 'true',
		'wmode', 'transparent',
		'allowFullScreen', 'true',
		'allowScriptAccess','sameDomain',
		'FlashVars','videoURL='+videoURL+'&autoPlay=true&backgroundColor1=0x333333&backgroundColor2=0x222222',
		'movie', '/media/jcplayer',
		'salign','TL'
	); //end AC code
	gEl('video-stream').innerHTML = t;
	
	setTimeout("catchVideoClick()", 1000);
}

function catchVideoClick()
{
	// for landing only
	if ( gEl('demo-video1') && gEl('video-stream') )
	{
		document.onclick=function(e) {
			if (e && e.target && e.target == '[object HTMLEmbedElement]')
				return;
			unloadVideo();
		}
	}
}
function unloadVideo()
{
	if ( gEl('demo-video1') && gEl('video-stream') )
	{
		gEl('video-stream').innerHTML = '';
		document.onclick = function() { return; }
		hide('demo-video1');
	}
}

/* sign in, sign up */
function showBox4(me)
{
	gEl('overlay4').style.height = document.body.offsetHeight + 'px';
	show('overlay4');
	show(me);
	if (gEl('emailLogin'))
		gEl('emailLogin').focus();
	return false;
}
function hideBox4(me){
	hide(me);
	hide('overlay4');
	return false;
}


function hideBox(boxId, olId)
{
	gEl(olId).style.display = 'none';
	gEl(boxId).style.display = 'none';
}

function showBox(boxId, olId)
{
	gEl(olId).style.height = document.body.offsetHeight + 'px';
	show(olId);
	show(boxId);
	center(boxId);
}

function getDimensions (element)
{
	var display = element.style.display;
	if (display != 'none' && display != null) // Safari bug
		return { width: element.offsetWidth, height: element.offsetHeight};

	// All *Width and *Height properties give 0 on elements with display none,
	// so enable the element temporarily
	var els = element.style;
	var originalVisibility = els.visibility;
	var originalPosition = els.position;
	var originalDisplay = els.display;
	els.visibility = 'hidden';
	els.position = 'absolute';
	els.display = 'block';
	var originalWidth = element.clientWidth;
	var originalHeight = element.clientHeight;
	els.display = originalDisplay;
	els.position = originalPosition;
	els.visibility = originalVisibility;
	return {width: originalWidth, height: originalHeight};
}

function getWindowWidth() {
	if (window.innerWidth && window.innerWidth != 0)
		return window.innerWidth;
	if (document.documentElement.clientWidth && document.documentElement.clientWidth != 0)
		return document.documentElement.clientWidth;
	if (document.body.clientWidth && document.body.clientWidth != 0)
		return document.body.clientWidth;
	return 0;
}

function getWindowHeight() {
	if (window.innerHeight && window.innerHeight != 0)
		return window.innerHeight;
	if (document.documentElement.clientHeight && document.documentElement.clientHeight != 0)
		return document.documentElement.clientHeight;
	if (document.body.clientHeight && document.body.clientHeight != 0)
		return document.body.clientHeight;
	return 0;
}

function center(element)
{
	element = gEl(element);

	var my_width  = getWindowWidth();
	var my_height = getWindowHeight();

	element.style.position = 'absolute';
	element.style.zIndex   = 201;

	var scrollY = getScrollXY()[1];

	var elementDimensions = getDimensions(element);

	var setX = ( my_width  - elementDimensions.width  ) / 2;
	var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;

	element.style.left = setX + "px";
	element.style.top  = setY + "px";

	element.style.display  = 'block';
}

function showJoinnFree()
{
	if (gEl('overlay4'))
		hide('overlay4');
	if (gEl('loginparent'))
		hide('loginparent');
	
	gEl('overlay11').style.height = document.body.offsetHeight + 'px';
	show('overlay11');
	show('joinfparent');
	if (gEl('alt_joinfLogin'))
		setTimeout("gEl('alt_joinfLogin').focus()", 1000);
}
function hideJoinnFree()
{
	hide('joinfparent');
	hide('overlay11');
}

function showOrgLoginBox()
{
	gEl('overlayo4').style.height = document.body.offsetHeight + 'px';
	show('overlayo4');
	show('org-loginparent');
	
	if (gEl('orgLogin'))
		gEl('orgLogin').focus();

}
function hideOrgLoginBox()
{
	hide('org-loginparent');
	hide('overlayo4');
}

function hideBox3(me){
	hide(me);
	hide('overlay3');
	return false;
}

function runJoinForm(isOrg)
{
	var l = gEl('mask_email').value;
	var p = gEl('mask_password').value;
	
	if (l == 'Enter Valid Email' || p == 'Create a Password' || l =='' || p == '')
		return;
	if (isOrg)
	{
		gEl('ex_join_OLogin').value = l;
		gEl('ex_join_OPassword').value = p;
		
		gEl('ex_join_Form').setAttribute('action', '/register_organization/');
	}
	else
	{
		gEl('ex_join_Login').value = l;
		gEl('ex_join_Password').value = p;
		gEl('ex_join_Form').setAttribute('action', '/login/');
	}
	gEl('ex_join_Form').submit();
	
}
function alt_runJoinForm(isOrg)
{
	var l = gEl('alt_joinfLogin').value;
	var p = gEl('alt_joinfPassword').value;
	
	if (l == 'Enter Valid Email' || p == 'Create a Password' || l =='' || p == '')
		return;
	if (isOrg)
	{
		gEl('alt_ex_join_OLogin').value = l;
		gEl('alt_ex_join_OPassword').value = p;
		
		gEl('alt_ex_join_Form').setAttribute('action', '/register_organization/');
	}
	else
	{
		gEl('alt_joinfLogin').value = l;
		gEl('alt_joinfPassword').value = p;
		gEl('alt_ex_join_Form').setAttribute('action', '/login/');
	}
	gEl('alt_ex_join_Form').submit();
}

/* forgot password */
function getPassword()
{
	var l = gEl('emailLogin').value;
	var q = gEl('LoginSecurityQuestion').value;
	var a = gEl('answerLogin').value;
	
	var req = 'get=password&l=' + l + '&q=' + q + '&a=' + a;
	gEl('displaypass').innerHTML = '<div style="height: 19px; background: url(/images/loading2.gif) top left no-repeat"></div>';
	AjaxAfterLoadCall = 'getPasswordAfter';
	AjaxRequestPost('/ajax/', req, 'null');
}

function getPasswordAfter()
{
	if (AjaxRequestResult != '' && AjaxRequestResult != 'Try Again')
	{
		gEl('displaypass').innerHTML = AjaxRequestResult;

        if (AjaxRequestResult != 'Password has been sent to your email.')
            gEl('passwordLogin').value = AjaxRequestResult;
	}
	else
		gEl('displaypass').innerHTML = 'Try Again';
}

function getOrgPassword()
{
	var l = gEl('orgLogin').value;
	var q = gEl('orgLoginSecurityQuestion').value;
	var a = gEl('orgAnswerLogin').value;
	var m = gEl('orgType').value;
	
	var req = 'get=password&l=' + l + '&q=' + q + '&a=' + a + '&m=' + m;
	gEl('orgdisplaypass').innerHTML = '<div style="height: 19px; background: url(/images/loading2.gif) top left no-repeat"></div>';
	AjaxAfterLoadCall = 'getOrgPasswordAfter';
	AjaxRequestPost('/ajax/', req, 'null');
}

function getOrgPasswordAfter()
{
	if (AjaxRequestResult != '' && AjaxRequestResult != 'Try Again')
	{
		gEl('orgdisplaypass').innerHTML = AjaxRequestResult;
		gEl('orgPassword').value = AjaxRequestResult;
	}
	else
		gEl('orgdisplaypass').innerHTML = 'Try Again';
}


/* install bar */
function install ( aEvent )
{
	var params = {
		"Boloto Toolbar": { URL: aEvent.target.href,
		IconURL: aEvent.target.getAttribute("iconURL"),
		Hash: aEvent.target.getAttribute("hash"),
		toString: function () { return this.URL; }
		}
	};
	var _isNav = navigator.userAgent.toLowerCase();
	var em_ff = /^.+firefox\/([\.\d]*)/;
	var em_mac = /^.+mac.+/;
	var _isFF = false;
	var _isFFRight = false;
	if (em_ff.test(_isNav))
	{
		_isFF = true;
		var dets = new Array();
		var _isVer = RegExp.$1;
		dets = _isVer.split(".");
		if (dets[0] * 1 >= 3)
		{
			if ((dets[1] * 1 > 0) || (dets.length >= 3 && dets[2] * 1 >= 1))
				_isFFRight = true;
		}
	}
	if(_isFF == false)
	{
		alert("The Bar will only run on a FireFox Version 3.0.1 or later. Not compatible with Safari at this time.");
	}
	else if(_isFFRight)
	{
		InstallTrigger.install(params);
	}
	else
	{
		if (em_mac.test(_isNav))
		{
			alert("Mac Users must have FireFox Browser 3.0.1 or later to install The Bar. To download the lastest version of FireFox for Mac visit www.mozilla.com");
		}
		else
		{
			alert("You must have FireFox Browser 3.0.1 or later to install The Bar. To download the latest verion of FireFox go to www.mozilla.com.");
		}
	}
	return false;
}
function nodownload()
{
	alert("The Bar can only be installed on Microsoft Windows 2000 or newer");
	return false;
}

var PPNavtp = '';
function PPNav(tp)
{
	tp = (!tp) ? 'faq' : tp;
	if (PPNavtp == tp) return;
	PPNavtp = tp;
	var req = 'isAjax=1&t='+tp;
	AjaxRequestPost('/posts/', req, 'dina-content2');
}

/* sending from press page */
function sendFPress(tp)
{
	if (!tp || (tp != 'fb' && tp != 'bug'))
		return;
	var s,m;
	if (tp == 'fb')
	{
		s = gEl('c_fpf_subject').value;
		m = gEl('c_fpf_message').value;
	}
	else
	{
		s = gEl('c_fpb_subject').value;
		m = gEl('c_fpb_message').value;
	}
	if (s.length == 0 || m.length == 0)
	{
		alert('Please complete required fields');
		return;
	}
	if (gEl('c_fpf_post') && tp == 'fb')
		gEl('c_fpf_post').style.visibility = 'visible';
	if (gEl('c_fpb_post') && tp == 'bug')
		gEl('c_fpb_post').style.visibility = 'visible';

	var req = 'get=new_feedback&t=' + tp + '&n=&e=&p=&u=&s=' + s + '&m=' + m;
	//alert(req)
	//return;

	AjaxAfterLoadCall = 'sendFPressCB';
	AjaxRequestPost('/ajax/', req, 'null');
}

function sendFPressCB()
{
	if (AjaxRequestResult == 'ok')
	{
		if (gEl('c_fpf_subject'))
			gEl('c_fpf_subject').value = '';
		if (gEl('c_fpb_subject'))
			gEl('c_fpb_subject').value = '';
		if (gEl('c_fpf_message'))
			gEl('c_fpf_message').value = '';
		if (gEl('c_fpb_message'))
			gEl('c_fpb_message').value = '';
		alert('Thank You');
	}
	else
		alert(AjaxRequestResult);
	if (gEl('c_fpf_post'))
		gEl('c_fpf_post').style.visibility = 'hidden';
	if (gEl('c_fpb_post'))
		gEl('c_fpb_post').style.visibility = 'hidden';

}

function getCommentsBox()
{
	var c = gEl('comments');
	if (c.innerHTML.length < 10)
	{
		c.innerHTML = '<h2 style="text-align:center;margin-top: 10px;"><img src="/images/medium_load.gif" style="" /> Loading...</h2>'
		var req = 'get=comments';
		AjaxRequestPost('/ajax/', req, 'comments');
	}
	if (gEl('feedback-box'))
		show('feedback-box');
	if (gEl('bugs-box'))
		hide('bugs-box');
	showBox3('infobox2');
}

var lastSendType = '';
function sendComment(tp)
{
	tp = (tp) ? tp : '';
	tp = (tp == 'bug') ? tp : 'fb';
	lastSendType = tp;
	var cl = (tp == 'bug') ? 'c_loading_b' : 'c_loading';

	var s = (tp == 'bug') ? gEl('c_bug_subject').value : gEl('c_subject').value;
	var m = (tp == 'bug') ? gEl('c_bug_comment').value : gEl('c_comment').value;

	if (s.length == 0 || m.length == 0)
	{
		alert('Please complete form');
		return ;
	}

	var req = 'get=new_feedback&t=' + tp + '&s=' + s + '&m=' + m;

	gEl(cl).innerHTML = '<img src="/images/loading2.gif" hspace="5" style="position:relative;top: -3px;" />';
	AjaxAfterLoadCall = 'sendCommentCB';
	AjaxRequestPost('/ajax/', req, 'null');
}
function sendCommentCB()
{
	if (AjaxRequestResult == 'ok')
	{
		gEl('c_subject').value = '';
		gEl('c_comment').value = '';
		if (gEl('c_bug_comment'))
			gEl('c_bug_comment').value = '';
		if (gEl('c_bug_subject'))
			gEl('c_bug_subject').value = '';
		alert('Comment Sent');
		hideBox3('infobox2');
	}
	else
		alert('Try Again');
	var cl = (lastSendType == 'bug') ? 'c_loading_b' : 'c_loading';
	gEl(cl).innerHTML = '';
}


function sendFeedBack(tp)
{
	tp = (tp) ? tp : '';

	var n = (gEl('c_name')) ? gEl('c_name').value : '';
	var e = (gEl('c_email')) ? gEl('c_email').value : '';
	var p = (gEl('c_phone')) ? gEl('c_phone').value : '';
	var u = (gEl('c_url')) ? gEl('c_url').value : '';
	var m = (gEl('c_message')) ? gEl('c_message').value : '';

	if (n.length == 0 || e.length == 0)
	{
		alert('Please complete required fields');
		return;
	}

	var req = 'get=new_feedback&v=1&t=' + tp + '&n=' + n + '&e=' + e + '&p=' + p + '&u=' + u + '&m=' + m;
	if (gEl('c_post'))
		gEl('c_post').style.visibility = 'visible';

	AjaxAfterLoadCall = 'sendFeedBackCB';
	AjaxRequestPost('/ajax/', req, 'null');
}
function sendFeedBackCB()
{
	if (AjaxRequestResult == 'ok')
	{
		gEl('c_name').value = '';
		gEl('c_email').value = '';
		gEl('c_phone').value = '';
		gEl('c_message').value = '';
		alert('Thank You');
	}
	else
	{
		alert(AjaxRequestResult);
	}
	if (gEl('c_post'))
		gEl('c_post').style.visibility = 'hidden';
}


function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function ismaxwords(obj)
{
	var mwords = obj.getAttribute? parseInt(obj.getAttribute("maxwords")) : ""
	var words_s = obj.value.replace(/[ \t]+/gi, ' ');
	var words_a = words_s.split(' ');
	words_s = '';
	if (words_a.length > mwords)
	{
		for (var i = 0; i < mwords; i++)
			words_s += (words_s.length > 0) ? ' ' + words_a[i] : words_a[i];
		obj.value = words_s;
	}
	ismaxlength(obj);
}


function cleanIt(elm, isDef)
{
	if (elm.value == isDef)
		elm.value = '';
}

