//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//    File Description      : ppn_ench.js 
//                            This class contains all the javascript functions related to customized
//							  patient education materials, Online Request page,Request History and the confirmation page	 
//										 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var cookValue="";
var arrReqType="";
var xmlArtDoc=null;
var selectedContactInfo="";
var arrInsertValue="";
var strRequestName="";
var arrArticles="";
var strOutput="";
var xmlHttp;
var glbImagePath="";;
var strSelectCat="";
var glbEmail="";

//Enums
var PRODUCT="Product";
var CONDITION="Condition";
var ARTICLE="Article";
var SPECIALTY_ONCOLOGY="ONCOLOGY";
var SPECIALTY_PSYCHIATRY="PSYCHIATRY";
var SPECIALTY_PSYCHIATRY_GERIATRIC="PSYCHIATRY_GERIATRIC";
var LOGIN_URL="full_login_2.aspx";
var CUSTOMIZE_PAGE="CustomizeEducation.aspx";
var ONLINE_REQUEST_PAGE="onlinerequest.aspx";
var strContactInfoSelected;
var imgCount=0;



 //.............................XML Helper Methods....................................................... 
    //Used to get the xml node values based on browsers
    
   function loadXML(xmlFileAsString) 
    {
     var xmlDoc=null;
     if(Sys.Browser.agent == Sys.Browser.InternetExplorer)
        {
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async="false";
        xmlDoc.loadXML(xmlFileAsString);
       
        }
       else if(Sys.Browser.agent == Sys.Browser.Firefox)
        {
         var parser=new DOMParser();
	     xmlDoc=parser.parseFromString(xmlFileAsString,"text/xml");
          
        }
        return xmlDoc;
     }   

    
    function getNodeValue(node,nodePos,childPos)
    {
     var selValue="";
     if(Sys.Browser.agent == Sys.Browser.InternetExplorer)
      selValue=node[nodePos].childNodes[childPos].text;
     
     else
      selValue=node[nodePos].childNodes[childPos].textContent;
     
     return selValue;
    }
    
    function SelecteNodesInXML(xmlDoc, elementPath)
    {  
     var node=""; 
      if(Sys.Browser.agent == Sys.Browser.InternetExplorer)
            {
             node = xmlDoc.selectNodes('//'+elementPath);
            }
      if(Sys.Browser.agent == Sys.Browser.Firefox)
            {
             node = xmlDoc.getElementsByTagName(elementPath);
            } 
            
       return node;
      }	
      
        
    function xmlEscape(input)
    {
     return input.replace('&amp;','&');
    }
    
   function trim(s)
	{
	s = s.replace(/(^\s*)|(\s*$)/gi,"");
	s = s.replace(/[ ]{2,}/gi," ");
	s = s.replace(/\n /,"\n");
    return s;
	
	}

	
	function initialCap(value)
	 {
      value= value.substr(0, 1).toUpperCase() + value.substr(1);
      return value;
	}

  //.............................................Xml Helper Method ends Here.......................................


   function ValidateUser()
   {
    if(isUserAunthenticate=="True")   
     {
      return true;
     }
     else
     {
      document.forms[0].action=LOGIN_URL;
      document.forms[0].submit();
      
     }
     
   }

    

  
   function getObject(id)
    {
        return document.all?document.all[id]:document.getElementById(id);
    }
    
    function GetProduct(ddlProductsId,ddlConditionId)
    {
        document.getElementById('divChkBoxContent').innerHTML="";
       	var ddlObject = document.getElementById(ddlProductsId);
	    //document.getElementById('hdnSelectedProducts').value=ddlObject.options[ddlObject.selectedIndex].value;
	    //var url = document.location.href;//"http://saldtp061777:9002/pages/customizepatient.aspx";
        var ddlObject = document.getElementById(ddlProductsId);
        //url = url + "?prd="+ddlObject.options[ddlObject.selectedIndex].value;
        var strSelProduct=ddlObject.options[ddlObject.selectedIndex].value;
        updateDivWithItems(strSelProduct,PRODUCT);
        document.getElementById(ddlConditionId).selectedIndex=0;
    }
	
    function GetCondition(ddlProductsId,ddlConditionId)
    {
        document.getElementById('divChkBoxContent').innerHTML="";
        var url = document.location.href;
        var ddlObject = document.getElementById(ddlConditionId);
       // var hdnRelatedProductsFilter = document.getElementById('hdnSelectedProductOrCondition');
       // hdnRelatedProductsFilter.value = 'Condition:' + ddlObject.options[ddlObject.selectedIndex].value;
        //url = url + "?cnd="+ddlObject.options[ddlObject.selectedIndex].value;
        var strSelCond=ddlObject.options[ddlObject.selectedIndex].value;
        updateDivWithItems(strSelCond,CONDITION);
        document.getElementById(ddlProductsId).selectedIndex=0;
    }

    function updateDivWithItems(strSelValue,cltrType)
    {
   
        var strOutput = "";
        var selValue=""   
        var xmlDoc=loadXML(strArticles);//strArticles is coming from the html file
        var node="";   
        if(xmlDoc != null)
        {
            node= SelecteNodesInXML(xmlDoc,'Item');
            
        	if(node != null)
        	{
	            var title="";
	            var link="";
	            var description="";
	            var artId="";
	            var arrCondition="";
	            var image="";
	            if(node.length>0)
	            {
	            
	             document.getElementById('innerHTMLContent').innerHTML= "";
	              for (i=0;i<node.length;i++)
		            {
		               if(cltrType==PRODUCT)
                        {
                         selValue=getNodeValue(node,i,3);
                        }
                        else if(cltrType==CONDITION)//condition we get more than 1 value with ; seperated
                         {
                         selValue=getNodeValue(node,i,4);
                         arrCondition=selValue.split(';#');
                         selValue=valueInArray(arrCondition,strSelValue);
                        }
                         else if(cltrType==ARTICLE)
                         {
                           selValue=node [i].childNodes[0].text;
                         }


                          if(strSelValue==selValue)
		                  {
		                  var divItem=document.createElement('div');
		                  strOutput = "";
		                  artId=getNodeValue(node,i,0);
			              title = getNodeValue(node,i,1);
		                  description =  getNodeValue(node,i,2);
		                  link =  xmlEscape(getNodeValue(node,i,5));
		                  image=getNodeValue(node,i,8);

		                  strOutput = addNewItem(artId,title,description,link,image,i);
		                  divItem.innerHTML=strOutput ;
		                  document.getElementById('innerHTMLContent').appendChild(divItem);
		                 }
		            }
	            }
	            if(document.getElementById('innerHTMLContent').childNodes.length<=0)
	            {
	              getObject('innerHTMLContent').innerHTML = noResulstsText;
	            }
            }
        }
      
    }
    function valueInArray(arrCondition,strSelValue)
    {
      for (var i=0; i < arrCondition.length; i++) 
		{
		 if (arrCondition[i] == strSelValue) 
		 {
		  return strSelValue;
		 }
		}
		 return "";
    
    
    }
    
    function addNewItem(artId,title,desc,link,image,count)
    {
        var singleitemtemplate = "";
           
        singleitemtemplate = "<input type=checkbox  id=chkPatEdu"+count+" isChecked=false  desc='"+escape(desc)+"' title='"+escape(title)+"'  name=chkPatEdu value="+artId+" onclick=\"SetChkBoxItemsToDiv(this,'"+link+"','"+escape(image)+"','"+count+"')\" >" +"<label class='myCHKInfo'>" + title + "</label>";
        return singleitemtemplate;
    }
   
   function escapeString(str)
    {
		var eChars = ["\\", "'", '"'];
		var lasti = eChars.length;
		for (var i = 0; i < lasti; i++)
		 {
		  var sArray = str.split(eChars[i]);
		  var lastj = sArray.length;
		  str = '';
		  for (var j = 0; j < lastj; j++)
		 	{
			str += sArray[j] + '\\' + eChars[i];
			}
		 }
		var last = str.length - 2*eChars.length;
		return str.substring(0, last);
	}

  function openNewWindow(url) 
	{
		customLinkDownload(url);
	 var newWindow= window.open(url,'','width=500,height=400,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes'); 
 
	}
	

    function SetChkBoxItemsToDiv(id,link,image,count)
    {
      var singleitemtemplate = "";
      var desc='';
      var title='';
     // image=unescape(image);
      var isChecked=id.getAttribute("isChecked");
      if(id.checked==true ||isChecked=="true")//isChecked is used to populate data when user 
      {										//clicks from request history page.			
         id.checked=true;
         if(image=="")
         image="../../SiteCollectionimages/PFP_CPE_PDF_ICON.jpg";
         desc=unescape(id.getAttribute("desc"));
         title=unescape(id.getAttribute("title"));


	      var divChk=document.createElement('div');
	        singleitemtemplate = "<table width='95%' align='center' id='tbl"+count+"' cellspacing='0' cellpadding='0' border='0'>" +
	                "<tbody>" +
	                "<tr><td>&nbsp;&nbsp;</td></tr>"+
	                 "<tr>" +
	                   "<td width='113' rowspan='2'><a href=javascript:openNewWindow('"+escape(link)+"')><img src='"+image+"' border='0' /></a></td>" +
	                        "<td>" +
	                            "<div class='pi_box_content_bullet_title_1'>" +
	                                "<b><span>"+ title+ "</span></b>"+
	                             "</div>" +
	                        "</td>" +
	                     
	                    "</tr>" +
	                    "<tr>" +
	                       "<td>" + desc +
	                        "</td>" +
	                    "</tr>" +
	                "</tbody>" +
	            "</table>";
	       divChk.innerHTML=singleitemtemplate ;
	       document.getElementById('divChkBoxContent').appendChild(divChk);
	      // id.isChecked=false;
	      id.setAttribute('isChecked',"false");
	  	       

	    }
	    else
       {
       
         RemoveData("tbl"+count,id);
       }


      
    }
    
    function RemoveData(id,chkbox)
	{
	 
	   /* if(id!=null || id!='undefined')
	      {
	       document.getElementById(id).removeNode(true);
	       if(document.getElementById(chkbox)!=null)
	       document.getElementById(chkbox).checked=false;
	      }*/
	      
	       var parentNode = document.getElementById(id); 
     		 var len = parentNode .childNodes.length;
      
      		 for(var i = 0; i < len; i++)
       			{      
           		 parentNode.removeChild(parentNode.childNodes[i]);
            	 
	      }
       			parentNode.parentNode.removeChild(parentNode);
       			chkbox.checked=false;


	}
    var noResulstsText = "<table class='pe_article_init_1' cellspacing='0' cellpadding='0' border='0'>" +
		    "<tbody>" +
		        "<tr>" +
		            "<td width='22'>&nbsp;</td>" +
		            "<td width='10'>&nbsp;</td>" +
		            "<td>&nbsp;</td>" +
		            "<td width='30'>&nbsp;</td>" +
		        "</tr>" +
		        "<tr>" +
		            "<td></td>" +
		            "<td></td>" +
		            "<td>No Results Found.</td>" +
		            "<td>&nbsp;</td>" +
		        "</tr>" +
		        "<tr>" +
		            "<td colspan='4'>&nbsp;</td>" +
		        "</tr>" +
		    "</tbody>" +
		"</table>";
    function GetXmlHttpObject(handler)
    { 
    
     var objXmlHttp=null
      if (navigator.userAgent.indexOf("Opera")>=0)
      {
            alert("This example doesn't work in Opera");
            return 
      }
      if (navigator.userAgent.indexOf("MSIE")>=0)
      { 
            var strName="Msxml2.XMLHTTP";
            if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
            {
                strName="Microsoft.XMLHTTP";
            } 
            try
            { 
                objXmlHttp=new ActiveXObject(strName);
                objXmlHttp.onreadystatechange=handler ;
                return objXmlHttp;
            } 
            catch(e)
            { 
                alert("Error. Scripting for ActiveX might be disabled") 
                return 
            } 
      } 
      if (navigator.userAgent.indexOf("Mozilla")>=0)
      {
            objXmlHttp=new XMLHttpRequest();
            objXmlHttp.onload=handler;
            objXmlHttp.onerror=handler; 
            return objXmlHttp;
      }
    }
  

    function addOptions(ddlSelectId,value,text)
    {
        var ddlSelect = document.getElementById(ddlSelectId);
        
        var opt = document.createElement('option');
        opt .value = value;
        opt .text = text;
        try 
        {
            ddlSelect.add(opt , null); // standards compliant; doesn't work in IE
        }
        catch(ex) 
        {
            ddlSelect.add(opt ); // IE only
        }
    }


 function populateCombo(CtrlId,ItemsArray)
    {
    
    	var Items = ItemsArray.split('~');
        for(j=0;j<Items.length;j++)
        {
    	    addOptions(CtrlId,Items[j],Items[j]);
        }
      

    }
    function GeneratePreview()
     {
     	  var url = document.location.href;
		  var addressLine="";
		  var profileName="";
		  var cityStateZip="";
		  var drName="";
		  
		  if(!ValidateCutomizeRequest())
		  return;
		  
		  if(document.getElementById('displaycontactinformation')!=null)
		  profileName=document.getElementById('displaycontactinformation').innerHTML;
		  if(document.getElementById('displayPhyscianName')!=null)
		   drName=document.getElementById('displayPhyscianName').innerHTML;
		    if(document.getElementById('displayAddress1')!=null)
		   {
		   if(document.getElementById('displayAddress1').innerHTML!="") 
		    addressLine=document.getElementById('displayAddress1').innerHTML+" ";
		   }
		
		   if(document.getElementById('displayAddress2')!=null)
		   {
		   if(document.getElementById('displayAddress2').innerHTML!="") 
		   addressLine+=document.getElementById('displayAddress2').innerHTML+" ";
		   }
		
		   if(document.getElementById('displayAddress3')!=null)
		   {
		   if(document.getElementById('displayAddress3').innerHTML!="") 
		   addressLine+=document.getElementById('displayAddress3').innerHTML+" ";
		   }
		   if(document.getElementById('displayCity')!=null)
		   {
		   if(document.getElementById('displayCity').innerHTML!="") 
		   cityStateZip=document.getElementById('displayCity').innerHTML;
		   }
		   if(document.getElementById('displaystate')!=null )
		   {
		   if(document.getElementById('displaystate').innerHTML!="") 
		   if(cityStateZip!="")
		   cityStateZip+=",  "+document.getElementById('displaystate').innerHTML+"  ";
		   else
		   cityStateZip=document.getElementById('displaystate').innerHTML+"  ";

		   }
		   if(document.getElementById('displayZip')!=null)
           {
           if(document.getElementById('displayZip').innerHTML!="")
		    cityStateZip+=document.getElementById('displayZip').innerHTML;
		   }
		
            profileName=AssignAddressValues('hdnProfileName',profileName);
			drName=AssignAddressValues('hdnProfileName',drName);
            addressLine=AssignAddressValues('hdnProfileName',addressLine);
            cityStateZip=AssignAddressValues('hdnProfileName',cityStateZip);
            
            drName=AssignAddressValues('hdnDrName',drName);
            addressLine=AssignAddressValues('hdnDrName',addressLine);
            cityStateZip=AssignAddressValues('hdnDrName',cityStateZip);
            
            addressLine=AssignAddressValues('hdnAddress',addressLine);
            cityStateZip=AssignAddressValues('hdnAddress',cityStateZip);
            
            cityStateZip=AssignAddressValues('hdnZip',cityStateZip);
  


		   var phone="";
		   var eMail="";
		   var emgPhone="";
		   var fax="";
		   if(document.getElementById('displayPhone')!=null)
		   { 
		    if (document.getElementById('displayPhone').innerHTML!="")
		    phone="Phone: "+document.getElementById('displayPhone').innerHTML;
		   }
		   if(glbEmail!=null )
		   {
		    if(glbEmail!="")
		    eMail="E-mail: "+glbEmail;
		   }
		   if(document.getElementById('displayEmergencyPhone')!=null)
		   {
			if(document.getElementById('displayEmergencyPhone').innerHTML!="")
		    emgPhone="Emergency Phone: "+document.getElementById('displayEmergencyPhone').innerHTML;
		   }
		   if(document.getElementById('displayFax')!=null)
		   { 
		    if (document.getElementById('displayFax').innerHTML!="")
		    fax="Fax: "+document.getElementById('displayFax').innerHTML;
		   }

		   
            phone=AssignAddressValues('hdnPhone',phone);
			emgPhone=AssignAddressValues('hdnPhone',emgPhone);
			eMail=AssignAddressValues('hdnPhone',eMail);
			fax=AssignAddressValues('hdnPhone',fax);

            
            emgPhone=AssignAddressValues('hdnemgPh',emgPhone);
            eMail=AssignAddressValues('hdnemgPh',eMail);
            fax=AssignAddressValues('hdnemgPh',fax);

            eMail=AssignAddressValues('hdneMail',eMail);
            fax=AssignAddressValues('hdneMail',fax);
            
            fax=AssignAddressValues('hdnFax',fax);
 
		   
		   var image="";
		   document.getElementById('hdnPhoto').value=glbImagePath;
		   
		   
		   
		   var strInsert=GetSelectedCheckBox('chkboxInserts');
		   document.getElementById('hdnInserts').value=strInsert;
			  
		    document.getElementById("hdnAction").value ="Save";
		    document.getElementById('divErrorArticle').style.display='none';
            document.getElementById('divErrorInserts').style.display='none';
       
            
		    
		    SaveCustomizedReq();
		    SetCustCookie('IsPdfGenerate','true','','','');

			patientEducationTracking(document.getElementById("btnPrint"));


		    document.forms[0].submit();
		  
		   return;
		 
		 
    
}

