//document.write("<title>Oster</title>")
//alert(window.location.protocol+"//"+window.location.hostname)
/*---------------------*/
/* FUNCIONES GENERALES */
/*---------------------*/
var isIE, isGecko, isSafari, isKhtml
browser = navigator.userAgent.toLowerCase();
isIE = (document.all)? true : false;
isGecko = (browser.indexOf('gecko') > -1)? true : false;
isKhtml = (browser.indexOf('safari') > -1) || (browser.indexOf('kde') > -1)? true : false;
isOther = (!isIE && !isGecko && !isKhtml)? true : false;
isMac = (browser.indexOf('mac') > -1)? true : false;
isOsx = (browser.indexOf('os x')>-1||browser.indexOf('osx')>-1) ? true : false;

function popup(url,ancho,alto,id,extras){
	var left = (screen.availWidth-ancho)/2;
	var top = (screen.availHeight-alto)/2;
	if(extras!=""){extras=","+extras;};
	var ventana = window.open(url,id,'width='+ancho+',height='+alto+',left='+left+',top='+top+',screenX='+left+',screenY='+top+extras);
	//var bloqueado = "AVISO:\n\nPara ver este contenido es necesario que desactive\nel Bloqueo de Popups (ventanas) para este Sitio."
	var bloqueado = "WARNING:\n\nIn order to use this functionality, you need\nto deactivate Popup Blocking."
	if(ventana==null || typeof(ventana.document)=="undefined") alert(bloqueado);
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
	{
		if(src_img_seccion!=x.oSrc)
		{
		x.src=x.oSrc;
		}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
	 {
	 	document.MM_sr[j++]=x; 
		if(!x.oSrc) x.oSrc=x.src; 
		x.src=a[i+2];
	}//x.src=x.oSrc
}

function cambiarImagen(nombreImg, pathAndFile)
{
	img = MM_findObj(nombreImg)
	img.src = pathAndFile
}



function calcPosHoriz(){
	var ancho = (isIE)? document.body.clientWidth : window.innerWidth; // ancho de browser disponible
	var ancho_minimo = 765
	var layers = [ // layers a ubicar [nombre, pos x, pos y, condicion a chequear]
		['menu_productos',-329,130,true],
		['menu_quienes',-228,123,true],
		['menu_nuevos_productos',105,130,true],
		['layer_prod_detalle',0,( !(isMac && isIE)? 79 : 10 ),true],
		['layer_contacto',-100,90, !(isMac && isIE) ],
		['layer_legales',-100,90, !(isMac && isIE) ],
		['layer_privacidad',-100,90, !(isMac && isIE) ],
		['menu_servicios',-98,123, !(isMac && isIE) ]
	]
	for( var i = 0; i < layers.length; i++){
		if( layers[i][3] == true ){ // condicion
			obj = MM_findObj( layers[i][0] ); // objeto
			if( obj != null ){
				if(ancho>ancho_minimo){
				obj.style.left = (ancho/2) + layers[i][1]; 
				}
				else
				{obj.style.left = (ancho_minimo/2) + layers[i][1]; // ubicacion X
				}
				
				obj.style.top = layers[i][2]; // ubicacion
			}
		}
	}
}

/*-----------------------------------*/
/* MANIPULACION DEL MENU DESPLEGABLE */
/*-----------------------------------*/
var timeout_menu_productos, timeout_menu_quienes, timeout_menu_servicios, timeout_menu_nuevos_productos;

function cambiarImagenCondicional(nombre_menu)
{
	obj = MM_findObj(nombre_menu);
	//alert(nombre_menu)
	switch(true){
			case isGecko: 
				if(obj.style.MozOpacity<0.9){alert(obj.style.MozOpacity);}
				break;
			case isKhtml: 
				if(obj.style.KhtmlOpacity<0.9){alert(obj.style.KhtmlOpacity)} 
			 	break;
		}
	/*if(obj.style.display=='none')
	{
		alert("tiene que cambiar");
		//MM_swapImgRestore()
	}*/
}

function desplegarOcultarMenu(nombre)
{
	obj = MM_findObj(nombre);
	if(obj.style.display=='none')
	{
		desplegarMenu(nombre);
		mantenerDesplegado(nombre);
	}
	else
	{
		esperaryOcultar(nombre);
	}
}

function cambiarImagenMenu(nombre)
{
	obj = MM_findObj(nombre);
	if(obj.style.display=='none')
	{
		MM_swapImgRestore()
	}
}

function desplegarMenu(nombre){
	obj = MM_findObj(nombre);
	if(!isMac || isOsx )
	{
		switch(true){
			case isIE: obj.style.filter = 'alpha(opacity = 0)'; break;
			case isGecko: obj.style.MozOpacity = 0; break;
			case isKhtml: obj.style.KhtmlOpacity = 0; obj.style.Opacity = 0; break;
		}
		obj.style.display = 'inline';
		obj.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color='gray', Direction=135, Strength=2);";
		fadeIn(nombre, 1);
	}
	else
	{
		obj.style.display = 'inline';
	}
}

