var symbolItem = 1;
var isOn = 1;


function turnOn()
{
   isOn = 1;
}

function previewPress() {
  if (isOn==1) {
		isOn = 0;
		var t=setTimeout("turnOn()",3000);
		document.previewform.submit();
		document.getElementById('imagePreview').style.display="none";
		document.getElementById('barberpole').style.display="inline";
  }
}


function editSymbol(arg1) {
	document.editSymbolForm.submit();
}


function newsymbol() {
	var thm = document.getElementById('editSymbolURL');
	thm.value="";
	document.editSymbolForm.submit();
}

function clearTextRow(colind)
{
	var theTable = document.getElementById('textsizetable');
        var cols = theTable.getElementsByTagName("td");
 	for (var i=0;i<cols.length;i++){
 		if (i == colind) { 
 			cols[i].style.backgroundColor='#FF2222';
 		} else {
			cols[i].style.backgroundColor='#FFFFFF';
		}
 	}

	var theTable2 = document.getElementById('textsizetable2');
        var cols2 = theTable2.getElementsByTagName("td");
 	for (var i2=0;i2<cols2.length;i2++){
 		if (colind == (i2+cols.length)) { 
 			cols2[i2].style.backgroundColor='#FF2222';
 		} else {
			cols2[i2].style.backgroundColor='#FFFFFF';
		}
 	}
}

function chooseBig()
{
	setColorVis('visible');
	clearTextRow(0);
	scheme = document.getElementById('textstyle');
	scheme.value='big';
//	previewPress();
}

function chooseGoth()
{
	setColorVis('visible');
	clearTextRow(4);
	scheme = document.getElementById('textstyle');
	scheme.value='goth';
//	previewPress();
}

function chooseScript()
{
	setColorVis('visible');
	clearTextRow(5);
	scheme = document.getElementById('textstyle');
	scheme.value='script';
//	previewPress();
}

function chooseSmall()
{
	setColorVis('visible');
	clearTextRow(1);
	scheme = document.getElementById('textstyle');
	scheme.value='';
//	previewPress();
}

function setColorVis(vv)
{
//	var mm = document.getElementById('sampletable');
//	mm.style.visibility=vv;
	mm = document.getElementById('fillshapea');
	mm.style.visibility=vv;
	mm = document.getElementById('fillcolorb');
	mm.style.visibility=vv;
}


function chooseDoInvert()
{
       scheme = document.getElementById('inverted');
 	scheme.value='yes';

	var theTable = document.getElementById('inverttable');
        var cols = theTable.getElementsByTagName("td");
	cols[0].style.backgroundColor='#FFFFFF';
	cols[1].style.backgroundColor='#FF2222';
}

function chooseNotInvert()
{
	scheme = document.getElementById('inverted');
	scheme.value='';
	var theTable = document.getElementById('inverttable');
        var cols = theTable.getElementsByTagName("td");
	cols[0].style.backgroundColor='#FF2222';
	cols[1].style.backgroundColor='#FFFFFF';
}


function chooseGrunge()
{
	setColorVis('visible');
	clearTextRow(2);
	scheme = document.getElementById('textstyle');
	scheme.value='grunge';
//	previewPress();
}


function choosePaper()
{
	setColorVis('hidden');
	clearTextRow(3);
	scheme = document.getElementById('textstyle');
	scheme.value='paper';
//	previewPress();
}

function dohidesymbolsimple()
{
var sym = document.getElementById("symbollayersimple");
sym.style.visibility = 'hidden';
}

function pickTheme(ca, cb)
{

   document.getElementById("color1x").value = cb;
//   but = document.getElementById("colorcell");
//   but.style.backgroundColor='#'+cb;
   but = document.getElementById("ColorButton2cell");
   but.style.backgroundColor='#'+cb;

   document.getElementById("color0x").value = ca;
//   but = document.getElementById("thetext");
//   but.style.color='#'+ca;
   but = document.getElementById("ColorButtoncell");
   but.style.backgroundColor='#'+ca;
//	 previewPress();
}

