 //**************************************************************************************
 //  Prayer:       Praise the Lord for giving us the wisdom to accomplish this code.
 //                This is only tiny comparing to God's creation. May we ask Him to 
 //                grant us strength and use us more in His works to glorify His name.
 //
 //     CBC Miami web development team pray this in our Lord Jesus Christ's name.
 //                                                                                Amen.
 //**************************************************************************************

var gstr_lang=" ";
    

document.onmouseup=noRightClick;
document.onmousedown=noRightClick;

//Function to disable right click on pages.
function noRightClick() 
{
  if (event.button==2 || event.button==1+2 || event.button==2+1) 
  {
    if ( parent.gstr_lang=="Chinese" )
    {
      alert("    此網頁由主的小僕製作為傳褔音之用，要認識我們的主耶穌基督，請到 \r\n595 SW 124 Avenue, Miami, FL 33184 美亞美華人浸信教會，我們也希望認識你。");
    }
    else
    {
      alert("This page is created by the LORD'S little servants to spread the gospel. To know our LORD Jesus Christ, \r\nwe welcome you come join us at 595 SW 124 Avenue, Miami, FL 33184, Chinese Baptist Church of Miami.");
    }
  }
}

function ReqNewPage(str_lang, str_page, str_state)
{
   SetCurrentLang(str_lang, str_state);
   window.location = str_page;
}


function SetCurrentLang(str_lang, str_state)
{
   if ( str_state=="Init" )
   {
      gstr_lang = str_lang;
   }
   else if (parent.gstr_lang!= str_lang)
   {
      parent.gstr_lang = str_lang;
   }
}


