//////////////////////////////////////////////
// Cross DHTML TOC
// TgSpTicker.js
// COPYRIGHT ADVANTYS 1999
// Last modified : August 25 1999
//////////////////////////////////////////////

//TgSpTicker_ticker
//Constructor
function TgSpTicker_ticker(top,left,width,height,speed,way,step,startpos,content,color,bgpic,position,visibility)
{
		//Private properties
		//******************
		this.ns4 = (document.layers)? true:false
		this.ie4 = (document.all)? true:false
		this.content=content;
		this.w=width;
		this.h=height;
		this.manualscroll=false; 
		this.click=0;			// stored mouse X cursor position in manualscroll()
		this.delta=0;			//store the difference betxeen click and the mouse coordinates while the mousebutton 1 is down
		this.firstpass=0;		//store the fisrt passage in manualscroll()
		this.scrollindex=startpos; // index du scrolling
		this.l = left;
		this.t = top;
		this.way = way
		//visibility is set to true by default is not passed as argument
		//**************************************************************
		if (visibility!=null) this.visibility = visibility;
		else this.visibility = true;

		//position is set to true by default is not passed as argument
		//************************************************************
		if (position!=null) this.position = position;
		else this.position = 'absolute';

		//color is set to '' by default is not passed as argument
		//*******************************************************
		if (color==null) this.color=''
		else this.color = color;

		//bgpic is set to '' by default is not passed as argument
		//*******************************************************
		if (bgpic==null) this.bgpic=''
		else this.bgpic = bgpic;
		this.changeDirection=false;
		this.objname = "AdvTicker"+(TgSpTicker_ticker.count++)

		//Public properties
		//*****************
		this.speed= 0   //  speed;		//scrolling speed
		this.tmpStep=step;
		this.step=step;			//scrolling step

		//Public Methods
		//**************
		this.hide=TgSpTicker_hide;
		this.show=TgSpTicker_show;
		this.moveTo=TgSpTicker_move;
		this.resize=TgSpTicker_resize;
		this.changeColor=TgSpTicker_changeColor;
		this.write=TgSpTicker_writeContent;
		this.onchangedirection=null;

		//Private Methods
		//***************
    this.autoScroll=TgSpTicker_autoScroll;	
		this.build=TgSpTicker_build;
		this.activate=TgSpTicker_activate
		this.writeTicker=TgSpTicker_write

		//Calling some core methods
		//*************************
		this.build();
		this.writeTicker();
		this.activate();
		//activate the scrolling
		//*********************
		this.autoScroll();

}
TgSpTicker_ticker.count = 0


//TgSpTicker_startManualScroll
//Set the scroll for manuel (mouse) move
function TgSpTicker_startManualScroll()
{
	this.parent.manualscroll = true
}


//TgSpTicker_stopManualScroll
//Set the scroll for autmatic move
function TgSpTicker_stopManualScroll()
{
		this.parent.manualscroll = false
		this.parent.firstpass = 0
}


//TgSpTicker_manualScroll
//Get the mouse pointer coordinates if the manual mode is set on
function TgSpTicker_manualScroll(e)
{	
		if (this.parent.manualscroll == true)
		{
			if (this.parent.way==0)
				{var pos = (this.parent.ns4)? e.screenX:event.screenX}
			else
				{var pos = (this.parent.ns4)? e.screenY:event.screenY}

			if (this.parent.firstpass==0)
			{
					this.parent.click = pos;
					this.parent.firstpass=1;
			}
			else
			{
				var buf=this.parent.delta
				this.parent.delta = this.parent.click-pos
				if ((buf>=0 &&this.parent.delta <0 ) ||  (buf<0 &&this.parent.delta >=0 )) this.parent.changeDirection=true;
				this.parent.click = pos
				this.parent.scrollindex=this.parent.scrollindex-this.parent.delta;
			}
			if (this.parent.changeDirection) 
			{
				this.parent.changeDirection=false;
				if (this.parent.onchangedirection !=null) this.parent.onchangedirection();
			}
		}
		if (this.parent.ns4){
		routeEvent(e);
		 }		 
}


