var THOUSANDSEP = ",";
var DECIMALSEP = ".";

var book="BOOKS";
var gift="GIFTS";
var music="MUSIC";
var stationery="STATIONERY";
var multimedia="MULTIMEDIA";
var searchClearDivItemId="";
//changes by rahul jain for ratings
var searchClearDivItemName="";
var searchimageSrc="";
var searchauthorName="";
var searchitemPrice="";
var searchitemPriceUsd="";
var searchshippingInfo="";
var searchbindingInfo="";

var itemIdData = new Array();
var itemNameData = new Array();
var imageSrc = new Array();
var authorName = new Array();
var itemPrice = new Array();
var itemPriceUsd = new Array();
var shippingInfo =  new Array();
var bindingInfo = new Array();
var itemlPriceData = new Array();
var itemlDiscountedPrice = new Array();
//var bookObjectArray = [];
var book_object_var = {};
//upto here by rahul jain for ratings

//function to replace CDATA from the response
function replace(str)
{	
	var string="";	
	var newstr = str.replace(/<!\[CDATA\[/, string);
	newstr=newstr.replace(/\]\]>/, string);	
	return newstr;
}
//function to replace CDATA from the response and split them by " $%&@$%&@ " for displaying the results....
function replaceGetSearchResult(str)
{	//alert("str:"+str);
	var string="";
	//if(str== undefined || str==null)
	//return;
	var newstr = str.replace(/<!\[CDATA\[/, string);
	newstr=newstr.replace(/\]\]>/, string);
	newstr = newstr.split(" $%&@$%&@ ");	
	return newstr;
}
//To replace semicolon as it was giving 'Expected )'  error 
function replaceGetSearchResult1(str)
{	
	//alert("str replaceGetSearchResult1 :"+str);
	var string="";
	var newstr = str.replace(/<!\[CDATA\[/, string);
	newstr=newstr.replace(/\]\]>/, string);
	//newstr=newstr.replace(/\'/g, "\*$");
	return newstr;
	
}

//function to clear the dynamically cretaed divs before the result page is populated again...
function removePreviousRecords()
{
	var parent="";
	var children="";
	parent = document.getElementById("categoryResult");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}
	
	parent = document.getElementById("searchResultsTable");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}
	
	parent = document.getElementById("ItemDescriptionTableTd");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}

	parent = document.getElementById("pageLabels");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}

	parent = document.getElementById("searchCondition");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}
	parent = document.getElementById("authorDescriptionTd");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}
	parent = document.getElementById("FeedBackTableTd");
	children = parent.childNodes.length;
	for(var count=0;count<children;count++)
	{
		parent.removeChild(parent.childNodes[0]);
	}
}

//function for paging.....and  displaying the no of results and keyword. on which search is made......
function showPages(isPrevious,previousID,isNext,nextID,pageStart,totalAllowedPages,totalPages,totalRecords,pageNo,allowedRecords,inputKeyword,flag)
{
	var recordStart="";
	var recordEnd="";	
	recordStart = pageNo==0?1:(eval(pageNo)*eval(allowedRecords)+1);
	var recordEnd = (eval(recordStart)+eval(allowedRecords)-1)>eval(totalRecords)?eval(totalRecords):(eval(recordStart)+eval(allowedRecords)-1);
	var element="";
	var font="";
	var Strong="";
	var page = document.getElementById("pageLabels");

	var searchCondition = document.getElementById("searchCondition");
	if(totalRecords == null || totalRecords == "null" || totalRecords == "" || totalRecords == "0")
	{
		totalRecords = "0.";
		document.getElementById("pageLabels").style.display = 'none';		
	}
	else
	{
		document.getElementById("pageLabels").style.display = 'block';
	}	
	if(totalRecords==1)
	{
		element = document.createTextNode("Results "+recordStart+" of "+totalRecords);
	}
	else
	{
		element = document.createTextNode("Results "+recordStart+" - "+recordEnd+" of "+totalRecords);
	}

	searchCondition.appendChild(element);	
	var text="";

	if(inputKeyword!='')
	{		
		font = document.createElement("font");
		font.className="recordsText";
		text = document.createTextNode(" for \"");
		font.appendChild(text);
		searchCondition.appendChild(font);
		font = document.createElement("font");
		font.className="searchCondition";
		text = document.createTextNode(inputKeyword+"\"");
		font.appendChild(text);
		searchCondition.appendChild(font);		
	}	
	var count = 0;	
	if(isPrevious=='true')
	{
		var childElement = document.createElement("a");		
		if(flag=="true")
		var js = "javascript:onclick=itemSearchResult(\"" + previousID +"\",\"\",\"true\")";
		if(flag=="false")
		var js = "javascript:onclick=itemSearchResult(\"" + previousID +"\",\"\",\"false\")";
		childElement.setAttribute("href",js);
		childElement.className = "pagestext";
		var nodeVal = "<<" + "  ";
		var textNode = document.createTextNode(nodeVal);
		childElement.appendChild(textNode);
		page.appendChild(childElement);
	}
	for(count=eval(pageStart);count<totalAllowedPages;count++)
	{
		var	aLinkpageNo = document.createElement("a");
		if(flag=="true")
		var js = "javascript:onclick=itemSearchResult(\"" + count +"\",\"\",\"true\")";
		if(flag=="false")
		var js = "javascript:onclick=itemSearchResult(\"" + count +"\",\"\",\"false\")";
		var textNode ="";
		var font="";
		aLinkpageNo.setAttribute("href",js);				
		aLinkpageNo.className = "pagestext";
		if(count==pageNo)
		{
			font = document.createElement("FONT");
			font.setAttribute("color","#FF0000");
			textNode = document.createTextNode(count + 1);
			font.appendChild(textNode);
			aLinkpageNo.appendChild(font);
			if(count<totalAllowedPages-1)
			{
				textNode = document.createTextNode(" |");
				aLinkpageNo.appendChild(textNode);
			}
		}
		else
		{
			textNode = document.createTextNode(count + 1);
			aLinkpageNo.appendChild(textNode);
			if(count<totalAllowedPages-1)
			{
				textNode = document.createTextNode(" |");
				aLinkpageNo.appendChild(textNode);
			}
		}

		var spaceNode = document.createTextNode("  ");		
		page.appendChild(aLinkpageNo);
		page.appendChild(spaceNode);
	}
	if(isNext=='true')
	{
		var childElement = document.createElement("a");
		if(flag=="true")
		var js = "javascript:onclick=itemSearchResult(\"" + nextID +"\",\"\",\"true\")";
		if(flag=="false")
		var js = "javascript:onclick=itemSearchResult(\"" + nextID +"\",\"\",\"false\")";
		childElement.setAttribute("href",js);
		childElement.className = "pagestext";
		var nodeVal = "  " + ">>";
		var textNode = document.createTextNode(' ' + ">>");
		childElement.appendChild(textNode);
		page.appendChild(childElement);
	}
}


