// ajax

function round(numero,decimales) {
	var rnum = numero;
	var rlength = decimales; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return newnumber;
}

var http; 
function getHTTPObject()
{
http=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  http=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  http=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (http==null)
{
  alert("Su navegador no soporta XMLHTTP.")
  }
		
}

var enProceso = false; // lo usamos para ver si hay un proceso activo
getHTTPObject();

//fin ajax
function abrenueva(pagina,h,w) {
ventana='N'+parseInt(Math.random()*10000,0);
v=window.open(pagina, ventana, 'location=no,toolbar=no,resizable=yes, scrollbars=auto, left=15, top =15,height='+h+', width='+w);
v.focus();
}

function abreFichaF(cod){
		p=window.open("fcentro.asp?fid="+cod,"FRA"+cod,"width=800, height=610, toolbar=no, scrollbars=no, menubar=no, top=150; left=200");
				
		p.focus()		
	}
	
	function abreFichaFin(cod,inID){
		p=window.open("fcentro.asp?fid="+cod+"&inID="+inID,"FRA"+cod,"width=800, height=610, toolbar=no, scrollbars=no, menubar=no, top=150; left=200");
				
		p.focus()		
	}
function abreFichaFca(cod,inID){
		p=window.open("fcentro.asp?fid="+cod+"&caID="+inID,"FRA"+cod,"width=800, height=610, toolbar=no, scrollbars=no, menubar=no, top=150; left=200");
				
		p.focus()		
	}
function abre(pagina,ventana,h,w) {

v=window.open(pagina, ventana, 'location=no,toolbar=no,resizable=yes, scrollbars=auto, left=15, top =15,height='+h+', width='+w);
v.focus();
}
function hayMarcas(e)
{if (e.length==undefined)
	return (e.checked)
	else
	{
	marcado=false;
for (i=0;i<e.length;i++)
marcado=(marcado || e[i].checked);
return (marcado)
	}

}
function on(o,f){
o.style.backgroundColor=f;
//o.style.backgroundColor='#FFE8C4';
}
function imprime_Tarifa(servicioid,subtarifaid)
	{ if (subtarifaid==0)
		AFMwindow=window.open('nuevo/imprimeTarifa.asp?servicioid='+servicioid,'','width=600,height=600,toolbar=0,location=0,status=1,scrollbars=1,menubar=0,resizable=1')
		else
		AFMwindow=window.open('nuevo/imprimeTarifa1.asp?servicioid='+servicioid+'&subtarifaid='+subtarifaid,'','width=600,height=600,toolbar=0,location=0,status=1,scrollbars=1,menubar=0,resizable=1')
			AFMwindow.focus();
			}
			function foco(e){
			if (navigator.appName != 'Netscape')
			e.focus();
			}
function right(e) {
var msg = "Erasmus © 2005 Intraempresas";
if (navigator.appName == 'Netscape' && e.which == 3) {
alert(msg); // Delete this line to disable but not alert user
return false;
}
else
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
alert(msg); // Delete this line to disable but not alert user
return false;
}
return true;
}
//document.onmousedown = right;
function off(o,f){
o.style.backgroundColor=f;}
function click(id){
eval('document.all.'+id+'.style.cursor="wait"');
eval('document.all.'+id+'.style.cssText="FONT-WEIGHT: normal;	FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;    FONT-SIZE: 10px;    COLOR: #0067C6;    FONT-STYLE: normal;    FONT-VARIANT: normal;	text-decoration: none;cursor=wait"');
eval('document.all.'+id+'.innerHTML="Procesando..."');
}
function precarga() {
if (document.getElementById) {  // DOM3 = IE5, NS6
document.getElementById('hidepage').style.visibility = 'hidden';
}
else {
if (document.layers) {  // Netscape 4
document.hidepage.visibility = 'hidden';
}
else {  // IE 4
document.all.hidepage.style.visibility = 'hidden';
      }
   }
}
function printer(direccion){
p=window.open(direccion,'impresora'+parseInt(Math.random()*100000,10),'width=750, height=590, toolbar=no, scrollbars=yes, menubar=no, top=150;left=200');p.focus()
//p.print();p.close;

		
}
function redondear(cantidad, decimales) {
var cantidad = parseFloat(cantidad);
var decimales = parseFloat(decimales);
decimales = (!decimales ? 2 : decimales);
return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
}  
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function marca(e)
{
if (e!=null)
{
	if (e[0]==null)
{e.checked=!e.checked;
}else
{
x=!e[0].checked;
for (i=0;i<e.length;i++)
e[i].checked=x;
}}}
function MO(e)
{
if (!e)
var e=window.event;
var S=e.srcElement;
while (S.tagName!="TD")
{S=S.parentElement;}
S.className="T";
}

function MU(e)
{
if (!e)
var e=window.event;
var S=e.srcElement;
while (S.tagName!="TD")
{S=S.parentElement;}
S.className="P";
}



function makeArray(n) {
 for (var i = 1; i <= n; i++) {
 this[i] = 0;
 } 
 return this;
}

