/************************************************/
/***** CODIGO GENERADO POR CODIGOENLACE.COM *****/
/***** AUTHOR: CODIGOENLACE.COM             *****/
/***** EMAIL: WEBMASTER@CODIGOENLACE.COM    *****/
/************************************************/

var anuncio = " www.todoenrenta.com.mx";
var velocidad = 0;
var currentCell = null;
var bAgregarCarrito = false;

function GetLicense()
{
	if ( ( document.domain != "www.todoenrenta.com.mx" ) && ( document.domain != "todoenrenta.com.mx" ) )
	{
		alert("Usted no cuenta con la licencia necesaria para operar el sistema todotienda. \r Favor de ponerse en contacto en www.todoenrenta.com.mx.");
		//GoPage("http://www.todoenrenta.com.mx");
	}
}

function InicioWindow() 
{
	//GetLicense();
	window.status = anuncio;
	var MiVelTool = setTimeout("InicioWindow()",velocidad);
}



/*DESDE AQUI ES CODOGIO GENERAL*/
/*DESDE AQUI ES CODOGIO GENERAL*/
/*DESDE AQUI ES CODOGIO GENERAL*/



function About()
{
	alert('www.codigoenlace.com');
}

function GetEmailTodoEnRenta(pMail,pMailTo,pMailToCss)
{
	var vJS = "";

	if ( pMail == 1 )
	{
		if ( pMailTo == true )
			vJS = "<a class=\""+pMailToCss+"\" href=\"&#109;&#097;&#105;&#108;&#116;&#111;:&#115;&#111;&#112;&#111;&#114;&#116;&#101;&#064;&#116;&#111;&#100;&#111;&#101;&#110;&#114;&#101;&#110;&#116;&#097;&#046;&#099;&#111;&#109;&#046;&#109;&#120;\">&#115;&#111;&#112;&#111;&#114;&#116;&#101;&#064;&#116;&#111;&#100;&#111;&#101;&#110;&#114;&#101;&#110;&#116;&#097;&#046;&#099;&#111;&#109;&#046;&#109;&#120;</a>";
		else
			vJS = "&#115;&#111;&#112;&#111;&#114;&#116;&#101;&#064;&#116;&#111;&#100;&#111;&#101;&#110;&#114;&#101;&#110;&#116;&#097;&#046;&#099;&#111;&#109;&#046;&#109;&#120;";
	}
	document.write(vJS);
}

function ChangeCssTd(pObjTd,pClassName)
{
	pObjTd.className = pClassName;
}

function GoPage(pPage)
{
	window.document.location.href = pPage;
}

function OpenPage(pPage)
{
	window.open(pPage);
}

function ValFormData(pForm, pSubmit, pButton)
{
	var bReturn = true;
	var iElements = 0;
	var formElements = pForm.elements;	
	for ( iElements=0; iElements<formElements.length; iElements++ )
	{
		if ( formElements[iElements].className.indexOf('jsreq') >= 0 )
		{
			if ( formElements[iElements].value.length <= 0 )
			{
				formElements[iElements].style.backgroundColor = "#F9FCB1";
				bReturn = false;
			}
			else if ( ( formElements[iElements].className.indexOf('jsmai') >= 0 ) && ( formElements[iElements].value.search('.+@.+\\.[a-z]+') == -1 ) )
			{
				formElements[iElements].style.backgroundColor = "#FFD7D7";
				bReturn = false;
			}
			else
			{
				formElements[iElements].style.backgroundColor = "#FFFFFF";
			}
		}
	}
	if ( bReturn == true && pButton != null )
		DisabledControl(pButton);
	if ( bReturn == true && pSubmit == true )
		SubmitJS(pForm);
	else
		return bReturn;
}

function DisabledControl(obj)
{
	obj.disabled = true;
}

function SubmitJS( pForm )
{
	pForm.submit();
}

function GetFrame(paramFrame,paramPage)
{
	top.frames[paramFrame].document.location.href = paramPage;
}

function LimiteLongitudTextArea(obj, length)
{
	var maxlength = length;
	if (obj.value.length>maxlength)
		obj.value=obj.value.substring(0, maxlength);
}

function DisabledKeyPress(e)
{
	var key;
    if ( window.event )
		key = window.event.keyCode;     /*IE*/
	else
		key = e.which;     /* firefox */
	/* if (key == 13) StartClick(); */
	e.cancelBubble = true;
	e.returnValue = false;
	return false;
}

function getRefById( id ) 
{
	if( document.all ) 
	{
	    return document.all[ id ];
  	} 
	else if( document.getElementById ) 
	{
	    return document.getElementById( id );
	}
}

