function getObj(name) {
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
 }
}

function findPosX(obj) {
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		curtop = eval(obj).offsetLeft;
	  tempEl = eval(obj).offsetParent;
	  while (tempEl != null) {
  		curtop += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
    }
	  return curtop;
	}
	else if (document.layers)
		curleft = obj.x;
	return curleft;
}

function findPosY(obj) 
{
var curtop = 0;
var printstring = '';
	if (document.getElementById || document.all)
	{
	  	curtop = eval(obj).offsetTop;
	  	tempEl = eval(obj).offsetParent;
	  	while (tempEl != null) {
    		curtop += tempEl.offsetTop;
    		tempEl = tempEl.offsetParent;
      	}
	  	return curtop;
	}
	else if (document.layers)
		curtop = obj.y;
	return curtop;
	
}




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; i<a.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&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

var whitespace = " \t\n\r";
function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function




function isEmail (s)
{   
		if (s.indexOf(" ")!=-1) return false;

		if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


var dtCh= "/";
var minYear=1980;
var maxYear=2050;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
  var arrdays = new Array()
	for (var i = 1; i <= n; i++) {
		arrdays[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {arrdays[i] = 30}
		if (i==2) {arrdays[i] = 29}
   }
   return arrdays
}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false //"validDate"
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false //"validDate"
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false //"validDate"
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
  if (!inthePast(dtStr)){
    return false //"inPast"
  }
return true
}

function inthePast(dtStr) {
  var now = new Date();
  var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
  var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
  var date = new Date(strYear, strMonth-1, strDay)

  //var date = new Date(dateString.substring(6,10),
  //                    dateString.substring(0,2)-1,
  //                    dateString.substring(3,5));
  
  if (today >= date)
    return true;
  else
    return false;
}






function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) 
	{ 
		test=args[i+2]; val=MM_findObj(args[i]);strFriendlyName = args[i+1];
		if (val) 
		{ 
			nm=val.name; if ((val=val.value)!="") 
		{
		
		if (test.indexOf('isDate')!=-1) 
		{
      if (!isDate(val)) errors+='- '+strFriendlyName+' must contain a valid date that is in the past.\n';
		}
		else if (test.indexOf('isEmail')!=-1)
		{
      if (isEmail(val)==false) errors+='- '+strFriendlyName+' must contain an e-mail address.\n';
			
    }
		else if (test!='R') 
		{
      if (isNaN(val)) errors+='- '+strFriendlyName+' must contain a number.\n';
      if (test.indexOf('inRange') != -1) 
			{ 
				p=test.indexOf(':');
      	min=test.substring(8,p); max=test.substring(p+1);
      	if (val-0<min || max<val-0) errors+='- '+strFriendlyName+' must contain a number between '+min+' and '+max+'.\n';
    	}
		}
		}
		else if (test.charAt(0) == 'R') 
		{
			errors += '- '+strFriendlyName+' is required.\n'; 
		}
		}
  } 
	if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


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; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_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];}
}


rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
}

function rand(number) {
        return Math.ceil(rnd()*number);
}

function PopUp(url,h,w,sb,rs,st,tb,mb,ti) 
{
  lft = (screen.availWidth -w)/2;
  t = (screen.availHeight -h)/2;
  p = "scrollbars=" + sb + ",resizable=" + rs + ",status=" + st + ",toolbar=" + tb + ",menubar=" + mb + ",titlebar=" + ti + ",top=" + t + ",left=" +lft + ",width=" + w + ",height=" + h;
  window.open(url, rand(101)-1, p);
}

function PopDetail(url,h,w,sb,rs,st,tb,mb,ti) 
{
  lft = (screen.availWidth -w)/2;
  t = ((screen.availHeight -h)/2)+229;
  p = "scrollbars=" + sb + ",resizable=" + rs + ",status=" + st + ",toolbar=" + tb + ",menubar=" + mb + ",titlebar=" + ti + ",top=" + t + ",left=" +lft + ",width=" + w + ",height=" + h;
  window.open(url, "detail", p);
}





function topButtonOnClick() {
  document.navForm.navEvent.value = "Top"
}

function prevButtonOnClick() {
  document.navForm.navEvent.value = "Prev"
}

function nextButtonOnClick() {
  document.navForm.navEvent.value = "Next"
}

function bottomButtonOnClick() {
  document.navForm.navEvent.value = "Bottom"
}
	 
	 
function setLink(strArg) {
	self.location.href = strArg;
}

function sendLinkBack(strArg) {
	window.opener.setLink(strArg);
	window.close();
}

function gotoPage(p)
{
	document.ImageBank.intpage.value = p
	document.ImageBank.submit()
}

