﻿var gDDFS = '../';

function Set_DDFS(DDFS)  {
    gDDFS = DDFS
 } 
 
<!-- Begin
	/* This script and many more are available free online at
	The JavaScript Source!! http://javascript.internet.com
	Created by: Ultimater :: http://ultimiacian.tripod.com/
	Add this snippet to the very beginning of your script. */

	if(!document.getElementById){
	if(document.all)
	document.getElementById=function(){
		if(typeof document.all[arguments[0]]!="undefined")
		return document.all[arguments[0]]
		else
		return null
	}
	else if(document.layers)
	document.getElementById=function(){
		if(typeof document[arguments[0]]!="undefined")
		return document[arguments[0]]
		else
		return null
	}
	}
	// End -->	
	
	browserName=navigator.appName;
	browserVer=parseInt(navigator.appVersion);
	
	if (browserVer > 2) {
	
	Home_R = new Image(72, 28);
	Home_R.src="../images/Home_R.gif";
	Home_O = new Image(72, 28);
	Home_O.src="../images/Home_O.gif";	
	
	Photos_R = new Image(86, 28);
	Photos_R.src="../images/Photos_R.gif";
	Photos_O = new Image(86, 28);
	Photos_O.src="../images/Photos_O.gif";		
	
	Profiles_R = new Image(94, 28);
	Profiles_R.src="../images/Profiles_R.gif";
	Profiles_O = new Image(94, 28);
	Profiles_O.src="../images/Profiles_O.gif";		
	
	ChatterMatter_R = new Image(140, 28);
	ChatterMatter_R.src="../images/ChatterMatter_R.gif";
	ChatterMatter_O = new Image(140, 28);
	ChatterMatter_O.src="../images/ChatterMatter_O.gif";			
	
	Events_R = new Image(87, 28);
	Events_R.src="../images/Events_R.gif";
	Events_O = new Image(87, 28);
	Events_O.src="../images/Events_O.gif";		
	
	Articles_R = new Image(79, 28);
	Articles_R.src="../images/Articles_R.gif";
	Articles_O = new Image(79, 28);
	Articles_O.src="../images/Articles_O.gif";		
	
	PrayerRequests_R = new Image(142, 28);
	PrayerRequests_R.src="../images/PrayerRequests_R.gif";
	PrayerRequests_O = new Image(142, 28);
	PrayerRequests_O.src="../images/PrayerRequests_O.gif";			
	
	ManageMyProfile_R = new Image(160, 28);
	ManageMyProfile_R.src="../images/ManageMyProfile_R.gif";
	ManageMyProfile_O = new Image(160, 28);
	ManageMyProfile_O.src="../images/ManageMyProfile_O.gif";			
	
	
	Logout_R = new Image(90, 28);
	Logout_R.src="../images/Logout_R.gif";
	Logout_O = new Image(90, 28);
	Logout_O.src="../images/Logout_O.gif";			
	
	BB_Photos_R = new Image(281, 49);
	BB_Photos_R.src="../images/BB_Photos_R.gif";
	BB_Photos_O = new Image(281, 49);
	BB_Photos_O.src="../images/BB_Photos_O.gif";		
	
	BB_Profiles_R = new Image(281, 49);
	BB_Profiles_R.src="../images/BB_Profiles_R.gif";
	BB_Profiles_O = new Image(281, 49);
	BB_Profiles_O.src="../images/BB_Profiles_O.gif";		
	
	BB_ChatterMatter_R = new Image(281, 49);
	BB_ChatterMatter_R.src="../images/BB_ChatterMatter_R.gif";
	BB_ChatterMatter_O = new Image(281, 49);
	BB_ChatterMatter_O.src="../images/BB_ChatterMatter_O.gif";		
	
	BB_Events_R = new Image(281, 49);
	BB_Events_R.src="../images/BB_Events_R.gif";
	BB_Events_O = new Image(281, 49);
	BB_Events_O.src="../images/BB_Events_O.gif";		
	
    BB_Articles_R = new Image(281, 49);
	BB_Articles_R.src="../images/BB_Articles_R.gif";
	BB_Articles_O = new Image(281, 49);
	BB_Articles_O.src="../images/BB_Articles_O.gif";	
	
    BB_PrayerRequests_R = new Image(281, 49);
	BB_PrayerRequests_R.src="../images/BB_PrayerRequests_R.gif";
	BB_PrayerRequests_O = new Image(281, 49);
	BB_PrayerRequests_O.src="../images/BB_PrayerRequests_O.gif";	

    BB_ManageMyProfile_R = new Image(281, 49);
	BB_ManageMyProfile_R.src="../images/BB_ManageMyProfile_R.gif";
	BB_ManageMyProfile_O = new Image(281, 49);
	BB_ManageMyProfile_O.src="../images/BB_ManageMyProfile_O.gif";	
	
    BB_CaptionContest_R = new Image(281, 49);
	BB_CaptionContest_R.src="../images/BB_CaptionContest_R.gif";
	BB_CaptionContest_O = new Image(281, 49);
	BB_CaptionContest_O.src="../images/BB_CaptionContest_O.gif";		
				
	DashImg = new Image(5, 9);
	DashImg.src="images/SideNavDash.gif";
	ClearImg = new Image(5, 9);
	ClearImg.src="images/Clear.gif";
	
	}
	
	function Dash_Roll(imgName) {
		var el = document.getElementById(imgName);
		if (el != null) {
				el.src = DashImg.src;
		}
	}
		
	function RollIt(imgName) {
		var el = document.getElementById(imgName);
		el.src = eval(imgName + "_O.src");
	}
	
	function UnRollIt(imgName) {
		var el = document.getElementById(imgName);
		el.src = eval(imgName + "_R.src");
	}
	

function CheckPreviewURL () {

    // this function is obsolete now, use CheckPreviewURL_v2(Form_Prefix) now - 11/10/2007 jbh
}

