	var stopper=false;
	
	var mouse1="out";
	var click1="no";
	var mouse2="out";
	var click2="no";
	var sc;
	var timer;
	var ghex1="";
	var ghex2="";
	var gr2=gg2=gb2=gr1=gg1=gb1=0;
	
	function setghex()
	{
		ghex2=document.myform.hexfval.value;
		gr2=document.myform.rfgval.value;
		gg2=document.myform.gfgval.value;
		gb2=document.myform.bfgval.value;
		
		ghex1=document.myform.hexbval.value;
		gr1=document.myform.rbgval.value;
		gg1=document.myform.gbgval.value;
		gb1=document.myform.bbgval.value;
	}

	function setreverse()
	{
		document.myform.hexfval.value = ghex2;
		document.myform.rfgval.value = gr2;
		document.myform.gfgval.value = gg2;
		document.myform.bfgval.value = gb2;
		document.myform.fgdisp.style.backgroundColor = "#"+document.myform.hexfval.value;
		
		document.myform.hexbval.value = ghex1;
		document.myform.rbgval.value = gr1;
		document.myform.gbgval.value = gg1;
		document.myform.bbgval.value = gb1;
		document.myform.bgdisp.style.backgroundColor = "#"+document.myform.hexbval.value;
		
	//	alert('hai');
		return false;
	}
		
	function hexenter(nm,hxv)
	{
		var n=nm;
		var tmp=hxv;
		var subrfg=tmp.substr(0,2);
		var subgfg=tmp.substr(2,2);
		var subbfg=tmp.substr(4,2);
		document.myform.fgdisp.style.backgroundColor="#"+subrfg+subgfg+subbfg;
		hexToDec(subrfg, subgfg, subbfg, n);
	}
	
	function viewfon(val)
	{
		 var ypos = parseInt(val)*-20;
		 document.myform.fd.style.backgroundPosition="0 "+ypos;
	}
	
	function viewcol(nam)
	{
		var n=nam;
		var selected=document.myform.fgcolname.value;
		var sel=selected.split("*");
		var sel=sel[1];
		
		document.myform.hexfval.value=sel;
		document.myform.fgdisp.style.backgroundColor="#"+sel;
		var subrfg=sel.substr(0,2);
		var subgfg=sel.substr(2,2);
		var subbfg=sel.substr(4,2);
		hexToDec(subrfg, subgfg, subbfg, n);
	}
 
	function sevent()
	{
		if(timer)
		    clearTimeout(timer);
		document.myform.submit();
	}
	
	function fshow(val)
	{
		 var ypos = parseInt(val)*-20;
		 document.myform.fd.style.backgroundPosition="0 "+ypos;
		 document.myform.yp.value=ypos;
	//	 document.myform.submit();
	}
	
	function numcheck(n)
	{
		if(n=='crdx')
		{
			var val=document.myform.crdx.value;
			var valstr=val.toString();
			for(i=0; i<=valstr.length-1; i++)
			{
				var asci=valstr.charCodeAt(i);
				if (asci < 48 || asci > 57)
				{
					alert("Please enter a number");
					document.myform.crdx.value=10;
					break;
				}
			}
		}
		if(n=='crdy')
		{
			var val=document.myform.crdy.value;
			var valstr=val.toString();
			for(i=0; i<=valstr.length-1; i++)
			{
				var asci=valstr.charCodeAt(i);
				if (asci < 48 || asci > 57)
				{
					alert("Please enter a number");
					document.myform.crdy.value=20;
					break;
				}
			}
		}
		if(n=='fontsize')
		{
			var val=document.myform.fontsize.value;
			var valstr=val.toString();
			for(i=0; i<=valstr.length-1; i++)
			{
				var asci=valstr.charCodeAt(i);
				if (asci < 48 || asci > 57)
				{
					alert("Please enter a number");
					document.myform.fontsize.value=15;
					break;
				}
			}
		}
	}

	function textcheck(v)
	{
		var name=v;
		
		if(name=="hexfval")
		{
			var val=document.myform.hexfval.value;
			var valstr=val.toString();
			for(i=0; i<=valstr.length-1; i++)
			{
				var asci=valstr.charCodeAt(i);
				if((asci<48)||(asci>57 && asci<65)||(asci>70 && asci<97)||(asci>102))
				{
					alert("Please enter SIX digit HEX value of characters 0-9 | A-F | a-f.");
					document.myform.hexfval.value='00FF00';
					break;
				}
				else
					hexenter('hexfval', valstr);
			}
		}
		
	}

	function stop()
	{
		stopper=true;
	}

	function runner(x,val)
	{
		var name=x;	
		stopper = false;
		changer(name,val);
	}
	
	function resetcol()
	{
		var r=deciToHex(document.myform.rbgval.value);
		var g=deciToHex(document.myform.gbgval.value);
		var b=deciToHex(document.myform.bbgval.value);
		document.myform.hexbval.value=r+g+b;
		document.myform.bgdisp.style.backgroundColor="#"+r+g+b;
		
		r=deciToHex(document.myform.rfgval.value);
		g=deciToHex(document.myform.gfgval.value);
		b=deciToHex(document.myform.bfgval.value);
		document.myform.hexfval.value=r+g+b;
		document.myform.fgdisp.style.backgroundColor="#"+r+g+b;

	}

	function changer(y,val)
	{
		var name=y;
		var v;
		
		if(name!="")
		{
			var field = eval("document.myform."+y);
			var curr = field.value;
			var intval=parseInt(curr);
			v='fg';
			
			if(val == "-1" && intval>0)
				intval-=1;

			else if(val == "1" && intval<255)
				intval+=1;

			else if(val == "64" && intval<255)
			{
				intval+=64;
				if(intval==256)
					intval=255;				
				v='bg';
			}
			
			else if(val == "-64" && intval>=64)
			{
				if(intval==255)
					intval=256;
				intval-=64;
				v='bg';
			}

			field.value=intval;
		}

		resetcol();
		
		if(stopper==false && v=='fg')
			setTimeout("changer('"+name+"','"+val+"')",1);
		
		if(stopper==false && v=='bg')
			setTimeout("changer('"+name+"','"+val+"')",400);
	}
		
	function hexdisplay(n)
	{
		var name=n;
			
		if(name=="fgcolname")
		{
			var selected=document.myform.fgcolname.value;
			var sel=selected.split("*");
			var sel=sel[1];
			if(sel=="0")
				alert("Your choice is invalid. Please choose a valid color");
			else
			{
				document.myform.hexfval.value=sel;
				var subrfg=sel.substr(0,2);
				var subgfg=sel.substr(2,2);
				var subbfg=sel.substr(4,2);
				
				var decr=parseInt(subrfg,16);
				var decg=parseInt(subgfg,16);
				var decb=parseInt(subbfg,16);
				
				document.myform.fgdisp.style.backgroundColor="#"+subrfg+subgfg+subbfg;
				hexToDec(subrfg, subgfg, subbfg, name);
			}
		//	document.myform.submit();
		}
	}
	
	function getHexNum(num)
	{
		ar1 = new Array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15');
		ar2 = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
		if(num > 15)
			return num;
		else
		{
			red = ar2[num];
			return red;
		}
	}

	function deciToHex(arg)
	{
		res2 = 999;
		args = arg;
		while(args>15)
		{
			arg1=parseInt(args/16);
			arg2=args%16;
			arg2=getHexNum(arg2);
			args=arg1;
			if(res2 == 999)
				res2=arg2.toString();
			else
				res2=arg2.toString()+res2.toString();
		}

		if(args<16 && res2 != 999)
		{
			def = getHexNum(args);
			res2=def+res2.toString();
		}
		else if(res2 == 999)
		{
			if(args < 16)
				res2= getHexNum(args);
			else
				res2= 1;
		}

		if(res2.length == 1)
			res2 = "0"+res2;

			return res2;
	}
		
	function hexToDec(r,g,b,n)
	{
		var decr=parseInt(r,16);
		var decg=parseInt(g,16);
		var decb=parseInt(b,16);
		
		if(isNaN(decr)) decr=0;
		if(isNaN(decg)) decg=0;
		if(isNaN(decb)) decb=0;

		if(n=='fgcolname' || n=='hexfval')
		{				
			document.myform.rfgval.value=decr;
			document.myform.gfgval.value=decg;
			document.myform.bfgval.value=decb;
		}
	}

