//********* Pop up functions **************
var popUp;
function pop(url, xSize, ySize){
  if(popUp && !popUp.closed){
    popUp.location.replace(url);
  }else{
    Left = (screen.width - xSize ) /2;
    Top = (screen.height - ySize) /2;
    var opts = "width=" + xSize + ",height="+ ySize +",left="+ Left +",top="+ Top +",location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0";
    popUp = open(url,"popup",opts);
  }
  popUp.focus();
}
//******** Primary Pop up functions-use if need to pop up a window with other popups on it **************
var popUpw;
function popw(url, xSize, ySize){
  if(popUpw && !popUpw.closed){
    popUpw.location.replace(url);
  }else{
    Left = (screen.width - xSize ) /2;
    Top = (screen.height - ySize) /2;
    var opts = "width=" + xSize + ",height="+ ySize +",left="+ Left +",top="+ Top +",location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0";
    popUpw = open(url,"popupw",opts);
  }
  popUpw.focus();
}
//******Nothing Formula******************
function nothing(){
      var i = 0;
}
//*************Popup Help*********************
function popUpHelp(objectName){
 pop("/popups/popuphelp.jsp?name="+objectName,"300","300");
}
function refreshPage(url){
  document.forms[0].action= url;
  document.forms[0].submit();
}
//**********string trims****************
function ltrim(argvalue) {
  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }
  return argvalue;
}
function rtrim(argvalue) {
  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }
  return argvalue;
}
function trim(argvalue) {
  var tmpstr = ltrim(argvalue);
  return rtrim(tmpstr);
}
//*************form was changed************
function formChanged(){
 document.forms[0].formchanged.value="1";
}
function formChangedArea(area){
 eval("document.forms[0].formChanged"+ area + ".value='1'");
}
//************* Tab Functions *****************
function expandIt(whichEl) {
  //  whichIm = event.srcElement;
    if (whichEl.style.display == "none") {
        whichEl.style.display = "";
     //   whichIm.src = "triUp.gif";
    }
    else {
        whichEl.style.display = "none";
    //    whichIm.src = "triDown.gif";
    }
}
function expandItImSwap(whichEl) {
   whichIm = event.srcElement;
    if (whichEl.style.display == "none") {
        whichEl.style.display = "";
       whichIm.src = "/imgs/buttons/minus.gif";
    }
    else {
        whichEl.style.display = "none";
       whichIm.src = "/imgs/buttons/plus.gif";
    }
}
function RndNumber(){  //used mostly for tacking on the end of urls to defeat caching.
 var d = new Date();
 return (d.getSeconds() * d.getMinutes() * d.getDay());
}

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; ia.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) { //v4.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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); 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];}
}
//********************* End Rollover Functions ****************************
//********************* Form validation Section *************************
function isNumber(x){
 var anum=/(^\d+$)|(^\d+\.\d+$)/
 return(anum.test(x));
}
function isZipcode(fldvalue) {
 var valid = "0123456789-";
 var hyphencount = 0;
 if (fldvalue.length!=5 && fldvalue.length!=10) {
  return false;
 }
 for (var i=0; i <=  fldvalue.length; i++) {
  temp = "" + fldvalue.substring(i, i+1);
  if (temp == "-"){
   hyphencount++;
  }
  if (valid.indexOf(temp) == "-1") {  //invalid charactors
   return false;
  }
  if ((hyphencount > 1) || ((fldvalue.length==10) && ""+fldvalue.charAt(5)!="-")) {
   return false;
  }
 }
 return true;
}
//********************* Form Validation Section End ***********************
<!--Base Navigation Functions-->

var homePage="http://www.episcopalchurch.org";
var helpPage="http://www.episcopalchurch.org/info";
var helpPagePop="";
var searchPage="http://www.episcopalchurch.org/info";
var searchPagePop="";
var questionPage="http://comm.episcopalchurch.org/ME2/Sites/load.asp?SiteID=F0D0D0B1BAEC4A069F8D9E383CAFD5D5";
var questionPagePop = "";
//var feedbackPage="http://comm.episcopalchurch.org/ME2/Sites/load.asp?SiteID=F0D0D0B1BAEC4A069F8D9E383CAFD5D5";
var feedbackPage = "http://www.episcopalchurch.org/forms/question_form.htm";
var feedbackPagePop="";
var contactPage="http://www.episcopalchurch.org/info/form.html";
var contactPagePop="";
var loginPage="#";
var loginPagePop="";
var registerPage="#";
var registerPagePop="";
var languagePage="#";
var languagePagePop="";

function goHome() {
 window.location=homePage;
}
function goHelp() {
 if (helpPagePop==""){
  pop(helpPage,'400','400');
 }else{
  window.location.replace(helpPage);
}
}
function goSearch() {
        window.location=searchPage;
}

