function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}


function correctPNG()
{
  for(var i=0; i<document.images.length; i++)
  {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
    {
      var imgID = (img.id) ? "id='" + img.id + "' " : ""
      var imgClass = (img.className) ? "class='" + img.className + "' " : ""
      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
      var imgStyle = "display:inline-block;" + img.style.cssText
      if (img.align == "left") imgStyle = "float:left;" + imgStyle
      if (img.align == "right") imgStyle = "float:right;" + imgStyle
      if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
      var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
      img.outerHTML = strNewHTML
      i = i-1
    }
  }
}
//window.attachEvent("onload", correctPNG);



function cambiarTipoDir(form,dato_pais,dato_man_dir_completa,man_dir,
						lista_regiones,lista_provincias,lista_poblaciones,
						div_man_reg,div_man_provin,div_man_pob,
						td_txt_dir_completa,td_dir_completa,
						td_txt_region,td_regiones,
						td_txt_provincia,td_provincias,
						td_txt_poblacion,td_poblaciones,
						td_direccion,td_txt_direccion,
						td_cp,td_txt_cp)
{
	
	
	if(document.getElementById(man_dir).checked == true)
	{
		jQuery('#'+lista_provincias).hide();
		jQuery('#'+lista_poblaciones).hide();
		
		var cod_pais = document.forms[form].elements[dato_pais].value;
		var man_dir_completa = document.forms[form].elements[dato_man_dir_completa].value;
		
		if(cod_pais == '724') //ESPAÑA
		{
			jQuery('#'+td_txt_dir_completa).hide();  jQuery('#'+td_dir_completa).hide();

			jQuery('#'+lista_regiones).show();	jQuery('#'+div_man_reg).hide();
												jQuery('#'+div_man_provin).show();
												jQuery('#'+div_man_pob).show();

			jQuery('#'+td_txt_region).show();		jQuery('#'+td_regiones).show();
			jQuery('#'+td_txt_provincia).show();	jQuery('#'+td_provincias).show();
			jQuery('#'+td_txt_poblacion).show();	jQuery('#'+td_poblaciones).show();
			
			jQuery('#'+td_direccion).show();		jQuery('#'+td_txt_direccion).show();
			
			try{			
			jQuery('#'+td_cp).show();		jQuery('#'+td_txt_cp).show();
			}catch (e){}
			
		}
		else
		{
			if(man_dir_completa == '')
			{
				jQuery('#'+lista_regiones).hide();		jQuery('#'+div_man_reg).show();	
				jQuery('#'+lista_provincias).hide();	jQuery('#'+div_man_provin).show();	
				jQuery('#'+lista_poblaciones).hide();	jQuery('#'+div_man_pob).show();	
				
				jQuery('#'+td_txt_region).show();			jQuery('#'+td_regiones).show();	
				jQuery('#'+td_txt_provincia).show();		jQuery('#'+td_provincias).show();	
				jQuery('#'+td_txt_poblacion).show();		jQuery('#'+td_poblaciones).show();	
				
				jQuery('#'+td_direccion).show();		jQuery('#'+td_txt_direccion).show();	

				try{
				jQuery('#'+td_cp).show();		jQuery('#'+td_txt_cp).show();	
				}catch (e){}

				jQuery('#'+td_txt_dir_completa).hide();	jQuery('#'+td_dir_completa).hide();
				
			}
			else
			{
				jQuery('#'+td_txt_region).hide();		jQuery('#'+td_regiones).hide();	
				jQuery('#'+td_txt_provincia).hide();	jQuery('#'+td_provincias).hide();	
				jQuery('#'+td_txt_poblacion).hide();	jQuery('#'+td_poblaciones).hide();	
				
				jQuery('#'+td_direccion).hide();	jQuery('#'+td_txt_direccion).hide();
				try{
				jQuery('#'+td_cp).hide();	jQuery('#'+td_txt_cp).hide();
				}catch (e){}

				jQuery('#'+td_txt_dir_completa).show();	jQuery('#'+td_dir_completa).show();
			}
					
			
		}
	}
	else
	{
		jQuery('#'+td_txt_dir_completa).hide();	 jQuery('#'+td_dir_completa).hide();		
		
		jQuery('#'+lista_regiones).show();		jQuery('#'+div_man_reg).hide();	
		jQuery('#'+lista_provincias).show();	jQuery('#'+div_man_provin).hide();	
		jQuery('#'+lista_poblaciones).show();	jQuery('#'+div_man_pob).hide();	
		
		jQuery('#'+td_txt_region).show();	jQuery('#'+td_regiones).show();
		jQuery('#'+td_txt_provincia).show();	jQuery('#'+td_provincias).show();
		jQuery('#'+td_txt_poblacion).show();	jQuery('#'+td_poblaciones).show();

		jQuery('#'+td_direccion).show();	jQuery('#'+td_txt_direccion).show();

		try{
		jQuery('#'+td_cp).show();	jQuery('#'+td_txt_cp).show();
		}catch (e){}
	}

}




