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);	
  }
  if(objItem == null) return false;
  return objItem;
}

function getName (object)
{
  return (object.name) ? object.name : object.id;
}

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 alterDivs (obj)
{
  while (obj)
  {
    if (obj.tagName == "DIV")
    {
      obj.className = "MENUITEM";
      obj.onmouseover = menuItemHighlight;
      obj.onmouseout = menuItemDeHighlight;
      obj.style.cursor = "default";
    }
    else
      alterDivs (obj.firstChild);
    
    obj = obj.nextSibling;
  }    
}

function createRollOver (divId, minWidth, minHeight)
{
  div = getObject (divId);
  div.className = "MENUTITLE";
  div.onmouseover = menuHighlight;
  div.onmouseout = menuPreDeHighlight;
  div.style.cursor = "default";
  
  menu = getObject (divId + "_menu");
  menu.className = "MENU_SHOW"; 
  
  if (minWidth && menu.offsetWidth < minWidth)
    menu.style.width = minWidth;

  if (minHeight && menu.offsetHeight < minHeight)
    menu.style.height = minHeight;

  menu.maxHeight = menu.offsetHeight;
  menu.time = 10;
  menu.acc = menu.maxHeight / Math.pow (menu.time / 2, 2);
  menu.step = 0;
  menu.thisHeight = 0;
  menu.style.top = -menu.offsetHeight + "px";
  
  menu.onmouseover = function()
  {
    my_parent = getObject (divId);
    my_parent.onmouseover();
  }
  
  menu.onmouseout = function()
  {
    my_parent = getObject (divId);
    my_parent.onmouseout();
  }

  alterDivs (menu.firstChild);

	container = getObject (divId + "_container");
	container.style.visibility = 'visible';

}

function menuHighlight ()
{
  if (this.my_timer)
  {
    clearTimeout (this.my_timer);
    this.my_timer = null;
  }
  
  if (this.className != "MENUTITLE_SELECTED")
  {
    this.className = "MENUTITLE_SELECTED";
    
    objMenu = getObject (getName (this) + "_menu");
    
    if (objMenu.my_timer)
    {
      clearTimeout (objMenu.my_timer);
      objMenu.my_timer = null;
    }

    objMenu.direction = 1;
    objMenu.style.zIndex = 20;
	
	nav_box_back();
	
    objMenu.my_timer = setTimeout ("menuScroll ('" + getName (objMenu) + "')", 100);
  }
}

function menuScroll (divId)
{
  div = getObject (divId);
  //alert(divId);
  
  //ShowDiv(window, divId, '');
  
  if (div.my_timer)
  {
    clearTimeout (div.my_timer);
    div.my_timer = null;
  }
  
  div.step += div.direction; 
  
  if (div.step < (div.time / 2))
  {
    div.thisHeight = .5 * div.acc * Math.pow (div.step, 2);
    div.style.top = (-div.offsetHeight + div.thisHeight) + "px";
  }
  else
  {
    div.thisHeight = (div.maxHeight) - .5 * div.acc * Math.pow (div.time - div.step, 2);
    div.style.top = (-div.offsetHeight + div.thisHeight + 4) + "px";
  }

  if (((div.direction == 1) && (div.step < div.time)) || ((div.direction == -1) && (div.step > 0)))
    div.my_timer = setTimeout ("menuScroll ('" + divId + "')", 20);
  
  //if(div.direction == 1)
    //nav_box_back();
}

function menuPreDeHighlight ()
{
  this.my_timer = setTimeout ("menuDeHighlight ('" + getName (this) + "')", 200); 
}

function menuDeHighlight (divId)
{
  obj = getObject (divId);
  clearTimeout (obj.my_timer);
  obj.my_timer = null;

  obj.className = "MENUTITLE";
  
  objMenu = getObject (divId + "_menu");
  objMenu.style.zIndex = 19;
  
  if (objMenu.my_timer)
    clearTimeout (objMenu.my_timer);

  objMenu.direction = -1;
  objMenu.my_timer = setTimeout ("menuScroll ('" + divId + "_menu')", 10);
  
 
}

function menuItemHighlight()
{
  this.className = "MENUITEM_SELECTED";
}

function menuItemDeHighlight()
{
  this.className = "MENUITEM";
}

function createRollOvers ()
{
	createRollOver ('menu_products',0,190);
	createRollOver ('menu_development',0,150);
	createRollOver ('menu_service',0,140);
	createRollOver ('menu_company',0,150);
	createRollOver ('menu_dnie',0,220);
	createRollOver ('menu_contact',0,220);
}


function nav_box_forward()
{
  objNavTree = getObject ("nav_tree");
  objNavTree.style.zIndex = 20;
  objtop_link = getObject ("top_link");
  if(objtop_link)
  {
  objtop_link.style.visibility = "visible";
  objtop_link.style.zIndex = 20;
  }
}

function nav_box_back()
{
  objNavTree = getObject ("nav_tree");
  objNavTree.style.zIndex = 17;
  objtop_link = getObject ("top_link");
  if(objtop_link)
  {
  objtop_link.style.visibility = "hidden";
  objtop_link.style.zIndex = 17;
  }

}