function goFeedback() {
 if (feedbackPagePop==""){
  pop(feedbackPage,'640','480');
 }else{
  window.location.replace(feedbackPage);
}
}

function goQuestion() {
  if (questionPagePop==""){
    pop(questionPage,'640','480')
  }else{
    window.location.replace(questionPage);
}
}

function goContact() {
 if (contactPagePop==""){
  pop(contactPage,'400','400');
 }else{
  window.location.replace(contactPage);
}
}

function goLogin() {
 if (loginPagePop==""){
  pop(loginPagePop,'400','400');
 }else{
  window.location.replace(loginPagePop);
}
}
function goRegister() {
 if (registerPagePop==""){
  pop(registerPagePop,'400','400');
 }else{
  window.location.replace(registerPagePop);
}
}
function goLanguage(){
alert("We are currently working on adding language choices to the website. Right now, Spanish language content can be found in Episcopal News Service pages as well as the Hispanic Ministry pages.");

}
function goNewLanguage() {
 if (languagePagePop==""){
  pop(languagePagePop,'400','400');
 }else{
  window.location.replace(languagePagePop);
}
}

function JumpMenu(selObj,restore){
 var theFullString = selObj.options[selObj.selectedIndex].value;
 if (restore) selObj.selectedIndex=0;
 var theLength = theFullString.length;
 var endPos = theFullString.indexOf("~");
 var endPos2 = theFullString.lastIndexOf("~");
 var theUrl, theTarget, theParent;
if (endPos==0){ theUrl = theFullString.substring(1,endPos2);}
else if (endPos > 0) {theUrl = theFullString.substring(0,endPos);}
 else {theUrl = theFullString;}
 endPos2++
 if (endPos2 < theLength) {theTarget = theFullString.substring(endPos2,theLength)}
 else {theTarget = "window:Main";}
 if (theTarget == "window:New") {window.open(theUrl);}
 else if (theTarget == "window:Main") {eval("parent.location='"+theUrl+"'");}
}
function JumpMenuGo(selName,restore){
  var selObj = MM_findObj(selName); if (selObj) JumpMenu(selObj,restore);
}


var winwidth

function getClientWidth(){
  if (document.layers) { // netscape 4
    winwidth = window.innerWidth;}
else { // DOM3 = IE5, NS6, IE 4
    winwidth = document.body.clientWidth;
}
}

function reDo(lyrID,leftMargin){
getClientWidth();
 if (document.layers) {
  document.layers[lyrID].style.left=eval('winwidth- leftMargin +"px"');
 }
 else {
  document.getElementById(lyrID).style.left=eval('winwidth- leftMargin +"px"');
 }
 document.getElementById(lyrID) == blur;
}

//---  MOUSE POSITION ---
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
function captureMousePosition(e) {
	if (document.layers) {
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;
	}
	else if (document.all) {
		xMousePos = window.event.x+document.body.scrollLeft;
		yMousePos = window.event.y+document.body.scrollTop;
		xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
		yMousePosMax = document.body.clientHeight+document.body.scrollTop;
	}
	else if (document.getElementById) {
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;
	}
}
window.onresize=captureMousePosition;

function hideTip(divID) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divID).style.visibility = 'hidden';
	} 
	else {
		if (document.layers) { // netscape 4
			document.layers[divID].visibility = 'hidden';
		}
		else { // IE 4
			document.all[divID].style.visibility = 'hidden';
		}
	}
}

if (document.layers) { // Netscape
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = captureMousePosition;
}
else if (document.all) { // Internet Explorer
	document.onmousemove = captureMousePosition;
}
else if (document.getElementById) { // Netcsape 6
	document.onmousemove = captureMousePosition;
}

function goTip(x,y,divTip,tipWide) {
var el = (document.getElementById)? document.getElementById(divTip).style : (document.layers)? document.layers[divTip] : null;
var supersize = x + tipWide;
xMousePosMax = window.innerWidth+window.pageXOffset || document.body.clientWidth+document.body.scrollLeft || window.innerWidth+window.pageXOffset;
//alert(xMousePosMax);
if (document.layers) {
	el.left=x;
	el.top=y;
}
else {
	el.left=x+5+'px';
	el.top=eval('y+5 +"px"');
}

if (eval('supersize >= xMousePosMax')) {
	if (document.layers) {
		el.left=x-tipWide;
	}
	else {
		el.left=eval('x-tipWide +"px"');
	}
}
el.visibility = 'visible'
}

var popWin;
function newWindowOpen(strURL,wWidth,wHeight)
{
 if(popWin && !popWin.closed){
     popWin.location.replace(strURL);
 }
 else {
	var strProperties = 'width=' + wWidth + ',height=' + wHeight + ',status=0,toolbar=0,location=0,scrollbars=1,resizable=1';
	popWin = window.open(strURL,'',strProperties);
 }
 popWin.focus();
}

