// AJAX
function newAjax(){
   var xmlhttp=false;
   try{
     xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e){
     try{
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }catch(E){
       xmlhttp=false;
     }
 }
 if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
   xmlhttp = new XMLHttpRequest();
 }
 return xmlhttp;
}


////////////////////////////////////
//      SECTION CATEGORY          //
////////////////////////////////////

function saveCategory($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmcategory.id.value;
   pag = document.frmcategory.pag.value;
   if(!is_empty(document.frmcategory.name.value))
   {
   	name = document.frmcategory.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   status = document.frmcategory.status.value;
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/gallery_category.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&name="+name+"&status="+status+"&pag="+pag);
   }
}

function updateCategory($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmcategory.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/gallery_category.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delCategory($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmcategory.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/gallery_category.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}


////////////////////////////////////
//         SECTION NEWS           //
////////////////////////////////////

function saveNews($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   var send = true;
   id = document.frmnews.id.value;
   pag = document.frmnews.pag.value;
   if(!is_empty(document.frmnews.the_title.value))
   {
   	the_title = document.frmnews.the_title.value;
   }else{
   	send = false;
	error_form();
   }
   if(!is_empty(document.frmnews.the_subtitle.value))
   {
   	the_subtitle = document.frmnews.the_subtitle.value;
   }else{
   	send = false;
	error_form();
   }
   /*if(!is_empty(document.frmnews.elm1.value))
   {*/
   	elm1 = document.frmnews.elm1.value;
   /*}else{
   	send = false;
	error_form();
   }*/
   status = document.frmnews.status.value;
   if(send)
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/news.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&the_title="+the_title+"&the_subtitle="+the_subtitle+"&elm1="+elm1+"&status="+status+"&pag="+pag);
   }
}

function updateNews($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmnews.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/news.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delNews($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmnews.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/news.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}


////////////////////////////////////
//         SECTION USERS          //
////////////////////////////////////

function saveUser($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmuser.id.value;
   if(!is_empty(document.frmuser.nick.value))
   {
   	nick = document.frmuser.nick.value;
   }else{
   	send = "failure";
	error_form();
   }
   if(!is_empty(document.frmuser.name.value))
   {
   	name = document.frmuser.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   if(!is_empty(document.frmuser.pass.value) && !is_empty(document.frmuser.cpass.value))
   {
		if(document.frmuser.pass.value == document.frmuser.cpass.value)
		{
   			pass = document.frmuser.pass.value;
		}
		else
		{
			send = "failure";
			error_form();	
		}
   }else{
   	send = "failure";
	error_form();
   }
   if(!is_empty(document.frmuser.lastname.value))
   {
   	lastname = document.frmuser.lastname.value;
   }else{
   	send = "failure";
	error_form();
   }
   if(!is_empty(document.frmuser.email.value))
   {
	if(document.frmuser.email.value.search(/^[\w-\.]{2,}@([\w-]{2,}\.)*[\w-]{2,}\.[\w-]{2,4}$/ig)){
		send = "failure";
		alert("La cuenta de correo no es valida, debes escribirla por ejemplo: juan@mail.com");
		document.frmuser.email.focus();
		return false;
	} else{  
   		email = document.frmuser.email.value;
	}
   }else{
   	send = "failure";
	error_form();
   }
   if(send=="next")
   {
	   ajax=newAjax();
	   ajax.open("POST", "../controller/user.cnt.php",true);
	   ajax.onreadystatechange=function() {
		  if(ajax.readyState==1)
		  {
			//preloader.innerHTML = "       Enviando...";        
			preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
		  }else if (ajax.readyState==4) {		  
				 divActualizable.innerHTML = ajax.responseText
		  }
	   }
	   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	   ajax.send("task="+$task+"&nick="+nick+"&pass="+pass+"&name="+name+"&lastname="+lastname+"&email="+email+"&pag="+pag);
   }
}

function updateUser($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/user.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id);
   hidden_form();
}

function delUser($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/user.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id)
}


////////////////////////////////////
//           IMAGE           //
///////////////////////////////////

function delimage($id)
{
   divActualizable = document.getElementById('delima'+$id);
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/image.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id)
}

