var tot_val =1
var loop =1
function show_page(val)
{
tot_val = tot_val + val;
loop = document.getElementsByTagName("div").length-1
if ( (tot_val >=1) &&  (tot_val <=loop))
if (loop > 1)
{
if (tot_val == 1)
document.all.item("Previous").style.display = "none"
else
document.all.item("Previous").style.display = ""
if (tot_val == loop)
{ document.all.item("Next").style.display = "none"; document.all.item("submit").style.display = ""  }
else
{ document.all.item("Next").style.display = "" ; document.all.item("submit").style.display = "none"  }
for (i=1; i<= loop; i++)
{
if (i == tot_val)
document.all.item("Page_Val_"+ i).style.display = "";
else
document.all.item("Page_Val_"+ i).style.display = "none";
}
}
else // if there is no page breaks -- loop =1
{
// document.all.item("Previous").style.display = "none";
// document.all.item("Next").style.display = "none"
document.getElementById("Previous").style.display = "none";
document.getElementById("Next").style.display = "none"
}
var text_HTML ="<table border=0 height=2 cellspacing=0 cellpadding=0 width=20%><tr>"
for (i=1;i<=loop;i++)
{
if (i <= tot_val)
text_HTML = text_HTML +"<td bgcolor=000000></td>"
else
text_HTML = text_HTML +"<td bgcolor=e9e9e9></td>"
}
text_HTML =text_HTML + "</tr></table>"
text_HTML =text_HTML + "<font size=1>" + parseInt((tot_val/loop)*100) + "% Complete</font>"
//document.all.item ("survey_completed").innerHTML = text_HTML;
document.getElementById("survey_completed").innerHTML = text_HTML;
}
// Part II
var quest_mandatory= new Array()
var quest_mandatory_name= new Array()
// Loaded with the page (to be put in one time function call
function set_int_variables()
{
var text="";
var cnt_j =0;
var chk_dup_name=""
// Replace all document.all.length to document.getElementsByTagName("body")[0].getElementsByTagName("*").length
for (i=0;i<=document.all.length-1;i++)
{
if (document.all.item(i).name != null)
if (document.all.item(i).name.indexOf('Survey') != -1) // Filtering items that are questions
if (document.all.item(i).name.indexOf('*') != -1) // Filtering mandatory questions
{ //text =  text + document.all.item(i).name;
if (chk_dup_name !=document.all.item(i).name)
{
quest_mandatory[cnt_j] = i;
quest_mandatory_name[cnt_j] = document.all.item(i).name;
chk_dup_name = document.all.item(i).name;
cnt_j++;
}
}
}
//alert (text);
}
function ret_fun()
{
var flag_validate = true;
var visibility_check;
var q_type;
var is_radio;
for (i=0;i<=quest_mandatory.length-1;i++)
{
q_type =  document. all. item(quest_mandatory_name[i]).type
if ( ( q_type != "text") &&  (q_type!= "select-one") &&  (q_type != "hidden") &&  (q_type != "textarea") &&  (q_type!= "check")  )
{
visibility_check =  check_for_visible_quests(document. all. item(quest_mandatory[i]),quest_mandatory_name[i] )
is_radio = true;
}
else
{
visibility_check =  check_for_visible_quests(document. all. item(quest_mandatory_name[i]),quest_mandatory_name[i] )
is_radio = false
}
if (visibility_check == false)
{
if (is_radio == true)
{
for (n=0;n<=(document.getElementsByName(quest_mandatory_name[i]).length-1);n++)
{ document.getElementsByName(quest_mandatory_name[i])[n].style.background="ffeeee";}
is_radio = false;
}
alert ('Please answer the mandatory question before you proceed')
//////document. all. item(quest_mandatory[i]).select()
if (document. all. item(quest_mandatory[i]).type != "hidden")
{ document. all. item(quest_mandatory[i]).style.background="ffeeee";
document. all. item(quest_mandatory[i]).focus()
}
flag_validate = false;
break;
}
else// Making the answered questions with white background
{
if (is_radio == true)
{
for (n=0;n<=(document.getElementsByName(quest_mandatory_name[i]).length-1);n++)
{ document.getElementsByName(quest_mandatory_name[i])[n].style.background="ffffff";}
}
document. all. item(quest_mandatory[i]).style.background="ffffff";
}
} // end if
if  (flag_validate == true)
show_page(1);
else
return false;
} // end function ret_fun()
function check_for_visible_quests(o,q_name) {
var c=o;
while (o.tagName != "DIV") {
o = o.parentNode;
}
if (o.style.display != "none")
{
if(validate(c,q_name) == false)
return false;
else
return true
}
}
function validate(c,q_name)
{
var quest_type=c.type;
switch (quest_type)
{
case 'radio':
flag_checked = false;
for (k=0;k<=(document.getElementsByName(c.name).length-1);k++)
{ if ((document.getElementsByName(c.name)[k].checked) == true )
flag_checked=true;
}
if (flag_checked == false)
return false;
else
return true ;
break;
case 'text':
if (c.value.length == 0)
return false;
else
return true ;
break;
case 'hidden':
if (c.value.length == 0)
return false;
else
return true ;
break;
case 'textarea':
if (c.value.length == 0)
return false;
else
return true ;
break;
case 'select-one':
if (c.selectedIndex == 0)
return false;
else
return true ;
break;
default: // For radio that is not detected
flag_checked = false;
for (k=0;k<=(document.getElementsByName(q_name).length-1);k++)
{ if ((document.getElementsByName(q_name)[k].checked) == true )
flag_checked=true;
}
if (flag_checked == false)
return false;
else
return true ;
break;
}
}
