﻿var xmlHttp;
var xmlHttpobj;


function callAJAX()
{
  xmlHttp=GetXmlHttpObject();
  var type= document.addcommentForm.contentType.value;
  var landingpage= document.addcommentForm.page.value;
  var contitle= document.addcommentForm.contenttitle.value;
  var comment= document.addcommentForm.comment.value;
  var dbcomment= document.addcommentForm.dbcomment.value;
  
if(type=="Blog")
{
 var url="/cps/rde/xchg/pershing-llc/xml-files/blog-insert.xml";

}
else
{
  var url="/cps/rde/xchg/pershing-llc/xml-files/comments-insert.xml";

}
  var querystring="landing-page="+landingpage+"&contenttitle="+contitle+"&comment="+escape(comment)+"&contentType="+type+"&dbcomment="+escape(dbcomment);
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("POST", url, true);
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send(querystring);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
  if (xmlHttp.status==200)
  {
     var xmlDoc=xmlHttp.responseXML.getElementsByTagName("result")[0];
     var result = xmlDoc.childNodes[0].nodeValue;
     if(result=='success')
      {
        document.getElementById("txtHint").innerHTML= "<span style='color:green'><b>Thank You for your Comments</b></span>";
        document.getElementById('comment').value="";
        document.getElementById('commentsCheckbox').checked=false;
     }
     else
     {
      document.getElementById("txtHint").innerHTML= "<span style='color:red'>Please Try Again Later</span>";
      document.getElementById('comment').value="";
      document.getElementById('commentsCheckbox').checked=false;
     }
  }
  else
  {
   document.getElementById("txtHint").innerHTML= "<span style='color:blue'>Please Wait.Submitting Your Comments...</span>";
  }
}
else
{
  document.getElementById("txtHint").innerHTML= "<span style='color:blue'>Please Wait.Submitting Your Comments...</span>";
}
}

function GetXmlHttpObject()
{
 var xmlHttp=null;
 try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
 catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function validate()
{
 if(CommentsValidation())
 {
  if(privacyCheck())
 {
  callAJAX();
  return true;
  }
 }
 return false;
}
 


//Most Viewed and Most Emailed Insertions

function callAjaxForMostDocs()
{
  xmlHttp=GetXmlHttpObject();
  var type= document.addcommentForm.contentType.value;
  var page= document.addcommentForm.page.value;
  var contitle= document.addcommentForm.contenttitle.value;
    
  var url="/cps/rde/xchg/pershing-llc/xml-files/most-viewed-insert.xml";
  var querystring="page="+page+"&contenttitle="+contitle+"&contentType="+type;
  xmlHttp.onreadystatechange=stateChangedForMostDocs;
  xmlHttp.open("POST", url, true);
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlHttp.send(querystring);
}
function stateChangedForMostDocs() 
{ 
if (xmlHttp.readyState==4)
{ 
  if (xmlHttp.status==200)
  {
     var xmlDoc=xmlHttp.responseXML.getElementsByTagName("result")[0];
     var result = xmlDoc.childNodes[0].nodeValue;
     if(result=='success')
      {
        document.getElementById("txtHint").innerHTML= "<span style='color:green'><b>Thank You for your Comments</b></span>";
        document.getElementById('comment').value="";
        document.getElementById('commentsCheckbox').checked=false;
     }
     else
     {
      document.getElementById("txtHint").innerHTML= "<span style='color:red'>Please Try Again Later</span>";
      document.getElementById('comment').value="";
      document.getElementById('commentsCheckbox').checked=false;
     }
  }
 }
}