var _val_agt=navigator.userAgent.toLowerCase();
var _val_is_major=parseInt(navigator.appVersion);
var _val_is_ie=((_val_agt.indexOf("msie")!=-1) && (_val_agt.indexOf("opera")==-1));
var _val_isNT=_val_agt.indexOf("windows nt")!=-1;
var _val_IE=(document.all);
var _val_IE4=(_val_is_ie && (_val_is_major==4) && (_val_agt.indexOf("msie 4")!=-1));
var _val_IE6=(_val_is_ie && (_val_agt.indexOf("msie 6.0")!=-1));
var _val_NS=(document.layers);
var _val_DOM=(document.getElementById);
var _val_isMac=(_val_agt.indexOf("Mac")==-1);
var _val_allString="document.";
_val_allString += (_val_IE)?"all.":(_val_DOM)?"getElementById(\"":"";
var _val_styleString=(_val_IE)?".style":(_val_DOM)?"\").style":"";
var _val_endAllString=(_val_DOM && !_val_IE)?"\")":"";
var _val_px=(_val_DOM)?"px":"";

function dom_getAttribute(control,attribute)
{
	var attrib;
	if (_val_DOM)
		attrib = control.getAttribute(attribute, false);
	else
		attrib = eval(_val_allString + control.id + "." + attribute + _val_endAllString);
	return attrib;
}

function dom_getElementByID(id)
{
	var element = eval(_val_allString + id + _val_endAllString);
	return element;
}

function RunUnderwritingCondition(theInput, causeOfConditional)
{if(dom_getElementByID(theInput).checked) RunUnderwritingConditionNoCh(causeOfConditional);}

function RunUnderwritingRestriction(theInput, causeOfRestriction)
{if(dom_getElementByID(theInput).checked) {
    RunUnderwritingRestrictionNoCh(causeOfRestriction);
    try{dom_getElementByID('btn_Next').disabled=true; 
        dom_getElementByID('but_inf').title='header=[Disabled because of:] body=['+causeOfRestriction+']';
        dom_getElementByID('but_inf').style.display='block';}catch(e){};
    try{dom_getElementByID('btn_Finish').disabled=true;
        dom_getElementByID('but_inf').title='header=[Disabled because of:] body=['+causeOfRestriction+']';
        dom_getElementByID('but_inf').style.display='block';}catch(e){}
    }else{try{dom_getElementByID('btn_Next').disabled=false;
        dom_getElementByID('but_inf').style.display='none';}catch(e){};
    try{dom_getElementByID('btn_Finish').disabled=false;
        dom_getElementByID('but_inf').style.display='none';}catch(e){}} }

function ShowSubSurvey(theInput, url)
{if(dom_getElementByID(theInput).checked) ShowSubSurveyNoCh(url);}

function RunUnderwritingConditionNoCh(causeOfConditional)
{tb_show("Caption From JavaScript", "UnderwritingCondition.aspx?cause=" + causeOfConditional + "&TB_iframe=true&height=300&width=610&modal=true", null);scroll(0,0);}

function RunUnderwritingRestrictionNoCh(causeOfRestriction)
{tb_show("Caption From JavaScript", "UnderwritingRestriction.aspx?cause=" + causeOfRestriction + "&TB_iframe=true&height=270&width=525&modal=true", null);scroll(0,0);}

function ShowSubSurveyNoCh(url)
{tb_show("Caption From JavaScript", url+"&TB_iframe=true&height=440&width=815&modal=true", null);scroll(0,0);}

function ChangeGroup(groupId, visible) 
{ 
	try{
	var divarr = document.getElementsByTagName('span');
	var divarrlength = divarr.length;	
	for (var i = 0; i < divarrlength; i++)
	{
		if(divarr[i].className.indexOf('group_'+groupId)>=0)
		{
		    divarr[i].style.display=(visible?'block':'none');
			
			var valarr = divarr[i].getElementsByTagName('span');
			var valarrlength = valarr.length;	
			for (var y = 0; y < valarrlength; y++)
			{
			    if(valarr[y].className==''){
			        try{
				    if((''+valarr[y].controltovalidate).length>0)
				    {
					    ValidatorEnable(valarr[y], visible);  
				    }
				    }catch(e){}
			        try{
				    if((''+valarr[y].ClientValidationFunction).length>0)
				    {
					    ValidatorEnable(valarr[y], visible);  
				    }
				    }catch(e){}
				}
			}
		}
	}
    ViewSurvey.UpdateGroup(groupId,(visible?'1':'0'));
    resizeIframe();
    }catch(e){}
}

function RunChangeGroup(theInput, groupId, visible) 
{if(dom_getElementByID(theInput).checked) ChangeGroup(groupId, visible); }
function RunCBChangeGroup(theInput, groupId, visible) 
{if(dom_getElementByID(theInput).checked) ChangeGroup(groupId, visible); else ChangeGroup(groupId, !visible); }

function CheckListValidatorEvaluateIsValid(val)
{
    var control = dom_getElementByID(dom_getAttribute(val,"ControlToValidate"));
    var minimumNumberOfSelected = parseInt(dom_getAttribute(val,"MinimumNumberOfSelected"));
    var selectedItemCount = 0;
    var liIndex = 0;
    var currentListItem = dom_getElementByID(control.id + '_' + liIndex.toString());
    while (currentListItem != null)
    {
        if (currentListItem.checked) selectedItemCount++;
        liIndex++;
        currentListItem = dom_getElementByID(control.id + '_' + liIndex.toString());
    }
    try{
        var otherControl = dom_getElementByID(dom_getAttribute(val,"OtherControl"));
        if (otherControl.checked) selectedItemCount++;
    }catch(e){}
    return selectedItemCount >= minimumNumberOfSelected;
}
function RadioListValidatorEvaluateIsValid(val)
{
    var liIndex = 0;
    var currentListItem = dom_getElementByID(dom_getAttribute(val,"ControlToValidate") + '_' + liIndex.toString());
    while (currentListItem != null)
    {
        if (currentListItem.checked) return true;
        liIndex++;
        currentListItem = dom_getElementByID(dom_getAttribute(val,"ControlToValidate") + '_' + liIndex.toString());
    }    
    return false;
}
function DropListValidatorEvaluateIsValid(val)
{
    var control = dom_getElementByID(dom_getAttribute(val,"ControlToValidate"));
    var options = control.getElementsByTagName ('option');
    return !options[0].selected;
}
function addquote(str) {
    str=str.replace(/\'/g,"&rsquo;");
    return str;
}
function addslashes(str) {
    str=str.replace(/\\/g,'\\\\');
    str=str.replace(/\0/g,'\\0');
    str=str.replace(/\'/g,'\\\'');
    str=str.replace(/\"/g,'\\"');
    return str;
}
function stripslashes(str) {
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\\\/g,'\\');
    str=str.replace(/\\0/g,'\0');
    return str;
}
