//Copyright ChessWorld 2001-2006 All rights reserved


function myDrawFunction_SetColorRed(x)
{
	jg.setColor("#ff0000");
}

function myDrawFunction_SetColorGreen(x)
{
	jg.setColor("#00FF00");
}

function myDrawFunction_SetColorBlue(x)
{
	jg.setColor("#0000FF");
}

function myDrawFunction_SetColorYellow(x)
{
	jg.setColor("#FFFF00");
}

function myDrawFunction_SetColorCyan(x)
{
	jg.setColor("#00FFFF");
}

function myDrawFunction_SetColorMagenta(x)
{
	jg.setColor("#FF00FF");
}

function myDrawFunction_SetColorGrey(x)
{
	jg.setColor("#C0C0C0");
}

function myDrawFunction_SetColorWhite(x)
{
	jg.setColor("#FFFFFF");
}



function myDrawFunction_FillSquare(x,y)
          {
						
      			if (x<1 || x>8) 
      			{
      				 x=1;
      			}
      						
      			if (y<1 || y>8) 
      			{
      				 y=1;
      			}
      
      			x=(x*32)-29;
      			y=259-(y*32);
      				
                 jg.setStroke(2); 
         //      jg.setColor("#ff0000"); // red
                 jg.fillRect(x, y, 32, 32); 
                 jg.paint();
			 }



function myDrawFunction_Square(x,y)
          {
					
      					if (x<1 || x>8) 
      					{
      						 x=1;
      					}
      					
      					if (y<1 || y>8) 
      					{
      						 y=1;
      					}
      
      					
      				    								
      				x=(x*32)-30 +10;
      				y=258-(y*32) +10;
      				
                     jg.setStroke(2); 
                   //  jg.setColor("#ff0000"); // red
                     jg.drawRect(x, y, 32, 32); 
                     jg.paint();
					 }


function myDrawFunction_Circle(x,y)
          {
					
      					if (x<1 || x>8) 
      					{
      						 x=1;
      					}
      					
      					if (y<1 || y>8) 
      					{
      						 y=1;
      					}
      
      					
      				//-32
      				//256	
      				
      				//need +10 and -10 for the boards boarder offset
      								
      				x=(x*32)-30 +10;
      				y=258-(y*32) +10;
      				
                     jg.setStroke(2); 
                  //   jg.setColor("#ff0000"); // red
                     jg.drawEllipse(x, y, 32, 32); 
                     jg.paint();
					 }


          function myDrawFunction_Line(x1,y1,x2,y2)
          {
					 				 var x3,y3,x4,y4;
					
					
        					if (x1<1 || x1>8) 
        					{
        						 x1=1;
        					}
        					
        					if (x2<1 || x2>8) 
        					{
        						 x2=1;
        					}
        					
        					if (y1<1 || y1>8) 
        					{
        						 y1=1;
        					}
        
        					if (y2<1 || y2>8) 
        					{
        						 y2=1;
        					}
        										
        								
        				x1=(x1*32)-16; 			x2=(x2*32)-16;
        				y1=256-(y1*32)+16;     y2=256-(y2*32)+16;
        				
               jg.setStroke(2); 
           //    jg.setColor("#ff0000"); // red
               jg.drawLine(x1, y1, x2, y2);
							 
					
			//http://tecfa.unige.ch/vrml/tools/rad-convert.html
			//var theta = 0.7853981633974483; // arrowhead sharpness - radian of 45 degrees
			//	var theta = 0.17453292519943295
			//	var size = 20; // arrowhead length
			//	angle=Math.atan2( y2-y1, x2-x1 )+Math.PI;								
			//	x3=( x2+Math.cos( angle-theta )*size );
		    //	y3=( y2+Math.sin( angle-theta )*size );
  		    //	x4=( x2+Math.cos( angle+theta )*size );
            //  y4=( y2+Math.sin( angle+theta )*size );
		    //	jg.drawLine(x2,y2,x3,y3);
	        //	jg.drawLine(x2,y2,x4,y4);							 
							  
               jg.paint();
			    }
			    
			    
			    function myDrawFunction_Arrow(x1,y1,x2,y2)
				{
							 var x3,y3,x4,y4;
					
					
        					if (x1<1 || x1>8) 
        					{
        						 x1=1;
        					}
        					
        					if (x2<1 || x2>8) 
        					{
        						 x2=1;
        					}
        					
        					if (y1<1 || y1>8) 
        					{
        						 y1=1;
        					}
        
        					if (y2<1 || y2>8) 
        					{
        						 y2=1;
        					}
        										
        				//13 instead of 16 for x axis?				
        				x1=(x1*32)-13; 			x2=(x2*32)-13;
        				y1=256-(y1*32)+16;     y2=256-(y2*32)+16;
        				
               jg.setStroke(2); 
            //   jg.setColor("#ff0000"); // red
               jg.drawLine(x1, y1, x2, y2);
							 
					
				//http://tecfa.unige.ch/vrml/tools/rad-convert.html
				//var theta = 0.7853981633974483; // arrowhead sharpness - radian of 45 degrees
				var theta = 0.17453292519943295
				
				var size = 14; // arrowhead length
							
				angle=Math.atan2( y2-y1, x2-x1 )+Math.PI;								
				x3=( x2+Math.cos( angle-theta )*size );
				y3=( y2+Math.sin( angle-theta )*size );
  				x4=( x2+Math.cos( angle+theta )*size );
            	y4=( y2+Math.sin( angle+theta )*size );

				jg.drawLine(x2,y2,x3,y3);
				jg.drawLine(x2,y2,x4,y4);							 
				
				//final bridge of the arrow
				jg.drawLine(x3,y3,x4,y4);							 

							  
               jg.paint();
			    }
		