function AssignAddressValues(hdnCtrl,strValue)
{
if(document.getElementById(hdnCtrl).value=="" && strValue!="")
{
    document.getElementById(hdnCtrl).value=strValue;
    strValue="";
	
	}
	return strValue;
}

 function ValidateCutomizeRequest()
	{
	 var isValid=true;
	 if(!SelectedCheckBox('chkPatEdu'))
	  {
	  document.getElementById('divErrorSave').style.display='block';
	  document.getElementById('divErrorSave').innerHTML="Please select at least one article";
	  isValid=false;
	  }
	  /*if(!SelectedCheckBox('chkboxInserts'))
	  {
	   document.getElementById('divErrorInserts').style.display='block';
	   document.getElementById('divErrorInserts').innerHTML="Please select at least one Content Inserts ";
	   return;
	  }*/
	  if(trim(document.getElementById('txtSaveAs').value)=="")
		 {
		 document.getElementById('divErrorSave').style.display="block";
		 document.getElementById('divErrorSave').innerHTML="Please enter request name";
		 isValid=false;
		 }
		 
        if(!CheckContactInformationSelected())
        {
        document.getElementById('divErrorSave').style.display="block";
		 document.getElementById('divErrorSave').innerHTML="Please fill the contact info or select some other contact.";
		 isValid=false;

        }
	 
 	  
	  return isValid;
	
 }
 
 function CheckContactInformationSelected()
 {
 
 		var isRecord = true;
 		if((document.getElementById("rdoContactInfo1").checked == true) || strContactInfoSelected ==1)
		{
		 if(ContactInformationRecodord1 == null || ContactInformationRecodord1 == "")
		 isRecord = false;		 
		}
	if((document.getElementById("rdoContactInfo2").checked == true)|| strContactInfoSelected ==2)
		{
		if(ContactInformationRecodord2 == null || ContactInformationRecodord2 =="")
		  isRecord = false;	
		}
		if((document.getElementById("rdoContactInfo3").checked == true)|| strContactInfoSelected ==3)
		{
		 if(ContactInformationRecodord3 == null || ContactInformationRecodord3 =="")
		 isRecord = false;	
		}
         return isRecord;
 }

function SelectedCheckBox(chkBoxName)
	{
		var isSelect=false;
		var chkbox=document.getElementsByName(chkBoxName);
		if(chkbox!=null)
		{
		   for (i = 0; i < chkbox.length; i++)
		   {
		 
		      if (chkbox[i].checked)
		      {
		         isSelect=true;		
		      }
		    
		
		   }
		
		}
		return isSelect;
  }

/*function EnableButton(field)
{
if(trim(field.value).length >= 1)
{
document.getElementById('btnPrint').disabled=false;
}
else
{
document.getElementById('divErrorSave').style.display="block";
document.getElementById('divErrorSave').innerHTML="Please enter request name";
document.getElementById('btnPrint').disabled=true;
}

}*/
    
function SaveCustomizedReq()
   {
     
	  document.getElementById('hdnSelArticle').value=GetSelectedCheckBox('chkPatEdu');
	  document.getElementById('hdnContactInfo').value=GetSelectedContactinfo();
	  document.getElementById('hdnUserId').value=strUserId;
	 /* if(document.getElementById('chkLogo').checked)
      document.getElementById('hdnLogo').value=true;
      else*/
      document.getElementById('hdnLogo').value=false;

    }

    
  function GetSelectedContactinfo()
	{
	  var Contactinformationselected ='';
		if((document.getElementById("rdoContactInfo1").checked == true) || strContactInfoSelected ==1)
		{
		 Contactinformationselected =1;
		}
		if((document.getElementById("rdoContactInfo2").checked == true)|| strContactInfoSelected ==2)
		{
		 Contactinformationselected =2;
		}
		if((document.getElementById("rdoContactInfo3").checked == true)|| strContactInfoSelected ==3)
		{
		 Contactinformationselected =3;
		}
		return Contactinformationselected; 
    }
    
    function GetSelectedCheckBox(chkBoxName)
	{
		var strValue="";
		var chkbox=document.getElementsByName(chkBoxName);
		if(chkbox!=null)
		{
		   for (i = 0; i < chkbox.length; i++)
		   {
		 
		      if (chkbox[i].checked)
		      {
		         //strInsert+="<p>"+chkbox[i].value + "</p>"
		         if(strValue=="")
		         strValue=chkbox[i].value;
                 else
		         strValue=strValue+","+chkbox[i].value;
		
		      }
		    
		
		   }
		
		}
		return strValue;
  }
  
 
 function updateDivWithInserts(xmlDoc)
    {
      
        var strOutput = "";        
        if(xmlDoc  != null)
        {
          
        	var node= SelecteNodesInXML(xmlDoc,'Item');
        	if(node != null)
        	{
        	    var insId="";
	            var title="";
	            var brief ="";
	            var description="";
	            if(node.length>0)
	            {
	             document.getElementById('divInsertContent').innerHTML= "";
	              for (i=0;i<node.length;i++)
		            {
		                var divItem=document.createElement('div');
		                divItem.className='information1';
		                strOutput = "";
		                insId=getNodeValue(node,i,0);
			            title = getNodeValue(node,i,1);
		                brief =getNodeValue(node,i,2);
		                description =getNodeValue(node,i,3);
		                strOutput = addNewInserts(insId,title,brief ,description,i);
		                divItem.innerHTML=strOutput ;
		                document.getElementById('divInsertContent').appendChild(divItem);
		            }
	            }
	           
            }
        }
       // document.getElementById('innerHTMLContent').innerHTML = strOutput;
    }
    
     function addNewInserts(insId,title,brief ,desc,count)
    {                  
        var singleitemtemplate = "";
        singleitemtemplate = "<table class='pe_article_init_1'  cellspacing='0' cellpadding='0' border='0'>" +
                "<tbody>" +
                "<tr>"+
                    " <td colspan=1><input type=checkbox id=chkInsert"+count+" name=chkboxInserts value=\""+insId+"\" ><b>" + title+
                    "</b></td></tr>"+
                  "<tr>" +
                       "<td style=padding-left:21px><span>"+brief+
                        "<span></td>" +
                  "</tr>" +
                   "</tbody>" +
            "</table>";
        return singleitemtemplate;
    }

function SetCustomizeRequest(strOutput)
 {
   
  var xmlDoc=loadXML(strOutput);
  if(xmlDoc  != null)
        {
           	
        	var node = node = SelecteNodesInXML(xmlDoc,'Item');
        	if(node != null)
        	{
        	    var product="";
        	    var condition="";
                var articles="";
	            var requestName="";
	            var ContactSel="";
	            var InsertId="";
	            var logo="";
	            if(node.length>0)
	            {
	             for (i=0;i<node.length;i++)
		            {		              		              
		                product=getNodeValue(node,i,0);
		                condition= getNodeValue(node,i,1);
		                articles= getNodeValue(node,i,2);
		                ContactSel= getNodeValue(node,i,3);
						InsertId= getNodeValue(node,i,4);
		                requestName= getNodeValue(node,i,5);
		                logo=getNodeValue(node,i,6);		                
			        }
	            
	            if(product!="" && product!='Select a Product')
	            {
	                document.getElementById('ddlProducts').value=product;
	                GetProduct('ddlProducts','ddlCondition');
	              
	            }
	            if(condition!=""&& condition!='Select a Condition')
	            {
	                document.getElementById('ddlCondition').value=condition;
	                GetCondition('ddlProducts','ddlCondition');
	            }
	              arrArticles=articles;
                  SetCheckBoxChecked('chkPatEdu',articles);
                  arrInsertValue=InsertId;
                  strRequestName=requestName;
                  if(document.getElementById('txtSaveAs')!=null)
                  {
                  SetCheckBoxChecked('chkboxInserts',arrInsertValue);
                  document.getElementById('txtSaveAs').value=strRequestName;
                  /*if(document.getElementById('txtSaveAs').value.length>0)
				   {
				    document.getElementById('btnPrint').disabled=false;
				   }*/
				   
                  }

                /* if(logo=="False")
                  {
                   document.getElementById('chkLogo').checked=false;
                  } */
                  
                 if(ContactSel!=1)
                  {
                   GetContactDetails(ContactSel);
                  }
              
               
                                
	          }
	        }    

}
}

 
 function SetCheckBoxChecked(chkBoxName,articlesId)
 {
   
   if(articlesId!=null && articlesId!='')
    {
       var arrArticlesId=articlesId.split(',');
        var chkbox=document.getElementsByName(chkBoxName);
		if(chkbox!=null)
		{
		 for(var countArt=0;countArt<arrArticlesId.length;countArt++)
		 {
		   for (i = 0; i < chkbox.length; i++)
		   {
		 
		      if (chkbox[i].value==arrArticlesId[countArt])
		      {
		         //isChecked=true;
		        // chkbox[i].isChecked=true;
		       //  var myBoolean=new Boolean();
		        
		        
		         chkbox[i].setAttribute('isChecked',"true");
		         chkbox[i].checked=true;
		          if(chkBoxName!="chkboxInserts")
		         {
		          chkbox[i].click();
		         }
		         
		         
		      	         
		         
		      }
		   	
		   }
		 }
	   }
	}   

 }

function GetRequestHistory(reqHistResult,fileType)
{
 
 
 //DetectBrowser();
 var isPdf=GetCustCookie('IsPdfGenerate');
 DeleteCustCookie('IsPdfGenerate','','');
 
 if(isPdf!=null)
 //if(pdfPath!='' && pdfPath!=undefined && isPdf!=null )
   {
	 
	
	if(fileType.match("PDF"))
	{
	window.open('CustomizedPatientEducation.aspx?PDF=x.pdf');
	}
	else
	{
	window.open('CustomizedPatientEducation.aspx?HTML=x.html');

	}

	}
  var xmlDoc=loadXML(reqHistResult);
  var divReq=document.getElementById('divReqHistory');
   if(xmlDoc  != null)
        {
           	
        	var node = SelecteNodesInXML(xmlDoc,'Record');
        	if(node != null)
        	{
        	    var insId="";
	            var requestName="";
	            var requestType="";
	            var date="";
	            if(node.length>0)
	            {
	            var strDiv="";
	             document.getElementById('divReqHistory').innerHTML= "";
	             var divHead=document.createElement('div');
				 divHead.innerHTML="<table class='datatable'><tr><td width='25%'><b>Request Name</b></td><td width='40%'><b>Request Type</b></td><td width='20%'><b>Date Created</b></td><td width='15%'><b>Remove</b></td></tr></table><br\>"
	             document.getElementById('divReqHistory').appendChild(divHead);
                        for (i=0;i<node.length;i++)
		            {
		               
		                var classstyle = "";
		                insId=getNodeValue(node,i,0);;
			            requestName= getNodeValue(node,i,1);
		                requestType= getNodeValue(node,i,2);
		                date= getNodeValue(node,i,3);
		                var divRes=document.createElement('div');
		                var navigatePg="";
		                if(requestType=="Online Request")
		                {
		                navigatePg=ONLINE_REQUEST_PAGE;
		                }
		                else
		                {
		                navigatePg=CUSTOMIZE_PAGE;

		                }
		                if(i%2==0)
		                {
		                classstyle="altrow"; 
		                }
		               else
		               classstyle="";
		               var nameLength= requestName.length;
		               var request='';
                       for (j=0;j<=nameLength;j++)
   				    	{
   				    	if (j%15==0 && j!=0)
                             {
					    request+=requestName.charAt(j)+' ';

                         }
                         else
                         {
                          request+=requestName.charAt(j);
                         }
                         }
		               
		               		               
		               var strDiv="<table class="+classstyle+" id=tblHist"+insId+" width='100%'><tr><td width='25%'><a href=\""+navigatePg+"\" onclick=\"SetCustCookie('PPNRequest','"+insId+"','','','','');\" >"+request+"</a>"+
		                         "</td>"+
		                         "<td width='40%'>"+requestType+"</td>"+
		                         "<td width='20%'>"+date+"</td>"+
		                         "<td width='15%'><a href='javascript:void(0)' onclick=\"RemoveTable(this,'"+insId+"~"+requestType+"')\">remove</a></td></tr></table>";
		                         
		                   
		                divRes.innerHTML=strDiv;
		                document.getElementById('divReqHistory').appendChild(divRes);
		       	                
		            }
	            }
	           
  }

 
}
}

function RemoveTable(tblId,reqId)
{

    if(tblId!=null)
       {
       

       var XMLhttp = getHTTPObject();
								
		var url=window.location.href+"?Remove="+reqId;
										
		XMLhttp .open("GET", url, true);
		XMLhttp .send(null);
		XMLhttp .onreadystatechange = function()
		{
			if (XMLhttp .readyState == 4)
				{
			   //tblId.removeNode(true);
			   document.forms[0].submit();
			   
        		}

		}
        
        
        }
  
}

   function Dovalidate()
   {
 

   	var valid=true;
   	var errorMsgs ="";
    var formControls = "txtcontactinformation,txtPhyscianName,txtAddress1,txtAddress2,txtAddress3,txtCity,ddlstate,txtZipCode,txtPhone,txtEmergencyPhone,txtEmailAddress,txtFax";
    var currentUrl=document.URL;
    var url = currentUrl.substring(currentUrl.lastIndexOf("/")+1,currentUrl.length).toLowerCase();
    if(url.toLowerCase() == ONLINE_REQUEST_PAGE)
    {
    if(document.getElementById("txtEmailAddress").value=="")
    {
    errorMsgs +="Please enter a Email Address";
    valid=false;
  
    }
    else
    {
    if(!checkValidEmaillAddress(document.getElementById("txtEmailAddress").value))
    {
     	errorMsgs +="Please enter a valid Email Address";
     	valid=false;
    }    
    }    
    }
    else
    { 	
    var  controls= formControls.split(",");
     valid=false;
    for(var count=0; count<controls.length; count++)
    {   
    var control = controls[count];
    validstatus ="";
    var validstatus = containsValue(control)
    if(validstatus == true)	   
	    valid= true;	    	
	}
	
	if(valid == false)
	{
	errorMsgs +="Please enter at least one field";
     	valid=false;
	}		
	}
		
		if(document.getElementById("txtPhone").value != "")
		{		
			   if(!validatePhone(document.getElementById("txtPhone").value,"txtPhone"))
			   {
				   errorMsgs +="Please enter a valid Phone Number <br>";
				   	valid= false;	
			   }				  
		}
		
		if(document.getElementById("txtEmergencyPhone").value != "")
		{
		    if(!validatePhone(document.getElementById("txtEmergencyPhone").value,"txtEmergencyPhone"))
			   {
				   errorMsgs +="Please enter a valid Emergency Phone number <br>";
				   	valid= false;	
			   }
			   		
		   	
		}
		if(document.getElementById("txtFax").value != "")
		{
		 if(!IsNumeric(document.getElementById("txtFax").value))
		   {
		    errorMsgs +="Please Enter a valid Fax number <br>";
		    valid= false;	
		    }
		}
		if(document.getElementById("txtZipCode").value != "")
		{
		 if(!IsNumeric(document.getElementById("txtZipCode").value))
		   {
		    errorMsgs +="Please Enter a valid Zip code <br>";
		    valid= false;	
		    }
		}
	    if(document.getElementById("txtEmailAddress").value != "")
	    {
		 if(!checkValidEmaillAddress(document.getElementById("txtEmailAddress").value))
	    {
	     errorMsgs +="Please Enter a valid Email Address <br>";
		    valid= false;
		    
		}
		}
  		document.getElementById("divErrorDisplay").innerHTML = errorMsgs ;
  		return valid;


	return valid;
	}
	
	function validatePhone(phoneField,controlName)
	{
	var num =phoneField; 
	 num= phoneField.replace(/[^\d]/g,'');
	
	     if(num.length != 10) 
	     {		        //Alert the user that the phone number entered was invalid.
       		return false;                 
	  	 }
    else {
        //Email was valid.  If format type is set, format the Phone to the desired style.

           document.getElementById(controlName).value = "(" + num.substring(0,3) + ")-" + 
            num.substring(3, 6) + "-" + num.substring(6);
            return true;
           }
          
           }


	function checkValidEmaillAddress(EmailAddress) {
     var emailReg = "^[\\w-_\.+]*[\\w-_\.]\@([\\w-]+\\.)+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(EmailAddress);
  }                
  function containsValue(control)
  {
    var controlvalue =  document.getElementById(control).value;
    if(controlvalue != null && controlvalue != "")
    {
    return true;
    }
    return false;
    
  }
