function togglecont(cid){
   document.getElementById(cid).style.display=(document.getElementById(cid).style.display != "block")? "block" : "none";
}
function dispcont(cid){ document.getElementById(cid).style.display="block"; }
function hidecont(cid){ document.getElementById(cid).style.display="none"; }
function swapcont(cid, oid){
  document.getElementById(cid).style.display="block";
  document.getElementById(oid).style.display="none"; 
}
// These two old functions work fine except in Safari, Grrrr
//function getYOld( oElement ) {
//  var iReturnValue = 0;
//  while( oElement != null ) {
//    iReturnValue += oElement.offsetTop;
//    oElement = oElement.offsetParent;
//  }
//  return iReturnValue;
//}
//function getXOld( oElement ) {
//  var iReturnValue = 0;
//  while( oElement != null ) {
//    iReturnValue += oElement.offsetLeft;
//    oElement = oElement.offsetParent;
//  }
//  return iReturnValue;
//}

function getX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
function getY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

String.prototype.pluralize = function(count, plural) {
  if (plural == null) plural = this + 's';
  return (count == 1 ? this : plural)
}

function maskKeyPress(objEvent) {
  var iKeyCode=objEvent.keyCode? objEvent.keyCode : objEvent.charCode
  if(iKeyCode>=48 && iKeyCode<=57) return true;
  if(iKeyCode == 8 || iKeyCode == 9) return true;
  return false;
}

function getStyle(el,styleProp) {
	if (el.currentStyle)
		var y = el.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	return y;
}

function getPos(forElement) {
	var valueT = 0, valueL = 0;
	var element = forElement;
	do {
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		// Safari fix
		if (element.offsetParent==document.body) {
			if (getStyle(element,'position')=='absolute') {
				break;
			}
		}
	} while (element = element.offsetParent);
	return [valueL, valueT];
}

function ShowTooltip(cid, RowID, ParentID, Name, FName, Maiden, IsFound, RSVP, IsDeceased, LoggedIn, ID) {
  var TT = document.getElementById(cid);
  var RowElem = document.getElementById(RowID);
  var Details;
  var ClickLink = '';
  if(Maiden != ''){Name = Name + "<br>(" + Maiden + ")"};
  if(IsDeceased == 1){
    Details = 'We are sad to report this person has passed away.';
  } else {
    if(IsFound == 0){
      Details = FName + ' has not been found. Click on the <b>Tip</b> icon if you have any past or present info!';
      ClickLink = '<a href="TipAdd.cfm?ID=' + ID + '">Click here to add a tip</a>';
    } else {
      ClickLink = '<a href="Details.cfm?ID=' + ID + '">Click for details</a>';
      if(LoggedIn == 0) {
        Details = FName + ' has been found but has not registered yet.';
      } else if(RSVP == 1) {
        Details = FName + ' has been found and is planning to attend the 25<sup>th</sup> Reunion.';
      } else {
        Details = FName + ' has been found.';
      };
    };
  };
  document.getElementById('ttnamebox').innerHTML = Name;
  document.getElementById('ttdetailsbox').innerHTML = Details;
  document.getElementById('ttClickBox').innerHTML = ClickLink;

  var a = getPos(RowElem);
  var x = a[0] + document.getElementById(ParentID).offsetWidth;
  var y = a[1] + (RowElem.offsetHeight / 2);

//  x = getX(RowElem) + document.getElementById(ParentID).offsetWidth;
//  y = getY(RowElem) + (RowElem.offsetHeight / 2);
  TT.style.left = x;
  TT.style.display="block";
  TT.style.top = y - (TT.offsetHeight / 2);
 }
 
function CancelEdit(headto) { 
  ConfirmStatus = confirm("Cancel changes?");
  if (ConfirmStatus == true) {
    self.document.location=headto;
  };
}

function CancelBack() { 
  ConfirmStatus = confirm("Cancel changes?");
  if (ConfirmStatus == true) {
    history.go(-1);
  };
}

function setfocus(eid) {
  document.getElementById(eid).focus();
}

function ValidTip(thisform) {
with (thisform) {
  if (TipText.value.length == 0) {
    alert("Please enter your tip information"); return;};
  ConfirmStatus = confirm("Save this tip?");
  if (ConfirmStatus == true) {
    document.AddTip.submit();}
}
}

function ValidContact(thisform) {
with (thisform) {
  if (MessText.value.length == 0) {
    alert("Please enter a note to the person you wish to contact"); return;};
  ConfirmStatus = confirm("Send this message?");
  if (ConfirmStatus == true) {
    document.ContactUser.submit();}
}
}

function ValidDetails(thisform) {
with (thisform) {
  if (FirstName.value.length == 0) {
    alert("Please enter your First Name"); return;}
  else if (LastName.value.length == 0) {
    alert("Please enter your Last Name"); return;
  };
  ConfirmStatus = confirm("Save your details?");
  if (ConfirmStatus == true) {
    document.EditForm.submit();}
}
}

