// serch control 
function getForm(formName) {return document.getElementById('search');}
function getFormField(fieldName, formName) {return eval('theForm.' + fieldName);}
function getFormValue(fieldName, defaultValue, formName) {
  var field = document.getElementById('fieldName'); 
  if (field != undefined) return field.value;
  return defaultValue;
}
function deselectTabs() {
  document.getElementById('tab_w').className = 'tab-unselected';
  document.getElementById('tab_i').className = 'tab-unselected';
  document.getElementById('tab_n').className = 'tab-unselected';
  document.getElementById('tab_v').className = 'tab-unselected';
  document.getElementById('tab_s').className = 'tab-unselected';
}
function selectTab(mode) {
  if (mode == undefined) mode = getFormValue('t', 'w', 'search');
  deselectTabs();
  document.getElementById('tab_' + mode).className = 'highlight3';
}
function setSearchMode(mode) {
  if (mode == undefined) mode = '';
  document.getElementById("t").value=mode;  
  selectTab(mode);
}
// end serch control 

//newsletter sign up control
function sendEmailTBLocal() {
	xmlHttp=getAjaxObjectTB()
	if (xmlHttp==null) {
		alert ('Your browser does not support HTTP Request. Please contact us at "info@prodege.com" to get your password.')
		return;
	}
	txtEmail = document.getElementById("emailAddressLocal").value;
	if (txtEmail == "") {
		alert ("Please enter your Email Address.")
		return;
	}
	url="/?cmd=sb-pswd-reminder&email=" + txtEmail;
	url=url+"&amp;sid="+Math.random();
	xmlHttp.onreadystatechange=getPResultTBLocal;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function getPResultTBLocal() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		result = xmlHttp.responseText
		if (result == 1) {
			alert("Your Password has been sent.");
		} 
		else  if (result == 2) {
			alert("Your Email Address was not found on our system.");
		}
		else if (result == 3) {
			alert("Please enter a valid Email Address.");
		} 
		else  {
			alert("There was an unexpexted error sending your password." +
			String.fromCharCode(10) + String.fromCharCode(10) + "Please try again or contact us at info@prodege.com");
		} 
	}
}
function logInTBLocal() {
	txtEmail = document.getElementById("emailAddressLocal");
	txtPswd = document.getElementById("pswdLocal");
	valid = true;
	if (txtEmail.value == "") {
		alert("Please enter your Email Address");
		return;
	}
	if (txtPswd.value == "") {
		alert("Please enter your Password");
		return;
	}
	document.getElementById("signInBoxLocal").submit();
}
function enterLoginTBLocal(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if(charCode == 13) {
		logInTBLocal();
		return false;
	}  
}
// end newsletter sign up control


//feature tout controls
var curFeature = 0;
var opacNum = 100;
var isPlaying = true;
var curToutDiv = 0;
var featureTimer;

function togglePlay() {
    togglePlayAuto(!isPlaying, 10);
}
function togglePlayAuto(isPlay, intval) {
    if (isPlay) {
        featureTimer = setTimeout(changeFeature, intval);
        document.getElementById("toggle").className = "tgToggle";
    } else {
        if (featureTimer != null) {
			clearTimeout(featureTimer);
		}
        document.getElementById("loaderInd").style.width = "0";
		document.getElementById("toggle").className = "tgToggle tgPlay";
		//$("#loaderInd").stop(true,true);
		//document.getElementById("loaderInd").style.width = "0";
    }
    isPlaying = isPlay;
}
    
function showFeature(featureNum, auto) {
	var loaderDiv = document.getElementById("loaderInd").style.width;
	var newToutDiv = curToutDiv == 0 ? 1 : 0;
	document.getElementById("tgImg" + newToutDiv).src = "/content/clients/swagbucks/images/features/feature" + images[featureNum];
	var ftrLinkA = document.getElementById("dvTout" + newToutDiv);
	var actionTagA = document.getElementById("actionTag" + newToutDiv);
	if (targets[featureNum] == "none") {
		ftrLinkA.removeAttribute("href");
		ftrLinkA.style.cursor = "default";
		actionTagA.style.display = "none";
	} else {
		ftrLinkA.href = hrefs[featureNum];
		actionTagA.style.display = "block";
	}
	ftrLinkA.target = targets[featureNum];
	ftrLinkA.style.display = (targets[featureNum] == "none" ? "none" : "");
	document.getElementById("tgTitle" + newToutDiv).innerHTML = titles[featureNum];
	document.getElementById("tgDesc" + newToutDiv).innerHTML = descriptions[featureNum];
	document.getElementById("tgAction" + newToutDiv).innerHTML = actionTexts[featureNum];
	$("#dvTout" + curToutDiv).fadeOut(300);
	$("#dvTout" + newToutDiv).fadeIn(300,function(){togglePlayAuto(auto, 5000);});
	curToutDiv = newToutDiv;
	document.getElementById("ftrTab" + curFeature).className = "opt secBorder" + (curFeature == 3 ? " clearBkd" : "");
	document.getElementById("ftrTab" + featureNum).className = "opt slct" + (curFeature == 3 ? " clearBkd" : "");
	loaderDiv = "0";
	//$("#loaderInd").animate({width: '436px'},4500,'linear');
	curFeature = featureNum;
    //togglePlayAuto(auto, 5000);
}
function changeFeature() {
    var newFeature = (curFeature == 3 ? 0 : curFeature + 1);
    showFeature(newFeature, true);
}
function fadeIn() {
    if (opacNum < 100) {
        opacNum += 4;
        changeOpac(document.getElementById("ftrBkd"), opacNum);
    }
    else {
        clearInterval(ftrFader);        
    }
}
function changeOpac(elm, opacity) {
    elm.style.opacity = (opacity / 100);
    elm.style.MozOpacity = (opacity / 100);
    elm.style.KhtmlOpacity = (opacity / 100);
    elm.style.filter = "alpha(opacity=" + opacity + ")";
}

function loadImages() {
	document.getElementById("imageLoader1").src = "/content/clients/swagbucks/images/features/feature" + images[1];
	document.getElementById("imageLoader2").src = "/content/clients/swagbucks/images/features/feature" + images[2];
	document.getElementById("imageLoader3").src = "/content/clients/swagbucks/images/features/feature" + images[3];
	document.getElementById("imageLoader1").style.display = "none";
	document.getElementById("imageLoader2").style.display = "none";
	document.getElementById("imageLoader3").style.display = "none";
}	
function startToutsScroll() {
	featureTimer = setTimeout(changeFeature, 3000);
	//$("#loaderInd").animate({width: '436px'},4750,'linear');
}	
function showOther(tst) {
	if (tst < 0) {
		(curFeature > 0 ? showFeature(curFeature -1, false) : showFeature(3, false));
	} else {
		(curFeature < 3 ? showFeature(curFeature +1, false) : showFeature(0, false));
	}
}
//end feature tout controls