/* ------------ Below Functions relate to Color Table ------------ */

	function findPosX(obj)
	{
		var curleft=0;
		if(obj.offsetParent)
		{
			while(obj.offsetParent)
			{
				curleft+=obj.offsetLeft
				obj=obj.offsetParent;
			}
		}
		else if(obj.x)
			curleft+=obj.x;
		return curleft;
	}

	function findPosY(obj)
	{
		var curtop=0;
		if(obj.offsetParent)
		{
			while(obj.offsetParent)
			{
				curtop+=obj.offsetTop
				obj=obj.offsetParent;
			}
		}
		else if(obj.y)
			curtop+=obj.y;
		return curtop;
	}
		
	function showtab(e,n)
	{	
		setghex();
		
		sc=n;
		var tabid = document.getElementById('tb');
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			
		if(document.all)e = event;
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;

		if(sc=='show1')
		{
			var sc1id = document.getElementById('show1');
			var posx = findPosX(sc1id);
			var posy = findPosY(sc1id);
			
			tabid.style.left=posx-70;
			tabid.style.top=posy+30;
			tabid.style.display = "block";
		}

		if(sc=='show2')
		{
			var sc2id = document.getElementById('img1');
			var posx = findPosX(sc2id);
			var posy = findPosY(sc2id);
			
			document.myform.fgcolname.selectedIndex=0;
			tabid.style.left=posx-70;
			tabid.style.top=posy+30;
			tabid.style.display = "block";
		}

		if(timer)
		    clearTimeout(timer);
	}

	function showval(rr,gg,bb)
	{
		if(sc=='show1')
		{
			mouse1="in";
			click1="no";
			var hexid = document.getElementById('hx1');
			var hval=""+deciToHex(rr)+deciToHex(gg)+deciToHex(bb);
			hexid.value=hval;
			var dispid = document.getElementById('cv1');
			dispid.style.backgroundColor="#"+hval;
			document.myform.rbgval.value=rr;
			document.myform.gbgval.value=gg;
			document.myform.bbgval.value=bb;
		}
			
		if(sc=='show2')
		{
			mouse2="in";
			click2="no";
			var hexid = document.getElementById('hx2');
			var hval=""+deciToHex(rr)+deciToHex(gg)+deciToHex(bb);
			hexid.value=hval;
			var dispid = document.getElementById('cv2');
			dispid.style.backgroundColor="#"+hval;
			document.myform.rfgval.value=rr;
			document.myform.gfgval.value=gg;
			document.myform.bfgval.value=bb;
		}
	}
		
	function clicked(rr,gg,bb)
	{
		setghex();
		
		if(sc=='show1')
		{
			mouse1="in";
			click1="yes";
		}

		if(sc=='show2')
		{
			mouse2="in";
			click2="yes";
		}

		var tabid = document.getElementById('tb');
		tabid.style.display = "none";
	//	sevent();
	}
		
	function deltaba()
	{
		if(sc=='show1')
			mouse1="out";
		if(sc=='show2')
			mouse2="out";
		if(timer)
		    clearTimeout(timer);
		timer = setTimeout('blotab()',500);
	}
		
	function blotab()
	{
		if(mouse1 == "out" && mouse2 == "out")
		{
			var tabid = document.getElementById('tb');
			tabid.style.display = "none";
			setreverse();
		}	
	}
	

