//function main_contenido_load(url){
 //	$.historyLoad(url.substring(url.indexOf('#')+1));

//}

//function main_contenido_load_aux(url){
function main_contenido_load(url){
	if(url.substring(url.indexOf('#')+1)=='' || url.indexOf('..')!=-1)
		return;
		$('#detalle_producto').slideUp('fast');
		cargar_url_id(url.substring(url.indexOf('#')+1),'main_contenido');
		if(url.indexOf('id_producto')==-1)
			cambiar_publicidad_head();
}
//ex main_slide_load

function cargar_url_id(url,id){
		$('#'+id).load(url,function(){$('#main_load').fadeOut('normal');abrir(id);});
		$('#main_load').remove();
		$('#main_wrapper').append('<div id="main_load"></div>');
		$('#main_load').fadeIn('normal');
	return false;
}

function cargar_url_id2(url,id){
		 $('#'+id).load(url);
	return false;
}

function cargar_url_id_efecto(url,id){
		$('#'+id).slideUp('fast',function(){loadContent(url,id);});
		$('#main_load').remove();
		$('#main_wrapper').append('<div id="main_load"></div>');
		$('#main_load').fadeIn('normal');
	return false;
}

function main_contenido_load_accion(url,url2,id){
 //	cargar_url_id2('include/breadcrumbing.php?url='+url.substring(url.indexOf('#')+1),'breadcrumbing');
//	cargar_url_id2('include/funciones.php?url='+url.substring(url.indexOf('#')+1),'funciones');
	$('#main_contenido').load(url.substring(url.indexOf('#')+1)+'.php',function(){cargar_url_id2(url2,id);});
}

function empezar_carga(target){
		$('#main_upload').remove();
		$('#main_wrapper').append('<div id="main_upload" align="center"><form action="include/cancel.php" target="'+target+'" name="form_upload" id="form_upload"><a onclick="document.form_upload.submit();window.terminar_carga();"><img src="plantilla/upload.gif"><br><span style="font-size:15px;">Cancelar</span></a></form> </div>');
		$('#main_upload').fadeIn('normal');
}

function terminar_carga(){
	$('#main_upload').fadeOut('normal');
}

function loadContent(url,id) {
		$('#'+id).load(url,function(){showNewContent(id);})
}
function showNewContent(id) {
			$('#'+id).slideDown('normal',hideLoader);
}
function hideLoader() {
			$('#main_load').fadeOut('normal');
}



function loadurl_sub(url){
	var pagecnx = createXMLHttpRequest();
	pagecnx.open('GET', url, true);
	pagecnx.send(null);
}



function loadurlkey(e,url,id){
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==13)
		loadurl(url,id);
}

function createXMLHttpRequest() {
	var xmlHttp=null;
	if (window.ActiveXObject)
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
			xmlHttp = new XMLHttpRequest();
	return xmlHttp;
}

function abrir_cerrar(id){
	if(document.getElementById(id).style.display=='none')
		$('#'+id).slideDown('fast');
	else
		$('#'+id).slideUp('fast');
}

function abrir_cerrar_tabla(id,largo){
 if(document.getElementById(id).style.display=='none'){
     $('#'+id).slideDown('fast');
     ordenar_tabla(id,largo);
 } else
     $('#'+id).slideUp('fast');
}

function cerrar(id){
	if(document.getElementById(id).style.display!='none')
		$('#'+id).slideUp('fast');
}

function abrir(id){
	if(document.getElementById(id).style.display =='none')
		$('#'+id).slideDown('fast');
}

function getNameValues(name){
    var temp=document.getElementsByName(name);
    j=0;
    for(i=0;i<temp.length;i++)
        if(temp[i].checked)
            j++
    var valores=new Array(j);
    for(i=0;i<temp.length;i++)
        if(temp[i].checked)
            valores[i]=temp[i].value;
    return valores;
}

function getIdValue(id){
    if(document.getElementById(id)!=undefined)
        return document.getElementById(id).value;
    else
    	return false;
}

function getIdHtml(id){
    if(document.getElementById(id)!=undefined)
        return document.getElementById(id).innerHTML;
    else
    	return false;
}

function getRadioButtonSelectedChecked(ctrl){
var temp=document.getElementsByName(ctrl);
    for(i=0;i<temp.length;i++)
        if(temp[i].checked) return true;
	return false;
}

function getRadioButtonSelectedValue(ctrl){
var temp=document.getElementsByName(ctrl);
    for(i=0;i<temp.length;i++)
        if(temp[i].checked) return temp[i].value;
}

function MarcarCheckBox(name){
    var temp=document.getElementsByName(name);
        for(i=0;i<temp.length;i++)
            temp[i].checked=1
}

function DesmarcarCheckBox(name){
    var temp=document.getElementsByName(name);
        for(i=0;i<temp.length;i++)
            temp[i].checked=0
}

function cargar_url_dragdrop(url){
	$('#main_dragdrop_aux').load(url,function(){$('#main_dragdrop').fadeIn('normal');$('#main_dragdrop_aux').fadeIn('normal');});
}

