﻿// JScript File

function getHTTPObject(){
    var xhr = false;
    if (window.XMLHttpRequest){
        xhr = new XMLHttpRequest();
    }else if(window.ActiveXObject){
        try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e){
            try {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e){
                xhr = false;
            }
        }
    }
    return xhr;
}

function isValid(){
    var lblError = document.getElementById('lblError');
    var defColor = document.getElementById('defColor').value;
    var errColor = document.getElementById('errColor').value;
    lblError.innerHTML = "&nbsp;";
    //reset all
    var retval = true;
    var required = document.getElementById('required').value.split(',');
    for(i=0;i<required.length;i++)
    {
        changeLabelColor('lbl' + required[i], defColor);
    }
    for(i=0;i<required.length;i++)
    {
        if (document.getElementById('txt' + required[i]) != null)
        {
            if (document.getElementById('txt' + required[i]).value == '')
            {
                retval = false;
                changeLabelColor('lbl' + required[i], errColor);
            }
        }
        if (document.getElementById('ddl' + required[i]) != null)
        {
            if (ddlSelectedValue('ddl' + required[i]) == '')
            {
                retval = false;
                changeLabelColor('lbl' + required[i], errColor);
            }
        }
    }
    if (retval == true){
        //any custom validations
        try {
            if (customValidation) {
                retval = customValidation();
            }
        } catch(e) {}
    }

    if (retval == false) 
    {
        document.getElementById('lblError').innerHTML = "There are one or more errors in your submission.";
    }
    return retval;
}

function changeLabelColor(l_sObj,l_sColor){
    var l_obj = document.getElementById(l_sObj);
    l_obj.style.color = l_sColor;
}

function ddlSelectedValue(l_sObj){
    var l_oDDL = document.getElementById(l_sObj);
    return l_oDDL[l_oDDL.selectedIndex].value;
}

//useful for finding elements within .net controls
//that get renamed to soemthing like 'control$asdf_myid'
//type is optional if looking for something other than an input
function findElementById(l_id, l_oType){
    var l_obj = document.getElementById(l_id);
    if (l_obj == null)
    {
        if (l_oType == undefined) {l_oType = 'INPUT';}
        var l_oColl = document.getElementsByTagName(l_oType);
        for (i=0;i<l_oColl.length;i++)
        {
            if (l_oColl[i].id.indexOf('_' + l_id) > 0){
                l_obj = l_oColl[i];
            }
        }
    }
    return l_obj;
}

function popWin(url,height,width,toolbar,menubar,locationbar,scroll,resize,status,name) {

	var spec
	spec = "status="+status+",toolbar="+toolbar+",menubar="+menubar+",location="+locationbar+",scrollbars="+scroll+",resizable="+resize+",height="+height+",width="+width;

	remote = window.open(url, name, spec);
	remote.focus();
	remote.location.href = url;
}

function hideMe(l_obj){
    l_obj.style.visibility='hidden';
}


