var ajax_obj= new Array();
var box_array = new Array();
var box_border = 1;
var box_drag_obj;
var box_x;
var box_y;
var col_num = 2;
var cookie_use = false;
var cookie_count = 0;
var date = new Date();
var dest_obj = false;
var doc_height = false;
var doc_height_scroll = false;
var drag_area_width = false;
var drag_clear = false;
var drag_obj = false;
var drag_obj_child = false;
var drag_obj_parent = false;
var drag_clear = false;
var drop_box;
var drop_count = -1;
var img_max = 'http://www.opengospel.com/images/icons/bullet_max.gif';
var img_min = 'http://www.opengospel.com/images/icons/bullet_min.gif';
var load_html = '<div style="padding:5px;" align="center"><img src="http://www.opengospel.com/images/loading.gif" alt="" width="16" height="16" /></div>';
var month = new Array(12);
	month[0] = "jan"
	month[1] = "feb"
	month[2] = "mar"
	month[3] = "apr"
	month[4] = "may"
	month[5] = "jun"
	month[6] = "jul"
	month[7] = "aug"
	month[8] = "sep"
	month[9] = "oct"
	month[10] = "nov"
	month[11] = "dec"
var mouse_x;
var mouse_y;
var move_ok = true;
var scroll_active = false;
var scroll_speed = 4;
var ua = navigator.userAgent.toLowerCase();

function box_get(col_index,box_height,external_url,unique_id) {
	box_index++;
	var div = document.createElement('DIV');
	div.className = 'box_0';
	div.id = 'box_' + box_index;
	box_get_head(div,external_url);
	box_get_body(div,box_height);
	var obj = document.getElementById('op_col_' + col_index);
	obj.appendChild(div);
	box_array[box_index] = new Array();
	box_array[box_index]['obj'] = div;
	box_array[box_index]['parent_obj'] = div.parentNode;
	box_array[box_index]['unique_id'] = unique_id;
	box_array[box_index]['box_height'] = box_height;
	return box_index;
}

function box_get_body(parent_obj,box_height) {
	var div = document.createElement('DIV');
	div.id = 'box_body_' + box_index;
	parent_obj.appendChild(div);
}

function box_get_drag() {
	return false;
}

function box_get_drop() {
	drop_box = document.createElement('DIV');
	drop_box.className = 'box_drop';
	drop_box.id='drop_box';
	drop_box.style.display = 'none';
	document.body.appendChild(drop_box);
}

function box_get_head(parent_obj,external_url) {
	var div = document.createElement('DIV');
	div.className = 'box_head';
	div.style.cursor = 'move';
	div.id = 'box_head_' + box_index;
	div.onmousedown = box_get_init;

	var image = document.createElement('IMG');
	image.id = 'box_hide_' + box_index;
	image.src = img_min;
	image.style.width = '16px';
	image.style.height = '16px';
	image.style.cursor = 'pointer';
	image.onmousedown = box_pop;
	div.appendChild(image);

	var span = document.createElement('SPAN');
	span.id = 'box_name_' + box_index;
	span.onmousedown = box_pop;
	div.appendChild(span);
	parent_obj.appendChild(div);

	var feed = document.createElement('DIV');
	feed.id = 'box_feed_' + box_index;
	feed.style.width = '17px';	
	div.appendChild(feed);

	var yhoo = document.createElement('DIV');
	yhoo.id = 'box_yhoo_' + box_index;		
	div.appendChild(yhoo);
}

function box_get_html(boxid, xml) {
	var item_ct = xml.getElementsByTagName("item").length;
	var item_name = xml.getElementsByTagName("title");
	var item_link = xml.getElementsByTagName("link");
	var item_jpeg = xml.getElementsByTagName("comments");
	var item_desc = xml.getElementsByTagName("description");
	var feed = item_name[0].childNodes[0].nodeValue.split(' - ');
	var name = '<a href="javascript:;" class="tab_link_0">'+feed[1]+'</a> ('+item_ct+')';
	var html = '';
	if (item_ct > 0) {
		if (boxid == 5) {
			html += '<div class="box_1">';
			html += '<div class="box_head" style="margin-left:22px;padding:0px 0px 5px 0px;"><span id="box_name_'+boxid+'"></span><div id="box_feed_'+boxid+'"></div><div id="box_yhoo_'+boxid+'"></div></div>';
			html += '<div class="box_2"><div class="box_3"><div class="box_4" style="padding:0px;">';
			if (item_ct > 4) { item_ct = 4; }
			html += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
			html += '<tr><td>';			
			for (var i=1;i < ((item_ct)+1);i++) {
				var item_url = item_link[i].childNodes[0].nodeValue.split('?uid=');
				if (i == 1) { var display = ''; } else { var display = 'none'; }
				html += '<div id="news_'+i+'" style="display:'+display+';padding:5px 5px 0px;"><div style="float:left;width:175px;">';
				html += '<a href="/index.html?uid='+item_url[1]+'" style="border:none;"><img src="'+item_jpeg[(i-1)].childNodes[0].nodeValue+'" width="165" height="120" class="image"></a>';
				html += '</div><div style="float:left;width:145px;">';
				html += '<h2><a href="/index.html?uid='+item_url[1]+'">'+item_name[i].childNodes[0].nodeValue+'</a></h2>'+item_desc[i].childNodes[0].nodeValue;
				html += '</div></div>';
			}
			html += '</tr></td></table>';	
			html += '<table width="100%" border="0" cellspacing="5" cellpadding="0">';
			html += '<tr>';
			for (var i=1;i < ((item_ct)+1);i++) {
				if (item_name[i]) {
					html += '<td width="50%" valign="top" class="box_2">';
					html += '<table width="100%" border="0">';
					html += '<tr>';
					html += '<td valign="top"><a href="javascript:news_get('+i+','+item_ct+');" style="border:none;"><img src="'+item_jpeg[(i-1)].childNodes[0].nodeValue+'" width="31" height="23" class="image"></a></td>';
					html += '<td valign="top" width="100%"><a href="javascript:news_get('+i+','+item_ct+');" class="link">'+item_name[i].childNodes[0].nodeValue+'</a></td>';
					html += '</tr>';
					html += '</table>';
					html += '</td>';
					if (i == 2) {
						html += '</tr>';
						html += '<tr>';						
					}
				}
			}			
			html += '<div style="clear:both;height:0px;"></div>';
			html += '</div></div></div></div>';
			name = feed[1]+' ('+item_ct+')';
		} else if (boxid == 3) {
			html += '<div style="padding:0px 5px 5px 5px;">';
			for (var i=1;i < ((item_ct)+1);i++) {
				var item_url = item_link[i].childNodes[0].nodeValue.split('?uid=');
				if (item_url[1]) {
					html += '<div class="box_row"><img src="http://www.opengospel.com/images/icons/date.gif" alt="" width="16" height="16" align="absmiddle" style="padding-top:3px;" /><a href="/index.html?uid='+item_url[1]+'">'+item_name[i].childNodes[0].nodeValue+'</a>';
					html += '<div class="box_row" style="border:none; margin:0px 0px 0px 21px;"><span class="desc">'+item_desc[i].childNodes[0].nodeValue+'</span></div>';
				}
			}
			html += '</div>';
		} else {
			html += '<div style="padding:0px 5px 5px 5px;">';
			for (var i=1;i < ((item_ct)+1);i++) {
				var item_url = item_link[i].childNodes[0].nodeValue.split('?uid=');
				if (item_url[1]) {
					html += '<div class="box_row"><img src="http://www.opengospel.com/images/icons/page.gif" alt="" width="16" height="16" align="absmiddle" style="padding-top:3px;" /><a href="/index.html?uid='+item_url[1]+'">'+item_name[i].childNodes[0].nodeValue+'</a>';
					html += '<div class="box_row" style="border:none; margin:0px 0px 0px 21px;"><span class="desc">'+item_desc[i].childNodes[0].nodeValue+'</span></div>';
				}
			}
			html += '</div>';
		}
	}
	var rss_url = item_link[0].childNodes[0].nodeValue.split('?');
	document.getElementById('box_body_' + boxid).innerHTML = html;
	if (document.getElementById('box_name_' + boxid)) {
		document.getElementById('box_name_' + boxid).innerHTML = name;
		if ((boxid == 3) || (boxid == 5)) {
			document.getElementById('box_feed_' + boxid).innerHTML = '<a href="xml/op.php?'+rss_url[1]+'" target="_blank"><img src="http://www.opengospel.com/images/icons/rss.gif" alt="" border="0" style="padding-right:1px;"/></a>';
			document.getElementById('box_yhoo_' + boxid).innerHTML = '<a href="http://us.rd.yahoo.com/my/atm/'+feed[0]+'/'+item_name[0].childNodes[0].nodeValue+'http://add.my.yahoo.com/rss?url='+item_link[0].childNodes[0].nodeValue+'" target="_blank"><img src="http://www.opengospel.com/images/icons/yahoo_add.gif" alt="" border="0" /></a>';
		}
	}
}