function SetCustCookie(name,value,expires,path,domain,secure)
   {
         document.cookie = name + "=" + escape (value) +
            ((expires) ? "; expires=" + expires.toGMTString() : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
      }
      
       function DeleteCustCookie (name,path,domain) {
         if (GetCustCookie (name)) {
            document.cookie = name + "=" +
               ((path) ? "; path=" + path : "") +
               ((domain) ? "; domain=" + domain : "") +
               "; expires=Thu, 01-Jan-70 00:00:01 GMT";
         }
      }      //
 

   
      function GetCustCookie (name)
       {
         var arg = name + "=";
         var alen = arg.length;
         var clen = document.cookie.length;
         var i = 0;
         while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg) {
               return getCookieVal (j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) {
               break;
            }
         }
         return null;
      }
 
    
      function getCookieVal(offset) {
         var endstr = document.cookie.indexOf (";", offset);
         if (endstr == -1) {
            endstr = document.cookie.length;
         }
         return unescape(document.cookie.substring(offset, endstr));
      }
      
      
    function GetInserts(strInserts)
	  {
	  /* if(SPECIALTY_ONCOLOGY==strSpecialty.toUpperCase())
	     {
	      document.getElementById('patientEdu').style.display='none';
	     }
	     else
	     {*/
		   var xmlDoc=loadXML(strInserts); 
		   updateDivWithInserts(xmlDoc );
		   if(cookValue!=null)
		   {
		    SetCheckBoxChecked('chkboxInserts',arrInsertValue);
		    document.getElementById('txtSaveAs').value=strRequestName;
		 // }
	   }
	  
	   
	  }
  
 function CustomizeArticle(articleId)
 {
   document.forms[0].action=CUSTOMIZE_PAGE;
   //SetCustCookie('CustomizeArticle',articleId,'','/','','');
   setCookie("customizeArticle",articleId,null,"/",null,null);
   document.forms[0].submit();
 // updateDivWithItems(articleId,ARTICLE);

 }

 function CustomizeArticleinProductCenter(articleId)
 {
  
    
   document.forms[0].action="../content/"+CUSTOMIZE_PAGE;
  // SetCustCookie('CookArticle2',articleId,'','/','','');
  setCookie("customizeArticle",articleId,null,"/",null,null);

   document.forms[0].submit();
 

 }


 function CustomizeRequestLoad()
	{
	 	
      cookValue=GetCustCookie('PPNRequest');
	  DeleteCustCookie ('PPNRequest','','');
	  var customizeArticleID= getCookie('customizeArticle');
	  DeleteCustCookie("customizeArticle","/",null);
	  
	  if(cookValue!='' && cookValue!=null )
	  {
	     document.getElementById('divSelectArticle').style.display='none';
	     document.getElementById('btnMaterial').className="addMaterialBtn";

	     var url = document.location.href;//"http://saldtp061777:9002/pages/customizepatient.aspx";
		  url = url + "?CustReq="+cookValue;
		  isCustRequest=true;
		  var xmlHttp = getHTTPObject();
          xmlHttp .open("GET", url, true);
		  xmlHttp .send(null); 
		 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	        	{
	                strOutput = xmlHttp.responseText.substring(13,xmlHttp.responseText.indexOf('</ResponseXml>'));       
	          		SetCustomizeRequest(strOutput );
	                  
	             }
		  xmlHttp .onreadystatechange = function()
			{
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	        	{
	                strOutput = xmlHttp.responseText.substring(13,xmlHttp.responseText.indexOf('</ResponseXml>'));       
	          		SetCustomizeRequest(strOutput );
	                  
	             }
			}
 	     }
 	     
 	     else if(customizeArticleID!='' && customizeArticleID!=null)//when customize link is selected
 	     {
 	      var arrCustArt= customizeArticleID.split(';');
          if(arrCustArt.length>1)
            {
              customizeArticleID=arrCustArt[0];//gets the article id
              var arrType=arrCustArt[1].split('='); //identifies product or condition
               if(arrType.length>0)
                 {
                   if(arrType[0]=="Product")
                     {
                       document.getElementById('ddlProducts').value=arrType[1];
                        GetProduct('ddlProducts','ddlCondition');
                        /* for(var i=0;i<document.getElementById('ddlProducts').length;i++)
                            {
                             if(arrType[1]==document.getElementById('ddlProducts').options[i].text)
                               {
                                document.getElementById('ddlProducts').value=arrType[1];
                                }
                             }*/
                                    
                             
                           }
                       else if(arrType[0]=="Condition")
                        {
                         document.getElementById('ddlCondition').value=arrType[1];
                         GetCondition('ddlProducts','ddlCondition');
                        }
                     }
                   }
                                
                   else
                    {
                      updateDivWithItems(customizeArticleID,ARTICLE);
                    }
                        
                  document.getElementById('divChkBoxContent').style.display='block';
                  document.getElementById('divSelectArticle').style.display='none';

                  document.getElementById('btnMaterial').className="addMaterialBtn";
                  SetCheckBoxChecked('chkPatEdu',customizeArticleID);

           }
 	 
}
      
     function doAction(ctlId)
     {
      var btnType= document.getElementById(ctlId);
      if(btnType.className=="addMaterialBtn")
      {
       btnType.className="closedBtn";
       document.getElementById('divSelectArticle').style.display='block';
       return;

      }
      if(btnType.className=="closedBtn")
      {
       btnType.className="addMaterialBtn";
       document.getElementById('divSelectArticle').style.display='none';
       document.getElementById('divChkBoxContent').style.display='block';
       return;


      }

     }
      
      
 //.............................Contact Information methods.............................................................
 

   var ContactInformationRecodords;   
   var ContactInformationRecodord1=null;   
	var ContactInformationRecodord2=null;
	var ContactInformationRecodord3=null;
	//var Contactinformationselected = null;
	var Action;
	var IsRecordPresent;
	var ContactInformation;
	
function SendSessionValues(RecordPresent, ContactInformationDetails)
{

IsRecordPresent ="";
IsRecordPresent =RecordPresent;
ContactInformation ="";
ContactInformation =ContactInformationDetails;
}
      
function CheckStatus()
		{
		
		
//		var IsRecordPresent
	//	IsRecordPresent= "[SESSION:IsRecordPresent]"
		if(Action == "strOutput")
		{
		IsRecordPresent="";
		IsRecordPresent= strOutput .substring(strOutput.indexOf('<IsRecordPresent>')+17,strOutput.indexOf('</IsRecordPresent>')); 
		}   
		
		
		if(IsRecordPresent == "False")
		{
		//DisplayContactInformation(1);
		document.getElementById("rdoContactInfo1").checked = true;
		document.getElementById("rdoContactInfo1").checked = "checked";

		}
		else
		{
		
		//var ContactInformation =""
		 
		ContactInformationRecodords =""; 
		ContactInformationRecodord1 = "";
		ContactInformationRecodord2 ="";
		ContactInformationRecodord3 = "";
		if(Action != "strOutput")
		{
		//ContactInformation ="[SESSION:ContactInformationRecord]"
		//var ContactInformationSelected ="[SESSION:ContactInformationRecordSelected]";
		}
		else
		{
		var contactDetails =strOutput.split("(*&^%$#@!}]"); 
		ContactInformation =contactDetails[0];
		}
		ContactInformationRecodords =ContactInformation.split("(*&^%$/%#"); 
		ContactInformationRecodord1 = ContactInformationRecodords[0];
		ContactInformationRecodord2 = ContactInformationRecodords[1];
		ContactInformationRecodord3 = ContactInformationRecodords[2];
				
		if(ContactInformationRecodord1 != "" && ContactInformationRecodord1 != null)
		{
		document.getElementById("btnadd1").style.display ="none";
		document.getElementById("btnedit1").style.display ="block";
		}
		if(ContactInformationRecodord2 != "" && ContactInformationRecodord2 != null)
		{
		document.getElementById("btnadd2").style.display ="none";
		document.getElementById("btnedit2").style.display ="block";
		}
		if(ContactInformationRecodord3 != "" && ContactInformationRecodord3 != null)
		{
		document.getElementById("btnadd3").style.display ="none";
		document.getElementById("btnedit3").style.display ="block";		
		}
		
		if(Action != "strOutput")
		{
		if(cookValue==null ||cookValue=="" )
		{
		//GetContactDetails("1");
		UpdateControls(ContactInformationRecodord1,1);
		document.getElementById("rdoContactInfo1").checked = true;
		document.getElementById("rdoContactInfo1").checked = "checked";
	
		}
		}
		else
		{
		var selectInfo =GetSelectedContactinfo(); 
		GetContactDetails(selectInfo );		
		}		
		}
		}
		




function GetContactDetails(ContactSelected)
{
switch(ContactSelected) 
{
case '1':
{
DisplayContactInformation(1)
break;
}
case '2':
{
DisplayContactInformation(2)
break;
}
case '3':
{
DisplayContactInformation(3)
break;
}
}

}

function UpdateControls(ContactInformationRecord,contactinformationType)
{
//
if(ContactInformationRecord != null)
{
	var arrEnties = ContactInformationRecord.split("%$#@!");
	for(var count=0;count<=arrEnties.length;count++)
	{
		if(arrEnties[count])
		{
			var arrValues = arrEnties[count].split("===");
			var Control = arrValues[0];
			var ControlValue = arrValues[1];			
			switch(Control)
			{
			case "ContactInformation" :
			{
			document.getElementById("txtcontactinformation").value = ControlValue ;
			document.getElementById("displayContactInformation").innerHTML = ControlValue ;
			glbContactInformation ="";
			glbContactInformation = ControlValue;
			break;
			}
			case "PhyscianName" :
			{			
			document.getElementById("txtPhyscianName").value = ControlValue ;
			document.getElementById("displayPhyscianName").innerHTML = ControlValue ;
			glbPhysicianName ="";
			glbPhysicianName = ControlValue ;
			break;
			}
			case "Address1" :
			{			
			document.getElementById("txtAddress1").value = ControlValue ;
			document.getElementById("displayAddress1").innerHTML = ControlValue ;
			glbAddress1="";
			glbAddress1=ControlValue;
			
			break;
			}
			case "Address2" :
			{
			document.getElementById("txtAddress2").value = ControlValue ;
			document.getElementById("displayAddress2").innerHTML = ControlValue ;
			glbAddress2="";
			glbAddress2=ControlValue;

			break;
			}
			case "Address3" :
			{
			document.getElementById("txtAddress3").value = ControlValue ;
			document.getElementById("displayAddress3").innerHTML = ControlValue ;
			glbAddress3="";
			glbAddress3=ControlValue;
			break;
			}
			case "City" :
			{
			document.getElementById("txtCity").value = ControlValue ;
			document.getElementById("displayCity").innerHTML = ControlValue ;
			glbCity="";
			glbCity = ControlValue;
			break;
			}
			case "State" :
			{
			document.getElementById("ddlstate").value = ControlValue ;
			document.getElementById("displayState").innerHTML = ControlValue ;
			glbState="";
			glbState=ControlValue;
			break;
			}
			case "Zip" :
			{
			document.getElementById("txtZipCode").value = ControlValue ;
			document.getElementById("displayZip").innerHTML = ControlValue ;
			glbZipCode="";
			glbZipCode=ControlValue;
			break;
			}
			case "Phone" :
			{
			document.getElementById("txtPhone").value = ControlValue ;
			document.getElementById("displayPhone").innerHTML = ControlValue ;
			glbPhone="";
			glbPhone=ControlValue;

			break;
			}
			case "EmergencyPhone" :
			{
			document.getElementById("txtEmergencyPhone").value = ControlValue ;
			document.getElementById("displayEmergencyPhone").innerHTML = ControlValue ;
			glbEmergencyPhone="";
			glbEmergencyPhone=ControlValue;

			break;
			}
			case "Email" :
			{
			document.getElementById("txtEmailAddress").value = ControlValue ;
			document.getElementById("displayEmailAddress").innerHTML =getDisplayValue(ControlValue) ;
 
			glbEmail="";
			glbEmail=ControlValue;

			break;
			}
			
			case "Fax" :
			{
			document.getElementById("txtFax").value = ControlValue ;
			document.getElementById("displayFax").innerHTML = ControlValue ;
			glbFax="";
			glbFax=ControlValue;

			break;
			}
			case "ContactInformationType" :
			{
			document.getElementById("hdnContactInformationType").value = ControlValue ;			
			break;
			}
			case "IsContactInformationSelected" :
			{
			document.getElementById("hdnIsContactInformationSelected").value = ControlValue ;			
			break;
			}			
			case "ImagePath" :
			{
			//
			//http://saldtp072327:2009/SiteCollectionImages/01105B4E-DED8-462C-9324-EE5B0FCDEB9E.gif
			if(ControlValue != "" && ControlValue != null)
			{
			
			document.getElementById("imgText").src="";
			document.getElementById("imgDisplay").src="";
			document.getElementById("imgText").src= "../../../"+ControlValue;	
			document.getElementById("imgDisplay").src="../../../"+ControlValue;
			glbImagePath="";
			glbImagePath.length=0;
			glbImagePath= "../../../"+ControlValue;
			}	
			else
			{
			document.getElementById("imgText").src="../../SiteCollectionImages/sampleImg.gif";
			document.getElementById("imgDisplay").src="../../SiteCollectionImages/sampleImg.gif";
			glbImagePath="../../SiteCollectionImages/sampleImg.gif";

			}		
			break;
			}
			
		}	
		}	
	}
	
	}
}



function EditContactInformation()
{
ResetTextControls();

if((document.getElementById("rdoContactInfo1").checked == true) || strContactInfoSelected ==1)
{
document.getElementById("divContactInformationForm1").innerHTML="";
document.getElementById("divContactInformationForm1").innerHTML= document.getElementById("displayText").innerHTML;
document.getElementById("ContactinfoDescription1").style.display = "none";
document.getElementById("divContactInformationForm1").style.display = "block";
//document.getElementById("divradio1").style.display = "block";

}
else if((document.getElementById("rdoContactInfo2").checked == true) || strContactInfoSelected == 2)

{
document.getElementById("divContactInformationForm2").innerHTML ="";
document.getElementById("divContactInformationForm2").innerHTML = document.getElementById("displayText").innerHTML;
document.getElementById("ContactinfoDescription2").style.display = "none";
document.getElementById("divContactInformationForm2").style.display = "block";

}
else if((document.getElementById("rdoContactInfo3").checked == true) || strContactInfoSelected ==3)

{
document.getElementById("divContactInformationForm3").innerHTML ="";
document.getElementById("divContactInformationForm3").innerHTML = document.getElementById("displayText").innerHTML;
document.getElementById("ContactinfoDescription3").style.display = "none";
document.getElementById("divContactInformationForm3").style.display = "block";
}

document.getElementById("txtcontactinformation").value =document.getElementById("displayContactInformation").innerHTML;
document.getElementById("txtPhyscianName").value = document.getElementById("displayPhyscianName").innerHTML;
document.getElementById("txtAddress1").value = document.getElementById("displayAddress1").innerHTML ;
document.getElementById("txtAddress2").value = document.getElementById("displayAddress2").innerHTML;
document.getElementById("txtAddress3").value =document.getElementById("displayAddress3").innerHTML;
document.getElementById("txtCity").value =document.getElementById("displayCity").innerHTML;
document.getElementById("ddlstate").value = document.getElementById("displayState").innerHTML;
document.getElementById("txtZipCode").value =document.getElementById("displayZip").innerHTML;
document.getElementById("txtPhone").value = document.getElementById("displayPhone").innerHTML;
document.getElementById("txtEmergencyPhone").value =document.getElementById("displayEmergencyPhone").innerHTML;
document.getElementById("txtEmailAddress").value = getTextValue(document.getElementById("displayEmailAddress").innerHTML);
document.getElementById("txtFax").value = document.getElementById("displayFax").innerHTML;
imgCount++;
if(	glbImagePath != "")	 
document.getElementById("imgText").src=glbImagePath+"?"+imgCount;

document.getElementById("divSave").style.display = "none";
document.getElementById("divUpdate").style.display = "block";


}

//This method will remove the <br> from the email address
function getTextValue(value)
{

var replaceText = value.replace(/<BR>/g, "<br>");
var intIndexOfMatch = replaceText.indexOf('<br>');
while (intIndexOfMatch != -1)
{
replaceText = replaceText.replace('<br>','')
intIndexOfMatch = replaceText.indexOf('<br>');
}
return replaceText;
}



function UpdateView()
{

	CheckStatus();
	ResetDisplayControls();
	ResetTextControls();
	
	if((document.getElementById("rdoContactInfo1").checked == true) || strContactInfoSelected ==1)
	{
		UpdateControls(ContactInformationRecodord1 ,1);			
		document.getElementById("divContactInformationForm1").innerHTML="";
		document.getElementById("divContactInformationForm1").innerHTML = document.getElementById("displayLabel").innerHTML;
		document.getElementById("divContactInformationForm1").style.display = "block";
		document.getElementById("ContactinfoDescription1").style.display = "none";
		AssingDisplayValues();
				
	}
	else if((document.getElementById("rdoContactInfo2").checked == true) || strContactInfoSelected ==2)
	{
		UpdateControls(ContactInformationRecodord2 ,2);		
		document.getElementById("divContactInformationForm2").innerHTML="";
		document.getElementById("divContactInformationForm2").innerHTML = document.getElementById("displayLabel").innerHTML;
		document.getElementById("divContactInformationForm2").style.display = "block";
		document.getElementById("ContactinfoDescription2").style.display = "none";
		AssingDisplayValues();
	
	}
	else if((document.getElementById("rdoContactInfo3").checked == true) || strContactInfoSelected ==3)
	{
		UpdateControls(ContactInformationRecodord3 ,3);		
		document.getElementById("divContactInformationForm3").innerHTML="";
		document.getElementById("divContactInformationForm3").innerHTML = document.getElementById("displayLabel").innerHTML;
		document.getElementById("divContactInformationForm3").style.display = "block";
		document.getElementById("ContactinfoDescription3").style.display = "none";
		AssingDisplayValues();
		
		
	}
}

 function AssingDisplayValues()
	{
	
		document.getElementById("displayContactInformation").value = document.getElementById("txtcontactinformation").value ;
		document.getElementById("displayPhyscianName").value = document.getElementById("txtPhyscianName").value;
		document.getElementById("displayAddress1").value = document.getElementById("txtAddress1").value;
		document.getElementById("displayAddress2").value = document.getElementById("txtAddress2").value;
		document.getElementById("displayAddress3").value = document.getElementById("txtAddress3").value ;
		document.getElementById("displayCity").value =document.getElementById("txtCity").value;
		document.getElementById("displayState").value =document.getElementById("ddlstate").value ;
		document.getElementById("displayZip").value = document.getElementById("txtZipCode").value ;
		document.getElementById("displayPhone").value = document.getElementById("txtPhone").value ;
		document.getElementById("displayEmergencyPhone").value = document.getElementById("txtEmergencyPhone").value ;		
		document.getElementById("displayFax").value = document.getElementById("txtFax").value ;
		document.getElementById("divSave").style.display = "none";
		document.getElementById("divUpdate").style.display = "block";
		document.getElementById("displayEmailAddress").value =document.getElementById("txtEmailAddress").value ;
		imgCount++
		if(	glbImagePath != "")	 
		document.getElementById("imgDisplay").src=glbImagePath +"?"+imgCount;
		

	}

