var newWindow = null;
function closeWin() {
    if (newWindow != null) {
        if (!newWindow.closed)
            newWindow.close();
    }
}

function popUpWin(url, type, strWidth, strHeight) {
    closeWin();
    if (type == "fullScreen") {
        strWidth = screen.availWidth - 10;
        strHeight = screen.availHeight - 160;
    }
    var tools = "";
    if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width=" + strWidth + ",height=" + strHeight + ",top=0,left=0";
    if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width=" + strWidth + ",height=" + strHeight + ",left=0,top=0";
    newWindow = window.open(url, 'newWin', tools);
    newWindow.focus();
}
function collapse(intCatId,e)
{
	var value = e.options[e.selectedIndex].value
	var oldState = intCatId.states;
	var o = document.getElementById(intCatId);
	
	if(value == "1")
	{
		if(oldState == "shown")
		{
			document.getElementById(intCatId).style.display= 'none';
			e.states = "hidden";
		}
		else
		{
			o.style.display= 'block';
			e.states = "shown";
	
		}
	}
	else
	{
		document.getElementById(intCatId).style.display= 'none';
		e.states = "hidden";
	}
}


function calcBoxes(e, inputID)
{
	//alert(e.checked);
	//alert(e.value);
	
	if(e.checked)
	{
		document.getElementById(inputID).value = Number(document.getElementById(inputID).value) + Number(e.value);
	}
	else
	{
		document.getElementById(inputID).value = Number(document.getElementById(inputID).value) - Number(e.value);
	}

}

function GetMyObjectByID(itemID)
{
// In the future will need to build in the ability to handle v4 netscape browsers.
	if (document.getElementById) // Good browsers
		return document.getElementById(itemID)
	else if (document.all) // medium browsers
		return document.all[itemID];
		
	// Need to handle v4 browsers in the future.
}
function CheckField(itemID)
{
	var o = GetMyObjectByID(itemID);
	if(o.value.length<1)
		return false;
	else
		return true;
}
function CheckSRNumber(itemID) {
    var o = GetMyObjectByID(itemID);
    if (o.value.length == 8)
        return true;
    else
        return false;
}
function CheckEmail(itemID) {
    var o = GetMyObjectByID(itemID);
    if (o != null) {
        // Make sure we let an email go through that is empty... The required field catcher will get that
        if (o.value.length < 1) {
            return false;
        }
        var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
        if (!regex.test(o.value)) {
            return false;
        }
        else {
            return true;
        }
    }
}
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}
function isPhoneNumberKey(evt) {
    try {
        var charCode = (evt.which) ? evt.which : event.keyCode;
    }

    catch (err)
         { }

    if (charCode == 13 || charCode == 32||(charCode>=96&&charCode<=105)) {
        return true;
    }

    else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }

    return true;
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    //alert(charCode);
    if (charCode == 13 ||charCode==46||(charCode>=96&&charCode<=105)||(charCode>=35&&charCode<=40)) {
        return true;
    }else
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}
