﻿// JScript File
var BookDetails="";
var checksetting=false;
var checkthumb = false;
var XMLPath = '../BookContent/Flipbooks/';
var DatacenterPath = 'http://c95871.r71.cf3.rackcdn.com/';
// global flag
var isIE = false;

// global request and XML document objects
var DetxmlHttp;
var XMLxmlHttp;
var downloadxmlHttp;
var  XMLTrue='False';

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file

var ShopiconShow='all';
var parameter='id';
var paramshoplinkNumbers='shoplinkNumbers';
var BookInfo='False'
var Bib_ID = "";
var bib_Loc = "0";

  function GetbookDetails()
  { 
      if(BookInfo=='False'){
         var id=document.getElementById("hdnbookID").value;
         var CMM_ID="";
       if(document.getElementById("hdnCMM_ID").value!="")
         CMM_ID="&CMM_ID="+ document.getElementById("hdnCMM_ID").value;
         
        var url="bookDetails.aspx?ID=" + id +""+ CMM_ID;
          DetxmlHttp=GetXmlHttpObject(stateChangedbookdetails);
          DetxmlHttp.open("GET", url , true);
          DetxmlHttp.send(null);
      }
  }
  function stateChangedbookdetails() { 
      if (DetxmlHttp.readyState==4 || DetxmlHttp.readyState=="complete"){
         BookDetails=DetxmlHttp.responseText;
      var elem = BookDetails.split('^');
        pageTitle( ':: '+elem[0]);//title
        ChageMetaTagbyname(elem[0],elem[2],elem[1]);
        document.getElementById("hdnbookID").value=elem[4];
        Bib_ID=elem[4];
        BookInfo='True';
        //Read Book XML File
        bib_Loc = elem[5];
        document.getElementById("hdnLoc").value = elem[5];
        if (bib_Loc == "1")
            DatacenterPath = '../BookContent/Flipbooks/';
        GetXML(Bib_ID);
      }
}
function GetFileDownload(id) {
   
        var url = "Idnwlod.aspx?ID=" + id ;
         //var url = "Idnwlod.aspx?ID=" + id + "&Bookurl=" + encodeURIComponent(location) + "&title=" + title;
        downloadxmlHttp = GetXmlHttpObject(stateChangeddownload);
        downloadxmlHttp.open("GET", url, true);
        downloadxmlHttp.send(null);
   
}
function stateChangeddownload() {
    if (downloadxmlHttp.readyState == 4 || downloadxmlHttp.readyState == "complete") {
    }
}
var deletexmlHttp;
function deletFileDownload(id)
{
   
        var url = "Idnwlod.aspx?ID=" + id +"&ac=del";
         //var url = "Idnwlod.aspx?ID=" + id + "&Bookurl=" + encodeURIComponent(location) + "&title=" + title;
        deletexmlHttp = GetXmlHttpObject(stateChangeddelet);
       deletexmlHttp.open("POST", url, true);
       deletexmlHttp.send(null);
   
}
function stateChangeddelet() {
    if (deletexmlHttp.readyState == 4 || deletexmlHttp.readyState == "complete") {
    }
}

  function GetXML(id)
  { 
      if(XMLTrue=='False'){
          var url = XMLPath + id + '_assets/xml/' + id + '_content1.xml';
          XMLxmlHttp=GetXmlHttpObject(stateChangedXML);
           XMLxmlHttp.open("GET", url , true);
           XMLxmlHttp.send(null);
      }
  } 
function stateChangedXML() { 
      if ( XMLxmlHttp.readyState==4 ||  XMLxmlHttp.readyState=="complete"){
        buildTopicList();
        XMLTrue='True';
      }
  } 
function queryString1() { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;
  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
          if (param_value.indexOf("(")!=-1)
          {
            document.getElementById("hdnbookID").value=RetriveBOOK_ID(param_value);
            document.getElementById("hdnCMM_ID").value=RetriveCommunityID(param_value);
          }
          else
          {
             document.getElementById("hdnbookID").value=param_value;
             document.getElementById("hdnCMM_ID").value="";
         }
         GetFileDownload(document.getElementById("hdnbookID").value);
      }
      // Get hoplinkNumbers=all/none
        if (param_name == paramshoplinkNumbers) {
          ShopiconShow = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {

  }}
  function RetriveCommunityID(ID)
  {
    if (ID.indexOf("(")!=-1)
    {
        var elem = ID.split('(');
        var elemCMM=elem[1].split(')');
        var CMM_ID=elemCMM[0];
        return CMM_ID;
    }
    else
      return ID;
  }
  function RetriveBOOK_ID(ID)
  {
    if (ID.indexOf("(")!=-1)
    {
        var elem = ID.split('(');
        var BOOK_ID=elem[0];
        return BOOK_ID;
    }
    else
      return ID;
  }
