window.onError = null

function fadeInLayer(TopLayer,Layer,i) {
	if (!i) i=0;
	
	if (document.all) document.all[Layer].style.backgroundColor=colors[i];
	if (document.layers) document.layers[TopLayer].document.layers[Layer].bgColor=colors[i];

	i++;
	var command='fadeInLayer(\'' + TopLayer + '\',\''+ Layer + '\' ,' + i + ')';

	if(i<colors.length) setTimeout(command,60);
}

function fadeOutInLayer(TopLayer,Layer,i) {
	if(!i && i!=0) i=colors.length-1;

	if (document.all) document.all[Layer].style.backgroundColor=colors[i];
	if (document.layers) document.layers[TopLayer].document.layers[Layer].bgColor=colors[i];

	i--;
	var command='fadeOutInLayer(\'' + TopLayer + '\',\''+ Layer + '\' ,' + i + ')';

	if(i>=0) setTimeout(command,60);		
}
		
function fade(layer,i) {
	if(!i) i=0;
	
	//if (document.all[layer].style!= null && document.all) document.all[layer].style.backgroundColor=colors[i];
	if (document.getElementById(layer).style!= null)document.getElementById(layer).style.backgroundColor=colors[i];
	if (document.layers) document.layers[layer].bgColor=colors[i];

	i++;
	var command='fade("' + layer + '",' + i + ')';

	if(i<colors.length) setTimeout(command,60);
}

function fadeOut(layer,i) {
	if(!i && i!=0) i=colors.length-1;

	//if(document.all[layer].style!= null && document.all) document.all[layer].style.backgroundColor=colors[i];
	if (document.getElementById(layer).style!= null)document.getElementById(layer).style.backgroundColor=colors[i];
	if(document.layers) document.layers[layer].bgColor=colors[i];

	i--;
	var command='fadeOut("' + layer + '",' + i + ')';

	if(i>=0) setTimeout(command,60);
}

function Hide(layer) {
    if (document.layers) {
        document.layers[layer].visibility = 'hidden';
    } else {
        //if (document.all) {
          //  document.all[id].style.visibility = 'hidden';
        //} else {
            document.getElementById(layer).style.visibility = 'hidden';
        //}
    }	
}

function Show(layer) {
    if (document.layers) {
        document.layers[layer].visibility = 'show';
    } else {
        //if (document.all) {
          //  document.all[id].style.visibility = 'visible';
        //} else {
            document.getElementById(layer).style.visibility = 'visible';
        //}
    }	
}

function getObj(id) {
	var obj
    if (document.layers) {
        obj=document.layers[id];
		obj.style=obj;
    } else {
        if (document.all) {
            obj=document.all[id]
        } else {
            obj=document.getElementById(id);
        }
    }	
	return obj;
}

function MoveBy(id,x,y) {
	var obj = getObj(id)

	if (document.all) {
		MoveTo(id,obj.style.posLeft+x,obj.style.posTop+y)
	} else {
		MoveTo(id,x+obj.style.left,y+obj.style.top)
	}
}

function MoveTo(id,x,y) {
	var obj = getObj(id)

	if (x!=null) {
		if (document.all) {
			obj.style.posLeft = x
		} else {
			obj.style.left = x
		}
	}

	if (y!=null) {
		if (document.all) {
			obj.style.posTop = y
		} else {
			obj.style.top = y
		}
	}
}		

function GetX(id) {
	var obj = getObj(id)
	if (document.all) {
		return obj.style.posLeft
	} else {
		return obj.style.left
	}
}

function GetY(id) {
	var obj = getObj(id)
	if (document.all) {
		return obj.style.posTop
	} else {
		return obj.style.top
	}	
}

function WriteToLayer(id, text) {
	if (document.getElementById) {
		d = document.getElementById(id);
		d.innerHTML = text;
	} else if (document.all) {
		d = document.all[id];
		d.innerHTML = text;
	} else if (document.layers)	{
		d = document.layers[id];
		d.document.open();
		d.document.write(text);
		d.document.close();
	}
}

function RotateTo(id, ToDeg, i, func) {
	var right=true;
	if(!i) i=0;
	if(!func) func='';
	if (i>=360) i=0;
	
	if (ToDeg!=i) {
		var left = (360-ToDeg+i);
		if (left>360) left=360-left;
		var right = (ToDeg-i);
		if (right<0) right=360-right;

		if (right<=left) {
			right=true;
			i=i+2;
		} else {
			right=false;
			i=i-2;
		}
	}

	Show(id);
	var RotateIT = false;
	if ((right) && ((ToDeg - i) > 2)) RotateIT = true;
	if ((!right) && ((i - ToDeg) > 2)) RotateIT = true;

	if (RotateIT) {
		y = Math.round(Math.sin((i-90)*Math.PI/180)*215)+240;
		x = Math.round(Math.cos((i-90)*Math.PI/180)*215)+210;
		MoveTo(id,x,y);	
		setTimeout('RotateTo(\''+id+'\','+ToDeg+','+i+',\''+func+'\')',20);
	} else {
		y = Math.round(Math.sin((ToDeg-90)*Math.PI/180)*215)+240;
		x = Math.round(Math.cos((ToDeg-90)*Math.PI/180)*215)+210;	
		MoveTo(id,x,y);
		if (func!='') eval(func);
	}
}

function SetToDegree(id, ToDeg, func) {
	if(!func) func='';
	
	y = Math.round(Math.sin((ToDeg-90)*Math.PI/180)*215)+240;
	x = Math.round(Math.cos((ToDeg-90)*Math.PI/180)*215)+210;

	MoveTo(id,x,y);
	if (func!='') eval(func);
}
function NRotateTo(id, ToDeg, i, func) {
	var right=true;
	if(!i) i=0;
	if(!func) func='';
	if (i>=360) i=0;
	
	if (ToDeg!=i) {
		var left = (360-ToDeg+i);
		if (left>360) left=360-left;
		var right = (ToDeg-i);
		if (right<0) right=360-right;

		if (right<=left) {
			right=true;
			i=i+2;
		} else {
			right=false;
			i=i-2;
		}
	}

	Show(id);
	var RotateIT = false;
	if ((right) && ((ToDeg - i) > 2)) RotateIT = true;
	if ((!right) && ((i - ToDeg) > 2)) RotateIT = true;

	if (RotateIT) {
		y = Math.round(Math.sin((i-90)*Math.PI/180)*215)+267;
		x = Math.round(Math.cos((i-90)*Math.PI/180)*215)+235;
		MoveTo(id,x,y);	
		setTimeout('NRotateTo(\''+id+'\','+ToDeg+','+i+',\''+func+'\')',20);
	} else {
		y = Math.round(Math.sin((ToDeg-90)*Math.PI/180)*215)+267;
		x = Math.round(Math.cos((ToDeg-90)*Math.PI/180)*215)+235;	
		MoveTo(id,x,y);
		if (func!='') eval(func);
	}
}
function NSetToDegree(id, ToDeg, func) {
	if(!func) func='';
	
	y = Math.round(Math.sin((ToDeg-90)*Math.PI/180)*215)+267;
	x = Math.round(Math.cos((ToDeg-90)*Math.PI/180)*215)+235;

	MoveTo(id,x,y);
	if (func!='') eval(func);
}

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function textCounter(field) {
	var maxlimit  = 500
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    alert( 'Max ' + maxlimit + ' characters.' );
    return false;
  }
}

function assocCounter(field) {
	var maxlimit  = 99
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    alert( strAssocMaxDigits1  + (maxlimit+1) + strAssocMaxDigits2);
    return false;
  }
}