//This method will add <br> if the lenght is more than 20 char
function getDisplayValue(value)
{

 	var nameLength= value.length;
	var request='';
    for (j=0;j<=nameLength;j++)
   	{
   	if (j%20==0 && j!=0)
      {
		request+=value.charAt(j)+'<br>';
      }
    else
    {
		request+=value.charAt(j);
     }
 }
 return request;

}

function DisplayContactInformation(contactinformationType)
{


			switch(contactinformationType) 
			{
			case 1 :
			{
			
			if(ContactInformationRecodord1 != "" && ContactInformationRecodord1 != null)
			{
			document.getElementById("divContactInformationForm2").innerHTML = "";
			document.getElementById("divContactInformationForm3").innerHTML = "";
			
			UpdateControls(ContactInformationRecodord1,1);
			
			//To refresh the image control with the updated image
			imgCount++;
			if(	glbImagePath != "")	 
			document.getElementById("imgDisplay").src=glbImagePath+"?"+imgCount;	
			
			document.getElementById("divContactInformationForm1").innerHTML = document.getElementById("displayLabel").innerHTML
			document.getElementById("divUpdate").style.display = "block";
			document.getElementById("divSave").style.display = "none";
			document.getElementById("rdoContactInfo1").checked = true;
			document.getElementById("displayradio").innerHTML= document.getElementById("divradio1").innerHTML;
			document.getElementById("divradio1").style.display = "none";
			document.getElementById("ContactinfoDescription1").style.display = "none";
			}
			else
			{
			ResetTextControls();
			ResetDisplayControls();
			glbEmail="";
			document.getElementById("imgText").src = "../../SiteCollectionImages/sampleImg.gif";
			document.getElementById("divContactInformationForm2").innerHTML = "";
			document.getElementById("divContactInformationForm3").innerHTML = "";
			document.getElementById("divContactInformationForm1").innerHTML = document.getElementById("displayText").innerHTML
			document.getElementById("divSave").style.display = "block";
			document.getElementById("divUpdate").style.display = "none";
			document.getElementById("ContactinfoDescription1").style.display = "none";
			}
			document.getElementById("btnAddContactInfo1").style.display="none"
			document.getElementById("btnAddContactInfo2").style.display="block"
			document.getElementById("btnAddContactInfo3").style.display="block"
			document.getElementById("divContactInformationForm2").style.display="none";
			document.getElementById("divContactInformationForm3").style.display="none";
			document.getElementById("divContactInformationForm1").style.display="block";
			document.getElementById("divradio2").style.display = "block";
			document.getElementById("ContactinfoDescription2").style.display = "block";
			document.getElementById("divradio3").style.display = "block";
			document.getElementById("ContactinfoDescription3").style.display = "block";
	
			document.getElementById("rdoContactInfo1").checked = true;
			document.getElementById("rdoContactInfo1").checked = "checked";
			strContactInfoSelected ="";
			strContactInfoSelected =1;
			break;
			}
			case 2 :
			{
			
			document.getElementById("rdoContactInfo2").checked = true;
			document.getElementById("rdoContactInfo2").checked="checked";
			
			if(ContactInformationRecodord2 != "" && ContactInformationRecodord2 != null)
			{
			document.getElementById("divContactInformationForm1").innerHTML = "";
			document.getElementById("divContactInformationForm3").innerHTML = "";
			UpdateControls(ContactInformationRecodord2 ,2)
			
			//To refresh the image control with the updated image
			imgCount++;
			if(	glbImagePath != "")	 
			document.getElementById("imgDisplay").src=glbImagePath+"?"+imgCount;	
			
			document.getElementById("divContactInformationForm2").innerHTML = document.getElementById("displayLabel").innerHTML
			document.getElementById("displayradio").innerHTML= document.getElementById("divradio2").innerHTML;
			document.getElementById("divradio2").style.display = "none";
			document.getElementById("btnadd2").style.display ="none";
			//document.getElementById("btnedit2").style.display ="block";
			document.getElementById("ContactinfoDescription2").style.display = "none";
			
			}
			else
			{
			document.getElementById("divContactInformationForm1").innerHTML = "";
			document.getElementById("divContactInformationForm3").innerHTML = "";
			ResetTextControls();
			ResetDisplayControls();
			glbEmail="";
			document.getElementById("imgText").src = "../../SiteCollectionImages/sampleImg.gif";
			document.getElementById("divContactInformationForm2").innerHTML = document.getElementById("displayText").innerHTML
			document.getElementById("divSave").style.display = "block";
			document.getElementById("divUpdate").style.display = "none";
			document.getElementById("ContactinfoDescription2").style.display = "none";
			}
			document.getElementById("btnAddContactInfo2").style.display="none"
			document.getElementById("btnAddContactInfo1").style.display="block"
			document.getElementById("btnAddContactInfo3").style.display="block"
			document.getElementById("divContactInformationForm2").style.display="block";
			document.getElementById("divContactInformationForm1").style.display="none";
			document.getElementById("divContactInformationForm3").style.display="none";
			document.getElementById("divradio1").style.display = "block";
			document.getElementById("ContactinfoDescription1").style.display = "block";
			document.getElementById("divradio3").style.display = "block";
			document.getElementById("ContactinfoDescription3").style.display = "block";
		
			document.getElementById("rdoContactInfo2").checked = true;
			document.getElementById("rdoContactInfo2").checked = "checked";
			strContactInfoSelected ="";
			strContactInfoSelected =2;
			
			break;
			}
			case 3 :
			{
			
			document.getElementById("rdoContactInfo3").checked = true;
			document.getElementById("rdoContactInfo3").checked="checked";
		
			if(ContactInformationRecodord3 != "" && ContactInformationRecodord3 != null)
			{
			document.getElementById("divContactInformationForm1").innerHTML = "";
			document.getElementById("divContactInformationForm2").innerHTML = "";
			UpdateControls(ContactInformationRecodord3 ,3)
			
			//To refresh the image control with the updated image
			imgCount++;
			if(	glbImagePath != "")	 
			document.getElementById("imgDisplay").src=glbImagePath+"?"+imgCount;	
			
			document.getElementById("divContactInformationForm3").innerHTML = document.getElementById("displayLabel").innerHTML
			document.getElementById("ContactinfoDescription3").style.display = "none";
			
			document.getElementById("displayradio").innerHTML= document.getElementById("divradio3").innerHTML;
			document.getElementById("divradio3").style.display = "none";
			
			}
			else
			{
			ResetTextControls();
			ResetDisplayControls();
			glbEmail="";
			document.getElementById("imgText").src = "../../SiteCollectionImages/sampleImg.gif";
			document.getElementById("divContactInformationForm1").innerHTML = "";
			document.getElementById("divContactInformationForm2").innerHTML = "";
			document.getElementById("divContactInformationForm3").innerHTML = document.getElementById("displayText").innerHTML
			document.getElementById("divSave").style.display = "block";
			document.getElementById("divUpdate").style.display = "none"
			document.getElementById("ContactinfoDescription3").style.display = "none";
			
			}
			document.getElementById("btnAddContactInfo3").style.display="none"
			document.getElementById("btnAddContactInfo2").style.display="block"
			document.getElementById("btnAddContactInfo1").style.display="block"
			
			document.getElementById("divContactInformationForm1").style.display="none";
			document.getElementById("divContactInformationForm2").style.display="none";
			document.getElementById("divContactInformationForm3").style.display="block";
			document.getElementById("divradio1").style.display = "block";
			document.getElementById("ContactinfoDescription1").style.display = "block";
			document.getElementById("divradio2").style.display = "block";
			document.getElementById("ContactinfoDescription2").style.display = "block";
		
			document.getElementById("rdoContactInfo3").checked = true;
			document.getElementById("rdoContactInfo3").checked = "checked";
			strContactInfoSelected ="";
			strContactInfoSelected =3;
			
			break;
			}
			}
			}

 

 function ResetTextControls()
	{
	
		document.getElementById("txtcontactinformation").value = "" ;
		document.getElementById("txtPhyscianName").value = "";		
		document.getElementById("txtAddress1").value = "";		
		document.getElementById("txtAddress2").value = "";		
		document.getElementById("txtAddress3").value = "";		
		document.getElementById("txtCity").value = "";
		document.getElementById("ddlstate").value = "";
		document.getElementById("txtZipCode").value = "";
		document.getElementById("txtPhone").value = "";
		document.getElementById("txtEmergencyPhone").value = "";
		document.getElementById("txtEmailAddress").value = "";
		document.getElementById("txtFax").value = "";
		
	}

 function ResetDisplayControls()
	{


		document.getElementById("displayContactInformation").innerHTML = "" ;
		document.getElementById("displayPhyscianName").innerHTML = "";
		document.getElementById("displayAddress1").innerHTML = "";
		document.getElementById("displayAddress2").innerHTML = "";
		document.getElementById("displayAddress3").innerHTML = "";
		document.getElementById("displayCity").innerHTML = "";
		document.getElementById("displayState").innerHTML = "";
		document.getElementById("displayZip").innerHTML = "";
		document.getElementById("displayPhone").innerHTML = "";
		document.getElementById("displayEmergencyPhone").innerHTML = "";
		document.getElementById("displayEmailAddress").innerHTML = "";
		document.getElementById("displayFax").innerHTML = "";
	}

function submitContactInformation()
{

var valid = Dovalidate()
if(valid ==true)
GetContactInfo("Save");

}

var popWindow = null;
function CheckImageUploaded()
{
   var contactInformationType = GetSelectedContactinfo();
   createCookie("InternalUserId",strUserId);//"01105B4E-DED8-462C-9324-EE5B0FCDEB9E");
   createCookie("ContactInformationType",contactInformationType);   
   var params = 'width=400,height=400,scrollbars,resizable';
   var strUrl = 'file_uploader.aspx';
   if(popWindow && !popWindow.closed)
    popWindow.focus();
   else
    popWindow = window.open(strUrl,'file_uploader',params); 
}


function UpdateContactInformation()
{

var valid = Dovalidate();
if(valid ==true)
GetContactInfo("Update");


}

function GetContactInfo(Operation)
{  

	var imagePath="";
	var internaluserid=strUserId; // "01105B4E-DED8-462C-9324-EE5B0FCDEB9E";
	var contactInfoType = GetSelectedContactinfo();	
	if(GetCustCookie("ImageUrl")!=null)
	imagePath =GetCustCookie ("ImageUrl");	
	var strSendXml="ContactInformation="+document.getElementById('txtcontactinformation').value+"&PhyscianName="+document.getElementById('txtPhyscianName').value+"&Address1="+document.getElementById('txtAddress1').value+"&Address2="+document.getElementById('txtAddress2').value+"&Address3="+document.getElementById('txtAddress3').value+"&City="+document.getElementById('txtCity').value+"&State="+document.getElementById('ddlstate').value+"&Zip="+document.getElementById('txtZipCode').value+"&Phone="+document.getElementById('txtPhone').value+"&EmergencyPhone="+document.getElementById('txtEmergencyPhone').value+"&Email="+document.getElementById('txtEmailAddress').value+"&Fax="+document.getElementById('txtFax').value+"&InternalUserId="+internaluserid+"&ContactInformationType="+contactInfoType +"&IsContactInformationSelected=True"+"&ImagePath="+imagePath; 

	var url = document.location.href;//"http://saldtp061777:9002/pages/customizepatient.aspx";
	 url = url + "?op="+Operation;
	 xmlHttp = GetXmlHttpObject(updateStateChanged);
	 xmlHttpPost(xmlHttp, url,strSendXml);	
	 document.getElementById("divWaitMessage").style.display ="block";
	 Action = "strOutput";
}

    function xmlHttpPost(xmlhttp, url,sendXml) 
    { 
        xmlhttp.open('POST', url, true); 
        xmlhttp.send(sendXml); 
    } 
    var strOutput;
    function updateStateChanged()
    {   

        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
         strOutput = xmlHttp.responseText.substring(13,xmlHttp.responseText.indexOf('</ResponseXml>'));              
        
        // eraseCookie("InternalUserId");
        // eraseCookie("ContactInformationType");
        // eraseCookie("ImageUrl");          
		DeleteCustCookie("InternalUserId");		
		DeleteCustCookie("ContactInformationType");
		DeleteCustCookie("ImageUrl");     
         UpdateView();
       
        }
    }
    
    function GetXmlHttpObject(handler)
    { 
    
      var objXmlHttp=null
      if (navigator.userAgent.indexOf("Opera")>=0)
      {
            alert("This example doesn't work in Opera");
            return 
      }
      if (navigator.userAgent.indexOf("MSIE")>=0)
      { 
            var strName="Msxml2.XMLHTTP";
            if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
            {
                strName="Microsoft.XMLHTTP";
            } 
            try
            { 
                objXmlHttp=new ActiveXObject(strName);
                objXmlHttp.onreadystatechange=handler ;
                return objXmlHttp;
            } 
            catch(e)
            { 
                alert("Error. Scripting for ActiveX might be disabled") 
                return 
            } 
      } 
      if (navigator.userAgent.indexOf("Mozilla")>=0)
      {
            objXmlHttp=new XMLHttpRequest();
            objXmlHttp.onload=handler;
            objXmlHttp.onerror=handler; 
            return objXmlHttp;
      }
    }
    
  
    
function CloseContactInformation()
{

	Contactinformationselected = GetSelectedContactinfo();
	if(Contactinformationselected == 1 || strContactInfoSelected == 1)
	{
		document.getElementById("divContactInformationForm1").style.display="none";
		document.getElementById("divradio1").style.display = "block";
		document.getElementById("ContactinfoDescription1").style.display = "block";
		if(ContactInformationRecodord1 == "" || ContactInformationRecodord1 == null)
		{
		document.getElementById("btnadd1").style.display ="block";
		document.getElementById("btnAddContactInfo1").style.display ="block";
		}

	
	}
	else if(Contactinformationselected == 2 || strContactInfoSelected == 2)
	{
		document.getElementById("divContactInformationForm2").style.display="none";
		document.getElementById("divradio2").style.display = "block";
		document.getElementById("ContactinfoDescription2").style.display = "block";
		if(ContactInformationRecodord2 == "" || ContactInformationRecodord2 == null)
		{
			document.getElementById("btnadd2").style.display ="block";
		document.getElementById("btnAddContactInfo2").style.display ="block";

		}

	
	}
	else if(Contactinformationselected == 3 || strContactInfoSelected == 3)
	{
		document.getElementById("divContactInformationForm3").style.display="none";
		document.getElementById("divradio3").style.display = "block";
		document.getElementById("ContactinfoDescription3").style.display = "block";
		if(ContactInformationRecodord3 == "" || ContactInformationRecodord3 == null)
		{
			document.getElementById("btnadd3").style.display ="block";
		document.getElementById("btnAddContactInfo3").style.display ="block";

		}

	
	}


}
      