function set_whitebox_height()
{
	rightbox = getObject("right_box");
	contentbox = getObject("content_box");
	white_box =  getObject("whitebox");
	
	
	//Compensate for banner
	objNavTree = getObject ("nav_tree");
	objMainTitle = getObject("main_title");
	if(objNavTree.offsetHeight > 60)
	{
		offset_ratio = (navigator.appName == "Microsoft Internet Explorer") ? 1.5 : 1;
		//alert("objNavTree.offsetHeight = " + objNavTree.offsetHeight);
		//alert("objMainTitle.offsetTop = " + objMainTitle.offsetTop)
		objMainTitle.style.marginTop = objNavTree.offsetHeight * offset_ratio;
	}
	
	if(rightbox)
	{
		maxheight = Math.max(rightbox.offsetHeight, contentbox.offsetHeight);
	}
	else
	{
		maxheight = contentbox.offsetHeight;
	}
	//alert(maxheight);
	white_box.style.height = maxheight + 200;
}


/*
function set_home_boxes()
{
	if(!getObject("right_box"))
	{
		home_prbox = getObject("home_product_box");
		home_pvbox = getObject("home_pv_box");
		home_adbox = getObject("home_ad_box");
		contentbox = getObject("content_box");
		
		home_prbox.style.marginRight = "0px";
		
		smallbox_w = (contentbox.offsetWidth / 2) - 30;
		home_pvbox.style.width = smallbox_w;
		home_adbox.style.width = smallbox_w;
		
		return;
	}
	
	rightbox = getObject("right_box");
	contentbox = getObject("content_box");
	home_pvbox = getObject("home_pv_box");
	home_adbox = getObject("home_ad_box");
	newsbox_obj = getObject("newsbox");
	
	max_width = rightbox.offsetLeft - contentbox.offsetLeft;
	
	smallbox_w = (max_width / 2) - 30;
	home_pvbox.style.width = smallbox_w;
	home_adbox.style.width = smallbox_w;
	
	max_box_height = Math.max(home_pvbox.offsetHeight, home_adbox.offsetHeight);
	home_pvbox.style.height = max_box_height;
	home_adbox.style.height = max_box_height;
	
	box_bottom = home_adbox.offsetTop + max_box_height;
	
	newsbox_obj.style.height = box_bottom - rightbox.offsetTop;
	
	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 form_popup(form_id, product)
{
	uri = "form.php?form_id=" + form_id;
	
	if(product && product.length != 0)
	{
		uri += "&product=" + product;
	}
	
	launch(uri, "form_popup", "height=500,width=500,channelmode=0,dependent=0,directories=0,fullscreen=0,location=1,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0", "myWindow");
	
	return;
}
function popup(url,title)
{
	//launch(url, title,  "height=400,width=700,channelmode=0,dependent=0,directories=0,fullscreen=0,location=1,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0", "myWindow2");
	window.open(url, "mywindow2","height=500,width=700,channelmode=0,dependent=0,directories=0,fullscreen=0,location=1,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0");
}
function form_popup_ssl(form_id, product)
{
	uri = "http://www.c3po.es/form.php?form_id=" + form_id;
	
	if(product && product.length != 0)
	{
		uri += "&product=" + product;
	}
	
	launch(uri, "form_popup", "height=400,width=500,channelmode=0,dependent=0,directories=0,fullscreen=0,location=1,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0", "myWindow");
	
	return;
}


function faq_popup(faq_id, faq_arr, faq_producto, lang)
{
	uri = "faq.php?faq_id=" + faq_id + "&faq_arr=" + faq_arr + "&faq_producto=" + faq_producto + "&lang=" + lang + "#" + faq_id;
	
	launch(uri, "faq_popup", "height=400,width=500,channelmode=0,dependent=0,directories=0,fullscreen=0,location=1,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0", "myWindow");
	
	return;
}

function drop_item(id_producto)
{
	document.forms.cart_controls.id_producto.value = id_producto;
	document.forms.cart_controls.form_action.value = 'drop_item';
	document.forms.cart_controls.submit();
}

function set_qty(id_producto, qty)
{
	if(qty == 0)
	{
		drop_item(id_producto);
		return;
	}
	document.forms.cart_controls.id_producto.value = id_producto;
	document.forms.cart_controls.qty.value = Math.floor(qty);
	document.forms.cart_controls.form_action.value = 'set_qty';
	document.forms.cart_controls.submit();
}

function dump_cart(conf_text)
{
	if(!confirm(conf_text)) return;
	document.forms.cart_controls.form_action.value = 'dump';
	document.forms.cart_controls.submit();
}


function order_1_repeat_data()
{
	f = document.forms.order_1;
	
	f.ship_name.value = f.name.value;
	f.ship_company.value = f.company.value;
	f.ship_address.value = f.address.value;
	f.ship_cp.value = f.cp.value;
	f.ship_city.value = f.city.value;
	f.ship_phone.value = f.phone.value;
	
	return;
}


function modify_cart()
{
	f = document.forms.order_1;
	
	f.modify_cart.value = 1;
	
	f.submit();
	
	return;
}

function ocultar(nombreCapa){

document.getElementById(nombreCapa).style.display="none";
}

function mostrar(nombreCapa){
document.getElementById(nombreCapa).style.display="block";
}

function canvia(nombreCapa){
if (document.getElementById(nombreCapa).style.display=="block")
	ocultar(nombreCapa);
else
	mostrar(nombreCapa);
}

