// JavaScript Document

var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 0;
offsetY = 20;
var toolTipSTYLE="";

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// * Dependencies * 
// this function requires the following snippets:
// JavaScript/readable_MM_functions/findObj
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}
function mostrarProductos(x){
	capa = findObj(x);
	if(obj = findObj("img" + x)){
		obj.src = (capa.style.display=="block")?"imagenes/cerrado.gif":"imagenes/abierto.gif";
	}
	if(capa){
		capa.style.display = (capa.style.display=="block")?"none":"block";
	}else{
	alert("No se encontro");
	}

}

function borrarcontenido(x){
 if(x.value == "0.00"){
	x.value= ""	 
 }	
}
function inputcolor(x, color){
x.style.borderColor = color;
}

function checarcantidad(x){
if(x.value == ""){
	x.value= "0.00";	
}		
}


function desbloquearMango(x){
var el = document.forms[0].elements;
//alert(x);
//el["cantidadataulfo"].disabled = false;
el["cantidad" + x].disabled = (el["cantidad" + x].disabled)?false:true;
el["calibre" + x].disabled = (el["calibre" + x].disabled)?false:true;
el["calidad" + x].disabled = (el["calidad" + x].disabled)?false:true;	
}

function desbloquear(x){
var el = document.forms[0].elements;
el["cantidad" + x].disabled = (el["cantidad" + x].disabled)?false:true;
el["calidad" + x].disabled = (el["calidad" + x].disabled)?false:true;	
}


function desbloquearCalidad(x, y){
	if(x.selectedIndex == 3)
		document.forms[0].elements[y].disabled = false;
	else
		document.forms[0].elements[y].disabled = true;
}

function checarForma(){
	var el = document.forms[0].elements;
	var checkboxs = false;
	var errors = "Los siguientes campos no son validos:\n";
	var errores = false;
	if(el["nombre"].value == ""){
		errores = true;
		errors += "  ->Debe de ingresar su nombre\n";
	}
	if(el["correo"].value == ""){
		errores = true;
		errors += "  ->Debe de ingresar su correo electronico\n";
	}
	if(el["direccion"].value == ""){
		errores = true;
		errors += "  ->Debe de ingresar su dirección\n";
	}
	if(el["ciudad"].value == ""){
		errores = true;
		errors += "  ->Debe de ingresar su ciudad\n";
	}
	if(el["estado"].value == ""){
		errores = true;
		errors += "  ->Debe de ingresar su estado\n";
	}
	if(el["pais"].selectedIndex == 0){
		errores = true;
		errors += "  ->Debe de selecionar su país\n";
	}
	
	if(el["telefono"].value == ""){
		errores = true;
		errors += "  ->Favor de ingresar su teléfono\n";
	}
	
	if(el["oficina"].selectedIndex == 0){
		errores = true;
		errors += "  ->Debe seleccionar la oficina que realizara la cotización\n";
	}
	
	
	
	for(var i = 0; i < el.length; i++){
		if(el[i].type == "checkbox")
			if(el[i].checked)
				checkboxs = true;
	}
	
	if(!checkboxs){
		errors += "  ->Debe seleccionar al menos un producto a cotizar\n";
		errores = true;
	}
	
	if(errores)
		alert(errors);
	
	return !errores;
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg)
{
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#000000";
    if(!bg) bg = "#FFFFFF";
    var content =
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + 
    '"><td align="center"><font face="sans-serif" color="' + fg +
    '" size="-2">&nbsp\;' + msg +
    '&nbsp\;</font></td></table></td></table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}

