function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

function getObj(name)
{
	if (document.getElementById)
	{
		return document.getElementById(name);
	}
	else if (document.all)
	{
		return document.all[name];
	}
	else if (document.layers)
	{
		if (document.layers[name])
		{
	   		return document.layers[name];
		}
		else
		{
			return document.layers.testP.layers[name];
		}
	}
}

function playAnimation(imgName)
{
	var now = new Date();
	var img = findObj(imgName);
	img.src = String("../images/bullet_anim.gif?" + now.getTime());
}
function stopAnimation(imgName){
	var now = new Date();
	var img = findObj(imgName);
	img.src = String("../images/bullet_static.gif?" + now.getTime());	
}

function pictureFileName(iNumber,sExt){
	imgSrc = 'pic_';
    imgKey = String(iNumber);
    
    for(var y = 4; y > imgKey.length; y--) imgSrc += '0';
    imgSrc += imgKey + '.' + sExt;
    return imgSrc;
}

function RollOver(imgName) 
{
  document.images[imgName].src = "images/" + imgName + "_over.gif";
}

function RollOut(imgName)
{
  document.images[imgName].src = "images/" + imgName + ".gif";
}

function openSlideViewer(slides){
  var iWindowW = 342;
  var iWindowH = 500;
  var url = "slideviewer.php?i=0&s=" + slides;
  
  var win = window.open(url, "slideViewer","location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,width=" + iWindowW + ",height=" + iWindowH );
}
function rollImg(oImg){
	//For manipulation only
	var sCurrentImgName = oImg.src.substring(oImg.src.lastIndexOf('/') + 1,oImg.src.length);
	var sCurrentStatus = sCurrentImgName.substr(sCurrentImgName.lastIndexOf('_'),5);
	
	//Will used for the final string building
	var sPath = oImg.src.substring(0,oImg.src.lastIndexOf('/') + 1);
	var sShortImgName = sCurrentImgName.substr(0,sCurrentImgName.lastIndexOf('_'));
	var sImgExt = sCurrentImgName.substring(sCurrentImgName.lastIndexOf('.'),sCurrentImgName.length);
	
	//New Status
	var sNewStatus = ((sCurrentStatus == '_norm') ? '_roll' : '_norm');
	
	var sNewImgName = sPath + sShortImgName + sNewStatus + sImgExt;
	
	oImg.src = sNewImgName;

}
function openPicture(sFileName,iW,iH){
	var width = iW;
	var height = iH;
	var winl = (screen.width-width)/2;
	var wint = (screen.height-height)/2 - 50;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	var sUrl = "pictureViewer.php?f=" + sFileName + "&w=" + iW + "&h=" + iH;

	window.open(sUrl,"PictureViewer" + iW,'top='+wint+',left='+winl+',width='+width+',height='+height+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0').focus();
}

function openWindowsAndCenter(URL,W,H){
	var width = W;
	var height = H;
	var winl = (screen.width-width)/2;
	var wint = (screen.height-height)/2 - 50;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	
	window.open(URL,"Popup",'top='+wint+',left='+winl+',width='+width+',height='+height+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1').focus();
}
function b2(a1,a2,b1){
	return (a2 * b1) / a1;
}