function box_get_init(e) {
	drop_count = 1;
	if (document.all) e = event;
	if (e.target) source = e.target;
		else if (e.srcElement) source = e.srcElement;
	if (source.nodeType == 3)
			source = source.parentNode;
	if (source.tagName.toLowerCase()=='img' || source.tagName.toLowerCase()=='a' || source.tagName.toLowerCase()=='input' || source.tagName.toLowerCase()=='td' || source.tagName.toLowerCase()=='tr' || source.tagName.toLowerCase()=='table') return;
	mouse_x = e.clientX;
	mouse_y = e.clientY;
	var numeric_id = this.id.replace(/[^0-9]/g,'');
	box_x = pos_l_get(this.parentNode)/1;
	box_y = pos_t_get(this.parentNode)/1 - document.documentElement.scrollTop;
	drag_obj = this.parentNode;
	doc_height_scroll = document.documentElement.scrollHeight + 100 + drag_obj.offsetHeight;
	if (drag_obj.nextSibling) {
		drag_obj_child = drag_obj.nextSibling;
		if (drag_obj_child.tagName!='DIV') drag_obj_child = drag_obj_child.nextSibling;
	}
	drag_obj_parent = box_array[numeric_id]['parent_obj'];
	drop_count = 0;
	box_get_time();
	return false;
}

function box_get_move(e){
	if (document.all) e = event;
	try { if (drop_count < 10) return; } catch (e) {}
	if  ((drag_obj) && (document.body!=drag_obj.parentNode)) {
		drag_obj.style.width = (drag_obj.offsetWidth - (box_border * 2)) + 'px';
		drag_obj.style.position = 'absolute';
		drag_obj.style.textAlign = 'left';
		if(drag_clear){
			drag_obj.style.filter = 'alpha(opacity=70)';
			drag_obj.style.opacity = '0.7';
		}
		drag_obj.parentNode.insertBefore(drop_box,drag_obj);
		drop_box.style.display='block';
		document.body.appendChild(drag_obj);
		drop_box.style.width = drag_obj.style.width;
		drop_box.style.height = (drag_obj.offsetHeight - (box_border * 2)) + 'px';
	}
	if (e.clientY < 50 || e.clientY > (doc_height-50)) {
		if (e.clientY < 50 && !scroll_active) {
			scroll_active = true;
			box_get_scroll((scroll_speed*-1),e.clientY);
		}
		if (e.clientY > (doc_height - 50) && document.documentElement.scrollHeight <= doc_height_scroll && !scroll_active) {
			scroll_active = true;
			box_get_scroll(scroll_speed,e.clientY);
		}
	} else {
		scroll_active = false;
	}
	var pos_l = e.clientX;
	var pos_t = e.clientY + document.documentElement.scrollTop;
	drag_obj.style.left = (e.clientX - mouse_x + box_x) + 'px';
	drag_obj.style.top = (box_y - mouse_y + e.clientY + document.documentElement.scrollTop) + 'px';
	if (!move_ok) return;
	move_ok = false;
	dest_obj = false;
	drop_box.style.display = 'none';
	var obj_found = false;
	var tmp_parent_array = new Array();
	if (!obj_found) {
		for (var no = 1; no < box_array.length; no++) {
			if (box_array[no]['obj'] == drag_obj) continue;
			tmp_parent_array[box_array[no]['obj'].parentNode.id] = true;
			if (!obj_found) {
				var tmp_x = pos_l_get(box_array[no]['obj']);
				var tmp_y = pos_t_get(box_array[no]['obj']);
				if (pos_l > tmp_x && pos_l < (tmp_x + box_array[no]['obj'].offsetWidth) && pos_t > (tmp_y - 20) && pos_t < (tmp_y + (box_array[no]['obj'].offsetHeight / 2))) {
					dest_obj = box_array[no]['obj'];
					dest_obj.parentNode.insertBefore(drop_box,box_array[no]['obj']);
					drop_box.style.display = 'block';
					obj_found = true;
					break;
				}
				if (pos_l > tmp_x && pos_l < (tmp_x + box_array[no]['obj'].offsetWidth) && pos_t >= (tmp_y + (box_array[no]['obj'].offsetHeight / 2)) && pos_t <( tmp_y + box_array[no]['obj'].offsetHeight)) {
					obj_found = true;
					if (box_array[no]['obj'].nextSibling) {
						dest_obj = box_array[no]['obj'].nextSibling;
						if (!dest_obj.tagName) dest_obj = dest_obj.nextSibling;
						if (dest_obj != drop_box) dest_obj.parentNode.insertBefore(drop_box,dest_obj);
					} else {
						dest_obj = box_array[no]['obj'].parentNode;
						box_array[no]['obj'].parentNode.appendChild(drop_box);
					}
					drop_box.style.display = 'block';
					break;
				}
				if (!box_array[no]['obj'].nextSibling && pos_l>tmp_x && pos_l < (tmp_x + box_array[no]['obj'].offsetWidth) && pos_t > pos_t > (tmp_y + (box_array[no]['obj'].offsetHeight))){
					dest_obj = box_array[no]['obj'].parentNode;
					box_array[no]['obj'].parentNode.appendChild(drop_box);
					drop_box.style.display = 'block';
					obj_found = true;
				}
			}
		}
	}
	if (!obj_found) {
		for (var no = 1; no <= col_num; no++) {
			if (!obj_found) {
				var obj = document.getElementById('op_col_' + no);
				var left = pos_l_get(obj)/1;
				var width = obj.offsetWidth;
				if (pos_l > left && pos_l < (left+width)) {
					dest_obj = obj;
					obj.appendChild(drop_box);
					drop_box.style.display='block';
					obj_found=true;
				}
			}
		}
	}
	setTimeout('move_ok=true',5);
}

function box_get_pick(e) {
	if (document.all) e = event;
	if (e.target) source = e.target;
		else if (e.srcElement) source = e.srcElement;
		if (source.nodeType == 3)
			source = source.parentNode;
	if (source.tagName.toLowerCase() == 'input') return true;
	if (drop_count>=0) return false; else return true;
}

function box_rss_get(url, boxid, col) {
	if (col != 0) { box_get(col, 0, true); }
	if (cookie_use) {
		if (!cookie_rss_src[url]) {
			cookie_rss_src[url] = cookie_count;
			set_cookie(cookie + cookie_count,url,60000);
			cookie_count++;
		}
	}
	if (!document.getElementById('box_body_'+boxid).innerHTML) document.getElementById('box_body_'+boxid).innerHTML = load_html;
	if (url.length>0 && url!='undefined') {
		var ajax_index = ajax_obj.length;
		if (ua.indexOf('msie') != -1) {
			ajax_obj[ajax_index] = new ActiveXObject("Msxml2.XMLHTTP");
		} else {
			ajax_obj[ajax_index] = new XMLHttpRequest();
		}
		ajax_obj[ajax_index].onreadystatechange = function box_rss_get_xml() {
			if (ajax_obj[ajax_index].readyState == 4) {
				if (ajax_obj[ajax_index].status == 200) {
					var xml = ajax_obj[ajax_index].responseXML;
					box_get_html(boxid, xml);
					ajax_obj[ajax_index] = false;
				} else {
					alert("There was an error while retrieving the URL: " + ajax_obj[ajax_index].statusText);
				}
			}
			return true;
		}
		ajax_obj[ajax_index].open("GET",url, true);
		ajax_obj[ajax_index].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax_obj[ajax_index].send(null);
	}
}

function box_get_scroll(direction,pos_y) {
	if (document.documentElement.scrollHeight>doc_height_scroll && direction>0) return;
	window.scrollBy(0,direction);
	if (direction < 0) {
		if (document.documentElement.scrollTop > 0) {
			drag_obj.style.top = (box_y - mouse_y + pos_y + document.documentElement.scrollTop) + 'px';
		} else {
			scroll_active = false;
		}
	} else {
		if (pos_y > (doc_height - 50)) {
			drag_obj.style.top = (box_y - mouse_y + pos_y + document.documentElement.scrollTop) + 'px';
		} else {
			scroll_active = false;
		}
	}
	if (scroll_active) setTimeout('box_get_scroll('+direction+',' + pos_y + ')',5);
}

