/// <reference path="jquery.js" />

var Gallery = {
    gIdStr: 'gallery',
    gJQIDSTR: '#gallery',
    ligthbox: false,
    loadByTag: false,
    easing: 'easeInOutBack', /* default = 'swing' */
    galleryId: 0,
    tagId: 0,
    //endIndex:0,
    currentPageIndex: 0,
    totalFiles: 0,
    _mainImageId: 'galleryMainImg',
    _singleItemWidth: 90,
    _visibleWidth: 416,
    _scrollPx: 416,
    _animationDuration: 1200,
    _itemsetLength: 4,
    _itemsetWidth: 0,
    _galleryWidth: 0,
    maxLeft: 0,
    webServiceMethod: 'GetGalleryImages',
    pageSize: 8, //must be a multiple of itemsetLength

    init: function() {
        //this.sendToAFriendBaseUrl = '/photo-galleries/image/#IMAGEID#';

        if (isIE6OrLess()) {
            Gallery.lightbox = false;
        }
        if (this.lightbox) {
            Gallery.webServiceMethod = Gallery.loadByTag ? 'GetAllTagImages' : 'GetAllGalleryImages';
        }
        else {
            Gallery.webServiceMethod = Gallery.loadByTag ? 'GetTagImages' : 'GetGalleryImages';
        }
        if (document.getElementById(Gallery.gIdStr)) {
            this.constructList();
            this.getGalleryImages();
            activated = this.lightbox ? $('.galleryMainImgWrap, .galleryHorizNav, #galleryImageCaption').hide() : this.setFirstImageActive();

        }
    },
    constructList: function() {
        $(Gallery.gJQIDSTR + " #galleryImages").html("<ul></ul>");
    },

    appendImage: function(objDetails) {
        var img = objDetails;
        //alert(img);
        var h = '';
        var lb = '';
        var f = '';
        var sep = img.Caption != '' ? ': ' : '';
        var title = 'title="' + img.Caption + sep + img.AltText + '"';
        onclickStr = "";
        if (this.lightbox == true) {
            lb = 'lightbox-';

            //h = '<li id="galleryImage_'+img.Id+'"><a href="'+img.MediumThumbPath+'" rel="'+lb+'gallery_'+this.galleryId+'" '+title+'><img src="'+img.SmallThumbPath+'" alt="'+img.Caption+':'+img.AltText+'" /></a></li>';
        }
        else {
            //      if (img.Dimensions){
            //        width = img.Dimensions.width?img.Dimensions.width:false;
            //        height = img.Dimensions.height?img.Dimensions.height:false;
            //        dims = height&&width?",Dimensions:{width:"+width+",height:"+height+"}":'';
            //      }
            dims = ",Dimensions:{width:" + img.ImageWidth + ",height:" + img.ImageHeight + "}";
            f = "Gallery.setMainImage({ImagePath:'" + img.ImagePath + "',Id:'" + img.Id + "',Caption:'" + img.Caption + "',AltText:'" + img.AltText + "',ImageReferenceId:'" + img.ReferenceId + "'" + dims + "},this);return false;"
            onclickStr = ' onclick="' + f + '"';
        }
        h = '<li id="galleryImage_' + img.Id + '"><a href="' + img.ImagePath + '" rel="' + lb + 'gallery_' + this.galleryId + '" ' + title + onclickStr + '><img src="' + img.ThumbPath + '" alt="' + img.AltText + '" /></a></li>';
        $('#gallery #galleryImages ul').append(h);
        this.galleryReConstructor();
    },

    setFirstImageActive: function() {
        if (Gallery.images) {
            //Gallery.setMainImageSource(Gallery.images.ImageItems[0].MediumThumbPath);
            $(Gallery.gJQIDSTR + " li:first").find('a').trigger('click');
            //      l = document.getElementById(liId).getElementsByTagName('a')[0];
            //      Gallery.setMainImage(Gallery.images.ImageItems[0],l);
        }
    },

    buildGallery: function(images) {
        firstRequest = false;
        images = images.d;
        if (images) {
            if (Gallery.totalFiles == 0) {
                firstRequest = true;
            }
            Gallery.images = images;
            Gallery.totalFiles = images.TotalFiles;
            //Gallery.endIndex = images.EndIndex;
            currentSet = images.ImageItems;
            if (currentSet && currentSet.length > 0) {
                csl = currentSet.length;
                for (var i = 0; i < csl; i++) {
                    if (currentSet[i]) {
                        Gallery.appendImage(currentSet[i]);
                    }
                }
            }
            //Gallery.currentPageIndex=images.EndIndex;
        }
        if (firstRequest) {
            if (Gallery.lightbox) {
                Gallery.startLightbox();
            }
            else {
                Gallery.setFirstImageActive();
            }
        }
    },

    getGalleryImages: function() {
        $("#galleryMainImg").ajaxSend(function(evt, request, settings) {
            //$(this).append('<div id="galleryLoadingImages"><div id="gliText"><p>Fetching more images</p></div></div>');
        });
        $("#galleryMainImg").ajaxComplete(function(request, settings) {
            //$("#galleryLoadingImages").remove();
        });
        var postData = '{';
        if (Gallery.loadByTag) {
            postData = postData + '"tagId":"' + this.tagId;
        }
        else {
            postData = postData + '"galleryId":"' + this.galleryId;
        }

        if (Gallery.ligthbox) {
            postData = postData + '"}';
        }
        else {
            postData = postData + '","pageSize":"' + this.pageSize + '","pageIndex":"' + (++this.currentPageIndex) + '"}';
        }
        $.ajax({
            type: "POST",
            url: "/Messaging/PhotoGallery.asmx/" + Gallery.webServiceMethod,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: postData,
            success: this.buildGallery
        });

    },
    galleryReConstructor: function() {
        this.setWidth();
        this._galleryWidth = this._calcWidth();
        this._itemsetWidth = this._singleItemWidth * this._itemsetLength;
        //this.maxLeft = (this._galleryWidth-this._itemsetWidth);
        this.maxLeft = (this._galleryWidth - this._scrollPx);

    },

    startLightbox: function() {

        $.Lightbox.construct({
            start: false,
            options: { start: false },
            show_linkback: false,
            files: {
                js: {
                    lightbox: '/scripts/jquery.lightbox.js',
                    colorBlend: '/scripts/jQuery.colorBlend.pack.js'
                },
                css: {
                    lightbox: '/styles/jquery.lightbox.css'
                },
                images: {
                    prev: '/images/prev.gif',
                    next: '/images/next.gif',
                    blank: '/images/blank.gif',
                    loading: '/images/loading.gif'
                }


            },
            opacity: 0.8,
            speed: 100,
            auto_relify: false,
            scroll: 'disabled'
        });

        $('#galleryImages a').lightbox({ start: false });

    },
    setMainImage: function(imgObj, el) {
        var mId = '#' + this._mainImageId;
        $("#stfImageId").attr('value', imgObj.Id);
        //$(mId+' img').stop();
        //$(mId+' img').fadeOut('fast');
        $(mId + ' img').stop().animate({ opacity: 0 }, 100);
        if (imgObj.Dimensions) {
            //get the parent width/height and add the border width/height of _mainImageId to image dimensions
            //pW = $(mId).parent().width()+parseInt($(mId).parent().css('paddingLeft'))+parseInt($(mId).parent().css('paddingRight'))
            var pW = parseInt($(mId).parent().width()) + parseInt($(mId).parent().css('paddingLeft')) + parseInt($(mId).parent().css('paddingRight'))
            var pH = $(mId).parent().height() + parseInt($(mId).parent().css('paddingTop')) + parseInt($(mId).parent().css('paddingBottom'));
            var bW = parseInt($(mId).css('borderLeftWidth')) + parseInt($(mId).css('borderRightWidth'));
            var bH = parseInt($(mId).css('borderTopWidth')) + parseInt($(mId).css('borderBottomWidth'));
            var iW = imgObj.Dimensions.width;
            var iH = imgObj.Dimensions.height;
            if (isIE6OrLess()) {
                pW = 570;
            }
            totalW = iW + bW;
            totalH = iH + bH;
            marginT = (pH - totalH) / 2;
            marginL = (pW - totalW) / 2;
            if (isIE6OrLess()) {
                marginL = marginL / 2;
            }
            $(mId).animate({ width: iW + 'px', height: iH + 'px', marginTop: marginT + 'px', marginLeft: marginL + 'px' }, 'normal', this.easing);
        }

        this.setActive(el);
        imgSrc = imgObj.ImagePath;
        imgEl = el.getElementsByTagName('img')[0];
        imgAlt = imgEl.alt;
        imgId = imgObj.Id;
        $("#galleryImageCaption").empty();
        if (imgObj.Caption != '') {
            $("#galleryImageCaption").append("<p>" + imgObj.Caption + "</p>");
        }

        mi = document.getElementById(this._mainImageId).getElementsByTagName('img')[0];
        mi.alt = imgAlt;
        $(mi).attr('height', iH);
        $(mi).attr('width', iW);

        if (isIE6OrLess()) {
            setTimeout("mi.src=\"" + imgSrc + "\"", 0);
        }
        else {
            mi.src = imgSrc;
        }
        var capt = imgObj.Caption;
        if (imgObj.Caption == '') {
            if (imgObj.AltText == '') {
                capt = '';
            }
            else {
                capt = imgObj.AltText;
            }
        }

        $("#" + this._mainImageId + " .caption p").html(capt);

        //    $(mId+' img').stop();
        //    $(mId+' img').fadeIn(2000);
        $(mId + ' img').animate({ opacity: 1 }, 200);
        $("#stfImageId").val(imgId);
        $("#stfGalleryId").val(this.galleryId);

        /* Set reference ID for comments, and refresh the comments panel. */
        if (document.getElementById('CommentReferenceId')) {
            $("#CommentReferenceId").attr('value', imgObj.ImageReferenceId);
            if (typeof (__doPostBack) == 'function') {
                __doPostBack(commentUpdatePanelId, '');
            }
            //            if (document.getElementById('btnUpdateCommentsContainer')) {
            //                $('#btnUpdateCommentsContainer input').trigger('click');
            //            }
        }


    },
    setMainImageSource: function setMainImageSource(strSrc) {
        im = document.getElementById(this._mainImageId).getElementsByTagName('img')[0];
        im.src = strSrc;
    },

    setActive: function(el) {
        //alert(el.firstChild.src);
        items = el.parentNode.parentNode.getElementsByTagName('li');
        for (var i = 0; i < items.length; i++) {
            imgEl = items[i];
            $(imgEl).removeClass('active');
        }
        el.parentNode.className = 'active';

    },
    slideLeft: function() {

        //    leftVal = this._getLeft()+this._itemsetWidth;
        leftVal = this._getLeft() + this._scrollPx;
        //this.notice(this._getLeft() + ' ' + (this._galleryWidth-this._itemsetWidth));
        if ((leftVal * -1) < 0) {
            leftVal = 0;
            $('#galleryImages ul').stop().animate({ left: leftVal + 'px' }, this._animationDuration / 2, this.easing);
        }
        if (((leftVal * 1) - 1) + (this._visibleWidth * (Math.floor(this._getImageCount() / this._itemsetLength))) < this._calcWidth()) {
            $('#galleryImages ul').stop().animate({ left: leftVal + 'px' }, this._animationDuration, this.easing);
        }

    },
    slideRight: function() {
        if (Gallery.totalFiles <= Gallery._itemsetLength) {
            // the total files are less than we need to slide...
            return;
        }
        //rightVal = this._getLeft()-this._itemsetWidth;
        rightVal = this._getLeft() - this._scrollPx;
        if ((rightVal * -1) > this.maxLeft) {
            rightVal = -this.maxLeft;
            $('#galleryImages ul').stop().animate({ left: rightVal + 'px' }, this._animationDuration / 2, this.easing);
        }
        if (rightVal * -1 < this._calcWidth()) {
            $('#galleryImages ul').stop().animate({ left: rightVal + 'px' }, this._animationDuration, this.easing);
        }
        //if end reached, fetch more images.
        if ((rightVal - this._visibleWidth) < -this.maxLeft) {
            //      alert($('#galleryImages ul').children().length +" < "+ (Gallery.totalFiles));
            var totalMinOffset = Gallery.totalFiles - Gallery._itemsetLength;
            modTotalLen = (Gallery.totalFiles % Gallery._itemsetLength);
            if (modTotalLen < Gallery._itemsetLength && modTotalLen > 0) {
                totalMinOffset = Gallery.totalFiles - (Gallery.totalFiles % Gallery._itemsetLength);
            }
            if ($('#galleryImages ul').children().length <= (totalMinOffset)) {
                this.getGalleryImages();
            }
        }
    },
    next: function() {
        //get next active image
        negation = $('#galleryImages').offset().left;
        nextIm = $(this.gJQIDSTR + " ul li.active").next();
        c = $(nextIm).find('a').trigger('click');
        if ($(nextIm).offset() && (($(nextIm).offset().left - negation) > $('#galleryImages').width())) {
            this.slideRight();
        }

        //if current image offset is out of the bounds - scroll to the bound.
        return; /* TODO: FIX THIS SO IT SCROLLS TO THE ACTIVE IMAGE */
        if ($(this.gJQIDSTR + " ul li.active").offset() &&
        (($(this.gJQIDSTR + " ul li.active").offset().left - negation) > $('#galleryImages').width()) ||
        (($(this.gJQIDSTR + " ul li.active").offset().left - negation) < 0)) {
            //scroll to the bound
            //$('#galleryImages ul').stop().animate( { left:-($(this.gJQIDSTR + " ul li.active").offset().left/2)+'px' },this._animationDuration, this.easing);
            operator = "";
            if (($(this.gJQIDSTR + " ul li.active").offset().left - negation) < 0) { operator = "-"; }
            rightVal = this._getLeft() - this._scrollPx;
            if ((rightVal * -1) > this.maxLeft) {
                rightVal = -this.maxLeft;
            }
            $('#galleryImages ul').stop().animate({ left: operator + rightVal + 'px' }, this._animationDuration / 2, this.easing);

        }


    },
    back: function() {
        //get next active image
        negation = $('#galleryImages').offset().left
        prevIm = $(this.gJQIDSTR + " ul li.active").prev();
        c = $(prevIm).find('a').trigger('click');
        if ($(prevIm).offset() && (($(prevIm).offset().left - negation) < 0)) {
            this.slideLeft();
        }

        //if current image offset is out of the bounds - scroll to the bound.
        return; /* TODO: FIX THIS SO IT SCROLLS TO THE ACTIVE IMAGE */

        if ($(this.gJQIDSTR + " ul li.active").offset() &&
        (($(this.gJQIDSTR + " ul li.active").offset().left - negation) > $('#galleryImages').width()) ||
        (($(this.gJQIDSTR + " ul li.active").offset().left - negation) < 0)) {
            //scroll to the bound
            $('#galleryImages ul').stop().animate({ left: ($(this.gJQIDSTR + " ul li.active").offset().left / 2) + 'px' }, this._animationDuration, this.easing);
        }

        leftVal = this._getLeft() + this._scrollPx;
        if ((leftVal * -1) < 0) {
            leftVal = 0;
            $('#galleryImages ul').stop().animate({ left: leftVal + 'px' }, this._animationDuration / 2, this.easing);
        }

    },
    toggleSendToFriend: function() {
        //$('#gallerySendToFriend').slideToggle();
        $('.gallerySendToFriendInner').slideToggle(500);
        $('.gallerySendToFriendInner').parent().css('overflow', 'hidden');
        //    setTimeout(function(){Gallery.createCaptcha()},500);

    },
    sendToFriend: function() {
        stfYourName = $("#stfYourName").css('backgroundColor', '#fff').attr('value');
        stfYourEmail = $("#stfYourEmail").css('backgroundColor', '#fff').attr('value');
        stfFriendName = $("#stfFriendName").css('backgroundColor', '#fff').attr('value');
        stfFriendEmail = $("#stfFriendEmail").css('backgroundColor', '#fff').attr('value');
        stfComment = $("#stfComment").attr('value');
        stfImageId = $("#stfImageId").attr('value');
        stfImageUrl = this.sendToAFriendBaseUrl;
        //validate stuff
        /* TODO: Add validation code */
        var stfErrors = {};
        if (!Validator.regex(Validator.mask.names, stfYourName) || !Validator.hasValue('stfYourName')) {
            stfErrors.stfYourName = 'Please enter your name';
        }
        if (!Validator.hasValue('stfYourEmail')) {
            stfErrors.stfYourEmail = "Please enter your email address.";
        }
        else if (!Validator.regex(Validator.mask.email, stfYourEmail)) {
            stfErrors.stfYourEmail = "Please enter a valid email address for your email address.";
        }

        if (!Validator.regex(Validator.mask.names, stfFriendName) || !Validator.hasValue('stfFriendName')) {
            stfErrors.stfFriendName = "Please enter your friends' name.";
        }
        if (!Validator.hasValue('stfFriendEmail')) {
            stfErrors.stfFriendEmail = "Please enter your friends' email address.";
        }
        else if (!Validator.regex(Validator.mask.email, stfFriendEmail)) {
            stfErrors.stfFriendEmail = "Please enter a valid email address for your friends' email address.";
        }
        if (this.sendToAFriendBaseUrl != '' && typeof (parseInt(stfImageId)) == 'number') {
            stfImageUrl = stfImageUrl.replace('#IMAGEID#', stfImageId);
        }
        else {
            if (typeof (parseInt(stfImageId)) != 'number') {
                stfErrors.stfImageId = "Sorry, but I couldn't detect the image you want to send. Please try selecting the image you want to send and try again.";
            }
        }

        //    if (Recaptcha.get_response()=="") {
        //      stfErrors.recaptcha_response_field="Please fill in the words you see in the image, or use the <a href=\"javascript:Recaptcha.reload();\">reload</a> button to get a new challenge.";
        //    } 
        //    else {
        //      //do a webservice call and wait for the response.
        //      solution = this.checkCaptcha(Recaptcha.get_response(), Recaptcha.get_challenge());
        //      
        //      if(solution.solved==true) {
        //        
        //      }
        //      else {
        //        stfErrors.recaptcha_response_field="Please fill in the words you see in the image, or use the <a href=\"javascript:Recaptcha.reload();\">reload</a> button to get a new challenge.";
        //      }
        //    }
        Gallery.stfErrorDiv = 'stfErrors';
        Gallery.iterator = 0;
        Gallery.stfErrorSet = Array();
        jQuery.each(stfErrors, function(i, n) { Gallery.stfErrorSet[Gallery.iterator] = i; Gallery.iterator++; });
        if (Gallery.stfErrorSet.length > 0) {
            $("#" + Gallery.stfErrorDiv).empty();
            $("#" + Gallery.stfErrorDiv).append("<ul></ul>");
            jQuery.each(stfErrors, function(i, n) {
                //$("#"+i).effect("highlight",{color:"#0099ff"},1500);
                $("#" + i).animate({ backgroundColor: "#fff" }, 100);
                $("#" + i).effect("pulsate", { times: 2 }, 200);

                //          $("#"+i).animate({backgroundColor:"#cceaec"},500);       
                $("#" + i).animate({ backgroundColor: "#eebbbb" }, 500);
                $("#" + Gallery.stfErrorDiv + " ul").append("<li>" + n + "</li>");
            }
      );
            return;
        }
        stfYourName = stfYourName;
        stfYourEmail = stfYourEmail;
        stfFriendName = stfFriendName;
        stfFriendEmail = stfFriendEmail;
        stfComment = stfComment;
        //pass to webservice
        $.ajax({
            type: "POST",
            url: "/Messaging/PhotoGallery.asmx/SendToAFriend",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: '{"imageUrl":"' + stfImageUrl + '",'
           + '"senderName":"' + stfYourName + '",'
           + '"senderEmail":"' + stfYourEmail + '",'
           + '"friendsName":"' + stfFriendName + '",'
           + '"friendsEmail":"' + stfFriendEmail + '",'
           + '"personalMessage":"' + stfComment + '"}',
            success: this.sendToFriendSuccess,
            error: this.sendToFriendError

        });

    },
    sendToFriendSuccess: function(responseData, textStatus) {
        if (responseData.d) {
            $("#stfYourName").val('');
            $("#stfYourEmail").val('');
            $("#stfFriendName").val('');
            $("#stfFriendEmail").val('');
            $("#stfFriendEmail").val('');
            $("#stfComment").val('');
            Gallery.toggleSendToFriend();
        }
    },
    sendToFriendError: function(XMLHttpRequest, textStatus, errorThrown) {
        // typically only one of textStatus or errorThrown 
        // will have info
        errorMsg = errorThrown ? errorThrown : textStatus;
        $("#" + Gallery.stfErrorDiv).empty();
        $("#" + Gallery.stfErrorDiv).append("<ul></ul>");
        $("#" + Gallery.stfErrorDiv + " ul").append("<li><p>Sorry, an error occured while trying to send this photo. Please try again later, or if this error perists, contact us and quote the following error message:</p><blockquote>" + errorMsg + "</blockquote></li>");
        alert(errorMsg);
        this; // the options for this ajax request
    },
    //  createCaptcha: function() {
    //  atwwwKey = '6Lei3AIAAAAAAMdTSzweh0dVRyrI7pefSn8TspSK';
    //  public_key=atwwwKey;
    //    Recaptcha.create(
    //      public_key,
    //      "recaptcha_div", 
    //      { 
    //        theme: "blackglass",
    //        callback: Recaptcha.focus_response_field
    //      }
    //    );  
    //  },
    //  checkCaptcha: function(response, challenge) {
    //    var solution = {};
    //    solution.solved=true;
    ////    solution.solved=false;
    //    return solution;
    //  },
    _getLeft: function() {
        return parseInt($('#galleryImages ul').css('left'));
    },
    _calcWidth: function() {
        w = 0;
        for (var i = 0; i < $('#galleryImages ul').children('li').length; i++) {
            s = $('#galleryImages ul').children('li')[i];
            var mL = parseInt($(s).css('marginLeft'));
            var mR = parseInt($(s).css('marginRight'));
            var pL = parseInt($(s).css('paddingLeft'));
            var pR = parseInt($(s).css('paddingRight'));
            var ie6Offset = 0;
            if (isIE6OrLess()) {
                /* Seriously WTH!? I hate IE6 */
                //pR = pR*2;
                //pL = pL*2;
                ie6Offset = this._itemsetLength;
            }
            w += $(s).width() + mL + mR + pL + pR + ie6Offset;
        };
        return w;
    },

    setWidth: function() {
        $('#galleryImages ul').css('width', this._calcWidth() + "px");
    },

    _getImageCount: function() {
        return $('#galleryImages ul').children().length;
    }
}