function CheckPreviewURL_v2(Form_Prefix) {

	var PU 
	var myDate = new Date()
	var DT
	var el = FindMyControl(Form_Prefix + '_hdPreviewURL');
	
	if (el == false) { return };
	
	if (el.value.length > 1) {
		PU = 'Preview.aspx?PreviewURL=' + escape(f.PreviewURL.value);
		// append a DateTime stamp to prevent caching
		DT = 'DATESTAMP' + myDate.getMonth();
		DT = DT + myDate.getDate();
		DT = DT + myDate.getYear();
		DT = DT + myDate.getHours();
		DT = DT + myDate.getMinutes();
		DT = DT + myDate.getSeconds();
		PU = PU + '&DT=' + DT;
		// pop-up preview URL
		PreviewWindow = window.open(PU, 'Preview', 'scrollbars=auto,width=800,height=570,toolbar=no,location=no,directories=no,location=no;status=no,resizable=yes');
		PreviewWindow.focus()
		el.value = '';
	}

}

function TimeUnique() {
	var Val 
	var today = new Date();
	Val = 'M' + today.getMonth();
	Val = Val + 'D' + today.getDay()
	Val = Val + 'Y' + today.getYear();
	Val = Val + 'H' + today.getHours();
	Val = Val + 'M' + today.getMinutes();
	Val = Val + 'S' + today.getSeconds();
	Val = Val + 'ML' + today.getMilliseconds();
	
	return Val;
}

function PositionLayer(LayerName, OffSetX, OffSetY) {

	var imgX;
	var imgY;
	var MyScrollTop;
    var el;
    
		
   	if (OffSetX == 450 ) { OffSetX = 325 }		// correction
	if (navigator.appVersion.indexOf('MSIE 7') > -1) { OffSetY = OffSetY + 20 } // correct for IE 7
	
	// find the center of the window
	
	// NOTE: The lines below are only required if the application design is centered, otherwise don't adjust
	//imgX = (document.body.clientWidth / 2);	
	//imgX = imgX - OffSetX

	imgX = OffSetX
	imgY = OffSetY;
	// adjust for scroll position
	if (document.documentElement && !document.documentElement.scrollTop)   // IE6 +4.01 but no scrolling going on
        { MyScrollTop = 0 }    
    else if (document.documentElement && document.documentElement.scrollTop)  // IE6 +4.01 and user has scrolled
        { MyScrollTop = document.documentElement.scrollTop }   
    else if (document.body && document.body.scrollTop) // IE5 or DTD 3.2
        { MyScrollTop = document.body.scrollTop }   
	imgY = imgY + MyScrollTop;
	// make sure they are integers
	imgX = parseInt(imgX);
	imgY = parseInt(imgY);
	
	el = FindMyControl(LayerName);
	if ( el != false ) {
	    el.style.left = imgX + 'px'; 
	    el.style.top = imgY + 'px';
	}

  
}

function PositionLayerAbsolute(LayerName, imgX, imgY) {

    var el;
    
	el = FindMyControl(LayerName);
	if ( el != false ) {
		el.style.left = imgX + 'px';
	    el.style.top = imgY + 'px'; 
    }
    
}

function ShowLayer(LayerName) {		

	// determine our browser type for layer usage
	var el;
	
	el = FindMyControl(LayerName);
	if ( el != false ) {
		el.style.visibility = 'visible';
    }
	
}

function CancelLayer(LayerName) {

    var f;
    var el;
    
	el = FindMyControl(LayerName);
	if ( el != false ) {
		el.style.visibility = 'hidden';
    }    

}		
       

function HideSelects() {
	var selects,i;
	selects=document.getElementsByTagName('select');
	for(i in selects)
	{
		if (selects[i].options) { selects[i].style.visibility = 'hidden'; }
	}
}			
	
function UnHideSelects() {
	var selects,i;
	selects=document.getElementsByTagName('select');
	for(i in selects)
	{
		if (selects[i].options) { selects[i].style.visibility = 'visible'; }
	}
}

function ShowTaskLayer(x, y, w, h, src) {

	ShowLayer('lyrTask'); 
	PositionLayer('lyrTask', x, y); 
    document.all.ifTask.style.width=w;
    document.all.ifTask.style.height=h; 
	document.frames('ifTask').location=src; 	

}

function Show_Add_Task(P_ID, Link) {

	ShowLayer('lyrTask'); 
	PositionLayer('lyrTask', 305, 130); 
	document.frames('ifTask').location = Link;

}

function Delete_List_Item(Flag, Action, Form_Prefix) {

    var el;
    var el2;

    if (confirm('This will remove this item from this list.  Click Ok to continue or Cancel.')) 
        {
            el = FindMyControl(Form_Prefix + '_hdFlag');
            el.value = Flag;
            el = FindMyControl(Form_Prefix + '_hdAction');
            el.value = Action;
            
            // Test if this should be an AJAX Submit or regular submit
            el = FindMyControl(Form_Prefix + '_hdAjaxButtonIDElement');
            if ( el == false ) { 
                // re-grab our original form element to get access to the form
                el = FindMyControl(Form_Prefix + '_hdFlag');
                el.value = Flag;
                el.form.submit(); 
                return; 
                }
                
            if ( el.value == '' ) {
                el.form.submit();
             }
            else {
                 // get the button control id
                el = FindMyControl(el.value); 
                btnControlID = el.value;
                // click our button for the AJAX post back, this is crazy and I'm sure there is a better way, but here we are...
                el = document.getElementById(btnControlID);
                el.click();    
            }
            
        }
    else
        { 
            return;
          }
}

function MoveItem(Flag, Form_Prefix) {
    var el;
    el = FindMyControl(Form_Prefix + '_hdFlag');
    el.value = Flag;
    el = FindMyControl(Form_Prefix + '_hdAction');
    el.value = 'MoveItem';
    el.form.submit();
}