function RoundDecimal(pCantidad,pDecimal)
{
	var result = 0;
	if ( pDecimal == 1 )
		result = Math.round(pCantidad*10)/10;
	else if ( pDecimal == 2 )
		result = Math.round(pCantidad*100)/100;
	else if ( pDecimal == 3 )
		result = Math.round(pCantidad*1000)/1000;
	return result;
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}

function checkNumber(pObj)
{
	if ( isNumeric(pObj.value) == false )
		pObj.value = 0;
	else if ( pObj.value == '.' )
		pObj.value = 0;
}

function SwitchMenu(obj,opt)
{
	if(document.getElementById)
	{
		if ( opt == 1 )
		{
			var iHeightScreen = parseInt(document.body.scrollHeight);
			var iposCursorY = parseInt(event.clientY);
			var iposCursorX = parseInt(event.clientX);
			var iHeightMenu = parseInt(document.getElementById(obj).style.height);
			var iPosTotal = iposCursorY + iHeightMenu;
			document.getElementById(obj).style.left = iposCursorX + 'px';
			if ( iPosTotal > iHeightScreen )
				document.getElementById(obj).style.top = (iposCursorY - iHeightMenu) + 'px';
		}

		var el = document.getElementById(obj);
		if(el.style.display != "block")
		{
			el.style.display = "block";
		}
		else
		{
			el.style.display = "none";
		}
	}
}

function KepPressAscii(e,pAscii)
{
	IE5=document.all? 1:0;
	whKey = !IE5? e.which:event.keyCode;
	if ( whKey == pAscii )
		return true;
	else
		return false;
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	

	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;

	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		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) {
			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);
	
	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 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() {
	sColor = this.className;
	if ( sColor == 'TgridRow' || sColor == 'TgridRow_Over' || sColor == '' )
		changeClass( this, 'TgridRow_Select' );
	else
		changeClass( this, 'TgridRow' );
}

function cellOut() {
	sColor = this.className;
	if ( sColor != 'TgridRow_Select' )
		changeClass( this, 'TgridRow' );
}

function cellOver() {
	sColor = this.className;
	if ( sColor != 'TgridRow_Select' )
		changeClass( this, 'TgridRow_Over' );
}

function changeClass( element, cssName ) {
  if( element.className && 'undefined' ) {
    element.className = cssName;
  }
}

function PaginacionOver(oImg,oSts,oName)
{
	if ( oSts )
		oImg.src = "../images/page_" + oName + ".png";
	else
		oImg.src = "../images/page_" + oName + ".png";
}

function InitSearchPanel(pTipo)
{
	var lHTML = "";
	if ( pTipo == "F" )
		lHTML = '';
	else if ( pTipo == "V" )
	{
		lHTML = '<a title=\'Panel de busqueda\' href="javascript:ViewSearchPanel();"><img onMouseOver="PaginacionOver(this,true,\'admin_view_search_over\');" onMouseOut="PaginacionOver(this,false,\'admin_view_search_normal\');" border=\"0\" src=\"../images/page_admin_view_search_normal.png\"></a>';
		getRefById('tableSearchPanel').style.display = "block";
	}
	else
		lHTML = '<a title=\'Panel de busqueda\' href="javascript:ViewSearchPanel();"><img onMouseOver="PaginacionOver(this,true,\'admin_view_search_over\');" onMouseOut="PaginacionOver(this,false,\'admin_view_search_normal\');" border=\"0\" src=\"../images/page_admin_view_search_normal.png\"></a>';
	document.write(lHTML);
}

function MultiSelect(pTable,pHidden,pSeparator)
{
	rHTML = "";
	var rHTML = "";
	var cells = getRefByTagName( 'tr', getRefById( pTable ));
	for( var i = 1; i < cells.length; ++i ) 
	{
		if( cells[i].className == "TgridRow_Select" )
		{
			rHTML = rHTML + getRefById(pHidden+i).value + pSeparator;
		}
   	}
	return rHTML;
}

function MultiSelect_All(pTable)
{
	var sCssName = "";
	var cells = getRefByTagName( 'tr', getRefById( pTable ));
	for( var i = 1; i < cells.length; ++i ) 
	{
		if ( i == 1 )
		{
			if ( cells[i].className == "TgridRow_Select" )
				sCssName = 'TgridRow';
			else
				sCssName = 'TgridRow_Select';
		}
		changeClass( cells[i], sCssName );
	}
}