//  function loading_iframe()
// {
//// var i, frames;
////frames = document.getElementsByTagName("iframe");
//////alert('ok') 
////for (i = 0; i < frames.length; ++i)
////{
////  alert('ok')    // The iFrame
////    //frames[i].style.display = "none";
//////    var x = $('iframe').val();
//////    $(x).contents().andSelf().children().get()
//////alert(x.lenght);
////  
////    var fbiframeclassname="fbLikeContainer";
////      var eln=  $('iframe > *');
////    alert(eln.length);
////    var str="";
////     for(var j = 0; j < eln.length; j++)
////        {
////      
////            str += "<b>Type:</b>" + eln[j].type + "&nbsp&nbsp";
////            str += "<b>Name:</b>" + eln[j].name + "&nbsp;&nbsp;";
////            str += "<b>Value:</b><i>" + eln[j].value + "</i>&nbsp;&nbsp;";
////            str += "<BR>";
////        } 
////       alert(str);

//////    eln.
////  alert(eln.contents().find('span').innerHTML)

//}


// 
// }
  
function loadXMLDoc() {
    try {
        
    queryString1();
    GetbookDetails();
    GetIlike();
  
    
 
    }
     catch(e) { return;}
     
      //loading_iframe();
  
}
// invoked by "Category" select element change;
// loads chosen XML document, clears Topics select
// element, loads new items into Topics select element
function loadDoc(evt) {
    // equalize W3C/IE event models to get event object
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        // equalize W3C/IE models to get event target reference
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
            try {
                if (elem.selectedIndex > 0) {
                    loadXMLDoc(elem.options[elem.selectedIndex].value);
                }	
            }
            catch(e) {
                var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
                alert("Unable to get XML data:\n" + msg);
                return;
            }
        }
    }
}

// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}
// add item to select element the less
// elegant, but compatible way.
// fill Topics select list with items from
// the current XML document
function buildTopicList() {
  
	var items = XMLxmlHttp.responseXML.getElementsByTagName("page");
	var content;
    //	var BookID=document.getElementById("hdnbookID").value//'TkbMc2KIKe';
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
	var active=1;
	document.getElementById("documentArea").innerHTML = "";
	div = document.getElementById("documentArea");
	    TotPage(items.length);
	    var CoverFullpath = DatacenterPath + Bib_ID + '_assets/images/' + Bib_ID + '_Zoom.jpg';
         var thumbCoverFullpath = DatacenterPath + Bib_ID + '_assets/images/' + Bib_ID + '_thumbNail.jpg';
	    var CoverimgTag = document.createElement("div");
	    var Coverimg = document.createElement("input");
	var ThumbCoverimgTag = document.createElement("img");
	    ThumbCoverimgTag.setAttribute('onclick', 'GoPage(-1)');
	    ThumbCoverimgTag.setAttribute("src", thumbCoverFullpath);
	   // BookcoverPage.Style.Add("background-image", "url(BookContent/Flipbooks/" + Bookid + "_assets/images/" + Bookid + "_thumbNail.jpg);");
	  
    var divthumb=document.createElement("div");
    var imgdivthumbnum= document.createElement("div"); 
        divthumb.className="divcon";
        imgdivthumbnum.className="pnum";
        imgdivthumbnum.innerHTML = "Cover";
            
        divthumb.appendChild(ThumbCoverimgTag);
        divthumb.appendChild(imgdivthumbnum);

        CoverimgTag.setAttribute("id", "page1");
        CoverimgTag.setAttribute("class", "page");
      
       // CoverimgTag.setAttribute("rel", "tooltip1");

        Coverimg.setAttribute("type", "image");
      // Coverimg.setAttribute("style" , "width: 950px; height: 1231px;");
        Coverimg.setAttribute("src", CoverFullpath + "?1316676683");
        Coverimg.setAttribute("original", CoverFullpath + "?1316676683");
        Coverimg.setAttribute("rel", "tooltip");
        CoverimgTag.appendChild(Coverimg);
        div.appendChild(CoverimgTag);

        document.getElementById("BookcoverPage").style.background ='url('+thumbCoverFullpath+')';
	  
    var slidsize=7;
    var Pages=0;
    if(test1(items.length/slidsize)){
       Pages=parseInt(items.length/slidsize)
    }
    else{
        Pages=parseInt(items.length/slidsize)+1;
    }
    var firstpage=1
	var ULid = document.getElementById("thunmulid");
	    ULid.innerHTML = "";
	var slidnum=1;
	var lislidTag ;
	var linum=1;
	var imgadded=1;
	var lislidTag = document.createElement("li");
        lislidTag.appendChild(divthumb);
     var j=2;
    for (var i = 0; i < items.length; i++) {
   
		content= getElementTextNS("", "background", items[i], 0);
		var Fullpath = DatacenterPath + Bib_ID + '_assets/images/thubmnail/' + content;
		var originalFullpath = DatacenterPath + Bib_ID + '_assets/images/zoom/' + content;
		if (i == 0) {
		    Fullpath = originalFullpath;
        }
		var divTag = document.createElement("div");
		divTag.setAttribute("id", "page" + (j + i));
		divTag.setAttribute("class", "page");
		divTag.setAttribute("style", "width: 960px; height: 1340px;");
		//divTag.setAttribute("rel", "tooltip" + (j + i));
		var imgTag = document.createElement("input");
		    imgTag.setAttribute("type", "image");
		   // imgTag.setAttribute("src", "img/grey.gif?1316676683");
		    imgTag.setAttribute("src", Fullpath + "?1316676683");
		    imgTag.setAttribute("style", "width: 960px; height: 1340px;");
		    imgTag.setAttribute("original", originalFullpath + "?1316676683");
		    imgTag.setAttribute("alt", "loading");
		    imgTag.setAttribute("rel", "tooltip");
		    divTag.appendChild(imgTag);
		    div.appendChild(divTag);

			Fullpath = DatacenterPath + Bib_ID + '_assets/images/thubmnail/' + content;
		    var imgslidTag = document.createElement("img"); //<img src="../example/images/thumb1st.png" />
		    imgslidTag.setAttribute("src", Fullpath);
		    imgslidTag.setAttribute('onclick', 'GoPage(' + i + ')');
		    imgslidTag.setAttribute("alt", "");
		    var imgdiv = document.createElement("div"); //;margin-left:2px;margin-right:2px;
		    var imgdivnum = document.createElement("div"); //;margin-left:2px;margin-right:2px;
		    imgdiv.className = "divcon";
		    imgdivnum.className = "pnum";
		    imgdivnum.innerHTML = i + 1;
		    imgdiv.appendChild(imgslidTag);
		    imgdiv.appendChild(imgdivnum);

		    if (firstpage == 1) {
		        if (imgadded < slidsize) {
		            if (slidnum < slidsize) {
		                slidnum = parseInt(slidnum + 1);
		                lislidTag.appendChild(imgdiv);
		            }
		            else if (slidnum == slidsize) {
		                slidnum = 1;
		                lislidTag.appendChild(imgdiv);
		            }
		            imgadded = parseInt(imgadded + 1);
		        }
		        else {
		            slidnum = 1;
		            imgadded = 2;
		            lislidTag = document.createElement("li");
		            lislidTag.appendChild(imgdiv);
		            firstpage = parseInt(firstpage + 1);
		        }
		    }
		    else {
		        if (imgadded < 8) {
		            if (slidnum < slidsize) {
		                slidnum = parseInt(slidnum + 1);
		                lislidTag.appendChild(imgdiv);
		            }
		            else if (slidnum == slidsize) {
		                slidnum = 1;
		                lislidTag.appendChild(imgdiv);
		            }
		            imgadded = parseInt(imgadded + 1);
		        }
		        else {
		            slidnum = 1;
		            imgadded = 2;
		            lislidTag = document.createElement("li");
		            lislidTag.appendChild(imgdiv);
		            firstpage = parseInt(firstpage + 1);
		        }
		    }
		    ULid.appendChild(lislidTag);
    }
    // clear detail display
 

		//$("input:image").lazyload({ placeholder: "img/grey.gif", effect: "fadeIn" });

		$("#documentArea input:image").lazyload({placeholder: "img/grey.gif", container: $("#documentArea") });

		//Select all anchor tag with rel set to tooltip
		$('input[rel=tooltip]').mouseover(function (e) {


		    // var parentTag = $(this).parent().get(0).tagName;
		    // alert("mouseover");
		    // alert($(this).parent().get(0).id);
		    document.getElementById("hdnlP").value = $(this).parent().get(0).id.replace("page", "");
		    // alert(document.getElementById("hdnlP").value);
		    //Grab the title attribute's value and assign it to a variable
		    /*var tip = $(this).attr('title');

		    //Remove the title attribute's to avoid the native tooltip from the browser
		    $(this).attr('title', '');

		    //Append the tooltip template and its value
		    $(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');

		    //Show the tooltip with faceIn effect
		    $('#tooltip').fadeIn('500');
		    $('#tooltip').fadeTo('10', 0.9);*/
		   // console.log(parseInt(document.getElementById("hdnlP").value));
		}).mousemove(function (e) {

		    /*  //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		    $('#tooltip').css('top', e.pageY + 10);
		    $('#tooltip').css('left', e.pageX + 20);
		    */
		   
		    document.getElementById("hdnlP").value = $(this).parent().get(0).id.replace("page", "");
		   // console.log(parseInt(document.getElementById("hdnlP").value));
		}).mouseout(function () {

		    /* //Put back the title attribute's value
		    $(this).attr('title', $('.tipBody').html());

		    //Remove the appended tooltip template
		    $(this).children('div#tooltip').remove();
		    */
		    // var parentTag = $(this).parent().get(0).tagName;
		    //alert("mouseout");
		    //alert($(this).parent().get(0).id);
		    document.getElementById("hdnlP").value = $(this).parent().get(0).id.replace("page", "");
		    //  alert(document.getElementById("hdnlP").value);
		    //console.log(parseInt(document.getElementById("hdnlP").value));
		});



		$("#slider").easySlider();


   deletFileDownload(document.getElementById("hdnbookID").value);
}

function test1(str) {
   return /^ *[0-9]+ *$/.test(str);
}
function roundNumber(number,decimal_points) {
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
	   var decimals = "";
	   for(var i=0;i<decimal_points;i++) decimals += "0";
	   return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}
function TotPage( tP)
{
    //hdntP
	document.getElementById("hdntP").value=tP;
	//document.getElementById("PRVID").style.cursor="default";
	//document.getElementById("NXTID").style.cursor="pointer";
}
   var img = new Image();

