function getXmlHttpRequestObject() {
	if (document.all) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

var xmlhttp = getXmlHttpRequestObject();

function toggleSignup(divid,formid,planid) {
	div = document.getElementById(divid);
	theform = document.getElementById(formid);
	div.className = 'subscribevisible';
	theform.plan_id.value = planid;
	theform.champ1.focus();
	oTop = div.offsetTop;
	window.scrollTo(0,oTop);
}

function toggleSignupTwo(divid,formid,planid) {
	div = document.getElementById(divid);
	theform = document.getElementById(formid);
	div.className = 'subscribetwovisible';
	theform.plan_id.value = planid;
	theform.champ1.focus();
	oTop = div.offsetTop;
	window.scrollTo(0,oTop);
}

function toggleSubscribe(divid0,divid1) {
	div0 = document.getElementById(divid0);
	div1 = document.getElementById(divid1);
	div0.className = 'signuphidden';
	div1.className = 'subscribevisible';
	oTop = div1.offsetTop;
	window.scrollTo(0,oTop);
}

function toggleAccount(divid0,divid1) {
	div0 = document.getElementById(divid0);
	div1 = document.getElementById(divid1);
	//curclass = div0.className;
	//curclass = curclass == 'planvisible' ? 'planhidden' : 'planvisible';
	div0.className = 'planhidden';
	div1.className = 'accountvisible';
}

function toggleExercise(divid0,divid1,divid2,divid3) {
	div0 = document.getElementById(divid0);
	div1 = document.getElementById(divid1);
	div2 = document.getElementById(divid2);
	div3 = document.getElementById(divid3);
	if (div0) {
		curclass = div0.className;
		curclass = curclass == 'exercisevisible' ? 'exercisehidden' : 'exercisevisible';
		if(div1){
			div1.className = 'grammarhidden';
		}
		if(div2){
			div2.className = 'audiohidden';
		}
		if(div3){
			div3.className = 'videohidden';
		}
		div0.className = curclass;
	}
}

function toggleGrammar(divid0,divid1,divid2,divid3) {
	div0 = document.getElementById(divid0);
	div1 = document.getElementById(divid1);
	div2 = document.getElementById(divid2);
	div3 = document.getElementById(divid3);
	if (div0) {
		curclass = div0.className;
		curclass = curclass == 'grammarvisible' ? 'grammarhidden' : 'grammarvisible';
		if(div1){
			div1.className = 'exercisehidden';
		}
		if(div2){
			div2.className = 'audiohidden';
		}
		if(div3){
			div3.className = 'videohidden';
		}
		div0.className = curclass;
	}
}

function toggleAudio(divid0,divid1,divid2,divid3) {
	div0 = document.getElementById(divid0);
	div1 = document.getElementById(divid1);
	div2 = document.getElementById(divid2);
	div3 = document.getElementById(divid3);
	if (div0) {
		curclass = div0.className;
		curclass = curclass == 'audiovisible' ? 'audiohidden' : 'audiovisible';
		if(div1){
			div1.className = 'exercisehidden';
		}
		if(div2){
			div2.className = 'grammarhidden';
		}
		if(div3){
			div3.className = 'videohidden';
		}
		div0.className = curclass;
	}
}

function toggleVideo(divid0,divid1,divid2,divid3) {
	div0 = document.getElementById(divid0);
	div1 = document.getElementById(divid1);
	div2 = document.getElementById(divid2);
	div3 = document.getElementById(divid3);
	if (div0) {
		curclass0 = div0.className;
		curclass0 = curclass0 == 'videovisible' ? 'videohidden' : 'videovisible';
		if(div1){
			div1.className = 'exercisehidden';
		}
		if(div2){
			div2.className = 'grammarhidden';
		}
		if(div3){
			div3.className = 'audiohidden';
		}
		div0.className = curclass0;
	}
}


var podPressHttp = getXmlHttpRequestObject();
var podPressDivName = '';
var podPressPlayersToLoad = new Array();

function podPressPlayerToLoad(divname, oftype, dimensionSetting, mediaFile) {
	var cnt = podPressPlayersToLoad.length;
	var x = new Array();
	x['divname'] = divname;
	x['oftype'] = oftype;
	x['dimensionSetting'] = dimensionSetting;
	x['mediaFile'] = mediaFile;
	podPressPlayersToLoad[cnt] = x;
}

function podPressShowPlayersToLoad() {
	if(podPressPlayersToLoad.length > 0) {
		podPressShowHidePlayerDiv(podPressPlayersToLoad[0]['divname'], podPressPlayersToLoad[0]['oftype'], podPressPlayersToLoad[0]['dimensionSetting'], podPressPlayersToLoad[0]['mediaFile'], 'yes', 'no');
	}
}

function podPressLoadPageIntoDiv(divname, params) {
	podPressDivName = divname;
	podPressHttp = getXmlHttpRequestObject();
	podPressHttp.open("GET", podPressBackendURL+'podpress_backend.php?'+params, true);
	podPressHttp.onreadystatechange = function () { if (podPressHttp.readyState == 4) { document.getElementById(divname).innerHTML=podPressHttp.responseText; podPressPlayersToLoad.shift(); podPressShowPlayersToLoad(); } }		
	podPressHttp.send(null);	
}

function podPressShowHidePlayerDiv(divname, oftype, dimensionSetting, mediaFile, forceShow, autoPlay) {
	if(document.getElementById(divname) == undefined) {
		return false;
	}

	if(autoPlay != 'no') { autoPlay = 'yes'; }
	if(document.getElementById(divname).title != '' && document.getElementById(divname).title != oftype) {
		var prev_oftype = document.getElementById(divname).title;
		if(document.getElementById(divname+'_label_'+prev_oftype) != undefined) {
			document.getElementById(divname+'_label_'+prev_oftype).innerHTML=podPressText_PlayNow;
		}
	}
	document.getElementById(divname).title = oftype;
	
	if(forceShow == 'yes') {
		document.getElementById(divname+'_label_'+oftype).innerHTML=podPressText_HidePlayer;
		document.getElementById(divname).style.display='block';
		podPressLoadPageIntoDiv(divname, 'podPressPlayerAutoPlay='+autoPlay+'&standalone=no&action=showplayer&dimension='+dimensionSetting+'&filename='+mediaFile);		
	} else {
		if(document.getElementById(divname+'_label_'+oftype).innerHTML == podPressText_PlayNow) {
			document.getElementById(divname+'_label_'+oftype).innerHTML=podPressText_HidePlayer;
			document.getElementById(divname).style.display='block';
			podPressLoadPageIntoDiv(divname, 'podPressPlayerAutoPlay='+autoPlay+'&standalone=no&action=showplayer&dimension='+dimensionSetting+'&filename='+mediaFile);		
		} else {
			if(document.getElementById('winplayer') != undefined) {
				if(document.getElementById('winplayer').controls) {
					document.getElementById('winplayer').controls.stop();
				}
				document.getElementById(divname+'_label_'+oftype).innerHTML=podPressText_PlayNow;
				document.getElementById(divname).style.display='none';
			} else {
				document.getElementById(divname+'_label_'+oftype).innerHTML=podPressText_PlayNow;
				document.getElementById(divname).style.display='none';
				document.getElementById(divname).innerHTML='';
			}
		}
	}
}

function podPressCustomSelectVal(select_elm, prompt_text){
	var val = prompt(prompt_text, '');
	var option = document.createElement('option');
	option.setAttribute('value', val);
	option.innerHTML = val;
	option.selected = true;
	select_elm.appendChild(option);
}

if(ap_instances == undefined) {
	var ap_instances = new Array();
	var ap_clearID = setInterval( ap_registerPlayers, 100 );
}
	
function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName('object');
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
	if(objectID.indexOf('audioplayer') == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) { 
				document.getElementById('audioplayer' + ap_instances[i].toString()).SetVariable('closePlayer', 1);
			}	else {
				document.getElementById('audioplayer' + ap_instances[i].toString()).SetVariable('closePlayer', 0);
			}
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function podPressShowRecorder()
{
	document.getElementById('podPress_audioCommentStatus').innerHTML = '<img src="http://podpress.mobatalk.com/images/mobatalk-bullet.jpg" width="16" height="16" border="0" /> Recording Audio Comment';
	document.getElementById('podPress_audioRecorder').style.display = 'block';
	document.getElementById('podPress_audioRecorder').src = 'http://podpress.mobatalk.com/recorder/record_app_JS.asp?code='+podPressMobatalkID+'&retpath='+podPressBackendURL+'mobatalk_audio_comment.php';
}

function podPressAttachAudioComment(argURL, argSize, argDuration)
{
	document.getElementById('podPress_audioRecorder').style.display = 'none';
	document.getElementById('podPress_audioCommentURL').value = argURL;
	document.getElementById('podPress_audioCommentSize').value = argSize;
	document.getElementById('podPress_audioCommentDuration').value = argDuration;
	document.getElementById('podPress_audioCommentStatus').innerHTML = '<img src="http://podpress.mobatalk.com/images/mobatalk-bullet.jpg" width="16" height="16" border="0" /> <font color="green"><b>Audio Comment Attached</b></font><br><object type="application/x-shockwave-flash" data="'+podPressBackendURL+'player.swf" width="290" height="24" id="audioplayerNEWCOMMENT"><param name="movie" value="'+podPressBackendURL+'player.swf" /><param name="FlashVars" value="playerID=NEWCOMMENT&amp;bg=0xF8F8F8&amp;leftbg=0xEEEEEE&amp;text=0x666666&amp;lefticon=0x666666&amp;rightbg=0xCCCCCC&amp;rightbghover=0x999999&amp;righticon=0x666666&amp;righticonhover=0xFFFFFF&amp;slider=0x666666&amp;track=0xFFFFFF&amp;loader=0x9FFFB8&amp;border=0x666666&amp;soundFile=' + argURL + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="transparent" /></object>';
}

function setRadio (formname,value) {
	var frm = document.getElementById(formname);
	var inputCollection = frm.getElementsByTagName('input');
	if (inputCollection) {
		for (i=0;i<inputCollection.length;i++) {
			if (inputCollection[i].getAttribute('type')=='radio') {
				inputCollection[i].checked = inputCollection[i].value == value ?  true : false;
			}
		}
	}
}