function copiarSelect(campo_ori,campo_des)
{
	var nav_fire = navigator.userAgent.indexOf('Firefox');
	var nav_moz = navigator.userAgent.indexOf('Gecko');
	

	//borra lo que haya en el listado
	while(document.getElementById(campo_des).options.length)
	{				
		if(nav_fire == -1 && nav_moz == -1) // no es firefox
			document.getElementById(campo_des).options.remove(0); 
		else
			document.getElementById(campo_des).remove(0); 
	}
	
	for(i=0; i < document.getElementById(campo_ori).options.length; i++)
	{				
		//alert(i);
		
		if(nav_fire == -1 && nav_moz == -1) // no es firefox
		{
			var oOption = document.createElement("OPTION");
			document.getElementById(campo_des).options.add(oOption);
			oOption.innerText = document.getElementById(campo_ori).options(i).text;
			oOption.value = document.getElementById(campo_ori).options(i).value;
		}
		else
		{
			var select = document.getElementById(campo_des);
			select.options[select.options.length] = new Option(document.getElementById(campo_ori).options[i].text, document.getElementById(campo_ori).options[i].value);
		}
	}
	document.getElementById(campo_des).disabled = false;	
	document.getElementById(campo_des).selectedIndex = document.getElementById(campo_ori).selectedIndex;
	//////

	
	
	//alert('Datos copiados');
}


function loadHtmlArea(url_virtual)
{
	_editor_url = "/Editor/"; 

	//alert('ggg');
	_url_virtual = url_virtual;

	_editor_field = "";
	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
	if (win_ie_ver >= 5.5) 
	{
		document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
		document.write(' language="Javascript1.2"></scr' + 'ipt>');        
	} 
	else 
	{ 
		document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); 
	}
	//alert(_editor_url+ 'editor.js');
}

function high(which2)
   {
   theobject=which2;
   highlighting=setInterval("highlightit(theobject)",90);
   }
   function low(which2)
   {
   clearInterval(highlighting);
   which2.filters.alpha.opacity=90;
   }
   function highlightit(cur2)
   {
   if(cur2.filters.alpha.opacity<100)
   cur2.filters.alpha.opacity+=12
   else if(window.highlighting)
   clearInterval(highlighting)
   }
function cambio0(id, colorF) {
         id.bgColor = colorF;
	}

function cambio(id, clase) {
         id.className = clase;
	}

function cambioClickColorCerrada(id) 
{
   if(document.getElementById(id).bgColor == '#ff7a7a')
	{
		document.getElementById(id).bgColor = '#dedede';
	}
	else
	{
		document.getElementById(id).bgColor = '#ff7a7a';
	}		
	
}

function cambioClickColor(id) 
{
    if(document.getElementById(id).bgColor != '#ff7a7a')
	{
		if(document.getElementById(id).bgColor == '#ff9e3b')
		{
			document.getElementById(id).bgColor = '#dedede';
		}
		else
		{
			document.getElementById(id).bgColor = '#ff9e3b';
		}		
	}
}

function cambioOnColor(id) 
{
	if(document.getElementById(id).bgColor != '#ff7a7a')
	{
		if(document.getElementById(id).bgColor != '#ff9e3b')
		{
			document.getElementById(id).bgColor = '#ffff87';
		}
	}	 
}
function cambioOutColor(id) 
{
    if(document.getElementById(id).bgColor != '#ff7a7a')
	{     
		if(document.getElementById(id).bgColor != '#ff9e3b')
		{
			document.getElementById(id).bgColor = '#dedede';
		}
	}
}

function cambioDownColor(id) 
{
	if(document.getElementById(id).bgColor != '#ff7a7a')
	{         
		if(document.getElementById(id).bgColor != '#ff9e3b')
		{
			document.getElementById(id).bgColor = '#dedede';
		}	
	}
}