function FindMyControl(MyID) {

	var frmElements,i,t,ctl;
	
	// Since the use of master pages mangles the names of child controls, we need a method 
	// of searching through the form elements and returning a reference to the control we are 
	// looking for that control by the name we know it as instead of the name ASP.Net creates.
	// First scan through all of the input elements and look for our control
	
    frmElements=document.getElementsByTagName('input');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }
   
    
   // Still not found, scan through all of the select elements
    frmElements=document.getElementsByTagName('select');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    } 
   
   // Still not found, scan through all of the textarea elements
    frmElements=document.getElementsByTagName('textarea');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }   
   
   // Still not found, scan through all of the iframe elements
    frmElements=document.getElementsByTagName('td');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }         
   
   // Still not found, scan through all of the span elements
    frmElements=document.getElementsByTagName('div');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    } 
    
   // Still not found, scan through all of the iframe elements
    frmElements=document.getElementsByTagName('img');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }  
    
   // Still not found, scan through all of the iframe elements
    frmElements=document.getElementsByTagName('table');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }         
    
   // Still not found, scan through all of the iframe elements
    frmElements=document.getElementsByTagName('iframe');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }       
   
   // Still not found, scan through all of the span elements
    frmElements=document.getElementsByTagName('span');
    for(i in frmElements)
    {
        t = String(frmElements[i].id); 
        t = '_' + t;
        if (t.indexOf(MyID) > -1 )
            { return frmElements[i] }
    }  
   
  return false;  

}


function ACE_Selection(source, eventArgs) {

        var el;
        var el_name;
        
        el_name = source.get_id()
        el_name = el_name.substring(el_name.indexOf('_ace') + 4, el_name.length);
        el = $get(el_name);
        el.value = eventArgs.get_value();
      
       //alert ("Key : " + eventArgs.get_text() + " Value : " + eventArgs.get_value());

   }
   
function Validate_FUM_Element(Label, ShortID) {

    var el;
    var RequiredFileCnt;
    var FileCnt;
    
    el = document.getElementById(ShortID + '_FileCnt');
    FileCnt = parseInt(el.value);
    el = document.getElementById(ShortID + '_RequiredFileCnt');
    RequiredFileCnt = parseInt(el.value);
  
    if (FileCnt < RequiredFileCnt) {
        alert('For \"' + Label + '\" at least ' + RequiredFileCnt + ' file(s) must be provided before you can mark as done.\n\nPlease go back and provide the required file(s).');
        return false;
   }
   else
   {
        return true;
    }

}

function ConfirmSendNow() {

    if (confirm('This will send the messages below out now. Click Ok to continue or cancel.')) { 
        var el; 
        el = FindMyControl('hdFlag'); 
        el.value = 'SendNow'; 
        el.form.submit()
    }

}
   