//function for atoz search
function fnAZSearch(itemAlphabet)
{
	document.AddToCart.itemnameatoz.value = itemAlphabet;
	document.AddToCart.submit();

}
//function that is called on click of paging....
function itemSearchResultPaging(pageNo)
{
	document.AddToCart.pageNo.value = pageNo;
	document.AddToCart.submit();
}
// this function displays the result of search.....
function displaySearchResultsNew(http_requestSearchItem,pageNo,flag,inputKeyword,bookId,flagidentity,allChild,function_selector)
{
	var bookObjectArray = [];
	if (http_requestSearchItem.readyState == 4)
	{
		 if (http_requestSearchItem.status == 200)
		 {	
			if(flagidentity==0)
                     setAtoZSearch();
			removePreviousRecords();
                    
		 	var responseDoc = http_requestSearchItem.responseXML; 			
			var pagingDetails = responseDoc.documentElement;
			
			var isPrevious=pagingDetails.getAttribute("isPrevious");
			var previousID=pagingDetails.getAttribute("previousID");
			var isNext=pagingDetails.getAttribute("isNext");
			var nextID=pagingDetails.getAttribute("nextID");
			var pageStart=pagingDetails.getAttribute("pageStart");
			var totalAllowedPages=pagingDetails.getAttribute("totalAllowedPages");
			var totalPages=pagingDetails.getAttribute("totalPages");
			var totalRecords=pagingDetails.getAttribute("totalRecords");
			var allowedRecords=pagingDetails.getAttribute("allowedRecords");

			var docs = responseDoc.getElementsByTagName("DOCUMENT");					 	
		 	var noOfDocuments = docs.length;
			var pagingDetails = document.getElementById("pagingDetails");
			var searchResults = document.getElementById("searchResults");
			if(noOfDocuments==0)
			{	
				document.getElementById('noResults').style.display='block';				
				document.getElementById('searchResults').style.display='none';	
				document.getElementById('pagingsResults').style.display='none';					
				
				var searchCond = document.getElementById("noResultsText");
				if(inputKeyword!='')
				{
					var text="";
					text = document.createTextNode(" for \"");
					searchCond.appendChild(text);
					text = document.createTextNode(inputKeyword+" \"");
					searchCond.appendChild(text);
				}				
			}
			else
			{  		
				document.getElementById('noResults').style.display='none';				
				document.getElementById('searchResults').style.display='table';		
				
			}
		 	var fields;
			var getTD = document.getElementById("SearchTR");
		    var imgPath;
			var isbnNo1Data = new Array();
			var author1Data = new Array();
			var publisher1Data = new Array();
			var bindingId1Data = new Array();
			var authorProfile1Data = new Array();
			var bindingDescription1Data = new Array();
			var bindingPrice1Data = new Array();
			var itemDescriptionData = new Array();
			var itemPriceData = new Array();
			var itemLeadTimeData = new Array();
			var itemTypeIdData = new Array();
			var itemTypeNameData = new Array();
			var itemTypeDescriptionData = new Array();
			var imageidData = new Array();
			var imageDescriptionData = new Array();
			var imageHeightData = new Array();
			var imageWidthData = new Array();
			var imageDefaultData = new Array();
			var relatedItemIdData = new Array();
			var relatedItemNameData = new Array();
			var catogeryIdData = new Array();
			var categoryDescriptionData = new Array();
			var categoryNameData = new Array();
			var isbnNo1DataData = new Array();			
			var imagePathData = new Array();
			var	itemHeight1Data = new Array();
			var	itemWidth1Data = new Array();
			var	itemLength1Data = new Array();
			var	itemDimensionUnit1Data = new Array();
			var	itemWeight1Data = new Array();
			var	itemWeightUnit1Data = new Array();
			var	itemKeywordData = new Array();
			var itemActualKeywordData = new Array();
			var	itemPageNoData = new Array();
			var	itemPublicationDateData = new Array();
			var	relaltedItemName = new Array();
			var	relaltedItemId = new Array();
			var	itemDiscountedPrice = new Array();
            var USDConversionRate=gUSDRate;
			var artistData = new Array();
			var	releasedByData = new Array();
			var	formatData = new Array();
			var	companyData = new Array();
			var	dateOfReleaseDateData = new Array();
         
			
		
		for(count=0;count<noOfDocuments;count++)
		   {
			//============================
			
			fields = docs[count].getElementsByTagName("FIELD");
		 		for(fieldCount=0;fieldCount<fields.length;fieldCount++)
		 		{
					
					var fieldName = fields[fieldCount].getAttribute("name");			
          
		            if(fieldName=='itemid')
					{
						itemIdData[count] = fields[fieldCount].firstChild.nodeValue;							
						itemIdData[count] = replaceGetSearchResult(itemIdData[count]);												
					}
					
					if(fieldName=='itemname')
					{
						itemNameData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemNameData[count] = replaceGetSearchResult1(itemNameData[count]);						
					}
					if(fieldName=='itemdescription')
					{
						itemDescriptionData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemDescriptionData[count] = replaceGetSearchResult1(itemDescriptionData[count]);						
					}
					if(fieldName=='itemdiscountedprice')
					{
						itemDiscountedPrice[count] = fields[fieldCount].firstChild.nodeValue;						
						itemDiscountedPrice[count] = replaceGetSearchResult(itemDiscountedPrice[count]);
                        itemlDiscountedPrice[count] = "Rs. "+itemDiscountedPrice[count];
					}
					
					if(fieldName=='itemprice')
					{
						itemPriceData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemPriceData[count] = replaceGetSearchResult(itemPriceData[count]);	
						itemPriceData[count] = itemPriceData[count].toString();
						itemPriceData[count] = removeZeros(itemPriceData[count]);	
						itemlPriceData[count] = "Rs. "+itemPriceData[count];
					}
					
					if(fieldName=='itemleadtime')
					{
						itemLeadTimeData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemLeadTimeData[count] = replaceGetSearchResult(itemLeadTimeData[count]);						
					}
					if(fieldName=='itemkeyword')
					{
						itemKeywordData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemKeywordData[count] = replaceGetSearchResult(itemKeywordData[count]);						
					}
					if(fieldName=='itemtypeid')
					{
						itemTypeIdData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemTypeIdData[count] = replaceGetSearchResult(itemTypeIdData[count]);						
					}
					if(fieldName=='itemtypename')
					{
						itemTypeNameData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemTypeNameData[count] = replaceGetSearchResult(itemTypeNameData[count]);						
					}
					if(fieldName=='itemtypedescription')
					{
						itemTypeDescriptionData[count] = fields[fieldCount].firstChild.nodeValue;						
						itemTypeDescriptionData[count] = replaceGetSearchResult(itemTypeDescriptionData[count]);						
					}

					if(fieldName=='imageid')
					{
						imageidData[count] = fields[fieldCount].firstChild.nodeValue;						
						imageidData[count] = replaceGetSearchResult(imageidData[count]);						
					}
					if(fieldName=='imagedescription')
					{
						imageDescriptionData[count] = fields[fieldCount].firstChild.nodeValue;						
						imageDescriptionData[count] = replaceGetSearchResult(imageDescriptionData[count]);
					}
					if(fieldName=='imagepath')
					{
						
						imagePathData[count] = fields[fieldCount].firstChild.nodeValue;	
						imagePathData[count] = replaceGetSearchResult(fields[fieldCount].firstChild.nodeValue);	
						imgPath=replaceGetSearchResult(fields[fieldCount].firstChild.nodeValue);	
					}
					if(fieldName=='imageheight')
					{
						imageHeightData[count] = fields[fieldCount].firstChild.nodeValue;						
						imageHeightData[count] = replaceGetSearchResult(imageHeightData[count]);						
					}
					if(fieldName=='imagewidth')
					{
						imageWidthData[count] = fields[fieldCount].firstChild.nodeValue;						
						imageWidthData[count] = replaceGetSearchResult(imageWidthData[count]);					
					}
					if(fieldName=='imagedefault')
					{
						imageDefaultData[count] = fields[fieldCount].firstChild.nodeValue;						
						imageDefaultData[count] = replaceGetSearchResult(imageDefaultData[count]);						
					}
					if(fieldName=='relateditemid')
					{
						relatedItemIdData[count] = fields[fieldCount].firstChild.nodeValue;
						relatedItemIdData[count] = replaceGetSearchResult(relatedItemIdData[count]);		
						relaltedItemId[count] = fields[fieldCount].firstChild.nodeValue;	
						relaltedItemId[count] = replace(relaltedItemId[count]);
					}
					if(fieldName=='relateditemname')
					{
						relatedItemNameData[count] = fields[fieldCount].firstChild.nodeValue;
						relatedItemNameData[count] = replaceGetSearchResult(relatedItemNameData[count]);
						relaltedItemName[count] = fields[fieldCount].firstChild.nodeValue;
						relaltedItemName[count] = replace(relaltedItemName[count]);
											
					}
					if(fieldName=='catogeryid')
					{
						catogeryIdData[count] = fields[fieldCount].firstChild.nodeValue;						
						catogeryIdData[count] = replaceGetSearchResult(catogeryIdData[count]);						
					}
					if(fieldName=='categorydescription')
					{
						categoryDescriptionData[count] = fields[fieldCount].firstChild.nodeValue;						
						categoryDescriptionData[count] = replaceGetSearchResult(categoryDescriptionData[count]);						
					}
					if(fieldName=='categoryname')
					{
						categoryNameData[count] = fields[fieldCount].firstChild.nodeValue;						
						categoryNameData[count] = replaceGetSearchResult(categoryNameData[count]);							
					}
								
					if(fieldName=='isbnbk')
					{
						isbnNo1Data[count]= fields[fieldCount].firstChild.nodeValue;
						isbnNo1Data[count] = replaceGetSearchResult(isbnNo1Data[count]);						
					}
							
					if(fieldName=='authorbk')
					{
						author1Data[count]= fields[fieldCount].firstChild.nodeValue;
						author1Data[count] = replaceGetSearchResult(author1Data[count]);
						//alert("author1Data[count]......"+author1Data[count]);
					}

					if(fieldName=='publisherbk')
					{
						publisher1Data[count]= fields[fieldCount].firstChild.nodeValue;
						publisher1Data[count] = replaceGetSearchResult(publisher1Data[count]);						
					}

					
					if(fieldName=='author_descriptionbk')
					{
						authorProfile1Data[count]= fields[fieldCount].firstChild.nodeValue;
						authorProfile1Data[count] = replaceGetSearchResult(authorProfile1Data[count]);						
					}
					if(fieldName=='bindingbk')
					{
						bindingDescription1Data[count]= fields[fieldCount].firstChild.nodeValue;
						bindingDescription1Data[count] = replaceGetSearchResult(bindingDescription1Data[count]);						
					}

					
					if(fieldName=='unit_of_measurementbk')
					{
						itemDimensionUnit1Data[count]= fields[fieldCount].firstChild.nodeValue;
						itemDimensionUnit1Data[count] = replaceGetSearchResult(itemDimensionUnit1Data[count]);						
					}	
					
						
					if(fieldName=='no._of_pagesbk')
					{
						itemPageNoData[count]= fields[fieldCount].firstChild.nodeValue;
						itemPageNoData[count] = replaceGetSearchResult(itemPageNoData[count]);						
					}
					if(fieldName=='itemactualkeyword')
					{
						itemActualKeywordData[count]= fields[fieldCount].firstChild.nodeValue;
						itemActualKeywordData[count] = replaceGetSearchResult(itemActualKeywordData[count]);						
					}					
					if(fieldName=='publication_datebk')
					{
						itemPublicationDateData[count]= fields[fieldCount].firstChild.nodeValue;
						itemPublicationDateData[count] = replaceGetSearchResult(itemPublicationDateData[count]);						
					}

					if(fieldName=='artist/bandgf')
					{
						artistData[count]= fields[fieldCount].firstChild.nodeValue;
						artistData[count] = replaceGetSearchResult(artistData[count]);						
					}
					if(fieldName=='released_bygf')
					{
						releasedByData[count]= fields[fieldCount].firstChild.nodeValue;
						releasedByData[count] = replaceGetSearchResult(releasedByData[count]);						
					}					
					if(fieldName=='formatgf')
					{
						formatData[count]= fields[fieldCount].firstChild.nodeValue;
						formatData[count] = replaceGetSearchResult(formatData[count]);						
					}
					if(fieldName=='companygf')
					{
						companyData[count]= fields[fieldCount].firstChild.nodeValue;
						companyData[count] = replaceGetSearchResult(companyData[count]);						
					}					
					if(fieldName=='date_of_releasegf')
					{
						dateOfReleaseDateData[count]= fields[fieldCount].firstChild.nodeValue;
						dateOfReleaseDateData[count] = replaceGetSearchResult(dateOfReleaseDateData[count]);						
					}
					
					if(fieldName=='usdconversionrate')
				    {
						
				        USDConversionRate=fields[fieldCount].firstChild.nodeValue;
					    USDConversionRate = replaceGetSearchResult(USDConversionRate);
					}
					
				}
			    var markedPriceUF = itemPriceData[count].replace(",","");
				var usdActual = parseFloat(markedPriceUF)/USDConversionRate;
				usdActual=(Math.round(usdActual*100)/100).toFixed(2);
				var itemPriceNew=itemPriceData[count] ;
				var discountNew="" + itemDiscountedPrice[count];
				var usdDiscount=0;
				var youSave;
				var usdYouSave;
				if (discountNew!=null && discountNew!='' && discountNew!="null")
				{
				 var sellingPriceUF = discountNew.replace(",","");
				 if(parseFloat(sellingPriceUF) < parseFloat(markedPriceUF))
                {
				   usdDiscount = parseFloat(sellingPriceUF)/USDConversionRate;
				   usdDiscount=(Math.round(usdDiscount*100)/100).toFixed(2);

				}
				    youSave = (parseFloat(itemPriceNew) - parseFloat(sellingPriceUF)).toFixed(2);
					usdYouSave = parseFloat(youSave)/USDConversionRate;
					usdYouSave=(Math.round(usdYouSave*100)/100).toFixed(2);
					
				}
				var imagePath= imgPath;
				//if(imagePathData[count]!="" || imagePathData[count]!=
				//alert("imagePath  "+imagePath);
               var imagePathData= ("," + imagePath).split(",")[1];
			    var book_object=create_book_object(itemIdData[count], itemNameData[count], usdActual, itemlPriceData[count], itemlDiscountedPrice[count], usdDiscount, youSave, usdYouSave, author1Data[count], imageSrc[count], itemLeadTimeData[count], bindingDescription1Data[count], itemDescriptionData[count], isbnNo1Data[count], publisher1Data[count], itemPublicationDateData[count], imagePathData, imageDefaultData[count]);
				//alert(book_object.name);
			    bookObjectArray.push(book_object);
			}
            
			//============================s
		    
			//}
		 
	 
		
        
     if(flagidentity==0)
       {
		if(noOfDocuments!=0)
		{
			 showPages(isPrevious,previousID,isNext,nextID,pageStart,totalAllowedPages,totalPages,totalRecords,pageNo,allowedRecords,inputKeyword,flag);
		}
		//Calling the fnGetRealetdCategories in getSearchResult.jsp to make the ajax call for related categories....

		fnGetRealetdCategories(http_requestSearchItem,flag,allChild);
       }
//rahul jain
		 //window.setTimeout('RatingsGet()',300);
        if(function_selector){
			show_book_description(bookObjectArray[0]);
			// var back = jQuery(".task_header .back_button img"); //.append(bookTitleElement);
			//  back.attr("src","/dotcom/oxford/images/backtohome.gif");
           
		}else{
			displayfromsearcharray(bookObjectArray);
		}


	}//end of request status 200
	}//end of readystate 4
	
}
 
function displayfromsearcharray(bookObjectArray){
        
		 for(var i=0; i<bookObjectArray.length; i++){
			  
			    var book_object1=bookObjectArray[i];
				book_object_var = bookObjectArray[i];
	            var searchContainer = jQuery("#searchResultsTable");
				
				
				var bookTitleElement = jQuery("<a href=# class=\"check_link\" data=" + i + "><strong>" + book_object1.name +"<\/strong><\/a>");
				searchContainer.append(createBookDetail(book_object1));
                
				//jQuery("#" + book_object1.book_id).find(".book_title").append(bookTitleElement);
				jQuery("#" + book_object1.book_id + " .book_description").append(create_note_for_dollar_price());
				searchContainer.find("#" +book_object1.book_id).append(create_addtocart_button_area(book_object1.book_id));
				searchContainer.find("#" +book_object1.book_id).append(create_showdetail_button_area(book_object1.book_id));
				var imgObj = jQuery("#" + book_object1.book_id + " .book_img img"); //.append(bookTitleElement);
				//alert(book_object1.image);
				imgObj.attr("src", book_object1.image);

				imgObj.load(function(book_object1){
				 // var imgsrcc = book_object.image;
				  //alert("ok" + $(this).attr("src"));
				 // $(this).attr("src",imgsrcc);

				});
				imgObj.error(function(){
				   var imgsrcc = "/dotcom/oxford/images/oxford_logo.jpg";
				  // alert("ok error" + $(this).attr("src"));
				   $(this).attr("src",imgsrcc);
				});

				searchContainer.append("<div class=\"book_result_seperator\"></div>");
				
				if(jQuery("#" + book_object1.book_id + " .book_offered_price").length){
					jQuery("#" + book_object1.book_id + " .book_actual_price").css("border-right","1px dotted #CBCBCB");
					jQuery("#" + book_object1.book_id + " .book_actual_price span").css("text-decoration","line-through");
				}else{
					 jQuery("#" + book_object1.book_id + " .book_actual_price").css("border-right","0px");
					 jQuery("#" + book_object1.book_id + " .book_actual_price span").css("text-decoration","none");
               }
		   }
				//alert(book_object1.name);
			/*jQuery(".book_title a").click(function(evt){
					   evt.preventDefault();
					   var index = ($(this).attr("data")); //alert(book_object1);
					   show_book_description(bookObjectArray[index]);
			});
			jQuery(".book_title a").click(function(evt){
					   evt.preventDefault();
					   var index = ($(this).attr("data")); //alert(book_object1);
					   show_book_description(bookObjectArray[index]);
			});*/
			jQuery(".book_img").click(function(){
                $(this).next().find(".book_title a").click();
			});
           
}



function RatingsGet()//itemIdData,noOfDocuments)
{
	for(count=0;count<itemIdData.length;count++)
	{
    	addfeedback(itemIdData[count],itemNameData[count]);
	}
}
//upto here by Rahul Jain

// function to display the related categorioes...
function displaySearchResultsCategory(http_requestSearchCategory,forwardURL,allChild)
{
	if (http_requestSearchCategory.readyState == 4)
	{
		 if (http_requestSearchCategory.status == 200)
		 {	
			var responseDoc = http_requestSearchCategory.responseXML; 			
			var root = responseDoc.documentElement;				 	
			var docs = responseDoc.getElementsByTagName("DOCUMENT");					 	
		 	var noOfDocuments = docs.length;
		 	var categoryNameData = new Array();
		 	var catID = "";
			tdCategory = document.getElementById("categoryResult");
			var aLink ="";
			var span="";
			var func="";
			var text="";
			var firstRecord=0;//variable count to print "Related Categories-" as text in the jsp..
			if(noOfDocuments>0)
			{
				document.getElementById("relatedCategories").style.display = 'block';
		 		for(count=0;count<noOfDocuments;count++)
		 		{
					fields = docs[count].getElementsByTagName("FIELD");
					for(fieldCount=0;fieldCount<fields.length;fieldCount++)
					{
						//changes here for child category
						if(allChild=="0")
						{
							var ifHomePage = fields[fieldCount].getAttribute("name");								
							if(ifHomePage == 'catviewifhomepage')
							{
								var ifHomePageData = fields[fieldCount].firstChild.nodeValue; 							
								ifHomePageData = replace(ifHomePageData);
								if(ifHomePageData == 'y'||ifHomePageData == 'Y')	
								{		
									for(namecount=0;namecount<fields.length;namecount++)
									{
										var fieldName = fields[namecount].getAttribute("name");
										if(fieldName=='catviewcategoryid')
										{
											catID = fields[namecount].firstChild.nodeValue;							
											catID = replaceGetSearchResult(catID);
										}
										if(fieldName=='catviewcategoryname')
										{
											if(firstRecord==0)
											{
												text = document.createTextNode("Related Categories -"); 
												tdCategory.appendChild(text);
											}
											firstRecord++;
											categoryNameData[count] = fields[namecount].firstChild.nodeValue;				
											categoryNameData[count] = replaceGetSearchResult(categoryNameData[count]);
											span = document.createElement("SPAN");
											span.className="relatedcategories";
											aLink = document.createElement("a");
											//aLink.className = "relatedcategories";
											func ="javascript:onclick=categoryItemSearch('"+catID+"','"+categoryNameData[count]+"','"+forwardURL+"');";
											aLink.setAttribute("href",func);
											text = document.createTextNode(categoryNameData[count]); 
											aLink.appendChild(text);
											span.appendChild(aLink);
											tdCategory.appendChild(span);			
											if(count < (noOfDocuments - 1))
											{
												text = document.createTextNode(" | "); 	
												tdCategory.appendChild(text);
											}
										}
									 }
								}
							}
						}
						else if(allChild=="1")
						{
							var fieldName = fields[fieldCount].getAttribute("name");
							if(fieldName=='catviewcategoryid')
							{
								catID = fields[fieldCount].firstChild.nodeValue;							
								catID = replaceGetSearchResult(catID);
							}
							if(fieldName=='catviewcategoryname')
							{
								if(firstRecord==0)
								{
									text = document.createTextNode("Related Categories -"); 
									tdCategory.appendChild(text);
								}
								firstRecord++;
								categoryNameData[count] = fields[fieldCount].firstChild.nodeValue;				
								categoryNameData[count] = replaceGetSearchResult(categoryNameData[count]);
								span = document.createElement("SPAN");
								span.className="relatedcategories";
								aLink = document.createElement("a");
								//aLink.className = "relatedcategories";
								func ="javascript:onclick=categoryItemSearch('"+catID+"','"+categoryNameData[count]+"','"+forwardURL+"');";
								aLink.setAttribute("href",func);
								text = document.createTextNode(categoryNameData[count]); 
								aLink.appendChild(text);
								span.appendChild(aLink);
								tdCategory.appendChild(span);			
								if(count < (noOfDocuments - 1))
								{
									text = document.createTextNode(" | "); 	
									tdCategory.appendChild(text);
								}
							}						
						}
					}
				}
			}
		 }
	}
}