function LostPass()
{
   divActualizable = document.getElementById('olvidar_pass');
   preloader = document.getElementById('preloader-3');
   
   if(document.frmclient.email.value)
	{
		email = document.frmclient.email.value;
	}else{
		enviar = false;
		alert("La cuenta de correo no es valida, debes escribirla por ejemplo: juan@mail.com");
		document.frmclient.email.focus();
		return false;
	}
	if(document.frmclient.email.value.search(/^[\w-\.]{2,}@([\w-]{2,}\.)*[\w-]{2,}\.[\w-]{2,4}$/ig)){
		enviar = false;
		alert("La cuenta de correo no es valida, debes escribirla por ejemplo: juan@mail.com");
		document.frmclient.email.focus();
		return false;
	}
   
   ajax=newAjax();
   ajax.open("POST", "controller/lostpass.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('gfx/loader.gif') no-repeat 50% 50%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("email="+email)
}


////////////////////////////////////
//         SECTION CITY           //
////////////////////////////////////

function saveCity($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmcity.id.value;
   pag = document.frmcity.pag.value;
   dpto = document.frmcity.dpto.value;
   if(!is_empty(document.frmcity.name.value))
   {
   	name = document.frmcity.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   status = document.frmcity.status.value;
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/city.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&dpto="+dpto+"&name="+name+"&status="+status+"&pag="+pag);
   }
}

function updateCity($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmcity.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/city.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delCity($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmcity.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/city.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}


////////////////////////////////////
//         SECTION LOT            //
////////////////////////////////////

function saveLot($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmlot.id.value;
   pag = document.frmlot.pag.value;
   city = document.frmlot.city.value;
   
   if(!is_empty(document.frmlot.name.value))
   {
   	name = document.frmlot.name.value;
   }else{
   	send = "failure";
	error_form();
   }

   numlot = document.frmlot.numlot.value;
   locate = document.frmlot.locate.value;
   quota = document.frmlot.quota.value;
   term = document.frmlot.term.value;
   gmaps = document.frmlot.gmaps.value;
   elm1 = document.frmlot.elm1.value;
   status = document.frmlot.status.value;
   
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/lot.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&city="+city+"&name="+name+"&numlot="+numlot+"&locate="+locate+"&quota="+quota+"&term="+term+"&elm1="+elm1+"&status="+status+"&pag="+pag+"&gmaps="+gmaps);
   }
}

function updateLot($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmlot.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/lot.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delLot($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmlot.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/lot.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}

function delGallery($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmimage.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/gallery.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}

function updateGallery($id,$value)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmimage.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/gallery.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=update"+"&id="+$id+"&value="+$value+"&pag="+pag)
}

function loteamiento($id,$nro)
{
   divActualizable = document.getElementById('lote_aqui');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "./view/lote.vw.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText;
			 $('html, body').animate({scrollTop: $('#lote_aqui').offset().top});
			 
			 var i;
			 for(i=0; i <= $nro; i++){
				 $("a[rel=group"+i+"]").fancybox(); 
				 $("#vmapa"+i).fancybox({
					'width' : '60%',
					'height' : '55%',
					'autoScale' : false,
					'transitionIn' : 'none',
					'transitionOut' : 'none',
					'type' : 'iframe' 
				 }); 
			 }
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("id="+$id+"&nro="+$nro)
}

////////////////////////////////////
//     SECTION GROUP EMAILS       //
////////////////////////////////////

function saveGroupMail($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmgroupmail.id.value;
   if(!is_empty(document.frmgroupmail.name.value))
   {
   	name = document.frmgroupmail.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   status = document.frmgroupmail.status.value;
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/groupmail.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&name="+name+"&status="+status+"&pag="+pag);
   }
}

function updateGroupMail($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/groupmail.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id);
   hidden_form();
}

function delGroupMail($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/groupmail.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}

/////////////////////////////////
//      SELECTION MAILS        //
/////////////////////////////////

function ChangeGroupMails()
{
   divActualizable = document.getElementById('sel');
   preloader = document.getElementById('preloader');
   group = document.frmnewmessage.group.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/sendmessage.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=select"+"&group="+group+"&pag="+pag)
}

function sendMessage()
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = 'true';
   group = document.frmnewmessage.group.value;
   selmails = document.frmnewmessage.selmails.value;
   if(document.frmnewmessage.subject.value)
   {
		subject = document.frmnewmessage.subject.value;
   }else{
	   	send = 'false';
		alert("El mensaje debe tener asunto!");
   }
   if(document.frmnewmessage.elm1.value)
   {
		elm1 =  document.frmnewmessage.elm1.value;
   }else{
	   	send = 'false';
		alert("El mensaje debe contenido!");
   }
   if(send == 'true')
   {
	   ajax=newAjax();
	   ajax.open("POST", "../controller/sendmessage.cnt.php",true);
	   ajax.onreadystatechange=function() {
		  if(ajax.readyState==1)
		  {
			//preloader.innerHTML = "       Enviando...";        
			preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
		  }else if (ajax.readyState==4) {		  
				 divActualizable.innerHTML = ajax.responseText
		  }
	   }
	   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	   ajax.send("task=send"+"&group="+group+"&subject="+subject+"&elm1="+elm1);
   }
}