function cambioI(id, colorF) {
         document.getElementById(id).bgColor = colorF;
	}

function cambioC(id, clase) {
         document.getElementById(id).className = clase;
	}


function cambioTipoPrecio(the_form, num_rangos, tipoPrecio)
{
    if(tipoPrecio == 0) //manual
	{
		var clase_pvp = 'selec';
		var read_pvp = false;
		var clase_porc = 'read';
		var read_porc = true;
	}
	else // porcentaje
	{
		var clase_pvp = 'read';
		var read_pvp = true;
		var clase_porc = 'selec';	
		var read_porc = false;
	}
	
	for (var i = 1; i <= num_rangos; i++) 
	{
		//alert('valores_pvp['+ i +'][pvp_t0]');
		document.getElementById('valores_pvp['+ i +'][pvp_t0]').className = clase_pvp;  
		document.getElementById('valores_pvp['+ i +'][pvp_t0]').readOnly = read_pvp;
		document.getElementById('valores_pvp['+ i +'][porc_t0]').className = clase_porc;  
		document.getElementById('valores_pvp['+ i +'][porc_t0]').readOnly = read_porc;
		
		document.getElementById('valores_pvp['+ i +'][pvp_t1]').className = clase_pvp;  
		document.getElementById('valores_pvp['+ i +'][pvp_t1]').readOnly = read_pvp;
		document.getElementById('valores_pvp['+ i +'][porc_t1]').className = clase_porc;  
		document.getElementById('valores_pvp['+ i +'][porc_t1]').readOnly = read_porc;
		
		document.getElementById('valores_pvp['+ i +'][pvp_t2]').className = clase_pvp;  
		document.getElementById('valores_pvp['+ i +'][pvp_t2]').readOnly = read_pvp;
		document.getElementById('valores_pvp['+ i +'][porc_t2]').className = clase_porc;  
		document.getElementById('valores_pvp['+ i +'][porc_t2]').readOnly = read_porc;
		
		
    } // end for
	document.getElementById('nuevo_rango[pvp_t0]').className = clase_pvp;  
	document.getElementById('nuevo_rango[pvp_t0]').readOnly = read_pvp;
	document.getElementById('nuevo_rango[porc_t0]').className = clase_porc;  
	document.getElementById('nuevo_rango[porc_t0]').readOnly = read_porc;
	
	document.getElementById('nuevo_rango[pvp_t1]').className = clase_pvp;  
	document.getElementById('nuevo_rango[pvp_t1]').readOnly = read_pvp;
	document.getElementById('nuevo_rango[porc_t1]').className = clase_porc;  
	document.getElementById('nuevo_rango[porc_t1]').readOnly = read_porc;
	
	document.getElementById('nuevo_rango[pvp_t2]').className = clase_pvp;  
	document.getElementById('nuevo_rango[pvp_t2]').readOnly = read_pvp;
	document.getElementById('nuevo_rango[porc_t2]').className = clase_porc;  
	document.getElementById('nuevo_rango[porc_t2]').readOnly = read_porc;
	

    return true;
} // end of the 'setCheckboxes()' function


function cambiar_plantilla(img,archivo) {
    // changes the current picture
    document.getElementById(img).src= "./templates/{$codigoUni}/template1/imagenes/" + archivo;
  }
  
 function cambiarAvatar(archivo) {
    // changes the current picture
    document.avatar.src= "./imagenes/avatares/" + archivo;
  }
  function cambiarIdioma(archivo) {
    // changes the current picture
    document.img_idioma.src= "../globalPFC/imagenes/idiomas/flag-" + archivo + ".png";
  }

function viewHide(id) 
{
    var targetElement = document.getElementById(id);
    if (targetElement.style.display == "none") {
		targetElement.style.display = "";
    } else {
		targetElement.style.display = "none";
    }
}

function loginTipo(tipo) 
{
    if(tipo == 'empleados')
	{
		document.getElementById('div_clientes').style.display = "none";
		document.form_login.appC.value='rrhh';
		document.form_login.clase.value='Empleados';
		document.form_login.metodo.value='loginEmpleado';
		document.getElementById('div_nuevo').style.display = "none";
	}
	else
	{
		document.getElementById('div_clientes').style.display = "";
		document.form_login.appC.value='ventas';
		document.form_login.clase.value='Clientes';
		document.form_login.metodo.value='loginCliente';
		document.getElementById('div_nuevo').style.display = "";
	}
    
}

