var ajaxloader="url('commongfx/ajax-loader.gif')";
var ajaxmini="url('commongfx/ajaxmini.gif')";

/*function calculatescroll(id){
document.getElementById(id+'text').style.backgroundImage=ajaxloader;
document.getElementById(id+'text').innerHTML="";
	new Ajax.Request("f/serviceops/form.php",
	{ 
	method: 'post', 
	postBody: 'type=scroller&show='+id+'&value='+$(id+'op').value,
	onComplete: function(req){
document.getElementById(id+'text').style.backgroundImage='';
$(id+'text').innerHTML=req.responseText;
} 
	});

}
*/
function contactbasicview(id){
document.getElementById('returndetails').style.backgroundImage=ajaxloader;
document.getElementById('returndetails').innerHTML="";
	new Ajax.Request("f/contacts/peoplesdetails.php",
	{ 
	method: 'post', 
	postBody: 'show='+id,
	onComplete: function(req){
document.getElementById('returndetails').style.backgroundImage="";
$('returndetails').innerHTML=req.responseText;
} 
	});

}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=660,height=500,left = 182,top = 50');");
}

function contactdelete(id,contact,type){
if(type == 'confirm'){
confirmationLayer();
document.getElementById('confbox').innerHTML = '<br /><br />Do you really want to delete records for<br /><br /><b>'+contact+'?</b><br /><br /><div class=\"row\"><div style=\"width: 49%; float: left\"><a href=\"javascript: contactdelete(\''+id+'\',\''+contact+'\',\'confirmed\');\" class=\"onewaylist\">Yes</a></div><div style=\"width: 49%; float: left;\"><a href=\"javascript: confirmationLayerRem();\" class=\"onewaylist\">No</a></div></div>';
} else if(type == 'confirmed'){
	new Ajax.Request("admin/contacts/otherfeatures.php",
	{ 
	method: 'post', 
	postBody: 'otherfeatures=deletecontact&id='+id,
	onComplete: function(req){
if(req.responseText){
$('returndetails').innerHTML=req.responseText;
contactpplsearch();
}
confirmationLayerRem();

} 
	});
}
}


function contactlink(uid,id,el){
$('cell'+el).innerHTML='';
$('cell'+el).style.backgroundImage = ajaxmini;
 	new Ajax.Request("admin/contacts/otherfeatures.php",
	{ 
	method: 'post', 
	postBody: 'otherfeatures=link&id='+id+'&el='+el+'&uid='+uid,
	onComplete: function(req){
$('cell'+el).style.backgroundImage = '';
var output=req.responseText.split("|");
$('cell'+el).innerHTML=output[1];
if(output[0] == 0){
$('cell'+el).style.backgroundColor ='#FFFFFF';
} else {
$('cell'+el).style.backgroundColor ='#99FF99';
}
}
	});
}


function contactcopydetail(id,el){
 	new Ajax.Request("admin/contacts/otherfeatures.php",
	{ 
	method: 'post', 
	postBody: 'otherfeatures=copydetails&id='+id+'&el='+el,
	onComplete: function(req){
$('output'+el).innerHTML=req.responseText;
if(el == 'to'){
$('toid').value=id;
}
}
	});
}

function contactcopy(type,id){
 	new Ajax.Request("admin/contacts/otherfeatures.php",
	{ 
	method: 'post', 
	postBody: 'otherfeatures=copyfield&type='+type+'&id='+id,
	onComplete: function(req){
if(type == 'address'){
var address=req.responseText.split('|');
$('form2').value=address[0];
$('form4').value=address[1];
$('form6').value=address[2];
$('form8').value=address[3];
$('form10').value=address[4];
} else if(type == 'mobile'){
$('form13').value=req.responseText;
} else if(type == 'phone'){
$('form11').value=req.responseText;
} else if(type == 'email'){
$('form12').value=req.responseText;
}
	}

	});

}

function contactcopyform(){
$('contactcopy').request({
onComplete:  function(req){
$('returndetails').innerHTML=req.responseText;
}
})
}


function contactadd(){
$('cont30').innerHTML = '';
$('cont30').style.backgroundImage=ajaxloader;
$('contactadd').request({
onComplete:  function(req){
$('returndetails').innerHTML=req.responseText;
}
})
}

function contactcal(year,month,day,el){
var showdate=day+'/'+month+'/'+year;
 	new Ajax.Request("admin/contacts/calendar.php",
	{ 
	method: 'post', 
	postBody: 'showdate='+showdate+'&el='+el,
	onComplete: function(req){
$('contactdate').innerHTML=req.responseText;
$('form'+el).value=showdate;	
	}

	});
}

function contactdate(el) {
	new Ajax.Request("admin/contacts/calendar.php",
	{ 
	method: 'post', 
	postBody: 'showdate='+$('form'+el).value+'&el='+el,
	onComplete: function(req){
//get element position(bottom, left)
var parentelement=document.getElementById('form'+el);
var top=parentelement.offsetTop;
var left=parentelement.offsetLeft;
//draw element with absolute positioning (top, left from location above)

var pagecontainer=document.getElementById('datelayer');
var confdiv2=document.createElement('div');
confdiv2.setAttribute('id','contactdate');  
confdiv2.setAttribute('class','contact');
pagecontainer.appendChild(confdiv2);
    var confElem = document.getElementById('contactdate');
    top=top+16;
    left=left+15;
confElem.style.position='absolute';
confElem.style.left=left+'px';
confElem.style.top=top+'px';
//Load date into element
$('contactdate').innerHTML=req.responseText;
} 
	});
}

function contactother(action){

$('nameinput').value="";
$('returnnames').innerHTML="";
$('returndetails').innerHTML="";
$('returndetails').style.backgroundImage=ajaxloader;
	new Ajax.Request("admin/contacts/otherfeatures.php",
	{ 
	method: 'post', 
	postBody: 'otherfeatures='+action,
	onComplete: function(req){
$('returndetails').style.backgroundImage='';

$('returndetails').innerHTML=req.responseText;
} 
	});

}

