// JavaScript Document
function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}
function fadeout(id,cont,c,lim)
{
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer")
	{
		document.getElementById(id+cont).style.filters.alpha.opacity=c*100;
	}
	else
	{
		document.getElementById(id+cont).style.opacity=c;
	}
	c=parseFloat(c)-0.1;
	if(c>0)
	{
		//alert("c>0=ok!");
		t=setTimeout("fadeout('"+id+"','"+cont+"','"+c+"','"+lim+"')",100);
	}
	else
	{
		c=0.0;
		if(browser=="Microsoft Internet Explorer")
		{
			document.getElementById(id+cont).style.filters.alpha.opacity=c*100;
		}
		else
		{
			document.getElementById(id+cont).style.opacity=c;
		}
		if(cont==lim)
		{
			t=setTimeout("gofade('"+id+"','1','"+c+"','"+lim+"')",0);
		}
		else
		{
			cont++;
			t=setTimeout("gofade('"+id+"','"+cont+"','"+c+"','"+lim+"')",0);
		}
		
	}
}

function fadein(id,cont,c,lim)
{
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer")
	{
		c=1;
		document.getElementById(id+cont).style.filters.alpha.opacity=c*100;
	}
	else
	{
		document.getElementById(id+cont).style.opacity=c;
		c=parseFloat(c)+0.1;
	}
	if(c<1)
	{
		//alert("c>0=ok! "+c);
		t=setTimeout("fadein('"+id+"','"+cont+"','"+c+"','"+lim+"')",100);
	}
	else
	{
		c=1;
		if(browser=="Microsoft Internet Explorer")
		{
			document.getElementById(id+cont).style.filters.alpha.opacity=c*100;
		}
		else
		{
			document.getElementById(id+cont).style.opacity=c;
		}
		if(cont==parseInt(lim)+1)
		{
			t=setTimeout("gofade('"+id+"','1','"+c+"','"+lim+"')",6000);
		}
		else
		{
			//cont++;
			t=setTimeout("gofade('"+id+"','"+cont+"','"+c+"','"+lim+"')",6000);
		}
		
	}
}


function gofade(id,cont,c,lim)
{
	//alert(id+' '+cont+' '+c+' '+' '+lim);
	//alert(parseInt(lim)+1);
	if(c==1)
	{
		fadeout(id,cont,c,lim);	
	}
	else
	{
		fadein(id,cont,c,lim);	
	}
}

function fadeoutprods(id,cont,c,lim)
{
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer")
	{
		c=0;
		document.getElementById(id+cont).style.display='none';
	}
	else
	{
		document.getElementById(id+cont).style.opacity=c;
		c=parseFloat(c)-0.1;
	}
	
	if(c>0)
	{
		//alert("c>0=ok!");
		t=setTimeout("fadeoutprods('"+id+"','"+cont+"','"+c+"','"+lim+"')",100);
	}
	else
	{
		c=0.0;
		if(browser=="Microsoft Internet Explorer")
		{
			document.getElementById(id+cont).style.display='none';
		}
		else
		{
			document.getElementById(id+cont).style.opacity=c;
		}
		if(cont==lim)
		{
			t=setTimeout("gofadeprods('"+id+"','1','"+c+"','"+lim+"')",0);
		}
		else
		{
			cont++;
			t=setTimeout("gofadeprods('"+id+"','"+cont+"','"+c+"','"+lim+"')",0);
		}
		
	}
}

function fadeinprods(id,cont,c,lim)
{
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer")
	{
		c=1;
		document.getElementById(id+cont).style.display='inline';
	}
	else
	{
		document.getElementById(id+cont).style.opacity=c;
		c=parseFloat(c)+0.1;
	}
	
	if(c<1)
	{
		//alert("c>0=ok! "+c);
		t=setTimeout("fadeinprods('"+id+"','"+cont+"','"+c+"','"+lim+"')",100);
	}
	else
	{
		c=1;
		if(browser=="Microsoft Internet Explorer")
		{
			document.getElementById(id+cont).style.display='inline';
		}
		else
		{
			document.getElementById(id+cont).style.opacity=c;
		}
		if(cont==parseInt(lim)+1)
		{
			t=setTimeout("gofadeprods('"+id+"','1','"+c+"','"+lim+"')",2000);
		}
		else
		{
			//cont++;
			t=setTimeout("gofadeprods('"+id+"','"+cont+"','"+c+"','"+lim+"')",2000);
		}
		
	}
}


