// JavaScript Document


function makeStateSelectOptions(target)
{
    var tmpStateList;
    var tmpReturnString;
    var tmpStateArray;
    var i;
    var selectFlag;

    var tmpStateList = "AL|AK|AZ|AR|CA|CO|CT|DC|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY"
    tmpReturnString = tmpReturnString + "<option value=''>&#160;</option>"
    tmpStateArray = tmpStateList.split("|");
    tmpReturnString = '<select id="' + target + '_state" name="' + target + '_state">'

    for (i = 0; i < tmpStateArray.length; i++)
    {
        tmpReturnString = tmpReturnString + "<option value='" + tmpStateArray[i] + "'>" + tmpStateArray[i] + "</option>"
    }
    tmpReturnString = tmpReturnString + "</select>"
    document.getElementById(target).innerHTML = tmpReturnString;
}

function doSearch(searchTerm) {
    tmpURL = "search.aspx?searchfield=" + searchTerm;
    window.location = tmpURL;
}


function pageWide()
{
    document.getElementById("mainLeft").style.width = "925px";
	document.getElementById("mainLeft").style.minHeight = "0px";
	document.getElementById("mainRight").style.width = "963px";
	document.getElementById("mainRight").style.paddingTop = "10px";
	document.getElementById("mainRight").style.paddingLeft = "17px";
	document.getElementById("mainRight").style.minHeight = "0px";
}


if (window.name != "pod") 
{
    window.name = "main";
}