function contactcrb(){
var total=0;
if($('crbtype1').checked){
total=total+1;
}
if($('crbtype2').checked){
total=total+2;
}
$('form14').value=total;
}

function contact2form(id,el){
$('cont'+el).innerHTML="";
$('cont'+el).style.backgroundImage=ajaxmini;
	new Ajax.Request("admin/contacts/peoplesdetails.php",
	{ 
	method: 'post', 
	postBody: 'showform='+el+'&id='+id,
	onComplete: function(req){
$('returndetails').innerHTML=req.responseText;
document.getElementById('cont'+el).setAttribute('onclick','');
if(el == 9|| el==16||el==17){
contactdate(el);
}
} 
	});

}

function contactedit(el){
if(document.getElementById('contactid') != null){
var element=document.getElementById('form'+el).value;
var id=document.getElementById('contactid').value;
if(element == undefined){
var element=document.getElementById('form'+el).innerHTML;
}
var element=encodeURIComponent(element);
	new Ajax.Request("admin/contacts/peoplesdetails.php",
	{ 
	method: 'post', 
	postBody: 'edit='+id+'&data='+element+'&type='+el,
	onComplete: function(req){
//$('cont'+el).innerHTML=req.responseText;
contactview(id);
} 
	});
} else {
if(document.getElementById('contactdate') != null){
hidecontactcal();

}
}
}
function hidecontactcal(){
var d = document.getElementById('datelayer');
var datebox=document.getElementById('contactdate');
d.removeChild(datebox);
}
function contactview(id){
if(!id) {
var id = document.getElementById('contactid').value;
}
document.getElementById('returndetails').style.backgroundImage=ajaxloader;
document.getElementById('returndetails').innerHTML="";
	new Ajax.Request("admin/contacts/peoplesdetails.php",
	{ 
	method: 'post', 
	postBody: 'show='+id,
	onComplete: function(req){
document.getElementById('returndetails').style.backgroundImage="";
$('returndetails').innerHTML=req.responseText;
} 
	});

}

function contactpplsearch(el){
if(!el){
var el='returnnames';
var el2='';
} else {
var el2=el;
}
if($('otherfeatures') != null && $('otherfeatures').value=='add'){
var fname=$('form3').value;
var sname=$('form5').value;
} else {
var fname='';
var sname='';
}
var preachstr = document.getElementById('nameinput'+el2).value;

if(preachstr.length > 2){
preachstr=preachstr;
} else {
preachstr='';
}
if(fname.length >2){
fname=fname;
} else {
fname='';
}
if(sname.length > 2){
sname=sname;
} else {
sname='';
}
$(el).style.backgroundImage=ajaxloader;
if(preachstr || sname || fname){
	new Ajax.Request("admin/contacts/peoplesearch.php", 
	{ 
	method: 'post', 
	postBody: 'name='+preachstr+'&fname='+fname+'&sname='+sname+'&el='+el2,
	onComplete: function(req){

$(el).style.backgroundImage="";
$(el).innerHTML = req.responseText;
} 
	});
}
if(preachstr.length <3 || fname.length <3 || sname.length < 3){
document.getElementById(el).innerHTML = '&nbsp;';
}

}
function sermonedit(id){
	new Ajax.Request("index.php?admin=sermons_v2.0",
	{ 
	method: 'get', 
	postBody: 'admin=sermons_v2.0',
	onComplete: function(req){
$('mainpagecontainer').innerHTML=req.responseText;
serloadexisting(id);
} 
	});

}
function sermonform(){
//layerPause();
$('sermonbutton').style.backgroundImage =ajaxloader;
$('sermonbutton').innerHTML ='&nbsp;';
	new Ajax.Request("f/sermons/existingform.php",
	{ 
	method: 'post', 
	postBody: 'action=updateform&exday='+$('exday').value+'&exmonth='+$('exmonth').value+'&exyear='+$('exyear').value+'&expreacher='+$('expreacher').value+'&exseries='+$('exseries').value+'&exbook='+$('exbook').value,
	onComplete: function(req){
if(req.responseText){
$('existingform').innerHTML = req.responseText;
//layerPauseRem();
}
} 
	});
}
function sermonresults(){
$('existingsermonsresults').innerHTML = '<br /><br /><br />';
$('existingsermonsresults').style.backgroundImage=ajaxloader;
	new Ajax.Request("f/sermons/editexisting.php",
	{ 
	method: 'post', 
	postBody: 'action=showexisting&type=formsubmit&exday='+$('exday').value+'&exmonth='+$('exmonth').value+'&exyear='+$('exyear').value+'&expreacher='+$('expreacher').value+'&exseries='+$('exseries').value+'&exbook='+$('exbook').value,
	onComplete: function(req){
$('existingsermonsresults').style.backgroundImage='';
if(req.responseText){
$('existingsermonsresults').innerHTML = req.responseText;
}
} 
	});
}