function NextPage()
{
    document.getElementById('thumbid').style.visibility='hidden';
    document.getElementById('settingid').style.display='none';
   
    var ThumbE=document.getElementById('thmID');
    var SetE=document.getElementById('setid');
        RemoveClassName(ThumbE,'bttnThumbclick');
        AddClassName(ThumbE,'bttnThumbnormal',true);
        RemoveClassName(SetE,'bttnSttngclick');
        AddClassName(SetE,'bttnSttngnormal',true);
    
    //hdnlP
    if(parseInt(document.getElementById("hdnlP").value)<parseInt(document.getElementById("hdntP").value)-1)
    {
         //document.getElementById("PRVID").style.cursor="pointer";
         var lP=document.getElementById("hdnlP").value;
         var Dimg= document.getElementById("page"+lP)
             Dimg.style.display='none';
             document.getElementById("hdnlP").value=parseInt(document.getElementById("hdnlP").value)+1;
             lP=document.getElementById("hdnlP").value;
         
         var Aimg=document.getElementById("page"+lP);
         var Fullpath=Aimg.src;//'../BookContent/Flipbooks/'+BookID+'_assets/images/thubmnail/'+content;
             Aimg.style.display='block';
         var myNewString =  Fullpath.replace("/thubmnail/", "/zoom/");
             Aimg.setAttribute("src",myNewString);
            Aimg.setAttribute("width","100%");
            Aimg.setAttribute("height","100%");
//            Aimg.removeAttribute("width");
//	    Aimg.removeAttribute("height");
           img.src = myNewString;
            img.onload = function() {
            //alert(this.width + 'x' + this.height);
            Aimg.setAttribute("width",this.width );
            Aimg.setAttribute("height",this.height);
            }
         


//            var width =Aimg.width;
//            var height = Aimg.height
//            alert("width:"+width+"height:"+height);
           
            var av=parseInt(lP)+1;
            var Avimg=document.getElementById("page"+av);
          if(Avimg!=null){
              var adFullpath=Avimg.src;
              var admyNewString =  adFullpath.replace("/thubmnail/", "/zoom/");
                  Avimg.setAttribute("src",admyNewString);
                
          }
    }
    else
      document.getElementById("NXTID").style.cursor="default";
}

function Next() {
    document.getElementById('thumbid').style.visibility = 'hidden';
    document.getElementById('settingid').style.display = 'none';

    var ThumbE = document.getElementById('thmID');
    var SetE = document.getElementById('setid');
    RemoveClassName(ThumbE, 'bttnThumbclick');
    AddClassName(ThumbE, 'bttnThumbnormal', true);
    RemoveClassName(SetE, 'bttnSttngclick');
    AddClassName(SetE, 'bttnSttngnormal', true);

    //hdnlP
   
     //   document.getElementById("hdnlP").value = parseInt(document.getElementById("hdnlP").value) + 1;

   
}
function PriPage()
{
    document.getElementById('thumbid').style.visibility='hidden';
    document.getElementById('settingid').style.display='none';
    var ThumbE=document.getElementById('thmID');
    var SetE=document.getElementById('setid');
        RemoveClassName(ThumbE,'bttnThumbclick');
        AddClassName(ThumbE,'bttnThumbnormal',true);
        RemoveClassName(SetE,'bttnSttngclick');
        AddClassName(SetE,'bttnSttngnormal',true);
    
    //hdnlP
    if(document.getElementById("hdnlP").value!="-1") {
       // document.getElementById("NXTID").style.cursor="pointer";
        var lP=document.getElementById("hdnlP").value;
        var Dimg= document.getElementById("page"+lP)
            Dimg.style.display='none';
            document.getElementById("hdnlP").value=parseInt(document.getElementById("hdnlP").value)-1;
            lP=document.getElementById("hdnlP").value;
         
        var Aimg=document.getElementById("page"+lP);
            Aimg.style.display='block';
        var Fullpath=Aimg.src;//'../BookContent/Flipbooks/'+BookID+'_assets/images/thubmnail/'+content;
        var myNewString =  Fullpath.replace("/thubmnail/", "/zoom/");
            Aimg.setAttribute("src",myNewString);
            
    }
    else{
       // document.getElementById("PRVID").style.cursor="default";
    }
}
function display(lP){
    var cp="page"+lP;
    var nP="page"+parseInt(lP+1,0);
    var imgCurrent=document.getElementById(cp)
    var imgNext=document.getElementById(np)
        imgCurrent.style.display =  "none";
        imgNext.style.display = "block";
}


//function removeElement(divNum) {
//  var d = document.getElementById('myDiv');
//  var olddiv = document.getElementById(divNum);
//  d.removeChild(olddiv);
//}

//function addElement() {
//  var ni = document.getElementById('myDiv');
//  var numi = document.getElementById('theValue');
//  var num = (document.getElementById('theValue').value -1)+ 2;
//  numi.value = num;
//  var newdiv = document.createElement('div');
//  var divIdName = 'my'+num+'Div';
//  newdiv.setAttribute('id',divIdName);
//  newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';
//  ni.appendChild(newdiv);
//}