////////////////////////////////////
//      SECTION DIREMAIL          //
////////////////////////////////////

function saveDiremail($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmdiremail.id.value;
   pag = document.frmdiremail.pag.value;
   if(!is_empty(document.frmdiremail.name.value))
   {
   	name = document.frmdiremail.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   if(document.frmdiremail.email.value)
	{
		email = document.frmdiremail.email.value;
	}else{
		enviar = false;
		alert("La cuenta de correo no es valida, debes escribirla por ejemplo: juan@mail.com");
		document.frmclient.email.focus();
		return false;
	}
	if(document.frmdiremail.email.value.search(/^[\w-\.]{2,}@([\w-]{2,}\.)*[\w-]{2,}\.[\w-]{2,4}$/ig)){
		enviar = false;
		alert("La cuenta de correo no es valida, debes escribirla por ejemplo: juan@mail.com");
		document.frmdiremail.email.focus();
		return false;
	}
   status = document.frmdiremail.status.value;
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/diremail.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&name="+name+"&email="+email+"&status="+status+"&pag="+pag);
   }
}

function updateDiremail($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmdiremail.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/diremail.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delDiremail($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmdiremail.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/diremail.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}

function selectEmail($id,$value)
{
   divActualizable = document.getElementById('recar');
   preloader = document.getElementById('preloader');
   cod = document.getElementById($value+'-'+$id).value;
   ajax=newAjax();
   ajax.open("POST", "../controller/group.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("id="+cod+"&nu="+$value)
}

function delEmail($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/listgroup.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id)
}

/////////////////////////////////
//      SELECTION BANNERS      //
/////////////////////////////////

function delBanner($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/banner.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id)
}


//////////////////////////
//
// OTHERS
//
//////////////////////////


function hidden_id()
{
	document.getElementById('lote_aqui').style.height = "0px";
}

function Xlightbox($obj){
	document.getElementById('xlb').style.position = "absolute";
	document.getElementById('xlb').style.width = "100%";
	document.getElementById('xlb').style.height = document.body.clientHeight+"px";
	document.getElementById('xlb').style.minHeight = "100%";
	document.getElementById('xlb').style.zIndex = "1001";
	document.getElementById('xlb').style.display = "block";
	document.getElementById('xlb').style.background = "url(gfx/overlay.png)";
	document.getElementById('xlb_content').style.position = "fixed";
	document.getElementById('xlb_content').style.display = "block";
	document.getElementById('xlb_content').style.width = "50%";
	document.getElementById('xlb_content').style.minHeight = "50%";
	document.getElementById('xlb_content').style.top = "23%";
	document.getElementById('xlb_content').style.left = "25%";
	document.getElementById('xlb_content').style.padding = "16px";
	//document.getElementById('xlb_content').style.background = "#fff";
	document.getElementById('xlb_content').style.zIndex = "1002";
	document.getElementById('xlb_content').style.overflow = "auto";
	document.getElementById('xlb_content').innerHTML = '<img src="'+$obj+'" width="500" border="0">';
	document.getElementById('close').style.cssFloat = "right";
	document.getElementById('close').style.fontWeight = "bold";
	document.getElementById('close').style.cursor = "pointer";
} 

function outLightbox(){
	document.getElementById('xlb').style.position = "normal";
	document.getElementById('xlb').style.width = "0%";
	document.getElementById('xlb').style.height = "0%";
	document.getElementById('xlb').style.zIndex = "0";
	document.getElementById('xlb').style.display = "none";
	document.getElementById('xlb').style.background = "";
	document.getElementById('xlb_content').style.display = "none";
	document.getElementById('xlb_content').style.width = "0%";
	document.getElementById('xlb_content').style.height = "%";
	document.getElementById('xlb_content').style.top = "0%";
	document.getElementById('xlb_content').style.left = "0%";
	document.getElementById('xlb_content').style.padding = "0px";
	//document.getElementById('xlb_content').style.background = "#fff";
	document.getElementById('xlb_content').style.zIndex = "0";
	document.getElementById('xlb_content').style.overflow = "auto";
	document.getElementById('xlb_content').innerHTML = '';
}