function elementfade(elem){
for(i=0;i<10;i++){
var time = i * 100;
setTimeout("elementopacity('"+elem+"','"+i+"')",time);
}
}
function elementfadeout(elem){
for(i=0;i<10;i++){
var time = i * 100;
setTimeout("elementopacity('"+elem+"','"+10-i+"')",time);
}
}
function elementopacity(elem,value){
var element=document.getElementById(elem);
if(value > 0){
element.style.opacity=value/10;
element.style.filter='alpha(opacity=' + value*10 + ')';
} else {
element.style.opacity=0;
element.style.filter='alpha(opacity=0)';
}
}
function serexupdateform(){
//layerPause();
	new Ajax.Request("admin/sermons_v2.0/existingform.php",
	{ 
	method: 'post', 
	postBody: 'action=updateform&exday='+$('exday').value+'&exmonth='+$('exmonth').value+'&exyear='+$('exyear').value+'&expreacher='+$('expreacher').value+'&exseries='+$('exseries').value+'&exbook='+$('exbook').value,
	onComplete: function(req){
if(req.responseText){
$('existingform').innerHTML = req.responseText;
//layerPauseRem();
}
} 
	});
}
function serexistingresults(){
	new Ajax.Request("admin/sermons_v2.0/editexisting.php",
	{ 
	method: 'post', 
	postBody: 'action=showexisting&type=formsubmit&exday='+$('exday').value+'&exmonth='+$('exmonth').value+'&exyear='+$('exyear').value+'&expreacher='+$('expreacher').value+'&exseries='+$('exseries').value+'&exbook='+$('exbook').value,
	onComplete: function(req){
if(req.responseText){
$('existingsermonsresults').innerHTML = req.responseText;
}
} 
	});
}
function serdelete(id,title,type){
if(type == 'confirm'){
confirmationLayer();
document.getElementById('confbox').innerHTML = '<br /><br />Do you really want to delete the sermon<br /><br /><b>'+title.replace(/\\'/g,'\'')+'?</b><br /><br /><div class=\"row\"><div style=\"width: 49%; float: left\"><a href=\"javascript: serdelete(\''+id+'\',\''+title+'\',\'confirmed\');\" class=\"onewaylist\">Yes</a></div><div style=\"width: 49%; float: left;\"><a href=\"javascript: confirmationLayerRem();\" class=\"onewaylist\">No</a></div></div>';
} else if(type == 'confirmed'){
	new Ajax.Request("admin/sermons_v2.0/editexisting.php",
	{ 
	method: 'post', 
	postBody: 'action=deletefile&id='+id,
	onComplete: function(req){
if(req.responseText){
serexistingresults();
}
confirmationLayerRem();

} 
	});
}
}



function serloadexisting(id){
	new Ajax.Request("admin/sermons_v2.0/editform.php",
	{ 
	method: 'post', 
	postBody: 'existingfile='+id,
	onComplete: function(req){
if(req.responseText){
$('sermoneditform').innerHTML = req.responseText;
$('sersubmit').href='javascript: sersubmit(\''+id+'\');';
hideModalLayer();
}
} 
	});
}

function seractivetoggle(id){
	new Ajax.Request("admin/sermons_v2.0/editexisting.php",
	{ 
	method: 'post', 
	postBody: 'action=activetoggle&id='+id,
	onComplete: function(req){
if(req.responseText == '1'){
$('seract'+id).src='../../commongfx/active.png';
} else if(req.responseText == '0') {
$('seract'+id).src='../../commongfx/deactive.png';
}
} 
	});

}

function sereditdialogue(){
//layerPause();
	new Ajax.Request("admin/sermons_v2.0/editexisting.php",
	{ 
	method: 'post', 
	postBody: 'action=showexisting',
	onComplete: function(req){
var exploderesult=req.responseText.split('|');
	$('toplayercontent').innerHTML= exploderesult[1];
	$('toplayertitle').innerHTML= exploderesult[0];
showModalLayer();
//layerPauseRem();
} 
	});

}


function sersaveseries(id){
	new Ajax.Request("admin/sermons_v2.0/seriesadmin.php",
	{ 
	method: 'post', 
	postBody: 'saveseriesid='+id+'&saveseriestitle='+$('editstitle').value+'&saveseriesdesc='+$('editsdesc').value,
	onComplete: function(req){
var exresponse=req.responseText.split('|');
$('seriesresults').innerHTML=exresponse[0];
$('series').innerHTML=exresponse[1];
confirmationLayerRem();

} 
	});

}


function serseriesedit(id){
	new Ajax.Request("admin/sermons_v2.0/seriesadmin.php",
	{ 
	method: 'post', 
	postBody: 'editseriesid='+id,
	onComplete: function(req){
confirmationLayer();
document.getElementById('confbox').innerHTML = req.responseText;
} 
	});

}

function seraddseries(){
	new Ajax.Request("admin/sermons_v2.0/seriesadmin.php",
	{ 
	method: 'post', 
	postBody: 'addseriestitle='+$('stitle').value+'&addseriesdesc='+$('sdesc').value,
	onComplete: function(req){
var exresponse=req.responseText.split('|');
$('seriesresults').innerHTML=exresponse[0];
$('series').innerHTML=exresponse[1];
} 
	});
}

function serdelseries(id,title,confirm){
if(confirm == 'confirm'){
confirmationLayer();
document.getElementById('confbox').innerHTML = '<br /><br />Do you really want to delete the series:<br /><br /><b>'+title+'</b><br /><br /><div class=\"row\"><div style=\"width: 49%; float: left\"><a href=\"javascript: serdelseries(\''+id+'\',\''+title+'\',\'confirmed\');\" class=\"onewaylist\">Yes</a></div><div style=\"width: 49%; float: left;\"><a href=\"javascript: confirmationLayerRem();\" class=\"onewaylist\">No</a></div></div>';

} else if(confirm == 'confirmed'){
	new Ajax.Request("admin/sermons_v2.0/seriesadmin.php",
	{ 
	method: 'post', 
	postBody: 'delseriesid='+id,
	onComplete: function(req){
confirmationLayerRem();
var exresponse=req.responseText.split('|');
$('seriesresults').innerHTML=exresponse[0];
$('series').innerHTML=exresponse[1];
} 
	});
}
}

function serchangedate(){
	new Ajax.Request("admin/sermons_v2.0/preachsearch.php",
	{ 
	method: 'post', 
	postBody: 'changeday='+$('serday').value+'&changemonth='+$('sermonth').value+'&changeyear='+$('seryear').value+'&service='+$('serservice').value,
	onComplete: function(req){
var exresponse=req.responseText.split('|');
$('preacher').value=exresponse[0];
if(exresponse[1]){
$('passage').value=exresponse[1];
} else {
$('passage').value='';
}
} 
	});
}


