// Banners with fadein and fadeout!
	window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);
	
	var d=document, banners = new Array(), currentBanner=0, ads = new Array(), currentAd=0;

	function so_init() {
		if (!document.getElementsByTagName) 
			return;
		
		var anchors = document.getElementsByTagName("a");
		
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") &&	anchor.getAttribute("rel") == "external")
				anchor.target = "_blank";
		}
		
		if(!d.getElementById || !d.createElement)return;
	
		// set font size!
		// if location has more than 4 slashes, then stop the sizing thing
		slashes = location.href.split('/').length-1;
		var s = readCookie('textWrap');
		if((s != null) && (slashes > 4)) 
			d.getElementById('textWrap').style.fontSize = s+"px";

		// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
		// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	
		// start banners
		if (d.getElementById("imageContainer") != null) {
			banners = d.getElementById("imageContainer").getElementsByTagName("img");
			for (i = 1; i < banners.length; i++) 
				banners[i].xOpacity = 0;
			banners[0].style.display = "block";
			banners[0].xOpacity = .99;
			
			setTimeout(so_xfade, 5000);
		}
	
		// start ads
		if(d.getElementById("adsContainer")!= null) {
			ads = d.getElementById("adsContainer").getElementsByTagName("img");
			for(i=1;i<ads.length;i++) ads[i].xOpacity = 0;
			ads[0].style.display = "block";
			ads[0].xOpacity = .99;
			
			setTimeout(ads_xfade,45000);			
		}	
	}
	
	function so_xfade() {
		cOpacity = banners[currentBanner].xOpacity;
		nIndex = banners[currentBanner+1]?currentBanner+1:0;
	
		nOpacity = banners[nIndex].xOpacity;
		
		cOpacity-=.03; 
		nOpacity+=.03;
		
		banners[nIndex].style.display = "block";
		banners[currentBanner].xOpacity = cOpacity;
		banners[nIndex].xOpacity = nOpacity;
		
		setOpacity(banners[currentBanner]); 
		setOpacity(banners[nIndex]);
		
		if(cOpacity<=0) {
			banners[currentBanner].style.display = "none";
			currentBanner = nIndex;
			setTimeout(so_xfade,5000);
		} else {
			setTimeout(so_xfade,70);
		}
		
		function setOpacity(obj) {
			if(obj.xOpacity>.99) {
				obj.xOpacity = 1;
				return;
			}
			obj.style.opacity = obj.xOpacity;
			obj.style.MozOpacity = obj.xOpacity;
			obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		}
		
	}
	
	function ads_xfade() {
		cOpacity = ads[currentAd].xOpacity;
		nIndex = ads[currentAd+1]?currentAd+1:0;
	
		nOpacity = ads[nIndex].xOpacity;
		
		cOpacity-=.03; 
		nOpacity+=.03;
		
		ads[nIndex].style.display = "block";
		ads[currentAd].style.display = "block";
		ads[currentAd].xOpacity = cOpacity;
		ads[nIndex].xOpacity = nOpacity;
		
		setOpacity2(ads[currentAd]); 
		setOpacity2(ads[nIndex]);
		
		if(cOpacity<=0) {
			ads[currentAd].style.display = "none";
			currentAd = nIndex;
			setTimeout(ads_xfade,45000);
		} else {
			setTimeout(ads_xfade,70);
		}
		
		function setOpacity2(obj) {
			if(obj.xOpacity>.99) {
				obj.xOpacity = 1;
				return;
			}
			obj.style.opacity = obj.xOpacity;
			obj.style.MozOpacity = obj.xOpacity;
			obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
		}
		
	}

// Flash functions

	function commitFlashObject(_obj, _container){
		var _output=_paramoutput=_src=_ver="";
		for(var _cO in _obj){
			_output+=_cO+"=\""+_obj[_cO]+"\" "
			_paramoutput+="<param name="+_cO+" value=\""+_obj[_cO]+"\">";
			if(_cO=="movie")_src="src=\""+_obj[_cO]+"\"";
			if(_cO=="version")_ver=_obj[_cO];
		}
		if(_ver=="")_ver="8,0,0,0"
		var ihtm="<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase="+location.protocol+"//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+_ver+" "+_output+">\n"
		ihtm+=_paramoutput+"\n"
		ihtm+="<embed "+_src+" pluginspage="+location.protocol+"//www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash "+_output+">\n";
		ihtm+="</embed>\n";
		ihtm+="</object>\n";
		document.getElementById(_container).innerHTML=ihtm
	}