/*function SearchImgLoad(myobj,imagePath, itemID, imageSource) 
{ 
   var oImg=new Image; 
   oImg.onload=function(){myobj.src=imagePath; imageSource = imagePath}
   oImg.onerror=function(){SearchImgLoad_Images(myobj, '/dotcom/'+gOrgFolder+'/images/'+itemID+'.jpg', imageSource);}
   oImg.src=imagePath;             
}*/

/*function SearchImgLoad_Images(myobj,imagePath, imageSource) 
{ 
   var oImg=new Image; 
   oImg.onload=function(){myobj.src=imagePath; imageSource = imagePath}
   oImg.onerror=function(){myobj.src='/dotcom/'+gOrgFolder+'/images/oxford_logo.jpg'; imageSource = '/dotcom/'+gOrgFolder+'/images/oxford_logo.jpg';}
   oImg.src=imagePath;             
}*/

function ImgLoad(myobj,imagePath, itemID) 
{ 
   var oImg=new Image; 
   oImg.onload=function(){myobj.src=imagePath} 
   oImg.onerror=function(){ImgLoad_Images(myobj, '/dotcom/'+gOrgFolder+'/images/'+itemID+'.jpg');}
   oImg.src=imagePath;             
}

function ImgLoad_Images(myobj, imagePath) 
{ 
   var oImg=new Image; 
   oImg.onload=function(){myobj.src=imagePath; imageSource = imagePath}
   oImg.onerror=function(){myobj.src='/dotcom/'+gOrgFolder+'/images/oxford_logo.jpg'} 
   oImg.src=imagePath;             
}

//function for add to cart
function AddToCart(ItemID)
{
	var url = '/dotcom/'+gOrgFolder+'/ShoppingCart/jsp/StockCheck.jsp?';
	document.AddToCart.action=url;	
	document.AddToCart.method="post";	
	document.AddToCart.ItemID.value=ItemID;
	document.AddToCart.submit();
}

function requestItem(ItemID)
{
	var url = '/dotcom/'+gOrgFolder+'/ShoppingCart/jsp/RequestItem.jsp?';
	document.AddToCart.action=url;	
	document.AddToCart.method="post";	
	document.AddToCart.ItemID.value=ItemID;
	document.AddToCart.submit();
}

function findItem()
{
	var url = '/dotcom/'+gOrgFolder+'/ShoppingCart/jsp/FindItem.jsp?';	
	document.AddToCart.action=url;	
	document.AddToCart.submit();
}
// ask rahul abt this....
function GiveFeedBack(ItemTypeID, ItemName)
{
	var url = '/dotcom/'+gOrgFolder+'/jsp/search/FeedBack.jsp?';	
	document.AddToCart.action=url;	
	document.AddToCart.ItemTypeID.value=ItemTypeID;
	document.AddToCart.ItemName.value=ItemName;
	document.AddToCart.OrgID.value='<%=Constants.ORGID%>';
	document.AddToCart.submit();
}

function getCustomerRelatedItems(ItemID)
{
	//alert(gOrgID);
	var lRelatedItems="/dotcom/ShoppingCart/CustomerRelatedItemsGet.kar?OrgId="+gOrgID+"&ItemId="+ItemID;
	submitForm(document.AddToCart, lRelatedItems, "POST", handleRelatedItems, 0, null);
}

function handleRelatedItems(pXMLObject)
{
	var lXMLResponse;
	var lBaseEdit;
	var lData;
	var lCount;
	var lSuccess;
	var lValue;
	var lId;
	var lDisplayText;
	var lElement;
	var lTextElement;
	var lBreakElement;
	var lPaymentCode;
	lXMLResponse = pXMLObject.responseXML;
	lBaseEdit = lXMLResponse.documentElement;
	lBaseEdit = copyNodes(lBaseEdit);
	lSuccess = handleResult(lBaseEdit.childNodes[0]);
	if (lSuccess)
	{
		lData = lBaseEdit.childNodes[1];
		if(lData.childNodes != null && lData.childNodes.length > 0)
		{
			for (var lAttributeCount = 0; lAttributeCount < lData.childNodes[0].attributes.length; lAttributeCount++)
			{
				var lAttribute = lData.childNodes[0].attributes[lAttributeCount];
				//alert("lAttribute: " + lAttribute);
				if (!isNodeNull(lAttribute))
				{	
					if (lAttribute.nodeName == "currentitemid")
					{
						lId = lAttribute.value;
						break;
					}
				}
			}
			var relatedItemsTable = document.getElementById("RelatedItemsTable"+lId);
			var relatedItemsDIV = document.getElementById("RelatedItemsDIV"+lId);
			if(relatedItemsDIV.childNodes.length > 0)
			{
				for(var count=relatedItemsDIV.childNodes.length - 1; count >= 0; count--)
				{
					relatedItemsDIV.removeChild(relatedItemsDIV.childNodes[count]);
				}
			}
			for (lCount = 1; lCount < lData.childNodes.length; lCount++)
			{
				relatedItemsTable.style.display="block";
				for (var lAttributeCount = 0; lAttributeCount < lData.childNodes[lCount].attributes.length; lAttributeCount++)
				{
					var lAttribute = lData.childNodes[lCount].attributes[lAttributeCount];
					//alert("lAttribute: " + lAttribute);
					if (!isNodeNull(lAttribute))
					{	
						if (lAttribute.nodeName == "itmmasteritemno")
						{
							lValue = lAttribute.value;
						}
						else if (lAttribute.nodeName == "itmmasteritemname")
						{
							lDisplayText = Url.decode(lAttribute.value);
						}
					}
				}
				lTextElement = document.createTextNode(lDisplayText);
				var span1 = document.createElement("SPAN");
				span1.className="relatedcategories";
				var aLink = document.createElement("A");
				var func ="/dotcom/oxford/jsp/search/getItemdetails.jsp?itemid="+lValue;
				aLink.setAttribute("href",func);
				aLink.appendChild(lTextElement);
				span1.appendChild(aLink);
				relatedItemsDIV.appendChild(span1);
				if(lCount != lData.childNodes.length -1 )
				{
					var lTextElement1 = document.createTextNode(" | ");
					relatedItemsDIV.appendChild(lTextElement1);
				}
			}
		}
	}
}


function getShippingTime(ItemID)
{
	//alert(gOrgID);
	var lShippingTime="/dotcom/ShoppingCart/CheckStock.kar?OrgId="+gOrgID+"&ItemId="+ItemID;
	submitForm(document.AddToCart, lShippingTime, "POST", handleShippingTime, 0, null);
}


function handleShippingTime(pXMLObject)
{
	var lXMLResponse;
	var lRoot;
	var lResult;
	var lSuccess;
	lXMLResponse = pXMLObject.responseXML;
	lRoot = lXMLResponse.documentElement;
	lRoot = copyNodes(lRoot);
	lResult = lRoot.childNodes[0];
	lStatus = lResult.attributes.getNamedItem("STATUS").value;
	if (lStatus != null && lStatus == "0")
	{
			if (lResult.attributes.getNamedItem("MESSAGE") != null)
			{
				var lMessage = lResult.attributes.getNamedItem("MESSAGE").value.split("#");
				var lItemId = lMessage[0];
				var lStockQty = lMessage[1];
				var lShipTimeTable = document.getElementById("ShipTimeTable"+lItemId);
				var lShipTimeSpan = document.getElementById("ShipTimeSpan"+lItemId);
				var lStockInt = null;
				//lStockQty = "0";
				try{
					if(lStockQty != null && lStockQty != "" && lStockQty != "null")
						lStockInt = parseInt(lStockQty);
				}catch(Exception)
				{}
				//lStockInt = 0;
				if(lStockInt != null && lStockInt != -1)
				{
					if(lShipTimeSpan)
					{
					if(lShipTimeSpan.childNodes.length > 0)
					{
						for(var count=lShipTimeSpan.childNodes.length - 1; count >= 0; count--)
						{
							lShipTimeSpan.removeChild(lShipTimeSpan.childNodes[count]);
						}
					}
					}
					if(lStockInt >= 4)
					{
						if(lShipTimeSpan)
					{
						//alert(lStockInt + "more than 4");
						lShipTimeTable.style.display="block";
						var text1 = document.createTextNode("48 hrs**");
					
						lShipTimeSpan.appendChild(text1);
					}
					}else if(lStockInt > 1)
					{
							if(lShipTimeSpan)
						{
						lShipTimeTable.style.display="block";
						var text1 = document.createTextNode("72 hrs**");
					
							lShipTimeSpan.appendChild(text1);
						}
					}else if(lStockInt == 1)
					{
							if(lShipTimeSpan)
						{
						lShipTimeTable.style.display="block";
						var text1 = document.createTextNode("96 hrs**");
						lShipTimeSpan.appendChild(text1);
						}
					}
					//document.getElementById("spanStockQty"+lItemId).appendChild(text);
				}
			}
	}
}


function checkStock(ItemID)
{
	//alert(gOrgID);
	var lCheckStock="/dotcom/ShoppingCart/CheckStock.kar?OrgId="+gOrgID+"&ItemId="+ItemID;
	submitForm(document.AddToCart, lCheckStock, "POST", handleStockCheck, 0, null);
}

function handleStockCheck(pXMLObject)
{
	var lXMLResponse;
	var lRoot;
	var lResult;
	var lSuccess;
	lXMLResponse = pXMLObject.responseXML;
	lRoot = lXMLResponse.documentElement;
	lRoot = copyNodes(lRoot);
	lResult = lRoot.childNodes[0];
	lStatus = lResult.attributes.getNamedItem("STATUS").value;
	if (lStatus != null && lStatus == "0")
	{
			if (lResult.attributes.getNamedItem("MESSAGE") != null)
			{
				var lMessage = lResult.attributes.getNamedItem("MESSAGE").value.split("#");
				//alert("handleStockCheck");
				//var lMessageTemp = "000000000010000375#0"
				//var lMessage = lMessageTemp.split("#");
				var lItemId = lMessage[0];
				var lStockQty = lMessage[1];
				var lstockTR = document.getElementById("TRStockQty"+lItemId);
				var lstockTD = document.getElementById("TDStockQty"+lItemId);
				var lStockInt = null;
				try{
					if(lStockQty != null && lStockQty != "" && lStockQty != "null")
						lStockInt = parseInt(lStockQty);
					
				}catch(Exception)
				{}
				//lStockInt = 0;
				if(lStockInt != null && lStockInt != -1)
				{
					//alert("handleStockCheck2");
					if(lstockTD.childNodes.length > 0)
					{
						for(var count=lstockTD.childNodes.length - 1; count >= 0; count--)
						{
							lstockTD.removeChild(lstockTD.childNodes[count]);
						}
					}
					if(lStockInt >= 5)
					{
						//alert("handleStockCheck3");
						lstockTD.className="stock_available";
						var text1 = document.createTextNode("Status: Available");
						lstockTD.appendChild(text1);
						//var text2 = document.createTextNode("Available");
						//var span = document.createElement("span");
						//span.className="productdetails";
						//span.appendChild(text2);
						//lstockTD.appendChild(span);
						var br1 = document.createElement("BR");
						lstockTD.appendChild(br1);

						//var text1 = document.createTextNode("Item in Stock");
						//lstockTD.appendChild(text1);
						var text2 = document.createTextNode("Item in Stock");
						var span = document.createElement("span");
						span.className="stockdetails";
						span.appendChild(text2);
						lstockTD.appendChild(span);
					}else if(lStockInt > 0)
					{
						lstockTD.className="stock_hurry";
						var text1 = document.createTextNode("Status: Available");
						lstockTD.appendChild(text1);
						//var text2 = document.createTextNode("Available");
						//var span = document.createElement("span");
						//span.className="productdetails";
						//span.appendChild(text2);
						//lstockTD.appendChild(span);
						var br1 = document.createElement("BR");
						lstockTD.appendChild(br1);
						//var br1 = document.createElement("BR");
						//lstockTD.appendChild(br1);

						//var text1 = document.createTextNode("Nos: ");
						//lstockTD.appendChild(text1);
						var text2 = document.createTextNode("Hurry! Less than five copies. Order Soon!!!");
						var span = document.createElement("span");
						span.className="stockdetails";
						span.appendChild(text2);
						lstockTD.appendChild(span);
					}else if(lStockInt == 0)
					{
						lstockTD.className="stock_unavailable";
						var text1 = document.createTextNode("Status: Not Available");
						lstockTD.appendChild(text1);
						//var text2 = document.createTextNode("Not Available");
						//var span = document.createElement("span");
						//span.className="productdetails";
						//span.appendChild(text2);
						//lstockTD.appendChild(span);
						var br1 = document.createElement("BR");
						lstockTD.appendChild(br1);

						/*var text1 = document.createTextNode("Nos: ");
						lstockTD.appendChild(text1);
						var text2 = document.createTextNode(lStockInt);
						var span = document.createElement("span");
						span.className="productdetails";
						span.appendChild(text2);
						lstockTD.appendChild(span);
						var br1 = document.createElement("BR");
						lstockTD.appendChild(br1);*/

						var text1 = document.createTextNode("To request for this item please ");
						var span = document.createElement("span");
						span.className="stockdetails";
						span.appendChild(text1);
						lstockTD.appendChild(span);
						var aLink =  document.createElement("a");
						aLink.className="stock_unavailable_link";
						var func ="javascript:onclick=requestItem('"+lItemId+"');";
						aLink.setAttribute("href",func);
						var text2 = document.createTextNode("Click Here");
						aLink.appendChild(text2);
						//lstockTD.appendChild(text1);
						lstockTD.appendChild(aLink);
						var br1 = document.createElement("BR");
						lstockTD.appendChild(br1);
					}
					//document.getElementById("spanStockQty"+lItemId).appendChild(text);
				}
			}
	}
}

