﻿function ShowHideUserComments(commentHideDivState, showDivState)
{    
    var commentDiv = document.getElementById('userComments');
    var showDiv = document.getElementById('ShowUserComment');
    var hideDiv = document.getElementById('HideUserComment');
    
    commentDiv.style.display = commentHideDivState;
    hideDiv.style.display = commentHideDivState;
    showDiv.style.display = showDivState;
    
}


var XMLHttpFactories = [
     function () {return new XMLHttpRequest()},
     function () {return new ActiveXObject("Msxml2.XMLHTTP")},
     function () {return new ActiveXObject("Msxml3.XMLHTTP")},
     function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
  var xmlhttp = false;
  for (var i=0;i<XMLHttpFactories.length;i++) {
    try {
            xmlhttp = XMLHttpFactories[i]();
    }
    catch (e) {
            continue;
    }
    break;
  }
  return xmlhttp;
}

function GetAssetid()
{
    var reg = /.*\/(\d\d\d\-\d\d\d\-\d\d\d).*/g;
    var assetid = '';
    if (reg.test(document.location.href))
    {
         assetid = document.location.href.replace(reg, "$1");
    }
    else
    {
        reg = /.*\/(\d+).*/g;
        assetid = document.location.href.replace(reg, "$1");
    }
    return assetid;
}

function HttpRequest(url, write)
{
    var req = false;
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
            try {
                            req = new XMLHttpRequest();
            } catch(e) {
                            req = false;
            }
        // branch for IE/Windows ActiveX version
        } else if(window.ActiveXObject) {
            try {
                    req = new ActiveXObject("Msxml2.XMLHTTP");
                   
            } catch(e) {
                    try {
                            req = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch(e) {
                            req = false;
                    }
                    }
        }
        
        try {
        //alert(url)
          req.open('GET', url, false); 
          req.send(null); 
          //alert(req.responseText)
          if (write)
            document.write(req.responseText); 
            
          return req.responseText;
         
        } 
        catch (e) { 
        //alert(e)
          return ""; 
          
        }
}
/*
function injectReadOnlyUserRating() { 
    var ord=Math.random()*10000000000000000;

    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();
    var theString = "/globalchunks/NewuserRatingReadOnly/" + assetid + "?HostingPageUrl=" + pageUrl + "&ord= " + ord;
    var text = HttpRequest(theString, false);
    var ratingDiv = document.getElementById('readOnlyRating');
    ratingDiv.innerHTML = text;
    }
    

    
function injectUserRating()
{
    var ord=Math.random()*10000000000000000;

    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();            
    var theString = "/globalchunks/NewuserRating/" + assetid + "?HostingPageUrl=" + pageUrl + "&ord= " + ord;
    var text = HttpRequest(theString, true);
}


function injectUserComments() { 
    var ord=Math.random()*10000000000000000;

    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();  
    var theString = "/globalchunks/UserComments/" + assetid + "?ord= " + ord;
    var text = HttpRequest(theString, false);
    var commentDiv = document.getElementById('userComments');
    document.getElementById('NoCommentsHeader').style.display = 'none'; 
    if (text.indexOf("Posted By") == -1)
    {
        document.getElementById('userCommentsHeader').style.display = 'none';                
        document.getElementById('NoCommentsHeader').style.display = 'block';   
    }
    else
        document.getElementById('userCommentsHeader').style.display = 'block';      
    commentDiv.innerHTML = text;
    }

*/


function injectReadOnlyUserRating(file) { 
    var ord = Math.random()*10000000000000000;
    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();
    var theString = file + assetid + "?HostingPageUrl=" + pageUrl + "&ord= " + ord;
    var text = HttpRequest(theString, false);
    var ratingDiv = document.getElementById('readOnlyRating');
    ratingDiv.innerHTML = text;
    }
    
function injectUserRating(file)
{
    var ord = Math.random()*10000000000000000;
    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();            
    var theString = file + assetid + "?HostingPageUrl=" + pageUrl + "&ord= " + ord;
    var text = HttpRequest(theString, true);
}


  
function injectUserComments(Page) { 
    var ord = Math.random()*10000000000000000;
    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();  
    var theString = "/globalchunks/UserComments.aspx/" + assetid + "?ord= " + ord + "&Page=" + Page;
    var text = HttpRequest(theString, false);
    var commentDiv = document.getElementById('userComments');
    document.getElementById('NoCommentsHeader').style.display = 'none'; 
    if (text.indexOf("Posted By") == -1)
    {
        document.getElementById('userCommentsHeader').style.display = 'none';                
        document.getElementById('NoCommentsHeader').style.display = 'block';   
    }
    else
        document.getElementById('userCommentsHeader').style.display = 'block';      
    commentDiv.innerHTML = text;
    scroll(0, 100)
    }    
  


function injectUserRatingArticle()
{
    var ord=Math.random()*10000000000000000;

    var pageUrl = window.location.pathname.replace(/\/preview\/\d+/i, "");
    var assetid = GetAssetid();            
    var theString = "/globalchunks/NewuserRatingArticle.aspx/" + assetid + "?HostingPageUrl=" + pageUrl + "&ord= " + ord;
    var text = HttpRequest(theString, true);
}
    
    
 function injectRegistration() 
 { 
    var ord=Math.random()*10000000000000000;
    var theString = "/globalchunks/Registration.aspx?ord= " + ord;
    HttpRequest(theString, true);
 }


function RefreshReadOnlyUserRating()
{
     injectReadOnlyUserRating("/globalchunks/NewuserRatingReadOnly.aspx/");
}


function AsynchronousPost(url)
{
  var rand = Math.random()*10000000000000000;
  url = url + '&rand=' + rand;
  if(window.XMLHttpRequest && !(window.ActiveXObject)) {
	try {
	  req = new XMLHttpRequest();
	} catch(e) {
	  req = false;
	}
	// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
	  try {
	  	  req = new XMLHttpRequest();
          if (req == null) {
    		req = new ActiveXObject("Msxml2.XMLHTTP");
            }
	} catch(e) {
	   try {
		  req = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch(e) {
			req = false;
		  }
	   }
	 }
	 try {
	  req.open('GET', url, false); 
	  req.send(null); 
	  } 
	 catch (e) { 
	 }

}