//TgSpTicker_autoScroll
//Scrolling function
function TgSpTicker_autoScroll()
{	
	//get the lenght on the child layer in order to re init the scroll when needed
	//****************************************************************************
	if (this.delta>=0) 
	{
	//Scroll from right to left
	//*************************
		this.scrollindex-=this.step;
		if (this.way==0) {if (this.scrollindex < -this.rootlayer.childlayer.w) {this.scrollindex=this.w;}}
		else {if (this.scrollindex < -this.rootlayer.childlayer.h) {this.scrollindex=this.h;}}
	}
	else	
	{
	//Scroll from left to right 
	//*************************
		this.scrollindex+=this.step;
		if (this.way==0)
		{
			if (this.scrollindex > this.w) {this.scrollindex=-this.rootlayer.childlayer.w;};
		}
		else	
		{
			if (this.scrollindex > this.h) {this.scrollindex=-this.rootlayer.childlayer.h;};
		}
	}
	//Assign the next coordinate to the object
	//****************************************
	if (this.way==0)
	{
		this.rootlayer.childlayer.css.left=this.scrollindex;
		this.rootlayer.childlayer.l=this.scrollindex;
	}
	else
	{
		this.rootlayer.childlayer.css.top=this.scrollindex;
		this.rootlayer.childlayer.t=this.scrollindex;
	}


	//Internet Explorer does not allow clipping in the rootlayer when the position is set to relative
	// The tip consist in clipping the childlayer to simulate de rootlayer automatic clip
	//************************************************************************************************
	if (this.ie4 && this.position=='relative')
		if (this.way==1)
		{
			if (this.rootlayer.childlayer.css.pixelTop>=0)
				if (this.rootlayer.childlayer.offsetTop>0)
					this.rootlayer.childlayer.css.clip='rect(0 '+this.w+' '+(this.h-this.rootlayer.childlayer.offsetTop)+ ' 0)'
				else
					this.rootlayer.childlayer.css.clip='rect(0 '+this.w+' 0 0)'
			else
				this.rootlayer.childlayer.css.clip='rect('+(Math.abs(this.rootlayer.childlayer.css.pixelTop))+' '+this.w+' '+(this.h-this.rootlayer.childlayer.css.pixelTop)+' 0)'
		}
		else
		{
			if (this.rootlayer.childlayer.css.pixelLeft>=0) 
				if (this.rootlayer.childlayer.offsetLeft>0)
					this.rootlayer.childlayer.css.clip='rect(0 '+(this.w-this.rootlayer.childlayer.offsetLeft)+' '+this.h+' 0)'
				else
					this.rootlayer.childlayer.css.clip='rect(0 0 '+this.h+' 0)'
			else 
				this.rootlayer.childlayer.css.clip='rect(0 '+(this.w+Math.abs(this.rootlayer.childlayer.css.pixelLeft))+' '+this.h+' '+Math.abs(this.rootlayer.childlayer.css.pixelLeft)+')'
		}

	//Use the speed attribute to call itself
	//**************************************
	timerID = setTimeout(this.obj+".autoScroll()", 0);
}


//TgSpTicker_build
//Bodytext builder
function TgSpTicker_build()
{
	if (this.ns4) 
	{
		//Netscape only
		//*************
		if (this.position=="absolute") 
		{
			var str= '<LAYER  ID="'+this.objname+'"'
			str+= ' POSITION=absolute LEFT='+this.l+' TOP='+this.t +' CLIP="0,0,'+this.w+','+this.h+'"'
			str+= ' HEIGHT='+this.h+'  WIDTH='+this.w+'  BGCOLOR="'+this.color+'" BACKGROUND="'+this.bgpic+'">\n'
			str+= '<LAYER ID="'+this.objname+'child" POSITION=relative HEIGHT='+this.h+' BGCOLOR="'+this.color+'">\n'

			str +=this.content+'</LAYER></LAYER>\n'
		}
		else
		{
			var str= '<ILAYER ID='+this.objname+'_ilayer><LAYER  ID="'+this.objname+'"'
			str+= ' POSITION=absolute LEFT='+this.l+' TOP='+this.t+' CLIP="0,0,'+this.w+','+this.h+'"'
			str+= ' HEIGHT='+this.h+'  WIDTH='+this.w+'  BGCOLOR="'+this.color+'"  BACKGROUND="'+this.bgpic+'">\n'
			str+= '<LAYER ID="'+this.objname+'child" POSITION=relative HEIGHT='+this.h+' BGCOLOR="'+this.color+'">\n'
			str +=this.content+'</LAYER></LAYER></ILAYER>\n'
		}
	}	
	else	
	{
		//Internet Explorer only
		//**********************
		if (this.position=="absolute") 
		{

			var str= '<DIV  ID="'+this.objname+'" STYLE="position:absolute;overflow:hidden;top:'+this.t+';left:'+this.l+';width:'+this.w+';height:'+this.h+';clip:rect(0,'+this.w+','+this.h+',0);background-color:'+this.color+';background-image:URL('+this.bgpic+');">\n'
			str+= '<DIV ID="'+this.objname+'child" STYLE="position:absolute;top:0;left:0;height:'+this.h+';background-color:'+this.color+';">\n'
			str +=this.content+'</DIV></DIV>\n'
		}
		else
		{

			var str= '<DIV  ID="'+this.objname+'" '
			str+= 'STYLE="position:relative;top:'+this.t+';left:'+this.l+';width:'+this.w+';height:'+this.h+';background-color:'+this.color+';">\n'
			str+= '<DIV ID="'+this.objname+'child" STYLE="position:absolute;background-color:'+this.color+';">\n'
			str +=this.content+'</DIV></DIV>\n'
		}
	}
	this.tickertext=str;
}


//TgSpTicker_write
//write the DHTML code corresponding to the object
function TgSpTicker_write()
{
	document.write(this.tickertext);
}


