﻿
var ie4=document.all;
var ns6=document.getElementById&&!document.all;
var ns4=document.layers;
var op5=document.all&&navigator.userAgent.indexOf("opera") > -1;
var timeoutId;
var default_winclose_timeout = 8000;
var default_short_winclose_timeout = 6000;
var glob_form_index = 0;


function SetGlobFormIndex() {
    for(var f=0; f < document.forms.length; f++) {
        if(document.forms[f].id == 'form1') glob_form_index = f;
    }
}            


function preload() {
    this.length = preload.arguments.length;
    for (var i = 0; i < this.length; i++) {
            this[i+1] = new Image();
            this[i+1].src = preload.arguments[i];
    }
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}



function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
	iPos = 0;
	while (elt != null) {
	iPos += elt["offset" + which];
	elt = elt.offsetParent;
	}
	return iPos;		
}	


function getElem(elem_name) {
    var elem = (document.getElementById)?document.getElementById(elem_name) : document.all? eval('document.all.'+elem_name) : eval('document.'+elem_name);    
    return elem;
}


function getPosOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}







function getElemWidth(elem) {
	if (ns4) {
		return elem.clip.width;
	} else {
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getElemHeight(elem) {
	if (ns4) {
		return elem.clip.height;
	} else {
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}





function CheckBrowserEdge(srcobj, destobj, whichedge){
    var edgeoffset=0
    if (whichedge=="rightedge"){
        var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
        var measure = destobj.offsetWidth
        if (windowedge-destobj.x < measure)
         edgeoffset=measure-srcobj.offsetWidth
    }
    else{
        var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset

        var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
        var measure = destobj.offsetHeight
        if (windowedge-destobj.y < measure){ //move up?
            edgeoffset=measure+srcobj.offsetHeight
            if ((destobj.y-topedge)<measure) //up no good either?
                edgeoffset=destobj.y+srcobj.offsetHeight-topedge
        }
    }
    return edgeoffset
}




function GetPageWidth() {
    if( window.innerHeight && window.scrollMaxY ) { // Firefox 
        return window.innerWidth + window.scrollMaxX;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
       return document.body.scrollWidth;
    }
    else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
     return document.body.offsetWidth + document.body.offsetLeft; 
   }
}

function GetPageHeight() {
    if( window.innerHeight && window.scrollMaxY ) { // Firefox 
        return window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
       return document.body.scrollHeight;
    }
    else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
     return document.body.offsetHeight + document.body.offsetTop; 
   }
}


function GetScreenWidth() {
    if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
        return window.innerWidth-19;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientWidth;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
        return document.body.clientWidth;
    }
}


function GetScreenHeight() {
    if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
        return window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
        return document.body.clientHeight;
    }
}



function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
}


function emailcheck(emailStr) {
    var emailPat = /^.+\@.+\..+$/;
    var matchArray = emailStr.match(emailPat);
    if (matchArray == null) {
    return false;
    }
    else
    {
    return true;
    }
}		        

function datecheck(dateStr, format) {
   dateStr = dateStr.replace(/ /g, '');	
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{2}(\/)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\/)\d{1,2}\1\d{1,2}$/		  
   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\/)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\/)\d{4}\1\d{1,2}$/		  
   } else { // The year must be third
      var reg1 = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/
      var reg2 = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/		  
   }
   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else 
      if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else 
      if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else 
      if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   if (parseFloat(yy) < 1900) { return false; }
   return true;
}	        


function zipcheck(zipStr) {
    var valid = "0123456789-";
    var hyphencount = 0;
    if (zipStr.length!=5 && zipStr.length!=10) {
	    return false;
    }
    for (var i=0; i < zipStr.length; i++) {
    temp = "" + zipStr.substring(i, i+1);
    if (temp == "-") hyphencount++;
    if (valid.indexOf(temp) == "-1") {
	    return false;
    }
    if ((hyphencount > 1) || ((zipStr.length==10) && ""+zipStr.charAt(5)!="-")) {
	    return false;
       }
    }
    return true;
}        


function numcheck(numStr){
    var num=/(^\d+$)|(^\d+\.\d+$)/
    if (num.test(numStr)) return true;
    else return false;
}


function phonecheck(phoneStr) {
	var phonePat;
	var phoneStrTmp;		
	var matchArray;
	var matchMax = 0;
	var matchCounter = 0;	
	// US
	matchMax += 1;
	phonePat = /^1?-?\(?(\d{3})\)?-([a-zA-Z0-9]{3})-([a-zA-Z0-9]{4})$/;
	matchArray = phoneStr.match(phonePat);
	if (matchArray == null) {
		matchCounter += 1;
	}
	if (matchCounter == matchMax) return false;
	else return true;
}		

function phonewextcheck(phoneStr) {
	var phonePat;
	var phoneStrTmp;		
	var matchArray;
	var matchMax = 0;
	var matchCounter = 0;	
	// US
	matchMax += 1;
	phonePat = /^1?[\.\-\/ ]?\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})( *(ext|x)\.? ?\d+)?$/i;
	matchArray = phoneStr.match(phonePat);
	if (matchArray == null) {
		matchCounter += 1;
	}
	if (matchCounter == matchMax) return false;
	else return true;
}	

           

function PageNavBox(elem, status, skip) {
    if(skip != 'skip') {
        if(status == 'over') {
            elem.style.borderColor='#679AC8';
            elem.style.cursor='pointer';
        }
        else {
            elem.style.borderColor='#D0DAEF';
            elem.style.cursor='default';                
        }
    }
}            



function CloseDynWin() {
    hidedynwin();
}


function ResetDynWinElem(elem) {
    elem.innerHTML = '';
    elem.style.width = '';
    elem.style.height = '';            
    elem.style.margin = '';
    elem.style.border = '';              
    elem.style.background = '';   
    return elem;
}

   
   
   
function Rov(elem) {
    elem.style.backgroundColor='#EADDF0';
}   

function Rou(elem) {
    elem.style.backgroundColor='';
}   



function CheckStrMaxLen(str, max) {
    if(str != '') {
        if(str.length > max) {
            str = str.substring(0,max) + '...';
        }
    }
    return str;
}



function DispFieldError(field_name, valid, msg) {
    // Error Msg
    var msgelem = document.getElementById(field_name+'Msg');
    msgelem.innerHTML = msg;
    
    // Field Background
    var fieldelem = eval('document.forms['+glob_form_index+'].'+field_name);
    if(fieldelem.type.indexOf('select') > -1) {
        var fieldelem = document.getElementById(field_name + 'Div');
        if(!valid) {
            fieldelem.style.border = "solid 1px red";                    
        }
        else if(valid) {
            fieldelem.style.border = "solid 1px #FFFFFF";   
        }            
    }           
    else {
        var fieldelem = document.getElementById(field_name);
        if(!valid) {
            fieldelem.style.border = "solid 1px red";                    
        }
        else if(valid) {
            fieldelem.style.border = "solid 1px #7F9DB9";   
        }
    }
}




function DispFieldErrorNoBord(field_name, valid, msg) {
    // Error Msg
    var msgelem = document.getElementById(field_name+'Msg');
    msgelem.innerHTML = msg;
    
}


function InputFocus(sender) { 
    if (sender.value == sender.defaultValue) sender.value = ""; 
}

function InputBlur(sender) { 
    if (sender.value == "") sender.value = sender.defaultValue; 
}








