function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function focalizar(){
    var foco=document.getElementById("centerframe");
    foco.style.display="none";
}

function cargar(){
    var foco=document.getElementById("centerframe");
    foco.style.display="block";
}

function gotoUrl(Url){

    // Creo el objeto AJAX
  var gotourl=nuevoAjax();
  var centro=document.getElementById("centro");
  gotourl.open("POST", "gotourl.php", true);
  gotourl.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  gotourl.send("GOURL="+Url+"&tb="+focoActual);
  gotourl.onreadystatechange=function(){
		if (gotourl.readyState==4){
			// Respuesta recibida. Coloco el texto plano en la capa correspondiente
			if (gotourl.responseText){
			centro.innerHTML=gotourl.responseText;
			}else{
        		centro.innerHTML="Error al cargar, cargue nuevamente la pagina presionando la tecla F5.";
			}
		}
	}
}

function logear()
{
	// Obtendo la capa donde se muestran las respuestas del servidor
	var divTransparente=document.getElementById("transparencia");
	var capa=document.getElementById("etiqueta");
	var user_=document.getElementById("inbox_user").value;
	var pass_=document.getElementById("inbox_pass").value;
	
	// Creo el objeto AJAX
	var ajax=nuevoAjax();

	// Coloco el mensaje "Cargando..." en la capa
	divTransparente.style.display="block";

	// Abro la conexión, envío cabeceras correspondientes al uso de POST 
	//y envío los datos con el método send del objeto AJAX
	ajax.open("POST", "login.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("log=in&user_="+user_+"&pass_="+pass_);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			// Respuesta recibida. Coloco el texto plano en la capa correspondiente
			if (ajax.responseText=="LOGIN OK!"){
				//Arregalr esto, hacia donde este el sitio nuevo
			window.location.href = "AdminCenter.php";
			}else{
			capa.innerHTML="Error user/pass incorrectos";
			divTransparente.style.display="none";}
		}
	}
}

function logout(){
cargar();
var log_out = nuevoAjax();
log_out.open("POST", "login.php", true);
log_out.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
log_out.send("log=out");
window.location.href = "http://www.simltd.com";
}

/*** contraer_externer ***/
var altura = 0;
var velocidad = 1;
function extender(obj, hasta) {
var objeto = document.getElementById(obj);
objeto.style.visibility = 'visible';
      objeto.style.height = hasta;
	/*  
		while (!(altura >= hasta)){
        altura += velocidad;
        objeto.style.height = altura;
        }
		*/
}

function contraer(obj) {
var objeto2 = document.getElementById(obj);
      /*
		while (!(altura <= 0)) {
        altura -= velocidad;
        objeto2.style.height = altura;
        } 
		*/
objeto2.style.visibility = 'hidden';
objeto2.style.height = '0px';
}
      
function extender_contraer (obj, hasta) {
if(document.getElementById(obj).style.height){
        altura=parseInt(document.getElementById(obj).style.height);
        }

if (altura <= 0) {
        extender(obj, hasta);
        } else {
        contraer(obj); if(obj=="calcu") contraer("dolaronline");
        }
}

/*** Calendario ***/
function leapYear(year) {
if (year % 4 == 0) // basic rule
return true // is leap year
return false // is not leap year
}

function getDays(month, year) {
var ar = new Array(12)
ar[0] = 31 // January
ar[1] = (leapYear(year)) ? 29 : 28 // February
ar[2] = 31 // March
ar[3] = 30 // April
ar[4] = 31 // May
ar[5] = 30 // June
ar[6] = 31 // July
ar[7] = 31 // August
ar[8] = 30 // September
ar[9] = 31 // October
ar[10] = 30 // November
ar[11] = 31 // December

return ar[month]
}

function getMonthName(month) {
var ar = new Array(12)
ar[0] = "January"
ar[1] = "February"
ar[2] = "March"
ar[3] = "April"
ar[4] = "May"
ar[5] = "June"
ar[6] = "July"
ar[7] = "August"
ar[8] = "September"
ar[9] = "October"
ar[10] = "November"
ar[11] = "December"

return ar[month]
}

function setCal() {
var now = new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
now = null

var firstDayInstance = new Date(year, month, 1)
var firstDay = firstDayInstance.getDay()
firstDayInstance = null

var days = getDays(month, year)

drawCal(firstDay + 1, days, date, monthName, year)
}

function drawCal(firstDay, lastDate, date, monthName, year) {
var headerHeight = 12 // height of the table's header cell
var border = 1 // 3D height of table's border
var cellspacing = 1 // width of table's border
var headerColor = "midnightblue" // color of table's header
var headerSize = "+1" // size of tables header font
var colWidth = 15 // width of columns in table
var dayCellHeight = 15 // height of cells containing days of the week
var dayColor = "darkblue" // color of font representing week days
var cellHeight = 15 // height of cells representing dates in the calendar
var todayColor = "red" // color specifying today's date in the calendar
var timeColor = "black" // color of font representing current time

var text = "" // initialize accumulative variable to empty string
text += '<CENTER>'
text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
text += monthName + ' ' + year 
text += '</FONT>' // close table header's font settings
text += '</TH>' // close header cell

var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
openCol += '<FONT COLOR="' + dayColor + '">'
var closeCol = '</FONT></TD>'

var weekDay = new Array(7)
weekDay[0] = "Sun"
weekDay[1] = "Mon"
weekDay[2] = "Tues"
weekDay[3] = "Wed"
weekDay[4] = "Thu"
weekDay[5] = "Fri"
weekDay[6] = "Sat"

text += '<TR ALIGN="center" VALIGN="center">'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
text += openCol + weekDay[dayNum] + closeCol 
}
text += '</TR>'

var digit = 1
var curCell = 1

for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
text += '<TR ALIGN="center" VALIGN="top">'
for (var col = 1; col <= 7; ++col) {
if (digit > lastDate)
break
if (curCell < firstDay) {
text += '<TD></TD>';
curCell++
} else {
if (digit == date) { // current cell represent today's date
text += '<TD HEIGHT=' + cellHeight + ' BGCOLOR="#999999">'
text += '<FONT COLOR="' + todayColor + '"><B>'
text += digit
text += '</B></FONT>'
text += '</TD>'
} else
text += '<TD HEIGHT=' + cellHeight + '><FONT>' + digit + '</FONT></TD>'
digit++
}
}
text += '</TR>'
}

text += '</TABLE>'
text += '</CENTER>'

document.getElementById("calendario").innerHTML=text;
}

/*** Calculadora ***/
var Accum = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
document.getElementById("ReadOut").value = Num;
FlagNewNum = false;
}
else {
if(document.getElementById("ReadOut").value == "0")
document.getElementById("ReadOut").value = Num;
else
document.getElementById("ReadOut").value += Num;
}
}
function Operation (Op) {
var Readout = document.getElementById("ReadOut").value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accum += parseFloat(Readout);
else if ( '-' == PendingOp )
Accum -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accum /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accum *= parseFloat(Readout);
else
Accum = parseFloat(Readout);
document.getElementById("ReadOut").value = Accum;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = document.getElementById("ReadOut").value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
document.getElementById("ReadOut").value = curReadOut;
}
function ClearEntry () {
document.getElementById("ReadOut").value = "0";
FlagNewNum = true;
}
function Clear () {
Accum = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
document.getElementById("ReadOut").value = parseFloat(document.getElementById("ReadOut").value) * -1;
}
function Percent () {
document.getElementById("ReadOut").value = (parseFloat(document.getElementById("ReadOut").value) / 100) * parseFloat(Accum);
}
