var currentField;

function chFont(v,t,u){
	if (!currentField) return;
	fm = currentField.form;
	fm.elements[currentField.name+"font"].value = v;
	currentField.style.fontFamily = t;
	currentField.focus();
	if (u==null)getPreview(document.forms[0]);
}
function chFontSize(v,t,u){
	if (!currentField) return;
	fm = currentField.form;
	fm.elements[currentField.name+"fontsize"].value = v;
	currentField.style.fontSize = t;
	currentField.focus();
	if (u==null)getPreview(document.forms[0]);
}
function chFontWeight(v,t,u){
	if (!currentField) return;
	fm = currentField.form;
	fm.elements[currentField.name+"fontweight"].value=(v)?t:"normal";
	currentField.style.fontWeight=(v)?t:"normal";
	currentField.focus();
	if (u==null)getPreview(document.forms[0]);
}
function chFontStyle(v,t,u){
	if (!currentField) return;
	fm = currentField.form;
	fm.elements[currentField.name+"fontstyle"].value=(v)?t:"normal";
	currentField.style.fontStyle=(v)?t:"normal";
	currentField.focus();
	if (u==null)getPreview(document.forms[0]);
}
function chFontColour(v,t){
	if (!currentField) return;
	fm = currentField.form;
	fm.elements[currentField.name+"fontcolour"].value = v;
	currentField.style.color = t;
	currentField.focus();
}
function chAlignment(v,t, u){
	if (!currentField) return;
	fm = currentField.form;
	fm.elements[currentField.name+"textalign"].value = v;
	currentField.style.textAlign = (t=="Centre")?"center":t.toLowerCase();
	if (u==null)window.setTimeout("currentField.focus();", 100);
	if (u==null)getPreview(fm);
}
function chBackColour(v,t){
	for (i=1;i<=14;i++){
		document.forms[0]["line"+i].style.backgroundColor = "#"+t;
		document.forms[0]["line"+i].style.color = "#"+v;
	}
	if (currentField) currentField.focus();
	getPreview(document.forms[0]);
}
function chBlockSize(s){
	l=s%3;
	switch (l){
		case 0:
			document.getElementById("lineblock2").style.display="none";
			document.getElementById("lineblock3").style.display="none";
		break;
		case 1:
			document.getElementById("lineblock2").style.display="block";
			document.getElementById("lineblock3").style.display="none";
		break;
		case 2:
			document.getElementById("lineblock2").style.display="block";
			document.getElementById("lineblock3").style.display="block";
		break;
	}
	updateCost(document.forms[1]);
	getPreview(document.forms[0]);
}
function setFormatTools(f){
	currentField = f;
	fm = currentField.form;
	var set=false;
	/*
	if (f.value == ""){
		fnt = fm.sf_font.options[fm.sf_font.selectedIndex];
		chFont(fnt.value, fnt.text, -1);
		chFontSize(fm.sf_fontsize.options[fm.sf_fontsize.selectedIndex].value, fm.sf_fontsize.options[fm.sf_fontsize.selectedIndex].text, -1);
		chFontWeight((fm.cb_bold.checked), "bold", -1);
		chFontStyle((fm.cb_italic.checked), "italic", -1);
	} else {
	*/
		v = fm.elements[f.name+"font"].value.split(":");
		fm.sf_font.selectedIndex = new Number(v[0]);
		fm.sf_fontsize.selectedIndex = new Number(fm.elements[f.name+"fontsize"].value);
		fm.cb_bold.checked = (fm.elements[f.name+"fontweight"].value=="bold");
		fm.cb_italic.checked = (fm.elements[f.name+"fontstyle"].value=="italic");
		set = true;
	//}
	for (i=0; i<fm.alignment.length;i++){
		if (set == true){
			if (fm.alignment[i].value == fm.elements[f.name+"textalign"].value){
				fm.alignment[i].checked = true;
			}
		} else {
			v=new Array("Left", "Centre", "Right");
			if (fm.alignment[i].checked == true){
				chAlignment(i,v[i],-1);
			}
		}
	}
}
function getPreview(fm){
	cl=fm.blockcolour.value;sz=fm.blocksize.value;cn=(fm.corners[0].checked)?0:1;lines=[];for(i=1;i<=Math.min(14,((sz%3)+1)*5);i++){t=(fm["line"+i].set==true)?fm["line"+i].value:'';f=fm["line"+i+"font"].value.split(":");fsz=fm["line"+i+"fontsize"].value;fwt=fm["line"+i+"fontweight"].value;fst=fm["line"+i+"fontstyle"].value;txa=fm["line"+i+"textalign"].value;l="l"+i+"="+txa+":"+fst+":"+fwt+":"+fsz+":"+f[0]+":"+t;lines.push(l.split("&").join("%26"));}
	cd=lines.join("&");q="cl="+cl+"&sz="+sz+"&cn="+cn+"&"+cd;i=document.images;for(im in i){if(i[im].id=="pdfpreview"){i[im].src="";i[im].src="http://www.adsbringcustomers.com/pdf/preview.php?r="+Math.random()+"&sid="+sid+"&"+q;}}
	return false;
}