function box_get_stop() {
	if (drop_count < 10) {
		drop_count = -1
		return;
	}
	drop_count = -1;
	if (drag_clear) {
		drag_obj.style.filter = null;
		drag_obj.style.opacity = null;
	}
	drag_obj.style.position = 'static';
	drag_obj.style.width = null;
	var numeric_id = drag_obj.id.replace(/[^0-9]/g,'');
	if (dest_obj && dest_obj.id!=drag_obj.id) {
		if (dest_obj.id.indexOf('op_col') >= 0) {
			dest_obj.appendChild(drag_obj);
			box_array[numeric_id]['parent_obj'] = dest_obj;
		} else {
			dest_obj.parentNode.insertBefore(drag_obj,dest_obj);
			box_array[numeric_id]['parent_obj'] = dest_obj.parentNode;
		}
	} else {
		if (drag_obj_child) {
			drag_obj_parent.insertBefore(drag_obj,drag_obj_child);
		} else {
			drag_obj_parent.appendChild(drag_obj);
		}
	}
	scroll_active = false;
	drop_box.style.display = 'none';
	drag_obj = false;
	drag_obj_child = false;
	dest_obj = false;
	if (cookie_use) setTimeout('cookie_put()',100);
	doc_height = document.documentElement.clientHeight;
}

function box_get_time() {
	if (drop_count >= 0 && drop_count < 10) {
		drop_count++;
		setTimeout('box_get_time()',10);
		return;
	}
}

function box_pop() {
	var numeric_id = this.id.replace(/[^0-9]/g,'');
	var hide = document.getElementById('box_hide_' + numeric_id);
	var obj = document.getElementById('box_body_' + numeric_id);
	obj.style.display = hide.src.indexOf(img_min) >= 0 ? 'none':'block';
	hide.src = hide.src.indexOf(img_min) >= 0 ? img_max:img_min
	setTimeout('drop_count=-5',5);
}

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