function handleCartDetailsGet(pXMLObject)
{
	var lXMLResponse;
	var lRoot;
	var lResult;
	var lSuccess;
	lXMLResponse = pXMLObject.responseXML;
	lRoot = lXMLResponse.documentElement;
	lRoot = copyNodes(lRoot);
	lSuccess = handleResult(lRoot.childNodes[0], null);
	if (lSuccess)
	{


		lData = lRoot.childNodes[1];
		if(lData != null && lData.firstChild != null)
		{
			var lHomePageCartTR = document.getElementById("HomePageCartTR");
			lHomePageCartTR.style.display="block";
			if(lData.childNodes[0].getAttribute("cartdtlstotalamount")!= null && lData.childNodes[0].getAttribute("cartdtlstotalamount") != "")
			{
				var lCartItemsPrice = document.createTextNode(" " + lData.childNodes[0].getAttribute("cartdtlstotalamount"));


				var markedPriceUF = lData.childNodes[0].getAttribute("cartdtlstotalamount").replace(",","");
				var usd = parseFloat(markedPriceUF)/USDConversionRate;
				//alert("USDConversionRate" + USDConversionRate);
				
				usd=(Math.round(usd*100)/100).toFixed(2);

				var lCartItemsPriceForUSD = document.createTextNode(" " + usd);

				var lhpcartitemprice = document.getElementById("hpcartitemprice");
				if(lhpcartitemprice != null && lhpcartitemprice.childNodes != null)
				{
					for (lCount = lhpcartitemprice.childNodes.length - 1; lCount >= 0; lCount--)
					{
						lhpcartitemprice.removeChild(lhpcartitemprice.childNodes[lCount]);
					}
				}				
				
				lhpcartitemprice.appendChild(lCartItemsPrice);


				var lhpcartitempriceinusd = document.getElementById("hpcartitempriceinusd");
				if(lhpcartitempriceinusd != null && lhpcartitempriceinusd.childNodes != null)
				{
					for (lCount = lhpcartitempriceinusd.childNodes.length - 1; lCount >= 0; lCount--)
					{
						lhpcartitempriceinusd.removeChild(lhpcartitempriceinusd.childNodes[lCount]);
					}
				}				
				
				lhpcartitempriceinusd.appendChild(lCartItemsPriceForUSD);
			}
			if(lData.childNodes[1].getAttribute("cartitemcount")!= null && lData.childNodes[1].getAttribute("cartitemcount") != "")
			{
				var lCartItemsCount = document.createTextNode(lData.childNodes[1].getAttribute("cartitemcount") + " ");

				var lhpcartitemcount = document.getElementById("hpcartitemcount");
				if(lhpcartitemcount != null && lhpcartitemcount.childNodes != null)
				{
					for (lCount = lhpcartitemcount.childNodes.length - 1; lCount >= 0; lCount--)
					{
						lhpcartitemcount.removeChild(lhpcartitemcount.childNodes[lCount]);
					}
				}	
				
				lhpcartitemcount.appendChild(lCartItemsCount);
			}
		}else
		{
				var lCartItemsPrice = document.createTextNode(" 0.00");
                var lCartItemsPriceUSD = document.createTextNode(" 0.00");
				var lhpcartitemprice = document.getElementById("hpcartitemprice");
				if(lhpcartitemprice != null && lhpcartitemprice.childNodes != null)
				{
					for (lCount = lhpcartitemprice.childNodes.length - 1; lCount >= 0; lCount--)
					{
						lhpcartitemprice.removeChild(lhpcartitemprice.childNodes[lCount]);
					}
				}
				lhpcartitemprice.appendChild(lCartItemsPrice);


				var lhpcartitempriceinusd = document.getElementById("hpcartitempriceinusd");
				if(lhpcartitempriceinusd != null && lhpcartitempriceinusd.childNodes != null)
				{
					for (lCount = lhpcartitempriceinusd.childNodes.length - 1; lCount >= 0; lCount--)
					{
						lhpcartitempriceinusd.removeChild(lhpcartitempriceinusd.childNodes[lCount]);
					}
				}				
				
				lhpcartitempriceinusd.appendChild(lCartItemsPriceUSD);

				var lCartItemsCount = document.createTextNode("0 ");
				var lhpcartitemcount = document.getElementById("hpcartitemcount");
				if(lhpcartitemcount != null && lhpcartitemcount.childNodes != null)
				{
					for (lCount = lhpcartitemcount.childNodes.length - 1; lCount >= 0; lCount--)
					{
						lhpcartitemcount.removeChild(lhpcartitemcount.childNodes[lCount]);
					}
				}
				lhpcartitemcount.appendChild(lCartItemsCount);
		}
	}
}

// function that fills categories in the left section
function fillCategory(http_request,forwardURL)
{
	if (http_request.readyState == 4)
	{							
    	 if (http_request.status == 200)
		{
			 var categoryTable = document.getElementById("resultTableCategory");
			 var categoryBody = categoryTable.firstChild;
			 if(categoryBody != null)
			 {
				 categoryTable.removeChild(categoryBody);
			 }
			 var tbodycategory = document.createElement("TBODY");
			 var tr="";
			 var td="";
			 var text="";
			 var table="";
			 var tbody="";
			 var innerTr = "";
			 var innerDiv = "";
			 var innerUl = "";
			 var innerLi = "";
			 var innerTd = "";
			 var img="";
			 
			 var itemtype1;
			 var responseDoc = http_request.responseXML; 			
			 var docs = responseDoc.getElementsByTagName("DOCUMENT");					 	
			 var noOfDocuments = docs.length;
			// alert("noOfDocuments...."+noOfDocuments);
			 var fields;	
			 var lastItemTypeName = "";	
			 var noOfItemType=0;
			 for(count=0;count<noOfDocuments;count++)
			 {
				fields = docs[count].getElementsByTagName("FIELD");	
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
				{					
					var ifHomePage = fields[fieldCount].getAttribute("name");				
					if(ifHomePage == 'catviewifhomepage')
					{
						var ifHomePageData = fields[fieldCount].firstChild.nodeValue; 							
						ifHomePageData = replace(ifHomePageData);	
						if(ifHomePageData == 'y'||ifHomePageData == 'Y')	
						{
							var try1;
							for(namecount=0;namecount<fields.length;namecount++)
							{
								var fieldname = fields[namecount].getAttribute("name");
								 if (fieldname == 'itmtypmstritemtypename')
								{
									var itemTypeData = fields[namecount].firstChild.nodeValue;
									itemTypeData = replace(itemTypeData);
									itemTypeData = itemTypeData.toString();
									lastItemTypeName = lastItemTypeName.toString();
									if(lastItemTypeName!=itemTypeData)
									{
										// to display more  not for the 1st entry inside this loop
										if(noOfItemType!=0)
										{
											tr = document.createElement("TR");										
											td = document.createElement("TD");
											innerDiv = document.createElement("div");
										    innerDiv.className="categoryheader";	
											var aLink = document.createElement("a");
											var func ="javascript:onclick=setAllCategory('"+lastItemTypeName+"');";
											aLink.setAttribute("href",func);
											text = document.createTextNode("More...");
											aLink.appendChild(text);	
											innerDiv.appendChild(aLink);
											td.appendChild(innerDiv);
											tr.appendChild(td);
											tbodycategory.appendChild(tr);										
										}
										noOfItemType++;
										tr = document.createElement("TR");										
										td = document.createElement("TD");
										innerDiv = document.createElement("div");
										innerDiv.className="categorytopheader";																	
										text = document.createTextNode(itemTypeData.toUpperCase());				
										innerDiv.appendChild(text);										
										td.appendChild(innerDiv);
										innerUl = document.createElement("ul");
										innerUl.className="leftnavigation";
										td.appendChild(innerUl);
                                        tr.appendChild(td);
										tbodycategory.appendChild(tr);									
										
										lastItemTypeName = itemTypeData;
										try1 = itemTypeData;
										
										
									}								
								}
							}	
							for(namecount=0;namecount<fields.length;namecount++)
							{
								var fieldname = fields[namecount].getAttribute("name");
								var catID;
								if(fieldname=='catviewcategoryid')
								{
									catID = fields[namecount].firstChild.nodeValue;							
									catID = replace(catID);
								}
									if(fieldname == 'catviewcategoryname')
								{
									var categoryData = fields[namecount].firstChild.nodeValue;
									categoryData = replace(categoryData);
								
									innerLi= document.createElement("li");
									var aLink = document.createElement("a");									
									var func ="javascript:onclick=categoryItemSearch('"+catID+"','"+categoryData+"','"+forwardURL+"');";
									aLink.setAttribute("href",func);	
									text = document.createTextNode(categoryData);
									aLink.appendChild(text);
									innerLi.appendChild(aLink);		
									innerUl.appendChild(innerLi);
									td.appendChild(innerUl);
									tr.appendChild(td);
									tbodycategory.appendChild(tr);								
									categoryTable.appendChild(tbodycategory);

								}										
							}
						}						
					}							
				}
			}
			// more link for the lastItemType....
			var moreTable = document.getElementById("moreCategoryForLastItemType");
		    var moreBody = moreTable.firstChild;
		    if(moreBody != null)
		    {
				 moreTable.removeChild(moreBody);
		    }
		    var moretbody = document.createElement("TBODY");			
			tr = document.createElement("TR");										
			td = document.createElement("TD");
			
			innerDiv = document.createElement("div");
			innerDiv.className="categoryheader";	
			var aLink = document.createElement("a");			
			
			var func ="javascript:onclick=setAllCategory('"+lastItemTypeName+"');";
			aLink.setAttribute("href",func);
			text = document.createTextNode("More...");
			aLink.appendChild(text);	
			innerDiv.appendChild(aLink);										
			
			td.appendChild(innerDiv);
			tr.appendChild(td);
			moretbody.appendChild(tr);	
			moreTable.appendChild(moretbody);
		}
	}
}


//	function to search items when a category is cliked....		
function categoryItemSearch(categoryID,category,forwardURL)
{	
	document.CategoryListForm.action=forwardURL;
	document.CategoryListForm.categoryID.value= categoryID;
	document.CategoryListForm.category.value= category;
	document.CategoryListForm.allChild.value="1";
	document.CategoryListForm.submit();
}
// functions that is called wen more all browse all is clicked....
function setAllCategory(itemType)
{
	var url = '/dotcom/'+gOrgFolder+'/jsp/search/AllCategory.jsp?';	
	document.CategoryListForm.action=url;
	document.CategoryListForm.itemType.value=itemType;
	document.CategoryListForm.submit();
}