function gofadeprods(id,cont,c,lim)
{
	//alertprods(id+' '+cont+' '+c+' '+' '+lim);
	//alert(parseInt(lim)+1);
	if(c==1)
	{
		fadeoutprods(id,cont,c,lim);	
	}
	else
	{
		fadeinprods(id,cont,c,lim);	
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function getandapplyheight(content1,content2,target)
{
	
	var totHeight1 = document.getElementById(content1).offsetHeight;
	var totHeight2 = document.getElementById(content2).offsetHeight;
	if(totHeight1<totHeight2)
	{
		document.getElementById(target).style.height = totHeight2 +'px';
	}
	else
	{
		document.getElementById(target).style.height = totHeight1 +'px';
	}
	
	
}

function verinum(num,target,dislock)
{
	var num =num;
	var dislock=document.getElementById(dislock);
	var target=document.getElementById(target);
	if(!(isNaN(num)) == false)
	{
		target.value = '';
	}
	else if(num.length==6)
	{
		dislock.disabled=false;
	}
	else
	{
		dislock.disabled=true;
	}
}


function checkmail(email)
{
	
	if(email.match(/\./) && email.match(/@/))
	{
		document.getElementById('descprog').disabled = false;
	}
}
	
	
function checkdown()
{
	var email=document.getElementById('email').value;
	var nombre=document.getElementById('nombre').value;
	var valid=document.getElementById('valid').checked;
	if(email.match(/\./) && email.match(/@/) && nombre!='' && valid==true)
	{
		document.getElementById('descprog').disabled = false;
	}
	else
	{
		document.getElementById('descprog').disabled = true;
	}
}

function checkdate(dia,mes,ano,fecha)
{
	var dia=document.getElementById('dia').value;
	var mes=document.getElementById('mes').value;
	var ano=document.getElementById('ano').value;
	var fecha=document.getElementById('fecha');
	
	if(dia!='' && mes!='' && ano!='')fecha.value=ano+'-'+mes+'-'+dia+' 12:00:00';
}
function degreesToRadians(num) {
	return (num) * Math.PI / 180;
}
function createIEMatrixString(M) {
	return 'M11=' + M.e(1, 1) + ', M12=' + M.e(1,2) + ', M21=' + M.e(2,1) + ', M22=' + M.e(2,2);
}
function rotateElement(e, deg) {
	
	deg_str = deg + "";
	rotate_transform = "rotate(" + deg + "deg)";
	
	e.style["rotation"] = deg_str + "deg"; // CSS3
	e.style.MozTransform = rotate_transform; // Moz
	e.style.OTransform = rotate_transform; // Opera
	e.style.WebkitTransform = rotate_transform; // Webkit/Safari/Chrome
	
	if(Matrix!='undefined')
	{
		matrix_str = createIEMatrixString(Matrix.Rotation(degreesToRadians(deg)));
		filter_str = "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', " + matrix_str + ")";
		e.style.filter = filter_str; // IE 6/7
		e.style.MsFilter = filter_str; // IE 8
		e.style["zoom"] = "1"; // ??? Probably IEs
	}
}

function checkMenu(id)
{
	var tabmenu=new Array();
	tabmenu['catalogo']='catalogo';
	tabmenu['como']='como';
	tabmenu['utildesc']='utildesc';
	tabmenu['pregfreq']='pregfreq';
	tabmenu['soporte']='soporte';
	
	var act = document.getElementById(id);
	if(act.className=='menuprincinact')
	{
		act.className= 'menuprincact';
	}
	else
	{
		act.className= 'menuprincinact';
	}
	var x;
	for(x in tabmenu)
	{
		alert(tabmenu[x]+' - '+id);
		if(id!=tabmenu[x])document.getElementById(tabmenu[x]).className= 'menuprincinact';
	}
	if(menuopen==true)document.getElementById('catalogo').className= 'menuprincact';
}

var blockmenu=false;
var t;
var tt;
function openmenu(id,action)
{
	var menu = document.getElementById(id);
	if(action=='show')
	{
		clearTimeout(tt);
		$("#introinicio").gx({"left":"-=1040"},500);
		blockmenu=true;
		$('#'+id).gx({'height': '200px', 'width': '1040px'}, 250, 'Linear');
		//alert(id+' '+menu.style.display+' '+menu.style.height+' '+menu.style.width);
		t=setTimeout("blockmenu=false;",250);
		//document.getElementById('catalogo').className= 'menuprincact';
	}
	if(action=='hide')
	{
		$("#introinicio").gx({"left":"-=1040"},500);
		tt=setTimeout("blockmenu=true;$('#"+id+"').gx({'height': '0px', 'width': '0px'}, 250, 'Linear');t=setTimeout(\"blockmenu=false;\",250);",150);
		
		//alert(id+' '+menu.style.display+' '+menu.style.height+' '+menu.style.width);
		
		//document.getElementById('catalogo').className= 'menuprincinact';
	}
	//
}

$(window).load(function () {
	$('#catalogobut').bind({
		mouseenter: function() {
			
			//checkMenu('catalogo');
			if(blockmenu==false)openmenu('catalog','show');
		},
		mouseleave: function() {
			//checkMenu('catalogo');
			if(blockmenu==false)openmenu('catalog','hide');
		}
	});
	
});