function ordenar_tabla(id,h){
	if(document.getElementById(id)==undefined) return;
	//height maximo
	if(h!=undefined){
		tableEl=document.getElementById(id);
		tableEl.style.width='97%';

	    if(document.all && document.getElementById && !window.opera){ //IE
			containerEl = tableEl.parentNode.insertBefore(document.createElement('div'), this.tableEl);
			containerEl.appendChild(tableEl);
			containerEl.style.height = h + 'px';
			containerEl.style.width = '100%';
			containerEl.style.overflow= 'auto';
		}
		if (!document.all && document.getElementById && !window.opera){//FF
			scrollWidth=17;
			thead = this.tableEl.getElementsByTagName('thead');
			thead = (thead[0]) ? thead[0] : null;
			tfoot = this.tableEl.getElementsByTagName('tfoot');
			tfoot = (tfoot[0]) ? tfoot[0] : null;
			tbody = this.tableEl.getElementsByTagName('tbody');
			tbody = (tbody[0]) ? tbody[0] : null;

			headHeight = (thead) ? thead.clientHeight : 0;
			headFoot = (tfoot) ? tfoot.clientHeight : 0;
			bodyHeight = tbody.clientHeight;

			var trs = tbody.getElementsByTagName('tr');
			tbody.style.overflow = '-moz-scrollbars-vertical';
			for (x=0; x<trs.length; x++) {
				var tds = trs[x].getElementsByTagName('td');
				tds[tds.length-1].style.paddingRight += this.scrollWidth + 'px';
			}
			cellSpacing = (tableEl.offsetHeight - (tbody.clientHeight + headHeight)) / 4;
			tbody.style.height = (h - (headHeight + cellSpacing * 2) - (headFoot+ cellSpacing * 2)) + 'px';
        }
    }

	//odd
	tbody=document.getElementById(id).getElementsByTagName('tbody');
	tbody = (tbody[0]) ? tbody[0] : null;
	var trs = tbody.getElementsByTagName('tr');
	for (x=0; x<trs.length; x++) {
		if(x%2==0)
		trs[x].className ="odd";
	}

	//ordenar tabla
	$('#'+id).tablesorter();

}

function ordenar_tabla_cookie(id,h){
	if(document.getElementById(id)==undefined) return;
	//height maximo
	if(h!=undefined){
		tableEl=document.getElementById(id);
		tableEl.style.width='97%';

	    if(document.all && document.getElementById && !window.opera){ //IE
			containerEl = tableEl.parentNode.insertBefore(document.createElement('div'), this.tableEl);
			containerEl.appendChild(tableEl);
			containerEl.style.height = h + 'px';
			containerEl.style.width = '100%';
			containerEl.style.overflow= 'auto';
		}
		if (!document.all && document.getElementById && !window.opera){//FF
			scrollWidth=17;
			thead = this.tableEl.getElementsByTagName('thead');
			thead = (thead[0]) ? thead[0] : null;
			tfoot = this.tableEl.getElementsByTagName('tfoot');
			tfoot = (tfoot[0]) ? tfoot[0] : null;
			tbody = this.tableEl.getElementsByTagName('tbody');
			tbody = (tbody[0]) ? tbody[0] : null;

			headHeight = (thead) ? thead.clientHeight : 0;
			headFoot = (tfoot) ? tfoot.clientHeight : 0;
			bodyHeight = tbody.clientHeight;

			var trs = tbody.getElementsByTagName('tr');
			tbody.style.overflow = '-moz-scrollbars-vertical';
			for (x=0; x<trs.length; x++) {
				var tds = trs[x].getElementsByTagName('td');
				tds[tds.length-1].style.paddingRight += this.scrollWidth + 'px';
			}
			cellSpacing = (tableEl.offsetHeight - (tbody.clientHeight + headHeight)) / 4;
			tbody.style.height = (h - (headHeight + cellSpacing * 2) - (headFoot+ cellSpacing * 2)) + 'px';
        }
    }

	//odd
	tbody=document.getElementById(id).getElementsByTagName('tbody');
	tbody = (tbody[0]) ? tbody[0] : null;
	var trs = tbody.getElementsByTagName('tr');
	for (x=0; x<trs.length; x++) {
		if(x%2==0)
		trs[x].className ="odd";
	}

    var tipo_orden=0;
    var columna=0;
     if($.cookie(id) != null)
     {

           columna=$.cookie(id).substring($.cookie(id).indexOf("-")+1);
           tipo_orden=$.cookie(id).substring(0,$.cookie(id).indexOf("-")); ;
     }
	//ordenar tabla
	$('#'+id).tablesorter({
        // sort on the first column and third column, order asc
        sortList: [[columna,tipo_orden]]
    });

}

function copiar_contenido(id_desde,id_para){
    $('#'+id_para).html($('#'+id_desde).html());
}

function confirmar_url_dragdrop(mensaje,url){
    if(confirm(mensaje))
        cargar_url_dragdrop(url);

}

function guardar_config_tabla(nombre_cookie, campo)
{
   if($.cookie(nombre_cookie) != null && $.cookie(nombre_cookie)=='0-'+campo)
   {
        $.cookie(nombre_cookie, '1-'+campo);
   }
   else
   {
     $.cookie(nombre_cookie, '0-'+campo);
   }
}

function cargar_chart(id,url,w,h){
    swfobject.embedSWF("include/open-flash-chart/open-flash-chart.swf",id, w, h, "9.0.0","expressInstall.swf",{"data-file":url});

}

/// carga informacion en una capa dependiendo del valor de select
/// @var url es la ruta de archivo que se cargara en la capa
/// @var div es el nombre de la capa donde se cargara la informacion
/// @var elmnt es el nombre de select
/// @var elmntValue es el valor de select que condiciona si es mostrada la informacion o no
/// @return void,null
function cargar_url_id_limpiar(url,div,elmnt, elmntValue)
{
    if(getIdValue(elmnt) != elmntValue )
    {
		cargar_url_id(url,div);
    }
     else
     {
       document.getElementById(div).innerHTML = '';
     }
}

