/*



*/

var editing  = false;
var editvalue;
var myfield;
var userdata = new Array();
var auth;
var cookiechecked=false;
var loginwindow=false;
var pageid='home';
var lastpage='home';
var edit=false;
var dialog;
var dialogopen=false;
var videodata=new Array();
var cmd="";
var a_index;
var winparameters = new Array();
var currentedit = new Array();
var iphone = false;

videodata[0]=	{
					title:		"",
					linkhtml:	""
				};


function init()
{
	checkbrowser();
	checkCookie();
	toggleedit();
	changecontent();
	teamkid();
	gohome();
}


if (document.getElementById && document.createElement) {
	var butt = document.createElement('BUTTON');
	var buttext = document.createTextNode('Submit Change');
	butt.appendChild(buttext);
	butt.onclick = saveEdit;
}

function checkbrowser()
{
	
	var agent=navigator.userAgent.toLowerCase();
	var iphone = ((agent.indexOf('iphone')!=-1));
	if (iphone)
	{  
		window.location = "http://www.faith-mbc.com/iphone/";
	}

}


function checklogin()
{
	if (!loginwindow && !auth)
	{
		userlogin();
	}
	else
	{
		hidelogin();
	}
	
}

// @makemenu
function userlogin() 
{
		
	var html = 
  				'<div id="formcontainer">' +
      			'<form action="" method="POST" class="form">' +
				'<div class="holder">' +
				'<label for="name">Username</label>' +
				'<div class="clear"></div>' +
    			'<div class="div_texbox">' +
    			'<span>' +
				'<input name="username" type="text" class="textbox" id="username" value="" />' +
				'</span>' +
				'</div>' +
				'<div class="clear"></div>' +
				'</div>' +
				'<div class="holder">' +
				'<label for="address">Password</label>' +
				'<div class="clear"></div>' +
				'<div class="div_texbox">' +
				'<span>' +
				'<input name="password" type="password" class="textbox" id="password" value="" />' +
				'</span>' +
				'</div>' +
				'<div class="clear"></div>' +
				'</div>' +
				'<div class="holder">' +
				'<div class="clear"></div>' +
				'</div>' +
				'<div class="button_div">' +
				'<table width="100%" border="0" align="center">' +
				'<tr>' +
				'<td>' +
				'<input name="Submit" type="button" value="Login" class="buttons" onClick="handleuser(this);"/>' +
				'</td>' +
				'<td>' +
				'<input name="Cancel" type="button" value="Cancel" class="buttons" onClick="hidelogin();"/>' +
				'</td>' +
				'</tr>' +
				'</table>' +
				'</div>' +
				'</form>' +
				'<div class="clear"></div>' +
				<!-- Personal details end -->
				'</div>' +
				
				'</div>' ;

  //document.getElementById('login').innerHTML = html;
  $('#login').html(html);
  
  loginwindow=true;
}

function hidelogin()
{
	document.getElementById('login').innerHTML="";
	loginwindow=false;
}

function handleuser(val)
{
	userdata['username'] = document.getElementById('username').value;
	userdata['password'] = document.getElementById('password').value;
	if (!verifyuser())
	{
		//document.getElementById('password').value = "";
	}
}

function gohome()
{
	pageid='home';
	document.getElementById('pcontent_main').innerHTML="Welcome to Faith Missionary Baptist Church";
	document.getElementById('pcontent_2').innerHTML="";
	getpagedata();
		
	lastpage='home';
	
}

function history()
{
	pageid='history';
	document.getElementById('pcontent_main').innerHTML="Coming Soon";
	document.getElementById('pcontent_2').innerHTML="";
	getpagedata();
		
	lastpage='history';
	
}

function staff()
{
	pageid='staff';
	document.getElementById('pcontent_main').innerHTML='<iframe id="scIFrame" name="PMfMuaWQNr1TNH4JLuWa" src="staff.html"' +
							'scrolling="no" allowTransparency="true" frameborder="0" width="600" height="500">';
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='staff';
	
}

function services()
{
	pageid='services';
	document.getElementById('pcontent_main').innerHTML='<iframe id="scIFrame" name="PMfMuaWQNr1TNH4JLuWa" src="services.html"' +
							'scrolling="no" allowTransparency="true" frameborder="0" width="600" height="500">';
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='services';
	
}

function contact()
{
	pageid='contact';
	document.getElementById('pcontent_main').innerHTML='<iframe id="scIFrame" name="contact" src="contact.html"' +
							'scrolling="no" allowTransparency="true" frameborder="0" width="600" height="500">';
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='contact';
	
}

function mission_links(id)
{
	switch (id)
	{
		case "eddie_williams":
			window.open('http://www.turkanamissions.org','_blank'); 
		break;
		
		case "stephen_westbrook":
			window.open('http://fbcberryville.org','_blank'); 
		break;
	}
}

function ministries()
{
	pageid='ministries';
	document.getElementById('pcontent_main').innerHTML="Coming Soon";
	document.getElementById('pcontent_2').innerHTML="";
	getpagedata();
	lastpage='ministries';
	
}

