// Start Ad-rotator Modules

// Variables used by ad-rotator module
var currentAd = 1;
var adHeight = 400;
var adPause = 5;
var totalAds = 4;
var isPaused = new Boolean;

function gotoNextAd() {
	var tm = 0;
	if (adPause == 0) {
		currentAd++;
		if (currentAd > totalAds) { currentAd = 1; }
		fadeIn('fbcover');
		tm = -(adHeight * (currentAd - 1));
		document.getElementById('fbcontentframe').style.top = (tm) + 'px';
		fadeOut('fbcover');
		document.getElementById('adPauseBtn').src = '/images/design-09/featured_products/pause-btn.png';
		isPaused = false;
		adPause = 5;
	} else {
		adPause--;
	}
	setTimeout('gotoNextAd()',1000);
}

function gotoPrevAd() {
	var tm = 0;
	currentAd--;
	if (currentAd < 1) { currentAd = totalAds; }
	fadeIn('fbcover');
	tm = -(adHeight * (currentAd - 1));
	document.getElementById('fbcontentframe').style.top = tm + 'px';
	fadeOut('fbcover');
}

function reducePause() {
	adPause = adPause - 5;
}

function rotateAds() {
	if (adPause == 0) {
		setTimeout('gotoNextAd()',5000);
	} else {
		setTimeout('reducePause()',5000);
	}
}

function prevAd() {
	gotoPrevAd();
	adPause = 6;
}

function nextAd() {
	adPause = 0;
}

function pauseAd() {
	if (isPaused) {
		adPause = 0;
		document.getElementById('adPauseBtn').src = '/images/design-09/featured_products/pause-btn.png';
		isPaused = false;
	} else {
		adPause = 30;
		document.getElementById('adPauseBtn').src = '/images/design-09/featured_products/play-btn.png';
		isPaused = true;
	}
}

function initAds() {
	fadeOut('fbcover');
	adPause = 5;
	isPaused = false;
	gotoNextAd();
}

function initMiniAds() {
	adHeight = 200;
	totalAds = 8;
	initAds();
}

// End Ad-rotator Modules


// Start pane fading modules - used by ad-rotator and front page panes

// Variables used by ad-rotator module & front page pane management modules
var currentTab = '';
var workingPane = '';
var fadelevel = 0;

function fadeIn(thisPane) {
	document.getElementById(thisPane).style.visibility = 'visible';
	fadelevel = 0;
	workingPane = thisPane;
	fadePaneIn();
}

function fadePaneIn() {
	fadelevel = fadelevel + 0.1;
	var alphalevel = fadelevel * 100;
	document.getElementById(workingPane).style.filter = 'alpha(opacity=' + alphalevel + ')';
	document.getElementById(workingPane).style.opacity = fadelevel;
	if (fadelevel < 1) {
		setTimeout('fadePaneIn()',2);
	} else {
		document.getElementById(workingPane).style.filter = 'alpha(opacity=100)';
		document.getElementById(workingPane).style.opacity = '1.0';
	}
}

function fadeOut(thisPane) {
	fadelevel = 1;
	workingPane = thisPane;
	fadePaneOut();
}

function fadePaneOut() {
	fadelevel = fadelevel - 0.1;
	var alphalevel = fadelevel * 100;
	document.getElementById(workingPane).style.filter = 'alpha(opacity=' + alphalevel + ')';
	document.getElementById(workingPane).style.opacity = fadelevel;
	if (fadelevel > 0) {
		setTimeout('fadePaneOut()',2);
	} else {
		document.getElementById(workingPane).style.filter = 'alpha(opacity=0)';
		document.getElementById(workingPane).style.opacity = '0.0';
		document.getElementById(workingPane).style.visibility = 'hidden';
	}
}

// End pane fading modules


// Start Popup Content modules - used by pop-up overlay - duplicated in template-menu-tab.js & lodingo.js

function gup(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function getURLParam() {
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		return unescape(strHref.substr(strHref.indexOf("?")));
	}
	return '';
}

function hideDbPopupContent() {
	document.getElementById('popupcontentbox').style.visibility = 'hidden';
}

function showDbPopupContent(contentTitle,contentURL) {
	document.getElementById('popuptitletext').innerHTML = contentTitle;
	document.getElementById('popupcontentpage').src = '/' + contentURL;
	document.getElementById('popupcontentbox').style.visibility = 'visible';
}

function hideDashboard() {
	setTimeout('location = "http://www.lodingo.com/"',0);
}

function showOverlay() {
	var popTitle = gup('title');
	document.getElementById('popuptitletext').innerHTML = '<strong>' + unescape(popTitle) + '</strong>';
	var popURL = '';
	fetchThis = gup('fetch');
	if (fetchThis.search('faqpage') == -1) {
		if ((fetchThis.search('clientlogin') != -1) || (fetchThis.search('dashboard') != -1)) {
			window.location = 'http://www.lodingo.com/' + fetchThis;
		} else {
			popURL = '/' + fetchThis;
		}
	} else {
		popURL = '/FAQRetrieve.aspx?ID=' + fetchThis.substring(7);
	}
	document.getElementById('popupcontentpage').src = popURL;
	document.getElementById('popupcontentbox').style.visibility = 'visible';
}