function sersubmit(id){

if($('active1').checked){
var active='1';
}  else if($('active2').checked){
var active='0';
}
var title=$('titlea').value+" "+$('titleb').value;

	new Ajax.Request("admin/sermons_v2.0/submit.php",
	{ 
	method: 'post', 
	postBody: 'series='+$('series').value+'&day='+$('serday').value+'&month='+$('sermonth').value+'&year='+$('seryear').value+'&service='+$('serservice').value+'&preacher='+$('preacher').value+'&reading='+$('passage').value+'&title='+escape(title)+'&existingsermon='+$('sermon').value+'&desc='+$('description').value+'&active='+active+'&serid='+id,
	onComplete: function(req){
$('sermoneditform').innerHTML=req.responseText;
} 
	});
}

function sertitlenum(action){
var currentnum=document.getElementById('titlea');
if(currentnum.value){
var prefix=currentnum.value[0];
var prelength=currentnum.value.length;
var num='';
for(a=1;a<prelength;a++){
num=num+currentnum.value[a];
}
num=parseFloat(num);
if(action == 'up'){
num++;
if(num <10){
num="0"+num;
}
document.getElementById('titlea').value=prefix+num;
}
if(action == 'down'){
num--;
if(num < 10){
num="0"+num;
}
document.getElementById('titlea').value=prefix+num;
}
}
}
function serseriesselected(){
	new Ajax.Request("admin/sermons_v2.0/seriesinfo.php",
	{ 
	method: 'post', 
	postBody: 'seriesid='+$('series').value+'&day='+$('serday').value+'&month='+$('sermonth').value+'&year='+$('seryear').value+'&service='+$('serservice').value,
	onComplete: function(req){
var exresponse=req.responseText.split('|');
$('titlea').value = exresponse[0];
if(exresponse[1]){
$('titleb').value = exresponse[1];
} else {
$('titleb').value = '';
}
} 
	});

}

function serselectpreacher(name){
document.getElementById('preacher').value=name;
}

function serpreachersearch(){
var preachstr = document.getElementById('preacher').value;
if(preachstr.length > 2){
	new Ajax.Request("admin/sermons_v2.0/preachsearch.php", 
	{ 
	method: 'post', 
	postBody: 'preacher='+$('preacher').value,
	onComplete: function(req){
$('preachoptions').innerHTML = req.responseText;
} 
	});
} else {
document.getElementById('preachoptions').innerHTML = '';
}
}

function sermondelete(file,type){
var file = file.replace(/\'/g,'\\\'');
if(type == 'confirm'){
//Draw new layer (confirmation layer)
confirmationLayer();
document.getElementById('confbox').innerHTML = '<br /><br />Do you really want to delete:<br /><br /><b>'+file.replace(/\\'/g,'\'')+'</b><br /><br /><div class=\"row\"><div style=\"width: 49%; float: left\"><a href=\"javascript: sermondelete(\''+file+'\',\'confirmed\');\" class=\"onewaylist\">Yes</a></div><div style=\"width: 49%; float: left;\"><a href=\"javascript: confirmationLayerRem();\" class=\"onewaylist\">No</a></div></div>';
} else if(type == 'confirmed'){
//Delete file (AJAX) and hide confirmation layer
	new Ajax.Request("admin/sermons_v2.0/upload.php", 
	{ 
	method: 'post', 
	postBody: 'deletefile='+file,
	onComplete: function(req){
confirmationLayerRem();
sermonselecta();
sermonslayer('1');
} 
	});


}
}
function sermonselecta(file){
	new Ajax.Request("admin/sermons_v2.0/editform.php", 
	{ 
	method: 'post', 
	postBody: 'file='+file,
	onComplete: function(req){
	$('sermoneditform').innerHTML= req.responseText;
var toplayer=document.getElementById('toplayer');
if(toplayer != null){
hideModalLayer();
}
} 
	});

}

function serseries(){
	new Ajax.Request("admin/sermons_v2.0/seriesadmin.php", 
	{ 
	method: 'post', 
	postBody: 'seriesadmin=1',
	onComplete: function(req){
var exploderesult=req.responseText.split('|');
	$('toplayercontent').innerHTML= exploderesult[1];
	$('toplayertitle').innerHTML= exploderesult[0];
showModalLayer();
sermonupload();
} 
	});
}


function sermonslayer(type){
	new Ajax.Request("admin/sermons_v2.0/fileslist.php", 
	{ 
	method: 'post', 
	postBody: 'type='+type,
	onComplete: function(req){
var exploderesult=req.responseText.split('|');
	$('toplayercontent').innerHTML= exploderesult[1];
	$('toplayertitle').innerHTML= exploderesult[0];
showModalLayer();
sermonupload();
} 
	});
}

function mincloseemail(){
hideModalLayer('ministrycontact');
document.getElementById('ministryemail').innerHTML = '';
}

function minemailsend(){
	new Ajax.Request("f/ministries/email.php", 
	{ 
	method: 'post', 
	postBody: 'type=sendmail&fromwho='+$('from').value+'&fromadd='+$('address').value+'&subject='+$('subject').value+'&body='+$('body').value+'&mid='+$('mid').value,
	onComplete: function(req){
	$('ministryemail').innerHTML= req.responseText;
} 
	});
}

