
var myBox4 = {};

myBox4.visiblePage = 0;
myBox4.canRotate = true;
myBox4.cycleTime = 7000;

$(document).ready(function(){
    $('#dropNav').droppy({speed: 70});

	$("DIV.box4 > div").not("DIV.box4 > div:first").hide();
	myBox4.childCount = $("DIV.box4 > div").length;
	// cyclePages(0);
	$("DIV.box4").mouseenter(function(){
		myBox4.canRotate = false;
	}).mouseleave(function(){
		myBox4.canRotate = true;
	});
	
	$("img.hoverFade").css("opacity",.6);
	$("img.hoverFade").hover(function () {
		$(this).stop().fadeTo(300,1);
	}, function () {
		$(this).stop().fadeTo(300,.6);
	});
	
	$(".floatBox").mouseenter(function () {
		// $(this).animate({height: '197px'}, 300);
		$(".floatBoxContent",this).animate({top: '-20px',height: '168px'}, 300);
		
	}).mouseleave(function () {
		// $(this).animate({height: '197px'}, 300);
		$(".floatBoxContent",this).animate({top: '120px',height: '29px'}, 300);
	}); 
});

var myCycle = setTimeout("rotateBox4()", myBox4.cycleTime);

function rotateBox4() {
	if (myBox4.canRotate) {
		myBox4.visiblePage = (myBox4.visiblePage + 1) % myBox4.childCount;
		if (myBox4.visiblePage == 0) {
			$("DIV.box4 > div").not($("DIV.box4 > div").eq(myBox4.visiblePage)).hide();
		}else{
			$("DIV.box4 > div").not($("DIV.box4 > div").eq(myBox4.visiblePage)).slideUp();
		};
		$("DIV.box4 > div").eq(myBox4.visiblePage).slideDown();
	};
	myCycle = setTimeout("rotateBox4()", myBox4.cycleTime);
};




function NavSel(url) {
    document.location.href = url
}
function ParentNavSel(url) {
    window.parent.document.location.href = url
}
function WinOpen(vURL, vName) {

    g_CtlWindow = window.open(vURL, vName, "height=600,width=800,status=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
}

function WinOpenRpt(vURL, vName) {
    //window.open(sFile, "RptReq", "top=0,left=0,height=" + (screen.Height*.7)+ ",width=" + (screen.width*.95)  +", status=yes,toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes");
    g_CtlWindow = window.open(vURL, vName, "height=" + (screen.Height * .9) + ",width=" + (screen.width * .95) + ",top=10,left=10,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes, resizable=yes");
}

function GoBack() {
    window.top.history.back();
}


function AmmendTitle(vTitle) {
    try {
        window.top.document.title = window.top.document.title + ": " + vTitle;
    }
    catch (e) {
        document.title = document.title + ": " + vTitle;
    }
}

function ReplaceTitle(vTitle) {
    window.top.document.title = vTitle;
}

function ShowFullImgTitle(ctl) {
    try {
        confirm(ctl.title);
    }
    catch (e) {
        //alert("error: " + e.message);
    }
}


function NumberWithCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}



function SelAll(VaryCtl, IsChecked) {
    try {
        //loop through all controls in array
        if (document.all(VaryCtl).length >= 1) {
            for (j = 0; j < document.all(VaryCtl).length; j++) {
                document.all(VaryCtl)[j].checked = IsChecked;
            }
        }
        else {
            document.all(VaryCtl).checked = IsChecked;
        }

    }
    catch (e) {
        alert('Error while selecting all.  ' + e.msg);
    }
}

function AnySelected(VaryCtl) {
    var iSelected = 0;
    var SelRow;
    try {
        //alert('ctl len' + document.all(VaryCtl).length);
        if (document.all(VaryCtl).length >= 1) {
            for (j = 0; j < document.all(VaryCtl).length; j++) {
                if (document.all(VaryCtl)[j].checked == true) { iSelected = iSelected + 1 }
            }
        }
        else {
            if (document.all(VaryCtl).checked == true) { iSelected = iSelected + 1 }
        }
        //alert('iSelected=' + iSelected);
        return iSelected;
    }
    catch (e) {
        return 0;
    }
}

function ShowHide(VaryCtl) {

    try {
        alert('Within ShowHide');
        if (document.getElementById(VaryCtl).style.display == 'none') {
            document.getElementById(VaryCtl).style.display = 'block';
        }
        else {
            document.getElementById(VaryCtl).style.display = 'none';
        }

    }
    catch (e) {
        alert('error: ' + e.message);
    }
}


function GetNewDate(ctl) {
    var d = new Date();
    var mon = d.getMonth() + 1;
    var year = d.getFullYear();
    var date = d.getDate();
    var dtdisplay = "";

    dtdisplay = mon + "/" + date + "/" + year;

    try {
        ctl.value = dtdisplay
    }
    catch (e) {
        ctl.value = "failed to fill in date.";
    }

}


