/*
    Show a color picker
*/
function pickClr(pObj, pVar, pEvent)
{
	currentclr = pVar;
	var cpObj = document.getElementById('cpicker');
	var mpos;
	if (pEvent)
		mpos = window.mousePos(pEvent);
	else
		mpos = window.mousePos();

	cpObj.style.left = mpos.x + 'px';
	cpObj.style.top = mpos.y + 'px';
	cpObj.style.display = 'block';
}
/*
	Initializer
*/
function initPage()
{
	initColorPicker('cpkbox', 'selectClr');
	updateCode();
}
/*
    Get the mouse coordinates in a window
*/
window.mousePos = function(e) {
     var posx = 0;
     var posy = 0;
     if (!e) var e = window.event;
     
     if (e.pageX || e.pageY)
     {
          posx = e.pageX;
          posy = e.pageY;
     }
     else if (document.documentElement)
     {
          posx = e.clientX + document.body.scrollLeft
                           + document.documentElement.scrollLeft;
          posy = e.clientY + document.body.scrollTop
                           + document.documentElement.scrollTop;
     }
     
     return {x:posx,y:posy}
}
/*
	Selects the color
*/
function selectClr(pClr)
{
	window[currentclr] = pClr;
	var cpObj = document.getElementById('cpicker');
	cpObj.style.display = 'none';
	var clrObj = document.getElementById(currentclr);
	clrObj.style.background = '#' + pClr;
	updateCode();
}

/*
	Updates banner code
*/
function updateCode()
{
	var qline = '';
	var qObj = document.getElementById('quotes');
	
	for (var i = 0; i < qObj.length; i++)
		if (qObj.options[i].selected)
			qline += '1';
		else
			qline += '0';
			
	var params = '?bg=' + bgclr + '&bgodd=' + oddbgclr + '&bgeven='  + evenbgclr + '&bghdr=' + hdrbgclr + '&fgodd=' + oddfgclr +
	             '&fgeven=' + evenfgclr + '&fghdr=' + hdrfgclr + '&q=' + qline + '&csp=' + cellspc + '&bgttl=' + ttlbgclr + '&ref=' +
				 encodeURIComponent(refurl) + '&refresh=' + refr + '&fsize=' + fontsize + '&font=' + encodeURIComponent(fontface) +
				 '&qstr=' + encodeURIComponent(quotestr) + '&bidstr=' + encodeURIComponent(bidstr) +
				 '&askstr=' + encodeURIComponent(askstr) + '&arrows=' + arrstyle;
				
    
	var tareaObj = document.getElementById('aresult');
	var fullsrc = '<iframe src="' + frameurl + params + '" width="' + twidth + '" height="' + theight + '"';
	tareaObj.value = fullsrc + ' frameborder="0" scrolling="no"></iframe>';
	
	var ifrObj = document.getElementById('previewdiv');
	ifrObj.innerHTML = 	fullsrc + ' style="border: 1px dashed #408080" scrolling="no" frameborder="0"></iframe>';
}

/*
	Updates information from text fields
*/
function updateTexts()
{
	var val;
	
	// frame width
	val = getVal('bwidth');
	
	if (isInt(val))
		twidth = parseInt(val);
	
	// frame height
	val = getVal('bheight');
	
	if (isInt(val))
		theight = parseInt(val);
	
	// cell spacing
	val = getVal('bcsp');
	
	if (isInt(val))
		cellspc = parseInt(val);
	
	// refresh interval
	val = getVal('refrint');
	
	if (isInt(val))
		refr = parseInt(val);
	
	// font size
	val = getVal('fsize');
	
	if (isInt(val))
		fontsize = parseInt(val);
	
	// referral url
	refurl = getVal('refurl');
	
	// font face
	fontface = getVal('fface');
	
	// quotes string
	quotestr = getVal('strquote');
	
	// bid string
	bidstr = getVal('strbid');
	
	// ask string
	askstr = getVal('strask');
	
	updateCode();
}

/*
	Sets the arrow style
*/
function arrSetStyle(pStyle)
{
	arrstyle = pStyle;
	updateCode();
}