function tipoPago(id)
{
	switch (id)
	{
		case "pre":
			document.getElementById("dias_pre").style.display = "";
			document.getElementById("dias_cre").style.display = "none";
			document.getElementById("dias_rec").style.display = "none";	
			
			document.getElementById("dias").style.display = "none";			
		break;
	
		case "cre":
			document.getElementById("dias_pre").style.display = "none";
			document.getElementById("dias_cre").style.display = "";
			document.getElementById("dias_rec").style.display = "none";	
			
			document.getElementById("dias").style.display = "";	
		break;

		case "rec":
			document.getElementById("dias_pre").style.display = "none";
			document.getElementById("dias_cre").style.display = "none";
			document.getElementById("dias_rec").style.display = "";	
			
			document.getElementById("dias").style.display = "";	
		break;


	}

}

function formaPago(id)
{
	
	if (id == "ccc") {
		document.getElementById("ccc0").readOnly = false;
		document.getElementById("ccc1").readOnly = false;
		document.getElementById("ccc2").readOnly = false;
		document.getElementById("ccc3").readOnly = false;

		document.getElementById("ccc0").Class = "read";
		document.getElementById("ccc1").Class = "read";
		document.getElementById("ccc2").Class = "read";
		document.getElementById("ccc3").Class = "read";

		document.getElementById("paypal").readOnly = true;
    } 
	else 
	{
		document.getElementById("ccc0").readOnly = true;
		document.getElementById("ccc1").readOnly = true;
		document.getElementById("ccc2").readOnly = true;
		document.getElementById("ccc3").readOnly = true;
		document.getElementById("paypal").readOnly = false;
   }
}

function cambiarTipoZona(zona)
{
	if(zona == 'segun_peso_zona')
	{
		//document.form_crearzonas.hasta_neto.disabled = true;
		document.getElementById('div_precio_zona').style.display = "none";

		//document.form_crearzonas.hasta_kg.disabled = false;
		document.getElementById('div_peso_zona').style.display = "";
	}
	else
	{
		//document.form_crearzonas.hasta_neto.disabled = true;
		document.getElementById('div_peso_zona').style.display = "none";

		//document.form_crearzonas.hasta_kg.disabled = false;
		document.getElementById('div_precio_zona').style.display = "";	
	}
}

function botonRegistro() 
{
   if (document.form_cliente.acepto.value == "on") 
	{
		//alert('acepto');
		document.form_cliente.b_reg.disabled = false;
		document.form_cliente.acepto.value='';
		
    } 
	else 
	{
		//alert('no acepto');
		document.form_cliente.b_reg.disabled = true;
		document.form_cliente.acepto.value='on';
    }
}

function viewHideMenu(id,id_img) 
{
    var targetId, srcElement, targetElement;
    var targetElement = document.getElementById(id);
	var targetElementIMG = document.getElementById(id_img);

    if (targetElement.style.display == "none") {
		targetElement.style.display = "";
		targetElementIMG.src="imagenes/ocultar.gif";
    } else {
		targetElement.style.display = "none";
		targetElementIMG.src="imagenes/mostrar.gif";
    }
}

