function valida(theform)
{
  if(theform.name.value == '') { alert('Nombre obligatorio'); theform.name.focus(); return false;}
  if(theform.empresa.value == '') { alert('Empresa obligatoria'); theform.empresa.focus(); return false;}
  if(theform.poblacion.value == '') { alert('Población obligatoria'); theform.poblacion.focus(); return false;}    
  if(theform.pais.value == 'España')
  {    
    if(parseInt(parseFloat(theform.provincia.value)) != parseInt(parseFloat(theform.cp.value.substr(0,2)))) { alert('Provincia y Código Postal no se corresponden'); theform.cp.focus(); return false;}
    if(theform.cp.value.length != 5) { alert('Código Postal incorrecto'); theform.cp.focus(); return false; }
  }
  var filter=/^[A-Za-z][A-Za-z0-9_.ñÑ-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.-]+[A-za-z]$/;
   if(filter.test(theform.email.value) == false) { alert('Debe introducir email válido'); theform.email.select(); return false; }
  if(theform.telefono.value == '') { alert('Teléfono obligatorio'); theform.telefono.focus(); return false;}
  if(theform.message.value == '') { alert('Mensaje obligatorio'); theform.message.focus(); return false;}
}

function getObject(objectName)
{	
  var objItem;
  
  if (document.all)
    objItem = document.all[objectName];
  else
  {
    objItem = document.getElementById(objectName);
    if (objItem==null)
      objItem= document.getElementsByName(objectName)[0];
    if (document.getElementsByName(objectName).length>1)
      objItem=document.getElementsByName(objectName);	
  }

  return objItem;
}

function getName (object)
{
  return (object.name) ? object.name : object.id;
}

function page_setup()
{
	topbar_obj = getObject("topbar");
	linkbar_obj = getObject("linkbar");
	footer_obj = getObject("footer");
	content_obj = getObject("content");
	fs_obj = getObject("fs");
	//buscar_container_obj = getObject("buscar_container");
	
	//buscar_container_obj.style.top = linkbar_obj.offsetTop + 1;
	
	total_noncontent_height = topbar_obj.offsetHeight + linkbar_obj.offsetHeight + footer_obj.offsetHeight;
	content_obj.style.height = fs.offsetHeight - total_noncontent_height;
	//alert(total_noncontent_height);
}

function search(s)
{
	//alert("Este dispositivo está en desarrollo.");
	location.href = "buscar.php?s=" + escape(s);
	return;
}

function fetch_item(ref)
{
	//alert(ref + "\n\nEste dispositivo está en desarrollo.");
	launch('item_select.php?ref=' + escape(ref), 'popup', popup_config, 'myWindow');
}

function msg_fabricante(id_fabricante, id_page)
{
	launch('fabricante_info.php?id_fabricante=' + id_fabricante + '&id_page=' + id_page, 'popup', popup_config, 'myWindow');
}

function cart_submit(id_fabricante)
{
	launch('cart_submit.php?id_fabricante=' + id_fabricante, 'popup', popup_config, 'myWindow');
}

function roll(obj, NewClassName)
{
	obj.className = NewClassName
}

var popup_config = 'height=500,width=500,screenX=100,left=100,screenY=100,top=100,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0';

function orange_item_button(pagina_origen,ref)
{
	//alert("Este dispositivo está en desarrollo.");
	//Ignore pagina_origen.
	launch('../item_select.php?ref=' + ref, 'popup', popup_config, 'myWindow');
	
}

function page_info(id_paginas)
{
	launch('page_message.php?id_paginas=' + id_paginas, 'popup', popup_config, 'myWindow');
}

function nothing(x)
{
	return;
}

function launch(newURL, newName, newFeatures, orgName) {
  var remote = open(newURL, newName, newFeatures);
  if (remote.opener == null) // if something went wrong
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
}



function add_2_cart(id)
{
	location.href = "add_carro_popup.php?id=" + id;
	return;
}

function view_cart()
{
	opener.parent.location.href = "carro.php";
	window.close();
	return;
}


function item_message(ref)
{
	location.href = "item_message.php?ref=" + ref;
	return;
}


function set_checkbox(form_name, checkbox_name, value) {

	if(value == "") return;
	
	var checkbox = eval("document." + form_name + "." + checkbox_name);
	
	checkbox.checked = true;
		
	return;	

}

function set_combobox(form_name, select_name, value) {

	if(value == "") return;
	
	var selector = eval("document." + form_name + "." + select_name);
	var num_options = selector.options.length;
	
	for (i=0; i<num_options; i++) {
	
		option_val = selector.options[i].value;
		
		if (option_val == value) selector.options[i].selected = true;
	
	}
	
	return;	

}



function update_qty(id, qty)
{
	location.href = "carro.php?form_action=set_qty&id=" + id + "&qty=" + qty;
	
	return;
}

function drop_item(id)
{
	location.href = "carro.php?form_action=drop_item&id=" + id;
	
	return;
}

function dump_cart()
{
	if(confirm("¿Está seguro que desea eliminar todos los artícuos?"))
	{
		location.href = "carro.php?form_action=dump";
	}
	return;
}