//displays the results when browse all or more is clicked.....
function displayAllCategories(http_requestSearchNew,forwardURL)
{
	if (http_requestSearchNew.readyState == 4)
	{
		 if (http_requestSearchNew.status == 200)
		 {
		 	var responseDoc = http_requestSearchNew.responseXML; 
		 
			var docs = responseDoc.getElementsByTagName("DOCUMENT");					 	
		 	var noOfDocuments = docs.length;
		 	var fields;	
		 	var lastItemTypeName = "";	
			var noOfItemType=0;
			var noOfCategory=0;
			var count1=0;
			var categoryNoArray = new Array();
			var categoryNoArray1 = new Array();
			var itemTypeArray = new Array();
			var itemTypeImagePathArray = new Array();
			var categoryNames = new Array();
			var catID = new Array();
			var itemType = "";
			var rowState="";
			var categoryName = "";
			var itemTypeData = "";
			var catIDs = "";
			var table = "";
			var tr = "";
			var td = "";
			var tbody = "";
			var text = "";
			var font = "";
			var beforeSpace = "";
			var afterSpace = "";
			var catIDs = "";
			var categoryNameData = "";
			var br = "";
			var img = "";
			var linkTag = "";


			var itemtypeimage = new Array();
			var itemtypeimagepath = "";
			var itemtypeimagepathData = "";


			for(count=0;count<noOfDocuments;count++)			
		 	{				
				fields = docs[count].getElementsByTagName("FIELD");	
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
		 		{		 				
					itemType = fields[fieldCount].getAttribute("name");												
					if(itemType == 'itmtypmstritemtypename')
					{						
						itemTypeData = fields[fieldCount].firstChild.nodeValue;			
						itemTypeData = replace(itemTypeData);							
						if(lastItemTypeName!=itemTypeData)
						{
							categoryNoArray[count1] = noOfCategory;
							count1++;							
							noOfCategory=0;																	
							lastItemTypeName = itemTypeData;
							itemTypeArray[noOfItemType] = itemTypeData;

							// chnages for image of itemtype
							for (imagecount=0;imagecount<fields.length;imagecount++)
							{					
								itemtypeimagepath = fields[imagecount].getAttribute("name");
								if(itemtypeimagepath=="itmtypmstritemtypeimagepath")
								{
									itemtypeimagepathData = fields[imagecount].firstChild.nodeValue;
									itemtypeimagepathData = replace(itemtypeimagepathData);	
									itemtypeimage[noOfItemType] = itemtypeimagepathData;
								}								
							}

							noOfItemType++;							
						}
					}
				}			
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
		 		{						
					categoryName = fields[fieldCount].getAttribute("name");												
					if(categoryName=='catviewcategoryid')
					{
						catIDs = fields[fieldCount].firstChild.nodeValue;							
						catIDs = replace(catIDs);						
						catID[count]=catIDs;
					}				
					if(categoryName == 'catviewcategoryname')
					{						
						categoryNameData = fields[fieldCount].firstChild.nodeValue;						
						categoryNameData = replace(categoryNameData);						
						noOfCategory++;						
						categoryNames[count]=categoryNameData;										
					}
				}
			}
									 
			categoryNoArray[count1] = noOfCategory;		
			var sum = new Array();			
			sum[0] = 0;
			var catLength = 1;
			var sumArrLength = categoryNoArray.length + categoryNoArray.length;
			for(var a=0;a<sumArrLength;a=a+2)
			{				
				sum[a+1]=sum[a]+categoryNoArray[catLength];	
				sum[a+2]=sum[a+1];
				catLength = catLength + 1;
			}
			var last=sum.length;			
			sum[last-1]=count;		

			var categoryResult = document.getElementById("categoryResult");			
			var itemDetailsLength = noOfItemType + noOfItemType;
			var maintable = "";
			var maintr = "";
			var maintd = "";
			var maintbody = "";
			var itemTypeLength = 0;
			var mainfont="";
			var img = "";
			var font="";
			var div="";
			for(var print=0;print<itemDetailsLength;print=print+2)
			 {
				maintable = document.createElement("TABLE");
				maintable.setAttribute("width","100%");
				maintable.setAttribute("border","0");
				maintable.setAttribute("cellspacing","0");
				maintable.setAttribute("cellpadding","0");
				maintbody = document.createElement("TBODY");
				maintr = document.createElement("TR");
				maintd = document.createElement("TD");				
				maintd.setAttribute("width","20%");
				maintd.setAttribute("align","left");
				maintd.className="border_newreleases";

				var innerTable="";
				var innerTbody="";
				var innerTr="";
				var innerTd="";
				var span="";
				innerTable = document.createElement("TABLE");
				innerTable.setAttribute("width","100%");
				innerTable.setAttribute("border","0");
				innerTable.setAttribute("cellspacing","0");
				innerTable.setAttribute("cellpadding","0");
				innerTable.setAttribute("height","23");
				innerTbody = document.createElement("TBODY");
				innerTr = document.createElement("TR");
				innerTd = document.createElement("TD");
				innerTd.setAttribute("align","center");
				//innerTd.className="border_newreleases";
				span = document.createElement("SPAN");
				span.className="newreleaseheader";

				//Add ITEMTYPE name....				
				text = document.createTextNode(itemTypeArray[itemTypeLength].toUpperCase());	
				span.appendChild(text);
				innerTd.appendChild(span);
				innerTr.appendChild(innerTd);
				innerTbody.appendChild(innerTr);
				innerTable.appendChild(innerTbody);
				maintd.appendChild(innerTable);
				maintr.appendChild(maintd);
				
				maintd = document.createElement("TD");
				maintd.setAttribute("width","80%");
				maintd.className="bottom_border";
				innerTable = document.createElement("TABLE");
				innerTable.setAttribute("width","100%");
				innerTable.setAttribute("border","0");
				innerTable.setAttribute("cellspacing","0");
				innerTable.setAttribute("cellpadding","0");
				innerTable.setAttribute("height","23");
				//innerTable.className="bottom_border";
				innerTbody = document.createElement("TBODY");
				innerTr = document.createElement("TR");
				innerTd = document.createElement("TD");
				innerTr.appendChild(innerTd);
				innerTbody.appendChild(innerTr);
				innerTable.appendChild(innerTbody);
				maintd.appendChild(innerTable);
				maintr.appendChild(maintd);
				maintbody.appendChild(maintr);

				maintable.appendChild(maintbody);
				categoryResult.appendChild(maintable);
				//itemtype over.....

				maintable = document.createElement("TABLE");
				maintable.className="three_sides_greyborder";
				maintable.setAttribute("width","100%");
				maintable.setAttribute("border","0");
				maintable.setAttribute("cellspacing","0");
				maintable.setAttribute("cellpadding","0");
				maintbody = document.createElement("TBODY");
				maintr = document.createElement("TR");
				maintd = document.createElement("TD");
				maintd.setAttribute("width","100%");
				maintd.setAttribute("colspan","2");
				maintd.setAttribute("valign","top");
				innerTable = document.createElement("TABLE");
				innerTable.setAttribute("width","100%");
				innerTable.setAttribute("border","0");
				innerTable.setAttribute("cellspacing","0");
				innerTable.setAttribute("cellpadding","0");
				//innerTable.className="three_sides_greyborder";
				innerTbody = document.createElement("TBODY");
				innerTr = document.createElement("TR");
				innerTd = document.createElement("TD");
				var categoryTable="";
				var categoryTbody = "";
				var categoryTr = "";
				var categoryTd = "";
				var outerDiv="";
				var innerDiv="";

				categoryTable = document.createElement("TABLE");
				categoryTable.setAttribute("width","100%");
				categoryTable.setAttribute("border","0");
				categoryTable.setAttribute("cellspacing","0");
				categoryTable.setAttribute("cellpadding","0");
				categoryTbody = document.createElement("TBODY");
				categoryTr = document.createElement("TR");
				categoryTd = document.createElement("TD");
				categoryTd.setAttribute("width","2%");
				categoryTr.appendChild(categoryTd);

				categoryTd = document.createElement("TD");
				categoryTd.setAttribute("align","center");
				categoryTd.setAttribute("valign","top");
				categoryTd.setAttribute("width","8%");
				outerDiv = document.createElement("DIV");
				outerDiv.className="image_border_outer";
				innerDiv = document.createElement("DIV");
				innerDiv.className="image_border_outer";
				img = document.createElement("img");
				/*if(itemTypeArray[itemTypeLength].toUpperCase() == book)
				{
					img.setAttribute("src","/dotcom/"+gOrgFolder+"/images/booksicon.jpg");
				}
				else if(itemTypeArray[itemTypeLength].toUpperCase() == gift)
				{
					 img.setAttribute("src","/dotcom/"+gOrgFolder+"/images/giftsicon.jpg");
				}
				else if(itemTypeArray[itemTypeLength].toUpperCase() == music)
				{
					img.setAttribute("src","/dotcom/"+gOrgFolder+"/images/musicicon.jpg");
				}
				else if(itemTypeArray[itemTypeLength].toUpperCase() == multimedia)
				{
					 img.setAttribute("src","/dotcom/"+gOrgFolder+"/images/multimediaicon.jpg");
				}
				else if(itemTypeArray[itemTypeLength].toUpperCase() == stationery)
				{
					 img.setAttribute("src","/dotcom/"+gOrgFolder+"/images/stationaryicon.jpg");
				}*/
				img.setAttribute("src","/dotcom/"+gOrgFolder+"/DynamicAdmin/ImgGallery/"+itemtypeimage[itemTypeLength]);
img.setAttribute("width","160px");
				innerDiv.appendChild(img);
				outerDiv.appendChild(innerDiv);
				categoryTd.appendChild(outerDiv);				
				categoryTr.appendChild(categoryTd);
				
				categoryTd = document.createElement("TD");
				categoryTd.setAttribute("width","4%");
				categoryTr.appendChild(categoryTd);


				//displaying categories....
				categoryTd = document.createElement("TD");
				categoryTd.setAttribute("align","left");
				categoryTd.setAttribute("valign","top");
				categoryTd.setAttribute("width","86%");
				var allCategoryTable="";
				var allCategoryTbody="";
				var allCategoryTr="";
				var allCategoryTd="";
				allCategoryTable = document.createElement("TABLE");
				allCategoryTable.setAttribute("width","100%");
				allCategoryTable.setAttribute("border","0");
				allCategoryTable.setAttribute("cellspacing","0");
				allCategoryTable.setAttribute("cellpadding","0");
				allCategoryTbody = document.createElement("TBODY");
				allCategoryTr = document.createElement("TR");
				var categoryBlockTable="";
				var categoryBlockTbody="";
				var categoryIndividualTr="";
				var categoryIndividualTd="";				
				var colsInRow = 3;

				for(var got=sum[print];got<sum[print+1];got++)
				{				
					if(colsInRow == 0)
					{
						allCategoryTbody.appendChild(allCategoryTr);
						allCategoryTr = document.createElement("TR");
						colsInRow = 3;
					}			
					allCategoryTd = document.createElement("TD");
					allCategoryTd.setAttribute("width","33%");
					categoryBlockTable = document.createElement("TABLE");
					categoryBlockTable.setAttribute("width","100%");
					categoryBlockTable.setAttribute("border","0");
					categoryBlockTable.setAttribute("cellspacing","0");
					categoryBlockTable.setAttribute("cellpadding","0");
					categoryBlockTbody = document.createElement("TBODY");
					categoryIndividualTr = document.createElement("TR");
					categoryIndividualTd = document.createElement("TD");
					categoryIndividualTd.setAttribute("width","12%");
					img = document.createElement("img");					
					img.setAttribute("src","/dotcom/"+gOrgFolder+"/images/arrow_categories.gif");
					img.setAttribute("hspace","6");
					img.setAttribute("vspace","4");	
					categoryIndividualTd.appendChild(img);
					categoryIndividualTr.appendChild(categoryIndividualTd);

					categoryIndividualTd = document.createElement("TD");
					categoryIndividualTd.setAttribute("width","88%");
					linkTag = document.createElement("a");
					linkTag.setAttribute("href","javascript:onclick=categoryItemSearch('"+catID[got]+"','"+categoryNames[got]+"','"+forwardURL+"');");
					linkTag.className="categories_header";					
					text = document.createTextNode(categoryNames[got]);	
					linkTag.appendChild(text);				
					categoryIndividualTd.appendChild(linkTag);
					categoryIndividualTr.appendChild(categoryIndividualTd);
					categoryBlockTbody.appendChild(categoryIndividualTr);
					categoryBlockTable.appendChild(categoryBlockTbody);
					allCategoryTd.appendChild(categoryBlockTable);
					allCategoryTr.appendChild(allCategoryTd);
					colsInRow = colsInRow - 1;					 
				 }
				
				//end of displaying categories				
				allCategoryTbody.appendChild(allCategoryTr);
				allCategoryTable.appendChild(allCategoryTbody);
				categoryTd.appendChild(allCategoryTable);

				categoryTr.appendChild(categoryTd);
				categoryTbody.appendChild(categoryTr);
				categoryTable.appendChild(categoryTbody);
				innerTd.appendChild(categoryTable);

				innerTr.appendChild(innerTd);
				innerTbody.appendChild(innerTr);
				innerTable.appendChild(innerTbody);
				maintd.appendChild(innerTable);


				maintr.appendChild(maintd);
				maintbody.appendChild(maintr);
				maintable.appendChild(maintbody);
				categoryResult.appendChild(maintable);				
				itemTypeLength = itemTypeLength + 1;	

			}				
		}		
	}
}

//function that fills the itemtype drop down on the home page....			
function fillItemType(http_request)
{
if (http_request.readyState == 4)
	{						
		if (http_request.status == 200)
		 {
			var i=1;
			var itemtypelist= document.ItemForm.itemType;
			itemtypelist.options[0]= new Option("All Products","All Products");
			var responseDoc= http_request.responseXML;
		 	var docs = responseDoc.getElementsByTagName("DOCUMENT");	
			var noOfDocuments = docs.length;
			var fields;	
			for(count=0;count<noOfDocuments;count++)			
		 	{				
				fields = docs[count].getElementsByTagName("FIELD");	
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
				{				
					var itemType = fields[fieldCount].getAttribute("name");	
					if(itemType == 'itmtypmstritemtypename')
					{						
						var itemTypeData = fields[fieldCount].firstChild.nodeValue;						
						itemTypeData = replace(itemTypeData);	
						if(itemTypeData.constructor == Array)
							itemTypeData = itemTypeData[0];
						allItemType[i-1] = itemTypeData;
						//itemTypeData = itemTypeData.toUpperCase();
						itemtypelist.options[i]= new Option(itemTypeData,itemTypeData);
						i++;
					}	
				}				
			}			
		}								 	
	}
}
// function called on click of seach button...		
function fnSearch(itemAlphabet,forwardURL,itemTypeId)
{
	 itemAlphabet = itemAlphabet.toLowerCase();
	if(document.ItemForm.itemType.value == 'All Products' && document.ItemForm.title1.value=="")
	 {
		setAllCategory('');
	 }
	 else
	{
		 if(document.ItemForm.itemType.value == 'All Products')
		 {
			document.ItemForm.itemType.value = "";
		 }
		 var keyword = document.ItemForm.title1.value;
		 keyword= replaceScript(keyword);
		 // removing dependencies of ato z search from keyword....
		 if(itemAlphabet=="" || itemAlphabet==null)
		{
			  document.ItemForm.title1.value=keyword;		 
		 }
		 else
		{
		 document.ItemForm.title1.value="";
		}
		
		 //REPLACE KEYWORD SEARCH BY TITLE SEARCH 
		 //THAT'S WHY MADE KEYWORD AS ""

        // document.ItemForm.title1.value=keyword;
		// document.ItemForm.keyword.value="";
         document.ItemForm.itemnameatoz.value = itemAlphabet;
		 document.ItemForm.bookItemTypeId.value = itemTypeId;
		 document.ItemForm.allChild.value="0";
		 document.ItemForm.action=forwardURL;	
		 document.ItemForm.submit();
		 tagcloudImpl(keyword);
	}
}
function tagcloudImpl(keyword)
	{
        
		var requestProcessed = false;
        var xmlHttp;
 
    //try {
  //  netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   // } catch (e) {
  //  alert("Permission UniversalBrowserRead denied.");
  // }

    try
    {  
        // Firefox, Opera 8.0+, Safari  
        xmlHttp = new XMLHttpRequest();  
    }
    catch (e)
    {  // Internet Explorer  
        try
        {    
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");    
        }
        catch (e)
        {    
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");      
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");      
                return false;
            }    
        }  
    }
    
    		//  alert('overe here tagcloudImpl');
     xmlHttp.open("POST","/dotcom/tagIndexAction.do?keyword="+keyword,true);
     xmlHttp.send(null);
     

	}