function announcements()
{
	var html="";
	pageid='announcements';
	getannouncements();
	var type="'ann',";
	len = fcontent.length;
	html += '<table id="announcements" cellspacing="0" >';
	html += '<thead>';
	html += '<tr>';
	html += '<td align="center">Current Announcements</td>';
	if (auth)
	{
		html += '<td colspan="3" align="center">Command</td>';
	}
	html += '</tr>';
	html += '</thead>';
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="7" align="right"></td>';
	html += '</tr>';
	html += '</tfoot>';
	html += '<tbody>';

	for (var i=0;i<len;i++)
	{
		html += '<tr height="23" id='+fid[i]+' onclick="editannouncement('+fid[i]+')" >';
		html += '<td align="left">'+fcontent[i]+'</td>';
		
		if (auth)
		{
			html += '<td width="50"><div align="center">Add';
			html += '<input type="radio" onClick="add('+type+fid[i]+')" name="CMD" value="1" />';
			html += '</div></td>';
			html += '<td width="50"><div align="center">Edit';
			html += '<input type="radio" onClick="edt('+type+fid[i]+')" name="CMD" value="2" />';
			html += '</div></td>';
			html += '<td width="50"><div align="center">Del';
			html += '<input type="radio" onClick="del('+type+fid[i]+')" name="CMD" value="3" />';
			html += '</div></td>';
		}
		html += '</tr>';
	}
		
	html += '</tbody>';
	html += '</table>';
	
	document.getElementById('pcontent_main').innerHTML=html;
	document.getElementById('pcontent_2').innerHTML="";
	lastpage='announcements';
		
}

// @support
function support()
{
	winparameters = {
								divid:		"dialogdiv",
								title:		"Support Contact",
								text:		"",
								width:		550,
								height:		200,
								center:		1,
								resize:		0,
								scrolling:	0,
								html:		'<tr>' +
											'<td><div align="center">' +
											'For business hours support, call the main office (870)246-5553 and ask for LJ' +
									 		'</td>' +
											'</tr>' +
											'<tr><br></tr>' +
											'<tr>' +
											'<td><div align="center">' +
											'For after hours support, call LJ @ (870)403-7593' +
									 		'</td>' +
											'</tr' +
											'<tr><br></tr>' +
											'<tr>' +
											'<td colspan="1"><div align="center">' +
											'<input type="button" value="OK"  class="dialogbutton" onClick="killwindow();" />' +
											'</td>' +
											'</tr>',
								firstinput:	""
							}
		
			createwindow(winparameters); 

}

// @createwindow
function createwindow(parameters)
{
	dialogopen=true;
	var title = parameters['title'];
	var width = "width=" + parameters['width'] + "px";
	var height = "height=" + parameters['height'] + "px";
	var resize = "resize=" + parameters['resize'];
	var scrolling = "scrolling=" + parameters['scrolling'];
	var center = "center=" + parameters['center'];
	var settings = "'" + width + "," + height + "," + resize + "," + scrolling + "," + center + "'";
	var firstinput = parameters['firstinput'];
	var myhtml = "";
	myhtml+= ' <form action="" onsubmit="return false;" name="dialogform" id="dialogform" class="dialog">';
	myhtml+= ' <table id="dialogtable" cellspacing="0">';
	
	myhtml+= parameters['html'];				  
				  
	myhtml+=	'</table>';
	myhtml+=	'</form>';
	
	dialog=dhtmlwindow.open("mywin", "inline", myhtml, title, settings);
	dialog.onclose=
		function () { 
						dialog.hide;
						dialogopen=false;
						clearinput(); 
						return true;
					  }
		
	if (firstinput)
	{
		var element = document.getElementById(firstinput);
	
		// Use a delay so that IE will give focus properly
		setTimeout('document.getElementById("'+firstinput+'").select()', 100)
		
		//document.getElementById(firstinput).value="";
		document.getElementById(firstinput).focus();
	}
	
}

// @killwindow
function killwindow()
{
	dialog.hide();
	dialogopen=false;
}

function processedit(id)
{
	var cmd = currentedit['cmd'];
	var type = currentedit['type'];
	var id = currentedit['id'];
	if (cmd=='edit' || cmd=='add')
	{
		var newvalue = document.getElementById('editor').value;
		killwindow();
	}
	ajaxrequest.open("GET", ajax_url + 'command=processedit&cmd='+cmd+'&type='+type+'&id='+id+'&newvalue='+newvalue, false);
	ajaxrequest.send(null);
	

}

function hidemod()
{
		document.getElementById('edit').innerHTML="";
}

function mod_announcements(cmd,id)
{
	currentedit= 	{
						type:	"announcement",
						cmd:	cmd,
						id:		id
					}
	
	if (cmd=='del')
	{
		if (confirm("Do you really want to delete this announcement?"))
		{
			processedit();
			return;
		}
		else
		{
			killwindow();
			return;
		}
	}
					
	winparameters = {
								title:		"Faith MBC Content Editor",
								width:		550,
								height:		200,
								center:		1,
								resize:		0,
								scrolling:	0,
								html:	'<textarea name="modtext" id="editor" value="'+editvalue+'"cols="1" rows="5"></textarea>' +
										'<input type="button" value="OK" class="dialogbutton" onClick="processedit(this)" />' +
										'<input type="button" value="Cancel"  class="dialogbutton" onClick="killwindow();" />',
								firstinput:	"editor"
							}
		
	createwindow(winparameters); 

}