$(document).ready(init);
function init() {
  Gallery.init();
}


/** isIE6OrLess()
 *  for some of our methods its neccesary to know if we're dealing with an old browser
 *
 *  @returns {bool}
 */
function isIE6OrLess() {
    //Detect < IE6
    version=0
    if (navigator.appVersion.indexOf("MSIE")!=-1){
        temp=navigator.appVersion.split("MSIE");
        version=parseFloat(temp[1]);
    }
    if (version<=6.0 && version !=0) { //NON IE browser will return 0
      return true;
    }
    return false;
}



var Validator = { 
  validated:false,
  mask: {
		email		:	/^([\w.])+\@(([\w])+\.)[a-zA-Z0-9]{2,}/,
		domain		:	/^(http:\/\/)([\w]+\.){1,}[A-Z]{2,4}\b/gi,
		numeric		:	/^[0-9]+$/gi,
		alphanumeric:	/^[0-9a-f\-\s]+$/gi,
		names		:	/^[a-z\.\-\s\']{1,}$/gi          //'
  },
  hasValue: function(el) {
    v = Validator.getValue(el);
    if (v==undefined) { return false; }
    if (v=='') { return false; }
    if (v==null) { return false; }
    return true;
  },
  regex: function(rgMask, valueToTest) {
    retVal = rgMask.test(valueToTest);
    rgMask.exec(valueToTest);
    return retVal;
  },
  getValue: function(elId){
    return $('#'+elId).attr('value');
  },
  setValue: function(strVal, elId){
    $('#'+elId).attr('value',strVal);
  },
  remove: function(rx,str) {
		  return str.replace(rx, '');
  },
  /* Strip all non alphabetic chars from a string */
  stripNonAlpha: function(str) {
		  return Validator.remove(/[^A-Za-z]+/g, str);
  },
  /* Strip all non alphanumeric chars from a string */
  stripNonAlphaNumeric: function(str) {
		  return Validator.remove(/[^A-Za-z0-9]+/g,str);
  },
  /* Strip all non numeric chars from a string (except minus and decimal point) */
  stripNonNumeric: function(str) {
		  return Validator.remove(/[^0-9\-\.]/g,str);
  },
  /* Strip all non numerics explicitly from a string (including minus and decimal points) */
  stripNonNumericExplicit: function(str) {
		  return Validator.remove(/[^0-9]/g,str);
  }
};
