﻿// JScript File

    var timerID
    var mypop

function CheckNumeric(evt) {
    //disallow alpha keys, allow TAB etc.
    var list = 'abcdefghijklmnopqrstuvwxyz';

    var charcode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    var ch = String.fromCharCode(charcode);
    ch = ch.toLowerCase();
    var a = list.indexOf(ch);
    if (a != -1) {
        if (window.event) {//IE
            window.event.returnValue = null
        } else { //firefox
            evt.preventDefault()
        }
    }
}
function LTrim(String) {
    var i = 0;
    var j = String.length - 1;

    if (String == null)
        return (false);

    for (i = 0; i < String.length; i++) {
        if (String.substr(i, 1) != ' ' &&
       String.substr(i, 1) != '\t')
            break;
    }

    if (i <= j)
        return (String.substr(i, (j + 1) - i));
    else
        return ('');
}


function RTrim(String) {
    var i = 0;
    var j = String.length - 1;

    if (String == null)
        return (false);

    for (j = String.length - 1; j >= 0; j--) {
        if (String.substr(j, 1) != ' ' &&
         String.substr(j, 1) != '\t')
            break;
    }

    if (i <= j)
        return (String.substr(i, (j + 1) - i));
    else
        return ('');
}
function Trim(String) {
    if (String == null)
        return (false);

    return RTrim(LTrim(String));
}
function isvalidemail(email) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {
        return true;
    }
    else {
        return false;
    }
}
function isDarkColor(cHex) {
    if (cHex.substring(0,3)=='rgb') {cHex=rgbConvert(cHex)} //firefox returns rgb(3,4,5)
    if (cHex.charAt(0)=="#") {
        cHex= cHex.substring(1,7)
        //bgHex=cutHex(bgHex)
        //calculate luminance http://en.wikipedia.org/wiki/Luminance_(relative) shows 0.2126, 0.7152, 0.077
        //http://www.scantips.com/lumin.html shows 0.3, 0.59, 0.11
        if (0.3*parseInt(cHex.substring(0,2),16)+
            0.59*parseInt(cHex.substring(2,4),16)+
            0.11*parseInt(cHex.substring(4,6),16)<128) {
                return true
            }else {
                return false
            }
        //if (HexToR(bgHex)+HexToG(bgHex)+HexToB(bgHex)<500)
    }
    return false
}
function fitPic(o) {
    //for details on window size and scrollbars see http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
    if (window.opener != null) { //only do if in popup
        //iWidth = window.innerWidth?window.innerWidth:document.body.offsetWidth; 
        //If got doctype then above can return width of document, not of window, so do this  
        //iWidth=document.documentElement.offsetWidth?document.documentElement.offsetWidth:iWidth
        //Give element 0 the same gap at bottom as at top
        //        o = document.forms[0].firstChild //this doesn't work cod find viewstate fields etc!
        //        alert(o.innerHTML)
        var oTopGap
        var oLeftGap
        oTopGap = findPosY(o)
        if (oTopGap < 5) { oTopGap = 5 }
        oLeftGap = findPosX(o)
        if (oLeftGap < 5) { oLeftGap = 5 }
        //        alert(9/0)  
        //        alert(oTopGap)  
        iWidth = o.offsetWidth
        iHeight = o.offsetHeight
        //window.resizeTo(17+iWidth+2*oLeftGap, iHeight + 2*oTopGap); //allow for extraneous vertical scrollbar in IE + Body margin etc.
        window.resizeBy((17 + iWidth + 2 * oLeftGap) - vpWidth(), (iHeight + 2 * oTopGap) - vpHeight()); //allow for extraneous vertical scrollbar in IE + Body margin etc.
    }
} 
function vpWidth() { //viewport width
return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
}
function vpHeight() {
return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
}

function mypopup(add, nname, specs) { //Don't use for .pdf - doesn't work! (because new window seems to spawn another one)
    //if (window.screenLeft!=null) {
    //specs +=',top=' + (window.screenTop+15) +',left=' + (window.screenLeft+15)
    //}

    //Center it based on passed ht and wd - these should be set by the calling routine to the MAXIMUM possible ht and wd of contents
    var sss, n, z
    sss = specs.toLowerCase() + "="
    var arr = (sss.replace(/,/g, "=")).split("=")
    n = myIndexOf(arr, "height") //IE doesn't have an 'indexOf' for arrays!
    if (n != -1) {
        z = parseInt(arr[n + 1])
        if (z < screen.height) {
            specs += ",top=" + (screen.height - z) / 2
        } else {
            specs += ",top=0"
        }
    }
    n = myIndexOf(arr, "width") //IE doesn't have an 'indexOf' for arrays!
    if (n != -1) {
        z = parseInt(arr[n + 1])
        if (z < screen.width) {
            specs += ",left=" + (screen.width - z) / 2
        } else {
            specs += ",left=0"
        }
    }

    //In FF, if a PREVIOUS instance of the popup window has been hidden, doing 'window.focus()' (in the new window's onLoad) will do nothing to bring it to forefront
    //unless has configured tools/options/javascript/advanced/Raise or Lower Windows).SO, what we do here is, before opening the pop-up, look to see if a previous popup
    //OF THE SAME NAME is open, we set focus to it, _before_ opening the new one(!).
    //This dance is NOT required for IE, but we do it anyway (can't hurt?)
    try {
        if (mypop && mypop.name == nname) { mypop.focus() }
    }
    catch (Error) { }
    mypop = window.open(add, nname, specs)
    if (timerID != "" && timerID != null) { //clear any existing timer first
        window.clearTimeout(timerID)
    }
    timerID = setTimeout("checkpopup(true)", 1000)
}
function myIndexOf(arr, val) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == val) {
            return i;
        }
    }
    return -1;
}

