// Write out title from image to span om proctpages

/*addOnLoad("setImgHover()");


function setImgHover(){ 
	var allImgs = document.getElementsByTagName('img');
	for(i = 0; i < allImgs.length; i++){
		if(allImgs[i].className == "hoverText"){
			allImgs[i].onmouseover = showTitle;
			allImgs[i].onmouseout = removeTitle;
		}	
	}	
}
function showTitle(){
	if(document.getElementById("messageContainer")){
		document.getElementById("messageContainer").innerHTML = this.title;	
	}
}
function removeTitle(){
	if(document.getElementById("messageContainer")){
		document.getElementById("messageContainer").innerHTML = "";
	}
}
*/
// Open Close read more span in prodpages

addOnLoad("addReadMore()");

var readMoreStatus = "open";

function addReadMore(){
	showHide();
	var allAs = document.getElementsByTagName('a');
	for(i = 0; i < allAs.length; i++){
		if(allAs[i].className == "readMore"){
			allAs[i].onclick = showHide;
			break;
		}
	}
}
function showHide(){
	if(readMoreStatus == null){
		openReadMore();
		return false;
	}
	else if(openReadMore != null){
		hideReadMore();
		return false;
	}
}
function hideReadMore(){
	var allSpans = document.getElementsByTagName('span');
	for(i = 0; i < allSpans.length; i++){
	    if(allSpans[i].className == "shorten"){
	        allSpans[i].style.display = "inline";
	    }
		if(allSpans[i].className == "bread"){
			allSpans[i].style.display = "none";	
			readMoreStatus = null;
		}
	}
}
function openReadMore(){
	var allSpans = document.getElementsByTagName('span');
	for(i = 0; i < allSpans.length; i++){
	    if(allSpans[i].className == "shorten"){
	        allSpans[i].style.display = "none";
	    }
		if(allSpans[i].className == "bread"){
			allSpans[i].style.display = "inline";
			readMoreStatus = "open";
		}
	}
}
// Brows Comments.
	var product_comments = new Array(); // The array which contains the comments
	var commentPage = 0; // Current page
	var commentsPerPage = 999; // Number of objects per page

	
	function init_comments() {
	
		// Find the Div that contains the comments
		var allDivs = document.getElementsByTagName('BODY')[0].getElementsByTagName('DIV');
		for( i = 0 ; i < allDivs.length ; ++i ) {
			if( allDivs[i].className == 'comments' ) {
				break;
			}
		}
		
		// Save the comments from HTML into an Array
		var allComments = allDivs[i].getElementsByTagName('DIV');
		for( i = 0 ; i < allComments.length; ++i ) {
			product_comments[i] = allComments[i].innerHTML;
		}
		browseComments(0); // Send 0 to the browse-function will display the current page (start-page)			
	}

function browseComments( direction ) {

		// Calculate which page will be current and check that the current page exists
		commentPage = commentPage + direction;
		if( commentPage <= 0 ) {
			commentPage = 0;
		} else if( commentPage >= ( Math.ceil( product_comments.length / commentsPerPage ) -1 ) ) {
			commentPage = Math.ceil(product_comments.length / commentsPerPage) -1;
		}
		
		// Once again find the Div that contains the comments
		var allDivs = document.getElementsByTagName('BODY')[0].getElementsByTagName('DIV');
		for( i = 0 ; i < allDivs.length ; ++i ) {
			if( allDivs[i].className == 'comments' ) {
				comments_cont = allDivs[i];
				break;
			}
		}
		
		// Empty the comments Div and fill it with the comments associated with the current page
		comments_cont.innerHTML = '';
		var tempArray = new Array();
		for( i = ( commentPage * commentsPerPage ) ; i < ( ( commentPage * commentsPerPage ) + commentsPerPage ) && i < product_comments.length ; ++i ) {
			tempArray[i] = document.createElement('DIV');
			tempArray[i].className = 'comment_container';
			comments_cont.appendChild(tempArray[i]);
			tempArray[i].innerHTML = product_comments[i];
		}
		comments_cont.style.display = 'block'; // Display the comments container
	}

// Show and hide comment layer

addOnLoad("initOpenLayer()");

/* WorkAround: Making explicit call to function to close the comments layer as the now comments layer will  
   always be visible on Page Load. This is to ensure that alignment of login textboxes is correct. Without this
   workaround the three parts of textbox are not aligned together when the page is loaded and any Javascript      call on the page fixes the problem and brings them together. This problem is currently appearing only in
   Internet Explorer, not in Firefox.
*/
addOnLoad("closeComments()");

var commentStatus = null; 