function checkemail(){
var emailfromwho=document.getElementById('from');
var emailfromadd=document.getElementById('address');
var emailsubject=document.getElementById('subject');
var emailbody=document.getElementById('body');
if(emailfromwho != null && emailfromadd !=null && emailsubject != null && emailbody !=null){
if(emailfromwho.value && emailfromadd.value && emailsubject.value && emailbody.value){
document.getElementById('messagesubmit').innerHTML='<a href=\"javascript: minemailsend();\" class=\"onewaylist\" style=\"font-size: 16pt\">Send this email</a>';
}
}
}
function layerPause(){
var pagecontainer=document.getElementById('conflayer');
var confdiv1=document.createElement('div');
confdiv1.setAttribute('id','pauseshadow');
var confdiv2=document.createElement('div');
confdiv2.setAttribute('id','pauselogo');
pagecontainer.appendChild(confdiv1);
pagecontainer.appendChild(confdiv2);
elementfade('pauseshadow');
elementfade('pauselogo');
    var viewport = getViewportDimensions();
document.getElementById('pauseshadow').style.height=viewport.height+'px';
document.getElementById('pauseshadow').style.width=viewport.width+'px';
    var confElem = document.getElementById('pauselogo');
    if(confElem != null) {
        centerElement(confElem);
        window.onresize = function() {
            centerElement(confElem);
    var viewport = getViewportDimensions();
document.getElementById('pauseshadow').style.height=viewport.height+'px';
document.getElementById('pauseshadow').style.width=viewport.width+'px';
        }
    }
}

function layerPauseRem(){
var d = document.getElementById('conflayer');
var confshadow=document.getElementById('pauseshadow');
var confbox=document.getElementById('pauselogo');
elementfadeout('pauseshadow');
setTimeout(d.removeChild(confbox),1100);
setTimeout(d.removeChild(confshadow),1100);
}
function confirmationLayer(){
var pagecontainer=document.getElementById('conflayer');
var confdiv1=document.createElement('div');
confdiv1.setAttribute('id','confshadow');
var confdiv2=document.createElement('div');
confdiv2.setAttribute('id','confbox');
confdiv1.setAttribute('onclick','confirmationLayerRem()');

pagecontainer.appendChild(confdiv1);
pagecontainer.appendChild(confdiv2);
    var viewport = getViewportDimensions();
document.getElementById('confshadow').style.height=viewport.height+'px';
document.getElementById('confshadow').style.width=viewport.width+'px';
    var confElem = document.getElementById('confbox');
    if(confElem != null) {
        centerElement(confElem);
        window.onresize = function() {
            centerElement(confElem);
    var viewport = getViewportDimensions();
document.getElementById('confshadow').style.height=viewport.height+'px';
document.getElementById('confshadow').style.width=viewport.width+'px';
        }
    }
}

function confirmationLayerRem(){
var d = document.getElementById('conflayer');
var confshadow=document.getElementById('confshadow');
var confbox=document.getElementById('confbox');
d.removeChild(confbox);
d.removeChild(confshadow);
}

function showModalLayer(elem1) {
if(!elem1){
var elem1='toplayer';
}
var toplayer=document.getElementById('toplayer');
if(toplayer!=null){
toplayer.style.height='400px';
toplayer.style.width='600px';
}
    var viewport = getViewportDimensions();
document.getElementById('shadow').style.height=viewport.height+'px';
document.getElementById('shadow').style.width=viewport.width+'px';
    var modalElem = document.getElementById(elem1);

    if(modalElem != null) {
        centerElement(modalElem);
        modalElem.style.display = 'block';
        window.onresize = function() {
            centerElement(document.getElementById(elem1));
    var viewport = getViewportDimensions();
document.getElementById('shadow').style.height=viewport.height+'px';
document.getElementById('shadow').style.width=viewport.width+'px';
        }
    }
}

function hideModalLayer(elem1) {

if(!elem1){
var elem1='toplayer';
document.getElementById('toplayercontent').innerHTML = '';
}
    var modalElem = document.getElementById(elem1);

    if(modalElem != null) {
        modalElem.style.height = '0px';
        modalElem.style.width = '0px';
        document.getElementById('shadow').style.height = '0px';
        document.getElementById('shadow').style.height = '0px';
        window.onresize = null;
    }
}


function centerElement(elem) {
    var viewport = getViewportDimensions();
    var left = (viewport.width == 0) ? 50 : parseInt((viewport.width - elem.offsetWidth) / 2, 10);
    var top = (viewport.height == 0) ? 50 : parseInt((viewport.height - elem.offsetHeight) / 2, 10);
    elem.style.left = left + 'px';
    elem.style.top = top + 'px';

    viewport = left = top = ele = null;    
}




function getViewportDimensions() {
    var intH = 0, intW = 0;
    
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}
function minshowemailform(mid){
document.getElementById('ministrycontact').style.height='400px';
document.getElementById('ministrycontact').style.width='600px';
showModalLayer('ministrycontact');
minemail(mid);
}
function minemail(mid){
	new Ajax.Request("f/ministries/email.php", 
	{ 
	method: 'post', 
	postBody: 'type=loadform&mid='+mid,
	onComplete: function(req){
	$('ministryemail').innerHTML= req.responseText;
} 
	});
}

function minchangetitle(mid,pid){
	new Ajax.Request("admin/ministries/editpage.php", 
	{ 
	method: 'post', 
	postBody: 'changetitle='+mid+'&page='+pid+'&newtitle='+$('newtitle'+pid).value,
	onComplete: function(req){
	$('mineditarea').innerHTML= req.responseText;
$('newpagetitle').value="";
} 
	});
}

function minedittitle(which,mid,pid){
if(which == 'pagetitle'){
document.getElementById('minpagetitle'+pid).innerHTML="<input type=\"text\" onchange=\"minchangetitle('"+mid+"','"+pid+"');\" id=\"newtitle"+pid+"\" />";
} else if(which == 'ministrytitle'){
document.getElementById('mintitle').innerHTML="<input type=\"text\" onchange=\"minchangetitle('"+mid+"','');\" id=\"newtitle\" />";
}
}
function minmove(mid,page,job){
	new Ajax.Request("admin/ministries/editpage.php", 
	{ 
	method: 'post', 
	postBody: 'move='+job+'&page='+page+'&ministry='+mid,
	onComplete: function(req){
	$('mineditarea').innerHTML= req.responseText;
$('newpagetitle').value="";
} 
	});
}

