// Abrir Nueva Ventana


function OpenWindow(Url,NombreVentana,Ancho,Alto){
 window.open(Url,'Ventana','status=yes,scrollbars=yes,resizable=yes,width='+Ancho+',height='+Alto);
}

//Funcion para Envio de formularios
function Send(form){
	document.getElementById(form).submit();	
}

//Funcion para mostrar mas informacion
function Show(id){
	if(document.getElementById(id).style.display =='none'){
		document.getElementById(id).style.display ='block'
		} else {
			document.getElementById(id).style.display ='none'
			}
	}

function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

$(function() {
		$("#fechallegada").datepicker();
		$("#inicio").datepicker();
		$("#fin").datepicker();
	});


///////////////////////////////////
// Funciones AJAX				 //
///////////////////////////////////

// Genera el Objeto de Conexion para Ajax
function newajax(){
	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){
				if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
				}
				}
				return xmlhttp; 
}

//Funcion de Precarga Ajax
function precarga(){
	loader = '<div class="loader"></div>';
	return loader;
}

//Elimina Imagenes

function DoDelImg(img,sct,tbl,ids,idv){	
	//alert(noticia);
	ajax = newajax();
	
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById('bkimgkontainer').innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById('bkimgkontainer').innerHTML = ajax.responseText;
        }
    }
	ajax.send("cmd=dodelimg"+"&img="+img+"&sct="+sct+"&tbl="+tbl+"&ids="+ids+"&idv="+idv)
}


function PrvCal(){	
	pmes = parseInt(document.getElementById('mfc').value)-1
	if(pmes < 1){
		pmes = 12
		pano = parseInt(document.getElementById('yfc').value)-1
	}else{
		pano = parseInt(document.getElementById('yfc').value)
		}
	
	idp = document.getElementById('idp').value
	
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById('showcalendar').innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById('showcalendar').innerHTML = ajax.responseText;
        }
    }
	ajax.send("cmd=showcal"+"&mes="+pmes+"&ano="+pano+"&idpropiedad="+idp)
}

function NxtCal(){	
	nmes = parseInt(document.getElementById('mfc').value)+1
	if(nmes > 12){
		nmes = 1;
		pano = parseInt(document.getElementById('yfc').value)+1
	}else{
		pano = parseInt(document.getElementById('yfc').value)
		}
	
	idp = document.getElementById('idp').value
	
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById('showcalendar').innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById('showcalendar').innerHTML = ajax.responseText;
        }
    }
	ajax.send("cmd=showcal"+"&mes="+nmes+"&ano="+pano+"&idpropiedad="+idp)
}

function addvigencia(val){	
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById('vencimiento'+val).innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById('vencimiento'+val).innerHTML = ajax.responseText;
        }
    }
	ajax.send("cmd=addvigencia"+"&idpropiedad="+val)
}

function asigvigencia(tiempo,id){
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById('vencimiento'+id).innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById('vencimiento'+id).innerHTML = ajax.responseText;
        }
    }
	ajax.send("cmd=addcontrato&idpropiedad="+id+"&tiempo="+tiempo)
	}
	
function modfecha(obj,id){
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById(obj+id).innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById(obj+id).innerHTML = ajax.responseText;
			$("#fecha_"+obj+"_"+id).datepicker();
        }
    }
	ajax.send("cmd=addvigenciaopen"+"&objeto="+obj+"&idpropiedad="+id)
}

function cancelfecha(obj,id){
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById(obj+id).innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById(obj+id).innerHTML = ajax.responseText;
			$("#fecha_"+obj+"_"+id).datepicker();
        }
    }
	ajax.send("cmd=cancelfecha"+"&objeto="+obj+"&idpropiedad="+id)
}

function savefecha(obj,id){
	fecha = document.getElementById('fecha_'+obj+'_'+id).value
	
	ajax = newajax();
	ajax.open("POST", "/include/ajaxlib.php", true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange=function() {
        if (ajax.readyState==1) {
            document.getElementById(obj+id).innerHTML = precarga();
        }
        if (ajax.readyState==4) {
            document.getElementById(obj+id).innerHTML = ajax.responseText;
			$("#fecha_"+obj+"_"+id).datepicker();
        }
    }
	ajax.send("cmd=savefecha"+"&objeto="+obj+"&idpropiedad="+id+"&fecha="+fecha)
}
