﻿function openCenteredWindow(imgName, imgwidth, imgheight){
    var width = (imgwidth + 10);
    var height = (imgheight + 80);
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars,left=" + left + ",top=" + top;
    window.open("/Viewer.html?" + imgName, "subWind", windowFeatures);
}

function changeLinkColor(buttonID) {
    return document.getElementById(buttonID).style.color = "yellow";
}

/* Validate the contact us form */
function validateForm(currentForm){
    var returnValue = true;

    if (!checkRequired(currentForm.firstName))
        returnValue = false;
    if (!checkRequired(currentForm.lastName))
        returnValue = false;
    if (!checkRequired(currentForm.emailAddress))
        returnValue = false;

    return returnValue;
}

// checks to see if required fields are blank or not and sets the warning on or off accordingly
function checkRequired(theElem){
    var isValid = true;
    if (isBlank(theElem.value)){
        setRequiredWarning(theElem, true);
        isValid = false;
    } else {
        setRequiredWarning(theElem, false);
    }

    return isValid;
}

// This function will set the border and background color of an input to
// red if a required field is left blank or clear it if it properly completed
function setRequiredWarning(theElem, setWarning) {
    if (setWarning) {
        theElem.style.border = "1px solid #f00";
        theElem.style.backgroundColor = "#fcc";
    } else {
        theElem.style.border = "1px solid #049";
        theElem.style.backgroundColor = "#fff";
    }
}

function isBlank(tVal){
	for (var i = 0; i < tVal.length; i++){
		var c = tVal.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '\t'))
			return false;
	}
	return true;
}

