// Button Rollover Code
function rollOver(imgID, imgName) {
  if (navigator.appName== "Netscape" && parseInt(navigator.appVersion) >= 3)
    document.images[imgID].src = imgName;
  else if (navigator.appName != "Netscape" && parseInt(navigator.appVersion) >= 4) 
    document.images[imgID].src = imgName;
}

function isBlank(val){
  if(val==null) {return true;}
  for(var i=0;i<val.length;i++) {
    if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
  }
  return true;
}

function isEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.lastIndexOf("@") != email.indexOf("@")) {  // @ can't appear more than once
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-/=?^_{|}~.@";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

 
function Left(str, n){
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else
    return String(str).substring(0,n);
}

function Right(str, n){
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else {
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}

function Len(str){  
  return String(str).length;  
}

function showElement(ele) {
  obj = document.getElementById(ele).style;
  obj.display='block';
}

function hideElement(ele) {
  obj = document.getElementById(ele).style;
  obj.display='none';
}

function popUpWindow(URL,W,H) 
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + W + ',height=' + H + ',left=487.5,top=350');");
}

function popupCenter(winname, url, winwidth, winheight, scrollbars, toolbars){

  var top   = (screen.availHeight - winheight - 29) / 2;
  var left  = (screen.availWidth - winwidth - 10) / 2;

  var urlPrefix = "";
  var winurl    = url;

  if (toolbars == "1")
	tbars = 1;
  else
	tbars = 0;

  var winopt    = "toolbar=" + tbars + ",location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollbars + ",copyhistory=0,resizable=0,width="+winwidth+",height="+winheight+",left="+left+",top="+top;
  //alert(winopt);
  newwin = window.open(winurl,winname,winopt);

}

function noSpaces(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if (((" ").indexOf(keychar) > -1))
   return false;

else
   return true;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

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){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = field.value.length;
}



function toggleObjects(hideObj, showObj) {
 
  if (document.getElementById) {
    document.getElementById(hideObj).style.display = 'none';
    document.getElementById(showObj).style.display = 'block';
  }
}

function toggleHelperLayer(layerId) {
  getDetailDiv = document.getElementById('help_' + layerId);
  var getDetailDivClass = getDetailDiv.className;

  if (getDetailDivClass.match('helperNone')) {
    var findOpenDetail = getElementsByClassName('helperBlock', 'div');
    if (findOpenDetail.length > 0) {
      for (var i = 0, j = findOpenDetail.length; i < j; i++) {
        var getOpenDetailById = document.getElementById(findOpenDetail[i].getAttribute('id'));
        getOpenDetailById.className = getOpenDetailById.className.replace('helperBlock', 'helperNone');
      }
    }

    moux -= '281';
    getDetailDiv.style.top = mouy + 'px';
    getDetailDiv.style.left= moux + 'px';
    getDetailDiv.className = getDetailDivClass.replace('helperNone', 'helperBlock');
  } else {
    getDetailDiv.className = getDetailDivClass.replace('helperBlock', 'helperNone');
  }
}

function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;    
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();                              
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';   
  var arrClass = strClass.split(delim);    
  for (var i = 0, j = objColl.length; i < j; i++) {                         
    var arrObjClass = objColl[i].className.split(' ');   
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]); 
          break comparisonLoop;
        }
      }
    }
  }
  return arr; 
}

// Get Mouse Coordinates
function getwindow() {
  var d = document, v = window, w, h, l, t;
  if(typeof v.innerWidth === 'number') {
    w = v.innerWidth;
    h = v.innerHeight;
    l = v.pageXOffset;
    t = v.pageYOffset;
  } else if((v = d.documentElement) &&
      typeof v.clientWidth === 'number' &&
      v.clientWidth !== 0 || (v = d.body)) {
    w = v.clientWidth;
    h = v.clientHeight;
    l = v.scrollLeft;
    t = v.scrollTop;
  }
  return {w: w, h: h, l: l, t: t};
}


var moux, mouy;
function getmouse(e) {
  e = e || window.event || {};
  var w = getwindow(),
    minx = w.l,
    miny = w.t,
    maxx = w.w + w.l,
    maxy = w.h + w.t;
  if(typeof e.pageX === 'number') {
    moux = e.pageX;
    mouy = e.pageY;
  } else {
    moux = e.x + w.l;
    mouy = e.y + w.t;
  }
//  document.forms.f.elements.t.value = 'mouse x =\t' + moux + '\nmouse y =\t' + mouy;
}

function toggleAllSelects(action) {
  var x = document.getElementsByTagName("select");

  for (i = 0; i < x.length; i++) {
    if (action == 'hide') {
      x[i].style.display = "none";
    } else {
       x[i].style.display = "block";
    }
  }
}