// function that displays the AtoZSearch Div
function setAtoZSearch()
{
	if(document.ItemForm.itemType.value == 'All Products' && document.ItemForm.title1.value=="")
	 {
		 document.getElementById('atozsearch').style.display='none';
	 }
	 else
	{
	document.getElementById('atozsearch').style.display='block';
	}
}
// function that hides the AtoZSearch Div
function fnCloseAtoZSearch()
{
	document.getElementById('atozsearch').style.display='none';
}

// ask bhavisa abt this.....
function fngetCurrDateTime()
{
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	if (minutes < 10)
	minutes = "0" + minutes;
	if (seconds < 10)
	seconds = "0" + seconds;
	var dateTime=day+"/"+month+"/"+year+"/"+hours+"/"+minutes+"/"+seconds;
	return dateTime;
}

// this function is called when serach is made from the get search result.jsp
//ie. related item search or keyword search
function searchRelatedItem(itemId,keyword)
{	
	//for search from here flag false is passed ....
	document.ItemForm.title1.value=keyword;	
	document.getElementById('searchResultsTable').style.display='block';	
	document.getElementById('ItemDescriptionTable').style.display='none';
	document.getElementById(searchClearDivItemId).style.display='none';
	document.getElementById('additionalDetails').style.display='none';		
	document.getElementById('feedback').style.display='none';
	document.getElementById('recommend').style.display='none';
	document.getElementById('additionalDetailsLink').className="";
	document.getElementById('allSearchResultsOnlyLink').className="current";
	itemSearchResult("0",itemId,"false");
}
// function that fills the attributes in the book layout/gift layout etc.....
function fillSelectedItemType(http_request_setItemType,requiredItemType,orgID,entityTypeId)
{
	if (http_request_setItemType.readyState == 4)
	{			
		if (http_request_setItemType.status == 200)
		 {
			var itemtypelist= document.ItemForm.itemType;
			itemtypelist.options[0]= new Option(requiredItemType,requiredItemType);		
			var responseDoc= http_request_setItemType.responseXML;
			var docs = responseDoc.getElementsByTagName("DOCUMENT");	
			var noOfDocuments = docs.length;
			var fields;
			var i=1;
			var j =1;
			for(count=0;count<noOfDocuments;count++)			
		 	{				
				fields = docs[count].getElementsByTagName("FIELD");				
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
			 	{		 					
					var itemType = fields[fieldCount].getAttribute("name");	
					if(itemType == 'itmtypmstritemtypeid')
					{
						book_ItemType_ID = fields[fieldCount].firstChild.nodeValue;
						book_ItemType_ID = replace(book_ItemType_ID);
					}
					if(itemType == 'attributes')
					{						
				 		var attributes = fields[fieldCount].firstChild.nodeValue;	
						if(!attributes == "")
						{
							attributes = replace(attributes);	
							var attribute = attributes.split("#");
							for(attCount=0;attCount<attribute.length-1;attCount++)
							{
								if(attribute[attCount].toLowerCase()=='author' || attribute[attCount].toLowerCase()=='publisher' ||  attribute[attCount].toLowerCase()=='isbn')
								{
									//attribute[attCount] = attribute[attCount].toUpperCase();
									itemtypelist.options[j]= new Option(attribute[attCount],attribute[attCount]);
									j++;
								}
								i++;
							}


				   		}										 	
					}
				}
			}
		 }			
	}
}
// function that removes zeros from the price that were  added to make the range search work....
function removeZeros(dataFromIndex){	
	var len = dataFromIndex.length;
	var value1 = '';
	var findIndex = -1;
	if(dataFromIndex == '000000000000000000000000000.00')
	{
		dataFromIndex = '0';	
		return dataFromIndex;
	}
	for(j=0;j<len;j++){
		value1 = dataFromIndex.substring(j,j+1);				
		if(eval(value1) != 0){			
			findIndex = dataFromIndex.indexOf(value1);			
			break;
		}
	}

	dataFromIndex = dataFromIndex.substring(findIndex);	
	return dataFromIndex;
}

// function that replaces "</script>" from keyword....
function replaceScript(str)
{	
	str=str.toLowerCase();
	var string="";	
	var newstr = str.replace("<script>", "script");
	newstr=newstr.replace("</script>", "script");
	return newstr;
}
//function that decides whetere to show the AtoZsearch div in inner layout...
// for isbn author it is not diplayed for book music it is displayed....
function setAtoZSearchLayout(itemtype)
{
	var selectedValue = document.ItemForm.itemType.value;
	selectedValue = selectedValue.toLowerCase();
	itemtype = itemtype.toLowerCase();
	if(selectedValue == itemtype)
	 {
		 document.getElementById('atozsearch').style.display='block';
	 }
	 else
	{
	document.getElementById('atozsearch').style.display='none';
	}
}

//on click of advanced search this function is called
function showAdvancedSearchPage()
{
	var url = '/dotcom/'+gOrgFolder+'/jsp/search/AdvancedSearch.jsp?';	
	document.ItemForm.action=url;	
	document.ItemForm.submit();
}
// function that fills the itemtype in the advanced search page.....
function fillAdvancedItemType(http_request)
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		 {			
			var i=1;		
			var itemtypelistAdvanced= document.AdvancedSearchPageForm.itemType;		
			itemtypelistAdvanced.options[0]= new Option("All Products","All Products");
			var responseDoc= http_request.responseXML;
		 	var docs = responseDoc.getElementsByTagName("DOCUMENT");	
			var noOfDocuments = docs.length;
			var fields;	
			for(count=0;count<noOfDocuments;count++)			
		 	{				
				fields = docs[count].getElementsByTagName("FIELD");				
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
			 	{						
					
					var itemType = fields[fieldCount].getAttribute("name");									
					if(itemType == 'itmtypmstritemtypename')
					{						
						var itemTypeData = fields[fieldCount].firstChild.nodeValue;						
						itemTypeData = replace(itemTypeData);	
						allItemType[i-1] = itemTypeData;	
						//itemTypeData = itemTypeData.toUpperCase();					
						itemtypelistAdvanced.options[i]= new Option(itemTypeData,itemTypeData);	
						i++;
					}
				}				
			}
		}
	}
}
// function that fills the categories in the advanced search page.....	
function fillCategoryInAdvancedSearch(http_request_category)
{	
	if (http_request_category.readyState == 4)
	{			
		if (http_request_category.status == 200)
		 {
			var i=1;
			var categoryList= document.AdvancedSearchPageForm.categoryID;
			categoryList.options.length=0;
			categoryList.options[0]= new Option("All Category","All Category");	
			var responseDoc= http_request_category.responseXML;		 
			var docs = responseDoc.getElementsByTagName("DOCUMENT");	
			var noOfDocuments = docs.length;		
			var fields;	
			var categoryIdData = new Array();
			var categoryNameData = new Array();
			for(count=0;count<noOfDocuments;count++)			
		 	{				
				fields = docs[count].getElementsByTagName("FIELD");				
				for(fieldCount=0;fieldCount<fields.length;fieldCount++)
			 	{					
					var categoryName = fields[fieldCount].getAttribute("name");		
					if(categoryName == 'catviewcategoryid')
					{
						categoryIdData[count] = fields[fieldCount].firstChild.nodeValue;
						categoryIdData[count] = replace(categoryIdData[count]);
						//categoryIdData[count] = categoryIdData[count].toUpperCase();
					}
					if(categoryName == 'catviewcategoryname')
					{
						categoryNameData[count] = fields[fieldCount].firstChild.nodeValue;
						categoryNameData[count] = replace(categoryNameData[count]);
						//categoryNameData[count] = categoryNameData[count].toUpperCase();
	
					}					
					categoryList.options[i]= new Option(categoryNameData[count],categoryIdData[count]);
				}
				i++;							
			}			
		}
	}					
}
// method that display the addtional search criteria depending upon the itemtype selected....
function fnShowHideDivInAdvancedSearch(selectedItemType)
{	
	//alert("recieved..selectedItemType..."+selectedItemType);
	document.getElementById('books').style.display='none';
	document.getElementById('gifts').style.display='none';
	document.getElementById('music').style.display='none';
	document.getElementById('multimedia').style.display='none';
	document.getElementById('stationery').style.display='none';
	document.getElementById('gobutton').style.display='none';

	if(selectedItemType=="All Products")
	{
		document.getElementById('gobutton').style.display='block';
	}
	else
	{
		selectedItemType = selectedItemType.toString();
		selectedItemType = selectedItemType.toLowerCase();
		//alert("selectedItemType..."+selectedItemType);
		if (document.getElementById(selectedItemType).style.display=='block')
		{
		  document.getElementById(selectedItemType).style.display='none';
		 
		}
		else
		{
		  document.getElementById(selectedItemType).style.display='block';
		  document.getElementById('gobutton').style.display='block';	
		  
		}
	}
	 
	// seting all previous selected values to blank......
	document.AdvancedSearchPageForm.title1.value='';
	document.AdvancedSearchPageForm.author1.value='';
	document.AdvancedSearchPageForm.publisher1.value='';
	document.AdvancedSearchPageForm.isbn1.value='';;

	// setting the radio button depending upon the itemtype selected from the drop down...
	//var fieldLen = document.AdvancedSearchPageForm.RadioGroup1.length;	
	//for(count=0;count<fieldLen;count++)
	//{
		//if(document.AdvancedSearchPageForm.RadioGroup1[count].value.toLowerCase()==selectedItemType)
		//{
			//document.AdvancedSearchPageForm.RadioGroup1[count].checked=true;
		//}
		//else
		//{
		//document.AdvancedSearchPageForm.RadioGroup1[count].checked=false;
		//}
	//}
}
// function that sets the itemtype and other search criteria depending upon the radio button selected.....
function setAdvacedSeacrhItemType()
{
	
	//var fieldLen = document.AdvancedSearchPageForm.RadioGroup1.length;	
	//var itemtype="";
	//for(count=0;count<fieldLen;count++)
	//{		
		//if(document.AdvancedSearchPageForm.RadioGroup1[count].checked)
		//{
			//itemtype = document.AdvancedSearchPageForm.RadioGroup1[count].value;
			//break;
		//}
	//}	
	
	var itemtypeLen = document.AdvancedSearchPageForm.itemType.options.length;
	for(count=0;count<itemtypeLen;count++)
	{
		
		
		itemtype = itemtype.toLowerCase();
		if(document.AdvancedSearchPageForm.itemType.options[count].value.toLowerCase()==itemtype)
		{
			document.AdvancedSearchPageForm.itemType.options[count].selected=true;
			break;
		}
	}
	setCategoryInAdvancedSearch(itemtype);
}

//function thats called on click of advanced search....

