function checkoptions()
{var a=this,p,q,l
if (RegExp){
re=/(label\([']*)([^']+)([']*[\)])/
a=a.replace(re,"label('$2')")
re=/(suffix\([']*)([^']+)([']*[\)])/
a=a.replace(re,"suffix('$2')")}
l=a.length
p=a.indexOf('[')
q=a.lastIndexOf(']')
if (p!=0 && l!=0) {a='['+a}
if  (q!=l-1 && l!=0) {a+=']'}

return a
}

String.prototype.check=checkoptions

function checktekst(tekst)
{var l,p,q
l=tekst.length
p=tekst.indexOf("'",tekst)
q=tekst.lastIndexOf("'",tekst)
if (p!=0||l==0){tekst="'"+tekst}
if (q!=l-1||l==0){tekst=tekst+"'"}
if (RegExp){
re=/["]/g
tekst=tekst.replace(re,'')}
return tekst
}

function convert(name,params)
{var len,res
lino++
len=params.length
res='{'+lino+'} '+name+'('
for(_i=0;_i<len-1;_i++)
{res+=params[_i]
if (_i<len-2)res+=','}
res+=')'+params[len-1].check()+';'+'\n'
construction+=res
return lino
}


function Point(a,b,options)//Draws a movable point at location (a,b)
{return convert('Point',[a,b,options])}

function FixedPoint(a,b,options)//Draws a fixed oint at location (a,b)
{return convert('FixedPoint',[a,b,options])}

function Midpoint(a,options)//The midpoint of Segment a
{return convert('Midpoint',[a,options])}

function Point_on_object(a,number,options)//a point on object a, 0<number<1 specifies the location
{return convert('Point on object',[a,number,options])}

function Intersect(a,b,options)//The point of intersection between the linear objects a and b
{return convert('Intersect',[a,b,options])}

function Intersect1(a,b,options)//One point of intersection of circle b and object a
{return convert('Intersect1',[a,b,options])}

function Intersect2(a,b,options)//The second point of intersection of circle b and object a
{return convert('Intersect2',[a,b,options])}

function PlotXY(a,b,c,options)//Plots (c,a) on coordinate system b
{return convert('PlotXY',[a,b,c,options])}

function UnitPoint(a,num,options)//Defines a draggable point num pixels to the right of point a
{return convert('UnitPoint',[a,num,options])}

function DriverPoint(a,b,options)//used in interapplet communication
{return convert('DriverPoint',[a,b,options])}

function Segment(a,b,options)//Connects points a and b by a Segment
{return convert('Segment',[a,b,options])}

function Line(a,b,options)//Draws a line though a and b
{return convert('Line',[a,b,options])}

function Ray(a,b,options)//Draws ray with foot b, a defines the direction
{return convert('Ray',[a,b,options])}

function Parallel(a,b,options)//Draws a line parallel to a through b
{return convert('Parallel',[a,b,options])}

function Perpendicular(a,b,options)//Draws a line perpendicular to a through b
{return convert('Perpendicular',[a,b,options])}

function AxisX(a,options)//Defines the horizontal axis of coordinatesystem a
{return convert('AxisX',[a,options])}

function AxisY(a,options)//Defines the vertical axis of coordinatesystem a
{return convert('AxisY',[a,options])}

function Circle_interior(a,options)//Draws the interior of circle a
{return convert('Circle interior',[a,options])}

function Circle_by_radius(a,b,options)//Circle with centre a through point b
{return convert('Circle by radius',[a,b,options])}

function Circle(a,b,options)//Circle with centre a and radius equal to the length of segment b
{return convert('Circle',[a,b,options])}

function OriginUnit(a,b,options)//Defines a coordinate system centered at point a, with a unit length determined by the distance of a to b  
{return convert('Origin&Unit',[a,b,options])}

function UnitCircle(a,options)//Coordinate system centered on circle a with unit length the radius of a 
{return convert('UnitCircle',[a,options])}

function Locus(a,b,c,n,options)//Locus of a point or straight object a, when point b moves along path c (circle, straight object or polygon). n defines the number of samples
{return convert('Locus',[a,b,c,n,options])}


function Polygon(a,options)//Draws a shaded polygon. a is a list of points. E.g. Polygon([P,Q,R],'') draws the triangle PQR. The square brackets are not necessary: Polygon(a,b,c,'') will also do.
{return convert('Polygon',Polygon.arguments)}



function ShowButton(a,b,text,list,options)//ShowButton at location (a,b) with caption text. list is a list of objects to be shown. E.g ShowButton(10,10,'Show',[p,q,r],'[green]') 
{var tekst
lino++
tekst=checktekst(text)
construction+='{'+lino+'} ShowButton('+a+','+b+','+tekst+')('
for(_i=0;_i<list.length;_i++)
{construction+=list[_i]
if (_i<list.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}

function HideButton(a,b,text,list,options)//HideButton at location (a,b) with caption text. list is a list of objects to be hidden. E.g HideButton(10,10,'Show',[p,q,r],'[green]') 
{var tekst
lino++
tekst=checktekst(text)
construction+='{'+lino+'} HideButton('+a+','+b+','+tekst+')('
for(_i=0;_i<list.length;_i++)
{construction+=list[_i]
if (_i<list.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}
function MoveButton(a,b,c,text,list,options)//MoveButton at location (a,b) with caption text. c gives the speed.list is a list of pairs of objects to be moved (order: destination first, then object to be moved). E.g MoveButton(10,10,'Move',[p,q,r,s],'[green]') 
{lino++
text=checktekst(text)
construction+='{'+lino+'} MoveButton('+a+','+b+','+c+','+text+')('
for(_i=0;_i<list.length;_i++)
{construction+=list[_i]
if (_i<list.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}
function AnimateButton(a,b,text,list1,list2,list3,list4,options)
//AnimateButton at location (a,b) with caption text. list1 is a list of paired objects to be animated (order:object,path), list2 specifies the speed, list3 specifies once only(1) or indefinitly (0); list 4 specifies the type of motion( back and forth(0),one way(1), clockwise(1), counterclockwise(0))
{lino++
tekst=checktekst(text)
construction+='{'+lino+'} AnimateButton('+a+','+b+','+tekst+')('
for(_i=0;_i<list1.length;_i++)
{construction+=list1[_i]
if (_i<list1.length-1){construction+=','}}
construction+=')('
for(_i=0;_i<list2.length;_i++)
{construction+=list2[_i]
if (_i<list2.length-1){construction+=','}}
construction+=')('
for(_i=0;_i<list3.length;_i++)
{construction+=list3[_i]
if (_i<list3.length-1){construction+=','}}
construction+=')('
for(_i=0;_i<list4.length;_i++)
{construction+=list4[_i]
if (_i<list4.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}

//JSP4 only
function SimultaneousButton(a,b,text,list,options)
//SimultaneousButton at location (a,b) with caption text. list is a list of buttons to be fired simultaneously.
{lino++
tekst=checktekst(text)
construction+='{'+lino+'} SimultaneousButton('+a+','+b+','+tekst+')('
for(_i=0;_i<list.length;_i++)
{construction+=list[_i]
if (_i<list.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}

//JSP4only
function FixedText(a,b,text,options)//Caption text at fixed position (a,b)
{lino++
text=checktekst(text)
construction+='{'+lino+'} FixedText('+a+','+b+','+text+')'+options.check()+';'+'\n'
return lino
}

//JSP4 only
function PeggedText(a,b,options)//Caption with text identical to that of b at position of point a 
{return convert('PeggedText',[a,b,options])}

//JSP4 only
function ConcatText(a,b,list,options)//Caption at position (a,b) with text of objects in list concatenated.
{lino++
construction+='{'+lino+'} ConcatText('+a+','+b+')('
for(_i=0;_i<list.length;_i++)
{construction+=list[_i]
if (_i<list.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}

function Image(a,b,loc,options)//Displays image loc (.gif or .jpg) at fixed position (a,b) 
{lino++
loc=checktekst(loc)
construction+='{'+lino+'} Image('+a+','+b+','+loc+')'+options.check()+';'+'\n'
return lino
}

//JSP4 only
function ImageOnPoint(a,loc,options)//Displays image loc (.gif or .jpg) at position of point a. 
{lino++
loc=checktekst(loc)
construction+='{'+lino+'} ImageOnPoint('+a+','+loc+')'+options.check()+';'+'\n'
return lino
}

//JSP4 only
function ImageBetweenPoints(a,b,loc,options)//Displays part of image loc (.gif or .jpg) at  between points a and b. 
{lino++
loc=checktekst(loc)
construction+='{'+lino+'} ImageBetweenPoints('+a+','+b+','+loc+')'+options.check()+';'+'\n'
return lino
}

function Length(a,b,c,text,options)//Length of segment a
{lino++
text=checktekst(text)
construction+='{'+lino+'} Length('+a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}
function Perimeter(a,b,c,text,options)//Perimeter of polygon a
{lino++
text=checktekst(text)
construction+='{'+lino+'} Perimeter('+a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}
function Circumference(a,b,c,text,options)//Circumference of circle or circle interior a
{lino++
text=checktekst(text)
construction+='{'+lino+'} Circumference('
construction+=a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}
function Slope(a,b,c,text,options)//Slope of straight object a
{lino++
text=checktekst(text)
construction+='{'+lino+'} Slope('+a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}
function Area(a,b,c,text,options)//Area of circle(interior) or polygon a
{lino++
text=checktekst(text)
construction+='{'+lino+'} Area('+a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}
function Radius(a,b,c,text,options)//Radius of circle(interior) a 
{lino++
text=checktekst(text)
construction+='{'+lino+'} Radius('+a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}
function Angle(a,b,c,d,e,text,options)//Angle abc
{lino++
construction+='{'+lino+'} Angle('+a+','+b+','+c+','+d+','+e+','+text+')'+options.check()+';'+'\n'
return lino
}
function Distance(a,b,c,d,text,options)//Distance between a and b
{lino++
text=checktekst(text)
construction+='{'+lino+'} Distance('+a+','+b+','+c+','+d+','+text+')'+options.check()+';'+'\n'
return lino
}
function RatioSegments(a,b,c,d,text,options)//Ratio of the length of a and b, |a|/|b|
{lino++
text=checktekst(text)
construction+='{'+lino+'} Ratio/segments('+a+','+b+','+c+','+d+','+text+')'+options.check()+';'+'\n'
return lino
}
function RatioPoints(a,b,c,d,e,text,options)//Ratio of the length of segments ac and ab: |ac|/|ab|
{lino++
text=checktekst(text)
construction+='{'+lino+'} Ratio/Points('+a+','+b+','+c+','+d+','+e+','+text+')'+options.check()+';'+'\n'
return lino
}
function Coordinates(a,b,c,d,text,options)//Location of point a w. r. t. coordinate system b 
{lino++
text=checktekst(text)
construction+='{'+lino+'} Coordinates('+a+','+b+','+c+','+d+','+text+')'+options.check()+';'+'\n'
return lino
}
function Calculate(a,b,text1,text2,list,options)//Perfoms the calculation in text2. Text1 contains a prefix string. List contains one or more object references.
{lino++
text1=checktekst(text1)
text2=checktekst(text2)
construction+='{'+lino+'} Calculate('+a+','+b+','+text1+','+text2+')('
for(_i=0;_i<list.length;_i++)
{construction+=list[_i]
if (_i<list.length-1){construction+=','}}
construction+=')'+options.check()+';'+'\n'
return lino
}

function Parameter(a,b,c,text,options)//Used in interapplet communication.
{lino++
text=checktekst(text)
construction+='{'+lino+'} Parameter('+a+','+b+','+c+','+text+')'+options.check()+';'+'\n'
return lino
}

function Reflection(a,b,options)//Reflects a across straight object b
{return convert('Reflection',[a,b,options])}

function Dilation(a,b,num,options)//Dilates a w.r.t. point b with factor num
{return convert('Dilation',[a,b,num,options])}

function DilationSegmentRatio(a,b,c,d,options)//Dilates a w.r.t. point b with factor |c|/|d|
{return convert('Dilation/SegmentRatio',[a,b,c,d,options])}

function Dilation3PtRatio(a,b,c,d,e,options)//Dilates a w.r.t. point b with factor |cd|/|ce|
{return convert('Dilation/3PtRatio',[a,b,c,d,e,options])}

function DilationMarkedRatio(a,b,c,options)//Dilates a w.r.t. point b with factor of measurement c
{return convert('Dilation/MarkedRatio',[a,b,c,options])}

function Rotation(a,b,c,options)//Rotates a around b with radian angle c
{return convert('Rotation',[a,b,c,options])}

function RotationMarkedAngle(a,b,c,d,e,options)//Rotates a around b with angle cde
{return convert('Rotation/MarkedAngle',[a,b,c,d,e,options])}

function Translation(a,b,c,options)//Translates a. b and c are fixed numbers
{return convert('Translation',[a,b,c,options])}

function VectorTranslation(a,b,c,options)//Translates a by the vector implied by points b(foot) and c(tail)
{return convert('VectorTranslation',[a,b,c,options])}

function TranslationFixedAngleMarkedDistance(a,b,c,options)//See JSP-grammar
{return convert('Translation/FixedAngle/MarkedDistance',[a,b,c,options])}

function PolarTranslation(a,b,c,options)//Same as Translation
{return convert('PolarTranslation',[a,b,c,options])}

function TranslationMarkedAngleFixedDistance(a,b,c,options)//See JSP-grammar
{return convert('Translation/MarkedAngle/FixedDistance',[a,b,c,options])}

function TranslationMarkedAngleMarkedDistance(a,b,c,options)//See JSP-grammar.
{return convert('Translation/MarkedAngle/MarkedDistance',[a,b,c,options])}

//JSP4 only

function RotationMeasuredAngle(a,b,c,options)//Rotates a w.r.t. b over the measured angle c.
{return convert('Rotation/MeasuredAngle',[a,b,c,options])}


function _help(functionname)
{var n,m,c,a
a=functionname.toString()
n=a.indexOf('{',a)
m=a.indexOf(' ',a)
a=a.substring(m+1,n)
c=a.indexOf('//',a)
if (c>0) {a=a.substring(0,c)+'\n'+a.slice(c+2)}
alert(a)}
