var anuncio = "Brotimex";
var velocidad = 0;
var currentCell = null;

function inicioWindowStatus() 
{
	window.status = anuncio;
	setTimeout("inicioWindowStatus()",velocidad);
}
inicioWindowStatus();

function GetIFrame(paramiFrame,paramPage)
{
	paramiFrame.location.href = paramPage;
}

function DoPage(pPage)
{
	document.location.href = pPage;
}

function DoAlertCarrito(pDiv, pHTML)
{
	window.setTimeout('DoAlertCarritoEfecto(\''+pDiv+'\',\''+pHTML+'\')',2500);
}
function DoAlertCarritoEfecto(pDiv, pHTML)
{
	document.getElementById(pDiv).innerHTML = pHTML;
	document.getElementById(pDiv).style.backgroundColor = "#CC0000";
	DoEffectCarrito(pDiv);
	window.setTimeout('document.getElementById(\''+pDiv+'\').style.backgroundColor = \'\'',2750);
}

function DoEffectCarrito(pDiv)
{
	Effect.Pulsate(pDiv, {duration:3});
}

function getRefByTagName( tag, scope ) {
  scope = scope || document;

  if( scope.getElementsByTagName ) {
    return scope.getElementsByTagName( tag );
  } else if( scope.all && scope.all.tags ) {
    return scope.all.tags( tag );
  }
  return null;
}

function getRefById( id ) {
  if( document.getElementById ) {
    return document.getElementById( id );
  } else if( document.all ) {
    return document.all[ id ];
  }
  return null;
}

function fondo_className(pObj,pClassName)
{
	getRefById(pObj).className = pClassName;
}

function SendMessage(pMessage)
{
	alert(pMessage);
}

function addListeners( table ) {
  var cells = getRefByTagName( 'tr', getRefById( table ));

  for( var i = 0; i < cells.length; ++i ) {
    if( cells[ i ].addEventListener ) {
      cells[ i ].addEventListener( 'click', cellClick, false );
      cells[ i ].addEventListener( 'mouseout', cellOut, false );
      cells[ i ].addEventListener( 'mouseover', cellOver, false );
    } else {
      cells[ i ].onclick = cellClick;
      cells[ i ].onmouseout = cellOut;
      cells[ i ].onmouseover = cellOver;
    }
  }
}

function cellClick() {
  if( currentCell ) {
    changeBackground( currentCell, '#f7f7f7' );
  }
  changeBackground( currentCell = this, '#E0E0E0' );
}

function cellOut() {
  if( this != currentCell )
    changeBackground( this, '' );    //#f7f7f7
}

function cellOver() {
  if( this != currentCell )
    changeBackground( this, '#E9E9E9' );
}

function changeBackground( element, colour ) {
  if( element.style
    && 'undefined' != typeof element.style.backgroundColor ) {
    element.style.backgroundColor = colour;
  }
}


function jsSubmit( form )
{
	form.submit();
}