function ViewSearchPanel()
{
	if ( getRefById('tableSearchPanel').style.display == "block" )
		getRefById('tableSearchPanel').style.display = "none";
	else
		getRefById('tableSearchPanel').style.display = "block";
}

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 GridTableResize(pDivHeaderGrid,pDivContentGrid,pDivFooterGrid,pTableGrid,pWidthScroll,pDivSpace1)
{
	var gridHeader_space = document.getElementById(pDivHeaderGrid).clientHeight;
	var gridFooter_space = document.getElementById(pDivFooterGrid).clientHeight;
	var window_width=document.body.offsetWidth;
	var window_height=document.body.offsetHeight;
	document.getElementById(pDivContentGrid).style.width = window_width + 'px';
	document.getElementById(pDivContentGrid).style.height = window_height - gridFooter_space - gridHeader_space + 'px';
	document.getElementById(pTableGrid).style.width = window_width - pWidthScroll + 'px';
	document.getElementById(pDivSpace1).style.height=window_height = gridHeader_space + 'px';
}

var GLB_DivWin_1;
function OpenWinImage(pImage,pWidth,pHeight,pResize,pScrolling)
{
	var sNameDiv = 'DivImageView';
	if ( document.getElementById(sNameDiv) != null )
		GLB_DivWin_1.close();
	var theBody = document.getElementsByTagName('BODY')[0];
	var oNewDiv = document.createElement('div');
	oNewDiv.id = sNameDiv;
	oNewDiv.innerHTML = '<div align="center" id="' + sNameDiv + '" ><img id="ImgImageView" border="0"  src="' + pImage + '"></div>';
	theBody.appendChild(oNewDiv);
	GLB_DivWin_1 = dhtmlwindow.open('divbox', 'div', sNameDiv, 'Galeria', 'width='+pWidth+'px,height='+pHeight+'px,left=0px,top=0px,resize='+pResize+',scrolling='+pScrolling);
	GLB_DivWin_1.moveTo('middle', 'middle');
}

function CloseWinImage()
{
	var sNameDiv = 'DivImageView';
	if ( document.getElementById(sNameDiv) != null )
	{
		var theBody = document.getElementsByTagName('BODY')[0];
		var oNewDiv = document.getElementById(sNameDiv);
		theBody.removeChild(oNewDiv);
	}
}

