var cdi = function(){
    var myHttpXML = CrearHttpRequest();
    var myRegExDate =/^(0[0-9]|[1-9]|[12][0-9]|3[01])[-\/](0[1-9]|[1-9]|1[012])[-\/](19|20)[0-9][0-9]$/;
    var myRegExDecimal =/^\d{1,3}(\.\d{0,2})?$/;
    var myRegExInteger =/^\d{1,3}$/;
    var myRegExemail =/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9_\.\-]+\.[a-zA-Z0-9_\.\-]+$/;
    var currentSection, _divtxtmenu, _txtmenu, _txtmenuopt, _txtslogan, _sloganText, auxcurrentSection;
    
    function CrearHttpRequest(){
        var objXMLHTTPRequest;
        try
        {
            objXMLHTTPRequest = new XMLHttpRequest; //IE7,IE8
        }
        catch (e)
        {
            try
            {
                objXMLHTTPRequest = new ActiveXObject("Mxxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    objXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");//IE5,IE6
                }
                catch(e)
                {
                    alert('Your browser does not support Async connections');
                }
            }
        }
        return objXMLHTTPRequest;
    }

    function ShowNewSection(){
        if (_divtxtmenu){
                if(_txtmenuopt){
                        _divtxtmenu.innerHTML = _txtmenuopt.innerHTML;
                }
        }
        if (_txtslogan){
                if(_txtslogan){
                        _txtslogan.innerHTML = _sloganText;
                        $("#"+_txtmenu+":hidden").removeAttr("style").hide().fadeIn();
                }
        }
    }
    function ShowImage(){
        $("#"+currentSection+":hidden").removeAttr("style").hide().fadeIn();
    }
    return {
        HttpRequest: function(action,url,parameters,callback){

            myHttpXML.onreadystatechange=function(){
                callback(myHttpXML);
            }
            myHttpXML.open(action,url,true);
            myHttpXML.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            myHttpXML.send(parameters);
        },
        Validemail: function(value){
            if(!value.match(myRegExemail)){
                return false;
            }
            return true;
        },
        ValidFormatDate: function(value){
            if(!value.match(myRegExDate)){
                return false;
            }
            return true;
        },
        ValidFormatDecimal: function(value){
            if(!value.match(myRegExDecimal)){
                return false;
            }
            return true;
        },
        ValidFormatInteger: function(value){
            if(!value.match(myRegExInteger)){
                return false;
            }
            return true;
        },
        ShowTextContent: function(menuopt,textmenu,slogantext){
            _divtxtmenu = document.getElementById(textmenu);
            _txtmenu = textmenu;
            _txtmenuopt = document.getElementById(menuopt);
            _txtslogan = document.getElementById('sloganbysection');
            _sloganText = slogantext;
            if (currentSection!=''){
                $("#"+textmenu).hide('blind',{},300,ShowNewSection);
            }else{
                ShowNewSection();
            }
            currentSection=menuopt;
        },
        HideRequiredField: function(requiredFieldId){
            var objrequiredField = document.getElementById(requiredFieldId);
            if (objrequiredField){
                objrequiredField.style.display = 'none';
            }
        },
        SetValue: function(obj,ctrl){
            var DOMelem = document.getElementById(ctrl);
            if (DOMelem){
                DOMelem.innerHTML = obj.value;
            }
        },
        ValidateContactInfo: function(campos){

            var count, index, obj, etiqueta;
            count = campos.length;

            for(index=0; index < count; index++){

                obj = document.getElementById(campos[index]);
                if (obj){
                    etiqueta = document.getElementById(obj.getAttribute('requiredfield'));

                    if(obj.value===''){
                        etiqueta.style.display = 'inline';
                        return false;
                    }else{
                        if(campos[index]=='txtemail'){
                           if(!cdi.Validemail(obj.value)){
                               etiqueta = document.getElementById('invalidemail');
                               etiqueta.style.display = 'inline';
                               return false;
                           }else{
                               etiqueta = document.getElementById('invalidemail');
                               etiqueta.style.display = 'none';
                           }
                        }
                        etiqueta.style.display = 'none';
                    }
                }
            }
            return true;
        },
        ShowThisImage: function(divId){
            auxcurrentSection = currentSection;
            currentSection = divId;
            if(auxcurrentSection!=''){
                $("#"+auxcurrentSection).hide('blind',{},300,ShowImage);
            }else{
                ShowImage();
            }
        },
        SetCurrentSection: function(currentSec){
            currentSection = currentSec;
        }
    }
}();