//..........................Online Request Form Code starts here................................................
  
	 function PopulateCategory(ctrlId,strCategory)
	{
	   var arrCategory= strCategory.split('~');
        for(j=0;j<arrCategory.length;j++)
        {
    	   // addOptions(ctrlId,arrCategory[j],arrCategory[j]);
    	  var divOption= appendDivInOnlineRequest(ctrlId,arrCategory[j]);
          divOption.onclick=GetTypeList;
        }     
        	   
	}
	
	function appendDivInOnlineRequest(ddlSelectId,text)
     {
        var ddlSelect = document.getElementById(ddlSelectId);
        var divOption = document.createElement('div');
       
        divOption.innerHTML = text;
        ddlSelect.appendChild(divOption); 
        return divOption ;
     }

	
	function GetListData(strType,strArt)
	{
	 arrReqType= strType.split('~');
     //xmlArtDoc=new ActiveXObject("Microsoft.XMLDOM");
 	 //xmlArtDoc.async="false";
  	// xmlArtDoc.loadXML(strArt);
  	 
  	 xmlArtDoc=loadXML(strArt);
  	
	}
	
   function GetTypeList()//ctrlId,typeCtrlId,itemCtrlId)
	  {
	      var ctrlId="lstCategory";
	      var typeCtrlId="lstType";
	      var itemCtrlId="lstItems";
	
	      strSelectCat= this.innerHTML;
	      ChangeSelectedColorDIV(ctrlId,this,strSelectCat);    
	      if(xmlArtDoc!= null && strSelectCat!="")
	        {
	         
	           document.getElementById(typeCtrlId).innerHTML="";
	           document.getElementById(itemCtrlId).innerHTML="";
	           SetValuesToControls(xmlArtDoc,typeCtrlId,strSelectCat,'');
	           
	    	 }
	 }
	 
 function ChangeSelectedColorDIV(divSelect,ctrlId,strSelectValue)
   {
       
     for(i=0;i<document.getElementById(divSelect).childNodes.length;i++)
	  {
	    if(document.getElementById(divSelect).childNodes[i].innerHTML==strSelectValue)
		 {		
		  ctrlId.className = 'navigationListSelected';
		 }
	    else
	      document.getElementById(divSelect).childNodes[i].className = '';
      }
    
   }	
	
  /* function ChangeSelectedColor(ctrlId,strSelectValue)
   {
      
     for(i=0;i<document.getElementById(ctrlId).length;i++)
	  {
	   if(document.getElementById(ctrlId).options[i].value==strSelectValue)
		{
		
		document.getElementById(ctrlId).options[document.getElementById(ctrlId).selectedIndex].className = 'navigationListSelected';
		document.getElementById(ctrlId).selectedIndex=-1;
		
		}
	   else
	   document.getElementById(ctrlId).options[i].className = '';
 
	  }

    
   }	*/
 

    function GetItemList()//catCtrlId,typCtrlId,itemCtrlId)
    {
      var catCtrlId ="lstCategory";
      var typCtrlId="lstType";
	  var itemCtrlId="lstItems";
	
      var strSelectType= this.innerHTML;;
      ChangeSelectedColorDIV(typCtrlId,this,strSelectType); 
      //var strSelectCat= document.getElementById(catCtrlId).value;
       document.getElementById(itemCtrlId).innerHTML="";
       //document.getElementById('divReqPreview').innerHTML="";

      SetValuesToControls(xmlArtDoc,itemCtrlId,strSelectCat,strSelectType);
     
     
    }

    function SetValuesToControls(xmlArtDoc,CtrlId,strSelectCat,strSelectType)
    {
      	
      	var j=0;
        var node =  node = SelecteNodesInXML(xmlArtDoc,'Item');
        var arrType=new Array();
        if(node != null)
        {
        	 var id="";
	         var article="";
	         var category ="";
	         var type="";
	         var link="";

	         if(node.length>0)
	           {
	             
	             for (var i=0;i<node.length;i++)
		           {               
		             id=getNodeValue(node,i,0); 
			         article= getNodeValue(node,i,1); 
		             category =getNodeValue(node,i,2); 
		             type= getNodeValue(node,i,3);
		             link= getNodeValue(node,i,4);
                     
		              
		             if(strSelectType!=null && strSelectType!='')
		             {
		             	 if(category ==strSelectCat && strSelectType== type)
		             	 {
		             	  createCheckbox(id,article,category ,type,trim(link),CtrlId);
		             	 }

		             }
		             else if(category ==strSelectCat )
		               {
		                arrType[j]=type;
		                j++;
		               }
		               
		             		               
		            }
		           if(strSelectType==null || strSelectType=='')
		            {
		            setTypeToLstBox(arrReqType,arrType,CtrlId);//to fill type listbox for type
		            }
	            }
	         }        
    } 
    
    function createCheckbox(artId,article,cat,type,link,CtrlId)
    {
      var divChk=document.createElement('div');
      var setChecked="";
       if(checkArticleIsPresentinOnlineReq(artId))
       setChecked="checked" ;
             
      var strchk="<input type='checkbox' "+setChecked+" name='chkItems' id='chkItem"+artId+"' value='"+artId+"' onclick=\"SetPreviewRequestToDiv(this,'lbl"+artId+"','"+cat+"','"+type+"','"+link+"')\"><label id='lbl"+artId+"' style=\"MARGIN-TOP: 2px\">"+article+"</label>";
      divChk.innerHTML=strchk;
      
      document.getElementById(CtrlId).appendChild(divChk);
    }

	/*function clearlistbox(id)
	{
	   var lb=document.getElementById(id);
  		for (var i=lb.options.length-1; i>=0; i--)
  		{
    	lb.options[i] = null;
  		}
  		lb.selectedIndex = -1;
	}*/


 function setTypeToLstBox(arrRqType,arrType,typeCtrlId)
	{
	  if(arrType!=null && arrType!="")
	   {
	    for (var j=0;j<arrRqType.length;j++)
		{
	    for (var i=0;i<arrType.length;i++)
		  {	
		     if(arrType[i]==arrRqType[j])
		       {
		        var divOption=appendDivInOnlineRequest(typeCtrlId,arrRqType[j]);
                divOption.onclick=GetItemList;
		         break;
		       }
		    }

		      
		  }
	  
	}
   }
  
  
function SetPreviewRequestToDiv(chkId,lblId,cat,type,link)
{
 var artId="";
 
 if(chkId!=null)
 {
  artId=chkId.value;
  if(chkId.checked)
  {
  AddPreviewDetails(artId,cat,lblId,'',type,link,chkId)
   
  }
 else
  {
    DeleteData(artId,chkId.id);
  }
        
}        
}

function AddPreviewDetails(artId,cat,lblId,article,type,link,chkId)
{

	var cId='';
	if(artId!="" && artId!=null)
	{
	 if(!checkArticleIsPresentinOnlineReq(artId))
	 {
	 
		 if(chkId!=null)
		 {
		  cId=chkId.id;
		  
		 }
		 var divPreview=document.createElement('div');
		 divPreview.id="div"+artId;
		 if(lblId!='')
		 article=document.getElementById(lblId).innerHTML;
		 
		 var strDiv="<table id=tblRequestPreview"+artId+" width='100%'><tr><td width='15%'>"+cat+
			           "</td>"+
				       "<td width='20%'>"+type+"</td>"+
				        "<td width='40%'><a name=aLink href=javascript:openNewWindow('"+escape(link)+"')>"+article+"</a></td>"+
				        "<td width='10%'><a href=\"javascript:DeleteData("+artId+",'"+cId+"');\" name=aRemove >remove</a></td></tr></table>";
		 divPreview.innerHTML=strDiv;
		 document.getElementById('divReqPreview').appendChild(divPreview);
		 }
	 }
}

function checkArticleIsPresentinOnlineReq(artId)
 {
   var parentNode = document.getElementById("divReqPreview"); 
   var len = parentNode .childNodes.length;
   var removeNode=document.getElementById("div"+artId); 
      
   for(var i = 0; i < len; i++)
       {      
       	if(parentNode.childNodes[i]==removeNode)
           return true;
      }

   return false;
 }

function DeleteData(id,chkbox)
{

    if(id!=null || id!=undefined)
      {
       //document.getElementById(id).removeNode(true);
        var parentNode = document.getElementById("divReqPreview"); 
        var len = parentNode .childNodes.length;
        var removeNode=document.getElementById("div"+id); 

      
      	for(var i = 0; i < len; i++)
       		{      
       		 if(parentNode.childNodes[i]==removeNode)
           	 parentNode.removeChild(removeNode);
           	}

       if(document.getElementById(chkbox)!=null)
          {
          if(document.getElementById(chkbox).checked)
          document.getElementById(chkbox).checked=false;
          }
             
      }
}
//Medical inquiry form

function PopulateDefaultUserProfile()
{

 if(window.location.search.substring(1).length >0 && getCookie("InquiryDetails")!=null)
 {
      var uiInquiryFields = "ddlTitle,txtFirstName,txtLastName,txtAddressLine1MI,txtAddressLine2MI,txtCityMI,ddlStateMI,txtZipMI,txtPhoneMI,txtExtMI,txtFaxMI,txtEmailAddressMI";  
      var uiInquiryFieldNames = uiInquiryFields.split(",");
      var userInquiryProfile = getCookie("InquiryDetails");
      var userInquiryDetails = userInquiryProfile.split(",");
      document.getElementById(uiInquiryFieldNames[0]).selectedIndex = userInquiryDetails[0];
      
      for(var j=1;j<userInquiryDetails.length;j++)
      {      
      document.getElementById(uiInquiryFieldNames[j]).value = userInquiryDetails[j];
      }
   deleteCookie("InquiryDetails");

 }
else
{

    var userProfile = strUserProfile ;
    var uiDbFields = "FIRST_NAME,LAST_NAME,CITY,STATE,ADDRESS_1,ADDRESS_2,EMAIL_ADDRESS,ZIP_CODE";
    var uiFields = "FirstName,LastName,CityMI,StateMI,AddressLine1MI,AddressLine2MI,EmailAddressMI,ZipMI";
    
    var userDetails = userProfile.split("#");
    var uiDbFieldNames = uiDbFields.split(",");
    var uiFieldNames = uiFields.split(",");
    
    if(userDetails.length>0)
    {
    
    for(var i=0;i<uiDbFieldNames.length;i++)
    {
     for(var j=0;j<userDetails.length-1;j++)
     {
     if(uiDbFieldNames[i].indexOf(userDetails[j].substring(0,userDetails[j].indexOf("~")))>=0)
     {
     if(uiDbFieldNames[i] =="STATE")
     {
     document.getElementById("ddl"+uiFieldNames[i]).value = userDetails[j].substring(userDetails[j].indexOf("~")+1);

     }
     else
     document.getElementById("txt"+uiFieldNames[i]).value = userDetails[j].substring(userDetails[j].indexOf("~")+1);
     }
     
     }
    }
    }
}
   
 }

