function add_favorite(id)
 {
 	var url = '/apps/api/addfavorites.php?mlsid=' + id;
 	jQuery("#envio-"+id).load(url);
 }
 
 function AddtoHiddenField(field){
	f = document.form;
	c = document.getElementById(field);
	c.value = '';
	cc = f.after;	
	for (var i = 0; i < cc.length; i++) {		
		c.value = listappend(c.value,cc.options[i].value);
	}
	
}

function listappend(thelist, newval, delim){

	if (newval == ""){
		newval = " ";
	}

	if (! delim){
		delim = ",";
	}

	if (thelist == ""){
		newstring = newval;
	}else{
		newstring = thelist + delim + newval;
	}
	return newstring;
}

  
 function MyMoveItem(fromObj, toObj, hiddenfield)
{
  for (var selIndex = fromObj.length - 1; selIndex >= 0; selIndex--)   
   {
      // Is this option selected?
      if (fromObj.options[selIndex].selected)
      {
         // Get the text and value for this option.
         var newText  = fromObj.options[selIndex].text;
         var newValue = fromObj.options[selIndex].value;

         // Create a new option, and add to the other select box.
         var newOption = new Option(newText, newValue)
         toObj[toObj.length] = newOption;

         // Delete the option in the first select box.
         fromObj[selIndex] = null;
      }
   }
   AddtoHiddenField(hiddenfield);
}
function get_tables()	
{
	var table = jQuery("#tables").val();
	 	var url = "listarcolumnas.php?ntable=" + table; 
	 	//var opt = jQuery.load(url);
	 	jQuery("#fields").append().load(url);  	
 	
}

function movetoUP(toObj, hiddenfield)
 {
  		 var selIndex = toObj.selectedIndex;
         
  		 if(selIndex > 0 ){

   		 var TextSel  = toObj.options[selIndex].text;
         var ValueSel = toObj.options[selIndex].value;

         var TextAnt  = toObj.options[selIndex-1].text;
         var ValueAnt = toObj.options[selIndex-1].value;
                       
         var OptionSel = Option(TextSel, ValueSel)
         toObj[selIndex-1] = OptionSel;
	         
         var OptionAnt = Option(TextAnt, ValueAnt)
         toObj[selIndex] = OptionAnt;
        
         toObj.options[selIndex-1].selected = true;
         
         AddtoHiddenField(hiddenfield);
         
         
  
  	 }
     
    
   
}

var valores;
function get_index(toObj)
{
 valores = "";
 
            var obj = toObj.getElementsByTagName('li');
            

     for(var i=0; i<obj.length; i++)
         {
             if(valores == "")
             {
              valores =  obj[i].id;  
             }
             else
             {
              valores +=  ','+obj[i].id;
             }
         }         
}