function thumb(){
settingvisibility('defaultid')
    var setdiv= document.getElementById('settingid');
        setdiv.style.display='none';
    var thumbid=document.getElementById('thumbid');
    //visibility:hidden;
    if(thumbid.style.visibility=='hidden'){
        checkthumb=false;
        thumbid.style.visibility='visible';}
    else{
        checkthumb=true;
        thumbid.style.visibility='hidden';}
}
function setting(){
//settingid
settingvisibility('defaultid')
    var setdiv= document.getElementById('settingid');
    if(setdiv.style.display=='none'){
      setdiv.style.display='block';
      checksetting=false;}
    else{
      setdiv.style.display='none';
      checksetting=true;}
   
    var thumbid=document.getElementById('thumbid');
        thumbid.style.visibility='hidden';
}
function settingvisibility(objid){
//infoID
    var setdiv= document.getElementById(objid);
    var infoID=document.getElementById('infoID');
    var sonetid=document.getElementById('sonetid');
    var bookmkid=document.getElementById('bookmkid');
    var emdID=document.getElementById('emdID');
    var shid=document.getElementById('shid');
    var fbid=document.getElementById('fbid');
    var videoid=document.getElementById('videoid');
    var audioid=document.getElementById('audioid');
    var ratingID=document.getElementById('ratingID');
    var RecID=document.getElementById('RecID');
    var zoomSettingID=document.getElementById('zoomSettingID');
    
        infoID.style.display='none';
        sonetid.style.display='none';
        bookmkid.style.display='none';
        emdID.style.display='none';
        shid.style.display='none';
        fbid.style.display='none';
        videoid.style.display='none';
        audioid.style.display='none';
        ratingID.style.display='none';
        RecID.style.display='none';
        zoomSettingID.style.display='none';
    if(setdiv!=null){
        if(setdiv.style.display=='none')
           setdiv.style.display='block';
        else
           setdiv.style.display='none';
       //display shoplink Panel     
       if(ShopiconShow=='none')
         shid.style.display='none';
        }
  OrgClass(objid);
}
function OrgClass(objID){
 var removeclassString='orngBttn';
 var AddclassString='orngClckBttn';
    
    document.getElementById('tbsoci').className='grayBttn';
    document.getElementById('tbinfo').className='grayBttn';
    document.getElementById('tbbookmrk').className='grayBttn';
    document.getElementById('tbrating').className='grayBttn';
    document.getElementById('tbzoom').className='grayBttn';
    document.getElementById('tbembed').className='grayBttn';
    document.getElementById('tbshop').className='grayBttn';
    document.getElementById('tbfb').className='grayBttn';
    document.getElementById('tbvdo').className='grayBttn';
    document.getElementById('tbaudio').className='grayBttn';
    document.getElementById('tbdoublepage').className='grayBttn';
    document.getElementById('tbrec').className='grayBttn';
    //document.getElementById('zoomSettingID').className='grayBttn';
    
   
    switch(objID)
    {
    case 'infoID':
        var setdiv= document.getElementById('tbinfo');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'sonetid':
        var setdiv= document.getElementById('tbsoci');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'bookmkid':
        var setdiv= document.getElementById('tbbookmrk');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'emdID':
        var setdiv= document.getElementById('tbembed');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'shid':
        var setdiv= document.getElementById('tbshop');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'fbid':
        var setdiv= document.getElementById('tbfb');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'videoid':
        var setdiv= document.getElementById('tbvdo');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'audioid':
        var setdiv= document.getElementById('tbaudio');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'ratingID':
        var setdiv= document.getElementById('tbrating');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'ZoomID':
        var setdiv= document.getElementById('tbzoom');
        AddClassName(setdiv,AddclassString,true);
        ZoomDisplay();
        break;
    case 'DoublepageID':
        var setdiv= document.getElementById('tbdoublepage');
        AddClassName(setdiv,AddclassString,true);
        break;
    case 'RecID':
        var setdiv= document.getElementById('tbrec');
        AddClassName(setdiv,AddclassString,true);
        break;
    default:
      break;
    }
}
function ZoomDisplay()
{
//zoomSettingID
       var setdiv= document.getElementById('settingid');
       var zoomSettingID= document.getElementById('zoomSettingID');
           setdiv.style.display='none';
           zoomSettingID.style.display='block';
}
function GoPage(pn){
     //hdnlP
       var hidpage=document.getElementById("hdnlP").value
       document.getElementById("hdnlP").value=parseInt(pn);
       var no = parseInt(document.getElementById("hdnlP").value)+1;
      // alert(no);
       $("#documentArea").scrollTo(parseInt(no * 1340), 0);
}
// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // we found it
            return true;

            }

         }

      }

   // if we got here then the class name is not there
   return false;

   }
// 
// HasClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {

         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {

            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {

               // remove array item
               arrList.splice(i, 1);

               // decrement loop counter as we have adjusted the array's contents
               i--;

               }

            }

         }

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   else
      {

      // assign modified class name attribute      
      objElement.className = strClass;
   
      }

   }
// 
// AddClassName
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

   }
// 
// RemoveClassName
// ----------------------------------------------------------------------------
 //var checksetting=false;
function resetSetting(elemnt,classname){
    if(checksetting){
     elemnt.className=classname;}
}