function createXMLHttpRequest() 
{
	var ua;
	if(window.XMLHttpRequest) 
	{
		try 
		{
			ua = new XMLHttpRequest();
		} 
		catch(e) 
		{
			ua = false;
		}
	}
	else if(window.ActiveXObject) 
	{
		try 
		{
			ua = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(e) 
		{
			ua = false;
		}
	}
	return ua;
}

function RequestShopCart(pIdProducto, pMethod, pAction, pCantidad, pOrigen) 
{
	if ( bAgregarCarrito == false )
	{
		var lobjAjax = createXMLHttpRequest();
		if ( pAction == "ADD" )
		{
			getRefById(pIdProducto+'imgAddCarritoMsg'+pOrigen).src = "../images_online/wait.gif";
			bAgregarCarrito = true;
			AddShopCartEffect(pIdProducto,pOrigen);
		}
		var sFileProccess = "../include/ocarrito_admin.php?idproducto=" + pIdProducto + "&cantidad=" + pCantidad + "&action=" + pAction;
		lobjAjax.open(pMethod, sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { ResponseShopCart(lobjAjax, pIdProducto, pAction, pOrigen); };
		lobjAjax.send(null);
	}
}

function ResponseShopCart(pobjAjax, pIdProducto, pAction, pOrigen)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			getRefById('divShopCart').innerHTML = response;
			if ( pAction == "ADD" )
			{
				getRefById(pIdProducto+'imgAddCarritoMsg'+pOrigen).src = "../images_online/anima_producto_en_carrito"+pOrigen+".gif?" + Math.random();	/* PARA QUE NO HAGA CACHE LA IAMGEN Y SIEMPRE SE VISUALICE */
				getRefById(pIdProducto+'linkAddCarritoMsg'+pOrigen).title = "Producto en carrito de compras";
				getRefById(pIdProducto+'linkAddCarritoMsg'+pOrigen).style.cursor = "help";
				getRefById(pIdProducto+'imgAddCarrito'+pOrigen).src = "../images_online/ico_addcarrito_disabled.jpg";
				ShowMessage("Carrito de compras","<img align='absmiddle' src='../images_online/ico_carrito_ok.png' /><span style='font-size:12px;font-family:Tahoma;color:#1D6421;line-height:23px;'>Producto agregado</span><br><a class='link2' style='margin-left:45px;' href='shopcart.php'>Mi carrito</a><br><a class='link2' style='margin-left:45px;' href='comprar.php'>Realizar pedido</a>",130,52,4000);
			}
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function AddShopCartEffect(pIdProducto,pOrigen)
{
	var iX = 0;
	var iY = 0;
	if ( pOrigen == "L" || pOrigen == "D" )
	{
		iX = "350";
		iY = "-600";
	}
	else if ( pOrigen == "R" )
	{
		iX = "50";
		iY = "-600";
	}
	iDivEffect = getRefById('divEffect'+pIdProducto);
	new Effect.Parallel([
  		new Effect.Move(iDivEffect, { sync: true, x: iX, y: iY, mode: 'relative' }), 
		new Effect.Scale(iDivEffect, 5, { sync: true, scaleFromCenter: false }),
  		new Effect.Opacity(iDivEffect, { sync: true, from: 1, to: 0 }) 
	], { 
  		duration: 0.7,
		queue: 'end',
		afterFinish: function()
			{
				new Effect.Move(iDivEffect, { x: iX*(-1), y: iY*(-1), mode: 'relative',
					afterFinish: function()
					{
						iDivEffect.style.width = "250px";
						iDivEffect.style.height = "125px";
		  				new Effect.Opacity(iDivEffect, { from: 0, to: 1, duration: 0.3 });
						bAgregarCarrito = false;
					}
				});
			}
	});
}

function SubmitShopCartUpdate(pForm)
{
	if ( ValFormData(pForm,false,null) == false )
		alert("Captura los datos obligatorios y en formato correcto");
	else
	{
		pForm.action = '../include/ocarrito_admin.php?action=SHOPCART';
		SubmitJS(pForm);
	}
}

function RequestAjax(pAction)
{
	var sFileProccess = "";
	var lobjAjax = createXMLHttpRequest();
	if ( pAction == "VALEMAILNEWACCOUNT" )
	{
		sFileProccess = "../include/oajax.php?action=" + pAction + "&email=" + getRefById('email').value;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxValEmailAccount(lobjAjax); };
	}
	else if ( pAction == "VALEMAILMODACCOUNT" )
	{
		sFileProccess = "../include/oajax.php?action=" + pAction + "&email=" + getRefById('email').value + "&idcliente=" + getRefById('idclienteVal').value;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxValEmailAccount(lobjAjax); };
	}
	else if ( pAction == "ENTERLOGINONLINE" )
	{
		sFileProccess = "../include/oajax.php?action=" + pAction + "&email=" + getRefById('email').value + "&password=" + getRefById('password').value + "&tlogin=" + getRefById('tlogin').value + "&id_redsocial=" + getRefById('id_redsocial').value;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxEnterLogin(lobjAjax,getRefById('iralogueo').value,getRefById('tlogin').value); };
	}
	else if ( pAction == "ENCUESTAPOLLINIT" )
	{
		iPage = 1;
		if ( getRefById('pagePAGINA') != undefined )
			iPage = getRefById('pagePAGINA').value;
		sFileProccess = "../include/oencuesta.php?action=" + pAction + "&pagina=" + iPage;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxEncuesta(lobjAjax); };
	}
	else if ( pAction == "ENCUESTAPOLLINIT_RESP" )
	{
		var iidencuesta_respuesta = 0;
		if ( getRefById('idencuesta_respuesta').length == undefined )
			iidencuesta_respuesta = getRefById('idencuesta_respuesta').value;
		else
		{
			for (var i=0;i<getRefById('idencuesta_respuesta').length;i++)
			{ 
		    	if (getRefById('idencuesta_respuesta')[i].checked) 
		        {
					iidencuesta_respuesta = getRefById('idencuesta_respuesta')[i].value;
					break;
				}
		    }
		}
		sFileProccess = "../include/oencuesta.php?action=" + pAction + "&idencuesta=" + getRefById('idencuesta').value + "&idencuesta_respuesta=" + iidencuesta_respuesta;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxEncuesta(lobjAjax); };
	}
	else if ( pAction == "VALCUPON" )
	{
		sFileProccess = "../include/oajax.php?action=" + pAction + "&cupon=" + getRefById('cupon').value;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxValCupon(lobjAjax); };
	}
	else if ( pAction == "SENDFORMCONTACTO" || pAction == "SENDFORMASISTENCIALINEA" || pAction == "SENDFORMCALLBACK" )
	{
		document.formForm.action = '../formatos/email_online/email_send.php?idmail=' + pAction;
		SubmitJS(document.formForm);
		return;
	}
	else if ( pAction == "SENDFORMCOTIZACION" )
	{
		document.formCotizador.action = '../formatos/email_online/email_send.php?idmail=' + pAction;
		SubmitJS(document.formCotizador);
		return;
	}
	else if ( pAction == "REGCOMMENTBLOGINS" )
	{
		document.formForm.action = '../include/oajax.php?action=' + pAction;
		SubmitJS(document.formForm);
		return;
	}
	lobjAjax.send(null);
}