function setActiveStyleSheet(SHEET_TITLE) {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == SHEET_TITLE) a.disabled = false;
    }
  }
}

function ValidPassForm(thisform) {
var NoSpace = /\s/;
 with (thisform) {
  if (OldPass.value.length < 1) {
    alert("Please enter your old password");
    return false;}
  else if (NewPass1.value.length < 6) {
    alert("Your new password must be at least 6 characters long"); 
    return false;}
  else if (NoSpace.test(NewPass1.value)) {
    alert("Passwords may not contain spaces"); 
    return false;}
  else if (NewPass1.value != NewPass2.value) {
    alert("New passwords do not match"); 
    return false;}
  return true;
 }
}

function ValidRegForm(thisform) {
var NoSpace = /\s/;
 with (thisform) {
  if (UserName.value.length < 1) {
    alert("Please enter a desired user name");
    UserName.focus();
    return false;}
  else if (UserName.value.length < 5) {
    alert("Your user name must be at least 5 characters long");
    UserName.focus();
    return false;}
  else if (NoSpace.test(UserName.value)) {
    alert("User names may not contain spaces"); 
    UserName.focus();
    return false;}
  else if (NewPass1.value.length < 6) {
    alert("Your password must be at least 6 characters long"); 
    NewPass1.focus();
    return false;}
  else if (NoSpace.test(NewPass1.value)) {
    alert("Passwords may not contain spaces"); 
    NewPass1.focus();
    return false;}
  else if (NewPass1.value != NewPass2.value) {
    alert("Passwords do not match"); 
    NewPass1.focus();
    return false;}
  return true;
 }
}

function ValidSearch(thisform) {
 with (thisform) {
  if (search.value.length < 3) {
    alert("You must search on at least three characters"); 
    return false;}
  rExp = /%/gi;
  self.document.location = "Semester.cfm?Search=" + escape(search.value.replace(rExp,''));
  return false;
 }
}

function LogOut(){ 
  ConfirmStatus = confirm("Are you sure you want to log out?");
  if (ConfirmStatus == true) {
    self.document.location="logout.cfm";    
  };
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed per frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i=i-2) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer = timer + 2;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i=i+2)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer = timer + 2;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function expnews(cid){
  var element = document.getElementById(cid);
  var ctrl = document.getElementById(cid + "ctrl");
  var moreimg = document.getElementById(cid + "more");
  if (element.style.display == "block") {
    element.style.display="none";
    ctrl.src = "site/plus.png";
    moreimg.src = "site/more.gif";
  } else {

    //changeOpac(1, "resetbutt");
    //rbutt.style.display="block";
    //opacity("resetbutt",1,100,500);


    element.style.display="none";
    changeOpac(1, cid);
    element.style.display="block";
    ctrl.src = "site/minus.png";
    moreimg.src = "site/dotclr.gif";
    opacity(cid, 1, 100, 500);
  }
}

function coatswap(coatcol) {
  coatcol = coatcol.substr(0,1);
  var coattop = document.getElementById("coattop")
  var coatmain = document.getElementById("coatmain")
  if (coatcol == "B") {
    coattop.src = "images/bluetop_05.jpg";
    coatmain.src = "images/bluetop_12.jpg";
  } else if (coatcol == "W") {
    coattop.src = "images/whitetop_05.jpg";
    coatmain.src = "images/whitetop_12.jpg";
  } else if (coatcol == "G") {
    coattop.src = "images/greentop_05.jpg";
    coatmain.src = "images/greentop_12.jpg";
  } else {
    coattop.src = "images/oscframe2_05.jpg";
    coatmain.src = "images/oscframe2_12.jpg";
  }
}

function recalcLC() {
  var tmpval;
  var qtyobj = document.getElementById("FQuantity");
  var totobj = document.getElementById("FTotal");
  decpl = 2;
  if (qtyobj.value.length > 0) {
    tmpval = qtyobj.value * 25;
    if (isNaN(tmpval)) {
      totobj.value="";
    } else {
      totobj.value = "$" + Math.round(tmpval * Math.pow(10,decpl)) / Math.pow(10,decpl) + " Can";
    }  
  } else {
    totobj.value="";     
  }
}

function delLCorder(Num, Size, Colour) {
  var sOrder = Num + " " + Size + " " + Colour + " Labcoat";
  return confirm(sOrder.pluralize(Num) + "\n\nAre you sure you want to remove this order?");
}

function addLCorder(thisform) {
  with (thisform) {
    if (OQty.value.length == 0) {
      alert("Please enter a quantity"); 
      OQty.focus();
      return false;
    }
    return true;
  }
}