function minsave(pid,mid,page,job){
var oEditor=FCKeditorAPI.GetInstance('body') ;
var pageValue=encodeURIComponent(oEditor.GetData());
	new Ajax.Request("admin/ministries/editpage.php", 
	{ 
	method: 'post', 
	postBody: 'pageid='+pid+'&page='+page+'&ministry='+mid+'&job='+job+'&pagebody='+pageValue,
	onComplete: function(req){
	$('mineditarea').innerHTML= req.responseText;
$('newpagetitle').value="";
} 
	});
}

function mineditpage(pid,mid) {
	new Ajax.Request("admin/ministries/editpage.php", 
	{ 
	method: 'post', 
	postBody: 'showedit='+pid+'&ministry='+mid,
	onComplete: function(req){
	$('mineditarea').innerHTML= req.responseText;
$('newpagetitle').value="";
} 
	});
}
function minaddpage(mid) {
	new Ajax.Request("admin/ministries/editpage.php", 
	{ 
	method: 'post', 
	postBody: 'newpage='+$('newpagetitle').value+'&ministry='+mid,
	onComplete: function(req){
	$('mineditarea').innerHTML= req.responseText;
$('newpagetitle').value="";
} 
	});
}
function minaddsection() {
	new Ajax.Request("admin/ministries/pages.php", 
	{ 
	method: 'post', 
	postBody: 'newsection='+$('newsectiontitle').value,
	onComplete: function(req){
	$('minadmin').innerHTML= req.responseText;
$('newsectiontitle').value="";
} 
	});
}

function minedit() {
	new Ajax.Request("admin/ministries/editpage.php", 
	{ 
	method: 'post', 
	postBody: 'editpage='+$('minselect').value,
	onComplete: function(req){
	$('mineditarea').innerHTML= req.responseText;
var mid=$('minselect').value;
mingrabimage(mid);
document.getElementById('minfiletitle').style.display = 'block';
document.getElementById('mid').value= $('minselect').value;
ministryupload();
} 
	});
}
function mingrabimage(mid){
	new Ajax.Request("admin/ministries/grabimage.php", 
	{ 
	method: 'post', 
	postBody: 'imageref='+mid,
	onComplete: function(req){
$('minfile').innerHTML = req.responseText;
} 
	});
}
function minpageaccesstoggle(pageid,user) {
	new Ajax.Request("admin/ministries/access.php", 
	{ 
	method: 'post', 
	postBody: 'edituseraccess='+user+'&pagechange='+pageid,
	onComplete: function(req){
//$('test'+user).innerHTML = req.responseText;
	if(req.responseText == 'No'){
  $('admin'+user+'page'+pageid).checked = false;
  } else if(req.responseText == 'Yes'){
  $('admin'+user+'page'+pageid).checked = true;
  } else {
$('pageaccess'+user).innerHTML = req.responseText;
}
	

} 
	});
}
function mintoggleadmin(uid) {
	new Ajax.Request("admin/ministries/admin.php", 
	{ 
	method: 'post', 
	postBody: 'user='+uid,
	onComplete: function(req){
	$('admin'+uid).innerHTML= req.responseText;
	if(req.responseText == 'No'){
  $('admin'+uid).style.backgroundColor= "#FF0000";
  $('admin'+uid).style.color= "#FFFFFF";
  } else {
  $('admin'+uid).style.backgroundColor= "#00FF00"; 
  $('admin'+uid).style.color= "#000000"; 
  }
minpageaccesstoggle('0',uid);
} 
	});
}
function minpage(page) {
	new Ajax.Request("admin/ministries/pages.php", 
	{ 
	method: 'post', 
	postBody: 'page='+page,
	onComplete: function(req){
	$('minadmin').innerHTML= req.responseText;
} 
	});
}
function massmailtoggleaccess(uid,accid) {
	new Ajax.Request("admin/mass_mail_admin/people.php", 
	{ 
	method: 'post', 
	postBody: 'user='+uid+'&accid='+accid,
	onComplete: function(req){
	$('user'+uid+'acc'+accid).innerHTML= req.responseText;
} 
	});
}
function massmailrefreshaccess() {
	new Ajax.Request("admin/mass_mail_admin/people.php", 
	{ 
	method: 'post',
	postBody: 'data=null',
	onComplete: function(req){
	$('useradmin').innerHTML= req.responseText;
} 
	});
}
function massmailrefreshaccimg(accid) {
	new Ajax.Request("admin/mass_mail_admin/accs.php", 
	{ 
	method: 'post',
	postBody: 'refreshimg='+accid,
	onComplete: function(req){
	$('accimg'+accid).innerHTML= req.responseText;
} 
	});
}

function massmailupload(){
if($('accid') != null){
new AjaxUpload('#accfile', {
 action: 'admin/mass_mail_admin/accs.php',
  name: 'userfile',
  data: {
    accid : document.getElementById('accid').value
  },
  autoSubmit: true,
  responseType: false,
  onChange: function(file, extension){},
  onSubmit: function(file, extension) {
document.getElementById('emailheader').innerHTML = "Uploading";
},
  onComplete: function(file, response) {
document.getElementById('emailheader').innerHTML = response;
var accid=document.getElementById('accid').value;
massmailrefreshaccimg(accid);
}
});
}
}

function ministryupload(){
new AjaxUpload('#minfile', {
  action: 'admin/ministries/upload.php',
  name: 'userfile',
  data: {
    mid : document.getElementById('mid').value
  },
  autoSubmit: true,
  responseType: false,
  onChange: function(file, extension){},
  onSubmit: function(file, extension) {
document.getElementById('minfile').innerHTML = "Uploading";

},
  onComplete: function(file, response) {
document.getElementById('minfile').innerHTML = response;
}
});
}
function sermonupload(){
new AjaxUpload('#sermonupload', {
  action: 'admin/sermons_v2.0/upload.php',
  name: 'userfile',
  data: {
  },
  autoSubmit: true,
  responseType: false,
  onChange: function(file, extension){},
  onSubmit: function(file, extension) {
document.getElementById('sermonupload').innerHTML = "Uploading";

},
  onComplete: function(file, response) {
if(response == 'Error'){
document.getElementById('sermonupload').innerHTML = 'Error - Click here to try again';
} else {
sermonselecta(response);
}
}
});
}