function upMap($obj){
	document.getElementById('xlb').style.position = "absolute";
	document.getElementById('xlb').style.width = "100%";
	document.getElementById('xlb').style.height = document.body.clientHeight+"px";
	document.getElementById('xlb').style.minHeight = "100%";
	document.getElementById('xlb').style.zIndex = "1001";
	document.getElementById('xlb').style.display = "block";
	document.getElementById('xlb').style.background = "url(gfx/overlay.png)";
	document.getElementById('xlb_content').style.position = "fixed";
	document.getElementById('xlb_content').style.display = "block";
	document.getElementById('xlb_content').style.width = "700px";
	document.getElementById('xlb_content').style.height = "350px";
	document.getElementById('xlb_content').style.top = "25%";
	document.getElementById('xlb_content').style.left = "25%";
	document.getElementById('xlb_content').style.padding = "16px";
	//document.getElementById('xlb_content').style.background = "#fff";
	document.getElementById('xlb_content').style.zIndex = "1002";
	document.getElementById('xlb_content').style.overflow = "hidden";
	document.getElementById('xlb_content').innerHTML = '<iframe width="700" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+$obj+'&amp;output=embed"></iframe>';
	document.getElementById('close').style.cssFloat = "right";
	document.getElementById('close').style.fontWeight = "bold";
	document.getElementById('close').style.cursor = "pointer";
} 

function outupMap(){
	document.getElementById('xlb').style.position = "normal";
	document.getElementById('xlb').style.width = "0%";
	document.getElementById('xlb').style.height = "0%";
	document.getElementById('xlb').style.zIndex = "0";
	document.getElementById('xlb').style.display = "none";
	document.getElementById('xlb').style.background = "";
	document.getElementById('xlb_content').style.display = "none";
	document.getElementById('xlb_content').style.width = "0%";
	document.getElementById('xlb_content').style.height = "%";
	document.getElementById('xlb_content').style.top = "0%";
	document.getElementById('xlb_content').style.left = "0%";
	document.getElementById('xlb_content').style.padding = "0px";
	//document.getElementById('xlb_content').style.background = "#fff";
	document.getElementById('xlb_content').style.zIndex = "0";
	document.getElementById('xlb_content').style.overflow = "auto";
	document.getElementById('xlb_content').innerHTML = '';
}