function mod_video(cmd,id)
{
	//alert("Really " + cmd + " video id # " + id + "?");
	currentedit= 	{
						type:	"video",
						cmd:	cmd,
						id:		id
					}
					
	winparameters = {
								title:		"Faith MBC Content Editor",
								width:		550,
								height:		200,
								center:		1,
								resize:		0,
								scrolling:	0,
								html:	'<textarea name="modtext" id="editor" value="'+editvalue+'"cols="1" rows="5"></textarea>' +
										'<input type="button" value="OK" class="dialogbutton" onClick="processedit(this)" />' +
										'<input type="button" value="Cancel"  class="dialogbutton" onClick="killwindow();" />',
								firstinput:	"editor"
							}
		
	createwindow(winparameters); 


}

function mod_audio(cmd,id)
{
	//alert("Really " + cmd + " video id # " + id + "?");
	currentedit= 	{
						type:	"audio",
						cmd:	cmd,
						id:		id
					}
					
	winparameters = {
								title:		"Faith MBC Content Editor",
								width:		550,
								height:		200,
								center:		1,
								resize:		0,
								scrolling:	0,
								html:	'<textarea name="modtext" id="editor" value="'+editvalue+'"cols="1" rows="5"></textarea>' +
										'<input type="button" value="OK" class="dialogbutton" onClick="processedit(this)" />' +
										'<input type="button" value="Cancel"  class="dialogbutton" onClick="killwindow();" />',
								firstinput:	"editor"
							}
		
	createwindow(winparameters); 


}

function add(type,id)
{
	var cmd="add";
	switch(type)
	{
		case 'ann': 
			mod_announcements(cmd,id);
		break;
		
		case 'vid':
			mod_video(cmd,id);
		break;
		
		case 'aud':
			mod_audio(cmd,id);
		break;
		
		default:
			alert("Cannot be edited");
	
	}
}

function edt(type,id)
{
	var cmd="edit";	
	switch(type)
	{
		case 'ann': 
			mod_announcements(cmd,id);
		break;
		
		case 'vid':
			mod_video(cmd,id);
		break;
		
		default:
			alert("Cannot be edited");
	
	}
}

function del(type,id)
{
	var cmd="del";	
	switch(type)
	{
		case 'ann': 
			mod_announcements(cmd,id);
		break;
		
		case 'vid':
			mod_video(cmd,id);
		break;
		
		default:
			alert("Cannot be edited");
	
	}
	
}

function showmedia(type)
{
	
	switch(type)
	{
		case "audio":
			audio();
		break;
		
		case "video":
			video();
		break;
		
		case "song":
			songs();
		break;
		
	}
	
	/*
	jQuery("#mediatable").jqGrid({
		url:'grid_ajax.php?grid=getmedia&type='+type+'&q=2',
		datatype: "json",
		colNames:['Date', 'Title','Description', 'Click'],
		colModel:[
			{name:'recorddate',index:'recorddate', width:100},
			{name:'title',index:'title', width:200},
			{name:'description',index:'description', width:400},
			{name:'filename',index:'filename', width:0, hidden:true}
		],
		rowNum:20,
		rowList:[10,20],
		imgpath: 'themes/sand/images',
		pager: jQuery('#pager2'),
		sortname: 'recorddate',
		viewrecords: true,
		sortorder: "ASC",
		width: 700,
		height: "100%",
		caption:"Faith Missionary Baptist Church Media Center"
	}).navGrid('#pager2',{edit:false,add:false,del:false})
	.navButtonAdd('#pager2',{caption:"Play Selected File", 
		onClickButton:function(){ 
			var id = jQuery("#mediatable").getGridParam('selrow');
			if(id){ 
				var ret = jQuery("#mediatable").getRowData(id); 
				alert("Media Server is Currently Unavailable");
				//alert("filename="+ret.filename); 
			} else { 
				alert("Please select Row") 
			} 
		}
	}); 
	
	*/
	
}