function tmpPopup(url) 
{

    window.open(url, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}



function setConsoleInfo(pageid) 
{
	window.parent.document.getElementById("curidspan").innerHTML = pageid;
	window.parent.document.getElementById("currpageid").value = pageid;

}

function doRo(item) {
    $(item).animate({ opacity: 0.5 }, 150)
    $(item).animate({ opacity: 1.0 }, 150)

}


var tmpLastElement = "";
function makeActive(tmpElement) {

    tmpLocationArray = tmpElement.split("_")
    tmpElementID = tmpLocationArray[2];
    tmpStoryID = tmpLocationArray[1];

    if (window.parent.document.getElementById("editmode").value == "true") {

        if (tmpLastElement != "") {
            //alert(tmpLastElement)
            document.getElementById(tmpLastElement).style.backgroundColor = "";
        }
        tmpLastElement = tmpElement;
        document.getElementById(tmpElement).style.backgroundColor = "#ffcc00";

        window.parent.document.getElementById("hdncurrstoryid").value = tmpStoryID;
        window.parent.document.getElementById("activeIndicator").value = tmpElementID;
    }
}

function swapFrame(url,tmpCurrTemplateID)
{
	window.location = url;
}


var prevItem;
function swapRotatorText(i) 
{
    
    $(prevItem).fadeOut("slow");
    $("#rotator" + i).fadeIn("slow");
    
    prevItem = "#rotator" + i;
}



var prevPodItem = "#pod1";
function swapPod(i) {
    var item = "#pod" + i;
    $(prevPodItem).fadeOut("slow");
    $(item).fadeIn("slow");

    prevPodItem = item;
}





var prevHomeItem = 0;
function swapHomeContent(id) {

    $(prevHomeItem).fadeOut("slow");
    $("#page" + id).fadeIn("slow");

    prevHomeItem = "#page" + id;
}


function swapHomeDiv(id) {
    var obj = "page" + id;

    document.getElementById("homeMain").style.display = "block";

    if (prevHomeItem != "#page" + id) {
        document.getElementById("page0").style.display = "none";
        document.getElementById("page1").style.display = "none";
        document.getElementById("page2").style.display = "none";

        swapHomeContent(id);
    }

}

function hideHomeContent() {

    if (prevHomeItem != 0) {
        var item = prevHomeItem.replace("#", "");
        document.getElementById(item).style.display = "none";
        document.getElementById("homeMain").style.display = "none";
        //document.getElementById("page1").style.display = "none";
        //document.getElementById("page2").style.display = "none";
        prevHomeItem = 0;
    }
}

function openEvite(id)
{
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;	
    var movefromedge=0;
    placementx=(ScreenWidth/2)-((650)/2);
    placementy=(ScreenHeight/2)-((500+50)/2);
    var PopUpUrl= "evite.aspx?storyid=" + id

	window.open(PopUpUrl,"","width=350,height=550,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}

function sendPageLink(headline)
{
	tmpURL = "includes/sendPageLink.asp?pageID=" + document.getElementById("currentpageid").value;
	window.open(tmpURL, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function printPage()
{
	tmpURL = "print.asp?storyid=" + document.getElementById("currentstoryid").value;
	window.open(tmpURL, "null", "height=800,width=630,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes");
}

function sendHomeLink(headline)
{
	tmpURL = "sendHomeLink.asp?pageID=" + document.getElementById("currentpageid").value;
	window.open(tmpURL, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function sendStoryLink()
{
	tmpURL = "includes/sendStoryLink.asp?storyid=" + document.getElementById("currentstoryid").value;
	window.open(tmpURL, null, "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function getEventList(pageid, source)
{

    $.ajax({
        url: "/retrieval/getEventList.aspx?pageid=" + pageid + "&source=" + source,
        cache: false,
        success: function(html)
        {
            $("#eventMain").html(html);
        }
    });
    if (window.parent.document.getElementById("currpageid") != null)
    {
        window.parent.document.getElementById("currpageid").value = pageid;
    }
}


/*
var event_http_request = false;
function getEventList(pageid, source) {
	if(event_http_request) {
		event_http_request.abort();
		event_http_request = false;
	}
	if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
		event_http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE 6-
		event_http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var url = "/retrieval/getEventList.aspx?pageid=" + pageid + "&source=" + source;

    event_http_request.onreadystatechange = function(){ writeEvents() };
	event_http_request.open("GET", url, true);
	event_http_request.send(null);

	if (window.parent.document.getElementById("currpageid") != null) 
    {
        window.parent.document.getElementById("currpageid").value = pageid;
    }

}

function writeEvents()
{
	if (event_http_request.readyState == 4)
	{
	    if (event_http_request.status == 200) {
	        document.getElementById("mainText").innerHTML = event_http_request.responseText;
		}
	}
}
*/

//TODO: I dont think this is used either
var addStory_http_request = false;
function addStory(id)
{
	if(addStory_http_request) {
		addStory_http_request.abort();
		addStory_http_request = false;
	}
	if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
		addStory_http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE 6-
		addStory_http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	var url = "/includes/getStoryBody.asp?storyid=" + id;
	

	addStory_http_request.onreadystatechange = function(){ writeNewStory() };
	addStory_http_request.open("GET", url, true);
	addStory_http_request.send(null);

}

function writeNewStory()
{	
	if (addStory_http_request.readyState == 4)
	{	
		if (addStory_http_request.status == 200)
		{	
			document.getElementById("extraStory").innerHTML = addStory_http_request.responseText;
		}
	}
}


function showGallery2(id)
{
	//document.getElementById("galleryDiv").style.height = "804px";
	//document.getElementById("galleryDiv").style.width = "730px";
	
	var flashObject = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="804" height="730">'
	+ '<param name="movie" value="/gallery.swf?gid=' + id + '">'
	+ '<param name="quality" value="high">'
	+ '	<param name="wmode" value="transparent" />'
	+ '<embed src="/gallery.swf?gid=' + id + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="804" height="730" wmode="transparent"></embed>'
	+ '</object>'
	document.getElementById("galleryDiv").innerHTML = flashObject;
	document.getElementById("galleryDiv").style.display = "block";
	document.getElementById("header").scrollIntoView();
}


//--------------------
function showGallery(id)
{
    $.ajax({
        url: "/retrieval/getGallery.aspx?gid=" + id,
        cache: false,
        success: function(html)
        {
            $("#gallery").html(html);
            $("a[rel^='prettyPhoto']").prettyPhoto();
        }
    });
}

/*
var showGallery_http_request = false;
function showGallery(id) {
    if (showGallery_http_request) {
        showGallery_http_request.abort();
        showGallery_http_request = false;
    }
    if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
        showGallery_http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE 6-
    showGallery_http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var url = "/retrieval/getGallery.aspx?gid=" + id;


    showGallery_http_request.onreadystatechange = function() { writeGallery() };
    showGallery_http_request.open("GET", url, true);
    showGallery_http_request.send(null);

}

function writeGallery() {
   
    if (showGallery_http_request.readyState == 4) {

        if (showGallery_http_request.status == 200) {

            document.getElementById("gallery").innerHTML = showGallery_http_request.responseText;
            $("a[rel^='prettyPhoto']").prettyPhoto();
        }
    }
}
*/
//------------------------



function closeGallery()
{
	//document.getElementById("galleryFrame").innerHTML = "";
	//document.getElementById("galleryDiv").style.height = "0px";
	//document.getElementById("galleryDiv").style.width = "0px";
	document.getElementById("galleryFrame").style.display = "none";
}


//--------------------


var getServiceTimes_http_request = false;
function getServiceTimes(id) {
    if (getServiceTimes_http_request) {
        getServiceTimes_http_request.abort();
        getServiceTimes_http_request = false;
    }
    if (window.XMLHttpRequest) { // Mozilla [11], Safari, IE 7
        getServiceTimes_http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE 6-
    getServiceTimes_http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var url = "/retrieval/getServiceTimes.aspx?storyid=" + id;


    getServiceTimes_http_request.onreadystatechange = function() { writeServiceTimes() };
    getServiceTimes_http_request.open("GET", url, true);
    getServiceTimes_http_request.send(null);

}

function writeServiceTimes() {
    
    if (getServiceTimes_http_request.readyState == 4) {
        if (getServiceTimes_http_request.status == 200) {
            document.getElementById("serviceTimes").innerHTML = getServiceTimes_http_request.responseText;
        }
    }
}
//------------------------












//This function is deprecated
function checkImage()
{
	if (document.getElementById("SPmiddle").innerHTML == "")
	{
		document.getElementById("SPmiddle").style.height = "0px";
		document.getElementById("SPstoryHolder").style.top = "0px";
	}
}

function resizeVidDiv()
{	
		document.getElementById("mainImage").style.height = "404px";
}

function resizeVidDivShort()
{	
		document.getElementById("mainImage").style.height = "303px";
}

var mainImageDefaultHeight = "203px";
function shrinkMainImageDiv()
{
	document.getElementById("mainImage").style.height = "0px";
	mainImageDefaultHeight = "0px";
}


function shrinkVidDiv()
{	
	document.getElementById("mainImage").style.height = mainImageDefaultHeight;

	if((document.getElementById("hdnvidfile").value != "" && document.getElementById("hdnvidfile").value != "/images/flvvideo/none") || document.getElementById("hdnlcid").value != 0)
	{
		resetVidDiv();
	}
	else
	{
		resetMainImage(document.getElementById("hdnvidimage").value);
	}		
}

function writeNewVideo(file, lcid)
{
	//shrinkVidDiv();
	ip = document.getElementById("hdnip").value;
	image = document.getElementById("hdnvidimage").value;
	//wideScreen = document.getElementById("hdniswidescreen").value;
	file = "images/flvvideo/" + file


	var flashObject = '<object id="flvVideo" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"  width="432" height="243" >'
	+ '          <param name="movie" value="mainimageplayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" />'
	+ '          <param name="quality" value="high" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="mainimageplayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=play" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  width="432" height="243" wmode="transparent"></embed>'
	+ '          </object>'


	document.getElementById("mainImage").innerHTML = flashObject;
	document.getElementById("headerdiv").scrollIntoView();	
}

function resetVidDiv()
{	
	lcid = document.getElementById("hdnlcid").value;
	ip = document.getElementById("hdnip").value;
	image = document.getElementById("hdnvidimage").value;
	file = document.getElementById("hdnvidfile").value;
	//wideScreen = document.getElementById("hdniswidescreen").value;
	
	var flashObject = '<object id="flvVideo" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="558" height="419" >'
	+ '          <param name="movie" value="mainimagepayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" />'
	+ '          <param name="quality" value="high" />'
	+ '      	 <param name="wmode" value="transparent" />'
	+ '          <embed src="mainimagepayer.swf?video=' + file + '&lcid=' + lcid + '&ip=' + ip + '&image=' + image + '&playflag=" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="558" height="419" wmode="transparent"></embed>'
	+ '          </object>'
	
	//alert(flashObject)
	document.getElementById("mainImage").innerHTML = flashObject;

}

function resetMainImage(image) {
    alert("If you see this tell Lee");
	var flashObject = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="539" height="203">'
    + '    <param name="movie" value="mainImage.swf?image=' + image + '" />'
    + '    <param name="quality" value="high" />'
	+ '    <param name="wmode" value="transparent" />'
    + '    <embed src="mainImage.swf?image=' + image + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="539" height="203" wmode="transparent"></embed>'
    + '    </object>'
	document.getElementById("mainImage").innerHTML = flashObject;
}


function showMinistryMenu() {
    document.getElementById("ministryMenu").style.display = "block";
}

function hideMinistryMenu() {
    document.getElementById("ministryMenu").style.display = "none";
}




