var width = 640;
var height = 480;
var zakaz_window;

create_zakaz = function(url)
{
	var xtop = (screen.height - height) / 2;
	var xleft = (screen.width - width) / 2;
	if (typeof(zakaz_window) == "undefined" || zakaz_window.closed == true)
	{
		zakaz_window = window.open(url, "details","height=" + height + ", width=" + width + ", top=" + xtop + ", left=" + xleft + ",scrollbars=yes, resizable=no");
		zakaz_window.focus();
	}
	else
	{
		zakaz_window.focus();
	}
}

chCurrent = function(nS, nI)
{
	el = document.getElementsByName("s"+nS+"[]");
	el[nI].value = 1 - el[nI].value;
	
	eln = document.getElementById("ch"+nS+nI);
	
	if(nI == 0) if(el[nI].value == 0) eln.src = 'img/b.gif'; else eln.src = 'img/bd.gif';
	if(nI == 1) if(el[nI].value == 0) eln.src = 'img/it.gif'; else eln.src = 'img/itd.gif';

	create_img();
}

selCurrent = function(nS, nI)
{
	el = document.getElementsByName("f"+nS+"[]");
	for(var i = 0; i < el.length; i++) el[i].value = 0;
	el[nI].value = 1;
	
	eln1 = document.getElementById("fch"+nS+"0");
	eln2 = document.getElementById("fch"+nS+"1");
	eln3 = document.getElementById("fch"+nS+"2");

	if(nI == 0) eln1.src = 'img/asd.gif'; else eln1.src = "img/as.gif";
	if(nI == 1) eln2.src = 'img/amd.gif'; else eln2.src = "img/am.gif";
	if(nI == 2) eln3.src = 'img/abd.gif'; else eln3.src = "img/ab.gif";
	create_img();
}

create_pdf = function()
{
	var param = $('setting').serialize();
	window.open('create_pdf.php?'+param);
}

create_img = function()
{
	for(var i = 1; i < 10; i++)
	{
		bl = ''; br = '';
		il = ''; ir = '';
		ul = ''; ur = '';
		f = 12;
		text = $("t"+i).value;
		
		el = document.getElementsByName("s"+i+"[]");
		if(el[0].value == 1) {bl = '<b>'; br = '</b>';}
		if(el[1].value == 1) {il = '<i>'; ir = '</i>';}
		//if(el[2].value == 1) {ul = '<u>'; ur = '</u>';}

		el = document.getElementsByName("f"+i+"[]");
		if(el[0].value == 1) {f = 'fSmall';}
		if(el[1].value == 1) {f = 'fMedium';}
		if(el[2].value == 1) {f = 'fLarge';}
		
		$('r'+i).innerHTML = "<label class="+f+">"+bl+il+ul+text+ur+ir+br+"</label>";
	}
}

setCard = function(id)
{
	$('pic').src = "template/c"+id+".jpg";
	$('selCard').value = id;
	selCard = id;
}

convertHexToRGB = function(col)
{
	if (col.indexOf('#') != -1) 
	{
		col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');

		r = parseInt(col.substring(0, 2), 16);
		g = parseInt(col.substring(2, 4), 16);
		b = parseInt(col.substring(4, 6), 16);

		return {r : r, g : g, b : b};
	}

	return null;
}

pickColor = function(color) 
{
	c = convertHexToRGB(color);
	$('p'+colId).style.color = color;
	$('r'+colId).style.color = color;
	$('sc'+colId).value = c.r+","+c.g+","+c.b;
}

hideP = function(obj)
{
	obj.hidePopup();
}

var colId;
var cp = new ColorPicker();
cp.writeDiv();