function resetcheckthumb(elemnt,classname){
    if(checkthumb){
     elemnt.className=classname;}
}
function ChageMetaTagbyname(new_keywords,new_description,new_Author)
{
//alert(new_keywords);
$('meta[name=Keywords]').attr('Keywords', new_keywords);
$('meta[name=Keywords]').attr('content', new_keywords);
$('meta[name=Description]').attr('Description', new_description);
$('meta[name=Description]').attr('content', new_description);
$('meta[name=Author]').attr('Author', new_Author);
$('meta[name=Author]').attr('content', new_Author);
}
engine = null;
function checkIE()
{
    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
       // This is an IE browser. What mode is the engine in?
       if (document.documentMode) // IE8
          engine = document.documentMode;
       else // IE 5-7
       {
          engine = 5; // Assume quirks mode unless proven otherwise
          if (document.compatMode)
          {
             if (document.compatMode == "CSS1Compat")
                engine = 7; // standards mode
          }
       }
        alert(engine);
       // the engine variable now contains the document compatibility mode.
    }

}
var sTargetURL = "redirectiontarget.htm";

function doRedirect()
{
    //  The JavaScript 1.0 version of this function supports
    //  browsers that don't have the ability to replace this
    //  file in the browser history.  As a result we want to
    //  make sure that we briefly delay so when the visitor
    //  is moving back through their browser-history they
    //  will have time to press the back-button on this page
    //  before the script moves them to the redirection
    //  target page again.
    //
    //  Notice that we have the timeout the same amount as in
    //  the meta-refresh version.
    //
    setTimeout( "window.location.href = sTargetURL", 2*1000 );
    
    //  The 2*1000 equals 2 seconds.
}
//  Browsers that support JavaScript 1.1 will replace the
//  earlier definition of doRedirect defined in the
//  JavaScript 1.0 code block.  Make sure that this
//  definition appears after the 1.0 definition in the file.
//
function doRedirect()
{
    //  JavaScript 1.1 added the 'replace' function on the
    //  location object so we can change locations without
    //  adding to the browser's history.
    //
    window.location.replace( sTargetURL );
}

//  Just to be a bit fun -- we call the doRedirect function
//  directly here.  This means that it is called before the
//  page fully loads.  If your visitor is using a later
//  browser, then they will most likely not even see any of
//  "this" page at all.
//
//doRedirect();

//-->
function timedRedirect()
{
    window.location.replace( sTargetURL );
}
function pageTitle(pagetitle)
{
document.title = "Book2look "+ pagetitle;
}
function bookmark()
{
    var elem = BookDetails.split('^');
    var title=elem[0];
    var sitename="book2look :: "+title;
   // alert("in fn bookmark    "+navigator.appName+"\n url is   "+url)
    //ns="Netscape and FireFox users, use CTRL+D to bookmark this site."
   	if (window.sidebar) // firefox
   	{
   	    url = window.location;
        window.sidebar.addPanel(sitename, url, "");
    }
    else if(window.opera && window.print)
    { // opera
       alert("You Need to Click Ctrl + D to bookmark this page");     
    } 
    else if(navigator.appName)
    { 
       alert("You Need to Click Ctrl + D to bookmark this page");     
    } 
    else if(document.all)// ie
    {
        url = window.location;
        window.external.AddFavorite(url, sitename);
    }
}


var InfoTrue = 'False'
var AudioTrue = 'False'
var VideoTrue = 'False'

var socialntTrue='False';
var BookmarkTrue='False';
var EmbededTrue='False';
var RatingTrue='False';
var IlikeTrue='False';
var ShopTrue='False';


var infoxmlHttp;
var AudioxmlHttp;
var VideoxmlHttp;
var socialxmlHttp;

var BookmarkxmlHttp;
var EmbededxmlHttp;
var RatingxmlHttp;
var IlikexmlHttp;
var ShopxmlHttp;
function Getinfo()
  { 
      if(InfoTrue=='False'){
          var id=Bib_ID;
          var url="info.aspx?ID=" + id ;
              infoxmlHttp=GetXmlHttpObject(stateChangedinfo);
              infoxmlHttp.open("GET", url , true);
              infoxmlHttp.send(null);
      }
  } 
function stateChangedinfo() { 
      if (infoxmlHttp.readyState==4 || infoxmlHttp.readyState=="complete"){
            document.getElementById('infID').innerHTML="";
            document.getElementById('infID').innerHTML=infoxmlHttp.responseText;
            InfoTrue='True';
      }
  } 
 
  function GetSocialnet()
  { 
      if(socialntTrue=='False'){
          var elem = BookDetails.split('^');
          var title=elem[0];
          var id=Bib_ID;
          var url="socialnt.aspx?ID=" + id +"&Bookurl="+ encodeURIComponent(location) + "&title=" + title ;
              socialxmlHttp=GetXmlHttpObject(stateChangedsocial);
              socialxmlHttp.open("GET", url , true);
              socialxmlHttp.send(null);
      }
  } 
function stateChangedsocial() { 
      if (socialxmlHttp.readyState==4 || socialxmlHttp.readyState=="complete"){
            document.getElementById('socialdisplay').innerHTML="";
            document.getElementById('socialdisplay').innerHTML=socialxmlHttp.responseText;
            socialntTrue='True';
      }
  } 
  