function Validate_Form_Element(Label, FieldName, DataType, DisplayOption, MaxLength, Required) {

    var el;
    var el2;
    var ElementValid = true; 
   
   // make sure MaxLength is a good number    
   MaxLength= parseInt(MaxLength);
   if (MaxLength == 'NaN') { MaxLength = 0 } 
     
    switch (DisplayOption) {
        case "CL":
              // Required value test - currently test for at least one being checked
              var inputs = document.getElementsByTagName ('input');
              var SomethingChecked = false; 
              if (inputs) {
                for (var i = 0; i < inputs.length; ++i) {
                  if (inputs[i].type == 'checkbox' && inputs[i].name.indexOf(FieldName) > -1)
                        {
                            if (inputs[i].checked == true) { SomethingChecked = true }
                        } 
                  }
              }
             if ( Required == 'Yes' && SomethingChecked == false ) {
                    ElementValid = false;
                    alert(Label + ' is a required field.  Please select a value for this item.');
               } 
            break; 
        case "DC":
            
            break;
        case "DD":
            el = FindMyControl(FieldName);
            if (el == false) { return true }
            // Required value test
            if (Required == 'Yes' && el.selectedIndex <= 0) 
                {
                    ElementValid = false;
                    alert(Label + ' is a required field.  Please select a value for this item.');                    
                }
            break;
        case "HD":
            
            break;
        case "HF":
            
            break;
        case "HF2":
            
            break;
        case "ML":
            
            break;
        case "PW":
            
            break;
        case "RL":
              // Required value test
              var inputs = document.getElementsByTagName ('input');
              var SomethingChecked = false; 
              if (inputs) {
                for (var i = 0; i < inputs.length; ++i) {
                  if (inputs[i].type == 'radio' && inputs[i].name.indexOf(FieldName) > -1)
                        {
                            if (inputs[i].checked == true) { SomethingChecked = true }
                        } 
                  }
              }
             if ( Required == 'Yes' && SomethingChecked == false ) {
                    ElementValid = false;
                    alert(Label + ' is a required field.  Please select a value for this item.');
               } 
            break;
        case "SL":
            el = FindMyControl(FieldName);
            if (el == false) { return true }
            // Set background of element to white
            el.style.backgroundColor = '#FFFFFF';
            // Required value test
            if (Required == 'Yes' && el.value.length <= 0) 
                {
                    ElementValid = false;
                    el.style.backgroundColor = '#fbcdcf';
                    alert(Label + ' is a required field.  Please enter a value for this item.');
                }
            // Max length test
            if (ElementValid &&  MaxLength > 0 && el.value.length > MaxLength)
                {
                    ElementValid = false;
                    el.style.backgroundColor = '#fbcdcf';
                    alert('The value you provided for ' + Label + ' is too long.  It should only be ' + String(MaxLength) + ' characters, but you have provided a value with ' + String(el.value.length) + ' characters.');
                }  
            // Numeric test 
            if (ElementValid &&  ( DataType == 'tinyint' || DataType == 'int' || DataType == 'money' || DataType == 'smallint' || DataType == 'int' || DataType == 'real' ) && IsNumeric(el.value) == false)
                {
                    ElementValid = false;
                    el.style.backgroundColor = '#fbcdcf';
                    alert('The value you provided for ' + Label + ' does not appear to be a valid number.');
                }  
                
            break;
            
        case "AC":
            el = FindMyControl(FieldName);
            if (el == false) { return true }
            // ACE controls have 2 elements, get the visible one
            el2 =  FindMyControl('txt' + el.id);
            // Set background of element to white
            el2.style.backgroundColor = '#FFFFFF';
            // Required value test
            if (Required == 'Yes' && el.value.length <= 0) 
                {
                    ElementValid = false;
                    el2.style.backgroundColor = '#fbcdcf';
                    alert(Label + ' is a required field.  Please select a value for this item by typing a few letters to find the item.  Then specifically click on the item to select it.');
                }
           break;
      }
      
      return ElementValid
    
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.,$-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function ShowMessages() {

    // Also display message if set
    var el;
    el = FindMyControl('hdMessage');
    if (el != false ) {
            if (el.value != '' ) {
            Show_Message(el.value);        
            el.valueOf = '';
        }
        
    }

}  

function ShowBillingMessage() {

    var el;
    var t;
    el = FindMyControl('hdMsg');
    if (el != false ) {
            if (el.value != '' ) {
                t = el.value;
                el = document.getElementById('divMsgPopUp');
                el.innerHTML = t;
                PositionLayer('lyrMsg', 350, 200);
                ShowLayer('lyrMsg');
        }
    }


}

function cancelSubmit(e) {

  		if (e && e.preventDefault) 
		    e.preventDefault(); // DOM style (firefox / netscapee) 
		  window.event.returnValue = false; // IE style 
}  


  function forceClick(e, elemId) {
        var elem = document.getElementById(elemId);
        var evt = (e) ? e : window.event;
        var intKey = (evt.which) ? evt.which : evt.keyCode;
        
        if(intKey == 13) {
            elem.click();
            return false;
        }

        return true;
    }

  
function Show_Help_Popup(IconsID, HelpText) {

    var el,left,top,html,el2;
   
    el = document.getElementById(IconsID);
    if (el != null) {
         t = findPos(el);
         left = parseInt(t[0]);
         top = parseInt(t[1]);
    }  
    else {
        left = 100;  
        top = 100; 
    }       
    
    left = left + 3;
    top = top + 20;  
   
    if (navigator.appVersion.indexOf('MSIE 6') > 0) { left = left + 53; top = top + 10 };  
    if (navigator.appVersion.indexOf('MSIE') == -1) { left = left + 53; top = top + 10 };  
    
    // append a cancel layer method
    HelpText = HelpText + '<p align=\"center\"><a href=\"javascript: CancelLayer(\'lyr' + IconsID + '\');\"><b>Done</b></a></p>';
    //  make sure this layer doesn't already exist
    el2 = document.getElementById('lyr' + IconsID);
    if (el2 == null) {
        var layer = document.createElement('DIV');
        layer.style.position = 'absolute';
        layer.style.left = left + 'px';
        layer.style.top = top + 'px';
        layer.style.width = '200px';
        layer.style.zIndex = '91';
        layer.id = 'lyr' + IconsID;
        layer.style.backgroundColor = 'white';
        layer.style.border = 'solid 2px #000099';
        layer.style.padding = '8px';
        layer.innerHTML = HelpText;
        document.body.appendChild(layer);
    }
    else {
        ShowLayer('lyr' + IconsID)
    }
    
    
//    alert(left + '-' + top);

}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function AddFormulaField(FormulaField, Field) {

    var el;
    var T;
    
    T = FormulaField.substring(0, FormulaField.length - 2) + '_FF'
    el = FindMyControl(T);
    el.value = el.value + Field + ' ';
    el.focus();
    

}

function Cancel_Edit_Attempt() {

    return true;

}

function Calc_Formula_Field(FormElementName) {

    var el;
    var RawFormula;
    var TempFormula;
    var spT;
    var Field;
    var Results;
    var T;
    
    T = FormElementName.substring(0, FormElementName.length - 2) + '_FF'
    el = FindMyControl(T);
    if (el == false) {
        alert('The raw formula field containing formula was not retrieved.');
        return;
    }
    RawFormula = el.value;
    TempFormula = RawFormula;
    // replace out all the valid symbols and operators with spaces
    for (x = 0; x < 100; x++) { TempFormula = TempFormula.replace('(', ' ') }
    for (x = 0; x < 100; x++) { TempFormula = TempFormula.replace(')', ' ') }
    for (x = 0; x < 100; x++) { TempFormula = TempFormula.replace('+', ' ') }
    for (x = 0; x < 100; x++) { TempFormula = TempFormula.replace('-', ' ') }
    for (x = 0; x < 100; x++) { TempFormula = TempFormula.replace('*', ' ') }
    for (x = 0; x < 100; x++) { TempFormula = TempFormula.replace('/', ' ') }    
    // split our temp formula into our pieces
    spT = TempFormula.split(' ');
    for (x = 0; x < spT.length; x++) 
    {
        Field = spT[x];
        if (Field != ' ' && Field != '') {
            
            // Get the fields value
            el = FindMyControl(Field);
            Val = el.value;
            Val = Val.replace('$', '');
            Val = Val.replace(',', '');
            if (Val == '' || IsNumeric(Val) == false) {
                alert('The value provided for ' + Field + ' does not appear to be a valid number.');
                return;
            }
            else {
                RawFormula = RawFormula.replace(Field, Val);
            }

            
        }
            
    }
    // calculate the results
    Results = eval(RawFormula);
    el = FindMyControl(FormElementName);
    Results = addCommas(Results);
    el.value = Results;
    

}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function Set_Date_Range(Range_Type, ClientID1, ClientID2) {

    var datePicker1;
    var datePicker2;
    var date1;
    var date2;
    var el;
    var Y;
    
    el = FindMyControl(ClientID1);
    datePicker1 = eval(el.id);
    el = FindMyControl(ClientID2);
    datePicker2 = eval(el.id);
    
    date1 = new Date;
    date2 = new Date;
    
    if (Range_Type == 'L30' ) {
        date1.setDate(date1.getDate() - 30);
        datePicker1.SetDate(date1);
        datePicker2.SetDate(date2);
    }
    
    if (Range_Type == 'L60' ) {
        date1.setDate(date1.getDate() - 60);
        datePicker1.SetDate(date1);
        datePicker2.SetDate(date2);
    }    
    
    if (Range_Type == 'L90' ) {
        date1.setDate(date1.getDate() - 90);
        datePicker1.SetDate(date1);
        datePicker2.SetDate(date2);
    }    
    
    if (Range_Type == 'Q1' ) {
        Y = date1.getYear();
        date1.setFullYear(Y,0,1);
        datePicker1.SetDate(date1);
        date2.setFullYear(Y,2,31);
        datePicker2.SetDate(date2);
    }    
    
    if (Range_Type == 'Q2' ) {
        Y = date1.getYear();
        date1.setFullYear(Y,3,1);
        datePicker1.SetDate(date1);
        date2.setFullYear(Y,5,30);
        datePicker2.SetDate(date2);
    }    
    
    if (Range_Type == 'Q3' ) {
        Y = date1.getYear();
        date1.setFullYear(Y,6,1);
        datePicker1.SetDate(date1);
        date2.setFullYear(Y,8,30);
        datePicker2.SetDate(date2);    
}    
    
    
    if (Range_Type == 'Q4' ) {
        Y = date1.getYear();
        date1.setFullYear(Y,9,1);
        datePicker1.SetDate(date1);
        date2.setFullYear(Y,11,31);
        datePicker2.SetDate(date2);    
    }    
    
    if (Range_Type == 'YTD' ) {
        Y = date1.getYear();
        date1.setFullYear(Y,0,1);
        datePicker1.SetDate(date1);
        datePicker2.SetDate(date2);    
    }        
    
    if (Range_Type == 'PRY' ) {
        Y = date1.getYear();
        Y = Y - 1;
        date1.setFullYear(Y,0,1);
        datePicker1.SetDate(date1);
        date2.setFullYear(Y,11,31);
        datePicker2.SetDate(date2);    

    }       
        
    
}

function validEmail(email) 
{
     var invalidChars = " /:,;"; // NOTE - first char is a SPACE

     for (i = 0;  i < invalidChars.length; i++) { // does it contain any invalid characters?
          var badChar = invalidChars.charAt(i);
          if (email.indexOf(badChar, 0) > -1) return false;
     }

     var atPos = email.indexOf("@", 1);  // there must be one "@" symbol
     if (atPos == -1) return false;
     // and only one "@" symbol
     if (email.indexOf("@", atPos + 1) != -1) return false;

     periodPos = email.indexOf(".", atPos);
     // and at least one "." after the "@"
     if (periodPos == -1) return false;
     // must be at least 2 characters after the "."
     if (periodPos + 3 > email.length)  return false;

     return true;
}

function Validate_Profile_Photo_Upload() {

    var el;
    
    el = FindMyControl('hdAction');
    el.value = "Update Profile Photo"
    
    el.form.submit();

}

function Validate_Add_Prof_Comment() {

    var el;
    
    el = FindMyControl('txtAddComment');
    if ( el.value.length == 0 ) { alert('You must have some comment text to add a comment.  Please type something and then select \"Add Comment\".'); return; }
    if ( el.value.length > 500 ) { alert('Comments are limited to 500 characters.  You have typed ' + el.value.length + ' characters.  Please shorten your comment and then select \"Add Comment\".'); return; }
    
    el = FindMyControl('hdAction');
    el.value = "Add Comment"
    
    el.form.submit();

}

// Profile  SEARCH Scripts ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var PreviousKeyword = '';
var Tmr1;
var BusySearching = false;
var CancelClear = false;
var lnkCnt  = -1;

function DoProfileSearch(PageNo) {

    var el;
    var CurrentKeyword = '';
    var Category = '';
    var Param = '';
    
    clearTimeout(Tmr1);
       
    el = FindMyControl('txtProfileSearch');
    CurrentKeyword = el.value;
    PageNo = parseInt(PageNo);
                
    if ( PreviousKeyword != CurrentKeyword || PageNo > 0 ) {
        Searches.ProfileSearch(Category, CurrentKeyword, PageNo, Param, DrawProfileSearchResults, ErrorHandler, TimeOutHandler);
    }

    PreviousKeyword = CurrentKeyword;
    BusySearching = true;
    lnkCnt  = -1;
    if ( PageNo <= 0 ) { Tmr1 = setTimeout('DoProfileSearch(0)', 300); }

}

function StopSearch() {

    clearTimeout(Tmr1);
    
}

function DrawProfileSearchResults(results) {

    var el;
    var HTML;
    var T;
    var Cnt = 0;
    
    el = document.getElementById('divSearchResults');
    el.style.visibility = 'visible';
    
    // run the rows
    HTML = '<table class="tblSearchResults">';
    HTML += '<tr>';
    for (var i = 0; i < results.length; i++) {
        HTML += '<td>';
        if ( results[i].Photo_Width > 0 ) {
            HTML += '<div class="divPS_Photo"><a href="ViewProfile.aspx?Profile_ID=' + results[i].Profile_ID + '"><img src="GetFile.aspx?Type=ProfilePhoto&Profile_ID=' + results[i].Profile_ID + '" width="' + results[i].Photo_Width + '" height="' + results[i].Photo_Height + '" alt="" /></a></div>';
        }
        else
        {
            HTML += '<div class="divPS_Photo"><a href="ViewProfile.aspx?Profile_ID=' + results[i].Profile_ID + '"><img src="../images/NoPhoto.jpg" width="180" height="150" alt="" /></a></div>';
        }
        HTML += '<div class="divPS_Name"><a href="ViewProfile.aspx?Profile_ID=' + results[i].Profile_ID + '">' + results[i].First_Name + ' ' + results[i].Last_Name + '</a></div>'
        HTML += '</td>';
        Cnt += 1;
        if ( Cnt >= 3 ) { 
            HTML += '</tr><tr>';
            Cnt = 0
        }
        
        
    }
    HTML += '</table>';
        
    el.innerHTML = HTML;

}

function ErrorHandler(result) {
    var msg = result.get_exceptionType() + "\r\n";
    msg += result.get_message() + "\r\n";
    msg += result.get_stackTrace();
    alert(msg);
}

function TimeOutHandler(result) {
    alert("Timeout :" + result);
}

function AddPhoto() {

    PositionLayer('lyrAddPhoto', 400, 150); 
    ShowLayer('lyrAddPhoto');
}

function Validate_Photo_Upload() {

    var el;
    
    el = FindMyControl('chkAck');
    if ( el.checked == false ) { alert('You must check the checkbox next to the photo acknowledgement statement.'); return; }
    
    el = FindMyControl('hdAction');
    el.value = "Add Photo";
    
    el.form.submit();

}

var tmrScroll;
var scrollPOS = 0;

function StopScroll() {

    clearTimeout(tmrScroll);

}

function ScrollThumbsDown() {

    var el;
    var currTop;
    
    el = FindMyControl("divPhotoThumbnails");
    scrollPOS += 10;
    el.scrollTop = scrollPOS;

    tmrScroll = setTimeout('ScrollThumbsDown()', 50);  
}

function ScrollThumbsUp() {

    var el;
    var currTop;
    
    el = FindMyControl("divPhotoThumbnails");
    scrollPOS -= 10;
    el.scrollTop = scrollPOS;

    tmrScroll = setTimeout('ScrollThumbsUp()', 50);     
}

function ShowPhoto(POA_ID) {

    var el;
    var html;
    
    el = document.getElementById('div' + POA_ID);
    html = el.innerHTML;
    el = document.getElementById('divPhotoView');
    el.innerHTML = html;
    
}

function AddComment(POA_ID) {

    var el;
    
    el = FindMyControl('hdParam');
    el.value = POA_ID;

    PositionLayer('lyrAddComment', 400, 150); 
    ShowLayer('lyrAddComment');
}

function Validate_Add_Comment() {

    var el;
    
    el = FindMyControl('txtPhotoComment');
    if ( el.value.length == 0 ) { alert('You must have some comment text to add a comment.  Please type something and then select \"Add New\".'); return; }
    if ( el.value.length > 500 ) { alert('Comments are limited to 500 characters.  You have typed ' + el.value.length + ' characters.  Please shorten your comment and then select \"Add New\".'); return; }
    
    el = FindMyControl('hdAction');
    el.value = "Add Photo Comment"
   
    el.form.submit();

}

function Validate_Add_KB_Comment() {

    var el;
    
    el = FindMyControl('txtAddComment');
    if ( el.value.length == 0 ) { alert('You must have some comment text to add a comment.  Please type something and then select \"Add Comment\".'); return; }
    if ( el.value.length > 500 ) { alert('Comments are limited to 500 characters.  You have typed ' + el.value.length + ' characters.  Please shorten your comment and then select \"Add Comment\".'); return; }
    
    el = FindMyControl('hdAction');
    el.value = "Add Comment"
    
    el.form.submit();

}

function SetDivMainHeight() {

    var el;
    var myHeight;
    
    return; // was causing the page to be chopped off... odd 6/8/2009
    
    el = document.getElementById("divMain");
    if ( el != null ) {
        myHeight = el.offsetHeight;
        alert(document.documentElement.scrollHeight + ' < ' + document.documentElement.clientHeight);
        if ( document.documentElement.scrollHeight < document.documentElement.clientHeight ) { 
            el.style.height = '700px';
        }
    }

}


var _ScrollerID;

function StopTextScroll() {

    clearTimeout(tmrScroll);

}

function ScrollTextDown(ScrollerID) {

    var el;
    var currTop;
    
    if ( ScrollerID != null ) { _ScrollerID = ScrollerID }
    
    el = FindMyControl(_ScrollerID);
    currTop = parseInt(el.style.top);
    if ( String(currTop) == 'NaN' ) { currTop = 0 }
    currTop = currTop - 10;
    el.style.top = currTop + 'px';
    
    tmrScroll = setTimeout('ScrollTextDown()', 50);
    
}

function ScrollTextUp(ScrollerID) {

    var el;
    var currTop;
    
    if ( ScrollerID != null ) { _ScrollerID = ScrollerID }
    
    el = FindMyControl(_ScrollerID);
    currTop = parseInt(el.style.top);
    if ( String(currTop) == 'NaN' ) { currTop = 0 }
    currTop = currTop + 10;
    if ( currTop >= 0 ) { currTop = 0 };
    el.style.top = currTop + 'px';
   
    tmrScroll = setTimeout('ScrollTextUp()', 50);    
}

function ChangeMonth() {

    var el;
    
    el = FindMyControl('selMonth');
    location.href = 'Events.aspx?SelectedDate=' + el.value;

}

function ToggleFilters() {

    var el;
    var t = '';
    var html = '';
    var spT = '';
    var Date1;
    var txtDate1;
    var Date2;
    var txtDate2;
    var U_ID;
    
    el = FindMyControl('hdU_ID');
    U_ID = el.value;    
    // gather the checkbox selections
    for (i = 0; i < 20; i++)  {
        el = document.getElementById('chkFilters_' + i);
        if (el != null ) { 
            if ( el.checked == true ) { t = t + el.value + ', '; }
        }
    }
    // save it in the cookies
    document.cookie = 'SelectedFilters=' + t;
    // run the list
    html = '<table class="tblEventsList">';
    for (i=0; i < myEvents.length; i++)
    {
                spT = myEvents[i];
                spT = spT.split('|')    
                if (spT.length == 9 ) {
                    if ( t.indexOf(spT[4]) > -1 ) {
                        Date1 = new Date(spT[2]);
                        Date2 = new Date(spT[3]);
                        html = html + '<tr id="tr' + spT[5] + '_' + spT[0] + '_dayrow" class="trEventRow">';
                        html = html + '<td class="tdEventsTitle" onmouseover="HighlightDay(\'' + spT[5] + '\');">' + spT[1]
                        // name
                        if ( spT[4]  == 'Individual' ) { html = html + '&nbsp;(' + spT[8] + ')'; }
                        // details link
                        if ( parseInt(spT[6]) > 2 ) {
                            html = html + '&nbsp;<a href="javascript: ShowEventDetails(' + spT[0] + ');" ><span class="smaller" style="color: #000099;">view details &gt;&gt;</span></a>';
                        }
                        // edit link
                        if ( U_ID == spT[7] && spT[4]  == 'Individual'  ) {
                            html = html + '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="Form.aspx?Form_ID=15f661bd-75ca-45ea-bbbe-53539ce9a225&EV_ID=' +  spT[0] + '" ><span class="smaller" style="color: #000099;">edit event &gt;&gt;</span></a>';
                        }
                        
                        html = html + '</td>';
                        txtDate1 = getCalendarShortDate(Date1);
                        html = html + '<td class="tdEventsDates">' + txtDate1 + '</td>';
                        html = html + '<td class="tdEventsCategory">' + spT[4] + '</td>';
                        html = html + '</tr>';
                    }
                }
                
    }    
   html = html + '</table>';
   // set it
    el = document.getElementById('divEvents_List');   
    el.innerHTML = html;
}

var LastD

function HighlightDay(CurrentD) {

    var el;
    
    el = document.getElementById(LastD);
    if ( el != null ) {
        el.className = 'tdCal_D';
    }
    
    CurrentD = 'tdCal_D' + CurrentD;
    LastD = CurrentD
    el = document.getElementById(CurrentD);
    if ( el != null ) {
        el.className = 'tdCal_D_over';
    }
    
    // clear all highlighted rows
    frmElements=document.getElementsByTagName('tr');
    for(i in frmElements)
    {
        MyID = String(frmElements[i].id); 
        t = '_dayrow';
        if (MyID.indexOf(t) > -1 )
            { 
                el = document.getElementById(MyID);
                if ( el != null ) {
                    el.className = 'trEventRow';
                }            
            }
    }    

}

function HighlightEvents(DayNum) {

    var MyID;
    var el;
    
    HighlightDay(DayNum);
    
    // clear all
    frmElements=document.getElementsByTagName('tr');
    for(i in frmElements)
    {
        MyID = String(frmElements[i].id); 
        t = '_dayrow';
        if (MyID.indexOf(t) > -1 )
            { 
                el = document.getElementById(MyID);
                if ( el != null ) {
                    el.className = 'trEventRow';
                }            
            }
    }

    frmElements=document.getElementsByTagName('tr');
    for(i in frmElements)
    {
        MyID = String(frmElements[i].id); 
        t = 'tr' + DayNum + '_';
        if (MyID.indexOf(t) > -1 )
            { 
                el = document.getElementById(MyID);
                if ( el != null ) {
                    el.className = 'trEventRow_Highlight';
                }            
            }
    }


}

function getCalendarShortDate(Date1)
{
   var daynames = new Array(7);
   daynames[0] = "Sun"
   daynames[1] = "Mon"
   daynames[2] = "Tue"
   daynames[3] = "Wed"
   daynames[4] = "Thu"
   daynames[5] = "Fri"
   daynames[6] = "Sat"
   
   var daynumber = Date1.getDay();
   var dayname = daynames[daynumber];
   var monthday    = Date1.getDate();
   var year        = Date1.getYear();
   var dateString = dayname + ', <b>' + monthday + '</b>';
   return dateString;
} 

function getCalendarDate(Date1)
{
   var months = new Array(12);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   
   var daynames = new Array(7);
   daynames[0] = "Sun"
   daynames[1] = "Mon"
   daynames[2] = "Tue"
   daynames[3] = "Wed"
   daynames[4] = "Thu"
   daynames[5] = "Fri"
   daynames[6] = "Sat"
   
   var monthnumber = Date1.getMonth();
   var monthname   = months[monthnumber];
   var daynumber = Date1.getDay();
   var dayname = daynames[daynumber];
   var monthday    = Date1.getDate();
   var year        = Date1.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = dayname + ', ' + monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
} 

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
}

