var metodoHistory = "";
var idtim;

	function applyColor(obj) {
		obj.style.background = "#FFFFFF";
	}

	function restoreColor(obj) {
		obj.style.background = "#F3F6FD";
	}

	function onlyNumber() {
	    if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 46)
	        event.returnValue = false;
	}

	function windowAction() {
		var windowAction = new getObj('windowAction');
		windowAction.style.display = "block";
	}

	function windowAction2(source, obj) {
		var windowAction = new getObj('windowAction');
		var iAction = new getObj('iAction');
		var posX = findPosX(obj);
		var posY = findPosY(obj);

		if (metodoHistory == source) {
			windowAction.style.display = "none";
			frm.orderField.style.display = "block";
			metodoHistory = "";
			iAction.obj.src = "";

		} else {
			iAction.obj.src = source;
			windowAction.style.top = 150;
			windowAction.style.left = 300;
			windowAction.style.top = posY + 5;
			windowAction.style.left = posX - 500;
			windowAction.style.display = "block";
			metodoHistory = source;
		}
	}
	
	
	function windowClose() {
		var windowAction = new getObj('windowAction');
		windowAction.style.display = "none";
	}

	function setHeight(obj) {
		var bloque = new getObj(obj);
		var altura = bloque.obj.clientHeight;

		if (altura > 0) {
			var contenedor = new getParentObj('windowAction');
			var contenido = new getParentObj('iAction');
			contenedor.style.height = (altura + 15);
			contenido.style.height = (altura + 25);
		}
	}

	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 getObj(name) {
		if (document.getElementById) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;

		} else if (document.all) {
			this.obj = document.all[name];
			this.style = document.all[name].style;

		} else if (document.layers) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		}
	}
	function getParentObj(name) {
		if (window.parent.document.getElementById) {
			this.obj = window.parent.document.getElementById(name);
			this.style = window.parent.document.getElementById(name).style;

		} else if (window.parent.document.all) {
			this.obj = window.parent.document.all[name];
			this.style = window.parent.document.all[name].style;

		} else if (window.parent.document.layers) {
			this.obj = window.parent.document.layers[name];
			this.style = window.parent.document.layers[name];
		}
	}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
	clearTimeout(idtim);
		for(i = opacStart; i >= opacEnd; i--) {
			idtim = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
	clearTimeout(idtim);
		for(i = opacStart; i <= opacEnd; i++)
			{
			idtim = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if(opacity == 0) {
		windowClose();
	} else {
		windowAction();
	}
}

function shiftOpacity(id, millisec, aux) {
	//if an element is invisible, make it visible, else make it ivisible document.getElementById(id).style.opacity
	if(document.getElementById(id).style.opacity == 0) {
		currentOpac(id, 100, millisec);
	} else {
		currentOpac(id, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