function GetBookmark()
{ 
     if(BookmarkTrue=='False'){
          var elem = BookDetails.split('^');
          var title=elem[0];
          var id=Bib_ID;
          var url="Bookmark.aspx?ID=" + id +"&Bookurl="+ encodeURIComponent(location) + "&title=" + title ; ;
              BookmarkxmlHttp=GetXmlHttpObject(stateChangedBookmark);
              BookmarkxmlHttp.open("GET", url , true);
              BookmarkxmlHttp.send(null);
      }
  } 
function stateChangedBookmark() { 
      if (BookmarkxmlHttp.readyState==4 || BookmarkxmlHttp.readyState=="complete"){
            document.getElementById('bookmarkDisplay').innerHTML="";
            document.getElementById('bookmarkDisplay').innerHTML=BookmarkxmlHttp.responseText;
            BookmarkTrue='True';
      }
  } 
  
function GetEmbededCode()
{ 
    if(EmbededTrue=='False'){
        var id=Bib_ID;
        var CMM_ID="";
        if(document.getElementById("hdnCMM_ID").value!="")
           CMM_ID="&CMM_ID="+ document.getElementById("hdnCMM_ID").value;
         
          var url="embeded.aspx?ID=" + id +""+ CMM_ID;
              EmbededxmlHttp=GetXmlHttpObject(stateChangedEmbeded);
              EmbededxmlHttp.open("GET", url , true);
              EmbededxmlHttp.send(null);
      }
  } 
function stateChangedEmbeded() { 
      if ( EmbededxmlHttp.readyState==4 ||  EmbededxmlHttp.readyState=="complete"){
            document.getElementById('EmbededDisplay').innerHTML="";
            document.getElementById('EmbededDisplay').innerHTML= EmbededxmlHttp.responseText;
            EmbededTrue='True';
      }
  } 
function GetRating()
{ 
    if(RatingTrue=='False'){
          var id=Bib_ID;
          var url="Rating.aspx?ID=" + id ;
              RatingxmlHttp=GetXmlHttpObject(stateChangedRating);
              RatingxmlHttp.open("GET", url , true);
              RatingxmlHttp.send(null);
      }
  } 
function stateChangedRating() { 
      if(RatingxmlHttp.readyState==4 || RatingxmlHttp.readyState=="complete"){
            document.getElementById('RatingDisplay').innerHTML="";
            document.getElementById('RatingDisplay').innerHTML= RatingxmlHttp.responseText;
            RatingTrue='True';
            var el=document.getElementById('goratingPage');
            var loc = location.search;
            el.setAttribute("href",'../CommentsLists.aspx'+loc);
      }
  } 
function GetIlike()
{ 
    if(IlikeTrue=='False'){
        var id=Bib_ID;
        var CMM_ID="";
          if(document.getElementById("hdnCMM_ID").value!="")
            CMM_ID="&CMM_ID="+ document.getElementById("hdnCMM_ID").value;
       
        var url="Ilike.aspx?ID=" + id +""+ CMM_ID +"&FBurl="+ encodeURIComponent(location);
            IlikexmlHttp=GetXmlHttpObject(stateChangedIlike);
            IlikexmlHttp.open("GET", url , true);
            IlikexmlHttp.send(null);
      }
  } 
function stateChangedIlike() { 
      if(IlikexmlHttp.readyState==4 || IlikexmlHttp.readyState=="complete"){
            document.getElementById('ilikeDisplay').innerHTML="";
            document.getElementById('ilikeDisplay').innerHTML= IlikexmlHttp.responseText;
            IlikeTrue='True';
            
      }
  } 
function GetShop()
{ 
    if(ShopTrue=='False'){
       var elem = BookDetails.split('^');
       var title=elem[0];
       var Pub=elem[3];
       var Auth=elem[1];
       var id=Bib_ID;
       var CMM_ID="";
       if(document.getElementById("hdnCMM_ID").value!="")
         CMM_ID="&CMM_ID="+ document.getElementById("hdnCMM_ID").value;
         
        var url="shop.aspx?ID=" + id +""+ CMM_ID +"&title="+ title+"&Auth="+Auth+"&pub="+Pub;
            ShopxmlHttp=GetXmlHttpObject(stateChangedShop);
            ShopxmlHttp.open("GET", url , true);
            ShopxmlHttp.send(null);
      }
  } 
function stateChangedShop() { 
      if(ShopxmlHttp.readyState==4 ||  ShopxmlHttp.readyState=="complete"){
            document.getElementById('Shopdisplay').innerHTML="";
            document.getElementById('Shopdisplay').innerHTML= ShopxmlHttp.responseText;
            ShopTrue='True';
      }
    }