function initOpenLayer(){
	if(document.getElementById("openLayer1Head") && document.getElementById("hideComment")){
		document.getElementById("openLayer1Head").onclick = openCloseComment;
		document.getElementById("hideComment").onclick = openCloseComment;
	}
}
function openCloseComment(){
	if(commentStatus != null){
		closeComments();
	}
	else{
		openComments();
	}
}
function closeComments(){
	if(document.getElementById("openLayer1Body")){
		document.getElementById("openLayer1Body").style.display = "none";
		commentStatus = null;
	}
}
function openComments(){
	if(document.getElementById("openLayer1Body")){
		document.getElementById("openLayer1Body").style.display = "block";		
		commentStatus = "open";
	}
}
// Show and hide Tip a Friend layer

addOnLoad("initOpenLayer2()");

var commentStatus2 = null; 

function initOpenLayer2(){
	if(document.getElementById("openLayer2Head") && document.getElementById("hideTip")){
		document.getElementById("openLayer2Head").onclick = openCloseTip;
		document.getElementById("hideTip").onclick = openCloseTip;
	}
}
function openCloseTip(){
	if(commentStatus2 != null){
		closeTip();
	}
	else{
		openTip();
	}
}
function closeTip(){
	if(document.getElementById("openLayer2Body")){
		document.getElementById("openLayer2Body").style.display = "none";
		commentStatus2 = null;
	}
}
function openTip(){
	if(document.getElementById("openLayer2Body")){
		document.getElementById("openLayer2Body").style.display = "block";
		commentStatus2 = "open";
	}
}


// Show and hide Combination Discount Pushset based on the items count

addOnLoad("initOpenCombinationDiscountPushSets('PushSets')");
var pushsetsContainer;
var pushsetItems;
var combinationDiscountStatus = null; 

function initOpenCombinationDiscountPushSets(PushSets)
{
   // get the container for all pushset items
   pushsetsContainer = document.getElementById(PushSets);   
   if(pushsetsContainer != null)
   {
        var tempArray = pushsetsContainer.getElementsByTagName('div');
        pushsetItems = new Array();
        var pushsetItemIndex = 0;
        var index = 0;
        
        // Get all pushset items and put them in an array
        for(index = 0; index <tempArray.length; index++)
        {
            if(tempArray[index].id == "PushsetItem")
            {
                pushsetItems[pushsetItemIndex] = tempArray[index];
                pushsetItemIndex++;                
            }            
        }
        
        /* If the length of array containing pushset items is more than 3, then hide the remaining pushset
           items and attach onclick handlers to the buttons to open/close this layer of extra pushset items */ 
        if(pushsetItems.length > 3)
        {
	        for(index = 3; index < pushsetItems.length; index++)
	            pushsetItems[index].style.display = 'none';	  
	       
	        var openPushSetLayerButton = document.getElementById("openPushSetLayerButton");
	        if(openPushSetLayerButton)
	            openPushSetLayerButton.onclick = openClosePushSetItemsLayer;
	      
	        var closePushSetLayerButton = document.getElementById("closePushSetLayerButton");
	        if(closePushSetLayerButton)
	            closePushSetLayerButton.onclick = openClosePushSetItemsLayer;
	       
	        var closePushSetLayer = document.getElementById("closePushSetLayer");
            if(closePushSetLayer)
                closePushSetLayer.style.display = 'none';            
        }	   
   }   
}

function openClosePushSetItemsLayer()
{
    if(combinationDiscountStatus == null)
        openPushSetItemsLayer();    
    else
        closePushSetItemsLayer();    
}

// function to open the layer of extra pushset items
function openPushSetItemsLayer()
{
    // display layer containing close button
    var closePushSetLayer = document.getElementById("closePushSetLayer");
    if(closePushSetLayer)
        closePushSetLayer.style.display = 'block';
    
    // hide layer containing open button    
    var openPushSetLayer = document.getElementById("openPushSetLayer");
    if(openPushSetLayer)
        openPushSetLayer.style.display = 'none';
        
    var index;
    // display all pushset items 
    for(index =0; index < pushsetItems.length; index++)
    {
        if(pushsetItems[index].style.display == 'none')
            pushsetItems[index].style.display = 'block';      
    }    
    combinationDiscountStatus = "open";        
}

// function to close the layer of extra pushset items
function closePushSetItemsLayer()
{
    var index;
    if(pushsetItems.length > 3)
    {
        // hide all extra (more than 3) pushset items
        for(index = 3; index < pushsetItems.length; index++)
            pushsetItems[index].style.display = 'none';       
    }
    
    // display layer containing open button
    var openPushSetLayer = document.getElementById("openPushSetLayer");
    if(openPushSetLayer)
        openPushSetLayer.style.display = 'block';
     
    // hide layer contianing close button 
    var closePushSetLayer = document.getElementById("closePushSetLayer");
    if(closePushSetLayer)
        closePushSetLayer.style.display = 'none';
    
    combinationDiscountStatus = null;    
}








