//use to add any custom javascripts to this site

/////////////////////////////////////////////////////////////
// the following three functions are used as default functions
// for setting over and out mouseover states for top nav
/////////////////////////////////////////////////////////////
    function menuOver(img) {
        //get file type
        strFileType = getFileType(img.src)
        if (img.src.indexOf("On." + strFileType) == -1) {
            img.src = img.src.replace("." + strFileType, "Over." + strFileType)
        }
    }
    
    function menuOut(img) {
        //get file type
        strFileType = getFileType(img.src)
        if (img.src.indexOf("Over." + strFileType) != -1) {
            img.src = img.src.replace("Over." + strFileType, "." + strFileType)
        }
    }

    function getFileType(strFileName){
        strFileType = ""
        arrParts = strFileName.split(".")
        strFileType = arrParts[arrParts.length-1]
        return strFileType
       
    }


// function: to clear login field
function clearSearchField(e) {
    if ("Search Keywords..." == e.value) {
        e.value = '';
    }
    else if (e.value == '') {
        e.value = "Search Keywords...";
    }
}

// function: force enter click
function forceClick(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {
        elem.click();
        return false;
    }
    return true;
}

//function: is alphanumeric
function alphaNumericCheck(str){
    var regex = /^[a-zA-z0-9]+$/;
    if (str.match(regex)) {
        return true;
    } else {
        return false;
    }
}

//function: is alphanumeric
function characterCheck(str) {
    var regex = /[a-zA-z]/;
    if (str.match(regex)) {
        return true;
    } else {
        return false;
    }
}

// function: do search
function doSearch(e, elemId, searchId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;
    var search = document.getElementById(searchId).value;

    //alert(search);
    //if ((search != "") && (alphaNumericCheck(search))) {
    if ((search != "") && (characterCheck(search))) {
        //location.href = "/search.aspx?search=" + escape(search);
        //document.location.href = '/search.aspx?cx=010297623881977876693%3Afktjx4wesvo&cof=FORID%3A10%3BNB%3A1&ie=UTF-8&q=' +
        document.location.href = '/search.aspx?usterms=' + search + '&ustype=0'
    }
    else {
        alert("Please submit a valid search");
    }
    return false;
}

// function: add rollover for SmartWebs buttons (handles GIFs and PNGs)
function addSWBtnRollovers() {
    //alert("images # " + document.images.length);
    for (i = 0; i < document.images.length; i++) {
        //if button is a smartwebs button

        if (document.images[i].src.indexOf('swbtn_') > 0) {
            //if button is a png
            //alert("src: " + document.images[i].src);
            imgSrc = document.images[i].src
            //alert(imgSrc)
            arrParts = imgSrc.split(".")
            ext = arrParts[arrParts.length - 1]
            //alert(ext)
            if (ext == "gif") {
                document.images[i].onmouseover = function() { swapSWButtons(this, 'gif'); };
                document.images[i].onmouseout = function() { swapSWButtons(this, 'gif'); };
            }
            if (ext == "jpg") {
                document.images[i].onmouseover = function() { swapSWButtons(this, 'jpg'); };
                document.images[i].onmouseout = function() { swapSWButtons(this, 'jpg'); };
            }
            if (ext == "png") {
                document.images[i].onmouseover = function() { swapSWButtons(this, 'png'); };
                document.images[i].onmouseout = function() { swapSWButtons(this, 'png'); };
            }
        }
        
        //while we're in here check uploadImages directories and make sure there are no staging urls floating around
       
            var theSource = document.images[i].src.toLowerCase()

            if (theSource.indexOf('uploadimages') > 0) {
                arrParts = theSource.split("/")
                theSource = theSource.replace(arrParts[0] + "//" + arrParts[2],"")
                document.images[i].src = theSource
            }
    }
}
// function: swap the rollover buttons
function swapSWButtons(img, ext) {
    thisSrc = img.src
    if (thisSrc.indexOf("Over") > 0) {
        thisSrc = thisSrc.replace("Over." + ext, "." + ext)
        img.src = thisSrc
    } else {
        thisSrc = thisSrc.replace("." + ext, "Over." + ext)
        img.src = thisSrc
    }
}

// function: add png class for PNG images
function addPNGfix() {
    //alert("images # " + document.images.length);
    for (i = 0; i < document.images.length; i++) {
        //get image extension
        imgSrc = document.images[i].src
        //alert(imgSrc)
        arrParts = imgSrc.split(".")
        ext = arrParts[arrParts.length - 1].toLowerCase()
        
        //if image is a PNG
        if (ext == "png") {
            //alert(ext);
            //if button is a png
            $(document.images[i]).addClass("png");
        }
    }
}

function init() {
    addSWBtnRollovers(); //add swbutton rollovers
    //setBackgroundBanner(); //set background banner (inner pages)
    //addPNGfix(); //add PNG fix
}
window.onload = init;

function searchSite() {
    
    if (document.getElementById("siteSearchBox")){
        if (document.getElementById("siteSearchBox").value != ""){
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBox").value) + "&ustype=0"
        }
    }
}
function searchSite404() {

    if (document.getElementById("siteSearchBoxF")) {
        if (document.getElementById("siteSearchBoxF").value != "") {
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBoxF").value) + "&ustype=0"
        }
    }
}
/////////////////////////////////////////////////////////////
// END
/////////////////////////////////////////////////////////////

//formats date to site spec
function formatDate(whichDate){
	showDate = new String()
	thisDate = new Date(whichDate)
	thisMonth = thisDate.getMonth()
	thisMonth += 1
	thisDay = thisDate.getDate()
	thisYear = thisDate.getYear()
	
	switch(thisMonth){
	    case 1:
	        showDate = "January, "
	        break;
	    case 2:
	        showDate = "February, "
	        break;
	    case 3:
	        showDate = "March, "
	        break;
	    case 4:
	        showDate = "April, "
	        break;
	    case 5:
	        showDate = "May, "
	        break;
	    case 6:
	        showDate = "June, "
	        break;
	    case 7:
	        showDate = "July, "
	        break;
	    case 8:
	        showDate = "August, "
	        break;
	    case 9:
	        showDate = "September, "
	        break;
	    case 10:
	        showDate = "October, "
	        break;
	    case 11:
	        showDate = "November, "
	        break;
	    case 12:
	        showDate = "December, "
	        break;
	}
	
	showDate = showDate + thisDay + " " + thisYear
	
		
	
	return showDate

}


//check for any documents in uploadDocs directory and add click tracking
//using Visistat 
$(document).ready(function() {

    $("#innerContentContainer a").click(function(i) {
        if (this.href.toLowerCase().indexOf('uploaddocs/') > -1) {

            var docFile = this.href.toLowerCase()
            var arrParts = docFile.split("/")
            docFile = arrParts[arrParts.length-1]
            //alert(docFile)
            VSLT(docFile)
        }

    });
    $("#homeContent a").click(function(i) {
        if (this.href.toLowerCase().indexOf('uploaddocs/') > -1) {

            var docFile = this.href.toLowerCase()
            var arrParts = docFile.split("/")
            docFile = arrParts[arrParts.length - 1]
            //alert(docFile)
            VSLT(docFile)
        }

    });



});

//-->	