function RequestAjaxCallMiniPop(pAction,pW,pH,pOcp,pFunctCallBack,pLen1,pLen2)
{
	/*,pLen2 es opcional para futuro*/
	var sFileProccess = "";
	var lobjAjax = createXMLHttpRequest();

	if ( pAction == "MINIPOP_CP" )
	{
		sTitle = "Codigo Postal";
		var sCP = getRefById(pOcp).value;
		if ( sCP.length < pLen1 )
		{
			alert("Captura un codigo postal minimo de " + pLen1 + " caracteres");
			return;
		}
		sFileProccess = "../tools/minipop.php?action=" + pAction + "&cp=" + sCP + "&functcallback=" + pFunctCallBack;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxMiniPop(lobjAjax,pW,pH,sTitle); };
	}
	else if ( pAction == "MESINTERES" )
	{
		sTitle = "Promoci&oacute;n - Meses sin intereses";
		sFileProccess = "../tools/minipop.php?action=" + pAction;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxMiniPop(lobjAjax,pW,pH,sTitle); };
	}
	else if ( pAction == "TESTIMONIOS" )
	{
		sTitle = "Testimonios";
		sFileProccess = "../tools/minipop.php?action=" + pAction + "&idp=" + pLen1;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { RequestAjaxMiniPop(lobjAjax,pW,pH,sTitle); };
	}
	lobjAjax.send(null);
}