function ShowEventDetails(EV_ID) {

    var el;
    el = document.getElementById('divEventDetails_' + EV_ID);
    
    PositionLayer(el.id, 305, 225);
    ShowLayer(el.id);

}

function ValidateNeedALogin() {

    var el;
    
    el = FindMyControl('txtFirst_Name');
    if ( el.value.length < 2 ) { alert('You must provide a valid first name in order to continue.'); return; }
    
    el = FindMyControl('txtLast_Name');
    if ( el.value.length < 2 ) { alert('You must provide a valid last name in order to continue.'); return; }
    
    el = FindMyControl('txtEmail');
    if ( el.value.length < 2 ) { alert('You must provide a email address in order to continue.\n\nEnter \"None\" if you do not have a valid email address.'); return; }    
    
    document.forms[0].submit();

}

// BEGIN Main Window Chat Scripts ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var tmrChat;
var chatU_ID;
var ChatWith_U_ID;
var Session_ID;

function StartChatHeartBeat(U_ID) {
    chatU_ID = U_ID;
    ChatHeartBeat();    
}

function ChatHeartBeat() {

    clearTimeout(tmrChat);
       
    Searches.ChatHeartBeat(chatU_ID, ChatHeartBeatResults, ErrorHandler, TimeOutHandler);
    
    tmrChat = setTimeout('ChatHeartBeat()', 5000);

}

