﻿//this prevents the window from scrolling to the top on validation
window.scrollTo = function() { }

var Popup; //the control that is popped up

function targetTheme(e,currentId) {
    //var Img = $(currentId);
    var modalPopupBehavior = $find('ctl00_ContentPlaceHolder1_Theme_modal1');
     modalPopupBehavior.show();
     setCookie('themeStyle', e);
    // Img.attr("src", "src=images/buttons/" + e + "_active.jpg");
    $("#ctl00_styleMe").attr("href", "css/" + e + ".css");
    // document.getElementById("ctl00_styleMe").href = "css/" + e + ".css";
}

function ShowPopup(DivName, Anchor, XOffset, YOffset){
    //check if this div is already showing. If so, we'll hide it
    var alreadyVisible = false;
    if(document.getElementById(DivName).style.display==''){
        alreadyVisible = true; 
    }
    
    //first hide any existing popups
    HidePopup('');
    
    if(!alreadyVisible){
        //get the item we're popping up
        Popup = document.getElementById(DivName);
                
        //find the anchor point
        var Apoint = document.getElementById(Anchor);
            
        //get it's position 
        var x = Apoint.offsetLeft;
        var y = Apoint.offsetTop;
        
        //alert(x);
       // alert(y);
        
        var parent = Apoint;
	    while ((parent=parent.offsetParent) != null) {
	        x += parent.offsetLeft;  
	        y += parent.offsetTop;
	   // alert(x);alert(y);
	    }
    	  
    	//calculate the popup's position
        x += XOffset;
        y += YOffset;
        
        //alert(x);alert(y);

     var elemPos = findPosition(Apoint);
     var elemPos2 = findPosition(Popup);
    //alert('Left: ' + elemPos.x + '\nTop: ' + elemPos.y);
    //alert(Popup.id+ ' Left: ' + elemPos2.x + '\nTop: ' + elemPos2.y);
            
        //Popup.style.left = elemPos.x + "px";
        //Popup.style.top = elemPos.y + "px";
       
       //alert(elemPos.x);
       
              
        Popup.style.left = x+ "px";
        Popup.style.top = y + "px";
               
        //show it
        Popup.style.display='';
    }
}

function HidePopup(SkipDiv){
    //SkipDiv indicates which popup NOT to hide    
    if(Popup != null){
        if(Popup.id != SkipDiv){
            //if it exists, hide it
            Popup.style.display='none';
        }
    }
}

 function elementPosition(obj) {
        var curleft = 0, curtop = 0;

        if (obj.offsetParent) {
            curleft = obj.offsetLeft;
            curtop = obj.offsetTop;

            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            }
        }
       // alert(curleft);
       // alert(curtop);
        return { x: curleft, y: curtop };
      }

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return { x: posX, y: posY };
   // return [ posX, posY ];
  } else {
  alert('left:'+posX + '  top:'+posY);
    //return [ oElement.x, oElement.y ];
    return { x: posX, y: posY };
  }
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


function setCookie(name, value, expires, path, domain, secure) {
    //if no expiry was passed, set it to a year from now
	if(expires == null){
		expires = new Date();
		expires.setHours(expires.getHours() + (365 * 24));
	}
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function ascClick() {
        $('#actionLinks').animate({ height: 'toggle', opacity: 'toggle' }, 400, "linear");
        return false;
}

function minstriesClick() {
    $('#ministriesLinks').animate({ height: 'toggle', opacity: 'toggle' }, 400, "linear");
    return false;
}

function groupadvClick() {
    $('#groupadvLinks').animate({ height: 'toggle', opacity: 'toggle' }, 400, "linear");
    return false;
}


function slideSwitch(id) {
 try
    {
    var $active = $('#' + id +' DIV.active');

    if ($active.length == 0) $active = $('#' + id +' DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next()
        : $('#' + id +' DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
    }
    catch (Err) { }
}

function reDirectThis(e) {
    window.location = e;
}