function movetoDOWN(toObj, hiddenfield)
 {
  		var selIndex = toObj.selectedIndex;
  		
  		if(selIndex < toObj.length) {
    	 
    	 var TextSel  = toObj.options[selIndex].text;
         var ValueSel = toObj.options[selIndex].value;
		 
         var TextAnt  = toObj.options[selIndex+1].text;
         var ValueAnt = toObj.options[selIndex+1].value;
                       
         var OptionSel = new Option(TextSel, ValueSel)
         toObj[selIndex+1] = OptionSel;
	         
         var OptionAnt = new Option(TextAnt, ValueAnt)
         toObj[selIndex] = OptionAnt;
       
         toObj.options[selIndex+1].selected = true;
  		 AddtoHiddenField(hiddenfield);
  		 
  	}
}
var contarlinea = new Array();

   function agregarlinea(div, line, f)
    {
        var f = (f == null) ? "" : f;
        contarlinea[div] = contarlinea[div] == null ? 1 : contarlinea[div] + 1;
        var mySelf = div + "_line_" + contarlinea[div];
        var myNum = contarlinea[div];
        var divTarget = document.getElementById(div);
        var divLine = document.getElementById(line).innerHTML;
        var divTitle = document.getElementById(line).getAttribute('title');
        var newDiv = document.createElement('div');
        newDiv.className = 'row';
        newDiv.setAttribute('id', mySelf);
        divLine = divLine.replace(/mySelf/g, mySelf);
        newDiv.innerHTML = divLine;
        newDiv.innerHTML += "<div class=\"cell\"><img style=\"cursor: pointer;\" src=\"/images/borrar.PNG\" border=\"0\" onclick=\"removerlinea(\'" + mySelf + "\'); " + f + "\"></div>";

        if (divTitle != null && divTarget.hasChildNodes() == false){
            var titles = divTitle.split(",");
            var newTitle = document.createElement('div');
            newTitle.className = 'row';
            for (i = 0; i < titles.length; ++i){
                var titleSize = titles[i].match(/\(\w+\)/,'');
                titleSize = titleSize[0].replace(/[\(\)]/g,'');
                var titleName = titles[i].replace(/\(\w+\)/,'');
                newTitle.innerHTML += "<div class=\"title\" style=\"width: " + titleSize + "px;\">" + titleName + "</div>";
            }
            divTarget.appendChild(newTitle);
            divTarget.setAttribute('cab', '1');
        }
        divTarget.appendChild(newDiv);
    }

    /**
     * Elimina una linea de un formulario
     * @param string div El ID del div que se quiere eliminar
     */
    function removerlinea(div)
    {
        var parentName = div.replace(/_line_\w+/g, '');
        var divParent = document.getElementById(parentName);
        var divTarget = document.getElementById(div);
        var hasTitle = divParent.getAttribute('cab');
        divParent.removeChild(divTarget);
        if (hasTitle != null && divParent.childNodes.length == 1){
            divParent.innerHTML = "";
        }
    }
    
    function delete_element(id){
			var url = "delete_row.php?id="+id;
			jQuery("#id").load(url);
			jQuery("#"+id).slideDown().hide();
		}
		
	function ocultar_div(){
		div = document.getElementById("ocultar");
		div.style.display = 'none';
	} 
	
	function render(item)
	{
		jQuery("" + item).wrap('<div class="tlb"><div class="trb"><div class="ttb"><div class="tbb"><div class="tbl"><div class="tbr"><div class="ttl"><div class="ttr"></div></div></div></div></div></div></div></div>');
	}
	
	function square(item)
	{
		jQuery("" + item).wrap('<div class="left"><div class="right-b"><div class="top"><div class="bottom"><div class="bottom_left"><div class="bottom_right"><div class="top_left"><div class="top_right"></div></div></div></div></div></div></div></div>');
	}
	
	
	function squaremid(item)
	{
		jQuery("" + item).wrap('<div class="mid-l-b"><div class="mid-r-b"><div class="top-c-b"><div class="bottom-c-b"><div class="bottom-l-b"><div class="bottom-r-b"><div class="top-l-b"><div class="top-r-b"></div></div></div></div></div></div></div></div>');
	}
	
	function renderorange(item)
	{
		jQuery("" + item).wrap('<div class="center-left-back"><div class="center-right-back"><div class="top-center-back"><div class="bottom-center-back"><div class="bottom-left-back"><div class="bottom-right-back"><div class="top-left-back"><div class="top-right-back"></div></div></div></div></div></div></div></div>');
	}
	
    function photoshadow(item)
    {
        jQuery("" + item).wrap('<div class="left_center"><div class="right_center"><div class="center_top"><div class="center_bottom"><div class="left_bottom"><div class="right_bottom"><div class="left_top"><div class="right_top"></div></div></div></div></div></div></div></div>');
    }
    
    function hoverdrop(item)
    {
        jQuery("" + item).wrap('<div class="drop-left-center"><div class="drop-right-center"><div class="drop-top-center"><div class="drop-center-bottom"><div class="drop-left-bottom"><div class="drop-right-bottom"><div class="drop-left-top"><div class="drop-right-top"></div></div></div></div></div></div></div></div>');
    }
    
	function blockUI(){
		jQuery.blockUI("<h1 class=\"wait_load\"'><img src=\"/jscripts/images/ajax-loader.gif\" /> Just a moment...</h1>");
	}
	
	function unblockUI(){
		jQuery.unblockUI();	
	}
	