function fadeIn(nombre , valor){
	if( valor<10 ) {
		obj = MM_findObj(nombre);
		switch(true){
			case isIE: obj.style.filter = 'alpha(opacity = '+ (valor*10) +')'; break;
			case isGecko: obj.style.MozOpacity = (valor /10); break;
			case isKhtml: obj.style.KhtmlOpacity = (valor /10); obj.style.opacity = (valor /10); break;
		}
		valor++;
		if(valor > 0 && isIE && !isMac) obj.style.filter += "progid:DXImageTransform.Microsoft.Shadow(color='gray', Direction=135, Strength=2)";
		setTimeout('fadeIn( \''+nombre+'\' , '+valor+' )' , 20);
	}
}

function ocultarMenu(nombre){
	obj = MM_findObj(nombre);
	if(!isMac || isOsx )
	{
	fadeOut(nombre,2);
	}
	else
	{
		obj.style.display = 'none';
	}
	/*
		if(window.location.pathname=='/' || window.location.pathname=='/default.asp')
	{
		obj_rotar1 = MM_findObj('rotar_img')
		obj_rotar2 = MM_findObj('rotar_flash')
		obj_rotar1.style.display = 'none';
		obj_rotar2.style.display = 'inline';
	}
	*/
}

function fadeOut(nombre , valor){
	obj = MM_findObj(nombre) ;
	if( valor > 1 ) {
		switch(true){
			case isIE: obj.style.filter = 'alpha(opacity = '+valor+'0)'; break;
			case isGecko: obj.style.MozOpacity = (valor /10); break;
			case isKhtml: obj.style.KhtmlOpacity = (valor /10); obj.style.Opacity = (valor /10); break;
		}
		valor--;
		setTimeout('fadeOut( \''+nombre+'\' , '+valor+' )' , 20);
	}else{
		obj.style.display='none';
	}
}

function esperaryOcultar(nombre){
	eval("timeout_"+nombre+" = setTimeout('ocultarMenu(\\'"+nombre+"\\')',1)");
}



function mantenerDesplegado(nombre){
	eval("clearTimeout(timeout_"+nombre+")");
}

function menuSeleccionar(obj){
	with(obj.style){
		if(isIE && !isMac){
			filter = "progid:DXImageTransform.Microsoft.alpha(opacity=100)   progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#FFFFFF,EndColorStr=#ACC7DB)";
		}else{
			backgroundColor = '#CEE6F4';		
		}
		borderColor = '#639CC0';
	}
}
function menuDeseleccionar(obj){
	with(obj.style){
		if(isIE && !isMac){
			filter = "";
		}else{
			backgroundColor = '#E7F2F8';
		}
		borderColor = '#E7F2F8';
	}
}



/*-----------------------------*/
/* VALIDACIONES DE FORMULARIOS */
/*-----------------------------*/
function emailvalido(obj,nombre) 
{
	msg=""; 
	if(obj.value!="")
	{
		var reg1=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
		var reg2=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
		if(reg1.test(obj.value)||!reg2.test(obj.value))msg="\n* "+nombre+" debe ser un  email.";
	}
	return msg;
}

function completo(obj,nombre,tipo)
{
	if(tipo=='int')
	{
		if((obj.value=='')||(isNaN(obj.value)))return "\n* "+nombre+" debe ser un número."; 
		return "";
	}
	else
	{
		if(obj.value=='')
		{return "\n* "+nombre+" debe ser completado."; }
		return "";
	}
}

function telefonovalido(obj,nombre){var reg=/\d{3,}(.?\d{3,})+/; if((obj.value!="")&&!reg.test(obj.value)){return "\n* "+nombre+" debe ser un número de teléfono";}else{return "";}}




/*------------------------*/
/* MANIPULACION DE LAYERS */
/*------------------------*/
var layers_footer = ['layer_contacto','layer_legales','layer_privacidad','layer_prod_detalle'];
var timeout_layer_contacto, timeout_layer_legales, timeout_layer_privacidad ;