function fnSearchFromAdvancedSearch(forwardURL)
 {
	if(document.AdvancedSearchPageForm.itemType.value=='All Products' && document.AdvancedSearchPageForm.categoryID.value == '-1' && document.AdvancedSearchPageForm.price.value=="-1" && document.AdvancedSearchPageForm.keyword.value=="" && document.AdvancedSearchPageForm.title1.value=="" && document.AdvancedSearchPageForm.author1.value=="" && document.AdvancedSearchPageForm.publisher1.value=="" && document.AdvancedSearchPageForm.isbn1.value=="")
	 {
		setAllCategory('');
	 }
	 else
	 {
	 	document.AdvancedSearchPageForm.isFromAdvancedSearch.value="1";
		 if(document.AdvancedSearchPageForm.itemType.value=='All Products')
	 	{
			document.AdvancedSearchPageForm.itemType.value = "";
		 } 
		 if(document.AdvancedSearchPageForm.categoryID.value == 'All Category' || document.AdvancedSearchPageForm.categoryID.value == '-1')
	 	{
			document.AdvancedSearchPageForm.categoryID.value = "";
			document.AdvancedSearchPageForm.category.value = "";
			document.AdvancedSearchPageForm.allChild.value = "0";
		 } 
	 	else
	 	{
			document.AdvancedSearchPageForm.category.value = document.AdvancedSearchPageForm.categoryID[document.AdvancedSearchPageForm.categoryID.selectedIndex].text; 
			document.AdvancedSearchPageForm.allChild.value = "1";
	 	}
	 
		if(document.AdvancedSearchPageForm.price.value == '[Select One]' || document.AdvancedSearchPageForm.price.value=="-1")
		{
			document.AdvancedSearchPageForm.price.value = "";
		}			
		 var keyword = document.AdvancedSearchPageForm.keyword.value;
		 keyword= replaceScript(keyword);
		 document.AdvancedSearchPageForm.keyword.value=keyword;	
		 var title1 = document.AdvancedSearchPageForm.title1.value;
		 title1= replaceScript(title1);
		 document.AdvancedSearchPageForm.title1.value=title1;	
	 	var author1 = document.AdvancedSearchPageForm.author1.value;
		 author1= replaceScript(author1);
		 document.AdvancedSearchPageForm.author1.value=author1;	
		 var publisher1 = document.AdvancedSearchPageForm.publisher1.value;
		 publisher1= replaceScript(publisher1);
		 document.AdvancedSearchPageForm.publisher1.value=publisher1;	
		 var isbn1 = document.AdvancedSearchPageForm.isbn1.value;
		 isbn1= replaceScript(isbn1);
		 document.AdvancedSearchPageForm.isbn1.value=isbn1;		
		document.AdvancedSearchPageForm.action=forwardURL;
		document.AdvancedSearchPageForm.submit();
	}
}
//function thats called when some one clicks on the itemimage to see item description.....
function fnShowDetails(itemID,itemName,imageSrc,authorName,itemPrice,itemPriceUsd,shippingInfo,bindingInfo,itemdescription)
{
    itemName = itemName.replace(/\*\$/g, "'");
    itemdescription = itemdescription.replace(/\*\$/g, "'");
if (authorName && authorName!='UNKNOWN')
{
	document.title = itemName + " By " + authorName;
	setMetatags(itemName + " By " + authorName,itemdescription);
}
else
{   
	document.title = itemName ;
	setMetatags(itemName,itemdescription);
}

searchClearDivItemId=itemID;
searchClearDivItemName=itemName;
searchimageSrc = imageSrc;
searchauthorName= authorName;
searchitemPrice= itemPrice;
searchitemPriceUsd= itemPriceUsd;
searchshippingInfo= shippingInfo;
searchbindingInfo=bindingInfo;
//imageSrc = ;
//authorName = ;
//itemPrice = ;
//itemPriceUsd = ;
//shippingInfo = ;
//bindingInfo = ;




//show_book_description(book_object);
/*
//document.getElementById('searchResultsTable').style.display='none';		
document.getElementById('ItemDescriptionTable').style.display='block';
document.getElementById(itemID).style.display='block';
document.getElementById('additionalDetails').style.display='block';		
document.getElementById('feedback').style.display='block';
document.getElementById('recommend').style.display='block';
document.getElementById('additionalDetailsLink').className="current";
document.getElementById('allSearchResultsOnlyLink').className="";
document.getElementById('pageLabels').style.display='none';	*/
//rahul
	//addfeedback(itemID,itemName);	
	//getShippingTime(itemID);
	//getCustomerRelatedItems(itemID);
}
//funvtion that is called when some one clicks on the my serch link.. from the description page...
function fnDisplaySerachResultsOnly()
{
document.getElementById('searchResultsTable').style.display='block';	
document.getElementById('ItemDescriptionTable').style.display='none';
document.getElementById(searchClearDivItemId).style.display='none';
document.getElementById('additionalDetails').style.display='none';		
document.getElementById('feedback').style.display='none';
document.getElementById('recommend').style.display='none';
document.getElementById('additionalDetailsLink').className="";
document.getElementById('allSearchResultsOnlyLink').className="current";
document.getElementById('pageLabels').style.display='block';	
document.getElementById('feedbackLink').className="";
document.getElementById('recommendLink').className="";
document.getElementById('FeedBackTable').style.display='none';
document.getElementById('RecommendTable').style.display='none';
clearDIV('AddEdit1'+searchClearDivItemId);
clearDIV('RecommendItem'+searchClearDivItemId);
}
function feedbackCall(book_object)
{

/*document.getElementById('additionalDetailsLink').className="";
document.getElementById('feedbackLink').className="current";
document.getElementById('recommendLink').className="";*/
document.getElementById('FeedBackTable').style.display='block';
clearDIV('AddEdit1'+searchClearDivItemId);
clearDIV('RecommendItem'+searchClearDivItemId);
searchClearDivItemId=book_object.book_id;
searchClearDivItemName=book_object.name;
addfeedbackAdd(searchClearDivItemId,searchClearDivItemName);
}
function fnDisplayItemDescriptionOnly()
{
	document.getElementById('FeedBackTable').style.display='none';
		document.getElementById('RecommendTable').style.display='none';
	document.getElementById('additionalDetails').style.display='block';
	document.getElementById('additionalDetailsLink').className="current";
document.getElementById('allSearchResultsOnlyLink').className="";
document.getElementById('feedbackLink').className="";
document.getElementById('recommendLink').className="";
}
function recommendCall(book_object)
{
/*document.getElementById('additionalDetailsLink').className="";
document.getElementById('feedbackLink').className="";
document.getElementById('recommendLink').className="current";
document.getElementById('RecommendTable').style.display='block';*/
clearDIV('RecommendItem'+searchClearDivItemId);
clearDIV('AddEdit1'+searchClearDivItemId);
searchClearDivItemId=book_object.book_id;
searchClearDivItemName=book_object.name;
searchimageSrc=book_object.image;
searchauthorName=book_object.author;
searchitemPrice=book_object.item_price;
searchitemPriceUsd=book_object.offered_price;
searchshippingInfo=book_object.item_lead_time_data;
searchbindingInfo=book_object.binding_description;
recommenditem(searchClearDivItemId,searchClearDivItemName,searchimageSrc,searchauthorName,searchitemPrice,searchitemPriceUsd,searchshippingInfo,searchbindingInfo);
//recommenditem(searchClearDivItemId,searchClearDivItemName,'/dotcom/oxford/images/oxford_logo.jpg','ALISTER','0125','20100.00','null','paperback');
}









function setAuthor(authorname)
{
	
	document.AddToCart.author1.value=authorname;
	document.AddToCart.action="/dotcom/oxford/jsp/search/GetSearchResults.jsp?authorFlag=1";
    document.AddToCart.submit();
	
}

	

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) 
{	
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) 
		n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec; 
	if (z<0) z--; 
	for(var i = z; i < 0; i++) y.unshift('0');
	y.splice(z, 0, pnt); 
	if(y[0] == pnt) y.unshift('0'); 
	while (z > 3) {
		z-=3; 
		y.splice(z,0,thou);
	}
	var r = curr1+n1+y.join('')+n2+curr2;
	return r;
}

function setMetatags(booktitle,description)
{

var metatags = document.getElementsByTagName("meta");

for (var cnt = 0; cnt < metatags.length; cnt++)
    {
        var name = metatags[cnt].getAttribute("name");
        var content = metatags[cnt].getAttribute("content");

       // Update the Title meta tag
        if (metatags[cnt].getAttribute("name") == "Keywords")
              metatags[cnt].setAttribute("content", booktitle);
		else if (metatags[cnt].getAttribute("name") == "description")
              metatags[cnt].setAttribute("content", description);
    }


}

function SearchImgLoad(imgObj, imagePath) 
{ 
   var oImg=new Image; 
   var imageSource;
   oImg.onload=function(){imgObj.src=imagePath; imageSource = imagePath;}
   oImg.onerror=function(){/*imgObj.src='/dotcom/'+gOrgFolder+'/images/oxford_logo.jpg';*/ imageSource = '/dotcom/'+gOrgFolder+'/images/oxford_logo.jpg';}
   //oImg.src=imagePath;
   //oImg.src=setTimeout(imagePath,20);
   setTimeout("function(){}",100);
 // sleep(10000);
   return imageSource;
}
 

function create_book_object(id, name, usdActual, itemlPrice, itemlDiscountedPrice, usdDiscount, youSave, usdYouSave, author1Data, imageSrc, itemLeadTimeData, bindingDescription1Data, itemDescriptionData, isbnNo1Data, publisher1Data, itemPublicationDateData, imagePath, imageDefault)
{ 
	//alert(name + "...................  "+usdActual);
    var book_object = {
   "name": name.toUpperCase(),
   "author_Actual": author1Data,
   "author":(author1Data != "")?"By "+author1Data:"",
	   
   "image":(imagePath==undefined || imagePath ==null || imagePath=="undefined")?"/dotcom/oxford/images/oxford_logo.jpg":"/dotcom/oxford/"+imagePath,
   //"image":"/dotcom/oxford/images/oxford_logo.jpg",
   "item_price": itemlPrice,
   "offered_price":itemlDiscountedPrice,
   "item_discount_price":itemlDiscountedPrice,
   "item_price_usd":usdActual,
   "$_price_actual":usdActual.split(".")[0],
   "rs_price_actual":itemlPrice.split(".")[1],
   "cent_price_actual":usdActual.split(".")[1],
   "paise_price_actual":itemlPrice.split(".")[2],
    "$_price_offered":(usdDiscount)?usdDiscount.split(".")[0]:"",
   "rs_price_offered":(usdDiscount)?itemlDiscountedPrice.split(".")[1]:"",
   "cent_price_offered":(usdDiscount)?usdDiscount.split(".")[1]:"",
   "paise_price_offered":(usdDiscount)?itemlDiscountedPrice.split(".")[2]:"",
   "$_price_discount":(usdDiscount)?usdYouSave.split(".")[0]:"",
   "rs_price_discount":(usdDiscount)?youSave.split(".")[0]:"",
   "cent_price_discount":(usdDiscount)?usdYouSave.split(".")[1]:"",
   "paise_price_discount":(usdDiscount)?youSave.split(".")[1]:"",
   "book_id":id,
   "item_lead_time_data": itemLeadTimeData,
   "binding_description": bindingDescription1Data,
   "item_description": itemDescriptionData,
   "publisher": publisher1Data,
   "year_of_publication": itemPublicationDateData,
   "isbn": isbnNo1Data
};
return book_object;
}

function createBookDetail(book_object){
var book_detail = "";
var i=book_object.book_id;
var bookid =  i;

//var imgSrc = imgObj.load SearchImgLoad(imgObj, book_object.image); 
//alert("......."+book_object.image);
book_detail += "<div id=\"GiftWrapper"+ bookid +"\">";
book_detail += "<div class='book_detail' id=" + bookid + ">";
book_detail += "	<div class=\"book_img\"><a href=\"/dotcom/oxford/jsp/search/getItemdetails.jsp?itemid="+i+"\"><img id=itemImage" + i + " src="+book_object.image+" ></a> <\/div>";
book_detail += "    <div class=\"book_description\">";
book_detail += "    	<div class=\"book_title\"><a href=\"/dotcom/oxford/jsp/search/getItemdetails.jsp?itemid="+i+"\" class=\"check_link\"><strong>" + book_object.name +"<\/strong></a> <\/div>";
book_detail += "        <div class=\"book_author\">" + book_object.author + "<\/div>";
//book_detail += "        <div class=\"ratingdiv\">Rating: <div id=\"rate"+i+"\" class=\"rating\"></div></div>";
book_detail += "        <div class=\"book_amount\">";
book_detail += "        	<div class=\"book_actual_price\">";
book_detail += "            	<div class=\"price_button\"><img src=\"\/dotcom\/oxford\/images\/price_button.gif\"\/><\/div>";
book_detail += "                <div class=\"price_details\">";
book_detail += "                	<div class=\"rupee_symbol\"><img src=\"\/dotcom\/oxford\/images\/ico_rupee.gif\" align=\"absmiddle\"\/><\/div>";
book_detail += "                    <div class=\"rupee_amount\"><span class=\"rupees\">" + book_object.rs_price_actual+ "<\/span><span class=\"paise\">." + book_object.paise_price_actual + "<\/span><\/div>";
book_detail += "                    <div class=\"dollar_symbol\"><img src=\"\/dotcom\/oxford\/images\/ico_dollar.gif\" align=\"absmiddle\"\/><\/div>";
book_detail += "                    <div class=\"dollar_amount\"><span class=\"rupees\">" + book_object.$_price_actual+ "<\/span><span class=\"paise\">." + book_object.cent_price_actual + "<\/span><\/div>";
book_detail += "            <\/div>";
book_detail += "    ";
book_detail += "            <\/div>";

if(book_object.rs_price_offered){
	
    // .css('text-decoration','line-through').css("color","red");
	book_detail += "            <div class=\"book_offered_price\">";
	book_detail += "            	<div class=\"price_button\"><img src=\"\/dotcom\/oxford\/images\/offered_price_buttton.gif\"\/><\/div>";
	book_detail += "                <div class=\"price_details\">";
	book_detail += "                	<div class=\"rupee_symbol\"><img src=\"\/dotcom\/oxford\/images\/ico_rupee.gif\" align=\"absmiddle\"\/><\/div>";
	book_detail += "                    <div class=\"rupee_amount\"><span class=\"rupees\">" + book_object.rs_price_offered+ "<\/span><span class=\"paise\">." + book_object.paise_price_offered + "<\/span><\/div>";
	book_detail += "                    <div class=\"dollar_symbol\"><img src=\"\/dotcom\/oxford\/images\/ico_dollar.gif\" align=\"absmiddle\"\/><\/div>";
	book_detail += "                    <div class=\"dollar_amount\"><span class=\"rupees\">" + book_object.$_price_offered+ "<\/span><span class=\"paise\">." + book_object.cent_price_offered + "<\/span><\/div>";
	book_detail += "                <\/div>";
	book_detail += "    ";
	book_detail += "          <\/div>";
	book_detail += "           <div class=\"discount_price\">";
	book_detail += "           		<div class=\"price_button\"><img src=\"\/dotcom\/oxford\/images\/dicount_price_button.gif\"\/><\/div>";
	book_detail += "                <div class=\"price_details\">";
	book_detail += "                	<div class=\"rupee_symbol\"><img src=\"\/dotcom\/oxford\/images\/ico_rupee.gif\" align=\"absmiddle\"\/><\/div>";
	book_detail += "                    <div class=\"rupee_amount\"><span class=\"rupees\">" + book_object.rs_price_discount+ "<\/span><span class=\"paise\">." + book_object.paise_price_discount + "<\/span><\/div>";
	book_detail += "                    <div class=\"dollar_symbol\"><img src=\"\/dotcom\/oxford\/images\/ico_dollar.gif\" align=\"absmiddle\"\/><\/div>";
	book_detail += "                    <div class=\"dollar_amount\"><span class=\"rupees\">" + book_object.$_price_discount+ "<\/span><span class=\"paise\">." + book_object.cent_price_discount + "<\/span><\/div>";
	book_detail += "                <\/div>";
	book_detail += "    ";
	book_detail += "          <\/div>";
}
else{
	// $(".book_actual_price").css("border-right","0px");
}
book_detail += "</div>";
book_detail += "        <\/div>";
book_detail += "    <\/div>";
book_detail += "<\/div>";

return(book_detail);

}

