function ControlForValidate(trid, controlid, fillradioid, fillinputid)
{
    this.trid = trid;
    this.controlid = controlid;
    this.fillradioid = fillradioid;
    this.fillinputid = fillinputid;
}
function KSQP_Validate(sWPQ)
{
    var controls = eval("g_ControlsForValidate" + sWPQ);
    var returnValue = true;
    for(var i = 0; i < controls.length; i++)
    {
        var res = true;
        var fillEl = document.all[controls[i].fillradioid];
        if((fillEl != null) && (fillEl.checked == true))
        {
            var fillElInp = document.all[controls[i].fillinputid];
            res = KSQP_ValidateControlWithTagName(controls[i], fillElInp);
        }
        else
        {
            var els = document.all[controls[i].controlid];
            try
            {
                if(els.tagName == null)
                {
                    res = KSQP_ValidateArrayControls(controls[i], els);
                }
                else
                {
                    res = KSQP_ValidateControlWithTagName(controls[i], els);
                }
            }
            catch(e)
            {
                res = KSQP_ValidateControlWithTagName(controls[i], els);
            }
        }
        if(res == false)
        {
           document.all[controls[i].trid].style.display = "";
           returnValue = res;
        }
        else
        {
           document.all[controls[i].trid].style.display = "none";
        }
    }
    return returnValue;
}

function  KSQP_ValidateControlWithTagName(data, el)
{
    var res = true;
    if(el.tagName.toLowerCase() == "select")
    {
        if(el.selectedIndex == -1)
        {
            res = false;
        }
    }
    else
    {
        if(KSQP_Trim(el.value).length == 0)
        {
            res = false;
        }
    }
    return res;
}

function KSQP_ValidateArrayControls(data, els)
{
    var res = true;
    var isChecked = false;
    for(var ii = 0; ii < els.length; ii++)
    {
        if(els[ii].checked == true)
        {
            isChecked = true;
        }
    }
    if(isChecked == false)
    {
        res = false;
    }
    return res;
}
function KWiz_SurveyPlusImage(imgId, width, height)
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
        var img = document.getElementById(imgId)
        var imgID = (img.id) ? "id='" + img.id + "' " : ""
        var imgClass = (img.className) ? "class='" + img.className + "' " : ""
        var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
        var imgStyle = "display:inline-block;" + img.style.cssText 
        if (img.align == "left") imgStyle = "float:left;" + imgStyle
        if (img.align == "right") imgStyle = "float:right;" + imgStyle
        if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
        + " style=\"" + "width:" + width + "px; height:" + height + "px;" + imgStyle + ";"
        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
        + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
        img.outerHTML = strNewHTML
    }
}

function KSQP_OnSubmit(sWPQ, oEl)
{
}

function KSQP_Trim(text) 
{
    text = text.replace(/^\s+/, '');
    return text.replace(/\s+$/, '');
}
