//-- Script provided by Zer0[Q] <zvegad@mochis.org> to Backlash Administrative Web Based Interface

function newCenterWindow(page, name, w, h) {
	var t = Math.round((screen.height / 2) - (h / 2))
	var l = Math.round((screen.width / 2) - (w / 2))

	nw = window.open(page, name, 'width='+w+',height='+h+',status=no,resizable=no,scrollbars=yes,top='+t+',left='+l)
	setTimeout('nw.focus();',250);
	}

function firstFocus() {
	if (document.forms.length > 0) {
		var frm = document.forms[0];
		for (i = 0; i < frm.length; i++) {
			if (((frm.elements[i].type == 'text') || (frm.elements[i].type == 'textarea' || frm.elements[i].type == 'password') || (frm.elements[i].type.toString().charAt(0) == "s")) && (frm.elements[i].value == "")) {
				frm.elements[i].focus();
				break;
				}
			}
		}
	}

function setFormStyle() {
	firstFocus();
	}

function onlyNumbers(dot) {
	if (event.keyCode < 48 || event.keyCode > 57)
		event.returnValue = false;
	}

function numericFormat(fld, milSep, decSep, fldlen, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter

	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key

	len = fldlen;

	text = (document.all) ? document.selection.createRange().text : document.getSelection();
	if (text.length >= fld.value.length) {
		fld.value = "";
		fld.select(false);
		}

	if (fld.value.length > len)
		return false

//	len = fld.size - 2;
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
		aux = '';
		for(; i < len; i++)
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
			aux += key;
			len = aux.length;
			if (len == 0) fld.value = '';
			if (len == 1 && decSep != '') fld.value = '0'+ decSep + '0' + aux;
			else fld.value = aux;
			if (len == 2 && decSep != '') fld.value = '0'+ decSep + aux;
			else fld.value = aux;

			if (decSep == '') {
				nLen1 = 0;
				nLen2 = -1;
				nLen3 = 0;
				}
			else {
				nLen1 = 2;
				nLen2 = -3;
				nLen3 = -1;
				}

			if (len > nLen1) {
				aux2 = '';
				for (j = 0, i = len + nLen2; i >= 0; i--) {
					if (j == 3) {
						aux2 += milSep;
						j = 0;
						}
					aux2 += aux.charAt(i);
					j++;
					}
				fld.value = '';
				len2 = aux2.length;
				for (i = len2 + nLen3; i >= 0; i--)
					fld.value += aux2.charAt(i);
				if (decSep != '')
					fld.value += decSep + aux.substr(len - 2, len);
				}
			return false;
	}

function onlyDate(e) {
	if (event.keyCode < 47 || event.keyCode > 57)
		event.returnValue = false;
	}

function validDate(obj, DateSeparator){
	d = obj.value;

	if (d == "")
		return true;

	Sp1=d.indexOf(DateSeparator,0)
	Sp2=d.indexOf(DateSeparator,(parseInt(Sp1)+1));

	mday = parseInt(d.substring(0,Sp1));
	mmonth = parseInt(d.substring(Sp1+1,Sp2));
	myear = parseInt(d.substring(Sp2+1, d.length));

	d = new Date(d);
	if ( (isNaN(d)) || !( validDay(mday, mmonth - 1, myear) ) ) {
		alert('Por favor introduzca una fecha valida');
		obj.focus();
		return false;
		}
	}

function validDay(tDay, tMonth, tYear) {
	var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (IsLeapYear(tYear)) {
		DaysInMonth[1]=29;
		}

	if (tDay <= DaysInMonth[tMonth])
		return true;
	else
		return false;		
	}

function IsLeapYear(tYear) {
	if ((tYear%4)==0)	{
		if ((tYear%100==0) && (tYear%400)!=0) {
			return false;
			}
		else {
			return true;
			}
		}
	else {
		return false;
		}
	}

var nav4 = window.Event ? true : false;
function acceptNum(evt){ 
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
var key = nav4 ? evt.which : evt.keyCode; 
return (key <= 13 || (key >= 48 && key <= 57));
}
var pong;
function makeArray(n){
  this.length = n;
  for (i=1;i<=n;i++){
    this[i]=0;
  }
  return this;
}

// standard date display function with y2k compatibility
function displayDate() {
  var this_month = new makeArray(12);
  this_month[0]  = "Enero";
  this_month[1]  = "Febrero";
  this_month[2]  = "Marzo";
  this_month[3]  = "Abril";
  this_month[4]  = "Mayo";
  this_month[5]  = "Junio";
  this_month[6]  = "Julio";
  this_month[7]  = "Agosto";
  this_month[8]  = "Septiembre";
  this_month[9]  = "Octubre";
  this_month[10] = "Noviembre";
  this_month[11] = "Diciembre";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Domingo";
  this_day_e[1]  = "Lunes";
  this_day_e[2]  = "Martes";
  this_day_e[3]  = "Miércoles";
  this_day_e[4]  = "Jueves";
  this_day_e[5]  = "Viernes";
  this_day_e[6]  = "Sábado";

  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = today.getYear();
  var dia = today.getDay();
    if (year < 1000) {
       year += 1900; }
  return( " " + this_day_e[dia] + ", " + day + " de " + this_month[month] + " " + year);
}
/***************************************************************************************/

function openOnePageUI(code) { 
var URLStr = "https://crs.univisit.com/OnePageCrs/OnePageUI.aspx?Code=";
var ie = document.all != undefined; 
if (ie){ 
var width = window.screen.width-9; 
var height = window.screen.height-65; 
var popUpWin=0; 
}else{ 
var width = window.screen.width; 
var height = window.screen.height; 
var popUpWin=0; 
} 
if(popUpWin){ 
if(!popUpWin.closed) 
popUpWin.close(); 
} 
popUpWin = open(URLStr + code, 'popUpWin', 'toolbar=no, location=no, directories=no, status=no, menubar=ye, scrollbar=no, resizable=no, copyhistory=yes,width='+width+',height='+height+',left=0, top=0'); 
} 