function ChatHeartBeatResults(results) {

    var spT;
    var el;
    var t;
    var top,left;
    
    if ( results.length >= 36 ) {
        spT = results.split('|');
        // Pop up request window
        // Session_ID|ChatWith_U_ID|Name|Photo_Width|Photo_Height 
        Session_ID= spT[0];
        ChatWith_U_ID = spT[1];
        el = document.getElementById('spCWM_Name');
        el.innerHTML = spT[2];
        el = document.getElementById('divCWM_Photo');
        if ( spT[3] != '0' ) {
            el.innerHTML = '<img src="GetFile.aspx?Type=ProfilePhoto&Profile_ID=' + ChatWith_U_ID + '" width="' + spT[3] + '" height="' + spT[4] + '" alt="" />';
        }
        else
        {
            el.innerHTML = '<img src="../images/NoPhoto.jpg" width="180" height="150" alt="" />';
        }        
        // show the request layer
        // Find chat button's position
        el = document.getElementById('imgChatBtn');
        if (el != null) {
             t = findPos(el);
             left = parseInt(t[0]);
             top = parseInt(t[1]);
        }  
        else {
            left = 100;  
            top = 100; 
        }       
        left = left - 425;
        left = String(left) + 'px';
        top = top + 18;
        top = String(top) + 'px';
        // Position who's online box'ie    
        el = document.getElementById('divChatWithMe');
        el.style.left = left;
	    el.style.top = top;   
	    
	    window.focus();
	         
    }
  
}

