String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'') };
var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
navHover = function() 
 { 
    if (document.getElementById("main_menu"))
    {
        var lis = document.getElementById("main_menu").getElementsByTagName("LI"); 
        for (var i=0; i<lis.length; i++) 
        { 
            lis[i].onmouseover=function() 
            {
            
                this.className+=" iehover"; 
            } 
            
            lis[i].onmouseout=function() 
            { 
                this.className=this.className.replace(new RegExp(" iehover\\b"), ""); 
            } 
        } 
    }
} 
if (window.attachEvent) 
	window.attachEvent("onload", navHover); 


var menuEng = new Class({
    initialize: function(element){
		this.speed = 40;
		this.thisElement = element;
		this.timer = null;
		this.direction =  null;
		this.width = document.getElementById('submenu2').offsetWidth;
		this.contW = document.getElementById('menuCont').offsetWidth;
	},
	moveLeft: function(){
		var pos = this.thisElement.getStyle('left').toInt();

		if (this.width-this.contW+pos >= 0)
		{
			this.thisElement.setStyle( 'left', ( pos + -10 ) + 'px' );
			this.timer = this.moveLeft.delay(this.speed, this);
		}
	},
	moveRight: function(){
		var pos = this.thisElement.getStyle('left').toInt();
		if (pos<0)
		{
			this.thisElement.setStyle( 'left', ( pos + 10 ) + 'px' );
			this.timer = this.moveRight.delay(this.speed, this);
		}
	},
	move: function(dir){
		if (dir=='left')
			this.moveLeft();
		else if (dir=='right')
			this.moveRight();
	},
	stop: function(){
		this.clearTimer();
        this.thisElement.removeEvents();
	},
	clearTimer: function(){
        $clear(this.timer);
    }
});

function NewWindow(mypage,myname,w,h,scroll){

	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;

	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no'

	if(myname!="nosettings") {		
        	win = window.open(mypage,myname,settings)
	}
	else {
		win = window.open(mypage,myname)
        }        
}

function validaNewsletter()
{
    var email = document.getElementById('mailnl').value.trim();
    if (!filter.test(email))
    {
        alert('Verifica tu correo electrónico');
    }
    else
    {
        document.getElementById('nlForm').submit();
    }
}

function clrField(obj,value)
{
    if (obj.value==value)
        obj.value="";
}