function daysInFebruary(whichYear) {
 return (whichYear % 4 == 0 && (!(whichYear % 100 == 0) || (whichYear % 400 == 0)) ? 29 : 28);
}
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
function isDate(mm, dd, yyyy) {
	if (mm !="" && !(mm > 0 && mm < 13))
	{
		//alert ("Invalid Month! Please enter a value between 1 and 12.");
		return false;
	}
	if (dd !="" && !(dd > 0 && dd < 32))
	{
		//alert ("Invalid Date! Please enter a value between 1 and 31.");
		return false;
	}
	if ((dd!="" && mm!="") && parseInt(dd) > daysInMonth[parseInt(mm)])
	{
		//alert ("Invalid Date for this Month!")
		return false;
	}
	if (yyyy !="" && !(yyyy > 1889 && yyyy < 2011))
	{
		//alert ("Invalid Year! Please enter a value between 1890 and 2010.");
		return false;
	}
	if ((mm=="2" || mm=="02" && dd!="" && yyyy!="") && dd > daysInFebruary(yyyy))
	{
		//alert ("Invalid Date for this Year!")
		return false;
	}
	return true;
}


colorbien='';
function validaf(form){

if(validaf2(form))
{form.submit();}
}
function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}
function imprime(xdiv){
MM_changeProp(xdiv,'','style.overflow','visible','DIV');window.print();MM_changeProp(xdiv,'','style.overflow','auto','DIV')
}

function validaf2(form){
cerror=0;

for (i=0;i<form.elements.length;i++){ 
ceste=0;
nombre=form.elements[i].name;
titulo=form.elements[i].title;
s=form.elements[i].value;
form.elements[i].style.backgroundColor=colorbien;
if (nombre.substring(2,3)=='_')
{
// validamos

// obligatorio
if ((nombre.substring(1,2)=='S') && (((s == null) || (s.length == 0 ))))
{
{ceste++;if(titulo!='')alert('Introduzca '+titulo)}
}
tipo=nombre.substring(0,1);


if ((tipo=='E') && (s != null) && (s.length != 0 )) // email 
{if ((s.indexOf("@") == -1) || (s.indexOf(" ") != -1) || (s.indexOf(".") == -1) || (s.length <5))ceste++;}

if ((tipo=='D') && (s != null) && (s.length != 0 )) // fecha 
{
if (s.indexOf("/") == -1) {ceste++;if(titulo!='')alert('Introduzca '+titulo)}
else {
	dd=s.substring(0,s.indexOf("/"));
	yy=s.substring(s.indexOf("/")+1,s.length);
	if (yy.indexOf("/") == -1) {ceste++;if(titulo!='')alert('Introduzca '+titulo)}
	else {
	mm=yy.substring(0,yy.indexOf("/"));
	yy=yy.substring(yy.indexOf("/")+1,yy.length);if (yy.length==2) yy='20'+yy;
	if (!isDate(mm, dd, yy)) {ceste++;if(titulo!='')alert('Introduzca '+titulo)}
	
	 }

}}


// numerico
if (((tipo=='N')||(tipo=='M')||(tipo=='T')||(tipo=='P')) && (s != null) && (s.length != 0 )){ // numerico
decallowed = 2; 
if (isNaN(s)) ceste++
else {
if (s.indexOf('.') == -1) s += ".";
dectext = s.substring(s.indexOf('.')+1, s.length);
if (dectext.length > decallowed){
ceste++;alert('Maximo 2 decimales');}}}

 //alert(ceste); 
if (ceste>0) {
cerror++;
if (colorbien='')
colorbien=form.elements[i].style.backgroundColor;
form.elements[i].style.backgroundColor='#FFFFCC';//CACA';//FFE8C4';
}	
}
if ((cerror==1)&&(ceste>0))
	{		if (tipo='L') form.elements[i].focus(); 
	else form.elements[i].select(); 
	}
} 

return (cerror==0);
}
function addlista(control,valor,texto){

eval("document.all['"+control + "']").add(new Option(texto,valor));
eval("document.all['"+control + "']").value=valor;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function printExcel(tabla){
var td;

Excel = new ActiveXObject("Excel.Application"); 
// Make Excel visible. //

// Create a new work book. 
Book = Excel.Workbooks.Add() 

fil=1
col=1
t=document.getElementById(tabla);
var tr=t.getElementsByTagName('tr'); 


th=t.getElementsByTagName('th'); 
	for(var q=0;q<th.length;++q) 
	{ 
		
		Book.ActiveSheet.Cells(fil,q+1).Value = ' '+th[q].innerHTML.replace(/<[^>]+>/g, '').replace('&nbsp;','') ;
Book.ActiveSheet.Cells(fil,q+1).Font.Bold = true
Book.ActiveSheet.Cells(fil,q+1).Font.Name = "Verdana";
Book.ActiveSheet.Cells(fil,q+1).Font.size=8;
	}

for(var p=0;p<tr.length;++p) 
{ 
	
	fil=fil+1;
	td=tr[p].getElementsByTagName('td'); 
	for(var q=0;q<td.length;++q) 
	{ 
	
		v=td[q].innerHTML.indexOf('select');
		if (v==-1)
		{
				Book.ActiveSheet.Cells(fil,q+1).Value = ' '+td[q].innerHTML.replace(/<[^>]+>/g, '').replace('&nbsp;','').replace('<br>','\n') ;
Book.ActiveSheet.Cells(fil,q+1).Font.Bold = false
Book.ActiveSheet.Cells(fil,q+1).Font.Name = "Verdana";
Book.ActiveSheet.Cells(fil,q+1).Font.size=8;}
		

}
}
Excel.Visible = true; 
}


 