function unpopPage() {
	var urlParm = getURLParam();
	if (urlParm == '') { setTimeout('location = "http://www.lodingo.com/"',0) }
	document.getElementById('dbholder').src = '/overlay.html' + urlParm + '&title=Welcome';
	document.getElementById('basepage').style.visibility = 'visible';
	document.getElementById('pagefader').style.visibility = 'visible';
	document.getElementById('dbholder').style.visibility = 'visible';
}

// End Popup Content modules


// Start Download modules

function doDl() {
	var popParms = gup('base').split(':');
	var popUrl = 'http://www.' + popParms[0] + '.com/download.php?f=' + popParms[1];
	window.open(popUrl,'','scrollbars=no,menubar=no,height=10,width=10,resizable=no,toolbar=no,location=no,status=no');
}

// End Download modules


// Start Login Form modules - used by the popup login box

function isEmpty(inputStr) {
	if (null == inputStr || '' == inputStr) {
		return (true)
	}
	return (false)
}

function checkEmail(thisEmail) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(thisEmail)){
		return (true)
	}
	return (false)
}

function emailFocus() {
	var userEmail = document.getElementById('SZUsername').value;
	if (!(document.getElementById('dashhelptext').innerHTML.search('You') == 0)) {
		document.getElementById('SZUsername').focus();
		document.getElementById('dashhelptext').style.color = '#999999';
		document.getElementById('dashhelptext').innerHTML = 'Please use the email address you entered when you registered.  Using the same email address each time allows us to consolidate your purchases into your personal download center.';
		document.getElementById('dashhelpbox').style.top = '30px';
		document.getElementById('rightwrong').src = '/images/spacer1x1.gif';
		document.getElementById('emailkey').src = '/images/spacer1x1.gif';
		document.getElementById('dashhelpbox').style.visibility = 'visible';
	}
}

function pwFocus() {
	var userEmail = document.getElementById('SZUsername').value;
	if (!checkEmail(userEmail)) {
		document.getElementById('rightwrong').src = '/images/design-09/dashboard/icn-wrong.png';
		document.getElementById('dashhelptext').style.color = 'red';
		document.getElementById('dashhelpbox').style.top = '30px';
		document.getElementById('dashhelptext').innerHTML = 'You have entered an invalid email address. Please use the email address you entered when you registered to consolidate your purchases into your personal download center.';
		document.getElementById('emailkey').src = '/images/spacer1x1.gif';
		document.getElementById('SZUsername').focus();
	} else {
		document.getElementById('dashhelptext').style.color = '#999999';
		document.getElementById('dashhelpbox').style.top = '60px';
		document.getElementById('rightwrong').src = '/images/design-09/dashboard/icn-right.png';
		document.getElementById('emailkey').src = '/images/design-09/dashboard/icn-key.png';
		document.getElementById('dashhelptext').innerHTML = 'Now enter the password you selected when you registered. If you have forgotten your password please click the key and it will be emailed to you.';
	}
}

function pwRetrieve() {
	var userEmail = document.getElementById('SZUsername').value;
	if (!checkEmail(userEmail)) {
		document.getElementById('rightwrong').src = '/images/design-09/dashboard/icn-wrong.png';
		document.getElementById('emailkey').src = '/images/spacer1x1.gif';
		document.getElementById('dashhelptext').style.color = 'red';
		document.getElementById('dashhelpbox').style.top = '30px';
		document.getElementById('dashhelptext').innerHTML = 'You have entered an invalid email address. Please use the email address you entered when you registered to consolidate your purchases into your personal download center.';
		document.getElementById('SZUsername').focus();
	} else {
		document.getElementById('loginForm').action = '/LostPasswordProcess.aspx';
		document.getElementById('loginForm').submit();
	}
}

function doLogin() {
	var userEmail = document.getElementById('SZUsername').value;
	if (!checkEmail(userEmail)) {
		document.getElementById('rightwrong').src = '/images/design-09/dashboard/icn-wrong.png';
		document.getElementById('emailkey').src = '/images/spacer1x1.gif';
		document.getElementById('dashhelptext').style.color = 'red';
		document.getElementById('dashhelpbox').style.top = '30px';
		document.getElementById('dashhelptext').innerHTML = 'You have entered an invalid email address. Please use the email address you entered when you registered to consolidate your purchases into your personal download center.';
		document.getElementById('SZUsername').focus();
		return (false);
	} else {
		var userPW = document.getElementById('SZPassword').value;
		if (isEmpty(userPW)) {
			document.getElementById('dashhelptext').style.color = 'red';
			document.getElementById('dashhelpbox').style.top = '60px';
			document.getElementById('dashhelptext').innerHTML = 'You must enter the password you selected when you registered. If you have forgotten your password please click the key and it will be emailed to you.';
			document.getElementById('SZPassword').focus();
			return (false);
		} else {
			document.getElementById('loginForm').submit();
			return (false);
		}
	}
}

// End Popup Content modules
