function showhideDiv(div, button, classShow, classHide) {

	var divElem = document.getElementById(div);
	var buttonElem = document.getElementById(button);
	if (divElem.style.display == 'block') {
		divElem.style.display = 'none';
		buttonElem.className = classHide;
	} else {
		divElem.style.display = 'block';
		buttonElem.className = classShow;
	}
}

function renameButton(button, text) {
	var buttonElem = document.getElementById(button);
	if (buttonElem) {
    	if (buttonElem.childNodes[0]) {
        	buttonElem.childNodes[0].nodeValue=text;
      	} else if (buttonElem.value) {
        	buttonElem.value=text;
        } else { //if (button.innerHTML) 
        	buttonElem.innerHTML=text;
      	}
	}
}

function activateChapters(productId) {
	window.location.href="/shop/product/"+productId+"/active";
}

function loadPublishersMore() {
	var div = document.getElementById('publishers');
	loadHtmlIntoDiv("/shop/product/publishersMore", div);
}

function loadPublishersLess() {
	var div = document.getElementById('publishers');
	loadHtmlIntoDiv("/shop/product/publishersLess", div);
}

function loadText(prodId, view, divId) {
	loadText(prodId, view, divId, null);
}

function loadText(prodId, view, divId, textId) {
	if (textId != null) {
		divId = divId + textId;
	}
	
	var div = document.getElementById(divId);
	var divName = div.getAttribute("name");

	url = "/shop/text/"+prodId+"/"+divName+"/"+view;
	if (textId) {
		url += "/";
		url += textId;
	}
	loadHtmlIntoDiv(url, div);
}

function mouseOnAddChapters(url, divName) {
	var form = dijit.byId('product_detailsForm');
	var chaptersSet = [];
	var chaptersNum = 0;
	
	var children = form.getChildren();
	for(i=2; i<children.length; i++) {
		var elementValue = children[i].getValue();
		if(elementValue) {
			chaptersSet[chaptersNum] = elementValue;
			chaptersNum++;
        }
	}
	
	if (chaptersSet.length > 0) {
		var div = document.getElementById(divName);
		loadHtmlIntoDiv(url + chaptersSet, div);
	}
	
	//var posx = 0;
//    var posy = 0;
//    var frame = document.getElementById('productTooltipFrame'); 
//    var tooltip = document.getElementById('productTooltip'); 
//    
//    if (!e) {
//        e = window.event;
//    }
//    if (e.clientX || e.clientY) {
//        posx = e.clientX + document.body.scrollLeft;
//        posy = e.clientY + document.body.scrollTop;
//    }
//	
//	if (chaptersSet.length > 0) {
//		var div = dojo.byId('productTooltip');
//		loadHtmlIntoDiv(url + chaptersSet, div);
//		wait(100);
//	    frame.style.top = posy + 10;
//	    frame.style.left = posx + 15;
//	    frame.style.visibility = 'visible';
//	}
}

function mouseOnAddChaptersToLibrary() {
	mouseOnAddChapters("/shop/product/add_chapters_to_library_price/", "libraryPrice");  
}

function mouseOnAddChaptersToCollection() {  
	mouseOnAddChapters("/shop/product/add_chapters_to_collection_price/", "collectionPrice");
}
