
function SetColour(string) 
{
	document.getElementById("tu_color").value = string;
  	preview();
}

function preview() {
	var oprev = document.getElementById('layTextHolder');
	var textprev = document.getElementById("tu_text").value;
	//textprev = textprev.replace(/\n/g, "<br />");
	oprev.innerHTML = textprev.replace(/ /g, "\u00A0");
	oprev.style.color = "#"+document.getElementById("tu_color").value;
	oprev.style.fontSize = (parseInt(document.getElementById("tu_fsize").value)+1)+"pt";
	if (document.getElementById("cb_bold").checked) {oprev.style.fontWeight='bold';}else{oprev.style.fontWeight='normal';}
	if (document.getElementById("cb_italic").checked) {oprev.style.fontStyle='italic';}else{oprev.style.fontStyle='normal';}
	if (document.getElementById("cb_uline").checked) {oprev.style.textDecoration='underline';}else{oprev.style.textDecoration='none';}
	var elSel=document.getElementById("tu_font");
 	for (i=0;i<elSel.length;i++)
    {
		if (elSel.options[i].value==elSel.value) {oprev.style.fontFamily = elSel.options[i].text; break}
	}
}

function zoom(what, state)
{
	//Image zoom in/out script- by javascriptkit.com
	//Visit JavaScript Kit (http://www.javascriptkit.com) for script
	//Credit must stay intact for use
	//TODO: use orgiginal photo (tu_psrc_w & tu_psrc_h) to determine minsize & maxsize & restore sizes
	zoomfactor=0.025; //Enter factor (0.05=5%)
	prefix=(state=="in")? 1 : -1;	
	minsize=200;
	stfactor=solidsize/tilesize;		//eg 1000/400=2.5
	smfactor=solidsize/minuploadres; 	//eg 1000/800=1.25
	maxsize_w=Math.round(tu_psrc_w/stfactor*smfactor); //max for tile preview
	maxsize_h=Math.round(tu_psrc_h/stfactor*smfactor); //max for tile preview
	if (!document.all&&!document.getElementById) return false;
	whatcache=eval("document.images."+what);
	if (whatcache.style.width=="" || state=="restore")
	{
		//determine default/ reset sizes from original, tu_psrc_w, tu_psrc_h & tilesize are GLOBALS
		if (tu_psrc_w > tu_psrc_h)
		{	// landscape
			whatcache.style.height	=tilesize+"px";
			whatcache.style.width	=parseInt((tu_psrc_w/tu_psrc_h)*tilesize)+"px";
		}
		else if (tu_psrc_w < tu_psrc_h)
		{	//portrait
			whatcache.style.height	=parseInt((tu_psrc_h/tu_psrc_w)*tilesize)+"px";
			whatcache.style.width	=tilesize+"px";	
		}
		else
		{	//square
			whatcache.style.height	=tilesize+"px";
			whatcache.style.width	=tilesize+"px";				
		} 
		if (state=="restore") return true;
	}
	else zoomhelper();
	beginzoom = setInterval("zoomhelper()",100);
}

function zoomhelper()
{
	if (parseInt(whatcache.style.width) < minsize || parseInt(whatcache.style.height) < minsize)
	{
		//if size become lower then minimum then disable zoom in, only zoom out
		if (prefix==1) 
		{
			whatcache.style.width=parseInt(parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix)+"px";
			whatcache.style.height=parseInt(parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix)+"px";	
		}
	}
	else if (parseInt(whatcache.style.width) > maxsize_w || parseInt(whatcache.style.height) > maxsize_h)
	{
		//if size become greater then max then disable zoom out, only zoom in
		if (prefix==-1) 
		{
			whatcache.style.width=parseInt(parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix)+"px";
			whatcache.style.height=parseInt(parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix)+"px";				
		}			
	}
	else
	{
		whatcache.style.width=parseInt(parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix)+"px";
		whatcache.style.height=parseInt(parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix)+"px";		
	}
	//alert(whatcache.style.width+" | "+whatcache.style.height);
}

function resetlayerposition(id){
	document.getElementById(id).style.left="0px"; 
	document.getElementById(id).style.top="0px";
}

function clearzoom()
{
	if (window.beginzoom) clearInterval(beginzoom);
}

/*
function handle(delta) {
	//alert ("handle(delta) activated!");
	if (delta < 0) 	{zoom('image','out'); clearzoom();}
	else 			{zoom('image','in'); clearzoom();}
}

function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		handle(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}
*/

function RenderBorder(image) 
{
	var oDiv=document.getElementById("layBorderHolder");
	if (ie4||ie5||ie6)
	{
		oDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image+"')";
	}
	else
	{
		oDiv.style.background="url("+image+")";
	}
}

function TextEdgeMask(image) 
{
	var oDiv=document.getElementById("layTextEdgeMask");
	if (ie4||ie5||ie6)
	{
		oDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image+"')";
	}
	else
	{
		oDiv.style.background="url("+image+")";
	}
}

function fTextHolder(image) 
{
	var oDiv=document.getElementById("layTextHolder");
	if (ie4||ie5||ie6)
	{
		oDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image+"')";
	}
	else
	{
		oDiv.style.background="url("+image+")";
	}
}