function setCookie(cookieName,cookieValue) {

  document.cookie = cookieName+"="+escape(cookieValue);
  
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

if (ReadCookie('MenuOculto') != 'yes')  
{ 
 setCookie('MenuOculto','yes'); 

} 

function advertencia_borrado(id_formulario){ 
	var targetElement = document.getElementById(id_formulario);;

    if (confirm('¿Estás seguro que deseas borrar esta página?')){ 
       targetElement.accion.value= 'borrar';
	   targetElement.submit() 
    } 
} 

function advertencia(id_formulario){ 
	var targetElement = document.getElementById(id_formulario);;

    if (confirm('¿Estás seguro que deseas borrar esta universidad?')){ 
       targetElement.submit() 
    } 
}

function miaccion(param)
{ 
       document.edicion_form.accion.value= param;
}

function miaccion_modulo(param1,param2,param3)
{ 
    if (confirm('¿Estás seguro que deseas deasignar este módulo?'))
		{ 
     document.modulo_asignados.accion.value= param1;
	document.modulo_asignados.id_asignatura.value= param2;
	document.modulo_asignados.id_modulo.value= param3;
	document.modulo_asignados.submit();
		}
}
function miaccion_plantilla(param1,param2)
{ 
   
	//var targetElement = document.getElementById('sonido');
	//targetElement.src= 'sonidos/guardandoelsistema.wav';
	if (confirm('¿Estás seguro que deseas borrar esta plantilla?'))
		{ 
    document.plantillas_form.id_plantilla.value= param1;
	document.plantillas_form.archivo.value= param2;
	document.plantillas_form.submit();
		}
}





function verModulo(url)
{
	window.open(url,"not","resizable=yes,location=no,status=no,scrollbars=yes,width=800,height=600")
	
}

function abrirPopUp(url,ventana,ancho,alto,resiz,stat,scroll) 
{
	props = 'width=' + ancho + ',height=' + alto + ',top=5,left=30,resizable=' + resiz + ',scrollbars=' + scroll + ',status=' + stat +'location=yes';
	window.open(url,ventana,props);
}


function abrirDialogo(url,ventana,ancho,alto,resiz,stat,scroll) 
{
	props = 'dialogWidth: '+ ancho + 'px; dialogHeight: ' + alto + 'px; edge: Raised; center: Yes;	help: No; resizable: ' + resiz + '; status: ' + stat + '; scroll: ' + scroll;
	showModalDialog(url, props, ventana); 
}

//var capaX;
//var msgX;
//var masX;
//var masY;
//var xcoord=0;

function mostrarTip(capa){
	// colocamos la capa donde hemos hecho click con el ratón
	//alert(this.capaX);
	
	if( document.captureEvents ) {
    //myReference was obtained as in the section on DHTML
    //non IE
    if( Event.CLICK ) {
        //NS 4, NS 6, Mozilla 0.9.x
        document.captureEvents( Event.CLICK );
    }
}
document.onclick = capturaRaton;
	

 alert(this.xcoord);
	/**
    * para Nestcape 4x abrimos el documento de la capa y escribimos la cadena de contenido
    */
    if(document.layers)
    {
		document.capa.document.write(unescape(this.msgX));
		document.capa.document.close();
		document.capa.visibility="visible"
    }
    /**
    * para Internet Explorer y Nestcape 6x escribimos en contenido del tip directamente
    */
    if(document.all)
    {
		document.all(capa).style.visibility="visible"
    }
    if(document.getElementById)
    {
		document.getElementById(this.capaX).style.visibility="visible"
    }
	return false;
}

function capturaRaton(e)
{

  if( !e ) {
    if( window.event ) {
      //DOM
      e = window.event;
    } else {
      //TOTAL FAILURE, WE HAVE NO WAY OF REFERENCING THE EVENT
      return;
    }
  }
  if( typeof( e.pageX ) == 'number' ) {
    //NS 4, NS 6+, Mozilla 0.9+
    var xcoord = e.pageX;
    var ycoord = e.pageY;
  } else {
    if( typeof( e.clientX ) == 'number' ) {
      //IE, Opera, NS 6+, Mozilla 0.9+
      //except that NS 6+ and Mozilla 0.9+ did pageX ...
      var xcoord = e.clientX;
      var ycoord = e.clientY;
      if( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
        ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
        window.navigator.vendor == 'KDE' ) ) {
        if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
          //IE 4, 5 & 6 (in non-standards compliant mode)
          xcoord += document.body.scrollLeft;
          ycoord += document.body.scrollTop;
        } else if( document.documentElement &&
          ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
          //IE 6 (in standards compliant mode)
          xcoord += document.documentElement.scrollLeft;
          ycoord += document.documentElement.scrollTop;
        }
      }
    } else {
      //TOTAL FAILURE, WE HAVE NO WAY OF OBTAINING THE
      //MOUSE COORDINATES
      return;
    }
  }
  this.xcoord=xcoord;
  alert(this.xcoord);
  window.alert('Mouse coordinates are ('+xcoord+','+ycoord+')');
}



function tip(capa,msg,masX,masY)
{
	this.capaX = capa;
	this.msgX = msg;
	this.masX = masX;
	this.masY = masY;

	if(document.all)
	{
		if(document.all(capa).style.visibility =="hidden")
			mostrarTip(capa);
		else
			document.all(capa).style.visibility = "hidden";
	}
	else if(document.layers)
	{
		if(document.layers[capa].visibility=="hide")
			mostrarTip(capa);
		else
			document.layers[capa].visibility="hide";
	}
	else if(document.getElementById)
	{
		if(document.getElementById(capa).style.visibility=="hidden")
			mostrarTip(capa);
		else
			document.getElementById(capa).style.visibility="hidden";
	}
}