// Cookies Management

	function createCookie(name,value,days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
	        var c = ca[i];
	        while (c.charAt(0)==' ') c = c.substring(1,c.length);
	        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	    return null;
	} 

// Boxes onclick events

	function clearField(field, value) {
		if(field.value==value)
			field.value = '';
	}
	
	function blurField(field, value) {
		if(field.value=='')
			field.value=value;
	}
	
	function increaseFont(div) {
		document.getElementById(div).style.fontSize = '18px';
		createCookie('textWrap',18);
	}

	function resetFont(div) {
		document.getElementById(div).style.fontSize = '14px';
		createCookie('textWrap',14);
	}

	function decreaseFont(div) {
		document.getElementById(div).style.fontSize = '12px';
		createCookie('textWrap',12);
	}

// Validations

	function imposeMaxLength(Object, MaxLen)
	{
		var int_value, out_value;
		
		if (Object.value.length > MaxLen)
		{
			in_value = Object.value;
			out_value = in_value.substring(0,MaxLen);
			Object.value = out_value;
			return false;
		}
		
		return true;
	}

	function echeck(str, message) {
		var filter = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
		
		if (filter.test(str))
			return true;
		
		alert(message);			
		return false;
	}
	
	function ncheck(str, message) {
		var NameStartChar = "A-Za-z:_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D"+
                    "\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF"+
                    "\uF900-\uFDCF\uFDF0-\uFFFD\u010000-\u0EFFFF";
		var NameChar = NameStartChar+"\\-\\0-9\u00B7\u0300-\u036F\u203F-\u2040";
		var filter = "^["+NameStartChar+"]["+NameChar+" ]*$";
		
		if (RegExp(filter).test(str) && (str.indexOf('...')==-1))
			return true;
		
		alert(message);		
		return false;
	}

	function validateSubscription(form) {
		if (ncheck(form.name.value, "Invalid Name")==false){
			form.name.focus();
			return false;
		} 

		if (echeck(form.email.value, "Invalid E-mail")==false){
			form.email.focus();
			return false;
		}
		
		return true;
	}

	function validateSuscripcion(form) {
		if (ncheck(form.name.value, "El nombre no es correcto. Intente de nuevo.")==false){
			form.name.focus();
			return false;
		} 

		if (echeck(form.email.value, "El email no es correcto. Intente de nuevo.")==false){
			form.email.focus();
			return false;
		}
		
		return true;
	}

// Special FX

	function setOpacity(obj, opacity) {
	  opacity = (opacity == 100) ? 99.999 : opacity;
	  obj.style.opacity = opacity /100;
	}
	
	function fadeOut(objId,opacity) {
	  if (document.getElementById) {
	    obj = document.getElementById(objId);
	    if (opacity >= 10) {
	      setOpacity(obj, opacity);
	      opacity -= 10;
	      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 200);
	    }
		else {
			obj.style.opacity=0;
			obj.style.display='none';
			obj.onclick = null;			
		}
	  }
	}

	function fadeIn(objId,opacity) {
	  if (document.getElementById) {
	    obj = document.getElementById(objId);
	    if (opacity <= 99) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('" + objId + "'," + opacity + ")", 200);
		} 
		else {
			obj.style.cursor = 'pointer';
			obj.title = 'Click to hide'
			obj.onclick = function(){ fadeOut(objId, 100); }
		}
	  }
	}

	function showDiv(id) {
	    document.getElementById(id).style.display = 'block';
	}
	
	function dropDown(id) {
	    document.getElementById(id).style.display = 'block';
		// moveDown(id, -120, 120);
	}

	function moveDown(id, y, h) {
		if(y < 0) {
			obj = document.getElementById(id);
			top = Math.round(y)	+ Math.round(h / 5); 
			obj.style.top = Math.round(top)+'px';
			setTimeout("moveDown('"+id+"', '"+top+"', '"+h+"')",150);	
		}
	}
	
	function dropUp(id) {
		moveUp(id, 0, 120);
	}

	function moveUp(id, y, h) {
		if(y >= -h) {
			obj = document.getElementById(id);
			top = y - Math.round(h / 5); 
			obj.style.top = top+'px';
			setTimeout("moveUp('"+id+"', '"+top+"', '"+h+"')",150);	
		}
		else
			document.getElementById(id).style.display = 'none';
	}