function GetCurrentLang()
{
   if ( typeof(parent.gstr_lang)=="undefined" )
   {
      return "English"; 
   }

   return parent.gstr_lang;     
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//************************************************
//
//************************************************
function ActEdit(strFellowship, strMonthSwitch)
{
   document.forms[0].fellowship.value = strFellowship;
   document.forms[0].month.value = strMonthSwitch;
   document.forms[0].submit();
}      


//************************************************
//
//************************************************
function RestoreValues(frmEdit)
{
    var str_name = frmEdit.name;
    var i = 0;
          
    for (i=0; i<frmEdit.length; i++)
    {
       if ( frmEdit[i].name.substring(0,4) == "org_" )
       {
          frmEdit[i-1].value=frmEdit[i].value;
       }
               
       if ( frmEdit[i].name.substring(0,4) == "chk_" )
       {
          frmEdit[i].checked = false;
       }  
               
       if ( frmEdit[i].name.substring(0,7) == "txt_new" )
       {
          frmEdit[i].value="";
       }
   }
}


var str_direction="";

//************************************************
//
//************************************************
function PopScripture(htmprintview)
{
   prtview = window.open(htmprintview, 'PopScripture', 'width=700, height=300, top=10, left=30, menubar=no, resizable=no, scrollbars=yes, location=no, status=no, toolbar=yes'); 
}


//************************************************
//
//************************************************
function PopPrintView(htmprintview)
{
   prtview = window.open(htmprintview, 'PrintViewPopup', 'width=820, height=600, top=10, left=30, menubar=no, resizable=no, scrollbars=yes, location=no, status=no, toolbar=yes'); 
}

//************************************************
// Map functions
//************************************************
var map = null;
var str_cbcAddress = '595 SW 124th Ave, Miami, FL 33184';

//Don't feel comfortable to see Lagt & Long 
// directly on htm or php, just hide them here.
function GetDestAddr(str_Dest)
{
    var str_Dest_Addr = "";

    switch (str_Dest)
    {
        case "RETREAT":
           str_Dest_Addr = "1200 Glory Way Blvd., Bradenton, FL 34212";
           break; 

        default:
           str_Dest_Addr = "595 SW 124th Ave, Miami, FL 33184";
           break;
    }
   
    return ( str_Dest_Addr );
}

//************************************************
//************************************************
function GetDestDesp(str_Dest)
{
    var str_Dest_Desp = "";

    switch (str_Dest)
    {
        case "RETREAT":
           str_Dest_Desp = "Bradenton Christian Retreat";
           break; 

        default:
           str_Dest_Desp = "Chinese Baptist Church of Miami";
           break;
    }
   
    return ( str_Dest_Desp );
}

//************************************************
//************************************************
function GetDestLagt(str_Dest)
{
    var n_Dest_Lagt = 0;

    switch (str_Dest)
    {
        case "RETREAT":
           n_Dest_Lagt = 27.518757;
           break; 

        default:
           n_Dest_Lagt = 25.762683;
           //n_Dest_Lagt = 25.76322;
           break;
    }
   
    return ( n_Dest_Lagt );
}

//************************************************
//************************************************
function GetDestLong(str_Dest)
{
    var n_Dest_long = 0;

    switch (str_Dest)
    {
        case "RETREAT":
           n_Dest_long = -82.403664;
           break; 

        default:
           n_Dest_long = -80.396641;
           //n_Dest_long = -80.39569;
           break;
    }
   
    return ( n_Dest_long );
}

//************************************************
//************************************************
function GetMap(str_Dest, strlang)      
{
   var str_address = GetDestAddr(str_Dest);
   var n_Lagt = GetDestLagt(str_Dest);
   var n_Long = GetDestLong(str_Dest);
   var strDesp = GetDestDesp(str_Dest);
 
   gstr_lang=strlang;

   map = new VEMap('cbcMap');
   map.SetDashboardSize(VEDashboardSize.Small); 

   map.LoadMap();
   FindLoc(str_address);
   PutCenterPin(str_address, n_Lagt, n_Long, strDesp);
   document.forms[0].txtFromLoc.focus();      
}

function FindLoc(str_address)
{
   try
   {
      map.Find(null, str_address);
   }
   catch(e)
   {
      alert(e.message);
   }
}

function PutCenterPin(str_address, n_Lagt, n_Long, strDesp)
{
    //Longitude=-80.39569
    //Lagtitude=25.76322          
    var cbcLatLong=new VELatLong(n_Lagt, n_Long); 
    var shape = new VEShape( VEShapeType.Pushpin, cbcLatLong);
    shape.SetTitle(strDesp);          
    shape.SetDescription(str_address);          
    map.AddShape(shape);
}

function GetDirRoute(n_switch, str_Dest)
{
    var str_from="";
    var str_to="";
    try
    {  
       //if (!document.forms[0].chkReverse.checked)
       if (0==n_switch) 
       {
          str_from=document.forms[0].txtFromLoc.value;
          //str_to=str_cbcAddress;
          str_to=GetDestAddr(str_Dest);                  
       }
       else
       {
          str_to=document.forms[0].txtFromLoc.value;
          //str_from=str_cbcAddress;
          str_from=GetDestAddr(str_Dest);  
       }
       
       //Look like the map.GetRoute() call just spawn a thread and then return immediately.
       // The problem here is a popup window that initiated in a thread will be block by the browser 
       // user unblock before the popup can show. 
       // but if we just popup ourself, after this call return, the direction info may not be ready
       // when this call returns because thread may prompt user to choose from a list of closest match addresses.

       //To solve this problem, we make a confirm box for user to choose if they want to print.
       // This actually helps to sync back the thread.   
       map.GetRoute(str_from,
                    str_to,
                    null,
                    null,
                    onGotRoute);
    }
    catch(e)
    {
        alert(e.message);
    } 
}
   
function onGotRoute(route)
{
      str_direction="";

      var routeinfo="Route info:\n\n";
      str_direction="Route info:<br/><br/>";

      routeinfo+="Total distance: ";
      str_direction+="Total distance: ";

      routeinfo+=   route.Itinerary.Distance+" ";
      str_direction+= route.Itinerary.Distance+" ";

      routeinfo+=   route.Itinerary.DistanceUnit+"\n";
      str_direction+=   route.Itinerary.DistanceUnit+"<br/>";
      
      var steps="";
      var str_steps="";

      var len = route.Itinerary.Segments.length;

      for(var i = 0; i < len ;i++)
      {
            steps+=route.Itinerary.Segments[i].Instruction+" -- (";
            str_steps+=route.Itinerary.Segments[i].Instruction+" -- (";

            steps+=route.Itinerary.Segments[i].Distance+") ";
            str_steps+=route.Itinerary.Segments[i].Distance+") ";

            steps+=route.Itinerary.DistanceUnit+"\n";
            str_steps+=route.Itinerary.DistanceUnit+"<br/>"; 
      }
      
      routeinfo+="Steps:\n"+steps+"\n\nTo print direction, allow \"Popup\" in your browser, then click \"OK\".\n\nTo view route on the map directly, click \"Cancel\".\n";
      str_direction+="Steps:<br/>"+str_steps;
      
      if(confirm(routeinfo))
      {
         PopPrintView('cbcshowdir.htm');
      }
}

//Support Retreat 2008
function PopLargeForm(htmprintview)
{
   prtview = window.open(htmprintview, 'LargeFormPopup', 'width=1024, height=800, top=10, left=30, menubar=no, resizable=no, scrollbars=yes, location=no, status=no, toolbar=no'); 
}