function RequestAjaxValCupon(pobjAjax)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			if ( response == "NOEXISTS" )
				alert("El codigo capturado no existe, verifique.");
			else if ( response == "NOVALSTS" )
				alert("El codigo que capturo ya no esta vigente, verifique.");
			else if ( response == "NOVALUTILIZADO" )
				alert("Ya ha utilizado el codigo capturado anteriormente en otra compra.");
			else if ( response == "VALOK" )
				GoPage("../online/comprar.php");
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function RequestAjaxValEmailAccount(pobjAjax)
{
	/* NOTA: FUNCION UTILIZADA EN ADMIN Y ONLINE */
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			if ( parseInt(response) <= 0 )
			{
				showPopWin('../tools/msg_wait.php', 200, 100, null, false);
				SubmitJS(document.formData);
			}
			else
				alert("El email capturado ya existe, intente otro.");
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function RequestAjaxEnterLogin(pobjAjax,pGotoLogin,pTipoLogin)
{
	if ( pobjAjax.readyState == 4 )
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			if ( response == "B" )
				getRefById('idMsgLogin').innerHTML = "Tu cuenta ha sido dada de baja, contactanos.";
			else if ( response == "E" )
				getRefById('idMsgLogin').innerHTML = "Tu email o contrase&ntilde;a son erroneos, intenta nuevamente.";
			else if ( response == "A" )
			{
				if ( pTipoLogin == "FACEBOOK" )
					top.document.location.href = pGotoLogin;
				else
					GoPage(pGotoLogin);
			}
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function RequestAjaxEncuesta(pobjAjax)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			if ( getRefById('divEncuestasPoll') != undefined )
				getRefById('divEncuestasPoll').innerHTML = response;
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function RequestAjaxMiniPop(pobjAjax,pW,pH,sTitle)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			
			var sMiniPop = "" + 
				"<div class='sample_popup' id='popup' style='display: none; width:"+pW+"px; height:"+pH+"px;'>" +
					"<div class='menu_form_header' style='width:"+pW+"px;' id='popup_drag'>" +
						"<img class='menu_form_exit' id='popup_exit' src='../include/minipop/form_exit.png' />" +
						"&nbsp;&nbsp;" + sTitle +
					"</div>" +
					"<div class='menu_form_body' style='width:"+pW+"px; height:"+pH+"px;' id='divMenuMiniPop'></div>" +
				"</div>";

			if ( getRefById('divMenuMiniPopGral') == undefined )
			{
				var theBody = document.getElementsByTagName('BODY')[0];
				var oNewDiv = document.createElement('div');
				oNewDiv.id = "divMenuMiniPopGral";
				oNewDiv.innerHTML = sMiniPop;
				theBody.appendChild(oNewDiv);
			}
			else
				getRefById('divMenuMiniPopGral').innerHTML = sMiniPop;

			getRefById('divMenuMiniPop').innerHTML = response;
			document.body.style.cursor = "default";
			popup_show('popup', 'popup_drag', 'popup_exit', 'mouse', -10, -10);
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function gotoPage(pAction)
{
	if ( pAction == "RECUPERAPASS" )
		GoPage("../formatos/email_online/email_send.php?idmail=" + pAction + "&email=" + getRefById('email').value);
}

function sendRequestForm(pForm, pAction, pParamProsAvisoFechaCookie) 
{
	var bCotinueRequestForm = false;

	if ( pAction == "SENDRECOMIENDALINK" || pAction == "SENDPROSPEAVISODATA" )
	{
		if ( ValFormData(pForm,false,null) == false )
			alert("Captura los datos obligatorios y en formato correcto");
		else
			bCotinueRequestForm = true;
	}

	if ( bCotinueRequestForm == true )
	{
		var sFileProccess = "";
		var lobjAjax = createXMLHttpRequest();
		var strForm = "";

		if ( pForm != null )
			strForm = getForm(pForm) + '&';

		if ( pAction == "SENDRECOMIENDALINK" )
		{
			sFileProccess = "../formatos/email_online/email_send.php?" + strForm + "idmail=" + pAction;
			lobjAjax.open("POST", sFileProccess + '&rnd982g=' + Math.random());
			lobjAjax.onreadystatechange = function() { RequestSendRecomienda(lobjAjax); };
		}
		else if ( pAction == "SENDPROSPEAVISODATA" )
		{
			sFileProccess = "../include/oajax.php?" + strForm + "action=" + pAction;
			lobjAjax.open("POST", sFileProccess + '&rnd982g=' + Math.random());
			lobjAjax.onreadystatechange = function() { RequestSendProspectos(lobjAjax,pParamProsAvisoFechaCookie); };
		}
		lobjAjax.send(null);
	}
}

function getForm(fobj) 
{
	var str = '';
 	var ft = '';
 	var fv = '';
 	var fn = '';
 	var els = '';
 	for(var i = 0;i < fobj.elements.length;i++) 
	{
  		els = fobj.elements[i];
 		ft = els.title;
  		fv = els.value;
  		fn = els.name;
 		switch(els.type) 
		{
  			case 'text':
  			case 'hidden':
  			case 'password':
  			case 'textarea':
  				if(encodeURI(ft) == 'required' && encodeURI(fv).length < 1) 
				{
					alert('' + fn + ' is a required field, please complete.');
					els.focus();
					return false;
	  			}
	  			str += fn + '=' + escape(fv) + '&'; /* CAMBIE encodeURI POR escape, creo que original era escape */
	  			break; 
  			case 'checkbox':
			case 'radio':
				if(els.checked) 
					str += fn + '=' + escape(fv) + '&'; /* CAMBIE encodeURI POR escape, creo que original era escape */
  				break;	

  			case 'select-one':
				str += fn + '=' +
				els.options[els.selectedIndex].value + '&';
  				break;
  		} 
 	} 
 	str = str.substr(0,(str.length - 1));
 	return str;
}

function RequestSendRecomienda(pobjAjax)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			if ( response == "OKSEND" )
				getRefById('divRecomiendaSend').innerHTML = "<tr><td>Tu recomendaci&oacute;n ha sido enviada. Gracias.</td></tr>";
			else
				alert("Por el momento no se pueden enviar recomendaciones.\rFavor de intentar mas tarde.");
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function RequestAddEmail(pAction,pEmail)
{
	var sFileProccess = "";
	var lobjAjax = createXMLHttpRequest();
	if ( pAction == "CLIENTE" )
	{
		sFileProccess = "../include/oemailcliente_admin.php?email=" + pEmail;
		lobjAjax.open("GET", sFileProccess + '&rnd982g=' + Math.random());
		lobjAjax.onreadystatechange = function() { ResponseAddEmail(lobjAjax,pAction); };
	}
	lobjAjax.send(null);
}

function ResponseAddEmail(pobjAjax,pAction)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
			if ( pAction == "CLIENTE" )
			{
				ShowMessage("Envio de emails","Clientes agregados",125,15,2000,0,-30);
				document.body.style.cursor = "default";
			}
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function SetAllCheckBoxes(FormName, FieldName, CheckAllCtrl)
{
	var CheckValue = CheckAllCtrl.checked;
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function Resolucion()
{
	document.writeln(screen.width + " x " + screen.height) 
}

function JSTrim(pCadena) 
{ 
	var sReturnCadena = "";
    for( i=0; i<pCadena.length; i++ ) 
    { 
        if ( pCadena.charAt(i) != " " )
            sReturnCadena = sReturnCadena + pCadena.charAt(i); 
    } 

    return sReturnCadena; 
} 

function formatCurrency(num,pSign) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if ( isNaN(num) )
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}

	return (((sign)?'':'-') + pSign + num + '.' + cents);
}

function onRollVertical(pOSroll,pY,pH_OSroll)
{
	new Effect.Move('oScrollDiv' + pOSroll, { x: 0, y: pY, mode: 'absolute', duration:0.5 });
	document.getElementById('oScrollText' + pOSroll).style.top = pH_OSroll + 'px';
	Effect.Appear('oScrollText' + pOSroll, { duration: 0.5 });
}


function explodeXML ( xmltag, element, xmldoc )
{
	var container = new Array();
	var nodes = xmldoc.getElementsByTagName(xmltag);

    for ( xy = 0; xy < nodes.length; xy++)
    {
		var node  = nodes[xy];
      	var ids = new Array();
      	for ( yz=0; yz < element.length; yz++)
      	{
        	try { ids[element[yz]] = node.getElementsByTagName(element[yz])[0].firstChild.nodeValue; }
        	catch (e) { ids[element[yz]] = null; }
      	}
      	container.push(ids);
    }
  	return container;
}

var ArrStarProductos = new Array();
var GLB_RatingProductosURLAction = '../tools/rating.php?';
function ajaxRating(xml)
{
	var response = explodeXML('nodo', new Array('rating','idproducto','index'), xml.responseXML);
//	alert(response[0]['rating'])
//	alert(response[0]['idproducto'])
	ShowMessage("Gracias","Producto calificado",100,15,2000);
	ArrStarProductos[response[0]['index']].locked = true;
}

function ShowMessage(pTitle,pMsg,pW,pH,pTimeOut,pLeft,pTop)
{
	var sDivMsg = "" + 
	"<div class='Msg_sample_popup' id='MsgPopup' style='display: none; width:"+pW+"px; height:"+pH+"px;'>" +
		"<div class='Msg_menu_form_header' style='width:"+pW+"px;' id='MsgPopup_drag'>" +
			"<img class='Msg_menu_form_exit' id='MsgPopup_exit' src='../include/minipop/form_exit_2.png' />" + pTitle +
		"</div>" +
		"<div class='Mgs_menu_form_body' style='width:"+pW+"px; height:"+pH+"px;' id='divMsgMiniPop'>" + pMsg + "</div>" +
	"</div>";
	
	/*var theBody = document.getElementsByTagName('BODY')[0];
	var oNewDiv = document.createElement('div');
	oNewDiv.id = "divShowMessage";
	oNewDiv.innerHTML = sDivMsg;
	oNewDiv.style.display = "block";
	theBody.appendChild(oNewDiv);*/
	
	if ( getRefById('divShowMessage') == undefined )
	{
		var theBody = document.getElementsByTagName('BODY')[0];
		var oNewDiv = document.createElement('div');
		oNewDiv.id = "divShowMessage";
		oNewDiv.innerHTML = sDivMsg;
		theBody.appendChild(oNewDiv);
	}
	else
		getRefById('divShowMessage').innerHTML = sDivMsg;

	if ( pLeft == undefined )
		pLeft = 5;
	if ( pTop == undefined )
		pTop = 0;

	popup_show('MsgPopup', 'MsgPopup_drag', 'MsgPopup_exit', 'mouse', pLeft, pTop);
	setTimeout( "new Effect.Fade('MsgPopup', { duration: 0.5, afterFinish: function() { document.getElementById('MsgPopup').style.display = 'none'; }});", pTimeOut );
}

function GoPostSearchAjax(pTypeSearch,pParamUrl,pForm,pIntuitive)
{
	if ( ( $("DivMainViewAjax") != null && pIntuitive ) && ( pTypeSearch == "FORM" ) )
	{
		getRefById('DivMainViewAjax').innerHTML = "<div align='center' style='padding:30px;'>Cargando productos, espere...</div>";
		var sUrl = "../include/oproductos.php";   
		var params = Form.serialize(pForm);
		var response = new Ajax.Updater('DivMainViewAjax', sUrl, {asynchronous: false, method: 'post', parameters: params, onComplete: window.setTimeout("SetSweetTitlesAjax()",750) }).transport;   
	}
	else if ( ( $("DivMainViewAjax") == null || pIntuitive == false ) && ( pTypeSearch == "FORM" ) )
	{
		getRefById(pForm).action = "main.php";
		SubmitJS(getRefById(pForm));
	}
	else if ( ( $("DivMainViewAjax") != null && pIntuitive ) && ( pTypeSearch == "URL" ) )
	{
		getRefById('DivMainViewAjax').innerHTML = "<div align='center' style='padding:30px;'>Cargando productos, espere...</div>";
		var params = "";
		var sUrl = "../include/oproductos.php?" + pParamUrl;   
		var response = new Ajax.Updater('DivMainViewAjax', sUrl, {asynchronous: false, method: 'post', parameters: params, onComplete: pForm == "ONPAGE" ? null : window.setTimeout("SetSweetTitlesAjax()",750) }).transport; 
	}
	else if ( ( $("DivMainViewAjax") == null || pIntuitive == false ) && ( pTypeSearch == "URL" ) )
		GoPage("../online/main.php?" + pParamUrl);
}

function AbreSoporte()
{
	var hdlWin = window.open("../admin/_ini_pagina_externo.php?sPageUrl=soporte.php?pag=1", "TERSoporte", "height=500, width=800, scrollbars=no, resizable=no, toolbars=no, menubar=no, status=no, location=no");
	hdlWin.focus();
}

function explodeArray(item,delimiter) 
{ 
	tempArray=new Array(1); 
	var Count=0; 
	var tempString=new String(item); 

	while (tempString.indexOf(delimiter)>0) 
	{ 
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter)); 
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
		Count=Count+1;
	} 

	tempArray[Count]=tempString; 
	return tempArray; 
}