document.observe("dom:loaded", function(){
massmailupload();
});



function massmaileditacc(accid) {
	new Ajax.Request("admin/mass_mail_admin/accs.php", 
	{ 
	method: 'post', 
	postBody: 'acceditid='+accid,
	onComplete: function(req){
var exploderesult=req.responseText.split('|');
$('acctitle').value=exploderesult[0];
$('accemail').value=exploderesult[1];
$('accdesc').value=exploderesult[2];
$('accsig').value=exploderesult[3];
$('accid').value=exploderesult[4];
$('emailheader').innerHTML="<div id=\"accfile\">Upload</div>";
$('accsubmit').value="Edit Account";
massmailupload();
} 
	});
}
function massmaileditreset(){
document.getElementById('accsubmit').value='Add Account';
document.getElementById('emailheader').innerHTML='<div id=\"accfile\">Upload</div>';
}

function massmailaccadd() {
	new Ajax.Request("admin/mass_mail_admin/accs.php", 
	{ 
	method: 'post', 
	postBody: 'title='+$('acctitle').value+'&description='+$('accdesc').value+'&accid='+$('accid').value+'&signature='+$('accsig').value+'&email='+$('accemail').value,
	onComplete: function(req){
$('acctitle').value = '';
$('accemail').value = '';
$('accdesc').value = '';
$('accsig').value = '';
$('accid').value = '';
$('accsubmit').value="Add Account";
	$('massmailaccs').innerHTML= req.responseText;
massmailrefreshaccess();
} 
	});
}
function pashowrules(user) {
	new Ajax.Request("admin/PA/rules.php", 
	{ 
	method: 'post', 
	postBody: 'showrules='+user,
	onComplete: function(req){
	$('parule'+user).innerHTML= req.responseText;
} 
	});
}
function paapprove(date) {
	new Ajax.Request("admin/PA/caldisplay.php", 
	{ 
	method: 'post', 
	postBody: 'approvedate='+date,
	onComplete: function(req){
	$('pacaldisplay').innerHTML= req.responseText;
} 
	});
}
function pareset(date,job) {
	new Ajax.Request("admin/PA/caldisplay.php", 
	{ 
	method: 'post', 
	postBody: 'resetdate='+date+'&jobno='+job,
	onComplete: function(req){
	$('pacaldisplay').innerHTML= req.responseText;
} 
	});
}
function pachange(job,date,view) {
	new Ajax.Request("admin/PA/caldisplay.php", 
	{ 
	method: 'post', 
	postBody: 'editdate2='+date+'&jobno='+job+'&operator='+$('changeoperator').value+'&view='+view,
	onComplete: function(req){
	$('pacaldisplay').innerHTML= req.responseText;
} 
	});
}
function paavailtoggle(date,service) {
	new Ajax.Request("admin/PA/availability.php", 
	{ 
	method: 'post', 
	postBody: 'date='+date+"&service="+service,
	onComplete: function(req){
	pacaltoggle(date,service);
if(req.responseText == 1){
$('paavail'+service+date).style.backgroundColor= "#00FF00";
	$('paavail'+service+date).innerHTML= '<a href="javascript: paavailtoggle(\''+date+'\',\''+service+'\')" class="palink">Yes</a>';
} else {
$('paavail'+service+date).style.backgroundColor= "#FF0000";
	$('paavail'+service+date).innerHTML= '<a href="javascript: paavailtoggle(\''+date+'\',\''+service+'\')" class="palink"><span style="color: #FFFFFF">No</span></a>';
}
} 
	});
}
function pacaltoggle(date,service) {
	new Ajax.Request("admin/PA/availability.php", 
	{ 
	method: 'post', 
	postBody: 'caldate='+date+"&calservice="+service,
	onComplete: function(req){
	if(req.responseText){
var exploderesult=req.responseText.split('|');
if(exploderesult[0]){
if(exploderesult[1] == 2){
$(exploderesult[0]).style.backgroundColor="#0066FF";
} else if(exploderesult[1] == 1 ){
$(exploderesult[0]).style.backgroundColor="#FFFFFF";
} else if(exploderesult[1] == 0 ){
$(exploderesult[0]).style.backgroundColor="#FF0000";
}
}
if(exploderesult[2]){
if(exploderesult[3] == 2){
$(exploderesult[2]).style.backgroundColor="#0066FF";
} else if(exploderesult[3] == 1 ){
$(exploderesult[2]).style.backgroundColor="#FFFFFF";
} else if(exploderesult[3] == 0 ){
$(exploderesult[2]).style.backgroundColor="#FF0000";
}
}
}
} 
	});
}
function pachangead(date,job) {
	new Ajax.Request("admin/PA/caldisplay.php", 
	{ 
	method: 'post', 
	postBody: 'editdate='+date+"&job="+job,
	onComplete: function(req){
	$('pacaldisplay').innerHTML= req.responseText;
} 
	});
}

function pachangeop(date,job) {
	new Ajax.Request("admin/PA/caldisplay.php", 
	{ 
	method: 'post', 
	postBody: 'chdate='+date+"&job="+job,
	onComplete: function(req){
	$('pacaldisplay').innerHTML= req.responseText;
} 
	});
}