function GetNewTime(ctl) {
    var d = new Date();
    var h = d.getHours();
    var m = d.getMinutes();
    var s = d.getSeconds();
    var AorP = " ";
    var timedisplay = "";
    if (h >= 12)
        AorP = "PM";
    else
        AorP = "AM";
    if (h >= 13)
        h = h - 12;
    if (s < 10)
        s = "0" + s;
    if (m < 10)
        m = "0" + m;
    timedisplay = h + ":" + m + " " + AorP;
    try {
        ctl.value = timedisplay
    }
    catch (e) {
        ctl.value = "failed to fill in time.";
    }

}

function chkdate(objName) {
    var strDatestyle = "US"; //United States date style
    //var strDatestyle = "EU";  //European date style
    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparatorArray = new Array("-", " ", "/", ".");
    var intElementNr;
    var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    strDate = datefield.value;
    if (strDate.length < 1) {
        return true;
    }
    for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
        if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
            strDateArray = strDate.split(strSeparatorArray[intElementNr]);
            if (strDateArray.length != 3) {
                err = 1;
                return false;
            }
            else {
                strDay = strDateArray[0];
                strMonth = strDateArray[1];
                strYear = strDateArray[2];
            }
            booFound = true;
        }
    }
    if (booFound == false) {
        if (strDate.length > 5) {
            strDay = strDate.substr(0, 2);
            strMonth = strDate.substr(2, 2);
            strYear = strDate.substr(4);
        }
    }
    if (strYear.length == 2) {
        strYear = '20' + strYear;
    }
    // US style
    if (strDatestyle == "US") {
        strTemp = strDay;
        strDay = strMonth;
        strMonth = strTemp;
    }
    intday = parseInt(strDay, 10);
    if (isNaN(intday)) {
        err = 2;
        return false;
    }
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth)) {
        for (i = 0; i < 12; i++) {
            if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
                intMonth = i + 1;
                strMonth = strMonthArray[i];
                i = 12;
            }
        }
        if (isNaN(intMonth)) {
            err = 3;
            return false;
        }
    }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
        err = 4;
        return false;
    }
    if (intMonth > 12 || intMonth < 1) {
        err = 5;
        return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
        err = 6;
        return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
        err = 7;
        return false;
    }
    if (intMonth == 2) {
        if (intday < 1) {
            err = 8;
            return false;
        }
        if (LeapYear(intYear) == true) {
            if (intday > 29) {
                err = 9;
                return false;
            }
        }
        else {
            if (intday > 28) {
                err = 10;
                return false;
            }
        }
    }
    if (strDatestyle == "US") {
        //uncomment out below if you want to format the date and select the correct format
        //datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
    }
    else {
        datefield.value = intday + " " + strMonthArray[intMonth - 1] + " " + strYear;
    }
    return true;
}
function LeapYear(intYear) {
    if (intYear % 100 == 0) {
        if (intYear % 400 == 0) { return true; }
    }
    else {
        if ((intYear % 4) == 0) { return true; }
    }
    return false;
}

function doDateCheck(from, to) {
    try {
        if (Date.parse(from.value) <= Date.parse(to.value)) {
            //alert("The dates are valid.");
            return 2;
        }
        else {
            if (from.value == "" || to.value == "") {
                //alert("Both dates must be entered.");
                return 1;
            }
            else {
                alert("To date must occur after the from date.");
                return 0;
            }
        }
    }
    catch (e) {
        return 0;
    }
}

function PDecimalNumber(Place) {
    //Limits the number of decimal places to the input number Place; 0 will stop entry of "." 
    var c = window.event.keyCode;
    var txt = window.event.srcElement.getAttribute("Value");
    var len = txt.length;

    if ((c < 48) || (c > 57)) {
        //allow entry of . or - only once and if allowable
        if (((c == 46) && (txt.indexOf(".") == -1) && (Place > 0)) || ((c == 45) && (txt.indexOf("-") == -1))) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        //assumes entry in logical order!
        if (((len - txt.indexOf(".")) > Place) && (txt.indexOf(".") != -1)) {
            return false;
        }
    }
}

function ScanRow(ctl) {
    //alert(ctl);	
    //alert('ID is ' + ctl.id );
    //alert('class is ' + ctl.className );
    //for (i=1; i < document.all.ANOTHER.rows.length; i++) {
    //	document.all.ANOTHER.rows(i).className = "TblRodd"
    //}
    if ((ctl.className == "TblReven") || (ctl.className == "TblRodd")) {
        ctl.className = "TblRscan";
    }
    else {
        if (ctl.className != "TblRsel") ctl.className = "TblRodd";
    }
}

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    } else {
        countfield.value = maxlimit - field.value.length;
    }
}