function dosetcolor(sname)
{

if (colorItem==2)
{
   document.getElementById("color1x").value = sname;
//   but = document.getElementById("colorcell");
//   but.style.backgroundColor='#'+sname;
   but = document.getElementById("ColorButton2cell");
   but.style.backgroundColor='#'+sname;
}
else
{
   document.getElementById("color0x").value = sname;
//   but = document.getElementById("thetext");
//   but.style.color='#'+sname;
   but = document.getElementById("ColorButtoncell");
   but.style.backgroundColor='#'+sname;
}
sym = document.getElementById("colorlayer");
sym.style.visibility = 'hidden';
//	previewPress();

}

function doOrderPrint()
{
	document.purform1.target="_blank";
	document.purform1.action="/ic/final_print.jsp";
	document.purform1.submit();
	document.purform1.target="";
	document.purform1.action="/ic/final_widget.jsp";
}

function doaddsymbol(sname, stan, pg) {
	lastStandard = stan;
	lastPage = pg;
	
	document.getElementById("sym-image").src=('http://cdn-i.imagechef.com/symbol/standard/'+sname+'M.gif');
	document.getElementById("editSymbolURL").value=('standard/'+sname);
	document.getElementById("chosenSymbol").value=('standard/'+sname);
	var sym = document.getElementById("cataloglayer");
	
	sym.style.display = 'none';
	var area = document.getElementById('editbuttontable');
	area.className='visoff';
}
function doaddsymbolold(sname)
{
document.getElementById("line1").value+=('<'+sname+'>');
var sym = document.getElementById("symbollayersimple");
sym.style.visibility = 'hidden';
}