function cookie_get(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function cookie_put(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function err_pop(id, msg) {
	var err = document.getElementById(id);
	if (err) {
		err.innerHTML = msg;
		err.style.display = 'block';
	//	setTimeout('err.style.display = \'none\'',5000);
	}
}

function find_get() {
	var q = document.find.q.value;
	document.getElementById('find_html').innerHTML = load_html;
	if (ua.indexOf('msie') != -1) {
		find_get_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		find_get_request = new XMLHttpRequest();
	}
	find_get_request.onreadystatechange = function find_get_xml() {
		if (find_get_request.readyState == 4) {
			if (find_get_request.status == 200) {
				var xml = find_get_request.responseXML;
				var result_ct = xml.getElementsByTagName("result").length;
				var id = xml.getElementsByTagName("id");
				var name = xml.getElementsByTagName("name");
				var teaser = xml.getElementsByTagName("teaser");
				var url = xml.getElementsByTagName("url");
				var list_ct = 0;
				var start = 0;
				var limit = 10;
				for (i=0;i<(result_ct/limit);i++) {
					list_ct++;
				}
				var html = '';
				if (result_ct > 0) {
					html += '<div style="padding:10px 5px 0px;" valign="center">';
					html += '<div style="float:left;" id="findtext">Results <b>'+(start+1)+' - ';
					if ((parseInt(start)+parseInt(limit)) > parseInt(result_ct)) {
						html += result_ct;
					} else {
						html += parseInt(start+limit)-1;
					}					
					html += '</b> of <b>'+result_ct+'</b> for <b>'+q+'</b></div>';
					html += '<div style="float:right;">';
					html += '<form id="findlists" name="findlists">Page: <select onchange="javascript:find_pop(this.value,'+list_ct+','+limit+','+result_ct+');">';
					for (i=0;i<list_ct;i++) {
						html += '<option value="'+i+'">'+(i+1)+'</option>';
					}
					html += '</select> of '+list_ct+'<input name="q" type="hidden" id="q" value="'+q+'" /></form></div>';
					html += '<div style="clear:both;height:0px;"></div>';
					html += '</div>';
					html += '<div>';
					for (i=0;i<list_ct;i++) {						
						html += '<ol id="findlist_'+i+'" start="'+(start+1)+'" style="margin-top:0px;display:';
						if (i == 0) {
							html += 'block;';
						} else {
							html += 'none;';
						}
						html += '" >';
						for (j=start;j<(start+limit);j++) {
							if (id[j]) {
								html += '<li style="padding:5px 0px"><a href="/index.html?uid='+id[j].childNodes[0].nodeValue+'";>'+name[j].childNodes[0].nodeValue+'</a><br />'+teaser[j].childNodes[0].nodeValue+'<br /><span class="smallprint" style="color:#999999;">'+url[j].childNodes[0].nodeValue+'</span></li>';								
							}
						}	
						start = j;					
						html += '</ol>';
					}
					html += '</div>';
				} else {
				//	not found.
				}
				document.getElementById('find_html').innerHTML = html;
			} else {
				alert("There was an error while retrieving the URL: " + find_get_request.statusText);
			}
		}
		return true;
	}
	find_get_request.open("POST", "xml/op.php", true);
	find_get_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	find_get_request.send('opid=find_get&q='+q);
}

function find_pop(id, list_ct, limit, result_ct) {
	var findtext = document.getElementById('findtext');	
	var findlist = document.getElementById('findlist_'+id);
	var q = document.findlists.q.value;
	var html = '';
	var start = (parseInt(id)*parseInt(limit))+1;
	if (findlist.style.display == 'none') {
		for (i=0;i<list_ct;i++) {
			document.getElementById('findlist_'+i).style.display = 'none';
		}
		findlist.style.display = 'block';
	} else {
		findlist.style.display = 'none';
	}
	html += 'Results <b>'+start+' - ';
	if ((parseInt(start)+parseInt(limit)) > parseInt(result_ct)) {
		html += result_ct;
	} else {
		html += parseInt(start+limit)-1;
	}
	html += '</b> of <b>'+result_ct+'</b> for <b>'+q+'</b>';
	findtext.innerHTML = html;
}

function list_get(parid, iptid, divid, text) {
	if (ua.indexOf('msie') != -1) {
		list_get_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		list_get_request = new XMLHttpRequest();
	}
	list_get_request.onreadystatechange = function list_get_xml() {
		if (list_get_request.readyState == 4) {
			if (list_get_request.status == 200) {
				var xml = list_get_request.responseXML;
				var item_ct = xml.getElementsByTagName("item").length;
				var item_id = xml.getElementsByTagName("id");
				var item_nm = xml.getElementsByTagName("name");
				var html  = '<select id="'+iptid+'">';
					html += '<option value="0">'+text+'</option>';
				if (item_ct > 0) {
					for (i=0;i<item_ct;i++) {
						html += '<option value="'+item_id[i].childNodes[0].nodeValue+'">'+item_nm[i].childNodes[0].nodeValue+'</option>';
					}
				} else {
					html += '<option value="0">No options available.</option>';
				}
				html += '</select>';
				document.getElementById(divid).innerHTML = html;
			} else {
				alert("There was an error while retrieving the URL: " + list_get_request.statusText);
			}
		}
		return true;
	}
	list_get_request.open("GET", "xml/op.php?opid=list_get&parid="+parid, true);
	list_get_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	list_get_request.send(null);
}

function mode_get(id) {
	var usrid = document.params.usrid;
	var stsid = document.params.stsid;
	var pmode = document.params.pmode;
	var mode = document.getElementById('mode_'+id);
	var html = '';
	var oid = cookie_get('oid');
	if (oid) {
		oid = oid.split('|');
	}
	for(i=0;i<=4;i++) {
		if (document.getElementById('tab_'+i)) {
			if (i == id) {
				document.getElementById('tab_'+id).className = 'tab_1';
				document.getElementById('mode_'+id).style.display = '';
			} else {
				document.getElementById('tab_'+i).className = 'tab_0';
				document.getElementById('mode_'+i).style.display = 'none';
			}
		}
	}
	switch (parseInt(id)) {
		case 0:
			box_index = 0;
			html += '<div style="padding:5px 5px 0px; width:735px;">';
			html += '<div id="op_col_1" style="width:365px;float:left;"><div style="clear:both;height:0px;"></div><div id="box_body_5"></div></div>';
			html += '<div id="op_col_2" style="width:365px;float:right;"><div style="clear:both;height:0px;"></div></div>';
			html += '<div style="clear:both;height:0px;"></div>';
			html += '</div>';
			mode.innerHTML = html;

			box_get_drop();
			if (cookie_use) {
				box_rss_get_w_cookie();
			}
			if (cookie_count == 0) {
				box_rss_get('xml/op.php?opid=rss_get&typid=2',1,1);
				box_rss_get('xml/op.php?opid=rss_get&typid=4',2,1);
				box_rss_get('xml/op.php?opid=rss_get&typid=5',5,0);
			}
			box_rss_get('xml/op.php?opid=rss_get&typid=6',3,2);
			box_rss_get('xml/op.php?opid=rss_get&typid=3',4,2);
			setTimeout('document.body.onmousemove = box_get_move;',3000);
			document.body.onmouseup = box_get_stop;
			document.body.onselectstart = box_get_pick;
			document.body.ondragstart = box_get_drag;
			doc_height = document.documentElement.clientHeight;
		break
		case 1:
			if (usrid.value != 0) {
				if (oid) {
					var val = '|||'+oid[3]+'|'+oid[4];
				} else {
					var val = '||||';
				}
				cookie_put('oid', val, 14);
			//	cookie_del('oid');
				location.href = 'index.html';
			} else {
				html += '<div style="padding:5px 5px 0px; width:735px;">';
				html += '<div style="width:365px;float:left;">';

				html += '<div class="box_1"><div class="box_2"><div class="box_3"><div class="box_4"><form name="signup" id="signup">';
				html += '<h2>Personalize your experience.</h2>';
        		html += 'It\'s easy and free. Register your email to begin enjoying the convenience	that comes with a customized site!<br />';
				html += '<div style="padding:5px 0px 0px;"><table cellpadding="0" cellspacing="0"><tr><td><span class="fineprint">First Name</span><br /><input name="fn" type="text" id="fn" /></td><td>&nbsp;&nbsp;</td><td><span class="fineprint">Last Name</span><br /><input name="ln" type="text" id="ln" /></td></tr></table></div>';
				html += '<div style="padding:5px 0px 0px;"><table cellpadding="0" cellspacing="0"><tr>';
				html += '<td><span class="fineprint">Gender</span><br /><select name="sx" id="sx"><option value="0"  selected>- Select One -</option><option value="M" >Male</option><option value="F" >Female</option></select></td><td>&nbsp;&nbsp;</td>';
				html += '<td><span class="fineprint">Zip Code</span><br /><input name="zp" type="text" id="zp" size="15" maxlength="15" /></td></tr></table></div>';
				html += '<div style="padding:5px 0px 0px;"></div>';
				html += '<div style="padding:5px 0px 0px;"><span class="fineprint">Email</span><br /><input name="ea" type="text" id="ea" /></div>';
				html += '<div style="padding:5px 0px 0px;"><table cellpadding="0" cellspacing="0"><tr><td><span class="fineprint">Password</span><br /><input name="pw1" type="password" id="pw1" /></td><td>&nbsp;&nbsp;</td><td><span class="fineprint">Re-type Password</span><br /><input name="pw2" type="password" id="pw2" /></td></tr></table></div>';
				html += '<div style="padding:5px 0px 0px;"></div>';
				html += '<div style="padding:5px 0px 0px;"><span class="fineprint">Security Question</span><br /><div id="op_sq"></div></div>';
				html += '<div style="padding:5px 0px 0px;"><span class="fineprint">Your Answer</span><br /><input name="sa" type="text" id="sa" size="20" maxlength="20" /></div>';
				html += '<div style="padding:5px 0px 0px;"><input name="ts" type="checkbox" id="ts" value="1" style="border:0px;" /><span class="fineprint">';
				html += 'I have read and agree to the Terms of Service and Privacy Policy, and to receive important communications electronically. ';
				html += 'For your convenience, these documents will be emailed to you</span></div>';
				html += '<div style="padding:5px 0px 0px;" align="right"><input type="button" value="Sign Up" class="button_1" onclick="user_put();" /></div>';
				html += '</form></div></div></div></div>';

				html += '<div style="clear:both;height:0px;"></div></div>';
				html += '<div style="width:365px;float:right;">';
				html += '<div class="box_1"><div class="box_2"><div class="box_3"><div class="box_4"><form name="signin" id="signin" action="javascript:user_get();">';
				html += '<h2>Sign In to your account.</h2>';
        		html += 'Please enter your <a href="javascript:sign_pop(\'eapw\');">email address and password</a> or <a href="javascript:sign_pop(\'open\');">OpenID</a>.<br />';
				html += '<div id="signin_err" style="display:none;padding:5px 0px;" class="error"></div>';
				html += '<div id="eapw" style="padding:5px 0px 0px;"><table cellpadding="0" cellspacing="0"><tr><td><span class="fineprint">Email</span><br /><input name="ea" type="text" id="ea" /></td><td>&nbsp;&nbsp;</td><td><span class="fineprint">Password</span><br /><input name="pw" type="password" id="pw" /></td></tr></table></div>';
				html += '<div id="open" style="padding:5px 0px 0px;display:none;"><span class="fineprint">OpenID</span><br /><input name="oi" type="text" id="oi" /><input name="returl" type="hidden" id="returl" /><input name="orgid" type="hidden" id="orgid" /></div>';
				html += '<div style="padding:5px 0px 0px;"><input name="rm" type="checkbox" id="rm" value="1" style="border:0px;" /><span class="fineprint"> remember me (uncheck on a shared computer)</span></div>';
				html += '<div style="padding:5px 0px 0px;" align="right"><input type="submit" class="button_1" value="Sign In" /></div>';
				html += '</form></div></div></div></div>';
				html += '<div style="clear:both;height:0px;"></div></div>';
				html += '<div style="clear:both;height:0px;"></div>';
				html += '</div>';
				mode.innerHTML = html;
				document.signin.returl.value = location.href;
				document.signin.orgid.value = document.params.orgid.value;
				list_get(38, 'sq', 'op_sq', '- Select One -');
			}
		break
		case 2:
		//	mode_get_2();
			html += '<div style="padding:5px;">';
			html += '<div class="box_2"><div class="box_3"><div class="box_4" align="center">';
			html += '<form id="find" name="find" action="javascript:find_get();"><input name="q" type="text" id="q" size="100" maxlength="100" style="border-right:0px;" /><input type="submit" class="button_2" value="Find" /></form>';
			html += '</div></div></div>';
			html += '<div id="find_html"></div>';
			html += '</div>';
			mode.innerHTML = html;
		break
		case 3:
		//	mode_get_3();
			if (usrid.value == 0) {
				pmode.value = 3;
				mode_get(1);
			} else {
				html += '<div style="padding:5px;">';
				html += '<div class="box_2" style="border-width:0px 1px 0px 0px;float:left;margin-right:5px;width:212px;">';
				html += '<div class="box_2" style="border-width:1px 0px 0px 1px;margin-left:10px;">';
				html += '<div class="box_3" style="border-width:1px 0px 0px 1px;">';
				html += '<div class="box_4" style="border-width:1px 0px 0px 1px;"><h4>My Information</h4></div>';
				html += '</div>';
				html += '</div>';
				html += '<div class="box_5" style="border-width:1px 1px 0px 1px;margin-right:10px;padding:10px;" align="center"><img src="http://www.opengospel.com/uico/'+usrid.value+'.gif" alt="" width="150" height="150" class="image" /></div>';
				html += '<div class="box_5" style="border-width:1px 1px 0px 1px;margin-right:10px;">';

				html += '<table width="100%" cellpadding="0" cellspacing="5">';
				html += '<tr><td><h4><a href="javascript:user_pop(0);"">Image</a></h4></td></tr>';
				html += '<tr id="user0" style="display:none;"><td colspan="2">';
				html += '<iframe></iframe>';
				html += '</td></tr>';
				html += '</table>';

				html += '</div>';
				html += '<div class="box_5" style="border-width:1px 1px 0px 1px;margin-right:10px;">';

				html += '<table width="100%" cellpadding="0" cellspacing="5">';
				html += '<tr><td><h4><a href="javascript:user_pop(1);">Contact Information</a></h4></td></tr>';
				html += '<tr id="user1" style="display:none;"><td><form name="user1">';
				html += '<table cellpadding="0" cellspacing="0"><tr valign="bottom"><td><span class="fineprint">Home</span><br /><input name="hp1" type="text" id="hp1" size="2" maxlength="3" /></td><td>&nbsp;</td><td><input name="hp2" type="text" id="hp2" size="2" maxlength="3" /></td><td>&nbsp;</td><td><input name="hp3" type="text" id="hp3" size="2" maxlength="4" /></td></tr></table>';
				html += '<table cellpadding="0" cellspacing="0"><tr valign="bottom"><td><span class="fineprint">Mobile</span><br /><input name="mp1" type="text" id="mp1" size="2" maxlength="3" /></td><td>&nbsp;</td><td><input name="mp2" type="text" id="mp2" size="2" maxlength="3" /></td><td>&nbsp;</td><td><input name="mp3" type="text" id="mp3" size="2" maxlength="4" /></td></tr></table>';
				html += '<span class="fineprint">Address</span><br /><input name="addr" type="text" id="addr" /><br />';
				html += '<span class="fineprint">City</span><br /><input name="cty" type="text" id="cty" /><br />';
				html += '<table cellpadding="0" cellspacing="0"><tr><td><span class="fineprint">State</span><br /><select id="st"><option value="TX">TX</option></select></td><td>&nbsp;</td><td><span class="fineprint">Zip</span><br /><input name="zp" type="text" id="zp" size="4" maxlength="6" /></td></tr></table>';
				html += '<table cellpadding="0" cellspacing="0" width="100%"><tr><td align="right"><input type="button" class="button_1" value="Update" onclick="javascript:user_upd(1);" /></td></tr></table>';
				html += '</form></td></tr>';
				html += '</table>';

				html += '</div>';
				html += '<div class="box_5" style="border-width:1px 1px 1px 1px;margin-right:10px;">';

				html += '<table width="100%" cellpadding="0" cellspacing="5">';
				html += '<tr><td><h4><a href="javascript:user_pop(2);"">Account</a></h4></td></tr>';
				html += '<tr id="user2" style="display:none;"><td colspan="2">dfg</td></tr>';
				html += '</table>';

				html += '</div>';

				html += '<div class="box_2" style="border-width:0px 0px 5px 1px;"><img src="http://www.opengospel.com/apps/op/v1/images/1ptrans.gif" alt="" width="100%" height="10" /></div>';
				html += '</div>';
				html += '<div style="width:517px;float:right;">';
				html += '<div class="box_2" style="margin-bottom:5px;">';
				html += '<div class="box_3">';
				html += '<div class="box_4">';
				html += '<div><table width="100%" cellspacing="0" cellpadding="0"><tr><td><h4>Share Your Prayer</h4></td></tr></table></div>';
				html += '<div style="margin-top:5px;">';
				html += '<div style="float:left;width:52px;"><img src="http://www.opengospel.com/uico/'+usrid.value+'.gif" alt="" width="50" height="50" class="image" /></div>';
				html += '<div style="float:left;width:20px;"><img src="http://www.opengospel.com/apps/op/v1/images/talk.gif" alt="" width="20" height="20" /></div>';
				html += '<div style="float:right;width:431px;">';
				html += '<div class="msg_0">';
				html += '<div class="msg_1" style="padding:5px;">';
				html += '<form name="pray">';
				html += '<table width="100%" cellspacing="5" cellpadding="0">';
				html += '<tr><td><input type="text" name="name" style="color:#999999;width:405px;" onfocus="javascript:if (this.value == \'1. Start with a 1-line summary...\') { this.style.color = \'#000000\'; this.value = \'\'; };" onblur="javascript:if (this.value == \'\') { this.style.color = \'#999999\'; this.value = \'1. Start with a 1-line summary...\'; };" value="1. Start with a 1-line summary..." /></td></tr>';
				html += '<tr><td><div id="pray_type"></div></td></tr>';
				html += '<tr><td><textarea name="text" cols="" rows="3" style="color:#999999;width:405px;" onfocus="javascript:if (this.value == \'3. Share your prayer in more detail...\') { this.style.color = \'#000000\'; this.value = \'\'; };" onblur="javascript:if (this.value == \'\') { this.style.color = \'#999999\'; this.value = \'3. Share your prayer in more detail...\'; };">3. Share your prayer in more detail...</textarea></td></tr>';
				html += '<tr><td align="right"><input type="button" name="button" id="button" class="button_1" value="Post" onclick="javascript:msg_put();" /></td></tr>';
				html += '</table>';
				html += '</form>';
				html += '</div>';
				html += '<div style="clear:both;height:0px;"></div>';
				html += '</div>';
				html += '</div>';
				html += '<div style="clear:both;height:0px;"></div>';
				html += '</div>';
				html += '</div>';
				html += '</div>';
				html += '</div>';
				html += '<div class="box_0">';
				html += '<div>';
				html += '<table width="100%" cellspacing="5" cellpadding="0"><tr>';
				html += '<td nowrap="nowrap"><h4>Read & Reply</h4></td>';
				html += '<td width="100%" align="center" class="fineprint">show <a href="javascript:msgs_see(\'all\');">all prayer requests</a> or <a href="javascript:msgs_see(\'mine\');">just mine</a>.</td>';
				html += '<td><a href="http://us.rd.yahoo.com/my/atm/'+id+'/'+id+'http://add.my.yahoo.com/rss?url='+id+'" target="_blank" style="border:none;"><img src="http://www.opengospel.com/images/icons/yahoo_add.gif" alt="" border="0"/></a></td>';
				html += '<td><a href="xml/op.php?'+id+'" target="_blank" style="border:none;"><img src="http://www.opengospel.com/images/icons/rss.gif" alt="" border="0"/></td>';
				html += '</tr></table></div>';
				html += '<div id="msgs_html" style="padding:0px 5px 5px 5px;"></div>';
				html += '</div>';
				html += '</div>';
				html += '<div style="clear:both;height:0px;"></div>';
				html += '</div>';
				mode.innerHTML = html;
				list_get(22, 'type', 'pray_type', '2. Select your type of prayer...');
				msgs_get('msgs_html','%');
				user_data_get(document.params.usrid.value);
			}
		break
		case 4:
		//	mode_get_4();
			html += '<table width="100%" border="0" cellspacing="5" cellpadding="0">';
			html += '<tr>';
			html += '<td>';
			html += '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="op_box" style="padding:0px;">';
			html += '<tr>';
			html += '<td>';
			html += '<table width="100%" border="0" cellspacing="5" cellpadding="0">';
			html += '<tr>';
			html += '<td>';
			html += '<embed src="http://www.opengospel.com/images/flash/player.swf" width="470" height="20" allowscriptaccess="always" allowfullscreen="true" flashvars="height=20&width=470&file=upload/mp3/xck2v3.mp3&backcolor=0xFFFFFF" />';
			html += '</td>';
			html += '</tr>';
			html += '</table>';
			html += '</tr>';
			html += '</table>';
			html += '</td>';
			html += '</tr>';
			html += '</table>';
			mode.innerHTML = html;
		break
	}
}

function msg_pop(id, ct, msgid) {
	var msg = document.getElementById('post_'+id);
	if (msg.style.display == 'none') {
		for (i=0;i<ct;i++) {
			document.getElementById('post_'+i).style.display = 'none';
		}
		msg.style.display = 'block';
		msgs_get('post_'+id+'_html', msgid);
	} else {
		msg.style.display = 'none';
	}
}

function msg_put() {
	var usrid = document.params.usrid.value;
	var usrea = document.params.usrea.value;
	var name  = document.pray.name.value;
	var typid = document.pray.type.value;
	var text  = document.pray.text.value;
	if (ua.indexOf('msie') != -1) {
		msg_put_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		msg_put_request = new XMLHttpRequest();
	}
	msg_put_request.onreadystatechange = function msg_put_xml() {
		if (msg_put_request.readyState == 4) {
			if (msg_put_request.status == 200) {
				var xml = msg_put_request.responseXML;
				var done = xml.getElementsByTagName("done");
				if (done[0].childNodes[0].nodeValue == 1) {
				//	alert('saved');
					msgs_get('msgs_html','%');
				} else {
				//	user not found.
				}
			} else {
				alert("There was an error while retrieving the URL: " + msg_put_request.statusText);
			}
		}
		return true;
	}
	msg_put_request.open("POST", "xml/op.php", true);
	msg_put_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	msg_put_request.send('opid=msg_put&usrid='+usrid+'&name='+name+'&typid='+typid+'&text='+text);
}

function msg_upd(id, msgid) {
	var usrid = document.params.usrid.value;
	var usrea = document.params.usrea.value;
	var text  = document.getElementById('post_'+id+'_text').value;
	if (ua.indexOf('msie') != -1) {
		msg_upd_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		msg_upd_request = new XMLHttpRequest();
	}
	msg_upd_request.onreadystatechange = function msg_upd_xml() {
		if (msg_upd_request.readyState == 4) {
			if (msg_upd_request.status == 200) {
				var xml = msg_upd_request.responseXML;
				var done = xml.getElementsByTagName("done");
				if (done[0].childNodes[0].nodeValue == 1) {
				//	alert('saved');
					msgs_get('post_'+id+'_html', msgid);
				} else {
				//	user not found.
				}
			} else {
				alert("There was an error while retrieving the URL: " + msg_upd_request.statusText);
			}
		}
		return true;
	}
	msg_upd_request.open("POST", "xml/op.php", true);
	msg_upd_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	msg_upd_request.send('opid=msg_upd&usrid='+usrid+'&usrea='+usrea+'&msgid='+msgid+'&text='+text);
}

function msgs_get(div, msgid) {
	var usrid = document.params.usrid;
	if (ua.indexOf('msie') != -1) {
		msgs_get_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		msgs_get_request = new XMLHttpRequest();
	}
	msgs_get_request.onreadystatechange = function msgs_get_xml() {
		if (msgs_get_request.readyState == 4) {
			if (msgs_get_request.status == 200) {
				var xml = msgs_get_request.responseXML;
				if (div == 'msgs_html') {
					var msg_ct = xml.getElementsByTagName("message").length;
				} else {
					var msg_ct = xml.getElementsByTagName("post").length;
				}
				var msg_msgid = xml.getElementsByTagName("msgid");
				var msg_usrid = xml.getElementsByTagName("usrid");
				var msg_usrea = xml.getElementsByTagName("usrea");
				var msg_name  = xml.getElementsByTagName("name");
				var msg_text  = xml.getElementsByTagName("text");
				var msg_date  = xml.getElementsByTagName("date");
				var html = '';
				html += '<table cellpadding="0" cellspacing="0" id="preqs" width="100%">';
				if (msg_ct > 0) {
					for (i=(msg_ct-1);i>=0;i--) {
						if (div == 'msgs_html') {
							html += '<tr id="preq_'+msg_usrid[i].childNodes[0].nodeValue+'_'+i+'"><td>';
							html += '<div style="margin:5px 0px 0px 0px;">';
							html += '<div style="float:left;width:52px;"><img src="http://www.opengospel.com/uico/'+msg_usrid[i].childNodes[0].nodeValue+'.gif" alt="" width="50" height="50" class="image" /></div>';
							html += '<div style="float:left;width:20px;"><img src="http://www.opengospel.com/apps/op/v1/images/talk.gif" alt="" width="20" height="20" /></div>';
							html += '<div style="float:right;width:433px;">';
							html += '<div class="msg_0">';
							html += '<div class="msg_1" style="padding-top:5px;">';
							html += '<table width="100%" cellspacing="0" cellpadding="0">';
							html += '<tr><td><a href="javascript:msg_pop('+i+','+msg_ct+','+msg_msgid[i].childNodes[0].nodeValue+');" class="bold">'+msg_name[i].childNodes[0].nodeValue+'</a></td></tr>';
							html += '<tr><td><span class="fineprint"><a href="javascript:;">'+msg_usrea[i].childNodes[0].nodeValue+'</a> wrote at '+msg_date[i].childNodes[0].nodeValue+'</span></td></tr>';
							html += '</table>';
							html += '<div id="post_'+i+'" style="display:none;">';
							html += '<div style="padding-top:5px;"><table width="100%" cellspacing="0" cellpadding="0"><tr><td>'+msg_text[i].childNodes[0].nodeValue+'</td></tr></table></div>';
							html += '<div style="margin:10px 0px 0px 0px;">';
							html += '<div style="float:left;width:52px;"><img src="http://www.opengospel.com/uico/'+usrid.value+'.gif" alt="" width="50" height="50" class="image" /></div>';
							html += '<div style="float:left;width:20px;"><img src="http://www.opengospel.com/apps/op/v1/images/talk.gif" alt="" width="20" height="20" /></div>';
							html += '<div style="float:right;width:339px;" class="msg_0">';
							html += '<div class="msg_1">';
							html += '<form>';
							html += '<div><textarea name="post_'+i+'_text" id="post_'+i+'_text" cols="" rows="" style="width:314px;"></textarea></div>';
							html += '<div style="padding-top:5px;" align="right"><input type="button" name="button" id="button" value="Post" class="button_1" onclick="javascript:msg_upd('+i+','+msg_msgid[i].childNodes[0].nodeValue+');" /></div>';
							html += '</form>';
							html += '</div>';
							html += '</div>';
							html += '<div style="clear:both;height:0px;"></div>';
							html += '</div>';
							html += '<div id="post_'+i+'_html"></div>';
							html += '</div>';
							html += '</div>';
							html += '<div style="clear:both;height:0px;"></div>';
							html += '</div>';
							html += '</div>';
							html += '<div style="clear:both;height:0px;"></div>';
							html += '</div>';
							html += '</tr></td>';
						} else {
							html += '<tr><td>';
							html += '<div style="margin:10px 0px 0px 0px;">';
							html += '<div style="float:left;width:52px;"><img src="http://www.opengospel.com/uico/'+msg_usrid[i].childNodes[0].nodeValue+'.gif" alt="" width="50" height="50" class="image" /></div>';
							html += '<div style="float:left;width:20px;"><img src="http://www.opengospel.com/apps/op/v1/images/talk.gif" alt="" width="20" height="20" /></div>';
							html += '<div style="float:right;width:339px;" class="msg_0">';
							html += '<div class="msg_1">';
							html += '<div><span class="fineprint"><a href="javascript:;">'+msg_usrea[i].childNodes[0].nodeValue+'</a> wrote at '+msg_date[i+1].childNodes[0].nodeValue+'</span></div>';
							html += '<div>'+msg_text[i+1].childNodes[0].nodeValue+'</div>';
							html += '</div>';
							html += '</div>';
							html += '<div style="clear:both;height:0px;"></div>';
							html += '</div>';
							html += '</tr></td>';
						}
					}					
				} else {
					if (div == 'msgs_html') {
						html += '<tr><td align="center">There are no prayer requests available at this time.</td></tr>';
					}
				}
				html += '<table>';
				document.getElementById(div).innerHTML = html;
			} else {
				alert("There was an error while retrieving the URL: " + msgs_get_request.statusText);
			}
		}
		return true;
	}
	msgs_get_request.open("GET", "xml/op.php?opid=msgs_get&msgid="+msgid, true);
	msgs_get_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	msgs_get_request.send(null);
}

function msgs_see(filter) {
	var usrid = document.params.usrid.value;
	var table = document.getElementById('preqs');
	var row = table.rows;
	var found = 0;
	for (i=0;i<row.length;i++) {
		if (row[i].id) {
			if (filter == 'all') {
				row[i].style.display = '';
			} else {
				if (row[i].id.indexOf('_'+usrid+'_') != -1) {
					row[i].style.display = '';
				} else {
					row[i].style.display = 'none';
				}
			}
		}
	}
}

function news_get(id, ct) {
	for (i=1; i<=ct; i++) {
		document.getElementById('news_'+i).style.display = 'none';
	}
	document.getElementById('news_'+id).style.display = '';
}

function op(orgid) {
	var oid = cookie_get('oid');
	if (oid) {
		oid = oid.split('|');
	}
	var url = location.href.split('uid=');
	var usr = location.href.split('usr=');
	var html = '';
	html += '<div id="main" class="main">';
	html += '<div id="head" class="head">';	
	html += '<div id="name" class="name">North Irving Baptist Church</div>';
	html += '<div id="user" class="user"></div>';
	html += '<div style="clear:both;height:0px;"></div>';
	html += '<div id="mast" class="mast">';
	html += '<div id="mast_over" class="mast_over">';
	html += '<img src="images/1ptrans.gif" alt="" width="745" height="125" />';
	html += '<div id="menu" class="menu">';
	html += '<div style="float:left;">';
	html += '<div class="tab_1" id="tab_0"><a href="index.html">Home</a></div>';
	html += '<div class="tab_0" id="tab_3"><a href="javascript:mode_get(3);">PrayerShare</a></div>';
//	html += '<div class="tab_0" id="tab_4"><a href="javascript:mode_get(4);">Sermons & Media</a></div>';
	html += '<div class="tab_0" id="tab_2"><a href="javascript:mode_get(2);">Search</a></div>';
	html += '</div>';
	html += '<div id="sign" style="float:right;">';
	if ((oid) && (oid[0]) && (oid[1])) {
		html += '<div class="tab_0" id="tab_1"><a href="javascript:mode_get(1);">Sign Out</a></div>';
	} else {
		html += '<div class="tab_0" id="tab_1"><a href="javascript:mode_get(1);">Sign In</a></div>';
	}
	html += '</div>';
	html += '<div style="clear:both;height:0px;"></div>';
	html += '</div>'	
	html += '</div>';
	html += '</div>';	
	html += '</div>';
	html += '<div id="body" class="body">';
	html += '<div id="mode" class="mode">';
	html += '<div id="mode_0"></div>';
	html += '<div id="mode_1"></div>';
	html += '<div id="mode_2"></div>';
	html += '<div id="mode_3"></div>';
	html += '<div id="mode_4"></div>';
	html += '<form name="params" id="params">';
	html += '<input name="orgid" type="hidden" id="orgid" value="'+orgid+'"/>';
	html += '<input name="usrid" type="hidden" id="usrid" value="0"/>';
	html += '<input name="usrea" type="hidden" id="usrea" value=""/>';
	html += '<input name="pmode" type="hidden" id="pmode" value="0"/>';
	html += '</form>';
	html += '</div>';
	html += '<div id="foot" class="foot">Copyright © '+date.getFullYear()+'. All rights reserved.</div>';
	html += '</div>';
	html += '</div>';
	html += '<div id="side" class="side"><img src="http://www.opengospel.com/images/ad_120x600.gif" alt="" width="120" height="600" /></div>';
	html += '<div style="clear:both;height:0px;"> </div>';
	html += '<iframe id="op" name="op" src="" style="display:none;" frameborder="0"></iframe>';
	document.getElementById('html').innerHTML = html;
	if ((oid) && (oid[0]) && (oid[1])) {
		user_set(oid[0], oid[1]);
		document.params.usrid.value = oid[0];
		document.params.usrea.value = oid[1];
	} else {
		user_set(0, 'welcome, guest');
	}
	if (url[1]) {
		page_get(url[1]);
	} else if (usr[1]) {
		user_get(usr[1]);
	} else {
		mode_get(0);
	}
}

function page_get(pgeid) {
	if (ua.indexOf('msie') != -1) {
		page_get_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		page_get_request = new XMLHttpRequest();
	}
	page_get_request.onreadystatechange = function page_get_xml() {
		if (page_get_request.readyState == 4) {
			if (page_get_request.status == 200) {
				var xml = page_get_request.responseXML;
				var page_name = xml.getElementsByTagName("name");
				var page_date = xml.getElementsByTagName("date");
				var page_html = xml.getElementsByTagName("html");
				var page_box = new Array();
					page_box[0] = "video"
					page_box[1] = "photo"
					page_box[2] = "file"
					page_box[3] = "link"
				var html = '';
				html += '<div style="padding:5px 10px 10px;"><div class="box_6">';
				html += '<h1>'+page_name[0].childNodes[0].nodeValue+'</h1>';
				html += '</div>';
				html += '<div><div style="float:left;width:200px;">';

				for (i=0; i<page_box.length; i++) {
					var item_ct   = xml.getElementsByTagName(page_box[i]).length;
					var item_id   = xml.getElementsByTagName(page_box[i]+'_id');
					var item_ico  = xml.getElementsByTagName(page_box[i]+'_ico');
					var item_desc = xml.getElementsByTagName(page_box[i]+'_desc');
					var item_type = xml.getElementsByTagName(page_box[i]+'_type');
					var item_html = xml.getElementsByTagName(page_box[i]+'_html');
					var item_url = xml.getElementsByTagName(page_box[i]+'_url')
					if (item_id[0]) {
						html += '<div class="box_6">';
						if (page_box[i] == 'video') {
							for (j=0; j<item_ct; j++) {
								if (j == 0) {
									html += '<div><h4>Related Video</h4></div>';
								}
								html += '<div class="play" id="rv_'+j+'" style="position:absolute;display:none;margin-top:5px;">';
								html += '<table cellspacing="10">';
								html += '<tr>';
								html += '<td><h4>Video Viewer</h4></td>';
								html += '<td align="right" class="fineprint"><a href="javascript:rv_pop('+j+','+item_ct+');">CLOSE</a></td>';
								html += '</tr>';
								html += '<tr>';
								html += '<td colspan="2">'+item_html[j].childNodes[0].nodeValue+'</td>';
								html += '</tr>';
								html += '</table>';
								html += '</div>';								
								html += '<div style="padding:5px 0px 0px;">';
								html += '<div style="float:left;width:67px;"><img src="'+item_url[j].childNodes[0].nodeValue+'" alt="" width="60" height="50" class="image" /></div>';
								html += '<div><a href="javascript:rv_pop('+j+','+item_ct+');">'+item_desc[j].childNodes[0].nodeValue+'</a>';
								html += '<div style="clear:both;height:0px;"></div>';
								html += '</div>';
								html += '</div>';
							}
						} else if (page_box[i] == 'photo') {
							html += '<div><h4>Related Photos</h4></div>';
							html += '<div class="play" id="rp" style="position:absolute;display:none;margin-top:5px;">';
							html += '<table cellspacing="10">';
							html += '<tr>';
							html += '<td><h4>Photo Viewer</h4></td>';
							html += '<td align="right" class="fineprint"><a href="javascript:rp_pop('+pgeid+');">CLOSE</a></td>';
							html += '</tr>';
							html += '<tr>';
							html += '<td colspan="2">';
							html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="250" title="photos">';
							html += '<param name="movie" value="http://www.opengospel.com/images/flash/photos.swf?pgeid='+pgeid+'" />';
							html += '<param name="quality" value="high" /><param name="BGCOLOR" value="#FFFFFF" />';
							html += '<embed src="http://www.opengospel.com/images/flash/photos.swf?pgeid='+pgeid+'" width="300" height="250" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>';
							html += '</object>';								
							html += '</td>';
							html += '</tr>';
							html += '</table>';
							html += '</div>';							
							html += '<div style="padding:5px 0px 0px;">';
							html += '<div style="float:left;width:72px;"><img src="'+item_ico[0].childNodes[0].nodeValue+'" alt="" width="65" height="50" class="image" /></div>';
							html += '<div><a href="javascript:rp_pop('+pgeid+');">'+item_desc[0].childNodes[0].nodeValue+'</a></div>';
							html += '<div style="clear:both;height:0px;"></div>';
							html += '</div>';
						} else if (page_box[i] == 'file') {
							html += '<div style="padding-bottom:5px;"><h4>Related Files</h4></div>';
							html += '<table cellspacing="0">';
							for (j=0; j<item_ct; j++) {
								html += '<tr>';
								html += '<td valign="top"><img src="http://www.opengospel.com/images/icons/'+item_type[0].childNodes[0].nodeValue+'.gif" alt="" width="16" height="16" style="padding-top:3px;"/></td>';
								html += '<td valign="top"><div style="padding-left:5px;"><a href="'+item_url[0].childNodes[0].nodeValue+'" target="_blank">'+item_desc[j].childNodes[0].nodeValue+'</a></div></td>';
								html += '</tr>';
							}
							html += '</table>';
						} else if (page_box[i] == 'link') {
							html += '<div style="padding-bottom:5px;"><h4>Most Viewed</h4></div>';
							html += '<table cellspacing="0">';
							for (j=0; j<item_ct; j++) {
								html += '<tr>';
								html += '<td valign="top"><img src="http://www.opengospel.com/images/icons/page.gif" alt="" width="16" height="16" style="padding-top:3px;"/></td>';
								html += '<td valign="top"><div style="padding-left:5px;"><a href="/index.html?uid='+item_id[j].childNodes[0].nodeValue+'">'+item_desc[j].childNodes[0].nodeValue+'</a></div></td>';
								html += '</tr>';
							}
							html += '</table>';
						}
						html += '</div>';
					}
				}
				html += '</div><div style="margin-left:220px;padding:5px;">';
				html += '<span style="color:#999999;">'+page_date[0].childNodes[0].nodeValue+'</span><br /><br />'+page_html[0].childNodes[0].nodeValue;
				html += '</div><div style="clear:both;height:0px;"></div></div>';
				html += '</div>';
				document.getElementById('mode_0').innerHTML = html;
			} else {
				alert("There was an error while retrieving the URL: " + page_get_request.statusText);
			}
		}
		return true;
	}
	page_get_request.open("GET", "xml/op.php?opid=rss_page_get&pgeid="+pgeid, true);
	page_get_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	page_get_request.send(null);
}

function pos_l_get(input_obj) {
  var return_val = input_obj.offsetLeft;
  while((input_obj = input_obj.offsetParent) != null) {
	if (input_obj.tagName!='HTML') return_val += input_obj.offsetLeft;
  }
  return return_val;
}

function pos_t_get(input_obj) {
  var return_val = input_obj.offsetTop;
  while((input_obj = input_obj.offsetParent) != null) {
	if (input_obj.tagName!='HTML') return_val += input_obj.offsetTop;
  }
  return return_val;
}

function rp_pop(pgeid) {
	var rp = document.getElementById('rp');
	if (rp.style.display == 'none') {
		rp.style.display = 'block';
	} else {
		rp.style.display = 'none';
	}
}

function rv_pop(id, ct) {
	var rv = document.getElementById('rv_'+id);
	if (rv.style.display == 'none') {
		for (i=0;i<ct;i++) {
			document.getElementById('rv_'+i).style.display = 'none';
		}
		rv.style.display = 'block';
	} else {
		rv.style.display = 'none';
	}
}

function sign_pop(id) {
	document.getElementById(id).style.display = '';
//	document.getElementById(id+'_btn').style.display = '';
	switch (id) {
		case 'open':
			document.signin.action = 'http://www.opengospel.com/openid/signin/'; 
			document.signin.method = 'post';
			document.getElementById('eapw').style.display = 'none';
		//	document.getElementById('eapw_btn').style.display = 'none';
		break
		case 'eapw':
			document.signin.action = 'javascript:user_get();'; 
			document.signin.method = 'post';		
			document.getElementById('open').style.display = 'none';
		//	document.getElementById('open_btn').style.display = 'none';
		break
	}
}

function user_get(oi) {
	if (oi === undefined) {
		var ea = document.signin.ea.value;
		var pw = document.signin.pw.value;
			oi = 0;
	}
	if ((oi == 0) && (ea == '')) {
		err_pop('signin_err', 'Please verify your email address');
		document.signin.ea.focus();
	} else if ((oi == 0) && (pw == '')) {
		err_pop('signin_err', 'Please verify your password');
		document.signin.pw.focus();
	} else {
		var oid = cookie_get('oid');
		if (oid) {
			oid = oid.split('|');
		}
		if (ua.indexOf('msie') != -1) {
			user_get_request = new ActiveXObject("Msxml2.XMLHTTP");
		} else {
			user_get_request = new XMLHttpRequest();
		}
		user_get_request.onreadystatechange = function user_get_xml() {
			if (user_get_request.readyState == 4) {
				if (user_get_request.status == 200) {
					var xml = user_get_request.responseXML;
					var number_of_users = xml.getElementsByTagName("user").length;
					var usrid = xml.getElementsByTagName("usrid");
					var usrea = xml.getElementsByTagName("usrea");
					var pmode = document.params.pmode.value;
					if (number_of_users == 1) {
						document.getElementById('user').innerHTML = 'welcome, '+usrea[0].childNodes[0].nodeValue;
						document.getElementById('sign').innerHTML = '<div class="tab_0" id="tab_1"><a href="javascript:mode_get(1);">Sign Out</a></div>';
						document.params.usrid.value = usrid[0].childNodes[0].nodeValue;
						if (oid) {
							var val = usrid[0].childNodes[0].nodeValue+'|'+usrea[0].childNodes[0].nodeValue+'|'+oid[2]+'|'+oid[3]+'|'+oid[4];
						} else {
							var val = usrid[0].childNodes[0].nodeValue+'|'+usrea[0].childNodes[0].nodeValue+'|||';
						}
						cookie_put('oid', val, 14);
						if (pmode == 0) {
							location.href = 'index.html';
						} else {
							mode_get(pmode);
						}
					} else {
					//	user not found.
						err_pop('signin_err', 'Invalid email address or password.');
					}
				} else {
					alert("There was an error while retrieving the URL: " + user_get_request.statusText);
				}
			}
			return true;
		}
		user_get_request.open("POST", "xml/op.php", true);
		user_get_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		if (oi == 0) {
			user_get_request.send('opid=user_get&usrid='+ea+'|'+pw);
		} else {
			user_get_request.send('opid=user_get&opnid='+oi);
		}
	}
}

function user_data_get(usrid) {
	if (ua.indexOf('msie') != -1) {
		user_data_get_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		user_data_get_request = new XMLHttpRequest();
	}
	user_data_get_request.onreadystatechange = function user_data_get_xml() {
		if (user_data_get_request.readyState == 4) {
			if (user_data_get_request.status == 200) {
				var xml = user_data_get_request.responseXML;
				var number_of_users = xml.getElementsByTagName("user").length;
				var usrhp = xml.getElementsByTagName("usrhp");
				var usrmp = xml.getElementsByTagName("usrmp");
				var usraddr = xml.getElementsByTagName("usraddr");
				var usrcty = xml.getElementsByTagName("usrcty");
				var usrst = xml.getElementsByTagName("usrst");
				var usrzp = xml.getElementsByTagName("usrzp");
				if (number_of_users == 1) {
					if (usrhp[0].childNodes[0]) {
						var hp = usrhp[0].childNodes[0].nodeValue.split(' ');
						document.user1.hp1.value = hp[0];
						document.user1.hp2.value = hp[1];
						document.user1.hp3.value = hp[2];
					}
					if (usrmp[0].childNodes[0]) {
						var mp = usrmp[0].childNodes[0].nodeValue.split(' ');
						document.user1.mp1.value = mp[0];
						document.user1.mp2.value = mp[1];
						document.user1.mp3.value = mp[2];
					}
					if (usraddr[0].childNodes[0]) { document.user1.addr.value = usraddr[0].childNodes[0].nodeValue; }
					if (usrcty[0].childNodes[0]) { document.user1.cty.value = usrcty[0].childNodes[0].nodeValue; }
					if (usrst[0].childNodes[0]) { document.user1.st.value = usrst[0].childNodes[0].nodeValue; }
					if (usrzp[0].childNodes[0]) { document.user1.zp.value = usrzp[0].childNodes[0].nodeValue; }
				} else {
				//	user not found.
				}
			} else {
				alert("There was an error while retrieving the URL: " + user_get_request.statusText);
			}
		}
		return true;
	}
	user_data_get_request.open("POST", "xml/op.php", true);
	user_data_get_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	user_data_get_request.send('opid=user_get&usrid='+usrid)
}

function user_pop(id) {
	for (i=0;i<3;i++) {
		var form = document.getElementById('user'+i);
		if (i==id) {
			if (form.style.display == '') {
				form.style.display = 'none';
			} else {
				form.style.display = '';
			}
		} else {
			form.style.display = 'none';
		}
	}
}

function user_put() {
	var fn = document.signup.fn.value;
	var ln = document.signup.ln.value;
	var sx = document.signup.sx.value;
	var zp = document.signup.zp.value;
	var ea = document.signup.ea.value;
	var pw1 = document.signup.pw1.value;
	var pw2 = document.signup.pw2.value;
	var sq = document.signup.sq.value;
	var sa = document.signup.sa.value;
	var err = '2px red solid';
	for (i=0; i<document.signup.elements.length; i++) {
		document.signup.elements[i].style.border = '';
	}
	if (fn.length == 0) {
		document.signup.fn.style.border = err;
	} else if (ln.length == 0) {
		document.signup.ln.style.border = err;
	} else if (sx == 0) {
		document.signup.sx.style.border = err;
	} else if ((zp.length == 0) || (isNaN(zp))) {
		document.signup.zp.style.border = err;
	} else if (ea.length == 0) {
		document.signup.ea.style.border = err;
	} else if (pw1.length == 0) {
		document.signup.pw1.style.border = err;
	} else if (pw2.length == 0) {
		document.signup.pw2.style.border = err;
	} else if (pw1 != pw2) {
			document.signup.pw1.style.border = err;
			document.signup.pw2.style.border = err;
	} else if (sq == 0) {
			document.signup.sq.style.border = err;
	} else if (sa.length == 0) {
			document.signup.sa.style.border = err;
	} else {
		if (ua.indexOf('msie') != -1) {
			user_put_request = new ActiveXObject("Msxml2.XMLHTTP");
		} else {
			user_put_request = new XMLHttpRequest();
		}
		user_put_request.onreadystatechange = function user_put_xml() {
			if (user_put_request.readyState == 4) {
				if (user_put_request.status == 200) {
					var xml = user_put_request.responseXML;
					var number_of_users = xml.getElementsByTagName("user").length;
					var usrid = xml.getElementsByTagName("usrid");
					var usrea = xml.getElementsByTagName("usrea");
					var pmode = document.params.pmode.value;
					if (number_of_users == 1) {	
						user_set(usrid[0].childNodes[0].nodeValue, usrea[0].childNodes[0].nodeValue);
						document.getElementById('sign').innerHTML = '<div class="tab_0" id="tab_1"><a href="javascript:mode_get(1);">Sign Out</a></div>';
						document.params.usrid.value = usrid[0].childNodes[0].nodeValue;
						var val = usrid[0].childNodes[0].nodeValue+'|'+usrea[0].childNodes[0].nodeValue+'|||';
						cookie_put('oid', val, 14);
						location.href = 'index.html';
					}	else {
					//	user not setup right.
					}
				}
			}
			return true;
		}
		user_put_request.open("POST", "xml/op.php", true);
		user_put_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		user_put_request.send('opid=user_put&fn='+fn+'&ln='+ln+'&sx='+sx+'&zp='+zp+'&ea='+ea+'&pw='+pw1+'&sq='+sq+'&sa='+sa);
	}
}

function user_set(usrid, usrea) {
	var html = '';
	html += '<div id="user_icon" class="user_icon"><img src="http://www.opengospel.com/images/user.gif" height="21" width="21" alt="" class="image"></div>';	
	html += '<div id="user_name" class="user_name">'+usrea+'<br /><a href="javascript:mode_get(1);">';
	if (usrid == 0) {
		html += 'Sign In';
	} else {
		html += 'Sign Out';	
	}
	html += '</a></div>';
	html += '<div style="clear:both;height:0px;"></div>';
	document.getElementById('user').innerHTML = html;
}

function user_upd(id) {
	var usrid = document.params.usrid.value;
	if (ua.indexOf('msie') != -1) {
		user_upd_request = new ActiveXObject("Msxml2.XMLHTTP");
	} else {
		user_upd_request = new XMLHttpRequest();
	}
	user_upd_request.onreadystatechange = function user_upd_xml() {
		if (user_upd_request.readyState == 4) {
			if (user_upd_request.status == 200) {
				alert('here');
			}
		}
		return true;
	}
	user_upd_request.open("POST", "xml/op.php", true);
	user_upd_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	switch (id) {
		case 1:
			var hp = document.user1.hp1.value+' '+document.user1.hp2.value+' '+document.user1.hp3.value;
			var mp = document.user1.mp1.value+' '+document.user1.mp2.value+' '+document.user1.mp3.value;
			var addr = document.user1.addr.value;
			var cty = document.user1.cty.value;
			var st = document.user1.st.value;
			var zp = document.user1.zp.value;
			user_upd_request.send('opid=user_upd&hphone='+hp+'&mphone='+mp+'&address='+addr+'&city='+cty+'&state='+st+'&zip='+zp+'&usrid='+usrid);
		break;
	}
}