function Getaudio() {
        if (InfoTrue == 'False') {
            var id = Bib_ID;
            var url = "haudio.aspx?ID=" + id;
            AudioxmlHttp = GetXmlHttpObject(stateChangedaudio);
            AudioxmlHttp.open("GET", url, true);
            AudioxmlHttp.send(null);
        }
    }
    function stateChangedaudio() {
        if (AudioxmlHttp.readyState == 4 || AudioxmlHttp.readyState == "complete") {
            document.getElementById('audiodivID').innerHTML = "";
            document.getElementById('audiodivID').innerHTML = AudioxmlHttp.responseText;
            AudioTrue = 'True';
        }
    }
    function GetVideo() {
        if (VideoTrue == 'False') {
            var id = Bib_ID;
            var url = "hvideo.aspx?ID=" + id;
            VideoxmlHttp = GetXmlHttpObject(stateChangedVideo);
            VideoxmlHttp.open("GET", url, true);
            VideoxmlHttp.send(null);
        }
    }
    function stateChangedVideo() {
        if (VideoxmlHttp.readyState == 4 || VideoxmlHttp.readyState == "complete") {
            document.getElementById('VideodivID').innerHTML = "";
            document.getElementById('VideodivID').innerHTML = VideoxmlHttp.responseText;
            VideoTrue = 'True';
        }
    } 


function Zoomin(){
    //pagecontain
    var ConDiv = document.getElementById('documentArea')

   
   //showOfDivin('documentArea');
    var maxWidth = 960;
            /* Max hieght for the image */
            var maxHeight = 1340;
            /*Check if the current width is larger than the max*/
            $('input').each(function () {
                var width = $(this).width();
                    if (width < maxWidth) {
                    $(this).width($(this).width() + $(this).width() * 0.05);
                    $(this).height($(this).height() + $(this).height() * 0.05);
                    }
                });
            $('.page').each(function () {
                var width = $(this).width();
                    if (width < maxWidth) {
                        $(this).width($(this).width() + $(this).width() * 0.05);
                        $(this).height($(this).height() + $(this).height() * 0.05);
                    }
                });

}
  function showOfDivin(div) {
      alert(div);
        if(!div) {
        return;
        }
        div = typeof div === "string" ? document.getElementById(div) : div;
        var elms = div.getElementsByTagName("*");
       
    
        for(var i = 0, maxI = elms.length; i < maxI; ++i) {
            var elm = elms[i];
            
            var width =elm.width;
            var height = elm.height
          
                if(height<2000)
                {
          
                var Rewidth=parseInt(width + parseInt(parseFloat(width*10)/100));//1200;
                var p =parseFloat(height / width);//Aspect Retio
                var newx = parseInt(p * Rewidth);//// set to whatever you want the images max width to be.
                var newy = Rewidth; // whatever you want the images maximum height to be.
                elm.setAttribute("width", newy);
                elm.setAttribute("height", newx);
                }
            }
} 
function Zoomout(){
    //pagecontain
    var ConDiv = document.getElementById('documentArea')

    $('input').each(function () {
        $(this).width($(this).width() * 0.95);
        $(this).height($(this).height() * 0.95);
    });
    $('.page').each(function () {
        $(this).width($(this).width() * 0.95);
        $(this).height($(this).height() * 0.95);
    });

        //showOfDivout('documentArea');
  }
function showOfDivout(div) {
        if(!div) {
        return;
        }
        div = typeof div === "string" ? document.getElementById(div) : div;
        var elms = div.getElementsByTagName("*");
        
    
        for(var i = 0, maxI = elms.length; i < maxI; ++i) {
            var elm = elms[i];
            
            var width =elm.width;
            var height = elm.height;
          
              if(height>200)
                    {
                    var Rewidth=parseInt(width - parseInt(parseFloat(width*25)/100));//1200;
                    var p =parseFloat(height / width);//Aspect Retio
                    var newx = parseInt(p * Rewidth);//// set to whatever you want the images max width to be.
                    var newy = Rewidth; // whatever you want the images maximum height to be.
                        elm.setAttribute("width",newy);
		                elm.setAttribute("height",newx);
                    }
            }
} 
 
// function showWidth(ele, w) {
//      $("div").text("The width for the " + ele + 
//                    " is " + w + "px.");
//    }
    
  
    
//    $("#getd").click(function () { 
//      showWidth("document", $(document).width()); 
//    });
//    $("#getw").click(function () { 
//      showWidth("window", $(window).width()); 
//    });
function getStyle(el, style) {
  if(!document.getElementById) return;
 
   var value = el.style[toCamelCase(style)];
 
  if(!value)
    if(document.defaultView)
      value = document.defaultView.
         getComputedStyle(el, "").getPropertyValue(style);
   
    else if(el.currentStyle)
      value = el.currentStyle[toCamelCase(style)];
  
   return value;
}

function setStyle(objId, style, value) {
  document.getElementById(objId).style[style] = value;
}

function toCamelCase( sInput ) {
  var oStringList = sInput.split('-');
  if(oStringList.length == 1)  
    return oStringList[0];
  var ret = sInput.indexOf("-") == 0 ?
      oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
  for(var i = 1, len = oStringList.length; i < len; i++){
    var s = oStringList[i];
    ret += s.charAt(0).toUpperCase() + s.substring(1)
  }
  return ret;
}

function increaseWidth(addToWidth, whichDiv){
  var theDiv = document.getElementById(whichDiv);
  var currWidth = parseInt(getStyle(theDiv, "width"));
  var newWidth = currWidth + parseInt(addToWidth);
  setStyle(whichDiv, "width", newWidth + "px");
}
