function popitup(url, name, width, height, scrolling)
{
	newwindow=window.open(url,name,'width='+width+',height='+height+',toolbar=0,scrollbars='+scrolling+',location=0,statusbar=1,menubar=0,resizable=0,top=300,left=300');
	if (window.focus) {newwindow.focus()}
	return false;
}

function FitPic() {
	var x,y;
	var ancho = document.getElementById('imagen').width;
	var alto = document.getElementById('imagen').height;
	window.resizeTo(ancho, alto);
	if (self.innerHeight)
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) 
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	while(ancho > x){
	
		if (self.innerHeight) 
		{
			x = self.innerWidth;
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			
		{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		else if (document.body)
		{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		
		window.resizeBy(+(ancho-x),+(alto-y));
		
	}
	posY=(Math.round(screen.height-(alto))/2);
	posX=(Math.round(screen.width-(ancho))/2);
		moveTo(posX,posY);
		focus();
}


function newwindow(url, name, width, height)
{
	newwindow=window.open(url,name,'width='+width+',height='+height+',toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,top=300,left=300');
	if (window.focus) {newwindow.focus()}
	return false;
}

function exists(v)
{
	return ( typeof(v) != "undefined" );
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function hideFlash()
{
	if (document.getElementById('flashMessage'))
		document.getElementById('flashMessage').style.display='none';
}

function num_imagenes(numero) {
	if (isNaN(numero))
		num = 0;

	for(x = 1; x <= 30; x++)
	{
		if ((obj = document.getElementById('adj_image_' + x)) != null)
			if(parseInt(numero) >= x)
				obj.style.display = '';
			else
				obj.style.display = 'none';
	}			
}

function num_videos(numero) {
	if (isNaN(numero))
		num = 0;

	for(x = 1; x <= 30; x++)
	{
		if ((obj = document.getElementById('adj_video_' + x)) != null)
			if(parseInt(numero) >= x)
				obj.style.display = '';
			else
				obj.style.display = 'none';
	}			
}

function apostar(id, nombre, email, visitado, visitante) {
	if (escape(nombre).length === 0) {
		window.alert('Debe introducir un nombre.');
		return false;
	}
	
	var exp = /^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/;
	if ( ! exp.test(email) || escape(email).length === 0) {
		window.alert('Debe introducir un e-mail.');
		return false;
	}
	
	if (isNaN(visitado) || isNaN(visitante)) {
		window.alert('Debe introducir un resultado.');
		return false;
	}
	
	return popitup('/index.php/porras/votar/' + id + '/' + escape(nombre) + '/' + escape(email) + '/' + visitado + '/' + visitante, 'porra', 600, 500, 0);
}


function stock(modelos){
	//Le quitamos la ultima coma a modelos
	modelos=modelos.substring(0,modelos.length -1);
	id =  document.getElementById('selectMod').value;
	modelos = modelos.split(',');
	for (i=0; i < modelos.length; i++){ 
		modelos[i]= modelos[i].split(' ');
	} 
	for (i=0; i < modelos.length; i++){ 
		if(modelos[i][0] == id)
			if(modelos[i][2] == 0){
				document.getElementById('disponible').innerHTML = '<font style="font-size: 22px; color:#933826;font-variant:small-caps;">No Disponible</font>';
				document.getElementById('cantidad').innerHTML = '';
				document.getElementById('comprar').innerHTML = '';
			}else{
				document.getElementById('disponible').innerHTML = '';
				document.getElementById('cantidad').innerHTML = 'cantidad: &nbsp; &nbsp; <input type="text" class="textogrande" onKeyup="maxStock('+ modelos[i][1]+');" name="cantidad" id="txtCantidad" value="1" maxlength="3" style="width: 32px;"/>';
				document.getElementById('comprar').innerHTML = '<input type="image" src="/img/comprar.gif"/>';
			}
			
	} 
}

function maxStock(maximo){
	if(parseInt(document.getElementById('txtCantidad').value) > maximo)
	document.getElementById('txtCantidad').value = maximo;
}