function evaluateField(obj,value)
{
    var objVal = obj.value;
    if (objVal.trim()=="")
    {
        obj.value = value;
    }
}
var activeVideo = "";
jQuery.noConflict();
function showBox(idVideo)
{
    var w = 440;
    var h = 330;
    var autoplay = "true";
    resizeLayer();
    var width = jQuery(document).width();
    var height = jQuery(document).height();
    var x = eval(width/2);
    var y = eval(height/2);
    jQuery('#vidCont').css({'display':'block','top':y-300,'left':x-220});
    jQuery('#modalW').css({'display':'block'});
    jQuery('#closevidbtn').css({'position':'absolute','top':y+100,'left':x-45,'display':'block'});
    if (idVideo != 0)
    jQuery('#vid').attr('src',"http://www.tvolucion.com/embed/embed.php?id="+idVideo+"&w="+w+"&h="+h+"&skin=home&autoplay="+autoplay+"&move_reporting=esmas_home");
    activeVideo = idVideo;
}
function resizeLayer(){
    jQuery('#modalW').width(jQuery(document).width());
    jQuery('#modalW').height(jQuery(document).height());
}
function closeBox()
{
    jQuery('#modalW').css({'display':'none'});
    jQuery('#registro').css({'display':'none'});
    jQuery('#vidCont').css({'display':'none'});
    jQuery('#closevidbtn').css({'display':'none'});
    jQuery('#vid').attr('src',"#");
    activeVideo = "";
}
jQuery(window).resize(function() {
    if (activeVideo != "")
    {
        showBox(0);
        resizeLayer();
    }
});
jQuery(document).ready(function() {
    /*jQuery('#modalW').click(function() {
            closeBox();
    });*/
    formulario = new Formulario();
});
function showRegBox()
{
    var w = 440;
    var h = 330;
    var autoplay = "true";
    resizeLayer();
    var width = jQuery(document).width();
    var height = jQuery(document).height();
    var x = eval(width/2);
    var y = eval(height/2);
    jQuery('#registro').css({'display':'block','top':200,'left':x-220});
    jQuery('#modalW').css({'display':'block'});
}
function FormField (objId) {
    this.objId = objId;
    this.objInst = null;
    
    this.init = function(){
        if (this.objInst==null)
        if (this.objId.trim().length>0 && document.getElementById(this.objId))
        {
            this.objInst = document.getElementById(this.objId);
        }
    };
    
    this.isEmpty = function(){
        this.init();
        if (this.objInst!=null && this.objInst.value.trim() == "")
            return true;
        return false;
    };
    this.getFieldValue = function(){
        this.init();
        return this.objInst.value;
    };
    this.init();
}
function Formulario(){
    this.msgLlenaForm = "Proporciona los datos requeridos (*).";
    this.sendUrl = "http://enviayreporta.esmas.com/inversionistas/";
	this.submitAction = "upload.php";
    this.fieldArray2 = new Array();
    this.nombre = new FormField('nombref');
    this.apellido = new FormField('apellidof');
    this.presea = new FormField('preseaf');
    this.estado = new FormField('estadof');
    this.cp = new FormField('cpf');
    this.email = new FormField('emailf');
    this.lada = new FormField('ladaf');
    this.telefono = new FormField('telefonof');
    this.flag = true;
    this.form1 = document.getElementById('registropc');
    this.init = function()
    {
        var i = 0;
        this.fieldArray2[i++] = this.nombre;
        this.fieldArray2[i++] = this.apellido;
        this.fieldArray2[i++] = this.email;
    };
    
    this.fieldsOk = function()
    {
        this.init();
        var retVal = true;
        for (var i=0;i<this.fieldArray2.length;i++)
        {
            if (this.fieldArray2[i].isEmpty())
            {
                retVal = false;
            }
        }
        return retVal;
    };
    
    this.validate = function()
    {
        if (this.fieldsOk())
		{
			return true;
		}
        return false;
    };
    
    this.submit = function()
    {
		if (this.validate())
        {
            if (!filter.test(this.email.getFieldValue().trim()))
			{
				alert('Correo electrónico inválido');
				return;
			}
            else if (!this.telefono.isEmpty() && this.telefono.getFieldValue().trim().length < 8)
            {
                alert('Tu teléfono debe tener al menos 8 dígitos');
            }
			else
			{
                showWaitModal();
                
                AIM.submit(this.form1, {'onComplete' : completeCallback});
				this.form1.submit();
			}
        }
        else
        {
            alert(this.msgLlenaForm);
        }
    };
    this.reset = function()
    {
        this.form1.reset();
    };
}
function showWaitModal()
{
    jQuery('#waitmodal').width(jQuery('#registro').width());
    jQuery('#waitmodal').height(jQuery('#registro').height());
    jQuery('#waitmodal').css({'display':'block'});
}
function closeWaitModal()
{
    jQuery('#waitmodal').css({'display':'none'});
}
function completeCallback(response)
{
    jQuery('.form-cont').css({'display':'none'});
    jQuery('.form-gracias').css({'display':'block'});
    closeWaitModal();
}
function onKeyDownValidation(e,value,numberOnly)
{
    var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
    if (code==8 || code==37 || code==39 || code==46 || code==9)
    {
        return true;
    }
    if (numberOnly)
    {
        if (!codeIsNumber(code))
        {
            return false;
        }
    }
    return true;
}

function codeIsNumber(code)
{
    if ((code>=48&&code<=57)||(code>=96&&code<=105))
        return true;
    return false;
}

var formulario;