function mostrar_layer(nombre){
	/* OCULTO LOS OTROS QUE ESTÉN ACTIVOS */
	for(var i = 0; i < layers_footer.length; i++){
		if(nombre != layers_footer[i]){
			obj = MM_findObj(layers_footer[i]);
			obj.style.display = 'none';
		}
	}

	/** si esta en la home detener rotador**/
	/*
	if(window.location.pathname=='/' || window.location.pathname=='/default.asp')
	{
		obj_rotar1 = MM_findObj('rotar_img')
		obj_rotar2 = MM_findObj('rotar_flash')
		obj_rotar1.style.display = 'inline';
		obj_rotar2.style.display = 'none';
	}
	*/
	/* MUESTRO EL QUE PIDIÓ */
	obj = MM_findObj(nombre);
	if(obj.innerHTML==''){
		cargar_layer(nombre)
	}else{
		// excepcion para info de producto (ahora en popup)
		if(nombre=="layer_prod_detalle" && isMac && isIE){ 
			ancho = 326;
			alto = 330;
			win = popup('about:blank',ancho,alto,'winProducto','scrollbars=no');
			win.document.write('<html><head><link href="include/estilos.css" rel="stylesheet" type="text/css"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Oster</title><head><body scroll="no" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'+obj.innerHTML+'</body></html>');
			win.document.close();
			if(isIE && !isMac) win.location.reload();
		}else{
			desplegarMenu(nombre)
		}
		//obj.style.display = 'inline';
		//obj.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color='gray', Direction=135, Strength=7)";
	}
}
function cargar_layer(nombre){
	document.body.style.cursor = "wait";
	var xmlhttp = false;
	var url = nombre + '.asp';
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions and security blocked creation of the objects.
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (E) { xmlhttp = false; } }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp = new XMLHttpRequest();
	if (!xmlhttp){ 
	//if(true){ //para debuguear!
		//alert("Esta funcionalidad no está disponible en su Browser.\nPor favor, actualícelo y/o reduzca las configuraciones de Seguridad y vuelva a intentarlo.");
		popup(nombre+'_popup.asp', 475,360,'win'+nombre,'scrollbars=no');
		document.body.style.cursor ="default";
	}else{
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				document.body.style.cursor ="default";
				//alert(nombre);
				obj = MM_findObj(nombre);
				obj.innerHTML = xmlhttp.responseText;
				desplegarMenu(nombre);
				//obj.style.display = 'inline';
				//obj.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color='gray', Direction=135, Strength=7)";
			}
		}
		xmlhttp.send(null);
	}
}

function ocultar_layer(nombre){
	ocultarMenu(nombre);
	//obj = MM_findObj(nombre);
	//obj.style.display = 'none';
}


/*---------------------------------------*/
/* VALIDACION DEL FORMULARIO DE CONTACTO */
/*---------------------------------------*/
function enviar_form_contacto(){
	if(document.form_contacto){
		errColor='#FFB0B0'
		d = document.form_contacto
		for(i=0;i<d.length;i++) d.elements[i].style.backgroundColor='';
		error=""
		error += completo(d.nombre,"NOMBRE")
		error += completo(d.apellido,"APELLIDO")
		error += completo(MM_findObj('email'),"E-MAIL")
		error += emailvalido(MM_findObj('email'),"E-MAIL")
		error += completo(MM_findObj('email2'),"CONFIRMACIÓN DE E-MAIL")
		error += emailvalido(MM_findObj('email2'),"CONFIRMACIÓN DE E-MAIL")
		if(MM_findObj('email').value!=MM_findObj('email2').value)
			error += "\n* EMAIL Y CONFIRMACION DE EMAIL deben ser el iguales."
		error += completo(MM_findObj('asunto'),"ASUNTO")
		error += completo(MM_findObj('mensaje'),"MENSAJE")
		if(error!=""){
			alert("FORMULARIO INCOMPLETO:\t\n"+error);
		}else{
			obj = MM_findObj('layer_contacto');
			obj.style.display = 'none';
			d.submit();
		}
	}
}
/*---------------------------------------*/
/* MANIPULACION DE CAMPOS DE TEXTO       */
/*---------------------------------------*/
function aplicarTexto(campo,texto){
	obj = MM_findObj(campo);
	obj.innerHTML = texto;
}

<!--
var src_img_seccion
	src_img_seccion = window.location.protocol+"//"+window.location.hostname+"/"+"images/nav_bt_productos.gif"

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	if(selObj.options[selObj.selectedIndex].value!=0)
	{
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	}
	else(alert("Por favor\nSeleccione una opción válida."))
  if (restore) selObj.selectedIndex=0;
}
//-->