function AcceptChatRequest () {

    CancelLayer('divChatWithMe');
    ChatWith(ChatWith_U_ID, Session_ID);

}

function HideChatRequest() {

    var el;
    
   el = document.getElementById('divChatWithMe');
   el.style.left = '-1200px';
   
}

function WhosOnline() {

    var el,left,top,html;
    
    // clear current selection
    html = '<center><img src="../images/Core/WaitingRedSnake.gif" width="16" height="16" alt="" /></center>';
    el = document.getElementById('divWO_List');
    el.innerHTML = html;   
   
    // Find chat button's position
    el = document.getElementById('imgChatBtn');
    if (el != null) {
         t = findPos(el);
         left = parseInt(t[0]);
         top = parseInt(t[1]);
    }  
    else {
        left = 100;  
        top = 100; 
    }       
    left = left - 125;
    left = String(left) + 'px';
    top = top + 18;
    top = String(top) + 'px';
    // Position who's online box'ie    
    el = document.getElementById('divWhosOnline');
    el.style.left = left;
	el.style.top = top;
	// call AJAX routine to get Who's online
	Searches.GetWhosOnlineList(chatU_ID, DrawWhosOnlineList, ErrorHandler, TimeOutHandler);
    
}

function DrawWhosOnlineList(results) {

    var el;
    var HTML;
    var T;
    var Cnt = 0;
    
    el = document.getElementById('divWO_List');
        
    // run the rows
    HTML = '<table class="tblWO_List">';
    for (var i = 0; i < results.length; i++) {
        HTML += '<tr>';
        HTML += '<td style="width: 50px;">';
        if ( results[i].Photo_Width > 0 ) {
            HTML += '<div class="divWO_Photo"><a href="javascript: ChatWith(\'' + results[i].Profile_ID + '\', \'\');"><img src="GetFile.aspx?Type=ProfileThumbnail&Profile_ID=' + results[i].Profile_ID + '" width="' + results[i].Photo_Width + '" height="' + results[i].Photo_Height + '" alt="" /></a></div>';
        }
        else
        {
            HTML += '<div class="divWO_Photo"><a href="javascript: ChatWith(\'' + results[i].Profile_ID + '\', \'\');"><img src="../images/NoPhoto_small.gif" width="50" height="42" alt="" /></a></div>';
        }
        HTML += '</td>';
        HTML += '<td style="width: 108px;">';
        HTML += '<div class="divPS_Name"><a href="javascript: ChatWith(\'' + results[i].Profile_ID + '\', \'\');">' + results[i].First_Name + ' ' + results[i].Last_Name + '</a></div>'
        HTML += '</td>';
         HTML += '</tr>';
                
    }
    HTML += '</table>';
    
    if ( results.length <= 0 ) { HTML += '<p>No one else is online at this time.... sorry... maybe later someone else will come online.</p><p>&nbsp;</p><p>Nothing else to see for now.</p><p>&nbsp;</p><p>I\'d just click Close at the bottom and carry on with life for now.</p>' }
        
    el.innerHTML = HTML;

}

function CancelWhosOnline() {

    el = document.getElementById('divWhosOnline');
    el.style.left = '-1200px';
    
}

function ChatWith(Profile_ID, Session_ID) {

    var Link;
    var ChatWindow;
    var myDate = new Date();

    CancelWhosOnline()

    Link = 'ChatWindow.aspx?ChatWith=' + Profile_ID;
    if ( Session_ID != '' ) { Link = Link + '&Session_ID=' + Session_ID; }
	// append a DateTime stamp to prevent caching
    DT = 'DATESTAMP' + myDate.getMonth();
    DT = DT + myDate.getDate();
    DT = DT + myDate.getYear();
    DT = DT + myDate.getHours();
    DT = DT + myDate.getMinutes();
    DT = DT + myDate.getSeconds();
    Link = Link + '&DT=' + DT;
    // pop-up chat window
    ChatWindow = window.open(Link, Profile_ID, 'scrollbars=auto,width=450,height=450,toolbar=no,location=no,directories=no,location=no;status=no,resizable=yes');
    ChatWindow.focus()

}
// END Main Window Chat Scripts ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