function onSubmitSelectChange(pPage, pOption, pId)
{
	switch(pPage)
	{
		case "N":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/noticia_data.php?idnoticia='+pId, 650, 275, null, '-', false, '', 'Noticia - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar la noticia ?')+'&aspcall='+escape('../admin/noticia_update.php?update=B&idnoticia='+pId+'&gourl=../admin/noticia.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "A":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/producto_familia_data.php?idproducto_familia='+pId, 600, 400, null, '-', false, '', 'Familia de producto - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar la familia ?')+'&aspcall='+escape('../admin/producto_familia_update.php?update=B&idproducto_familia='+pId+'&gourl=../admin/producto_familia.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "B":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/producto_subfamilia_data.php?idproducto_subfamilia='+pId, 600, 400, null, '-', false, '', 'SubFamilia de producto - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar la subfamilia ?')+'&aspcall='+escape('../admin/producto_subfamilia_update.php?update=B&idproducto_subfamilia='+pId+'&gourl=../admin/producto_subfamilia.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "C":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/producto_data.php?idproducto='+pId, 600, 400, null, '-', false, '', 'Catalogo de producto - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar el producto ?')+'&aspcall='+escape('../admin/producto_update.php?update=B&idproducto='+pId+'&gourl=../admin/producto.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "D":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/promocion_data.php?idpromocion='+pId, 600, 400, null, '-', false, '', 'Promociones - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar la promoción ?')+'&aspcall='+escape('../admin/promocion_update.php?update=B&idpromocion='+pId+'&gourl=../admin/promocion.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "E":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/tip_data.php?idtip='+pId, 600, 400, null, '-', false, '', 'Tips - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar el tip ?')+'&aspcall='+escape('../admin/tip_update.php?update=B&idtip='+pId+'&gourl=../admin/tip.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "F":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/cliente_data.php?idcliente='+pId, 600, 400, null, '-', false, '', 'Clientes - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar el cliente ?')+'&aspcall='+escape('../admin/cliente_update.php?update=B&idcliente='+pId+'&gourl=../admin/cliente.php')+'', 250, 100, null, '', false, '', '');
					break;
			}
			break;
		case "G":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/producto_paquete_data.php?idproducto_paquete='+pId, 600, 400, null, '-', false, '', 'Racks - Registro');
					break;
				case "B": 
					parent.showPopWin('../tools/msgquestion_pop.php?id=0&pquestion='+escape('&iquest; Esta seguro de eliminar el rack ?')+'&aspcall='+escape('../admin/producto_paquete_update.php?update=B&idproducto_paquete='+pId+'&gourl=../admin/producto_paquete.php')+'', 250, 100, null, '', false, '', '');
					break;
				case "P": 
					parent.showPopWin('../admin/producto_paquete_producto.php?idproducto_paquete='+pId, 700, 600, null, '-', false, '', 'Racks/Productos');
					break;
			}
			break;
		case "H":
			switch(pOption)
			{
				case "V": 
					parent.showPopWin('../admin/oc_detalle.php?idoc='+pId, 700, 500, null, '-', false, '', 'Orden de Compra');
					break;
				case "A":
					DoPage('../admin/oc_up.php?idoc='+pId+'&estatus=A');
					break;
				case "T":
					DoPage('../admin/oc_up.php?idoc='+pId+'&estatus=T');
					break;
			}
			break;
			case "I":
			switch(pOption)
			{
				case "E": 
					parent.showPopWin('../admin/banners_data.php?idbanners='+pId, 600, 400, null, '-', false, '', 'Banners - Registro');
					break;
			}
			break;
	}
}

function ScTLoadPage()
{
	new Effect.Appear(document.getElementById('sctMain'))
	new Effect.SlideDown(document.getElementById('sctMain'))
}
function ScTUnLoadPage()
{
	new Effect.Fade(document.getElementById('sctMain'))
	new Effect.SlideUp(document.getElementById('sctMain'))
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function ValRangoFechas(fecha1,fecha2)
{
	if (fechaMayorOIgualQue(fecha2, fecha1))
	{
		return true;
	}
	else
	{
    	return false;
	}
}


function fechaMayorOIgualQue(fec0, fec1)
{
	var bRes = false;
    var sDia0 = fec0.value.substr(0, 2);
    var sMes0 = fec0.value.substr(3, 2);
    var sAno0 = fec0.value.substr(6, 4);
    var sDia1 = fec1.value.substr(0, 2);
    var sMes1 = fec1.value.substr(3, 2);
    var sAno1 = fec1.value.substr(6, 4);
    if (sAno0 > sAno1) 
		bRes = true;
    else
	{
    	if (sAno0 == sAno1)
		{
      		if (sMes0 > sMes1) 
				bRes = true;
      		else 
			{
       			if (sMes0 == sMes1)
        			if (sDia0 >= sDia1) 
						bRes = true;
			}
		}
	}
    return bRes;
}

function goToCarrito(pidPSF,pT,pTE,pIdP,pCantidad)
{
	var jsCantidad = 1;
	if ( document.getElementById(pCantidad) != null )
		jsCantidad = document.getElementById(pCantidad).value;
	document.location.href = "carrito_admin.php?idproducto_subfamilia=" + pidPSF + "&tipo=" + pT + "&tipo_empaque=" + pTE + "&idproducto=" + pIdP + "&cantidad=" + jsCantidad;
}