function doaddphoto(sname, stan, pg) {
	lastStandardP = stan;
	lastPageP = pg;
	var sym = document.getElementById("photocataloglayer");
	sym.style.display = 'none';
	if (sname != null) {
		lastDot = sname.lastIndexOf('.');
  	if (lastDot!=-1) {
  		snamesmall = sname.substring(0, lastDot) + "S.png";
		  document.getElementById("photo-image").src=('http://www.imagechef.com/ic/'+snamesmall);
  	}
	}
  var e=document.getElementsByName("customimg");
	for(var i=0;i<e.length;i++){e[i].value = sname;}

  previewPress();
}
function doOnLoad(isInitials)
{
document.getElementById("line1").focus();
document.getElementById("line1").select();
if (isInitials)
	initialmode();
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (!obj)
		return [curleft,curtop];

	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function ICToggleCatalog() {
	var catlayer = document.getElementById("cataloglayer");
	if (catlayer.style.display == 'inline')	{	catlayer.style.display='none';	return;	}
	else {
		var butt =  document.getElementById("imagemarker");
		var coors = findPos(butt);
		catlayer.style.left = coors[0] + "px"; //250;
		var ppx = coors[1];
		if (ppx<5) ppx=5;
		catlayer.style.top = ppx + "px";

		catlayer.style.display='inline';
		if (lastStandard==0) parent.FRAME1.location.href='/ic/browsesymbols-frame.jsp?sort=0'; 
		else if (lastStandard==1) parent.FRAME1.location.href='/ic/browsesymbols-frame.jsp?sort=1&page='+lastPage; 
		else if (lastStandard==2)	parent.FRAME1.location.href='/ic/browsesymbols-frame.jsp?sort=2'; 
		else if (lastStandard==3)	parent.FRAME1.location.href='/ic/browsesymbols-frame.jsp?sort=3'; 
		else if (lastStandard==4)	parent.FRAME1.location.href='/ic/browsesymbols-frame.jsp?sort=4'; 
		return;
	}
}

function ICToggleSymbols(item) {
	var syms = document.getElementById("symbollayersimple");

	if  (syms.style.visibility == new String('visible')) {
		syms.style.visibility='hidden';
		return;
	}
	else
		ICShowSymbols(item);
}

function ICTogglePhotoSelect(imgtoprocess, bRecrop) {
	var catlayer = document.getElementById("photoselectlayer");
	if (catlayer.style.display=='inline')	{
			catlayer.style.display='none';
			return;
	}	else {
			var butt =  document.getElementById("imagePreview");
			var coors = findPos(butt);
			var leftcoord = coors[0]-500;
			
			catlayer.style.left = leftcoord + "px"; //250;
			var ppx = coors[1]-390;
			if (ppx<5)
				ppx=5;
			catlayer.style.top = ppx + "px";

			catlayer.style.display='inline';
			if (bRecrop)
				parent.FRAME3.location.href='/ic/photobook/recrop.jsp?imgin=' + imgtoprocess; 
			else
				parent.FRAME3.location.href='/ic/photobook/process.jsp?imgin=' + imgtoprocess; 
			return;
	}
}


function ICShowColors(item) {
	var sym = document.getElementById("colorlayer");

	if (item==1)
		but =  document.getElementById("ColorButton");
	else
		but =  document.getElementById("ColorButton2");
	var coors = findPos(but);
  var coorx = coors[0];
  var coory = coors[1]-118;
	sym.style.left = coorx + "px";
	sym.style.top = coory + "px";

	colorItem = item;
	sym.style.visibility = 'visible';
}

function initialmode()
{
   var initlay = document.getElementById("Layer1");

  var but =  document.getElementById("pickbox");
   var coors = findPos(but);
    initlay.style.left = coors[0] + "px";
    initlay.style.top = coors[1] + "px";

   var tab = document.getElementById("symbol-tab");
   tab.className='ic_tab2';
    tab = document.getElementById("initial-tab");
   tab.className='ic_tab1';

  var initi =  document.getElementById("doinitials");
  initi.value="1";

  initlay.style.visibility='visible';
}

function symbolmode()
{
   var initlay = document.getElementById("Layer1");
  initlay.style.visibility='hidden';
   var tab = document.getElementById("symbol-tab");
   tab.className='ic_tab1';
    tab = document.getElementById("initial-tab");
   tab.className='ic_tab2';
  var initi =  document.getElementById("doinitials");
  initi.value="0";
}

function ICToggleColors(item) {
	var sym = document.getElementById("colorlayer");

	if  (sym.style.visibility == new String('visible'))
		{
			sym.style.visibility='hidden';
			return;
		}
	else
	ICShowColors(item);
}

function ICShowTint() {
	sym = document.getElementById("tintlayer");
	but =  document.getElementById("TintButton");
	var coors = findPos(but);
	sym.style.left = coors[0] + "px";
	var coory = coors[1]+20;
	sym.style.top = coory + "px" ;
	sym.style.visibility = 'visible';
}

function ICToggleTint(item) {
	var sym = document.getElementById("tintlayer");
	if (sym.style.visibility == 'visible') { sym.style.visibility='hidden';	return;	}
	else ICShowTint(item);
}

function doFilter(fil) {
 var filterval = document.getElementById("filter2").value;
 if (filterval.indexOf("blur") != -1) {
 	if (fil == "") fil = "blur"; else	fil += "_blur";
 }
 var e=document.getElementsByName("filter");
 for(var i=0;i<e.length;i++){e[i].value = 'filter_' + fil;}
 document.getElementById("filter2").value = fil;
// document.getElementById("filter3").value = fil;
 document.getElementById("tintlayer").style.visibility='hidden';
 previewPress();
}

function doFilter2(fil) {
 var e=document.getElementsByName("filter");
 for(var i=0;i<e.length;i++){e[i].value = 'filter_' + fil;}
 document.getElementById("filter2").value = fil;
 document.getElementById("tintlayer").style.visibility='hidden';
 previewPress();
}

function ICToggleBlur() {
 	var filterval = document.getElementById("filter2").value;
	if (filterval.indexOf("blur") != -1) { 
		if (filterval.indexOf("black") != -1)
			doFilter2("black");
		else if (filterval.indexOf("brown") != -1)
			doFilter2("brown");
		else if (filterval.indexOf("pink") != -1)
			doFilter2("pink");
		else if (filterval.indexOf("blue") != -1)
			doFilter2("blue");
		else 
			doFilter2("");
	} else { 
		if (filterval.indexOf("black") != -1)
			doFilter2("black_blur");
		else if (filterval.indexOf("brown") != -1)
			doFilter2("brown_blur");
		else if (filterval.indexOf("pink") != -1)
			doFilter2("pink_blur");
		else if (filterval.indexOf("blue") != -1)
			doFilter2("blue_blur");
		else 
			doFilter2("blur");
	}
}

function dohidecolors() {
	var sym = document.getElementById("colorlayer");
	sym.style.visibility = 'hidden';
}

function repositionsymbols()
{
	var catlayer = document.getElementById("cataloglayer");
	if (catlayer.style.visibility == 'visible') {
		var butt =  document.getElementById("imagemarker");
		var coors = findPos(butt);
		catlayer.style.left = coors[0] + "px"; //250;
		var ppx = coors[1] + "px";
		if (ppx<5) ppx=5;
		catlayer.style.top = ppx + "px";
	}		

	var sym = document.getElementById("symbollayersimple");
	if (sym.style.visibility == new String('visible')) {
		var but =  document.getElementById("SymButton2");
		var coors = findPos(but);	
		sym.style.left = coors[0] + "px";
		var coory = coors[1]-134;
		sym.style.top = coory + "px";
	}


	var sym = document.getElementById("colorlayer");
	if (sym.style.visibility == new String('visible')) {
	var but;
	if (colorItem==2)
		but =  document.getElementById("ColorButton2");
	else
		but =  document.getElementById("ColorButton");
		var coors = findPos(but);
		sym.style.left = coors[0] + "px";
		var coory = coors[1]-118;
		sym.style.top = coory + "px";
	}

	var but =  document.getElementById("pickbox");
	var initlay = document.getElementById("Layer1");
	var coors = findPos(but);
	initlay.style.left = coors[0] + "px";
	initlay.style.top = coors[1] + "px";

	catlayer = document.getElementById("photocataloglayer");
	if (catlayer.style.visibility == 'visible') {
		var butt =  document.getElementById("imagePreview");
		var coors = findPos(butt);
		var coorx = coors[0]-500;
		catlayer.style.left = coorx + "px"; //250;
		var ppx = coors[1]-390;
		if (ppx<5) ppx=5;
		catlayer.style.top = ppx + "px";
	}
	catlayer = document.getElementById("photoselectlayer");
	if (catlayer.style.visibility == 'visible') {
		var butt =  document.getElementById("imagePreview");
		var coors = findPos(butt);
		var coorx = coors[0]-400;
		catlayer.style.left = coorx + "px"; //250;
		var ppx = coors[1]-400;
		if (ppx<5) ppx=5;
		catlayer.style.top = ppx + "px";
	}

}


function ICShowSymbols(item) {
	var sym;
  sym = document.getElementById("symbollayersimple");

  var but;
	but =  document.getElementById("SymButton2");

	var coors = findPos(but);
	coory=coors[1]-134;
  sym.style.left = coors[0] + "px";
  sym.style.top = coory + "px";

	symbolItem = item;
	sym.style.visibility = 'visible';
}

function doPhotoDialog(bShow) {
	if (bShow) {
		document.getElementById("togglephoto").value = "1";
		previewPress();
	} else {
		document.getElementById("togglephoto").value = "0";
		document.getElementById("customimgp").value = "";
		document.getElementById("filter2").value = "";
		doFilter('');
	}
}