function createCookie(name, value,minutes) 
{
    if (minutes)
       {
		    var date = new Date();
		    date.setTime(date.getTime()+(minutes*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else
	    {
	     var expires = "";
	    }
	    document.cookie = name+"="+value;//+"path=/";   
 
   }
   
   function eraseCookie(name)
   {
   createCookie(name, ""); 
   }
   
    function readCookie (name)
       {
         var arg = name + "=";
         var alen = arg.length;
         var clen = document.cookie.length;
         var i = 0;
         while (i < clen)
          {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
             {
               return getCookieVal (j);
             }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0)
             {
               break;
             }
         }
         return null;
      }
//Javascript functions for Medical Inquiry

function CheckMaxLength(maxlength)
 {

  var value = document.getElementById("txtareaInquiryMI").value
	if (value.length < maxlength)
			return true;
		else
			return false;
 }



function populateM2MProduct(ddlProduct,productxml)
{

  var xmlDoc=loadXML(productxml);//strArticles is coming from the html file
  var node="";   
  addOptions(ddlProduct,"","Select Product")
  if(xmlDoc != null)
      {
        node= SelecteNodesInXML(xmlDoc,'Item');
        if(node != null)
        {   
            var text="";
            var value="";    
	       if(node.length>0)
	         {
	         for (i=0;i<node.length;i++)
		     {

	          text=getNodeValue(node,i,0);
              value=getNodeValue(node,i,1);
              addOptions(ddlProduct,value,text)
              }

	         }
	     }    
	  }          

  
}



function DisplayMedicalInquiry()
{

 document.getElementById('ddlPreferredResponseTimeMI').disabled = true;
  
    if(strSpecialty.toUpperCase()==SPECIALTY_ONCOLOGY || strSpecialty.toUpperCase()==SPECIALTY_PSYCHIATRY||strSpecialty.toUpperCase()==SPECIALTY_PSYCHIATRY_GERIATRIC)
    {
      document.getElementById("divPreResponseChannel").style.display = "block";
      document.getElementById("divPreResponseTime").style.display = "block";
    } 

	if(document.getElementById("divMedicalInquiryForm").style.display == "none")
	{
	   
		document.getElementById("divMedicalInquiryForm").style.display = "block";
		document.getElementById("divErrorMsgs").innerHTML="";
		DisableOnlineReqControls(true);
	}
	else
	{
		document.getElementById("divMedicalInquiryForm").style.display = "none";
		document.getElementById("divErrorMsgs").innerHTML="";
		DisableOnlineReqControls(false);

	}
}

//used to enable/disable online request controls if medical inquiry form is selected.
 function DisableOnlineReqControls(isDisable)
 {
 
   disableDivOnclick(document.getElementById('lstCategory'),isDisable,true);
   disableDivOnclick(document.getElementById('lstType'),isDisable,false);
  
    document.getElementById('txtSave').readOnly=isDisable;
   //disable Contact Info
    document.getElementById('btnSaveOnline').disabled = isDisable;
    document.getElementById('upLoadButton').disabled = isDisable;
    document.getElementById('Update').disabled = isDisable;
    document.getElementById('reset').disabled = isDisable;
    document.getElementById('saveButton').disabled = isDisable;
    document.getElementById('close').disabled = isDisable;
    document.getElementById('txtcontactinformation').readOnly=isDisable;
    document.getElementById('txtPhyscianName').readOnly=isDisable;
	document.getElementById('txtAddress1').readOnly=isDisable;
	document.getElementById('txtAddress2').readOnly=isDisable;
	document.getElementById('txtAddress3').readOnly=isDisable;
	document.getElementById('txtCity').readOnly=isDisable;
	document.getElementById('ddlstate').disabled = isDisable;
	document.getElementById('txtZipCode').readOnly=isDisable;
	document.getElementById('txtPhone').readOnly=isDisable;
	document.getElementById('txtEmergencyPhone').readOnly=isDisable;
	document.getElementById('txtEmailAddress').readOnly=isDisable;
	document.getElementById('txtFax').readOnly=isDisable;


    document.getElementById('btnAddContactInfo1').disabled = isDisable;
    document.getElementById('btnAddContactInfo2').disabled = isDisable;
    document.getElementById('btnAddContactInfo3').disabled = isDisable;
    document.getElementById('btnEditContactInfo1').disabled = isDisable;
    document.getElementById('btnEditContactInfo2').disabled = isDisable;
    document.getElementById('btnEditContactInfo3').disabled = isDisable;

    document.getElementById('btnEditContact').disabled = isDisable;
    toggleDisabled(document.getElementById('divReqPreview'));


    var arrRadio=document.getElementsByName('rdoContactInformation');
    for(var i=0;i<arrRadio.length;i++)
    {
     arrRadio[i].disabled = isDisable;

    }
    var items=document.getElementsByName('chkItems');// getElementById('lstItems');
    if (items!='undefined' && items!=null)
      {
       for (var x = 0; x < items.length; x++)
        {
          items[x].disabled=isDisable;
        }
     }
     var link=document.getElementsByName('aLink');// getElementById('lstItems');
     if (link!='undefined' && link!=null)
      {
       for (var x = 0; x < link.length; x++)
        {
        disableAnchor(link[x],isDisable);
        }
        }
     var remove=document.getElementsByName('aRemove');// getElementById('lstItems');
     if (remove!='undefined' && remove!=null)
      {
       for (var x = 0; x < remove.length; x++)
        {
          disableAnchor(remove[x],isDisable);

        }
     }


  
 }  
 
 function disableDivOnclick(element,disable,isCategory)
 {   
      
      if (element.childNodes && element.childNodes.length > 0)
       {
          for (var x = 0; x < element.childNodes.length; x++)
           { 
           // element.childNodes[x].disabled=disable;  
            if(disable)
 			{ 
               element.childNodes[x].onclick=null;
               if(element.childNodes[x].className!="")
               element.childNodes[x].className="navigationListnotSelected"; 
			   element.childNodes[x].style.cursor="text";
             }
             else
             {
               if(isCategory)
               element.childNodes[x].onclick=GetTypeList;
               else
               element.childNodes[x].onclick=GetItemList;
               
               if(element.childNodes[x].className!="")
               element.childNodes[x].className="navigationListSelected"; 
               element.childNodes[x].style.cursor="default";
                 		  
             }   
                
             }
       }

  
 }

 
 
 function disableAnchor(obj, disable)
 {
  if(disable)
  {
    var href = obj.getAttribute("href");
    if(href && href != "" && href != null)
    {
       obj.setAttribute('href_bak', href);
    }
    obj.removeAttribute('href');
    obj.style.color="gray";
  }
  else{
    obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
    obj.style.color="";
  }
}

    function toggleDisabled(el)
    {
                try {
                   el.disabled = el.disabled ? false : true;
                 
                   }
                catch(E){}
                
                if (el.childNodes && el.childNodes.length > 0) {
                    for (var x = 0; x < el.childNodes.length; x++) {
                        toggleDisabled(el.childNodes[x]);
                    }
                }
            }


function ValidateMedicalInquiry()
{

	var Errormsg="";	
	var valid = true;
	/* if(document.getElementById("txtAddressLine1MI").value == "")
	 {
	 Errormsg+="Please enter the address <br>";
	 valid = false;
	 }*/
	/*if(document.getElementById("txtCityMI").value == "")
	 {
	 	 Errormsg+="Please enter the City <br>";
		 valid= false;
	 }*/
	 if(document.getElementById("txtPhoneMI").value == "")
	 {
	    Errormsg+="Please enter a valid Phone Number <br>";
	    valid= false;
	 }
	  else
	 {
	 if(!IsNumeric(document.getElementById("txtPhoneMI").value))
	   {
	    Errormsg+="Please Enter a valid Phone number <br>";
	    valid= false;	
	    }

	 }

	  if(document.getElementById("txtEmailAddressMI").value == "")
	 {
	    Errormsg+="Please enter a valid Email Address <br>";
	    valid= false;
	 }

	/*if(document.getElementById("ddlStateMI").value == "")
	 {
	   Errormsg+="Please select the state <br>";
	    valid= false;
	 }*/
	 if(document.getElementById("ddlProductMI").value == "")
	 {
	    Errormsg+="Please select a Product <br>";
	    valid= false;
	 }
	 
	/* if(document.getElementById("txtZipMI").value == "")
	 {
	    Errormsg+="Please Enter ZipCode <br>";
	    valid= false;
	 }*/
	
	if(document.getElementById("txtZipMI").value != "")
	 {
	   if(!IsNumeric(document.getElementById("txtZipMI").value))
	   {
	    Errormsg+="Please Enter a valid Zip Code <br>";
	    valid= false;	
	    }
	 }
	 if(document.getElementById("txtareaInquiryMI").value == "")
	 {
	   Errormsg+="Please enter a Question <br>";
	   valid= false;
	 }
	 if(strSpecialty.toUpperCase()==SPECIALTY_ONCOLOGY || strSpecialty.toUpperCase()==SPECIALTY_PSYCHIATRY||strSpecialty.toUpperCase()==SPECIALTY_PSYCHIATRY_GERIATRIC)
	   {

	 if(document.getElementById("ddlPreferredChannelMI").value == "")
	 {
		Errormsg+="Please select a Preferred Channel <br>";
	 	valid= false;
	 }
	 }
	
	 if(document.getElementById("txtFaxMI").value!="")
		 {
		  if(!IsNumeric(document.getElementById("txtFaxMI").value))
		   {
		    Errormsg+="Please Enter a valid Fax number <br>";
		   valid= false;
		   }
	     }
	 
	 if(document.getElementById("txtEmailAddressMI").value!= "")
	   {
	    if (/^[a-zA-Z0-9]{1}[a-zA-Z0-9\._+-]*@[a-zA-Z0-9]{1}[a-zA-Z0-9\._+-]*\.[a-zA-Z]{2,6}$/.test(document.getElementById("txtEmailAddressMI").value)) 
	       {   
	         
	       }   
	       else
		   {		
		   Errormsg+="Please enter a valid Email Address <br>";
		     valid= false; 
		   }
	 
	   }
	   
	   if(strSpecialty.toUpperCase()==SPECIALTY_ONCOLOGY || strSpecialty.toUpperCase()==SPECIALTY_PSYCHIATRY||strSpecialty.toUpperCase()==SPECIALTY_PSYCHIATRY_GERIATRIC)
	   {	  
	 if(document.getElementById("ddlPreferredChannelMI").value == "EMail")
	    {
	       if(document.getElementById("txtEmailAddressMI").value=="")
	           {
	           
	              Errormsg+="Please enter a valid Email Address <br>";

	             valid= false;
	           }
	     }
	 else if(document.getElementById("ddlPreferredChannelMI").value == "Phone")
	    {
	    
	       if(document.getElementById("txtPhoneMI").value=="")
	          {	            
	            Errormsg+="Please enter a valid Phone Number <br>";
	             valid= false;
	           }
	       else if(document.getElementById("ddlPreferredResponseTimeMI").value=="")
	           {
	             Errormsg+="Please select your Preferred Time <br>";
	              valid= false;
	            }
	    }
	 else if(document.getElementById("ddlPreferredChannelMI").value == "Fax")
	         {
	          if(document.getElementById("txtFaxMI").value=="")
				{
	            Errormsg+="Please enter a valid Fax Number <br>";
	            valid= false;
	            }
	         }
	           else if(document.getElementById("ddlPreferredChannelMI").value == "Postal Mail")
	   {
	   if(document.getElementById("txtAddressLine1MI").value == "")
		 {
		 Errormsg+="Please enter the Address <br>";
		 valid = false;
		 }
		if(document.getElementById("txtCityMI").value == "")
			 {
			 	 Errormsg+="Please enter the City <br>";
				 valid= false;
			 }
		if(document.getElementById("ddlStateMI").value == "")
			 {
			   Errormsg+="Please select the State <br>";
			    valid= false;
			 }
			  if(document.getElementById("txtZipMI").value == "")
			 {
			    Errormsg+="Please Enter Zip Code <br>";
			    valid= false;
			 }
		
	 	  }

	         }
	         
	     document.getElementById("divErrorMsgs").innerHTML = Errormsg;
         return valid;
  }
  
  function EnablePrefferedTime()
  {
  
  if(document.getElementById("ddlPreferredChannelMI").value == "Phone")
  {
   document.getElementById('ddlPreferredResponseTimeMI').disabled = false;
  }
  else
  {
   document.getElementById('ddlPreferredResponseTimeMI').disabled = true;
  }
  }



 //function to check for the numeric data.

        function IsNumeric(data)
        {  
            var isNumeric = true;  
            if(data.length > 0)
            {                                  
                for(var count = 0;count<data.length;count++)
                {   
                   var charcode = data.charCodeAt(count);                   
                   if(charcode < 48 || charcode > 57)
                    {                    
                       isNumeric = false;
                   }
              }     
           }           
           return isNumeric;
        }
function isAlphabetic(val)
 {
   if (val.match(/^[a-zA-Z]+$/))
    {
     return true;
    }
  else
   {
   return false; 
   }
}

function SubmitMedicalEnquiry()
{ 

    var status = ValidateMedicalInquiry();
	if(status == true)
	{
	 /*var internaluserid= "011920092153181120";
	 var strSendXml="FirstName="+document.getElementById('txtFirstName').value+"&LastName="+document.getElementById('txtLastName').value+"&AddressLine1MI="+document.getElementById('txtAddressLine1MI').value+"&TitleMI="+document.getElementById('txtTitleMI').value+"&AddressLine2MI="+document.getElementById('txtAddressLine2MI').value+"&CityMI="+document.getElementById('txtCityMI').value+"&StateMI="+document.getElementById('ddlStateMI').value+"&ZipMI="+document.getElementById('txtZipMI').value+"&PhoneMI="+document.getElementById('txtPhoneMI').value+"&ExtMI="+document.getElementById('txtExtMI').value+"&FaxMI="+document.getElementById('txtFaxMI').value+"&EmailAddressMI="+document.getElementById('txtEmailAddressMI').value+"&ProductMI="+document.getElementById('ddlProductMI').value+"&PreferredChannelMI="+document.getElementById('ddlPreferredChannelMI').value+"&PreferredResponseTimeMI="+document.getElementById('ddlPreferredResponseTimeMI').value+"&InquiryMI="+document.getElementById('txtareaInquiryMI').value+"&internaluserid="+internaluserid;
	 var url = document.location.href;//"http://saldtp061777:9002/pages/customizepatient.aspx";
	 url = url + "?MedicalInq="+"SaveMedicalInquiry"
	 xmlHttp = GetXmlHttpObject(updateM2MStateChanged);
	 xmlHttpPost(xmlHttp, url,strSendXml);	 
	 }  
	   */
	 document.getElementById('hdnOrchID').value="PPNEnhM2MInquiry";	
	 document.getElementById("hdnProduct").value=getProductName(document.getElementById("ddlProductMI").options[document.getElementById("ddlProductMI").selectedIndex].text);
	 document.forms[0].action="controller.aspx";
	 document.forms[0].submit();
	 }
  
	 
}

 function getProductName(value)
		{	
			var productName = "";
	    	productName  = value.substring(0,value.indexOf("(")-1);
	    	productName = trim(productName);
	    	return productName;
		}

   
     function updateM2MStateChanged()
    {
        
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
          strOutput = xmlHttp.responseText.substring(13,xmlHttp.responseText.indexOf('</ResponseXml>'));       
          if(strOutput =="True")         
          {
		   document.getElementById("divResponse").innerHTML ="Medical Inquiry submitted succssfully"
		   document.getElementById("divResponse").style.color ="red";
         }
         else
         {
           document.getElementById("divResponse").innerHTML ="Medical Inquiry submission Failed"
         }
      
       }
    }
//Ends MedicalInquiry form
 
   function SaveOnlineRequest(obj)
   {
 
     if(GetArticlesForOnline()=="")
     {
      document.getElementById("divErrorSave").style.display="block";
      document.getElementById("divErrorSave").innerHTML="Please select at least one article";
      return;

     }
     if(document.getElementById("txtSave").value=="")
     	  {
       	  document.getElementById("divErrorSave").style.display="block";
       	  document.getElementById("divErrorSave").innerHTML="Please enter request name";
       	  return;
      	  }
      	  if(glbEmail=="")
      	  {
      	  document.getElementById("divErrorSave").style.display="block";
       	  document.getElementById("divErrorSave").innerHTML="Please enter Email Address for the selected contact information";
       	  return;
      	  }
      	       	 
      document.getElementById("hdnArticleId").value=GetArticlesForOnline();
	  document.getElementById("hdnContactInfo").value=GetSelectedContactinfo();
	  document.getElementById("hdnUserId").value="01105B4E-DED8-462C-9324-EE5B0FCDEB9E";//[SESSION:UserId];
	  document.getElementById("hdnAction").value ="Save";
	  var strToMailAdd=glbEmail;
	  SetCustCookie("OnlineSelectArt",GetArticlesForOnline(),"","","","");
	  SetCustCookie("ToEmailId",strToMailAdd,"","","","");

	onlineRequestTracking(obj, document.getElementById("hdnArticleId").value);

	  document.forms[0].submit();
	  
	 
  }

function GetArticlesForOnline()
{

  var arrOnlineArt='';

  if(document.getElementById("divReqPreview").childNodes.length>0)
  {
  var divReqlength=document.getElementById("divReqPreview").childNodes.length;
  for(var i=0;i<divReqlength;i++)
  {
  var childDiv= document.getElementById("divReqPreview").childNodes[i];
  if(childDiv!=null && childDiv!="")
   {
   if(arrOnlineArt=="")
   arrOnlineArt+=childDiv.id.replace('div',"");
   else
   arrOnlineArt+=","+childDiv.id.replace('div',"");
  
   } 
  }
   
 }
 return arrOnlineArt;
}

function PopulateProductBasedSpecality(PrdSpecialty)
 {
 
  var divPrdSpecialty=document.getElementById('divPrdSpecialty');
  var divcontent='';
  var arrProduct=PrdSpecialty.split('~');
  divcontent=document.createElement('div');
  divcontent.innerHTML="Related to "+initialCap(arrProduct[0]);//giving the specialty heading 
  divcontent.className='grey12bld';
  divPrdSpecialty.appendChild(divcontent);

  for(var i=1;i<arrProduct.length;i++)
   { 
   	 divcontent=document.createElement('div');
   	 var linkurl="../products/"+arrProduct[i]+".aspx";
   	 divcontent.innerHTML="<a href="+linkurl+">"+arrProduct[i]+"</a>";
   	 
   	 divcontent.className='rightLayoutTextContent';
   	 divPrdSpecialty.appendChild(divcontent);
   	 
   }
 }


function LoadThankYouPage(strArt)
{
 
  xmlArtDoc=loadXML(strArt);
  var selArt=GetCustCookie('OnlineSelectArt');
  //DeleteCustCookie('OnlineSelectArt','','');
  var strToMailAdd= GetCustCookie('ToEmailId');
  DeleteCustCookie('ToEmailId','','');
  var arrCategory=new Array();
  var count=0;
  var strToMailAdd;




 //selArt="737,731";
 if(selArt!="" || selArt!=null)
 {
    var arrselArt=selArt.split(',');
    var node = SelecteNodesInXML(xmlArtDoc,'Item'); 
    var arrType=new Array();
    var id="";
    var article="";
	var category ="";
	var type="";
	var link="";
    var divViewContent=document.getElementById('divViewContent');
    

   if(node != null && divViewContent!=null)
       {
       	divViewContent.innerHTML="";
       

       	document.getElementById('divSafetyInfo').innerHTML="";
	    document.getElementById('divInterestItems').innerHTML="";
	       if(node.length>0)
	         {
	          var strInnerHtml= "<table  class=datatable>"+
                                	"<tr>"+
                                    "<th scope=col width=15%></th>"+
                                    "<th scope=col  width=40%></th>"+
                                    "<th scope=col  width=65%></th>"+
                                    "</tr>";
				for (var i=0;i<node.length;i++)
		           {               
		             id=getNodeValue(node,i,0);
			         for(var j=0;j<arrselArt.length;j++)
   						{	 if(id==arrselArt[j])
   						      {
   						      article= getNodeValue(node,i,1);
		             		  category = getNodeValue(node,i,2);
		             		  type= getNodeValue(node,i,3);
		             		  link=xmlEscape(getNodeValue(node,i,4));
		             		   arrCategory[count]=category ;
		             		  count++;
	             		  
   						      strInnerHtml+="<tr><td><b>"+category+"</b></td>"+
   						      "<td><b>"+type+"</b></td>"+
   						      "<td><a href='"+link+"' target='_blank'>"+article+"</a></td></tr>";
   						       						     
   						      }
   						}
   						
					}   
					strInnerHtml+="</table>";
   					var div=document.createElement('div');
   					div.innerHTML=strInnerHtml;
   					divViewContent.appendChild(div);
   									
     
  				 }
			 }
 
		 }
		arrCategory= uniqueArr(arrCategory);
		var isSafety=false;
		 for(var catCount=0;catCount<arrCategory.length;catCount++)
		 {
		  category=arrCategory[catCount];
		  if(category!="")
		  {
		  if(catCount+1==arrCategory.length)
		  {
		   isSafety=true;
		  }
		  AddSafetyInformationContent(category,strToMailAdd,isSafety);
		  } 
		   
		 }
		
		
 }
 
  function uniqueArr(arrCat)
  {
	var temp = new Array();
	 for(i=0;i<arrCat.length;i++){
	  if(!contains(temp, arrCat[i])){
	   temp.length+=1;
	   temp[temp.length-1]=arrCat[i];
	  }
	 }
	 return temp;
}
 
//Will check for the Uniqueness
function contains(arrCat, value)
 {
	 for(j=0;j<arrCat.length;j++)
	   {
	   if(arrCat[j]==value)
	     return true;
	   } 
	   
	 return false;
}
 
 function SendMail(strToMailAdd)
 {
    
  

    if(strToMailAdd!="" && strToMailAdd!=null )
       {											
		url=window.location.href+"?mail="+strToMailAdd;
							
		var xmlhttp = getHTTPObject();
		xmlhttp .open("POST", url, true);
		//xmlhttp .send(document.getElementById('divSelectedProd').innerHTML+document.getElementById('divInterestItems').innerHTML +document.getElementById('divSafetyInfo').innerHTML); 
		xmlhttp .send(document.getElementById('divViewContent').innerHTML+"|||||"+document.getElementById('divInterestItems').innerHTML +"|||||"+document.getElementById('divSafetyInfo').innerHTML);
		xmlhttp .onreadystatechange = function()
	                       {
	                        }
                               
 		}
 }
 
 function AddInterestedLinksIntodiv(LinkUrl,product,LinkText)
 {
   var divInterestItems=document.getElementById('divInterestItems');
   var divHtmlContent=document.createElement('div');
   divHtmlContent.className="leftLayoutTextContent";
   divHtmlContent.innerHTML="<a href="+LinkUrl+" target='_blank'>"+product+" "+LinkText+"</a>";
   divInterestItems.appendChild(divHtmlContent);

 } 
 
 function AddInterestedLinks(product,FullPrescribingInformation,PatientProductInformationUrl)
 {

 /* if(Indication!="")
	 {
	 AddInterestedLinksIntodiv("../products/"+product+".aspx?tab=indication",product,"Indications");
	 }
   if(Scientific!="")
   	 {
   	  AddInterestedLinksIntodiv("../products/"+product+".aspx?tab=scientific_literature",product,"Scentific Literature");
     }
     if(Professional!="")
   	 {
   	  AddInterestedLinksIntodiv("../products/"+product+".aspx?tab=professional_resources",product,"Professional Resources");
	 }
     if(PatientEducation!="")
   	 {
   	  AddInterestedLinksIntodiv("../products/"+product+".aspx?tab=patient_education",product,"Patient Education Material");
     }
     
     if(ConditionInformation!="")
   	 {
   	  AddInterestedLinksIntodiv("../products/"+product+".aspx?tab=condition_information",product,"Condition Information");
     }
      */
     if(FullPrescribingInformation!='')
     {
       AddInterestedLinksIntodiv(FullPrescribingInformation,product,"Full Prescribing Information");
     }
    if(PatientProductInformationUrl!='')
     {
      AddInterestedLinksIntodiv(PatientProductInformationUrl,product,"Patient Product Information");
     }
    
  
 }
 
 function AddSafetyInformationContent(selProduct,strToMailAdd,isSafety)
 {
 
	 if(strProductCenter!="")//this variable is declared in thankyou page
	 {
	     var xmlInfoDoc=loadXML(strProductCenter);
		 var node = SelecteNodesInXML(xmlInfoDoc,'Item');
         if(node != null )
         {
       	   if(node.length>0)
	         {
	         var product="";
	         var strSafetyUrl="";
	         var strFullPrescribingInformation="";
			 var strPatientProductInformationUrl=""; 
	          for (var i=0;i<node.length;i++)
		           {               
		             product=getNodeValue(node,i,0);
		             if(selProduct==product)
		             { 
		               //strIndication=getNodeValue(node,i,1);//Indication Tab URL
					   //strScientific=getNodeValue(node,i,2);//Scientitfic Tab URL
					   //strProfessional=getNodeValue(node,i,3);//Professional tab URL
					   //strPatientEducation=getNodeValue(node,i,4);//PatientEducation tab url
					   //strConditionInformation=	getNodeValue(node,i,5);//Condition Info
                       strSafetyUrl=getNodeValue(node,i,1);//Saferty URL Info
                       strFullPrescribingInformation=getNodeValue(node,i,2);//Prescribibg Info
                       strPatientProductInformationUrl=getNodeValue(node,i,3);//Pateint URL Info
                       AddInterestedLinks(product,strFullPrescribingInformation,strPatientProductInformationUrl);
		               var url=strSafetyUrl;
		               
		               if(strSafetyUrl!="" )
		               {

		               
					     var http = getHTTPObject();
						 http.open("GET", url, true);
						 http.send(null); 
						 http.onreadystatechange = function()
						   {
							 if (http.readyState == 4)
							   {
							     if (http.status==200)
							      {
							        var divSafety=document.createElement('div');
							        divSafety.innerHTML=http.responseText;

							        document.getElementById('divSafetyInfo').appendChild(divSafety);
							       }
							       if(isSafety)
								   SendMail(strToMailAdd);
								  
								  
							    }
						    }
						   }//Send EMail
						   else if(isSafety)
						   {
						   	 SendMail(strToMailAdd);
						    }
						    
						  
								// break;
						    }//If ends
		                 
		              
			         }//for loop ends
                  

	             }
	         }   

        }
     }   
     
 
 function getHTTPObject()
  {
  
   var objXmlHttp=null
     /* if (navigator.userAgent.indexOf("Opera")>=0)
      {
            alert("This example doesn't work in Opera");
            return 
      }*/
      if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
      { 
            var strName="Msxml2.XMLHTTP";
            if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
            {
                strName="Microsoft.XMLHTTP";
            } 
            try
            { 
                objXmlHttp=new ActiveXObject(strName);
                return objXmlHttp;
            } 
            catch(e)
            { 
                alert("Error. Scripting for ActiveX might be disabled") 
                return 
            } 
      } 
      if (Sys.Browser.agent == Sys.Browser.Firefox)
      {
            objXmlHttp=new XMLHttpRequest();
            return objXmlHttp;
      }
      
 }
 
 
 function OnlineRequestLoad()
 {
   
    cookValue=GetCustCookie('PPNRequest');
    
	 DeleteCustCookie ('PPNRequest','','');
	 if(cookValue!='' && cookValue!=null )
	  {
	     var url = document.location.href;//"http://saldtp061777:9002/pages/customizepatient.aspx";
		 url = url + "?OnlineReqId="+cookValue;
		 xmlHttp = getHTTPObject();
		 xmlHttp .open("GET", url, true);
		 xmlHttp .send(null);
		  if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
			   {
				strOutput = xmlHttp.responseText.substring(13,xmlHttp.responseText.indexOf('</ResponseXml>'));       
          		SetOnlineRequest(strOutput );
			   }

		 xmlHttp .onreadystatechange = function()
			{
			 if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
			   {
				strOutput = xmlHttp.responseText.substring(13,xmlHttp.responseText.indexOf('</ResponseXml>'));       
          		SetOnlineRequest(strOutput );
			   }

			 }
	 			 
 	   }
   
 }

function SetOnlineRequest(strOutput)
 {
  var xmlDoc=loadXML(strOutput);
  if(xmlDoc  != null)
        {
           	
        	var node =SelecteNodesInXML(xmlDoc,'Item');
        	if(node != null)
        	{        	   
                var articlesId="";
	            var requestName="";
	            var ContactSel="";
	           if(node.length>0)
	            {
	             for (i=0;i<node.length;i++)
		            {		              		              
		                articlesId=getNodeValue(node,i,0); 
		                ContactSel= getNodeValue(node,i,1);
						requestName= getNodeValue(node,i,2);
					   
		                
			        }
	            
                  FindArticles(articlesId);
                  document.getElementById('txtSave').value=requestName;
                 

                  if(ContactSel!=1)
                  GetContactDetails(ContactSel);
                    
	            
	          }
	        }    

         }
  }

function FindArticles(articlesIds)
{
 var strArticlesId=articlesIds.split(',');
 if(xmlArtDoc  != null)
        {
           	
        	var node = SelecteNodesInXML(xmlArtDoc ,'Item');
        	if(node != null)
        	{        	   
                var id="";
	            var requestName="";
	            var articles="";
	            var ContactSel="";
	            var link="";

	             if(node.length>0)
	            {
	             for (i=0;i<node.length;i++)
		            {		              		              
		               
		             id=getNodeValue(node,i,0);
			         articles=getNodeValue(node,i,1);
		             category =getNodeValue(node,i,2);
		             type= getNodeValue(node,i,3);
		             link= getNodeValue(node,i,4);

		             
		             for(var j=0;j<strArticlesId.length;j++)
		             {
			             if(strArticlesId[j]==id)
			             {
			              AddPreviewDetails(id,category ,'',articles,type,link,null)
			          
			             }
		               
		             }
		             
		                
			        }
			      }
	          }  

          }
}



//Begin - Script to disable tabs and links

function getElementsByClass(searchClass,node,tag)
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//End - Script to disable tabs and links 



//Begin script for resoruce center
function loadXMLString(txt) 
{
  try //Internet Explorer
  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(txt);
	  return(xmlDoc); 
  }
  catch(e)
  {
	  try //Firefox, Mozilla, Opera, etc.
	    {
	    parser=new DOMParser();
	    xmlDoc=parser.parseFromString(txt,"text/xml");
	    return(xmlDoc);
	    }
	  catch(e) {alert(e.message)}
  }
   return(null);
}
function SelectNodes(xmlDoc, elementPath)
{
        if(window.ActiveXObject)
        {
            return xmlDoc.selectNodes(elementPath);
        }
        else
        {
           var xpe = new XPathEvaluator();
           var nsResolver = xpe.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
           var results = xpe.evaluate(elementPath,xmlDoc,nsResolver,XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
           var aNodes = new Array;
		   if (results != null)
		   {
		        var oElement = results.iterateNext();
		        while(oElement)
		        {
		            aNodes.push(oElement);
		            oElement = results.iterateNext();
		        }
		    }
           return aNodes;
        }
    }

function GetResourceCenterData(ReosurceXML)
{
  var xmlDoc=loadXMLString(ReosurceXML);
  var divArticles =document.getElementById('divArticles');
  var ddlProducts =document.getElementById('ddlProducts');
  var strCategories = document.getElementById('hdnCategories').value;
  var Categories = strCategories.split("|");
  if(document.getElementById("divCategory"))
  { 
	document.getElementById("divCategory").innerHTML=Categories[0];
  }
  if(xmlDoc  != null)
    {
    	var nodeList = SelectNodes(xmlDoc,"/Root/Products/Specialty/Product");
    	var optn = document.createElement("OPTION");
		optn.text = "Select by Product";
		optn.value = "";
		ddlProducts.options.add(optn);
		if(nodeList  != null)
	    {
			PopulateResourceProducts(nodeList,ddlProducts,"Specialty Related Products");
		}
		var nodeList =SelectNodes(xmlDoc,"/Root/Products/Others/Product");
		if(nodeList  != null)
	    {
			PopulateResourceProducts(nodeList,ddlProducts,"Other Products");
		}
     
	     var strHTML="";
	     for(cCount=0;cCount<Categories.length;cCount++)
	     {
		   var nodeList = SelectNodes(xmlDoc,"/Root/Tabs/" + Categories[cCount].replace(" ","") + "/Articles/Article");
		   strHTML += populateArticles(nodeList,Categories[cCount].replace(" ",""),cCount);
	     }
		divArticles.innerHTML=strHTML; 
              
    }
   
   changeResoruceCenterTab(Categories[0],"cTab1")
}
function replace(strValue,oldValue,newValue)
{
  var index=strValue.indexOf(oldValue);
  while(index>-1)
  {
    strValue=strValue.replace(oldValue,newValue);
    index=strValue.indexOf(oldValue);
  }
  return strValue;
}

function buildSendToHitBoxForDynamicLinks(articleLink,articleTitle,brand,conditions,highValue,contentType,specialty)
{
   var genericAttributes="";
   var strJSFunction="";
   if(highValue=="True")
   {
     genericAttributes="goal=hiValue";
   }
   if(contentType!="" && contentType!=null)
   {
     if(genericAttributes!="")
     {
       genericAttributes+=";content_type=" + contentType;
     }
     else
     {
    	 genericAttributes="content_type=" + contentType;
     }
   }
    if(specialty!="" && specialty!=null)
   {
     if(genericAttributes!="")
     {
     	genericAttributes+=";specialty=" + specialty;
     }
     else
     {
     	genericAttributes="specialty=" + specialty;
     }
   }
   articleTitle = articleTitle.replace(/&#34/g,"#34").replace(/&#39/g,"#39")
   articleTitle = replace(articleTitle,"/","#58");
   strJSFunction="javascript:sendToHitBoxForDynamicLinks('" + articleLink  +"','" + articleTitle + "','" + brand +"','" + conditions + "','" + genericAttributes + "')";
   return strJSFunction;
}

function PopulateResourceProducts(nodeList,ddlProducts,category)
{
       var optGroup = document.createElement("optgroup");
       optGroup.label = category;
       for(i=0;i<nodeList.length;i++)
       {
	      if(nodeList[i].getAttribute("Name")!="" && nodeList[i].getAttribute("Name")!=null)
          {
             addOption(ddlProducts,nodeList[i].getAttribute("ProductLink"),"  " + nodeList[i].getAttribute("Name"),optGroup);
          }
       }
}

function populateArticles(nodeList,Category,index)
{
if(nodeList!=null && nodeList.length>0)
{
	var strInnerHTML ="<table cellpadding='0' cellspacing='0'>";
	 for(i=0;i<nodeList.length;i++)
 	{
 	    var sendToHitBoxForDynamicLinks="";
 	    
 	    sendToHitBoxForDynamicLinks=buildSendToHitBoxForDynamicLinks(nodeList[i].getAttribute('ArticleLink'),nodeList[i].getAttribute('Title'),nodeList[i].getAttribute('Product'),nodeList[i].getAttribute('Conditions'),nodeList[i].getAttribute('IsHighValueArticle'),nodeList[i].getAttribute('ContentType'),nodeList[i].getAttribute('Specialty'));

   		 strInnerHTML +="<tr><td><a href='" + nodeList[i].getAttribute('ArticleLink') + "' onclick=\""+sendToHitBoxForDynamicLinks +"\">"+nodeList[i].getAttribute('Title').replace(/&lt;/g,"<").replace(/&gt;/g,">") +"</a>";
    			if(nodeList[i].getAttribute('IsPDF')=="True")
    				{
       					strInnerHTML += "(PDF <img src='../../sitecollectionimages/icon_pdf.gif' width='15' height='16' border='0' />)";
    				}
    			if(Category=="PatientEducation" && nodeList[i].getAttribute('IsCustomizable')=="True")
    			{
    				//strInnerHTML += " <a href='javascript:CustomizeArticleinProductCenter(" + nodeList[i].getAttribute('ID') + ")'>(Customize)</A>";
 					strInnerHTML += "<a href=\"javascript:CustomizeArticleinProductCenter('" + nodeList[i].getAttribute('ID') + ";Product=" + nodeList[i].getAttribute('Product') + "')\">(Customize)</A>";
    			}
    			strInnerHTML +="<div class='caption'><span class='greyItalic11'>"+nodeList[i].getAttribute('Description').replace(/&lt;/g,"<").replace(/&gt;/g,">")+"</span></div></td></tr>";
      }
  strInnerHTML +="</table>";
  if(index==0)
  {
  	strInnerHTML ="<div id='div" + Category + "' style='display:block'>" + strInnerHTML  + "</div>"; 
  }
  else
  {
	strInnerHTML ="<div id='div" + Category + "' style='display:none'>" + strInnerHTML  + "</div>";
  }
}
else
{
  strInnerHTML ="<div id='div" + Category + "' style='display:none'>No data available for this selection.</div>";
}
  return strInnerHTML;
}

function addOption(ddlProducts,value,text,Group)
{
	        var opt = document.createElement("option");
        	opt.value =value
        	opt.appendChild(document.createTextNode(text));
       	        try 
        	{
		      Group.appendChild(opt); // standards compliant; doesn't work in IE
        	}
        	catch(ex) 
        	{

            	 Group.appendChild(opt); // IE only
        	}
               
            ddlProducts.appendChild(Group);
     
}



function changeResoruceCenterTab(tab,calssName)
{

   TrackTabClick(tab);
   
   var strTabs = document.getElementById('hdnCategories').value;
   var tabs = strTabs.split("|");
   if(document.getElementById("divCategory"))
   { 
	document.getElementById("divCategory").innerHTML=tab;
   }
   if(document.getElementById("divLatestCategory"))
   { 
	document.getElementById("divLatestCategory").innerHTML=tab;
   }
   if(document.getElementById("hdnActiveTab"))
   { 
	document.getElementById("hdnActiveTab").value=tab;
   }

   for(cCount=0;cCount<tabs.length;cCount++)
   {
     
     var curTab =  tabs[cCount];
     curTab = curTab.replace(" ","");
     tab = tab.replace(" ","");

     if(tab==curTab)
      {
		  if(document.getElementById("div" + curTab))
		  {
			document.getElementById("div" + curTab).style.display="block";
	        var currentTab = cCount+1;
	        if(document.getElementById("cTab" + currentTab))
			{
			    document.getElementById("cTab" + currentTab).className="current";
			}
	
		  }
         
      }
     else
     {
        if(document.getElementById("div" + curTab))
          {
			document.getElementById("div" + curTab).style.display="none";
			var currentTab = cCount+1;
			if(document.getElementById("cTab" + currentTab))
			{
			    document.getElementById("cTab" + currentTab).className="";
			}
          }
     } 
	
   }
   
  }

 function redirectToProductPage(url)
 {
    var curTab="";
   if(document.getElementById("hdnActiveTab"))
   { 
     curTab=document.getElementById("hdnActiveTab").value;
   }
   window.location.href=url+"?tab="+curTab.replace(" ","_");
 }
//End script for resoruce center
//To hide the auto generated menu items...
function getChildCtrlByClassName(objParentId,className)
{
    var parentObj = document.all?document.all[objParentId]:document.getElementById(objParentId);
    var childObj = null;
    if(parentObj !=null)
        childObj = getObjectByClassName(parentObj,className);
    return childObj;
}
function getObjectByClassName(parentObj,className)
{
    if(parentObj != null && parentObj.childNodes !=null)
    {
        for(var i=0;i<parentObj.childNodes.length;i++)
        {
            var objChild = parentObj.childNodes[i];
            if(objChild != null)
            {
                if(objChild.className == className)
                {
                    return parentObj.childNodes[i];
                }
                else
                    getObjectByClassName(parentObj.childNodes[i],className);
            }
        }
    }
    else
        return;
}
function ToggleDivObjectByClassName(parentObj,className)
{
    if(parentObj != null && parentObj.childNodes !=null)
    {
        for(var i=0;i<parentObj.childNodes.length;i++)
        {
            var objChild = parentObj.childNodes[i];
            if(objChild != null)
            {
                if(objChild.className == className)
                {
                    //return parentObj.childNodes[i];
                    ToggleDiv(parentObj.childNodes[i]);
                }
                else
                    ToggleDivObjectByClassName(parentObj.childNodes[i],className);
            }
        }
    }
    else
        return;
}
function ToggleDiv(objDiv)
{
    if(objDiv.style.display == 'none')
    {
        objDiv.style.display = 'block';
    }
    else
    {
        objDiv.style.display = 'none';
    }
}
function ToggleAutoExpandedDiv()
{
    var parentObj = document.all?document.all['nav']:document.getElementById('nav');
    var splCntr = getObjectByChildATagText(parentObj,'Specialty Centers');
    if(splCntr != null)
    {
        if(splCntr.className == 'navoff')
            splCntr.className = 'navon';
        else
            splCntr.className = 'navoff';
        
        ToggleDivObjectByClassName(parentObj,'subnavofffirst');
        ToggleDivObjectByClassName(parentObj,'subnavoff');
        ToggleDivObjectByClassName(parentObj,'subnavofflast');
        ToggleDivObjectByClassName(parentObj,'subnavonfirst');
        ToggleDivObjectByClassName(parentObj,'subnavon');
        ToggleDivObjectByClassName(parentObj,'subnavonlast');
    }
}
function hideAutoExpandedDiv()
{
    var parentObj = document.all?document.all['nav']:document.getElementById('nav');
    var splCntr = getObjectByChildATagText(parentObj,'Specialty Centers');
    if(splCntr != null && splCntr.className == 'navoff')
    {
        hideDivObjectByClassName(parentObj,'subnavofffirst');
        hideDivObjectByClassName(parentObj,'subnavoff');
        hideDivObjectByClassName(parentObj,'subnavofflast');
        hideDivObjectByClassName(parentObj,'subnavonfirst');
        hideDivObjectByClassName(parentObj,'subnavon');
        hideDivObjectByClassName(parentObj,'subnavonlast');
    }
}

function getObjectByChildATagText(parentObj,title)
{
    if(parentObj != null && parentObj.childNodes !=null)
    {
        for(var i=0;i<parentObj.childNodes.length;i++)
        {
            var objChild = parentObj.childNodes[i];
            if(objChild != null)
            {
                var aTagInnerText = (objChild.innerText) ? objChild.innerText : (objChild.textContent) ? objChild.textContent : ""
                if(aTagInnerText == title)
                {
                    return parentObj.childNodes[i];
                }
                else
                    hideDivObjectByClassName(parentObj.childNodes[i],title);
            }
        }
    }
}

function hideDivObjectByClassName(parentObj,className)
{
    if(parentObj != null && parentObj.childNodes !=null)
    {
        for(var i=0;i<parentObj.childNodes.length;i++)
        {
            var objChild = parentObj.childNodes[i];
            if(objChild != null)
            {
                if(objChild.className == className)
                {
                    //return parentObj.childNodes[i];
                    objChild.style.display = 'none';
                }
                else
                    hideDivObjectByClassName(parentObj.childNodes[i],className);
            }
        }
    }
    else
        return;
}
//End of hide the auto generated menu items...

//Script for survey
var NoOfPagesVisited=getCookie("npv_ppn");
if(NoOfPagesVisited!=null)
{
	NoOfPagesVisited=parseInt(NoOfPagesVisited)+1;
	setCookie("npv_ppn",NoOfPagesVisited,null,"/",null,null);
}
else
{
	setCookie("npv_ppn",1,null,"/",null,null);
}
function moveToSurveyNext(step)
{
 hideAllSurveyDivs();
 if(document.getElementById("divSurveyStep" + step))
 {
   document.getElementById("divSurveyStep" + step).className="display";	
 }
}
function closeSurvey()
{
 if(document.getElementById("divSurvey"))
 {
   document.getElementById("divSurvey").className="hide";	
 }
 if(document.getElementById("hdnSurveyTargetURL").value!="")
	window.location.href=document.getElementById("hdnSurveyTargetURL").value;

}
function declinedSurvey()
{
	if(document.getElementById("hdnSurveyID"))
	{
		var declinedSurvey=document.getElementById("hdnSurveyID").value
		var user_id=getCookie("iuid_ppn")
		if(!user_id)
		  user_id="";
		declinedSurvey = declinedSurvey + "_" + user_id;
		if(declinedSurvey!="")
		{
		    if(document.getElementById("hdnReofferSurvey").value=="IntraSessions")
		    {
				var now = new Date();
				now.setFullYear(now.getFullYear()+2);
				setCookie("rs_ppn",declinedSurvey,now,"/",null,null);
			}
			if(document.getElementById("hdnReofferSurvey").value=="WithinSession")
			{
				setCookie("rs_ppn",declinedSurvey,null,"/",null,null);
			}
	    }
	}
	closeSurvey();
}

function hideAllSurveyDivs()
{
 if(document.getElementById("divSurveyStep1"))
 {
   document.getElementById("divSurveyStep1").className="hide";	
 }
 if(document.getElementById("divSurveyStep2"))
 {
   document.getElementById("divSurveyStep2").className="hide";	
 }
 if(document.getElementById("divSurveyStep3"))
 {
   document.getElementById("divSurveyStep3").className="hide";	
 }			
}

function GetSurvey(SurveyID)
{
  var url = "../content/Survey.aspx";
  
  if(SurveyID!=null && SurveyID!='')
  	 url = url + "?Operation=GetSurvey&SurveyID=" + SurveyID + "&dummy=" + new Date().getTime();
  else
 	 url = url + "?Operation=GetSurvey&dummy=" + new Date().getTime();
 	 
  TrackSurvey("start",url);
  
  xmlHttp = GetXmlHttpObject(surveyStateChanged);
  xmlHttpPost(xmlHttp, url,"");
}

function surveyStateChanged()
{     
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
         strSurveyInformation = xmlHttp.responseText;
	     if(strSurveyInformation!=null && strSurveyInformation!="")
	     	RenderSuerveyForm(strSurveyInformation)
	     else
	        closeSurvey();       
    }
}
function NodeText(node)
{

	 if(window.ActiveXObject)
	 {
	   return node.text;
	 }
	 else
	 {
	   return node.textContent;
	 }
	 
}
function RenderSuerveyForm(surveyXML)
{
	var xmlDoc=loadXMLString(surveyXML);
	
	if(xmlDoc != null)
	{
	    
	  var surveyNode=SelectNodes(xmlDoc,'//Survey');
	  if(surveyNode!=null)
	  {
		 	var invitationContentNode = SelectNodes(xmlDoc,"//InvitationContent");
		 	if(document.getElementById("divInvitationContent"))
		 	{
		 	 document.getElementById("divInvitationContent").innerHTML=NodeText(invitationContentNode[0]); 
		 	}
		 	document.getElementById("hdnSurveyID").value=surveyNode[0].getAttribute("id");
		 	document.getElementById("hdnReofferSurvey").value=surveyNode[0].getAttribute("ReofferSurvey");
			document.getElementById("hdnOnSurveyExitEntry").value=surveyNode[0].getAttribute("LaunchOnEntryOrExit");
			var tabNode = SelectNodes(xmlDoc,'//Question');
			if(tabNode!=null)
			{
			     var question = "";
		         if(tabNode.length>0)
			     {
		
					document.getElementById('divSurveyQuestions').innerHTML= "";
					for (var i=0;i<tabNode.length;i++)
			  		{  
						question=NodeText(tabNode[i].childNodes[0]);   
			   			divQuestions = document.createElement('div');     
			   			var QuestionId= tabNode[i].getAttribute("id");
			   			
			   			var divQuestionID = "divQuestion_"+ QuestionId;
						// Type of control radio,checkbox
						var controlType = tabNode[i].getAttribute("type");
						var questionIndex = i + 1;
						question = "<table cellspacing='0' cellpadding='0' border='0'>" +
					                "<tbody>" +
					                  "<tr>" +
					                    "<td class='srvquestion'>" + questionIndex + ".&nbsp;&nbsp;</td><td class='srvquestion'>" + question + "</td>" +
					                  "</tr>" +
					                "</body>" +
					                "</table>";
					   	createDiv(divQuestionID,question);
			            var controlHTML="";
			            if(controlType=="Radio")
			            {
			                    controlHTML="";
			                    var answerNodes= SelectNodes(tabNode[i],"//Answer[@questionid='"+ QuestionId +"']");
				   				for(var childcount=0; childcount<answerNodes.length;childcount++)
				   				{
				   				
									//Answer text
									var strAnswer = NodeText(answerNodes[childcount]); 
				   					//Answer ID
									var strValue = answerNodes[childcount].getAttribute("id");
									var divRadioID = "rdo"+childcount;
				                                	var controlHTML=CreateRadio(divRadioID,strAnswer,strValue,QuestionId ); 
				  					createDiv(divRadioID,controlHTML,"srvanswer");
								}  
			   			}
						else if(controlType=="TextBox")
						{
						   controlHTML="";
						   controlHTML=CreateTextBox(QuestionId)
			                           createDiv("txt" + QuestionId, controlHTML,"srvquestion");
						}
			                       
					}
		         }
			}
		LaunchSurveyOnExtryOrExit();
	  }
	}
	else
	{
		closeSurvey();
	}
}

// script to exit survey popup

function LaunchSurveyOnExtryOrExit()
{
	if(document.getElementById("hdnOnSurveyExitEntry").value=="OnPageEntry" ||document.getElementById("hdnOnSurveyExitEntry").value== "OnSiteEntry")
	{
		if(document.getElementById("hdnOnSurveyExitEntry").value== "OnSiteEntry")
		{
			if(document.referrer.indexOf(document.domain)==-1)
				document.getElementById("divSurvey").className="display";
		}
		else
		{
			document.getElementById("divSurvey").className="display";
		}
	}
	else if(document.getElementById("hdnOnSurveyExitEntry").value=="OnPageExit" ||document.getElementById("hdnOnSurveyExitEntry").value== "OnSiteExit")
	{

		bindOnClickEvent();
	}
}


function bindOnClickEvent()
{
	  for (var i=0;i<document.links.length;i++)
	  {	
	    if(document.links[i].id!="hrefSurveyClose")
		{
		s = document.links[i];
        s.onclick= new Function("return ShowSurveyOnExit(this);");
        }
     }
}

function ShowSurveyOnExit(link)
{
	var currentURL = getURLWithoutQuerystring(window.location.href);
	var targetURL = getURLWithoutQuerystring(link.href);
	
	if(document.getElementById("hdnOnSurveyExitEntry").value=="OnPageExit")
	{
		if(currentURL != targetURL  && targetURL.indexOf("javascript")==-1)
		{
			    document.getElementById("hdnSurveyTargetURL").value=targetURL;
				document.getElementById("divSurvey").className="display";
				self.scrollTo(0, 0);
				return false;
		}
	}
	else if(document.getElementById("hdnOnSurveyExitEntry").value=="OnSiteExit")
	{
	  var strDomain = document.getElementById("hdnDomain").value.toLowerCase();
	  if(strDomain =="" || strDomain ==null)
	     strDomain =document.domain;
		if(targetURL.indexOf(strDomain.toLowerCase())==-1 && targetURL.indexOf("javascript")==-1)
		{
			    document.getElementById("hdnSurveyTargetURL").value=link.href;
				document.getElementById("divSurvey").className="display";
				self.scrollTo(0, 0);
				return false;
		}
	}
}
function getURLWithoutQuerystring(url)
{
   var lastIndex = url.indexOf("?");
   if(lastIndex==-1)
     return url.toLowerCase().replace("#","");
   else
     return url.substring(0,lastIndex).toLowerCase().replace("#","");
}

// end of script to exit survey popup

function createDiv(divid,innerhtml)
{
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id',"div" + divid);
	newdiv.innerHTML=innerhtml;
	document.getElementById('divSurveyQuestions').appendChild(newdiv);
}

function CreateRadio(id,text,AnswerID,QuestionID)
{
 var radioTemplate = "";
 radioTemplate = "<table class=''  cellspacing='0' cellpadding='0' border='0'>" +
                "<tbody>" +
                  "<tr>" +
                    "<td class='srvanswerrdo'><input type=radio text='"+ text  +"'  id="+QuestionID+id+" name=grpRadio"+QuestionID +" value="+AnswerID+" /></td><td class='srvanswertxt'><span id=span"+QuestionID+AnswerID+">"+ text + "</span></td>"+
                    "</tr>" +
                "</tbody>" +
            "</table>";
return radioTemplate;
}

function CreateTextBox(QuestionID)
{
 var radioTemplate = "";
 textBoxTemplate = "<table class=''  cellspacing='0' cellpadding='0' border='0'>" +
                "<tbody>" +
                  "<tr>" +
                    "<td class='srvanswerrdo'><input type='text' id='srvTxt"+ QuestionID +"' name='srvTxt"+ QuestionID +"' value='' \></td>" +
                    "</tr>" +
                "</tbody>" +
            "</table>";
return textBoxTemplate;
}

function submitSurvey()
{
	var sruveyResponse=getSurveyResponse();
	var surveyId=document.getElementById("hdnSurveyID").value;
    var url = "Survey.aspx";
	url = url + "?Operation=SubmitSurvey&SurveyId=" + surveyId + "&dummy=" + new Date().getTime();
	
	TrackSurvey("finish",url);
	
	xmlHttp = GetXmlHttpObject(surveySubmitStateChanged);
    xmlHttpPost(xmlHttp, url, "SruveyResponse=" + sruveyResponse);
	document.getElementById("srvSubmit").disabled=true;
}
function surveySubmitStateChanged()
{     
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
         status= xmlHttp.responseText;
	     if(status!="False" && xmlHttp.status==200)
	     {
			 moveToSurveyNext(3);
			 self.scrollTo(0, 0);
         }
         else
         {
          alert("Error while submitting the survey.");
         }
    }
}