function checkpopup(dontCheckForClosed) {
var bad
if (mypop==null ||mypop==undefined) {
	bad=true;
	} else{
	if (mypop.closed) {bad=true;}
}
if (bad) {
    alert('Please set your browser to allow a pop-up window to open (the next screen shows in a pop-up window)')
} else {
   //////////////////// this causes any FIELD on the new form to lose focus!! mypop.focus()
}
}
function mypopupnocheck(add, nname, specs)//use this where pop-up may close itself
{//In Member app we will always check...
    mypopup(add, nname, specs)

//    //Center it based on passed ht and wd - these should be set by the calling routine to the MAXIMUM possible ht and wd of contents
//    var sss, n, z
//    sss = specs.toLowerCase() + "="
//    var arr = (sss.replace(/,/g, "=")).split("=")
//    n = myIndexOf(arr, "height") //IE doesn't have an 'indexOf' for arrays!
//    if (n != -1) {
//        z = parseInt(arr[n + 1])
//        if (z < screen.height) {
//            specs += ",top=" + (screen.height - z) / 2
//        } else {
//            specs += ",top=0"
//        }
//    }
//    n = myIndexOf(arr, "width") //IE doesn't have an 'indexOf' for arrays!
//    if (n != -1) {
//        z = parseInt(arr[n + 1])
//        if (z < screen.width) {
//            specs += ",left=" + (screen.width - z) / 2
//        } else {
//            specs += ",left=0"
//        }
//    }
//    mypop = window.open(add, nname, specs)
}

function mydelayclose(mess) {
    //alert(document.getElementById('nosucccccccccccccc').id)
    if (mypop) {
        if (!mypop.closed) {
            mypop.close(); mypop = null; if (mess != null) { alert(mess) }
            ////////////out 11/3/9 } else {
            timerID2 = setTimeout("mydelayclose('" + mess + "')", 100)
        }
    }
}
function getRenderedStyle(el, styleProp) {//Rendered style may be different from DECLARED
    //pass style as e.g. "background-color"
    if (el.currentStyle) {
        // var st = el.currentStyle[styleProp];
        styleProp = styleProp.replace(/\-(\w)/g, function(strMatch, p1) {
            return p1.toUpperCase();
        });
        st = el.currentStyle[styleProp];
    }
    else if (window.getComputedStyle)
        var st = document.defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
    return st;
}

function disableAllControls(c) {
//c is an ARRAY, eg "[el1]"
  var elem = document.forms[0].elements;
  for(var i=0;i<elem.length;i++) {
    if(elem[i].className!='mybtn') {
    elem[i].disabled=true
    }else {
    elem[i].className='mybtndis'
    }
   }
   var p
   for (var x=0;x<c.length;x++) {
    p=c[x]
       if (p.className!='mybtndis'){
       p.disabled=false //exception for close button
       }else{
       p.className='mybtn'
       }
   }
}
function m1(el) {
if(el.className!='mybtndis') {el.className='mybtnon'}
}
function m2(el) {
if(el.className!='mybtndis') {el.className='mybtn'}
}
function sizeToFillAvailableVertSpace(obj,bottomStuffHeight){
//This assumes that there are NO "height=100%' anywhere in document. So browser will show document in MINIMUM vertical space required.
//bottomstuffheight is required gap between bottom of obj and bottom of window (=bottom of document)
//find the current gap between the bottom of the doc and the bottom of the window. Then increase the size of obj by that amount!
  var nnn
  var winHeight
  var objTop
//   if(window.innerHeight !=undefined) {winHeight= window.innerHeight;} // most browsers
//    else{ // IE varieties
//    var D= (document.documentElement)? document.documentElement:document.body//standard modes:quirks
//    winHeight= D.clientHeight; 
//    }
    winHeight=vpHeight()
    objTop=findPosY(obj)
      
    var gap=winHeight-obj.offsetHeight-objTop

	nnn=0
	nnn+=obj.style.borderBottomWidth==""?0:parseInt(obj.style.borderBottomWidth)
	nnn+=obj.style.borderTopWidth==""?0:parseInt(obj.style.borderTopWidth)
	nnn+=obj.style.paddingBottom==""?0:parseInt(obj.style.paddingBottom)	
    nnn+=obj.style.paddingTop==""?0:parseInt(obj.style.paddingTop)
    nnn=obj.offsetHeight+gap-nnn-bottomStuffHeight
    
    //Important to have this IF, to avoid recursive calling!
    if (obj.style.height!=nnn>0?nnn+"px":"0px" ){	obj.style.height=nnn>0?nnn+"px":"0px" }	
	
	//obj.document.body.onresize=function(){myResize()}
}

