/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005
************************************************************************************************************/

var ct_slideSpeed = 10;	// Higher value = faster
var ct_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var ct_activeId = false;
var ct_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(ct_slideInProgress)return;
	ct_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('ct_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(ct_activeId &&  ct_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(ct_activeId,(ct_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,ct_slideSpeed);
		}
	}else{
		slideContent(numericId,(ct_slideSpeed*-1));
		ct_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('ct_a' + inputId);
	var contentObj = document.getElementById('ct_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',ct_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('ct_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('ct_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,ct_slideSpeed);				
			}else{
				ct_slideInProgress = false;
			}
		}else{
			ct_activeId = inputId;
			ct_slideInProgress = false;
		}
	}
}


function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='ct_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'ct_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'ct_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='ct_answer_content';
			contentDiv.id = 'ct_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}
window.onload = initShowHideDivs;

function OnChange(dropdown)
{
    var myindex  = dropdown.selectedIndex;
	var SelValue = parseInt(dropdown.options[myindex].value);
	var openWindow = true;
    var baseURL  = '';
	switch(SelValue){
	case 0:
		openWindow = false;
		break;
	case 1:
		baseURL  = 'bengali.html';
		break;
	case 2:
		baseURL  = 'hindi.html';
		break;
	case 3:
		baseURL  = 'marathi.html';
		break;
	case 4:
		baseURL  = 'german.html';
		break;
	case 5:
		baseURL  = 'spanish.html';
		break;
	}
	if(openWindow){
		openNew(baseURL);
		//window.open(baseURL,'mywindow','width=540,height=720,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); 
	}
    return true;
}

function openNew(baseURL){
		if(baseURL != 'english') {
			window.open(baseURL,'mywindow','width=540,height=720,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); 
			return;
		}
}

var bwpages, colpages, totalpages, colorcost, dispString;

function calcTotalPages() {

	var total, bwpages, colpages;
	
	totalpages = parseInt(document.calc.totalpgs.value);
	bwpages = parseInt(document.calc.nobwpgs.value);
	
	if(bwpages > totalpages) {
		alert("please check the number of pages entered");
	
	} else {
		total = totalpages - bwpages;
		document.calc.colpgs.value = total;
		document.calc.nocolpgs.value = total;
	}
	
	totalpages = 0.0;
	bwpages = 0.0;
}

var upperCost = 0;
var lowerCost = 0;

function calcTotal(){

	var dimes= new Array()
	
	//for each size, enter the cost for b/w pages...
	dimes["4x7"]="0.50";
	dimes["5x8"]="0.60";
	dimes["A5"]="0.65";
	dimes["6x9"]="0.65";
	dimes["8511"]="0.95";
	
	//..for coloured pages...
	dimes["4x7C"]="6.00";
	dimes["5x8C"]="6.50";
	dimes["A5C"]="7.50";
	dimes["6x9C"]="7.50";
	dimes["8511C"]="12.00";
	
	//..for spiral binding
	dimes["4x7S"]="50.00";
	dimes["5x8S"]="50.00";
	dimes["A5S"]="50.00";
	dimes["6x9S"]="50.00";
	dimes["8511S"]="50.00";
	
	//..for the soft cover...
	dimes["4x7P"]="60.00";
	dimes["5x8P"]="60.00";
	dimes["A5P"]="60.00";
	dimes["6x9P"]="60.00";
	dimes["8511P"]="60.00";
	
	//...and for the hard cover+case binding
	dimes["4x7H"]="150.00";
	dimes["5x8H"]="150.00";
	dimes["A5H"]="150.00";
	dimes["6x9H"]="150.00";
	dimes["8511H"]="150.00";

	//...and for the hard cover+dust jacket
	dimes["4x7J"]="200.00";
	dimes["5x8J"]="200.00";
	dimes["A5J"]="200.00";
	dimes["6x9J"]="200.00";
	dimes["8511J"]="200.00";

	//...paper thickness surcharge
	dimes["70M"]="1.00";
	dimes["130M"]="1.05";
	dimes["130A"]="1.10";

	var bookCost=0.00;
	
	var dimeofbook = document.calc.booksize.options[document.calc.booksize.selectedIndex].value;

	var pageCost = parseFloat(dimes[dimeofbook]);
	var pageColorCost = parseFloat(dimes[dimeofbook+"C"]);

	var bindingCost;

	var bindofbook = document.calc.bookbind.options[document.calc.bookbind.selectedIndex].value;
	bindingCost = parseFloat(dimes[dimeofbook+bindofbook]);
	
	var paper = document.calc.papertype.options[document.calc.papertype.selectedIndex].value;
	//paper thickness surcharge calculated here
	pageCost = pageCost*dimes[paper];
	
	if (document.calc.totalpgs.value=="" || document.calc.totalpgs.value=="0") {
		alert("please type in the total number of pages");
		return;	
	} else {
		totalpages = parseInt(document.calc.totalpgs.value);
	}

	if ((document.calc.nobwpgs.value=="" || document.calc.nobwpgs.value=="0") 
		&& (document.calc.nocolpgs.value=="" || document.calc.nocolpgs.value=="0")) {
		alert("please type in the number of b/w or color pages");
		return;	
	} else {
		bwpages = parseInt(document.calc.nobwpgs.value);
		colpages = parseInt(document.calc.nocolpgs.value);
	}
	
	if(totalpages==colpages) {
		lowerCost = parseFloat(pageColorCost*colpages);
		upperCost = lowerCost;
	} else {
		lowerCost = parseFloat(pageColorCost*colpages);
		upperCost = parseFloat(pageColorCost*colpages*2);
	}
	
	if (lowerCost==upperCost) {
		bookCost = parseFloat(pageCost*bwpages + lowerCost + bindingCost);
		dispString = "Each copy of your book will cost Rs. "+bookCost.toFixed(2);
	} else {
		lowerCost = parseFloat(pageCost*bwpages + lowerCost + bindingCost);
		upperCost = parseFloat(pageCost*bwpages + upperCost + bindingCost);
		dispString = "Each copy of your book will cost between Rs. "+lowerCost.toFixed(2)+" and Rs. "+upperCost.toFixed(2)+", depending on where the coloured pages are placed in the book.";
	}
		dispString += "<br/>This is only an approximation of the costs. Do <a href=\"contact.html\">contact us</a> for an accurate estimate and for enquiries regarding volume discounts.";
	
	var displayString="";
	displayString+="<table class=\"sample\">";
	displayString+="<th><td>";
	displayString+=dispString;
	displayString+="</td></th>";
	displayString+="</table>";
	
	document.getElementById("estimateInfo").innerHTML =displayString;
	
}