function getSurveyResponse()
{
   var strResult="";
   var SelectedAnswerId ="";
   var strSurveyInputControls=getInputControls();
   var SurveyInputControls = strSurveyInputControls.split("//");
   for(count=0;count<SurveyInputControls.length;count++)
   {
 	
	if(SurveyInputControls[count].match("grpRadio"))
        {
		var radioControls=document.getElementsByName(SurveyInputControls[count]);
              
		var QuestionID =SurveyInputControls[count].substring(8,SurveyInputControls[count].length);
		var AnswerText ="";
		for(i=0; i<radioControls.length; i++)
		{
    			if (radioControls[i].checked == true)
			   {
      				SelectedAnswerId =radioControls[i].value;
      				AnswerText = document.getElementById("span"+QuestionID+SelectedAnswerId).innerHTML;
     			}
		}
		if(strResult =="")
		{
			strResult = "QuesID~"+QuestionID+"|"+"AnsID~"+SelectedAnswerId+"|AnsValue~" + AnswerText;
		}
		else
		{
			strResult += "^"+"QuesID~"+QuestionID+"|"+"AnsID~"+SelectedAnswerId+"|AnsValue~" + AnswerText;
		}
   	}
	else if(SurveyInputControls[count].match("srvTxt"))
    {
	        
		var answerValue=document.getElementById(SurveyInputControls[count]).value;
		var QuestionID=SurveyInputControls[count].substring(6,SurveyInputControls[count].length);

	    if(strResult =="")
		{
			strResult += "QuesID~"+QuestionID+"|"+"AnsID~|AnsValue~"+answerValue;
		}
		else
		{
			strResult += "^"+"QuesID~"+QuestionID+"|"+"AnsID~|AnsValue~"+answerValue;
		}
	}
  }
  return strResult;
}