//TgSpTicker_writeContent
//re-write into the ticker
function TgSpTicker_writeContent(content) 
{
  if (this.ns4) 
  {
   this.rootlayer.childlayer.document.open()
   this.rootlayer.childlayer.document.write(content)
   this.rootlayer.childlayer.document.close()
  }
  else 
  {
    var str = "document.all." + this.objname + "child.innerHTML = '" + content + "'";
    eval(str);
  }
}


//TgSpTicker_move
//move the ticker
function TgSpTicker_move(x, y) 
{

  if (this.ns4) this.rootlayer.moveTo(x, y);
  else 
  {
	this.rootlayer.css.left = x;
    this.rootlayer.css.top  = y;
  }
  this.l=x;
  this.t=y;
}


//TgSpTicker_resize
//resize the ticker
function TgSpTicker_resize(w, h) 
{
  if (this.ns4) 
  {
	this.rootlayer.resizeTo(w, h);
  }
  else 
  {
	this.rootlayer.css.width = w;
	this.rootlayer.css.height  = h;
	this.rootlayer.css.clip  = "rect(0px "+w+"px "+h+"px 0px)"
  }
  this.w=w;
  this.h=h;
}


//TgSpTicker_hide
//hide the ticker
function TgSpTicker_hide() 
{
  if (this.ns4) this.rootlayer.css.visibility = "hide";
  else this.rootlayer.css.visibility = "hidden";
}


//TgSpTicker_show
//show the ticker
function TgSpTicker_show()
{
  if (this.ns4)  this.rootlayer.css.visibility = "show";
  else this.rootlayer.css.visibility = "visible";
}


//TgSpTicker_changeColor
//change the background color
function TgSpTicker_changeColor(color)
{
  if (this.ns4)  
  {
	this.rootlayer.css.bgColor = color;
	this.rootlayer.childlayer.css.bgColor= color;
  }
  else 
  {
	this.rootlayer.css.backgroundColor = color;
	this.rootlayer.childlayer.css.backgroundColor = color;
  }
}


//TgSpTicker_activate
//initialize the object, set all events, and make the object come alive
function TgSpTicker_activate()
{
		childobjname=this.objname+'child';
		if (this.ns4) childobjname='document.'+this.objname+'.document.'+childobjname
		ns4prefix =(this.ns4 && this.position=='relative') ? 'document.'+this.objname+'_ilayer.' :''
		this.rootlayer=(this.ns4) ? eval(ns4prefix+'document.'+this.objname):eval(this.objname)
		this.rootlayer.css=(this.ns4) ? eval(ns4prefix+'document.'+this.objname):eval(this.objname+'.style')
		this.rootlayer.childlayer=eval(ns4prefix+childobjname)
		this.rootlayer.childlayer.css=(this.ns4) ? eval(ns4prefix+childobjname):eval(childobjname+'.style')
		this.rootlayer.parent = this

		if (this.ns4) 
		{
			this.l = this.rootlayer.css.left;
			this.t = this.rootlayer.css.top;
			this.rootlayer.childlayer.w=this.rootlayer.childlayer.css.clip.right 
			this.rootlayer.childlayer.h=this.rootlayer.childlayer.css.clip.bottom 
			this.rootlayer.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE | Event.MOUSEOUT)
		}	
		else
		{
			this.l = parseInt(this.rootlayer.css.left);
			this.t = parseInt(this.rootlayer.css.top);
			this.rootlayer.childlayer.w=parseInt(this.rootlayer.childlayer.offsetWidth)
			this.rootlayer.childlayer.h=parseInt(this.rootlayer.childlayer.offsetHeight)
		}	
		if (this.way==0)
			{this.rootlayer.childlayer.l = this.scrollindex;}
		else
			{this.rootlayer.childlayer.t = this.scrollindex;}

		// events capture
		//****************
		/*
		this.rootlayer.onmousedown = TgSpTicker_startManualScroll
		this.rootlayer.onmouseup = TgSpTicker_stopManualScroll
		this.rootlayer.onmouseout = TgSpTicker_stopManualScroll
		this.rootlayer.onmousemove = TgSpTicker_manualScroll
		*/
		
		this.rootlayer.onmousemove = parate
		this.rootlayer.onmouseout = sigue
		

		//Needed by setTimeOut function : the parameter is a text string not a pointer
		//******************************************************************************
		this.obj= this.objname+"layer"
		eval(this.obj + "=this");

		//check the visibility set by user and do the action
		//**************************************************
		if (!this.visibility) this.hide();
}
//**************************************
// end of Ticker Object
//**************************************

function calculaH() {
	if ((!document.form.qty.value) || (!document.form.int.value) || (!document.form.per.value)) {
		alert("No todos los campos necesarios estan asignados");
		//return false;
	} 
	else { 
		var interes = eval(document.form.per.value) * eval(document.form.qty.value);
		alert (interes);
		interes = interes / 100;
		var quantitat = eval(document.form.qty.value) + interes;
		var qu = eval(document.form.per.value) * 12;
		qu = quantitat / qu;
		qu = Math.round(qu * 100) / 100;
		document.form.qu.value = qu;
	}
}

function parate()
{
	this.parent.step = 0;
}

function sigue()
{
	this.parent.step = this.parent.tmpStep;
}
