var apos=0;
var adir=2;
var alen=0;

var onload_functions = new Array();
var onunload_functions = new Array();
/**
* New function for handling multiple calls to window.onload and window.unload by pentapenguin
*/
window.onload = function()
{
	for (i = 0; i <= onload_functions.length; i++)
	{
		eval(onload_functions[i]);
	}
}

window.onunload = function()
{
	for (i = 0; i <= onunload_functions.length; i++)
	{
		eval(onunload_functions[i]);
	}
}
/**
* Javascript para guardias
* @author alexof <aguevara@vacorp.net>
* @version 1.0
* @since 22/11/2006
* @package JavaScript
*/
function objPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
/**
*
*/
function ayuda(msg,ref,img,rx,ry,ly,lx,fd,ms){

	obj = document.getElementById(ref);
	xy 	= objPos(obj);
	to	= 0;

	if ( typeof img == 'undefined' || img == '' ) { img = 'tooltipl.gif'; }

	ToolTip.prototype.mostrar=TTmostrar;

	tt=new ToolTip( obj,(xy[0]),(xy[1]) );
	tt.imagen = img;
	tt.timeout = to;
	tt.info = msg;

	if ( typeof rx != 'undefined' && rx != '' ) { tt.rx = rx; }
	if ( typeof ry != 'undefined' && ry != '' ) { tt.ry = ry; }
	if ( typeof lx != 'undefined' && lx != '' ) { tt.lx = lx; }
	if ( typeof ly != 'undefined' && ly != '' ) { tt.ly = ly; }
	if ( typeof fd != 'undefined' && fd != '' ) { tt.fd = fd; }
	if ( typeof ms != 'undefined' && ms != '' ) { tt.ms = ms; }

	/*setear el fade*/
	tt.fade = fd;
	tt.millisec = ms;

	tt.mostrar();
}
/**
* Hace un fade para un objeto
*/
function fade(id,opacStart,opacEnd){
    //speed for each frame
    var speed = Math.round(500 / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
/**
* cambia la opacidad de un objeto
*/
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 + ")";
}
/**
* Execute the delete command
* @param p page
* @param a action
* @param id id to delete
* @param msg message to show
*/
function makeDelete( p,a,ids,myvars,msg,sesion ){
	var error = 0;
	
	if ( typeof p == 'undefined' || p == '' ) { alert('Parameter 1 is missing'); error=1;}
	if ( typeof a == 'undefined' || a == '' ) { alert('Parameter 2 is missing'); error=1;}
	if ( typeof ids == 'undefined' || ids == '' ) { alert('Parameter 3 is missing'); error=1;}
	
	if ( error ){return false;}
	
	if (confirm( msg ) ){
		return gotToPage( p,a,ids,myvars,sesion );
		return false;
	}else{
		return false;
	}
}
/**
* Go to a page
* @param p page
* @param a action
* @param ids id to delete
* @param myvars
* @param sesion the current session
*/
function gotToPage( p,a,ids,myvars,sesion ){
	
	var url = '';

	for (x=0 ; x<ids.length ; x++){		
		url = url + '&'+myvars[x]+'='+ids[x];
	}
	
	location.href = p+'.php?sid=' + sesion +'&view=' + a + url;
	return false;
}
/**
* Set variable
*/
function setVar( form,myvar,myval ){
	
	var obj = eval('window.document.' + form + '.' + myvar);
	
	obj.value = myval;
	
	return true;
}
/**
* Go to a page
* @param p page
* @param a action
* @param ids id to delete
* @param myvars
* @param sesion the current session
*/
function gotToPageSimple( p ){

	location.href = p;
	return false;
}
/**
* change the image src
*/
function changeImageSrc(objID,newClass){
	obj = my_getbyid(objID);
	
	obj.className=newClass;
	
	return true;
}


function my_getbyid(id){
	itm = null;
	
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	
	return itm;
}

/**
* Set display of page element
* s[-1,0,1] = hide,toggle display,show
*/
function dE(n, s, type){
	
	if (!type){
		type = 'block';
	}

	var e = document.getElementById(n);

	
	if( e.style.display == 'block' )
		e.style.display = 'none'
	else
		e.style.display = 'block'
}

function validarFecha(obj){
	re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	
	if( obj.value != '' && !obj.value.match( re ) ){ 
		alert('El formato de fecha es inválido, debe ser dd/mm/aaaa');
		obj.focus();
	}
}
/**
* Ask to submit
*/
function askToSubmit(msg){
	
	if (confirm( msg ) ){
		return true;
	}else{
		return false;
	}
	
	return true;
}

function setNames(form){

	var tform = eval('window.document.' + form );
	
	/**/
	var spnNames = document.getElementById('names');
	var spnID = document.getElementById('spnidcard');
	
	spnNames.innerHTML = tform.regname.value+' '+tform.reglastname.value ;
	spnID.innerHTML = tform.idcard.value;
}


function animate(){
	var elem = document.getElementById('progress');
	if(elem != null) {
		if (apos==0) alen += adir;
		if (alen>32 || apos>79) apos += adir;
		if (apos>180) alen -= adir;
		if (apos>180 && alen==0) apos=0;
		elem.style.left = apos;
		elem.style.width = alen;
	}
}
function remove_loading(t_id) {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
}

function show_hide_box(an, width, height, borderStyle, href) {

	var boxdiv = document.getElementById(href);

	if (boxdiv != null) {
		if (boxdiv.style.display=='none') {
			move_box(an, boxdiv);
			boxdiv.style.display='block';
		} else
			boxdiv.style.display='none';
		return false;
	}

	boxdiv = document.createElement('div');
	boxdiv.setAttribute('id', href);
	boxdiv.style.display = 'block';
	boxdiv.style.position = 'absolute';
	boxdiv.style.width = width + 'px';
	boxdiv.style.height = height + 'px';
	boxdiv.style.border = borderStyle;
	boxdiv.style.backgroundColor = '#fff';

	var contents = document.createElement('iframe');
	contents.scrolling = 'no';
	contents.frameBorder = '0';
	contents.style.width = width + 'px';
	contents.style.height = height + 'px';
	contents.src = href;

	boxdiv.appendChild(contents);
	document.body.appendChild(boxdiv);
	move_box(an, boxdiv);

	return false;
}
function move_box(an, box) {
	var cleft = 33;
	var ctop = -15;
	var obj = an;
	while (obj.offsetParent) {
	cleft += obj.offsetLeft;
	ctop += obj.offsetTop;
	obj = obj.offsetParent;
	}
	box.style.left = cleft + 'px';
	ctop += an.offsetHeight + 10;
	if (document.body.currentStyle &&
	document.body.currentStyle['marginTop']) {
	ctop += parseInt(document.body.currentStyle['marginTop']);
	}
	box.style.top = ctop + 'px';
}

// opens standard dialog
function openContact (url)
{
  var posX = screen.availWidth/2 - 175;
  var posY = screen.availHeight/2 - 125;
  
  var wnd = window.open(url, 'contacto', 'status=no,resizable=no,width=500,height=350,left='+posX+',top='+posY);
  
  wnd.focus();   
  return wnd;
}

// opens standard dialog
function openExperience (url)
{
  var posX = screen.availWidth/2 - 175;
  var posY = screen.availHeight/2 - 125;
  
  var wnd = window.open(url, 'contacto', 'status=no,resizable=no,width=520,height=380,left='+posX+',top='+posY);
  
  wnd.focus();   
  return wnd;
}

// opens news pop up
function openNews (url)
{
  var posX = screen.availWidth/2 - 175;
  var posY = screen.availHeight/2 - 125;
  
  var wnd = window.open(url, 'news', 'status=no,resizable=no,width=520,height=380,left='+posX+',top='+posY);
  
  wnd.focus();   
  return wnd;
}

// opens standard dialog
function openPartOfTheTeam (url)
{
  var posX = screen.availWidth/2 - 175;
  var posY = screen.availHeight/2 - 125;
  
  var wnd = window.open(url, 'formulario', 'status=no,resizable=no,width=400,height=450,left='+posX+',top='+posY);
  
  wnd.focus();   
  return wnd;
}