function paadmintoggle(teamid) {
	new Ajax.Request("admin/PA/rules.php", 
	{ 
	method: 'post', 
	postBody: 'teamid='+teamid,
	onComplete: function(req){
	$('admin'+teamid+'response').innerHTML= req.responseText;
} 
	});
}
function paruletoggle(rid) {
	new Ajax.Request("admin/PA/rules.php", 
	{ 
	method: 'post', 
	postBody: 'ruleid='+rid,
	onComplete: function(req){
	$('rule'+rid+'response').innerHTML= req.responseText;
pachangeop();
} 
	});
}
function paruletoggleadmin(rid,user) {
	new Ajax.Request("admin/PA/rules.php", 
	{ 
	method: 'post', 
	postBody: 'ruleid='+rid+'&user='+user,
	onComplete: function(req){
	$('parule'+user).innerHTML= req.responseText;
pachangeop();
} 
	});
}

function massmailadd() {
	new Ajax.Request("admin/mass_mail_admin/names.php", 
	{ 
	method: 'post', 
	postBody: 'fname='+$('fname').value + '&sname='+$('sname').value+'&email='+$('email').value,
	onComplete: function(req){
	$('allnames').innerHTML= req.responseText;
	$('fname').value="";
	$('sname').value="";
	$('email').value="";
} 
	});
}

function massmailaddlist() {
	new Ajax.Request("admin/mass_mail_admin/names.php", 
	{ 
	method: 'post', 
	postBody: 'listtitle='+$('listtitle').value + '&listdesc='+$('listdesc').value+ '&listid='+$('listid').value,
	onComplete: function(req){
	$('allnames').innerHTML= req.responseText;
$('listid').value ="";
$('listtitle').value ="";
$('listdesc').value ="";
$('dellist').innerHTML ="&nbsp;";
} 
	});
}

function showResResponse(req){
	$('allnames').innerHTML= req.responseText;
}
function togglelist(who,listid){
	new Ajax.Request("admin/mass_mail_admin/addlist.php", 
	{ 
	method: 'post', 
	postBody: 'listid='+listid + '&who='+who,
	onComplete: function(req){
	document.getElementById(+listid+'_'+who+'_container').style.backgroundColor= 'RGB(255,0,0)';
	$(listid+'_'+who+'_container').innerHTML= req.responseText;
for(c=1;c<=16;c++){
var col1=(c*16)-1;
var time=(c*50)+1000;
setTimeout("changecolor('"+listid+"','"+who+"','"+col1+"')",time);
}
} 
	});
	

}
function changecolor(listid,who,col1){
document.getElementById(+listid+'_'+who+'_container').style.backgroundColor= 'RGB(255,'+col1+','+col1+')';
}
function deluser(emailid){
	new Ajax.Request("admin/mass_mail_admin/names.php", 
	{ 
	method: 'post', 
	postBody: 'deluser='+emailid,
	onComplete: showResResponse 
	});
}
function editemail(sname,fname,mailid,email){
var html1="<form  onsubmit=\"changeemail('"+mailid+"'); return false;\"><input type=\"text\" id=\""+mailid+"_chsname\" value=\""+sname+"\" class=\"input\" /></form>";
var html2="<form  onsubmit=\"changeemail('"+mailid+"'); return false;\"><input type=\"text\" id=\""+mailid+"_chfname\" value=\""+fname+"\" class=\"input\" /></form>";
var html3="<form  onsubmit=\"changeemail('"+mailid+"'); return false;\"><input type=\"text\" id=\""+mailid+"_email\" value=\""+email+"\" class=\"input\" /></form>";
document.getElementById(+mailid+'_sname').innerHTML = html1;
document.getElementById(+mailid+'_fname').innerHTML = html2;
document.getElementById(+mailid+'_lists').innerHTML = html3;
}
function changeemail(mailid){
	new Ajax.Request("admin/mass_mail_admin/names.php", 
	{ 
	method: 'post', 
	postBody: 'changemail='+$(mailid+'_email').value+'&changefname='+$(mailid+'_chfname').value+'&changesname='+$(mailid+'_chsname').value+'&emailid='+mailid,
	onComplete: showResResponse 
	});
}

function massmaildesc(id) {
	new Ajax.Request("admin/mass_mail_send/descs.php", 
	{ 
	method: 'post', 
	postBody: 'listid='+id+'&checked='+$('list'+id).checked,
	onComplete: function(req){
	$('list'+id+'div').innerHTML = req.responseText;
	} 
	});
}
 function massmailattach(){
var anum=document.getElementById('attachfiles').value;
var output="<input type=\"hidden\" name=\"filenum\" value=\""+anum+"\">";
var height=anum*21+"px";
 for(var a=1;a<=anum;a++){
 var output=output+"<input type=\"file\" name=\"file"+a+"\"><br />";
 }
document.getElementById('attachcontainer').innerHTML=output; 
document.getElementById('attachtitle').style.height= height;
 }

function showhide(letter){
	new Ajax.Request("admin/mass_mail_admin/names.php", 
	{ 
	method: 'post', 
	postBody: 'changeletter='+letter,
	onComplete: showResResponse 
	});

}
function editlist(id){
	new Ajax.Request("admin/mass_mail_admin/lists.php", 
	{ 
	method: 'post', 
	postBody: 'id='+id+'&field=title',
	onComplete: function(req){
$('listtitle').value=req.responseText;
$('listid').value=id;
$('dellist').innerHTML="<b>Delete List:</b> <img src=\"commongfx/delete.png\" alt=\"Delete List\" title=\"Delete List\" onclick=\"dellist("+id+")\">";
} 
	});
	new Ajax.Request("admin/mass_mail_admin/lists.php", 
	{ 
	method: 'post', 
	postBody: 'id='+id+'&field=desc',
	onComplete: function(req){
$('listdesc').value=req.responseText;
} 
	});
}
function dellist(id){
	new Ajax.Request("admin/mass_mail_admin/names.php", 
	{ 
	method: 'post', 
	postBody: 'deletelist='+id,
	onComplete: function(req){
	$('allnames').innerHTML= req.responseText;
$('listid').value ="";
$('listtitle').value ="";
$('listdesc').value ="";
$('dellist').innerHTML ="&nbsp;";
} 
	});

}