function getInputControls()
{
	var stroutput;
	var strControls="";
	var controls = document.getElementsByTagName("Input");
	for(controlcount=0;controlcount<controls.length;controlcount++)
	{
		if(controls[controlcount].type == "radio" || controls[controlcount].type == "text")
		{
			strControlName=controls[controlcount].name;
			if(strControlName.match("grp"))
			{
		    		if(!strControls.match(strControlName))
		       		{
			   		if(strControls == "")
			    		{
						strControls += strControlName;
			    		}	
			    		else
			    		{
						strControls +="//"+strControlName;
			    		}
				}
			}
			else if(strControlName.match("srvTxt"))
			{
				if(strControls == "")
			    	{
					strControls += strControlName;
			    	}	
			    	else
			    	{
					strControls +="//"+strControlName;
			    	}
			}	
		}
	}
	return strControls;
 }
function setCookie(name, value, expires, path, domain, secure)
{
        document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function SelectNodes(xmlDoc, elementPath)
{
        if(window.ActiveXObject)
        {
            return xmlDoc.selectNodes(elementPath);
        }
        else
        {
           var xpe = new XPathEvaluator();
           var nsResolver = xpe.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
           var results = xpe.evaluate(elementPath,xmlDoc,nsResolver,XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
           var aNodes = new Array;
		   if (results != null)
		   {
		        var oElement = results.iterateNext();
		        while(oElement)
		        {
		            aNodes.push(oElement);
		            oElement = results.iterateNext();
		        }
		    }
           return aNodes;
        }
}

// End of survey script






//Calendar control

function ShowSelectedMonth(link,selectedIndex)
   {
     for(index=1;index<=12;index++)
     {
        if(index==selectedIndex)
        {
            document.getElementById("divMonth" + index ).style.display="block";
            document.getElementById("aMonth" + index ).className='selectedMonth';
            
        }
        else
        {
           document.getElementById("divMonth" + index ).style.display="none";
    document.getElementById("aMonth" + index ).className='';
        }
     }
   } 


//...................CrossSiteSearchCode............................................................


function Search(objId) 
  {
    var searchTerm = document.getElementById(objId);
    if (searchTerm.value != '') 
        {              
         document.forms[0].action = "CrossSiteSearchResults.aspx?k=" + escape(searchTerm.value);
         document.forms[0].submit();
         }
  }
//Script for OnlineRequestPage SSO Redirection

		function SetPOPLink(link,site)
		{
		    PFP_SetSsoLink(link,site);
			link.href=link.href + "&TargetPage=OnlineRequest.aspx";
			link.target="_blank"
		}
		function SetOnlineRequestPage(link)
		{
		    link.href="onlinerequest.aspx";
			link.className ="";
			link.disabled=false;
		}
		function SetSSORedirection(link,site,page)
		{
     	   switch(site)
		   {
		      case 'POP': {
		          if(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP')) 
		          	 PartnerLinkInquiryClicked(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP').value+"&TargetPage="+page, '');
			         window.open(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP').value+"&TargetPage="+page); 
		           break; 
		         }
		      case 'PMI':  {
		         if(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI'))
		            PartnerLinkInquiryClicked(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI').value+"&TargetPage="+page, '');
		         	window.open(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI').value+"&TargetPage="+page); 
		          break; 
		         }
           }
		}
		
		
		function SetSSORedirection2(link,site,page)
		{
     	   switch(site)
		   {
		      case 'POP': {
		          if(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP')) 
		          	 PartnerLinkInquiryClicked(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP').value+"&TargetPage="+page, '');
			         window.open(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP').value+"&TargetPage="+page); 
		           break; 
		         }
		      case 'PMI':  {
		         if(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI'))
		            PartnerLinkInquiryClicked(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI').value+"&TargetPage="+page, '');
		         	window.open(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI').value+"&TargetPage="+page); 
		          break; 
		         }
           }
		}

		
		function PFP_SetSsoLink(link,site)
		{
		   switch(site)
		   {
		      case 'POP': {
		          if(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP')) 
			         link.href = document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPOP').value; 
		           break; 
		         }
		      case 'PMI':  {
		         if(document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI'))
		         	link.href = document.getElementById('ctl00_contentMidLeft_PPNEnhSSOLinks_hdnSSOPMI').value; 
		         break; 
		         }
           }
		}
//End of script for OnlineRequestPage SSO Redirection


//-------- Unsubscribe the user...
function UnsubscribeUser()
{
     var objHdnOrch = document.getElementById("hdnOrchId");
     if(objHdnOrch != null)
     {
         objHdnOrch.value="PPNUnsubscribeUser";
	     document.forms[0].action="controller.aspx";
	     document.forms[0].submit();
	 }
}
function querySt(qSKey)
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) 
    {
        ft = gy[i].split("=");
        if (ft[0] == qSKey) 
        {
            return ft[1];
        }
    }
    return "";	
}
function getCampaignID()
{
    var hdnCampaignIDCtrl = document.getElementById("hdnCampaignID");
    if(hdnCampaignIDCtrl !=null)
    {
        hdnCampaignIDCtrl.value = querySt('CampaignID');
    }
}

function getProductFromUrl()
{
    var hdnproductname = document.getElementById("hdnProduct");
    if(hdnproductname !=null )
    {   
        hdnproductname.value = querySt("productcode");
    }
    //document.getElementById("hdnProduct").value = 'None';
}


function getUnSubscribePageWithQS()
{
    var hdnCurrentUrl = document.getElementById("hdnCurrentUrl");
    if(hdnCurrentUrl !=null)
    {
        var url = document.location.href;
        hdnCurrentUrl.value = url.substring(url.lastIndexOf("/")+1,url.length);
    }
}
//End Unsubscribe the user...
function ProductOption(productLink, productName) 
{
    this.ProductLink = productLink;
    this.ProductName = productName;
}
function SortProductOptions(a, b) 
{
    var x = a.ProductName.toLowerCase();
    var y = b.ProductName.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function PopulateSortedResourceProducts(nodeList,ddlProducts,category)
{
	var sortedArray = new Array();
	
	var optGroup = document.createElement("optgroup");
	optGroup.label = category;
	for (i=0;i<nodeList.length;i++)
	{
		if (nodeList[i].getAttribute("Name") != null && nodeList[i].getAttribute("Name") != "")
		{
			// Add the product to the array
			sortedArray.push(new ProductOption(nodeList[i].getAttribute("ProductLink"), nodeList[i].getAttribute("Name")));
		}
	}
	
	// Sort The Product Array
	sortedArray.sort(SortProductOptions);
	
	for (i=0;i<sortedArray.length;i++)
	{
		addOption(ddlProducts,sortedArray[i].ProductLink,"  " + sortedArray[i].ProductName, optGroup);
	}
}