function sizeToFillAvailableHorizSpace(obj,rightStuffWidth){
//This assumes that there are NO "width=100%' anywhere in document. So browser will show document in MINIMUM vertical space required.
//rightStuffWIdth is required gap between bottom of obj and bottom of window (=bottom of document)
//find the current gap between the bottom of the doc and the bottom of the window. Then increase the size of obj by that amount!
  var nnn
  var winWidth
  var objLeft
//   if(window.innerWidth !=undefined) {winWidth= window.innerWidth;} // most browsers
//    else{ // IE varieties
//    var D= (document.documentElement)? document.documentElement:document.body//standard modes:quirks
//    winWidth= D.clientWidth; 
//    }
    winWidth=vpWidth()
    objLeft=findPosX(obj)
      
    var gap=winWidth-obj.offsetWidth-objLeft

	nnn=0
	nnn+=obj.style.borderRightWidth==""?0:parseInt(obj.style.borderRightWidth)
	nnn+=obj.style.borderLeftWidth==""?0:parseInt(obj.style.borderLeftWidth)
	nnn+=obj.style.paddingRight==""?0:parseInt(obj.style.paddingRight)	
    nnn+=obj.style.paddingLeft==""?0:parseInt(obj.style.paddingLeft)
    nnn=obj.offsetWidth+gap-nnn-rightStuffWidth    
    
    //Important to have this IF, to avoid recursive calling!
	if (obj.style.width!=nnn>0?nnn+"px":"0px" ) {obj.style.width=nnn>0?nnn+"px":"0px" }
	//obj.document.body.onresize=function(){myResize()}
}

function sizeToFillAvailableVertSpaceNewxxx(obj){

//The containing object should have a defined bottom-padding to set the bottom gap
  var  myHeight = 0;
  var nnn
//   if(window.innerHeight !=undefined) {myHeight= window.innerHeight;} // most browsers
//    else{ // IE varieties
//    var D= (document.body.clientWidth)? document.body: document.documentElement;//quirks:standard modes
//    myHeight= D.clientHeight; 
//    }
    myHeight=obj.parentNode.offsetHeight
  
    var topGap=obj.offsetTop

    var bottomGap
    bottomGap=obj.parentNode.style.paddingBottom
    bottomGap=bottomGap!=null?parseInt(bottomGap.replace("px","")):0
	nnn=myHeight-topGap-bottomGap
     obj.style.height=nnn>0?nnn+"px":"0px" 

}


function sizeToFillAvailableVertSpaceyyy(obj,bottomStuffHeight){

//bottomStuffHeight is sum of bottom page border etc.
//all parentnodes should be Height:100% for IE to work correctly WITHOUT this.
  var  myHeight = 0;
  var nnn
   if(window.innerHeight !=undefined) {winHeight= window.innerHeight;} // most browsers
    else{ // IE varieties
    //psw - IE* has BOTH doc.body and doc.documentElement. THe first relates to the document body, the second relates to the browser window - we want the second.
    //var D= (document.body.clientWidth)? document.body: document.documentElement;//quirks:standard modes
    var D= (document.documentElement)? document.documentElement:document.body//standard modes:quirks
    winHeight= D.clientHeight; 
    }
//  if( typeof (window.innerHeight) == 'number' ) {
//    //Non-IE
//    myHeight = window.innerHeight;
  //alert(obj.parentNode.innerHTML)
  
  	var curtop = 0;
	var locobj=obj
	if (locobj.offsetParent) {
	do {
			curtop += locobj.offsetTop;
	} while (locobj = locobj.offsetParent);
	 }

//	nnn=myHeight-curtop-10
//	alert(nnn>0?nnn:"0000")
//    obj.style.height=nnn>0?nnn+"px":"0px"
   
      
//out 4/7/9      
//    locobj=obj.parentNode
//    
//	if (locobj!="undefined") {
//	do {
//	    //alert(locobj.tagName)
//			if(locobj.setAttribute) {locobj.setAttribute("height","")}
//			if(locobj.style && locobj.style.height) {locobj.style.height=""}
//			locobj=locobj.parentNode
//	} while (locobj!="undefined" && locobj.tagName.toLowerCase()!="form")
//	}
//COULD here figure out the 'bottomstuff height' here directly, but will use passed value
	nnn=myHeight-curtop-bottomStuffHeight
     obj.style.height=nnn>0?nnn+"px":"0px"
 //   obj.parentNode.style.paddingBottom="4px" //fudge for Default.aspx
    //obj.parentNode.style.backgroundColor="red"
   //} 
}

function findPosY(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;
}


function findPosX(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;
}

