// JavaScript Document

function tabView(tab) { 
	document.getElementById("tab_1").style.display = "none";
	document.getElementById("tab_2").style.display = "none";
	document.getElementById("tab_3").style.display = "none";
	document.getElementById("tab_4").style.display = "none";
	document.getElementById("tab_5").style.display = "none";
	document.getElementById("tab_"+tab).style.display = "block";
}

/********************************************************
* makes a popup of determinate picture
*
* @param img (image path)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function PopUp(img, toWidth, toHeight){
	foto1= new Image();
	foto1.src=(img);
	Control(img, toWidth, toHeight);
}

/********************************************************
* control popup creation of determinate picture
*
* @param img (image path)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function Control(img, toWidth, toHeight){
	if((foto1.width!=0)&&(foto1.height!=0)){  
		verFoto(img, toWidth, toHeight);
	} else {funcion="Control('"+img+"')";  
		intervalo=setTimeout(funcion,20);
	}
}

/********************************************************
* open a popup of determinate picture on new window
*
* @param img (image path)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function verFoto(img, toWidth, toHeight){  
	ancho=foto1.width; 
	alto=foto1.height;
	ratio = ancho/alto;
	if (ratio > 1 ){ 
		reducc = ancho/toWidth;
		ancho = toWidth;
		alto = alto * 1/reducc;
	} else {
		reducc = alto/toHeight;
		alto = toHeight;
		ancho = ancho * 1/reducc;
	}
	height = alto+20;
	width = ancho+20;
	cadena="width="+width+",height="+height+",resizable=no, centered=yes";
	ventana=window.open(img,"",cadena);
}

/********************************************************
* resize an IMG object
*
* @param slider (IMG object)
* @param toWidth (required width)
* @param toHeight (required height)
*
********************************************************/
function preload(slider, toWidth, toHeight){
	image1 = new Image();
	image1.src = slider.src;
	width = image1.width;
	height = image1.height;
	ratio = width/height;
	if (width != 0 && height != 0){
		if (ratio >= 1){
			reducc = width/toWidth;
			width = toWidth;
			height = height * 1/reducc;
		} else {
			reducc = height/toHeight;
			height = toHeight;
			width = width * 1/reducc;
		}
	} else {
		height = toHeight;
		width = toHeight;
	}
	slider.setAttribute("width",width);
	slider.setAttribute("height",height);
}

/********************************************************
* confirm delete
*
* @param act (delete url action)
*
********************************************************/
function confdel(act){
	if(confirm("Are you sure to delete this item?")){
		document.forms[0].action = act;
		return true;
	} else {
		return false;
	}
}

/********************************************************
* send resort list values
*
* @param field (send field to sort list)
*
********************************************************/
function reSort(field){
	if (document.forms[0].orderDir.value == "DESC"){
		document.forms[0].orderDir.value = "ASC";
	} else {
		document.forms[0].orderDir.value = "DESC";
	}
	document.forms[0].orderField.value = field;
	document.forms[0].submit();
}

/********************************************************
* max characters of textarea ***acoted yet***
*
* @param obj (object textarea)
*
********************************************************/
function maxInput(obj, message){
	var textSize = (obj.value.length);
	document.formulary.counter.value = (200 - textSize);
	if (textSize == 199){
		aux=obj.value;
	}
	if (textSize >= 200){
		alert(message);
		obj.value = aux;
		obj.blur();
		return false;
	}
}

/********************************************************
* max characters of textarea ***limited to Troxler***
*
* @param obj (object textarea)
*
********************************************************/
function maxInput(obj, message){
	var textSize = (obj.value.length);
	document.formulary.counter.value = (200 - textSize);
	if (textSize == 199){
		aux=obj.value;
	}
	if (textSize >= 200){
		alert(message);
		obj.value = aux;
		obj.blur();
		return false;
	}
}

/********************************************************
* counter reset ***limited to Troxler***
*
* @param obj (object textarea)
*
********************************************************/
function counterReset(){
	if (document.formulary.counter){
		var textSize = (document.formulary.description.value.length);
		document.formulary.counter.value = (200 - textSize);
	}
}

function NoLetters(evt){
var nav4 = window.Event ? true : false;
var val = '0123456789';

var key = nav4 ? evt.which : evt.keyCode;
for (i=0; i<val.length; i++) {
	if (val.indexOf(String.fromCharCode(key),0) != -1) return true;
}
if (key <= 13) return true;
return false;
}

function imgXY(imgID) {
  /* This function returns the upperleft x,y coordinates of the specified image */
  var XY = new Object();
  var imgObj = document.images[imgID];
  if (document.layers) {
	XY.x = eval(imgObj).x;
	XY.y = eval(imgObj).y;
  } else {
	var x,y, tempEl;
	x = eval(imgObj).offsetLeft;
	y = eval(imgObj).offsetTop;
	tempEl = eval(imgObj).offsetParent;
  	while (tempEl != null) {
  		x += tempEl.offsetLeft;
		y += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	XY.x = x;
	XY.y = y;
  }
  return XY;
}
