////////////////////////
// Variables Globales //
////////////////////////

var ancho = screen.availWidth - 16;
var alto = screen.availHeight - 55;

var netscape_6_7 = (navigator.userAgent.toLowerCase().indexOf("netscape") > -1 && document.getElementById)?1:0;		

var copyRight = "© AUCOSTA 2008";


///////////////////////////////////
// Función para Mostrar el Plano //
//////////////////////////////////

function mostrarPlano() {
	window.open("paginas/plano.html","plano","width=950,height=600,top=50,left=30,scrollbars=no,resizable=no,status=yes");
}

/////////////////////////////
// Funciones para Imágenes //
/////////////////////////////

function ampliarFoto(sourceImg, titulo, pancho, palto) {
	code='<html><head><title>AUCOSTA (' + titulo + ')</title></head><body scroll="no" bgcolor="#BDC3DD" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"><table width=100% height=100% cellspacing=0 cellpadding=0 border=0><tr><td valign=top align=center>'
	code=code+"<a href='javascript:window.close();' onFocus='if(this.blur)this.blur()'><img src='" + sourceImg + "' border=0 alt='[ Cerrar ]' title='..{ Cerrar }..'></a></td></tr></table></body></html>"
	dimensiones = 'width=' + pancho + ',height=' + palto + ',resizable=0,titlebar=1,left=' + (((ancho-pancho)/2)+3) + ',top=' + (((alto-palto)/2)+5);
	info=window.open("","info",dimensiones);
	info.document.open();
	info.document.write(code);
	info.document.close();
}


///////////////////////////
// Funciones para Listar //
///////////////////////////

function encima(obj) {
	if(obj.style.backgroundColor != '#ffcc00') {
		obj.style.backgroundColor = 'cddbeb';
	}  
}

function fuera(obj, color_default) {
	if(obj.style.backgroundColor != '#ffcc00') {
		obj.style.backgroundColor = color_default;
	}
}


////////////////////////////////////////////////
// Funciones para ocultar y mostrar elementos //
////////////////////////////////////////////////

function mostrarId(obj) {
	if (netscape_6_7) {
		eval("document.getElementById('" + obj + "').style.display = '';");
	} else {
		eval("document.all." + obj + ".style.display = '';");
	}
}

function ocultarId(obj) {
	if (netscape_6_7) {
		eval("document.getElementById('" + obj + "').style.display = 'none';");
	} else {
		eval("document.all." + obj + ".style.display = 'none';");
	}
}


///////////////////////////
// Funciones Dreamweaver //
///////////////////////////

function MM_displayStatusMsg(msgStr) { // v1.0
	if (msgStr = "") {
			msgStr = ":: AUSUR - Autopista del Sureste - Concesionaria Española de Autopistas S.A. ::  ..-{ &copy; 2002-2004 }-..";
	}
	
	status = msgStr;
	document.MM_returnValue = true;
}


/////////////////////////////
// Funciones Botón Derecho //
/////////////////////////////

function rtclickcheck(keyp) {
  if (navigator.appName == "Netscape" && keyp.which == 3) {
    alert(copyRight);
    return false;
  }

  if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
    alert(copyRight);
    return false;
  }
}

document.onmousedown = rtclickcheck;


/////////////////////////////
// Funciones Botón Derecho //
/////////////////////////////

function ponFecha() {
	dias  = new Array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	
	fecha = new Date();
	indiceDia = fecha.getDay();
	indiceMes = fecha.getMonth();
	
	fechaActual = dias[indiceDia] + "<br>" + fecha.getDate() + " de " + meses[indiceMes] + " de " + fecha.getUTCFullYear();
	document.write(fechaActual);
}

function ponMes() {
	meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	
	fecha = new Date();
	indiceMes = fecha.getMonth();
	
	fechaActual = meses[indiceMes];
	document.write(fechaActual);
}


//////////////////////////
// Funciones Formulario //
//////////////////////////

function isNumeric(numero) {
	if ( (parseInt(numero,10)).toString() != (numero).toString() ) {
		return false;
	}
	
	return true;
}

function isEmail(StrObj) {
	var separateEmailsBy = ", "; 
	var email = "<none>"; // Si no hay ningún email correcto pongo esto 
	var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); 
	
	if (emailsArray) { 
		email = ""; 
		for (var i = 0; i < emailsArray.length; i++) { 
			if (i != 0) email += separateEmailsBy; 
			email += emailsArray[i]; 
		} 
	} 
	
	if (email == "<none>") {
		return false;
	} 
	
	return true;
}

function LTrim(s) {
	// Devuelve una cadena sin los espacios del principio
	var i=0, j=0;

	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++) if(s.substring(i,i+1) != ' ') { j=i; break; }
	
	return s.substring(j, s.length);
}

function RTrim(s) {
	// Quita los espacios en blanco del final de la cadena
	var j=0;

	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--) if(s.substring(i,i+1) != ' ') { j=i; break; }

	return s.substring(0, j+1);
}

function Trim(s) {
	// Quita los espacios del principio y del final
	if (LTrim(RTrim(s)) == ' ') {
		return '';
	} else {
		return LTrim(RTrim(s));
	}
}


////////////////////////////
// Funciones para números //
////////////////////////////

function devuelveConComa(numero) {
	var nuevoNumero = (numero.toString()).replace(".", ",");
	
	return nuevoNumero;
}

function devuelveConPunto(numero) {	
	var nuevoNumero = (numero.toString()).replace(",", ".");
	
	return nuevoNumero;
}

function establecerDecimales(value, precision) {
	var comprobarCasosCeros = false;
	
	value = (devuelveConPunto(value.toString()).toString()); //convert value to string
	precision = parseInt(precision, 10);
	
	if (value.substring(0, 2) == "0.") {
		comprobarCasosCeros = true;
	}

	var whole = "" + Math.round(value * Math.pow(10, precision));
	var decPoint = whole.length - precision;

	if (decPoint != 0) {
			result = whole.substring(0, decPoint);
			result += ".";
			result += whole.substring(decPoint, whole.length);
	} else {
			result = whole;
	}
	
	if (result == ".0") {
			result = "0.00"
	}
	if (comprobarCasosCeros == true) {
		if (result.substring(0, 1) == ".") {
			result = "0.0" + result.substring(1, 2);
		} else if (result.toString().length == 2) {
			result = "0." + result;
		}
	}
	
	result = result.replace(".", ",");
	
	return result;
}
