function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHide(){
  var i,p,v,obj,args=MM_showHide.arguments;
  for (i=0; i<(args.length-1); i+=2) {
		if ((obj=MM_findObj(args[i]))!=null) {
			v=args[i+1];
			if (obj.style) {
				obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
			obj.visibility=v; 
		}
	}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj("s"+args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// locate objects
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function xWidth(e,w){
	if(!(e=xGetElementById(e)))
		return 0;
	if (xNum(w)) {
		if (w<0)
			w = 0;
		else
			w=Math.round(w);
	} else 
		w=-1;
		var css=xDef(e.style);
	
	if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
		w = xClientWidth();
	}else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
		if(w>=0) {
			var pl=0,pr=0,bl=0,br=0;
			if (document.compatMode=='CSS1Compat') {
				var gcs = xGetComputedStyle;pl=gcs(e,'padding-left',1);
				if (pl !== null) {
					pr=gcs(e,'padding-right',1);
					bl=gcs(e,'border-left-width',1);
					br=gcs(e,'border-right-width',1);
				}else if(xDef(e.offsetWidth,e.style.width)){
					e.style.width=w+'px';pl=e.offsetWidth-w;
				}
			}
			w-=(pl+pr+bl+br);
			if(isNaN(w)||w<0) 
				return;
			else 
				e.style.width=w+'px';
		}
		w=e.offsetWidth;
	}
	else if(css && xDef(e.style.pixelWidth)) {
		if(w>=0) 
			e.style.pixelWidth=w;w=e.style.pixelWidth;
	}
	return w;
}

/* X Library, Copyright 2001-2005 Michael Foster (Cross-Browser.com). Distributed under the terms of the GNU LGPL */
/* floater_xlib.js compiled with XC v0.22b, see floater_xlib.txt for contributor copyrights, license info and documentation */
var xVersion='4.0',xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();if(window.opera){var i=xUA.indexOf('opera');if(i!=-1){var v=parseInt(xUA.charAt(i+6));xOp7Up=v>=7;xOp6Dn=v<7;}}else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){xIE4Up=parseFloat(navigator.appVersion)>=4;xIE4=xUA.indexOf('msie 4')!=-1;xIE5=xUA.indexOf('msie 5')!=-1;}else if(document.layers){xNN4=true;}xMac=xUA.indexOf('mac')!=-1;
function xDef(){for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}return true;}
function xGetComputedStyle(oEle, sProp, bInt){var s, p = 'undefined';var dv = document.defaultView;if(dv && dv.getComputedStyle){s = dv.getComputedStyle(oEle,'');if (s) p = s.getPropertyValue(sProp);}else if(oEle.currentStyle) {var a = sProp.split('-');sProp = a[0];for (var i=1; i<a.length; ++i) {c = a[i].charAt(0);sProp += a[i].replace(c, c.toUpperCase());}   p = oEle.currentStyle[sProp];}else return null;return bInt ? (parseInt(p) || 0) : p;}
function xGetElementById(e){if(typeof(e)!='string') return e;if(document.getElementById) e=document.getElementById(e);else if(document.all) e=document.all[e];else e=null;return e;}
function xNum(){for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}return true;}
function _xSlideTo(e){if (!(e=xGetElementById(e))) return;var now, s, t, newY, newX;now = new Date();t = now.getTime() - e.C;if (e.stop) { e.moving = false; }else if (t < e.slideTime) {setTimeout("_xSlideTo('"+e.id+"')", e.timeout);if (e.slideLinear) s = e.B * t;else s = Math.sin(e.B * t);newX = Math.round(e.xA * s + e.xD);newY = Math.round(e.yA * s + e.yD);xMoveTo(e, newX, newY);e.moving = true;}  else {xMoveTo(e, e.xTarget, e.yTarget);e.moving = false;}  }
function xStr(s){for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}return true;}
function xTop(e,iY){if(!(e=xGetElementById(e)))return 0;var css=xDef(e.style);if(css&&xStr(e.style.top)){if(xNum(iY))e.style.top=iY+'px';else{iY=parseInt(e.style.top);if(isNaN(iY))iY=xGetComputedStyle(e,'top',1);if(isNaN(iY))iY=0;}}else if(css&&xDef(e.style.pixelTop)){if(xNum(iY))e.style.pixelTop=iY;else iY=e.style.pixelTop;}return iY;}
function xLeft(e,iX){if(!(e=xGetElementById(e)))return 0;var css=xDef(e.style);if(css&&xStr(e.style.left)){if(xNum(iX))e.style.left=iX+'px';else{iX=parseInt(e.style.left);if(isNaN(iX))iX=xGetComputedStyle(e,'left',1);if(isNaN(iX))iX=0;}}else if(css&&xDef(e.style.pixelLeft)){if(xNum(iX))e.style.pixelLeft=iX;else iX=e.style.pixelLeft;}return iX;}
function xHeight(e,h){if(!(e=xGetElementById(e)))return 0;if(xNum(h)){if(h<0)h=0;else h=Math.round(h);}else h=-1;var css=xDef(e.style);if(e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body'){h=xClientHeight();}else if(css&&xDef(e.offsetHeight)&&xStr(e.style.height)){if(h>=0){var pt=0,pb=0,bt=0,bb=0;if(document.compatMode=='CSS1Compat'){var gcs=xGetComputedStyle;pt=gcs(e,'padding-top',1);if(pt!==null){pb=gcs(e,'padding-bottom',1);bt=gcs(e,'border-top-width',1);bb=gcs(e,'border-bottom-width',1);}else if(xDef(e.offsetHeight,e.style.height)){e.style.height=h+'px';pt=e.offsetHeight-h;}}h-=(pt+pb+bt+bb);if(isNaN(h)||h<0)return;else e.style.height=h+'px';}h=e.offsetHeight;}else if(css&&xDef(e.style.pixelHeight)){if(h>=0)e.style.pixelHeight=h;h=e.style.pixelHeight;}return h;}

function showmenu(id) {
	_submenu = document.getElementById("submenu_" + id);
	if (_submenu) {
		_menu = document.getElementById("menu_" + id);
		
		_x = findPosX(_menu);
		_y = findPosY(_menu) - 5;
		
		_width = xWidth('menu_' + id);
		
		xLeft('submenu_' + id, _x + _width);
		xTop('submenu_' + id, _y);
		MM_showHide('submenu_' + id, 'show');
	}
}

function hidemenu(id) {
	if (document.getElementById("submenu_" + id)) {
		document.getElementById("submenu_" + id).style.visibility = 'hidden';
	}
}

function showsubmenu (arr_str) {
	id_array = arr_str.split(',');
	document.getElementById("submenu_" + id_array[0]).style.visivility = 'visible';
	
	for (i=1;i<id_array.length;i++) {
		_submenu = document.getElementById("submenu_" + id_array[i]);
		if (_submenu) {
			_menu = document.getElementById("menu_" + id_array[i]);
			
			_x = findPosX(_menu);
			_y = findPosY(_menu) - 5;
			
			//_width = xWidth(_menu);
			_width = xWidth("menu_" + id_array[i]);
			
			xLeft('submenu_' + id_array[i], _x + _width);
			xTop('submenu_' + id_array[i], _y);
			MM_showHide('submenu_' + id_array[i], 'show');
			/*
			_submenu.style.left = _x + _width + 'px';
			_submenu.style.top = _y + 'px';
			_submenu.style.visibility = 'visible';
			*/
		}
	}
}

function hidesubmenu (arr_str) {
	id_array = arr_str.split(',');
	for (i=0;i<id_array.length;i++) {
		_submenu = document.getElementById("submenu_" + id_array[i]);
		if (_submenu) {
			_submenu.style.visibility = 'hidden';
		}
	}
	
	/*
	_submenu = document.getElementById("submenu_" + id);
	if (_submenu) {
		_submenu.style.visibility = 'hidden';
	}
	*/
}

function locateSubmenu(submenu) {
	if(document.getElementById("o"+submenu)) {
		tope = findPosY(document.getElementById("o"+submenu));
		document.getElementById("s"+submenu).style.left = findPosX(document.getElementById("td"+submenu)) - 3 + 'px';
		document.getElementById("s"+submenu).style.top = 47 + 'px';
		
		return;
		if (tope==165) {
			document.getElementById("s"+submenu).style.top = findPosY(document.getElementById("o"+submenu)) + 33 + 'px';
		} else {
			document.getElementById("s"+submenu).style.top = findPosY(document.getElementById("o"+submenu)) + 23 + 'px';
		}
	}
}

function changeMenu(state, tr) {
	if(state == 0) {
		MM_showHideLayers('2','','hide');
		MM_showHideLayers('4','','hide');
		document.getElementById("o2").style.top = 27 + 'px';
		document.getElementById("o4").style.top = 27 + 'px';
		if(document.getElementById("ttop")) {
			document.getElementById("ttop").style.height = 65 + 'px';
			document.getElementById("tbottom").style.height = 65 + 'px';
		}
		document.getElementById("t2").style.height = 27 + 'px';
		document.getElementById("t4").style.height = 27 + 'px';
		if(document.getElementById("tr"+tr)) {
			document.getElementById("tr"+tr).style.color = '#FFFFFF';
		}
	} else {
		document.getElementById("o2").style.top = 75 + 'px';
		document.getElementById("o4").style.top = 123 + 'px';
		if(document.getElementById("ttop")) {
			document.getElementById("ttop").style.height = 0 + 'px';
			document.getElementById("tbottom").style.height = 0 + 'px';
		}
		document.getElementById("t2").style.height = 75 + 'px';
		document.getElementById("t4").style.height = 123 + 'px';
		if(document.getElementById("tr"+tr)) { document.getElementById("tr"+tr).style.background = '#F47C32'; }
		MM_showHideLayers('2','','show');
		MM_showHideLayers('4','','show');
		locateSubmenu(2);
		locateSubmenu(4);
	}
}


function validarEmail(str_email) {
	var s = str_email;
	//var filter=/^[A-Za-z]([A-Za-z_])*(\.([A-Za-z0-9_])+)*@([A-Za-z0-9])+(\.([A-Za-z0-9_])+)+([A-Za-z])$/;
	var filter=/^[A-Za-z0-9_-]([A-Za-z0-9_-])*(\.([A-Za-z0-9_-])+)*@([A-Za-z0-9_-])+(-([A-Za-z0-9_-])+)?(\.([A-Za-z0-9_-])+)+([A-Za-z])$/;
	if (s.length == 0 ) return false;
	if (filter.test(s)) {
		return (true);
	} else {
		return (false);
	}
}

function update_shadow() {
	content_table = document.getElementById('content_bg');
	div_s = document.getElementById('div_shadow');
	img_s = document.getElementById('shadow_rep');
	
	left = findPosX(content_table) - 19;
	height = xHeight('content_bg') - 294 - 29;
	
	xLeft('div_shadow', left);
	xHeight('shadow_rep', height);
	MM_showHide('div_shadow','','show');
	MM_showHide('div_meses','show');
	try {
		update_table_meses();
	} catch(e){
		
	}
}

function ajaxObject() {
	var ajaxObject=false;
	try {
		/* DIFERENT BROWSERS */
		ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			/* IE */
			ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			ajaxObject = false;
		}
	}
	
	if (!ajaxObject && typeof XMLHttpRequest!='undefined') {
		ajaxObject = new XMLHttpRequest();
	}
	return ajaxObject;
}
//addToCart(this.form, 'display_loading_add_to_cart');

function validateNum (num) {
	quant = parseInt(num);
	var filter = /^([0-9])*$/;
	if (isNaN(quant) || num == '' || !filter.test(num)) {
		return(false);
	} else {
		return(true);
	}
}

function addToCart(id_skin, input_obj, display_loading) {
	if (!validateNum(input_obj.value)) {
		alert(unescape("Por favor ingrese un n%FAmero entero v%E1lido."));
		input_obj.focus();
		return(false);
	}
	
	document.getElementById(display_loading).innerHTML = '<img src="images/loading.gif" width="16" height="16" alt="" />';
	
	ao = ajaxObject();
	
	_values_send="id_product=" + id_skin + "&quantity=" + quant;
	_URL_="addtocart.php?";
	
	ao.open("GET",_URL_+_values_send,true);
	ao.onreadystatechange = function() {
		if (ao.readyState == 4) {
			if(ao.status == 200) {
				document.getElementById(display_loading).innerHTML = ao.responseText;
			}
		}
	}
	ao.send(null);
	return(false);
}

function removeFromCart (id_skin) {
	if (!window.confirm(unescape("%BFConfirma que desea eliminar el %EDtem seleccionado?"))) {
		return(false);
	}
	h = xHeight('td_carrito');
	document.getElementById('td_carrito').innerHTML = '<div align="center" style="height:' + h + 'px">Removiendo...</div>';
	ao = ajaxObject();
	
	_values_send="id_product=" + id_skin;
	_URL_="removefromcart.php?";
	
	ao.open("GET",_URL_+_values_send,true);
	ao.onreadystatechange = function() {
		if (ao.readyState == 4) {
			if(ao.status == 200) {
				document.getElementById('td_carrito').innerHTML = ao.responseText;
			}
		}
	}
	ao.send(null);
	return(false);
}
function cambiarI (Idimg,imgx) {
    document.images[Idimg].src = imgx;
}
function cambiaImagen_style(Idimg,img_url) {
  document.getElementById(Idimg).style.background = 'url(' + img_url + ')';
}