function audio()
{
	
	var filename;
	var title;
	var recorddate;
	var celldata;
	var image;
	var w='163';
	var h='16';
	var type="'aud',";
	
	pageid='audio';
	
	var html= '<table class="faith" width="100%" border="0" align="center">';
	html += '<thead>';
	html += '<tr>';
	html += '<td colspan="4"><div align="center">10 Newest Audio Files - For all Media <a href="http://itunes.apple.com/us/podcast/sunday-mornings-with-faith/id282106983" target="_blank">Click Here</a> </div></td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td width="15%" align="left">Record Date</td>';
	html += '<td width="20%" align="left">Title</td>';
	html += '<td width="30%" align="left">Description</td>';
	html += '<td width="25%" align="center">Media</td>';
	if (auth)
	{
		html += '<td colspan="3" align="center">Command</td>';
	}	
	html += '</tr>';
	html += '</thead>';
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="7" align="right"></td>';
	html += '</tr>';
	html += '</tfoot>';
	html += '<tbody>';
	
	ajaxrequest.open("GET", ajax_url + 'command=getmedia&type=audio', false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	var len = response.getElementsByTagName('filename').length;
	
	for (var i=0;i<len;i++)
	{
		id = response.getElementsByTagName('id')[i].firstChild.nodeValue;
		recorddate=response.getElementsByTagName('recorddate')[i].firstChild.nodeValue;
		title=response.getElementsByTagName('title')[i].firstChild.nodeValue;
		filename=response.getElementsByTagName('filename')[i].firstChild.nodeValue;
		try
		{
			description=response.getElementsByTagName('description')[i].firstChild.nodeValue;
		}
		catch(err)
		{
			description = title;
		}
		html+='<tr>';
		html+='<td>' + recorddate + '</td>';
		html+='<td>' + title + '</td>';
		html+='<td>' + description +'</td>';
		
		celldata = '<a href="http://www.faith-mbc.com/media/'+filename +'" title="'+title + '" rel="enclosure" onclick="window.open(\'http://embedthevideo.com/popup.php?url=\'+this.href,\'video\',\'width=360,height=175,top=20,left=20,scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=yes,left=0,top=0\');return false"><img src="http://www.faith-mbc.com/images/mp3.gif" alt="'+title+'" border="0" class="thumbnail" /></a><br />';
		//celldata= mediacode(filename,i,w,h,image);
		
		/*'<object id="id'+i+'" type="video/quicktime" width="163" height="16" data="media/' + 
		filename + '"><param name="src" value="media/'+filename+'"/><param name="controller" value="true"/>' +
		'<param name="autoplay" value="false"/><param name="scale" value="tofit"/><param name="volume" value="100"/>' +
		'<param name="loop" value="false"/></object>';
		*/
		
		html+='<td align="center">' + celldata + '</td>';
		if (auth)
		{
			
			html += '<td width="50"><div align="center">Edit';
			html += '<input type="radio" onClick="edt('+type+id+')" name="CMD" value="2" />';
			html += '</div></td>';
			
		}
		html+='</tr>';
		//html+='<tr>';
		//html+='<td colspan="4" align="center"><img src="images/scroll.gif" /></td>';
		//html+='</tr>';
	}
		html+='</tbody>';
		html+='</table>';
	document.getElementById('pcontent_main').innerHTML=html;
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='audio';
	
}



function video()
{
	pageid='video';
	var id;
	var filename;
	var title;
	var recorddate;
	var celldata;
	var image;
	var linkhtml;
	var vidparams=new Array();
	var w='154';
	var h='90';
	var type="'vid',";
	
	var html= '<table class="faith" width="100%" border="0" align="center">';
	html += '<thead>';
	html += '<tr>';
	html += '<td colspan="4"><div align="center">10 Newest Video Files - For all Media <a href="http://itunes.apple.com/us/podcast/faith-video-podcasts/id282106982" target="_blank">Click Here</a> </div></td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td width="15%" align="left">Date</td>';
	html += '<td width="25%" align="left">Title</td>';
	html += '<td width="40%" align="left">Description</td>';
	html += '<td width="20%" align="center">Click to Play</td>';
	if (auth)
	{
		html += '<td colspan="3" align="center">Command</td>';
	}
	html += '</tr>';
	html += '</thead>';
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="7" align="right"></td>';
	html += '</tr>';
	html += '</tfoot>';
	html += '<tbody>';
	
	ajaxrequest.open("GET", ajax_url + 'command=getmedia&type=video', false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	var len = response.getElementsByTagName('filename').length;
	
	for (var i=0;i<len;i++)
	{
		id = response.getElementsByTagName('id')[i].firstChild.nodeValue;
		recorddate=response.getElementsByTagName('recorddate')[i].firstChild.nodeValue;
		title=response.getElementsByTagName('title')[i].firstChild.nodeValue;
		filename=response.getElementsByTagName('filename')[i].firstChild.nodeValue;
		try
		{
			description=response.getElementsByTagName('description')[i].firstChild.nodeValue;
		}
		catch(err)
		{
			description = title;
		}
		html+='<tr>';
		html+='<td>' + recorddate + '</td>';
		html+='<td>' + title + '</td>';
		html+='<td>' + description +'</td>';
		
		
		linkhtml = mediacode(filename,i,w,h);
		videodata[i]=	{
							title:		title,
							html:		linkhtml
						};
						
						
		celldata = '<a href="http://www.faith-mbc.com/media/'+filename +'" title="'+title + '" rel="enclosure" onclick="window.open(\'http://embedthevideo.com/popup.php?url=\'+this.href,\'video\',\'width=360,height=305,top=20,left=20,scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=yes,left=0,top=0\');return false"><img src="http://www.faith-mbc.com/images/qtscreen.gif" alt="'+title+'" border="0" class="thumbnail" /></a><br />';
		
		//<a href="http://www.faith-mbc.com/new/media/'+filename+'">Click here to download</a><br />
						
		//celldata = '<img src="images/qtscreen.gif" id="img'+i+'" onclick="createwindow(\'' + title + '\', \'' + linkhtml + '\')"/>';
		//celldata = '<img id="img'+i+'" onclick="createwindow('+i+')" src="images/qtscreen.gif"/>';
		html+='<td align="center">' + celldata + '</td>';
		
		if (auth)
		{
			
			html += '<td width="50"><div align="center">Edit';
			html += '<input type="radio" onClick="edt('+type+id+')" name="CMD" value="2" />';
			html += '</div></td>';
			
		}
		
		html+='</tr>';
		
		
		
	}
		html+='</tbody>';
		html+='</table>';
		
	document.getElementById('pcontent_main').innerHTML=html;
	document.getElementById('pcontent_2').innerHTML="";
	lastpage='video';
	
}

function songs()
{
	var filename;
	var title;
	var recorddate;
	var celldata;
	var image;
	var w='163';
	var h='16';
	var type="'aud',";
	
	pageid='songs';
	
	var html= '<table class="faith" width="100%" border="0" align="center">';
	html += '<thead>';
	html += '<tr>';
	html += '<td colspan="4"><div align="center">10 Newest Songs - For all Songs <a href="http://itunes.apple.com/us/podcast/songs-of-faith/id282050652" target="_blank">Click Here</a> </div></td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td width="15%" align="left">Record Date</td>';
	html += '<td width="20%" align="left">Title</td>';
	html += '<td width="25%" align="center">Media</td>';
	if (auth)
	{
		html += '<td colspan="3" align="center">Command</td>';
	}	
	html += '</tr>';
	html += '</thead>';
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="7" align="right"></td>';
	html += '</tr>';
	html += '</tfoot>';
	html += '<tbody>';
	
	ajaxrequest.open("GET", ajax_url + 'command=getmedia&type=song', false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	var len = response.getElementsByTagName('filename').length;
	
	for (var i=0;i<len;i++)
	{
		id = response.getElementsByTagName('id')[i].firstChild.nodeValue;
		recorddate=response.getElementsByTagName('recorddate')[i].firstChild.nodeValue;
		title=response.getElementsByTagName('title')[i].firstChild.nodeValue;
		filename=response.getElementsByTagName('filename')[i].firstChild.nodeValue;
	
		html+='<tr>';
		html+='<td>' + recorddate + '</td>';
		html+='<td>' + title + '</td>';
		
		celldata = '<a href="http://www.faith-mbc.com/media/'+filename +'" title="'+title + '" rel="enclosure" onclick="window.open(\'http://embedthevideo.com/popup.php?url=\'+this.href,\'video\',\'width=360,height=175,top=20,left=20,scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=yes,left=0,top=0\');return false"><img src="http://www.faith-mbc.com/images/mp3.gif" alt="'+title+'" border="0" class="thumbnail" /></a><br />';
		//celldata= mediacode(filename,i,w,h,image);
		
		/*'<object id="id'+i+'" type="video/quicktime" width="163" height="16" data="media/' + 
		filename + '"><param name="src" value="media/'+filename+'"/><param name="controller" value="true"/>' +
		'<param name="autoplay" value="false"/><param name="scale" value="tofit"/><param name="volume" value="100"/>' +
		'<param name="loop" value="false"/></object>';
		*/
		
		html+='<td align="center">' + celldata + '</td>';
		if (auth)
		{
			
			html += '<td width="50"><div align="center">Edit';
			html += '<input type="radio" onClick="edt('+type+id+')" name="CMD" value="2" />';
			html += '</div></td>';
			
		}
		html+='</tr>';
		//html+='<tr>';
		//html+='<td colspan="4" align="center"><img src="images/scroll.gif" /></td>';
		//html+='</tr>';
	}
		html+='</tbody>';
		html+='</table>';
	document.getElementById('pcontent_main').innerHTML=html;
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='songs';
	
}

function biblestudy()
{
	var filename;
	var title;
	var description;
	var recorddate;
	var celldata;
	var image;
	var w='163';
	var h='16';
	var type="'aud',";
	
	pageid='biblestudy';
	
	var html= '<table class="faith" width="100%" border="0" align="center">';
	html += '<thead>';
	html += '<tr>';
	html += '<td width="15%" align="left">Record Date</td>';
	html += '<td width="20%" align="left">Week #</td>';
	html += '<td width="20%" align="left">Detail</td>';
	html += '<td width="25%" align="center">Media</td>';
	if (auth)
	{
		html += '<td colspan="3" align="center">Command</td>';
	}	
	html += '</tr>';
	html += '</thead>';
	html += '<tfoot>';
	html += '<tr>';
	html += '<td colspan="7" align="right"></td>';
	html += '</tr>';
	html += '</tfoot>';
	html += '<tbody>';
	
	ajaxrequest.open("GET", ajax_url + 'command=getmedia&type=biblestudy', false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	var len = response.getElementsByTagName('filename').length;
	
	for (var i=0;i<len;i++)
	{
		id = response.getElementsByTagName('id')[i].firstChild.nodeValue;
		recorddate=response.getElementsByTagName('recorddate')[i].firstChild.nodeValue;
		title=response.getElementsByTagName('title')[i].firstChild.nodeValue;
		description=response.getElementsByTagName('description')[i].firstChild.nodeValue;
		filename=response.getElementsByTagName('filename')[i].firstChild.nodeValue;
	
		html+='<tr>';
		html+='<td>' + recorddate + '</td>';
		html+='<td>' + title + '</td>';
		html+='<td>' + description + '</td>';
		
		celldata = '<a href="http://www.faith-mbc.com/media/'+filename +'" title="'+title + '" rel="enclosure" onclick="window.open(\'http://embedthevideo.com/popup.php?url=\'+this.href,\'video\',\'width=360,height=175,top=20,left=20,scrollbars=no,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=yes,left=0,top=0\');return false"><img src="http://www.faith-mbc.com/images/mp3.gif" alt="'+title+'" border="0" class="thumbnail" /></a><br />';
		//celldata= mediacode(filename,i,w,h,image);
		
		/*'<object id="id'+i+'" type="video/quicktime" width="163" height="16" data="media/' + 
		filename + '"><param name="src" value="media/'+filename+'"/><param name="controller" value="true"/>' +
		'<param name="autoplay" value="false"/><param name="scale" value="tofit"/><param name="volume" value="100"/>' +
		'<param name="loop" value="false"/></object>';
		*/
		
		html+='<td align="center">' + celldata + '</td>';
		if (auth)
		{
			
			html += '<td width="50"><div align="center">Edit';
			html += '<input type="radio" onClick="edt('+type+id+')" name="CMD" value="2" />';
			html += '</div></td>';
			
		}
		html+='</tr>';
		//html+='<tr>';
		//html+='<td colspan="4" align="center"><img src="images/scroll.gif" /></td>';
		//html+='</tr>';
	}
		html+='</tbody>';
		html+='</table>';
	document.getElementById('pcontent_main').innerHTML=html;
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='biblestudy';
	
}




function gallery()
{
	var html = '<iframe id="rzframe" src="gallery/index.php?x=browse" scrolling="auto" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:visible; width:100%;"></iframe>';
	pageid='gallery';
	document.getElementById('pcontent_main').innerHTML=html
	document.getElementById('pcontent_2').innerHTML="";
	loadintoIframe('rzframe', 'gallery/index.php?x=browse');
	resizeCaller();
	//getpagedata();
	lastpage='gallery';
	
}

function teamkid(section)
{
	switch(section)
	{
		case 'pk':
			pageid='teamkid_pk';
		break;
		case 'k2':
			pageid='teamkid_k2';
		break;
		case '34a':
			pageid='teamkid_34a';
		break;
		case '4b6':
			pageid='teamkid_4b6';
		break;
		default:
			pageid='teamkid';
	}
		
	var memoryverse = getmemoryverse();
	if (memoryverse!="None")
	{
		document.getElementById('memdiv').style.display="block";
		document.getElementById('memoryverse').innerHTML="This weeks Team Kid Memory Verse: \"" + memoryverse + "\" ";
	}
	else 
	{
		document.getElementById('memdiv').style.display="none";
	}
	document.getElementById('pcontent_main').innerHTML="Coming Soon";
	document.getElementById('pcontent_2').innerHTML="";
	getpagedata();
	lastpage='teamkid';
	
}

function vbs()
{
	pageid='vbs';
	document.getElementById('pcontent_main').innerHTML="Coming Soon";
	document.getElementById('pcontent_2').innerHTML="";
	getpagedata();
	lastpage='vbs';

	
}

function bible()
{
	var html = '<iframe id="scIFrame" src="bible/biblescheduler.html" scrolling="no" allowTransparency="true" frameborder="0" width="600" height="500">';
	pageid='bible';
	document.getElementById('pcontent_main').innerHTML=html
	document.getElementById('pcontent_2').innerHTML="";
	//getpagedata();
	lastpage='bible';
	
	
}


function calendar()
{
	//var html='<iframe id="scIFrame" name="PMfMuaWQNr1TNH4JLuWa" src="faithcal/theme/scrptcal.htm" scrolling="no" frameborder="0" width="775" height="750">';
	var html='<iframe src="http://www.google.com/calendar/embed?title=Faith%20Missionary%20Baptist%20Church&amp;showTitle=0&amp;showNav=0&amp;showTabs=1&amp;height=600&amp;wkst=1&amp;bgcolor=%236c5d84&amp;src=faithmbc%40gmail.com&amp;color=%23A32929&amp;ctz=America%2FChicago" style=" border-width:0 " width="775" height="585" frameborder="0" scrolling="no"></iframe>';	

	var linkhtml = '<a href="javascript:calupdate();">Admin</a>';
	
	pageid='calendar';
	
	document.getElementById('pcontent_main').innerHTML=html;
	document.getElementById('pcontent_2').innerHTML=linkhtml;
	
	//getpagedata();
	lastpage='calendar';
	
}


function calupdate()
{
	var html='<iframe id="scIFrame" name="calupdate" src="faithcal/calupdate.html" scrolling="no" frameborder="0" width="750" height="700">';

	document.getElementById('pcontent_main').innerHTML=html;
	
}

function editannouncement(i)
{
	//alert(i);
	
}
// @verifyuser
function verifyuser()
{
	var verified = 0;
	var admin = 0;
	ajaxrequest.open("GET", ajax_url + 'command=verifypageuser&username=' + userdata['username'] + '&password=' + userdata['password'], false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	try
	{
		verified = response.getElementsByTagName('verified')[0].firstChild.nodeValue;
		admin = response.getElementsByTagName('admin')[0].firstChild.nodeValue;
		
		if (admin==1)
		{
			var html = '<a href="javascript:newpageuser();"><font size="2" color="#FF0000">Add User</font></a>';
			document.getElementById('admin').innerHTML=html;
		}
	
	}
	catch(err)
	{
		
	}
	if (verified==1)
	{
		setCookie('FaithMBC_username',userdata['username'],7);
		checkCookie();
		alert(userdata['username'] + " - Logged in")
		hidelogin();
	}
	else
	{
		alert("Incorrect Username or Password");
		//hidelogin();
		return false;
	}
}

function logout()
{
	deleteCookie('FaithMBC_username');
	alert(userdata['username'] + " - Logged out");
	//document.getElementById('admin').innerHTML="Admin";
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
  	{
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1)
    	{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
    	} 
  	}
	return "";
}


function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function checkCookie()
{
	var username=getCookie('FaithMBC_username');
	if (username!=null && username!="")
	{
		auth=true;
		toggleedit();
	}
	else
	{
		auth=false;
	}
	
	cookiechecked=true;
}

function deleteCookie(name) 
{
	document.cookie = name +
		'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function toggleedit()
{
	//checkcookie();
	
	if (auth)
	{
		if (edit)
		{
			edit=false;
			html='<INPUT type=image name="admin" src="images/key_locked.gif" onClick="toggleedit();">';
			document.getElementById('editicon').innerHTML=html;
			document.onclick = "";
		}
		else
		{
			edit=true
			html='<INPUT type=image name="admin" src="images/key.gif" onClick="toggleedit();">';
			document.getElementById('editicon').innerHTML=html;
			document.onclick = catchIt;
			
		}
	}
}


function pageid()
{
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	
	//sPage = stripafter(sPage, '.');
	
	return(sPage);
}

function fieldid()
{
	var fieldid=1;
	
	return(fieldid);
}

function catchIt(e) {
	//alert(e.id);
	if (editing) return;
	if (!document.getElementById || !document.createElement) return;
	if (!e) 
		var obj = window.event.srcElement;
	else 
		var obj = e.target;
	
	if (obj.tagName == 'TEXTAREA' || obj.tagName == 'A') return;
	if (obj.tagName != 'P' || obj.id.charAt(0)!='p') 
	{
		return;
	}
	//alert(obj.id);
	
	
	if (obj.nodeName == 'HTML') return;
	var x = obj.innerHTML;
	var y = document.createElement('TEXTAREA');
	var z = obj.parentNode;
	myfield=obj.id;
	var val=z.attributes.length
	
	//alert(val);
	z.insertBefore(y,obj);
	z.insertBefore(butt,obj);
	z.removeChild(obj);
	y.value = x;
	y.focus();
	editing = true;
}

function saveEdit() {
	var area = document.getElementsByTagName('TEXTAREA')[0];
	var y = document.createElement('P');
	var z = area.parentNode;
	//alert(z.className);
	//alert(z.id);
	
	origstyle = z.style;
	//alert('Style: ' + origstyle);
	var badchar="'";
	
	y.innerHTML = area.value;
	
	var newstring = escapechars(area.value,badchar);
	var nslen=newstring.length;
	var thischar;
	var ascii;
	var finalstring="";
	//alert(nslen);
	for (var i=0;i< nslen;i++)
	{
		if (newstring.charCodeAt(i)==10)
		{
			finalstring+="<br>"
		}
		else
		{
			finalstring+=newstring.charAt(i);
		}
		//thischar = newstring.charAt(i);
		//ascii = newstring.charCodeAt(i);
		//alert(thischar + " = " + ascii);	
	}
	//alert(finalstring);					 
	
	//newtring = newstring.replace("<br>","\n")
	//alert(newstring);
	//var mypage = pageid();
	//var myfield=z.id;
	var myclass=z.className;

	storechange(pageid, myfield, myclass, finalstring);
	
	z.insertBefore(y,area);
	z.removeChild(area);
	z.removeChild(document.getElementsByTagName('button')[0]);
	editing = false;
}

function storechange(pageid, fieldid, classname, text)
{

	ajaxrequest.open("GET", ajax_url + 'command=updatepage&pageid=' + pageid + '&fieldid=' + 
					 fieldid + '&text=' + text + '&classname=' + classname, false);
	//ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);
	
	location.reload();

}

/*
function getpagedata(pageid, fieldid)
{
	ajaxrequest.open("GET", ajax_url + 'command=getpagedata&pageid=' + pageid + '&fieldid=' + fieldid, false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	var text = response.getElementsByTagName('text')[0].firstChild.nodeValue;
	
	text = escapecr(text);
	
	return(text);
	

}

*/

function nav()
{
	switch (lastpage)
	{
		case 'home':
			gohome();
		break;
		
		case 'history':
			history();
		break;
		
		case 'services':
			services();
		break;
		
		case 'announcements':
			announcements();
		break;
		
		case 'ministries':
			ministries();
		break;
		
		case 'video':
			video();
		break;
		
		case 'audio':
			audio();
		break;
		
		case 'calendar':
			calendar();
		break;
		
		default:
			gohome();
	}
}

// @getpagedata
function getpagedata()
{
	ajaxrequest.open("GET", ajax_url + 'command=getpagedata&pageid=' + pageid, false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	var pagedata=new Array();
	pagedata['id'] = new Array();
	pagedata['text'] = new Array();
	
	
	pagedata['numelements'] = response.getElementsByTagName('id').length;
	
	for (var i=0;i<pagedata['numelements'];i++)
	{
		try
		{

			pagedata['id'][i]=response.getElementsByTagName('id')[i].firstChild.nodeValue;
			pagedata['text'][i]=response.getElementsByTagName('text')[i].firstChild.nodeValue;

			document.getElementById(pagedata['id'][i]).innerHTML = pagedata['text'][i];
		}
		catch(err)
		{
			//alert(err);
			return(false);
			//gohome();
		}
	}
	
	return(true);
	
	

}

function getmemoryverse()
{
	ajaxrequest.open("GET", ajax_url + 'command=getmemoryverse&section=' + pageid, false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;

	var memoryverse=response.getElementsByTagName('verse')[0].firstChild.nodeValue;
	//pagedata['text']=response.getElementsByTagName('text')[i].firstChild.nodeValue;
	
	return(memoryverse);

}


function reloadpage()
{
	window.location = 'http://www.faith-mbc.com';
}

// @updatecomplete
function updatecomplete(id)
{
	ajaxrequest.open("GET", ajax_url + 'command=getbibleuser&id=' + id, false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);

	var response = ajaxrequest.responseXML.documentElement;
	try
	{
		var fullname = response.getElementsByTagName('fullname')[0].firstChild.nodeValue;
		var sequence = response.getElementsByTagName('sequence')[0].firstChild.nodeValue;
		var reading1 = response.getElementsByTagName('reading1')[0].firstChild.nodeValue;
		var reading2 = response.getElementsByTagName('reading2')[0].firstChild.nodeValue;
		var reading3 = response.getElementsByTagName('reading3')[0].firstChild.nodeValue;
	}
	catch(err)
	{
		alert("An error has occured, please update your account again");
		return(false)
	}

	
	winparameters = {
								divid:		"dialogdiv",
								title:		"Profile Updated",
								text:		"",
								width:		350,
								height:		300,
								center:		1,
								resize:		0,
								scrolling:	0,
								html:		'<tr>' +
											'<td>' +
											'Thanks for following through, your profile has been updated!' +
											'</td>' +
											'</tr>' +
											'<tr>' +
											'<td>&nbsp;</td>' +
											'</tr>' +
											'<tr>' +
											'<td>' +
											'Keep up the good work and remember -  it is not what God can do for you, ' +
											'it is all about what you can do for God. Reading and learning about Him ' +
											'is one way you can make a change in your life and your way of thinking.' +
											'</td>' +
											'</tr>' +
											'</table>' +
											'<table id="verses" cellspacing="1">' +
											'<tr>' +
											'<td colspan="3">' +
											'Here are your next set of daily verses (will also be emailed)' +
											'</td>' +
											'<tr>' +
											'<td>&nbsp;</td>' +
											'</tr>' +
											'<tr>' +
											'<td width="150px">Reading 1</td>' +
											'<td width="200px">Reading 2</td>' +
											'<td width="150px">Reading 3</td>' +
											'</tr>' +
											'</thead>' +
											'<tbody>' +
											'<tr>' +
											'<td>' + reading1 +'</td>' +
											'<td>' + reading2 +'</td>' +
											'<td>' + reading3 +'</td>' +
											'</tr>' +
											'<tr>' +
											'<td colspan=3 align="center">' +
											'<input type="button" value="Close" class="buttons_black" onClick="reloadpage();" />' +
											'</td>' +
											'</tr>',
								firstinput:	""
							}
		
			createwindow(winparameters); 
	
}

// @newuser
function newpageuser()
{
	
	var html = 	'<div id="formcontainer">' +
  				'<div id="leftSide">' +
	  			'<h1>New User Information </h1>' +
	  			'<hr size="1">' +
				'<form action="" onsubmit="return false;" name="adduserform" id="adduserform" class="form">' +
				
				'<div class="clear"></div>' +
				'<div class="holder">' +
				'<label for="name">Username</label>' +
				'<div class="clear"></div>' +
    			'<div class="div_texbox">' +
    			'<input name="username" type="text" class="textbox" id="username" value="" />' +
				'</div>' +
				'<div class="clear"></div>' +
				'</div>' +
				'<div class="holder">' +
				'<label for="address">Password</label>' +
				'<div class="clear"></div>' +
				'<div class="div_texbox">' +
				'<input name="password" type="text" class="textbox" id="password" value="" />' +
				'</div>' +
				'<div class="clear"></div>' +
				'</div>' +
				'<div class="clear"></div>' +
				'<div class="holder">' +
				'<label for="name">Master Password</label>' +
				'<div class="clear"></div>' +
    			'<div class="div_texbox">' +
    			'<input name="mpassword" type="password" class="textbox" id="mpassword" value="" />' +
				'</div>' +
				'<div class="holder">' +
				'<div class="clear"></div>' +
				'<div class="clear"></div>' +
				'</div>' +
				'<div class="button_div">' +
				'<input name="Submit" type="button" value="Add" class="buttons" onClick="addpageuser();" />' +
				'</div>' +
				'</form>' +
				'<div class="clear"></div>' +
				<!-- Personal details end -->
				'</div>' +
				'<div id="rightSide">' +
				'<p>Welcome to Faith Missionary\'s Bible Reading Program.  This schedule will give you verses to read daily and if followed will allow you to finish the Bible in one year.</p>' +
				'</div>' +
				'<div class="clear"></div>' +
				'</div>';
	
	document.getElementById('pcontent_main').innerHTML = html;


}

// @adduser
function addpageuser()
{
	var mpassword = document.getElementById('mpassword').value;
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;
	
	ajaxrequest.open("GET", ajax_url + 'command=validatemaster&password=' + mpassword, false);
	ajaxrequest.onreadystatechange = handlehttpresponse_xml;
	ajaxrequest.send(null);
	
	var response = ajaxrequest.responseXML.documentElement;
	var validated = response.getElementsByTagName('validated')[0].firstChild.nodeValue;
	if (validated==1)
	{
		ajaxrequest.open("GET", ajax_url + 'command=addpageuser&username=' + username + '&password=' + password, false);
		ajaxrequest.onreadystatechange = handlehttpresponse_xml;
		ajaxrequest.send(null);
		
		var response = ajaxrequest.responseXML.documentElement;
		var userstatus = response.getElementsByTagName('userstatus')[0].firstChild.nodeValue;
		if (userstatus=='clear')
		{
			alert("New User Added");
			if (confirm("New User Added - Add Another?"))
			{
				newpageuser;
			}
			else
			{
				//window.location = 'http://www.faith-mbc.com';
			}
		}
	}
	else
	{
		alert("Incorrect Master Password")
		
		//window.location = 'http://www.faith-mbc.com';
	}
	
}


