/*****************************************************************************
*  
*  Flust - fonts.js
*  For bruk gjennom Flust
*  
*  ***************************************************************************
*  
*  (C) Respons Reklamebyrå 2008-09
*  Kode av Andreas Håkestad
*  
*****************************************************************************/

var mrklappUpdateDelayer;
var UD_id 					= 0;

var generator_mrklapp_count1 = 0;
var generator_mrklapp_count2 = 0;
var generator_mrklapp_count3 = 0;


function emptyAllFields() {
	docForm.linje1.value = '';
	docForm.linje2.value = '';
	docForm.linje3.value = '';
	
	mrklappRemoveGlyph();
	
	mrklappUpdatePreview();
}

function mrklappUpdatePreview() {
	var form = document.getElementById('form');
	
	//document.form.submit();
	var newURL = 'preview.php?bk=mrklapp_bk&grafikk='+form.grafikk.value+'&rand='+(Math.random()*10000);
	
//	newURL += '&egendef_id='+document.getElementById("egendef_id").value;
	newURL += '&linje1='+encodeURIComponent(form.linje1.value);
	newURL += '&linje2='+encodeURIComponent(form.linje2.value);
	newURL += '&linje3='+encodeURIComponent(form.linje3.value);
	newURL += '&font='+form.font.value;
	//newURL += '&linje3='+document.getElementById("linje3").value;
	
	//alert(newURL);
	
	document.getElementById("preview").src = newURL;
}

function mrklappUpdatePreviewDelayed() {
	clearTimeout(mrklappUpdateDelayer);
	
	mrklappUpdateDelayer = setTimeout(mrklappUpdatePreview, 500);
}

function mrklappChangeTabView(forstebilde,sistebilde,fane) {
	var egendef = ((forstebilde == 200) || (sistebilde == 200));
	
	document.getElementById('mrklappGlyphsHolder').style.display = egendef ? 'none' : '';
	document.getElementById('mrklappGlyphsUDHolder').style.display = egendef ? '' : 'none';
	
	if(egendef) {
	} else {
		var tabell = "<table width=\"405\" height=\"160\" border=\"0\" cellspacing=\"0\" cellpadding=\"6\"><tr>";
		for(i=forstebilde;i<=sistebilde;i++) {
			tabell += "<td align=\"center\"><img alt=\"Symbol " + i + "\" border=\"0\" src=\"../../gfx/mrklapp/clipart/pre/Nr" + i + ".jpg\" onclick=\"mrklappChooseGlyph(" + i + ");\" style=\"cursor:pointer;\" /></td>";
			if(i == (forstebilde+4)) {
				tabell += "</tr><tr>";
			} else if(i == (forstebilde+9)) {
				tabell += "</tr><tr>";
			}

		}
		tabell += "</tr></table>";
		document.getElementById("mrklappGlyphsHolder").innerHTML = tabell;
	}
	
	if(fane != 0) {
		for(i=1;i<=6;i++) {
			if(fane == document.getElementById("tab" + i)) {
				document.getElementById("tab" + i + 'bk').className = 'mrklappTabNoBk';
				//document.getElementById("tab" + i + 'left').style.visibility = 'visible';
				//document.getElementById("tab" + i + 'right').style.visibility = 'visible';
			} else {
				document.getElementById("tab" + i + 'bk').className = 'mrklappTabBk';
				//document.getElementById("tab" + i + 'left').style.visibility = 'hidden';
				//document.getElementById("tab" + i + 'right').style.visibility = 'hidden';
			}
		}
	}
	//document.getElementById("symboler_ny").innerHTML = tabell;
}

function mrklappChooseGlyph(nr) {
	document.getElementById("form").grafikk.value = nr;
	//document.form.submit();
	mrklappUpdatePreview();
	
	if(nr > 0) {
		document.getElementById("mrklappRemoveGlyph").style.display = 'inline';
		
		if(nr >= 1000)
			UD_id = nr;
	}
}

function mrklappRemoveGlyph() {
	document.getElementById("mrklappRemoveGlyph").style.display = 'none';
	document.getElementById('form').grafikk.value = 0;
	//document.form.submit();
	mrklappUpdatePreview();
}

function mrklappUpdatePrices() {
	var price1 = 0;
	var price2 = 0;
	var price3 = 0;
	
	var count1 = document.getElementById('option1Count');
	var count2 = document.getElementById('option2Count');
	var count3 = document.getElementById('option3Count');
	
	var totalPrice = document.getElementById('totalPrice');
	
	var option1CountTotalPrice = document.getElementById('option1CountTotalPrice');
	var option2CountTotalPrice = document.getElementById('option2CountTotalPrice');
	var option3CountTotalPrice = document.getElementById('option3CountTotalPrice');
	
	//first choice
	error = 0;
	if(isNaN(count1.value))
		error = 1;
	
	if(error == 0) {
		price1 = (productPrice1 * Number(count1.value));
		option1CountTotalPrice.innerHTML = 'kr. ' + price1 + ',00';
	} else 
		option1CountTotalPrice.innerHTML = 'Feil';
				
	
	//second choice
	if(isNaN(count2.value))
		error = 2;
	
	if(error != 2) {
		price2 = (productPrice2 * Number(count2.value));
		option2CountTotalPrice.innerHTML = 'kr. ' + price2 + ',00';
	} else 
		option2CountTotalPrice.innerHTML = 'Feil';
				
	//third choice
	if(isNaN(count3.value))
		error = 3;
	
	if(error != 3) {
		price3 = (productPrice3 * Number(count3.value));
		option3CountTotalPrice.innerHTML = 'kr. ' + price3 + ',00';
	} else 
		option3CountTotalPrice.innerHTML = 'Feil';
	
	generator_mrklapp_totalPrice = price1 + price2 + price3;
	
	if(error > 0)
		totalPrice.innerHTML = 'Feil';
	else
		totalPrice.innerHTML = 'kr. ' + generator_mrklapp_totalPrice + ',00';
	
	generator_mrklapp_count1 = count1.value;
	generator_mrklapp_count2 = count2.value;
	generator_mrklapp_count3 = count3.value;
	/*
	generator_mrklapp_price1 = price1;
	generator_mrklapp_price2 = price2;
	generator_mrklapp_price3 = price3;
	*/
	
}