function create_note_for_dollar_price(){
var note="";
note += "<div class='note'>";
note += "        	<span class=\"price_description\">( * Dollar prices are indicative only and calculated on the date of exchange )<\/span>";
note += "        <\/div>";
return(note);

}
function create_book_action_detail(cart_object, gCartOnConfirm){
var book_action_detail="";
if(gCartOnConfirm == true)
	{
	book_action_detail += "        <div class=\"book_action_detail\">";
    book_action_detail += "        	<div class=\"book_detail_title\"><strong>Quantity:<\/strong><\/div>";
	book_action_detail += "            <div class=\"book_quantity\"><span>"+cart_object.quantity+"</span<\/div>";
	book_action_detail += "        <\/div>";
	}
	else{
book_action_detail += "        <div class=\"book_action_detail\">";
book_action_detail += "        	<div class=\"book_detail_title\"><strong>Quantity<\/strong><\/div>";
if(gCartOnConfirm == false)
	{
book_action_detail += "            <div class=\"book_quantity\"><input type=\"text\" maxlength=\"5\" id=\"Quant"+cart_object.book_id+"\" value="+cart_object.quantity+" style=\"width:75px;\"><\/div>";
	}
else
	{
book_action_detail += "            <div class=\"book_quantity\"><span>"+cart_object.quantity+"</span<\/div>";
	}
book_action_detail += "              <div class=\"item_action\">";
book_action_detail += "                        <a href=\"javascript:onclick=deleteItem('"+cart_object.book_id+"')\" class=\"action_link\"><img src=\"\/dotcom\/oxford\/images\/ico_delete.gif\"\/> Delete<\/a>";
book_action_detail += "                        <a href=\"javascript:onclick=updateQuantity('"+cart_object.book_id+"')\" class=\"action_link\"><img src=\"\/dotcom\/oxford\/images\/ico_update.gif\"\/> Update<\/a>";
book_action_detail += "                        <a href=\"javascript:onclick=showGifts('"+cart_object.book_id+"')\" class=\"action_link\" id=\"gift_wrap_bookid\"><img src=\"\/dotcom\/oxford\/images\/ico_wrap.gif\"\/> Gift Wrapper<\/a>";
book_action_detail += "	       <\/div>";
book_action_detail += "        <\/div>";
	}
return(book_action_detail);

}
function create_addtocart_button_area(itemIdData){
var cart_button="";
cart_button += "<div class=\"addtocart_button\"><a href=\"javascript:onclick=AddToCart('"+itemIdData+"')\"\"><img src=\"\/dotcom\/oxford\/images\/add_to_cart_button.gif\"\/><\/a><\/div>"
cart_button += "    ";
return(cart_button);

}
function create_showdetail_button_area(itemIdData){
var showdetail_button="";
showdetail_button += "<div class=\"showdetail_button\"><a href=\"/dotcom/oxford/jsp/search/getItemdetails.jsp?itemid="+itemIdData+"\"><img src=\"\/dotcom\/oxford\/images\/show_details_button.gif\"\/><\/a><\/div>"
showdetail_button += "    ";
return(showdetail_button);

}

function create_qty_wrap_design_area(){
var qty_wrap_design="";
qty_wrap_design += "<div class=\"book_qty_wrap_detail\">";
qty_wrap_design += "        <div class=\"quantity_area\">Quantity <strong>1<\/strong><\/div>";
qty_wrap_design += "        <div class=\"gift_wrapper_design\">Gift Wrapping: <strong>Gift Wrapper - Bee Design<\/strong><\/div>";
qty_wrap_design += "    <\/div>";
qty_wrap_design += "    <div class=\"item_action\"><a href=\"#\" class=\"showalert\"><img src=\"\/dotcom\/oxford\/images\/edit_item_buttn.gif\"\/><\/a> <\/div>";
return(qty_wrap_design);
}



function show_book_description(book_object){

	if (book_object.author && book_object.author!='UNKNOWN')
{
	document.title = book_object.name + " By " + book_object.author;
}
else
{
	document.title = book_object.name ;
	setMetatags(book_object.name,book_object.item_description);
}
  var searchCondition = jQuery("#searchCondition");
  //searchCondition.empty();
  var searchContainer = jQuery("#searchResultsTable");
 // searchContainer.empty();
  var pagingDetailsDiv = jQuery("#pagingDetails");
  pagingDetailsDiv.empty();
  //var bookTitleElement = jQuery("<a href=# class=\"check_link\" data=" + i + "><strong>" + book_object.name +"<\/strong><\/a>");
  var detailstablediv = jQuery("<div class=\"details_table_container\"></div>").css({'width':'100%', 'padding':'10px','height':'80px'});

        var lRequest;
	    var lXMLResponse;
		var lAJAXInteraction;
		var itemTypeId=book_object.book_id;
		//lAJAXInteraction = new AJAXInteraction('/dotcom/FMRatingsPrefetch.kar?itemTypeId='+itemTypeId, null,true);
		lAJAXInteraction = new AJAXInteraction('/dotcom/FMRatingsPrefetch.kar?itemTypeId='+itemTypeId+"&OrgId="+gOrgID, null,true);
		lRequest = lAJAXInteraction.doPost('LK=' + gLoginKey);
		lXMLResponse = lRequest.responseXML;
		var x=lXMLResponse.getElementsByTagName('ENTITY');
        var ratingsaverage;
		var ratingscount;
		for (i=0;i<x.length;i++)
		{
			ratingsaverage=x[i].getAttribute('ratingsaverage');
			ratingscount=x[i].getAttribute('ratingscount');
		
		} 		

 // var bookratingdiv =jQuery("<div >Rating: <div class=\"rating\"></div></div>");
  jQuery("#demo-container").empty().append(create_description_header(book_object)).css("background","#fff");
  searchContainer.append(createBookDetail(book_object));
  
  searchContainer.append(detailstablediv.append(create_book_info_table(book_object)));
  searchContainer.append(creat_book_description(book_object));
  jQuery("#" + book_object.book_id + " .book_amount").before("<div class=\"ratingdiv\">Rating: <div id=\"rate"+book_object.book_id+"\" class=\"rating\"></div></div>");
   $("#rate"+book_object.book_id).addClass(ratingsaverage).append("<div>"+ratingscount+"</div>"); 
  searchContainer.append("<div class=\"book_result_seperator\"></div>");
				
				if(jQuery("#" + book_object.book_id + " .book_offered_price").length){
					jQuery("#" + book_object.book_id + " .book_actual_price").css("border-right","1px dotted #CBCBCB");
					jQuery("#" + book_object.book_id + " .book_actual_price span").css("text-decoration","line-through");
				}else{
					 jQuery("#" + book_object.book_id + " .book_actual_price").css("border-right","0px");
					 jQuery("#" + book_object.book_id + " .book_actual_price span").css("text-decoration","none");
               }
  //$("#" + book_object.book_id).find(".book_title").append(bookTitleElement);
 
  jQuery(".book_detail").append(create_addtocart_button_area(book_object.book_id));
  jQuery("#" + book_object.book_id + " .addtocart_button").css("float","none");
   $("#" + book_object.book_id + " .book_description").append(create_note_for_dollar_price());
  var feedBackTable = jQuery("#FeedBackTableTd");
  feedBackTable.append(jQuery("<div id=AddEdit1"+book_object.book_id+" style =\"display:none;\"></div>"));
   var recommendItemTable = jQuery("#RecommendTableTd");
  recommendItemTable.append(jQuery("<div id=RecommendItem"+book_object.book_id+" style =\"display:none;\"></div>"));
// jQuery(".book_description").before("<div class=\"book_result_seperator\"></div>");
 $(".searchresults_page").hide();
 var imgObj = jQuery("#" + book_object.book_id + " .book_img img"); //.append(bookTitleElement);
				//alert(book_object1.image);
				imgObj.attr("src", book_object.image);

				imgObj.load(function(book_object){
				 // var imgsrcc = book_object.image;
				  //alert("ok" + $(this).attr("src"));
				 // $(this).attr("src",imgsrcc);

				});
				imgObj.error(function(){
				   var imgsrcc = "/dotcom/oxford/images/oxford_logo.jpg";
				  // alert("ok error" + $(this).attr("src"));
				   $(this).attr("src",imgsrcc);
				});
                
				//searchContainer.append("<div class=\"book_result_seperator\"></div>");
		   
}
function appendEmailAFriendForm(itemId)
{
var searchContainer = jQuery("#searchResultsTable");
searchContainer.append(create_Email_form());
}

function appendFeedbackForm(itemId)
{
var searchContainer = jQuery("#searchResultsTable");
searchContainer.append(create_feedback_form());
}

function create_book_info_table(book_object){
	var book_info_details="";
if(book_object.isbn != "null" && book_object.isbn != "" && book_object.isbn != null && book_object.publisher != "null" && book_object.publisher != "" && book_object.publisher != null && book_object.year_of_publication != "null" && book_object.year_of_publication != "" && book_object.year_of_publication != null && book_object.binding_description != "null" && book_object.binding_description != "" && book_object.binding_description != null)
{
book_info_details += "<div style=\"padding:10px;float:left;width:300px;background:#e5e5e5;\"><table width=\"100%\" style=\" padding:5px; \">";
if(book_object.isbn != "null" && book_object.isbn != "" && book_object.isbn != null){
book_info_details += "                                    <tr>";
book_info_details += "                                      <td> ISBN";
book_info_details += "                                      <\/td>";
book_info_details += "                                      <td> "+book_object.isbn;
book_info_details += "                                      <\/td>";
book_info_details += "                                      ";
book_info_details += "                                    <\/tr>";
}
if(book_object.publisher != "null" && book_object.publisher != "" && book_object.publisher != null){
book_info_details += "                                    <tr> ";
book_info_details += "                                      <td>Publisher";
book_info_details += "                                      <\/td>";
book_info_details += "                                      <td>"+book_object.publisher;
book_info_details += "                                      <\/td>";
book_info_details += "                                    <\/tr>";
}
if(book_object.year_of_publication != "null" && book_object.year_of_publication != "" && book_object.year_of_publication != null ){
book_info_details += "                                    <tr>";
book_info_details += "                                      <td>Year of Publishing";
book_info_details += "                                      <\/td>";
book_info_details += "                                      <td>"+book_object.year_of_publication;
book_info_details += "                                      <\/td>";
book_info_details += "                                    <\/tr>";
}
if(book_object.binding_description != "null" && book_object.binding_description != "" && book_object.binding_description != null){
book_info_details += "                                    <tr>";
book_info_details += "                                     <td>Binding";
book_info_details += "                                      <\/td>";
book_info_details += "                                      <td>"+book_object.binding_description;
book_info_details += "                                      <\/td>";
book_info_details += "                                    <\/tr>";
}
book_info_details += "                                    ";
book_info_details += "                                   <\/table></div>";
}
return(book_info_details);	
}


function creat_book_description(book_object){
var creat_book_description="";
creat_book_description += "<div class=\"book_detail_info\">";
creat_book_description += "     <h3>Description<\/h3>";
creat_book_description +=     "<p> " +  book_object.item_description + " </p>";
creat_book_description += "  <\/div>";
if(book_object.author_Actual!=null && book_object.author_Actual!='' && book_object.author_Actual!="null")
{
creat_book_description += "<div class=\"book_detail_info\"><a href=\"javascript:onclick=setAuthor('"+book_object.author_Actual+"')\" class=\"productdetails_orange\">Other Books by this Author<\/a><\/div>";
}
return(creat_book_description);	
}
//var obj = {name : "bookname", id : "bookid"};
function create_description_header(book_object){
addthis_pub  = 'oxford_bookstore';
//var bkobj = jQuery.parseJSON(book_object);
book_object_var = book_object;
//alert("Object " + obj);
var description_header="";
description_header += "<div class=\"task_header\">";
description_header += "    	<div class=\"task_desciption_area\" style=\"float: left; padding-top: 12px;\">";
description_header += "            ";
description_header += "            <div class=\"feedback\" style=\"float: left; margin: 0px 5px 3px 2px; padding: 2px;\"><a href=\"javascript:feedbackCall(book_object_var)\"\"><img alt=\"Feedback\" src=\"\/dotcom\/oxford\/images\/feedback_buttn.gif\"></a><\/div>";
description_header += "            <div class=\"forward\" style=\"float: left; margin: 0px 5px 3px 2px; padding: 2px;\"><a href=\"javascript:recommendCall(book_object_var)\"\"><img alt=\"Email a Friend\" src=\"\/dotcom\/oxford\/images\/email_buttn.gif\"></a><\/div>";
description_header += "        <\/div>      ";
description_header += "	    ";
description_header += "        <div style=\"float: right; padding: 13px 0px 18px ;\"> <a class=\"request_button\" href=\"javascript:findItem();\"><img src=\"\/dotcom\/oxford\/images\/request_button.gif\"></a><\/div>  ";
description_header += "        <div style=\"float: right;   padding:  13px 0 15px 11px;;\"><a class=\"back_button\" href=\"javascript:onclick=scBack()\"><img align=\"absmiddle\" src=\"\/dotcom\/oxford\/images\/backtoresults.gif\"><\/a><\/div>  ";
description_header += "        <div style=\"float: right;  padding:  18px 0 21px ;\"> <a onclick=\"return addthis_sendto()\" onmouseout=\"addthis_close()\" onmouseover=\"return addthis_open(this, '', window.location.href, '"+book_object.name+"')\" href=\"http://www.addthis.com/bookmark.php\"><img border=\"0\" width=\"125\" height=\"16\" alt=\"Valentines Day 2009\" src=\"http://s9.addthis.com/button1-share.gif\" /></a><\/div>  ";

description_header += "       <\/div>";
return description_header;
}

function create_search_header(){
	/*var search_header="";
	search_header += "<div class=\"task_header\">";
	search_header += "    	<div class=\"task_desciption_area\">";
	search_header += "           ";
	search_header += "            <div class=\"new_customer\" style=\"display:none\">Showing <strong>1<\/strong> of <strong>1<\/strong> for<strong>\"Books\"<\/strong><\/div>";
	search_header += "	    <\/div>";
	search_header += "    <\/div>";
	return(search_header);*/
}

function setMetatags(booktitle,description)
{

var metatags = document.getElementsByTagName("meta");

for (var cnt = 0; cnt < metatags.length; cnt++)
    {
        var name = metatags[cnt].getAttribute("name");
        var content = metatags[cnt].getAttribute("content");

       // Update the Title meta tag
        if (metatags[cnt].getAttribute("name") == "Keywords")
              metatags[cnt].setAttribute("content", booktitle);
		else if (metatags[cnt].getAttribute("name") == "description")
              metatags[cnt].setAttribute("content", description);
    }


}