function RequestSendProspectos(pobjAjax,pParamProsAvisoFechaCookie)
{
	if (pobjAjax.readyState == 4)
	{
		if (pobjAjax.status == 200)
		{
	  		var response = pobjAjax.responseText;
			if ( response == "VALOK" )
			{
				(function($){
					$(function() {
						$.cookie("TER_PROSAVISO_REG_"+pParamProsAvisoFechaCookie, "S", { expires: 3650 });
						$.nyroModalRemove(); 
					});
				})(jQuery)
			}
			else
			{
				alert("Por el momento no se pueden enviar sus datos.\rFavor de intentar mas tarde.");
				(function($){
					$(function() {
						$.nyroModalRemove(); 
					});
				})(jQuery)
			}
			document.body.style.cursor = "default";
		}
		else 
		{
			alert('There was a problem with the request. System Busy');
			document.body.style.cursor = "default";
		}
 	}
	else if (pobjAjax.readyState >= 1 && pobjAjax.readyState <= 3)
	{
		document.body.style.cursor = "wait";
	}
}

function CloseWinModal2Avisos(pNoMasAviso,pParamProsAvisoFechaCookie)
{
	(function($){
		$(function() {
			if ( pNoMasAviso )
				$.cookie("TER_PROSAVISO_REG_"+pParamProsAvisoFechaCookie, "S", { expires: 3650 });
			$.nyroModalRemove(); 
		});
	})(jQuery)
}

