// JavaScript Document

// Sub Nav function
function fnsubnav()
    {
    alert('test')
    if(document.getElementById("subnav")!= null)
      {
      if(document.getElementById("subnav").style.display=="none")
      document.getElementById("subnav").style.display="block";
      else
      document.getElementById("subnav").style.display="none";
      }
    }
    
//=========================Pop up Code=============================================
var xmlhttp;
var currPoll;

function showHint(str)
{
if (str.length==0)
  {
   if(document.getElementById("txtHint")!= null)
    document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
var url="popup.aspx";
url=url+"?D="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("divPopup").innerHTML=xmlhttp.responseText;
  }
}

//=================Response insert code===========================
function fnValidate()
{ 
   var Flag = 0;
   var Data = "";
   //alert(Flag)
   for(var i=0;i<20;i++)
   {
     var temp = "RadioButtonList1_"+i;
     if(document.getElementById(temp)!= null)
        if(document.getElementById(temp).checked==true)
          { 
            Data = document.getElementById(temp).value;
            Flag = 1;  
            break;         
          }        
   }
     // alert(Data); 
   if(Flag==1)
    {InsertHint(Data);}
   else
    {
    alert('Please select any response');
    return false; 
    }
}

function InsertHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
  // Set Cookie
  document.cookie = "Polls="+ReadCookie('Polls')+" , "+currPoll;
var url="popup.aspx";
url=url+"?M="+str;
url=url+"&D=";
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

//===========================Hide Div========================
function hideDiv()
{
    if(document.getElementById("topPopup")!= null)
        document.getElementById("topPopup").style.display="none"; 
        
    if(document.getElementById("hideshow")!= null)
        document.getElementById("hideshow").style.visibility="hidden";     //<div id="hideshow" style="visibility:hidden;">
}

//======================Set Cookies====================================
function ReadCookie(cookieName) {
           var theCookie=""+document.cookie;
           var ind=theCookie.indexOf(cookieName);
           if (ind==-1 || cookieName=="") return ""; 
           var ind1=theCookie.indexOf(';',ind);
           if (ind1==-1) ind1=theCookie.length; 
           return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
        }

function fnonloadtest(curr)
{  
 // alert(document.cookie +"<br/>  "+curr);
  var strTemp = ReadCookie('Polls')
  if(strTemp.indexOf(curr) > 0)
     { // alert('Av');
     }
  else {
    //alert('Not Av');
    currPoll= curr;
    showHint(curr); //Show Popup window
   }   
}