function serialize( mixed_value ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // +   improved by: Dino
    // +   bugfixed by: Andrej Pavlovic
    // +   bugfixed by: Garagoth
    // +      input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html)
    // +   bugfixed by: Russell Walker (http://www.nbill.co.uk/)
    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
 
    var _getType = function( inp ) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += serialize(okey) +
                        serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
        case "undefined": // Fall-through
        default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
            val = "N";
            break;
    }
    if (type != "object" && type != "array") {
        val += ";";
    }
    return val;
}


jQuery().ready(function ()
{

	jQuery(".b_comprar a img").click(function() {
		
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];

		var productX 		= jQuery("#productImageWrapID_" + productIDVal).offset().left;
		var productY 		= jQuery("#productImageWrapID_" + productIDVal).offset().top;

		if( jQuery("#productID_" + productIDVal).length > 0){
			var basketX 		= jQuery("#productID_" + productIDVal).offset().left;
			var basketY 		= jQuery("#productID_" + productIDVal).offset().top;
		} else {
			var basketX 		= jQuery("#basketTitleWrap").offset().left;
			var basketY 		= jQuery("#basketTitleWrap").offset().top;
		}

		var gotoX 			= basketX - productX;
		var gotoY 			= basketY - productY;

		var newImageWidth 	= 0;//jQuery("#productImageWrapID_" + productIDVal).width() / 3;
		var newImageHeight	= 0;//jQuery("#productImageWrapID_" + productIDVal).height() / 3;

		jQuery("#productImageWrapID_" + productIDVal + " img")
		.clone()
		.prependTo("#productImageWrapID_" + productIDVal)
		.css({'position' : 'absolute','z-index' : '10'})
		.animate({marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200);
		
		//, function() {

			jQuery("#procesando_cesta").show();

			jQuery.ajax({
				type: "POST",
				url: "controller.ath",
				data: { id_producto: productIDVal, async: "async", cantidad: "1", appC: "ventas", clase: "Cesta", metodo: "addProducto"}, 
				success: function(theResponse) {

					jQuery("#basketItemsWrap").html(theResponse);
					jQuery("#procesando_cesta").hide();
				
				}
			});  

		//});

	});

	jQuery(".botonera_comprar img").click(function() {
		
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];

		var productX 		= jQuery("#productImageWrapID_" + productIDVal).offset().left;
		var productY 		= jQuery("#productImageWrapID_" + productIDVal).offset().top;

		if( jQuery("#productID_" + productIDVal).length > 0){
			var basketX 		= jQuery("#productID_" + productIDVal).offset().left;
			var basketY 		= jQuery("#productID_" + productIDVal).offset().top;
		} else {
			var basketX 		= jQuery("#basketTitleWrap").offset().left;
			var basketY 		= jQuery("#basketTitleWrap").offset().top;
		}

		var gotoX 			= basketX - productX;
		var gotoY 			= basketY - productY;

		var newImageWidth 	= 0;//jQuery("#productImageWrapID_" + productIDVal).width() / 3;
		var newImageHeight	= 0;//jQuery("#productImageWrapID_" + productIDVal).height() / 3;

		jQuery("#productImageWrapID_" + productIDVal + " img")
		.clone()
		.prependTo("#productImageWrapID_" + productIDVal)
		.css({'position' : 'absolute','z-index' : '10'})
		.animate({marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200);
		
		//, function() {

			jQuery("#procesando_cesta").show();

			//alert(jQuery("#f_comprar").serialize());

			jQuery.ajax({
				type: "POST",
				url: "controller.ath",
				//data: { id_producto: productIDVal, async: "async", cantidad: "1", appC: "ventas", clase: "Cesta", metodo: "addProducto"}, 
				data: jQuery("#f_comprar").serialize(), 

				success: function(theResponse) {

					jQuery("#basketItemsWrap").html(theResponse);
					jQuery("#procesando_cesta").hide();
				
				}
			});  

		//});

	});
});


function mostrarCapa(capa)
{
	jQuery('#'+capa).show();
}			

function ocultarCapa(capa)
{
	jQuery('#'+capa).hide();
}			