function desplegar($obj,$tit,$nro)
{
	divActualizable = document.getElementById('datos2'+$obj);
	var eldiv = 'datos2'+$obj;
	document.getElementById('datos'+$obj).style.display = "none";
	document.getElementById('datos2'+$obj).style.display = "inline";
	
	document.getElementById('cambio'+$obj).innerHTML = '&nbsp;<a href="javascript:void();" onclick="ocultar(\''+$obj+'\',\''+$tit+'\'); return false" class="link_lote">'+$tit+'</a>';
	preloader = document.getElementById('preloader');
	ajax=newAjax();
	ajax.open("POST", "./view/lote2.vw.php",true);
	ajax.onreadystatechange=function() {
	  if(ajax.readyState==1)
	  {
		//preloader.innerHTML = "       Enviando...";        
		preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
	  }else if (ajax.readyState==4) {		  
			 divActualizable.innerHTML = ajax.responseText;
			 $("a[rel=group1]").fancybox(); 
			 var i;
			 for(i=0; i <= $nro; i++){
				 $("#vmapa"+i).fancybox({
					'width' : '60%',
					'height' : '55%',
					'autoScale' : false,
					'transitionIn' : 'none',
					'transitionOut' : 'none',
					'type' : 'iframe' 
				 }); 
			 }
			 
	  }
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	ajax.send("obj="+$obj)
}

function ocultar($obj,$tit)
{
	document.getElementById('datos2'+$obj).style.display = "none";
	document.getElementById('datos'+$obj).style.display = "inline";
	document.getElementById('cambio'+$obj).innerHTML = '&nbsp;<a href="javascript:void();" onclick="desplegar(\''+$obj+'\',\''+$tit+'\'); return false" class="link_lote">'+$tit+'</a>';
}

function TelcaPulsada( e ) {

   if ( window.event != null)                //IE4+
      tecla = window.event.keyCode;
   else if ( e != null )                 //N4+ o W3C compatibles
      tecla = e.which;
   else
      return;
    
   if (tecla == 27) {                     //se pulso escape
      outupMap();
	  outLightbox();
   }
}

document.onkeydown = TelcaPulsada;            //asigna el evento pulsacion tecla a la funcion
if (document.captureEvents){                //netscape es especial: requiere activar la captura del evento
    document.captureEvents(Event.KEYDOWN) ;
}


////////////////////////////////////
//      SECTION COMPANY           //
////////////////////////////////////

function saveCompany($task)
{
   divActualizable = document.getElementById('button');
  // preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmcompany.id.value;
   if(!is_empty(document.frmcompany.texto.value))
   {
   	texto = document.frmcompany.texto.value;
   }else{
   	send = "failure";
	error_form();
   }

   if(send=="next")
   {
	   ajax=newAjax();
	   ajax.open("POST", "../controller/company.cnt.php",true);
	   ajax.onreadystatechange=function() {
		  if(ajax.readyState==1)
		  {
			//preloader.innerHTML = "       Enviando...";        
			//preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
		  }else if (ajax.readyState==4) {		  
				 divActualizable.innerHTML = ajax.responseText
		  }
	   }
	   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	   ajax.send("task="+$task+"&id="+id+"&texto="+texto);
   }
}

function updateCompany($id)
{
   divActualizable = document.getElementById('load');
   //preloader = document.getElementById('preloader');
   ajax=newAjax();
   ajax.open("POST", "../controller/company.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        //preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id);
   hidden_form();
}

////////////////////////////////////
//   SECTION PROPERTY CATEGORY    //
////////////////////////////////////

function savePropertyCategory($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmpropertycategory.id.value;
   pag = document.frmpropertycategory.pag.value;
   if(!is_empty(document.frmpropertycategory.name.value))
   {
   	name = document.frmpropertycategory.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   status = document.frmpropertycategory.status.value;
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/property_category.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&name="+name+"&status="+status+"&pag="+pag);
   }
}

function updatePropertyCategory($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmpropertycategory.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/property_category.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delPropertyCategory($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmpropertycategory.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/property_category.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}


////////////////////////////////////
//  SECTION PROPERTY SUBCATEGORY  //
////////////////////////////////////

function savePropertySubcategory($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   send = "next";
   id = document.frmpropertysubcategory.id.value;
   pag = document.frmpropertysubcategory.pag.value;
   category = document.frmpropertysubcategory.category.value;
   if(!is_empty(document.frmpropertysubcategory.name.value))
   {
   	name = document.frmpropertysubcategory.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   status = document.frmpropertysubcategory.status.value;
   if(send=="next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/property_subcategory.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("task="+$task+"&id="+id+"&category="+category+"&name="+name+"&status="+status+"&pag="+pag);
   }
}

function updatePropertySubcategory($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmpropertysubcategory.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/property_subcategory.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delPropertySubcategory($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmpropertysubcategory.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/property_subcategory.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}

////////////////////////////////////
//      SECTION PROPERTY          //
////////////////////////////////////

function saveProperty($task)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   var send = "next";
   id = document.frmproperty.id.value;
   pag = document.frmproperty.pag.value;
   subcategory = document.frmproperty.subcategory.value;
   
   if(!is_empty(document.frmproperty.name.value))
   {
   	name = document.frmproperty.name.value;
   }else{
   	send = "failure";
	error_form();
   }
   
   if(!is_empty(document.frmproperty.description.value))
   {
   	description = document.frmproperty.description.value;
   }else{
   	send = "failure";
	error_form();
   }
   location = document.frmproperty.location.value;
   price = document.frmproperty.price.value;
   status = document.frmproperty.status.value;
   if(send == "next")
   {
   ajax=newAjax();
   ajax.open("POST", "../controller/property.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        //preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
			 if ( editor )
				return;
		
				var html = document.getElementById( 'description' ).innerHTML;
		
				// Create a new editor inside the <div id="editor">, setting its value to html
				var config = {};
				editor = CKEDITOR.appendTo( 'editor', config, html );
			  }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task="+$task+"&id="+id+"&subcategory="+subcategory+"&name="+name+"&description="+description+"&location="+location+"&price="+price+"&status="+status+"&pag="+pag)
   }
}

function updateProperty($id)
{
   divActualizable = document.getElementById('load');
   preloader = document.getElementById('preloader');
   pag = document.frmproperty.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/property.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        //preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("modify=yes"+"&id="+$id+"&pag="+pag);
   hidden_form();
}

function delProperty($id)
{
   divActualizable = document.getElementById('button');
   preloader = document.getElementById('preloader');
   pag = document.frmproperty.pag.value;
   ajax=newAjax();
   ajax.open("POST", "../controller/property.cnt.php",true);
   ajax.onreadystatechange=function() {
      if(ajax.readyState==1)
	  {
      	//preloader.innerHTML = "       Enviando...";        
        //preloader.style.background = "url('images/ajax-loader.gif') no-repeat 50% 90%"; 
      }else if (ajax.readyState==4) {		  
	         divActualizable.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

   ajax.send("task=delete"+"&id="+$id+"&pag="+pag)
}