function WinModalShow(pTitle, pPage, pW, pH, pModal, pFooter, pBook, pMin, pMax, pScroll, pheaderClass, pfooterClass, pcontainerClass, presizable, pclosable) {
	(function($){
		$.window({
			title: pTitle,
			url: pPage,
			width: pW,
			height: pH,
			showModal: pModal,
			showFooter: pFooter,
			bookmarkable: pBook,
			minimizable: pMin,
			maximizable: pMax,
			scrollable: pScroll,
			headerClass: pheaderClass,
			footerClass: pfooterClass,
			containerClass: pcontainerClass,
			resizable: presizable,
			closable: pclosable
		});
	})(jQuery)
}
































/***** FUNCTION *****/
function ValRangoFechas(fecha1,fecha2)
{
	if (fechaMayorOIgualQue(fecha2, fecha1))
	{
		return true;
	}
	else
	{
    	return false;
	}
}

/***** FUNCTION *****/
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;
}

/***** INIT *****/
/***** INIT *****/
/***** INIT *****/

InicioWindow();

/***** INIT *****/
/***** INIT *****/
/***** INIT *****/



/************************************************/
/***** CODIGO GENERADO POR CODIGOENLACE.COM *****/
/***** AUTHOR: CODIGOENLACE.COM             *****/
/***** EMAIL: WEBMASTER@CODIGOENLACE.COM    *****/
/************************************************/
