/*
 * jVal - dynamic jquery form field validation framework
 *      version 0.1.5
 * Author: Jim Palmer
 * Released under MIT license.
 */
(function($) {
        // core jVal function - returns TRUE if all jVal validation passes, false if not
        $.fn.jVal = function (options) {
                $.fn.jVal.clean(this);
                // clear jVal warnings
                if ((options || '').toString().toUpperCase() == 'CLEAN')
                        return this; // chainable
                $.fn.jVal.defaults = $.extend($.fn.jVal.defaults, options);
                $(this).stop().find('.jfVal,.jValCover').stop().remove();
                var passVal = true, dm = $.fn.jVal.defaults.message, ds = $.fn.jVal.defaults.style;
                $(this).find('.jVal,[jVal]:not(:disabled):visible').each(
                        function () {
                                var cmd = $(this).data('jVal');
                                if ( typeof cmd !== 'object' ) eval( 'cmd = ' + ( $(this).data('jVal') || $(this).attr('jVal') ) + ';' );
                                //$.fn.jVal.clean(this);
                                if ( cmd instanceof Object && cmd.valid instanceof RegExp && !cmd.valid.test($(this).val()) ) {
                                        $.fn.jVal.showWarning(cmd.target || this, cmd.message || dm, cmd.autoHide || false, cmd.styleType || ds);
                                        passVal = false;
                                } else if ( cmd instanceof Object && cmd.valid instanceof Function ) {
                                        var testFRet = cmd.valid( $(this).val(), this );
                                        if ( testFRet === false || testFRet.length > 0 ) {
                                                $.fn.jVal.showWarning(cmd.target || this, testFRet || cmd.message || dm, cmd.autoHide || false, cmd.styleType || ds);
                                                passVal = false;
                                        }
                                } else if ( ( cmd instanceof RegExp && !cmd.test($(this).val()) ) || ( cmd instanceof Function && !cmd($(this).val()) ) ) {
                                        $.fn.jVal.showWarning(cmd.target || this, dm, cmd.autoHide || false, cmd.styleType || ds);
                                        passVal = false;
                                }
                        }
                );
                return passVal;
        };
        // showWarning utility function
        $.fn.jVal.showWarning = function (elements, message, autoHide, styleType) {
                var par = $(elements).eq(0).parent();
                clearTimeout( $(par).data('autoHide') ) && $(par).data('autoHide', null);
                $.fn.jVal.clean(par);
                $(elements).css({marginTop:'',position:'',border:'2px solid #008ac9','-moz-border-radius': '5px','border-radius': '5px'});
                var dbw = $.fn.jVal.defaults.border,
                        dp = $.fn.jVal.defaults.padding,
                        fieldWidth = 0, fieldHeight = 0,
                        absoluteLeft = $(elements).eq(0).position().left,
                        absoluteTop = $(elements).eq(0).position().top;
						absoluteBottom = $(elements).eq(0).position().bottom;

                // normalize multi-element coordinates
                $(elements).each(function () {
                        fieldWidth += $(this).outerWidth(true);
                        fieldHeight = Math.max( $(elements).outerHeight(true), fieldHeight );
                        absoluteLeft = Math.min( $(this).position().left, absoluteLeft );
                        absoluteTop = Math.min( $(this).position().top, absoluteTop );
						absoluteBottom = Math.min( $(this).position().bottom, absoluteBottom );
                });
                var fwidth = 0, tPos = absoluteTop - dp - dbw, lPos = absoluteLeft + dp, rPos = absoluteLeft + fieldWidth + dp,
                        ph = (fieldHeight + (dp * 2)), fhp = fieldHeight + dp + dbw, fwp = fieldWidth + dp,
                        clips = [ 
                                'rect(0px, 5000px, ' + (dp + dbw) + 'px, 0px)', // top
                                'rect(' + fhp + 'px, 5000px, 5000px, 0px)', // bottom
                                'rect(' + dp + 'px, ' + dp + 'px, 5000px, 0px)', // left
                                'rect(' + dp + 'px, 5000px, 5000px, ' + fwp + 'px)']; // right
                // fixed alerts, no wrapping
                if (!$.fn.jVal.defaults.wrap) {
                        fieldWidth = ph = fph = 12;
                        rPos = lPos;
                }
                $(elements).eq(0).before(
                        '<div class="jValSpacer jValSpacer' + styleType + '" style="line-height:' + ph + 'px; height:' + ph + 'px; clip:' + clips[0] + '; ' +
                                'left:' + (absoluteLeft - dp) + 'px; top:' + tPos + 'px; ' + 
                                'width:' + (fieldWidth + (dp * 2)) + 'px;" />' +
                        '<div class="jfVal' + ( styleType ? ' jfVal' + styleType : '' ) + '" style="left:' + lPos + 'px; ' +
                                'top:' + tPos + 'px;">' +
                                /*'<div class="icon' + ( styleType ? ' icon' + styleType : '' ) + '" style="height:' + ph + 'px;"><div class="iconbg" /></div>' +*/
                                '<div class="content' + ( styleType ? ' content' + styleType : '' ) + '" style="height:' + ph + 'px; line-height:' + ph + 'px;">' +
                                        '<span class="message' + styleType + '">' + message + '</span>' +
                                '</div>' +
                        '</div>')
                        .parent().find('.jfVal>*').each(function () { fwidth += $(this).outerWidth() }).end()
                        .find('.jfVal').width(fwidth + 20);
                for (var si = 1; si < 4; si++) 
                        $(par).find('.jValSpacer:first').before( 
                                $(par).find('.jValSpacer:first').clone().css({clip:clips[si]}) );
                // autoHide = set spacer width + add autohide function to fx queue
                if ( autoHide )
                        $(par).data( 'autoHide', setTimeout(function () { $(par).find('.jfVal').animate({left:lPos,opacity:0}, 200, function () { $.fn.jVal.clean(par); }); }, 2000) )
                                .find('.jfVal').css({'left':rPos});
                else
                        $(par).find('.jfVal').css({opacity:0}).animate({left:rPos,opacity:1}, 200);
        };
        // validate key stroke
        $.fn.jVal.valKey = function (keyRE, e, cF, cA) {
                var ek = (typeof(e.keyCode) != 'undefined'), ec = (typeof(e.charCode) != 'undefined'),
                        k = e.keyCode, c = e.charCode, ks = k.toString();
                // return if invalid regex
                if ( !(keyRE instanceof RegExp) ) 
                        return false;
                // test for ENTER key and cF being valid function otherwise return true
                if ( /^13$/.test(String(k || c)) ) {
                        try { (this[cF]) ? this[cF](cA) : eval(cF); } catch(e) { return true; }
                        return -1;
                }
                // otherwise test for valid keys supported by the regex allowing meta keys by default
                if      ( e.ctrlKey || e.shiftKey || e.metaKey || (
                                ek && k > 0 && keyRE.test(String.fromCharCode(k)) ) ||
                                ( ec && c > 0 && String.fromCharCode(c).search(keyRE) != (-1) ) ||
                                ( ec && c != k && ek && ks.search(/^(8|9|45|46|35|36|37|39)$/) != (-1) ) ||
                                ( ec && c == k && ek && ks.search(/^(8|9)$/) != (-1) ||
                                ( !ec && ek && ks.search(/^(8|9|45|46|35|36|37|39)$/) != (-1) ) ) 
                        ) {
                        return 1;
                } else {
                        return 0;
                }
        };
        // clear all displayed jVal warnings within scope
        $.fn.jVal.clean = function (target) {
                $(target)
                        .find('.jfVal,.jValSpacer').stop().remove().end()
                        .find('.jVal,[jVal]').css({position:'',borderColor:'',left:'0px',top:'0px'}).parent().find('.jValRelWrap').remove();
        };
        $.fn.jVal.init = function (options) {
                $.fn.jVal.defaults = $.extend($.fn.jVal.defaults, options);
                $('.jVal,[jVal]').filter(':not(:disabled)').unbind("blur").bind("blur", function (e) { 
                        if ($.fn.jVal.defaults.blurCheck || $(this).hasClass('jValBlur'))
                                $(this).parent().jVal();
                });
                var keyFunc = function (e) {
                        eval( 'var cmd = ' + ( $(this).data('jValKey') || $(this).attr('jValKey') || $(this).data('jValKeyUp') || $(this).attr('jValKeyUp') ) + ';' );
                        var keyTest, ds = $.fn.jVal.defaults.style, dkm = $.fn.jVal.defaults.keyMessage,
                                autoHide = typeof(cmd.autoHide) != 'undefined' ? cmd.autoHide : true;
                        if ( cmd instanceof Object && cmd.valid instanceof Function ) {
                                keyTest = cmd.valid( e, this );
                                if ( keyTest === false || keyTest.length > 0 ) {
                                        $.fn.jVal.clean(cmd.target || this);
                                        // only show warning and allow keypress event to return true
                                        $.fn.jVal.showWarning(cmd.target || this, ( keyTest || (cmd.message || dkm).replace('%c', String.fromCharCode(e.keyCode || e.charCode))), autoHide, cmd.styleType || ds);
                                } else 
                                        $.fn.jVal.clean($(cmd.target || this).parent());
                        } else {
                                keyTest = $.fn.jVal.valKey( ( (cmd instanceof Object) ? cmd.valid : cmd ), e, (cmd instanceof Object) ? cmd.cFunc : null, (cmd instanceof Object) ? cmd.cArgs : null );
                                if ( keyTest == 0 ) {
                                        $.fn.jVal.clean(cmd.target || this);
                                        $.fn.jVal.showWarning(cmd.target || this, (( cmd instanceof Object && cmd.message) || dkm).replace('%c', String.fromCharCode(e.keyCode || e.charCode)), autoHide, cmd.styleType || ds);
                                        return false;
                                } else if ( keyTest == -1 ) 
                                        return false;
                                else 
                                        $.fn.jVal.clean($(cmd.target || this).parent());
                        }
                        return true;
                };
                $('.jValKey,[jValKey]').filter(':not(:disabled)').unbind("keypress").bind("keypress", keyFunc);
                $('.jValKeyUp,[jValKeyUp]').filter(':not(:disabled)').unbind("keyup").bind("keyup", keyFunc);
                return this; // chainable
        };
        // jVal defaults
        $.fn.jVal.defaults = {
                blurCheck: false,
                message: 'Invalid entry',
                style: 'pod',
                keyMessage: '"%c" Invalid character',
                padding: 3,
                border: 1,
                wrap: true
        };
        // automatically init on dom load
        $($.fn.jVal.init);
})(jQuery);

$.fn.customSelect = function() {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
  return this.each(function() {
    obj = $(this);  
    obj.after("<div class=\"selectoptions\"> </div>");
    obj.find('option').each(function(i){ 
      $(".selectoptions").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems\"><span>" + $(this).html() + "</span></div>");
    });

    obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"customselect\"/><div class=\"iconselect\">" + this.title + "</div><div class=\"iconselectholder\"> </div>").remove();

    $(".iconselect").click(function(){
      $(".iconselectholder").toggle("slow");
    });

    $(".iconselectholder").append($(".selectoptions")[0]);
    $(".in_world .iconselect").html(obj.find('option').first().html());
	  
    $(".selectitems").mouseover(function(){
	    $(this).addClass("hoverclass");
    });

	  $(".selectitems").mouseout(function(){
      $(this).removeClass("hoverclass");
    });
  	
	  $(".selectitems").click(function(){
	    $(".selectedclass").removeClass("selectedclass");
	    $(this).addClass("selectedclass");
	    var thisselection = $(this).html();
      $(".customselect").val(this.id);
	    $(".iconselect").html(thisselection);
	    $(".iconselectholder").toggle("slow");
	    if (this.id.indexOf('http') == 0) window.open(this.id);
	  });
  });  
  // do the rest of the plugin, using url and settings
}

$.fn.custom_request_Select = function two() {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
 return this.each(function two() {  
 obj = $(this);  
obj.after("<div class=\"select_options_two\"> </div>");
obj.find('option').each(function two(i){ 
  $(".select_options_two").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems_two\"><span>" + $(this).html() + "</span></div>");
});
obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"custom_request_select\"/><div class=\"iconselect_two\">" + this.title + "</div><div class=\"iconselectholder_two\"> </div>")
.remove();
$(".iconselect_two").click(function two(){
$(".iconselectholder_two").toggle("slow");});
	$(".iconselectholder_two").append( $(".select_options_two")[0] );
$(".selectitems_two").mouseover(function two(){
	$(this).addClass("hoverclass");
});
	$(".selectitems_two").mouseout(function two(){
	$(this).removeClass("hoverclass");
	});
	$(".selectitems_two").click(function two(){
	$(".selectedclass").removeClass("selectedclass");
	$(this).addClass("selectedclass");
	var thisselection = $(this).html();
$(".custom_request_select").val(this.id);
	$(".iconselect_two").html(thisselection);
	$(".iconselectholder_two").toggle("slow")
	});
    });  
  // do the rest of the plugin, using url and settings
}


$.fn.custom_request_date = function three() {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
 return this.each(function three() {  
 obj = $(this);  
obj.after("<div class=\"selectoptions_three\"> </div>");
obj.find('option').each(function three(i){ 
  $(".selectoptions_three").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems_three\"><span>" + $(this).html() + "</span></div>");
});
obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"custom_request_date\"/><div class=\"iconselect_three\">" + this.title + "</div><div class=\"iconselectholder_three\"> </div>")
.remove();
$(".iconselect_three").click(function three(){
$(".iconselectholder_three").toggle("slow");});
	$(".iconselectholder_three").append( $(".selectoptions_three")[0] );
$(".selectitems_three").mouseover(function three(){
	$(this).addClass("hoverclass");
});
	$(".selectitems_three").mouseout(function three(){
	$(this).removeClass("hoverclass");
	});
	$(".selectitems_three").click(function three(){
	$(".selectedclass").removeClass("selectedclass");
	$(this).addClass("selectedclass");
	var thisselection = $(this).html();
$(".custom_request_date").val(this.id);
	$(".iconselect_three").html(thisselection);
	$(".iconselectholder_three").toggle("slow")
	});
    });  
  // do the rest of the plugin, using url and settings
}


$.fn.custom_request_four = function four() {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
 return this.each(function four() {  
 obj = $(this);  
obj.after("<div class=\"selectoptions_four\"> </div>");
obj.find('option').each(function four(i){ 
  $(".selectoptions_four").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems_four\"><span>" + $(this).html() + "</span></div>");
});
obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"custom_request_date\"/><div class=\"iconselect_four\">" + this.title + "</div><div class=\"iconselectholder_four\"> </div>")
.remove();
$(".iconselect_four").click(function four(){
$(".iconselectholder_four").toggle("slow");});
	$(".iconselectholder_four").append( $(".selectoptions_four")[0] );
$(".selectitems_four").mouseover(function four(){
	$(this).addClass("hoverclass");
});
	$(".selectitems_four").mouseout(function four(){
	$(this).removeClass("hoverclass");
	});
	$(".selectitems_four").click(function four(){
	    $(".selectedclass").removeClass("selectedclass");
	    $(this).addClass("selectedclass");
	    var thisselection = $(this).html();
        $(".custom_request_date").val(this.id);
	    $(".iconselect_four").html(thisselection);
	    $(".iconselectholder_four").toggle("slow");
		window.open(this.id);
	});
    });  
  // do the rest of the plugin, using url and settings
}


$.fn.custom_request_five = function five() {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
 return this.each(function four() {  
 obj = $(this);  
obj.after("<div class=\"selectoptions_five\"> </div>");
obj.find('option').each(function four(i){ 
  $(".selectoptions_five").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems_five\"><span>" + $(this).html() + "</span></div>");
});
obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"custom_request_date\"/><div class=\"iconselect_five\">" + this.title + "</div><div class=\"iconselectholder_five\"> </div>")
.remove();
$(".iconselect_five").click(function four(){
$(".iconselectholder_five").toggle("slow");});
	$(".iconselectholder_five").append( $(".selectoptions_five")[0] );
$(".selectitems_five").mouseover(function four(){
	$(this).addClass("hoverclass");
});
	$(".selectitems_five").mouseout(function four(){
	$(this).removeClass("hoverclass");
	});
	$(".selectitems_five").click(function four(){
	$(".selectedclass").removeClass("selectedclass");
	$(this).addClass("selectedclass");
	var thisselection = $(this).html();
$(".custom_request_date").val(this.id);
	$(".iconselect_five").html(thisselection);
	$(".iconselectholder_five").toggle("slow")
	});
    });  
  // do the rest of the plugin, using url and settings
}




$.fn.custom_products = function six() {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
 return this.each(function six() {  
 obj = $(this);  
obj.after("<div class=\"selectoptions_six\"> </div>");
obj.find('option').each(function six(i){ 
  $(".selectoptions_six").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems_six\"><span>" + $(this).html() + "</span></div>");
});
obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"custom_request_date\"/><div class=\"iconselect_six\">" + this.title + "</div><div class=\"iconselectholder_six\"> </div>")
.remove();
$(".iconselect_six").click(function six(){
$(".iconselectholder_six").toggle("slow");});
	$(".iconselectholder_six").append( $(".selectoptions_six")[0] );
$(".selectitems_six").mouseover(function six(){
	$(this).addClass("hoverclass");
});
	$(".selectitems_six").mouseout(function six(){
	$(this).removeClass("hoverclass");
	});
	$(".selectitems_six").click(function six(){
	$(".selectedclass").removeClass("selectedclass");
	$(this).addClass("selectedclass");
	var thisselection = $(this).html();
$(".custom_request_date").val(this.id);
	$(".iconselect_six").html(thisselection);
	$(".iconselectholder_six").toggle("slow");
	if (this.id.indexOf('http') == 0) window.document.location.href = this.id;
	});
    });  
  // do the rest of the plugin, using url and settings
}

$(function() {
    $('#asia')
        .mouseover(function() { 
            var src = $('#mapping img').attr("src").match(/[^\d{10}$^\.]+/) + "_asia.jpg";
            $('#mapping img').attr("src", src);
        })
        .mouseout(function() {
            var src = $('#mapping img').attr("src").replace("_asia", "");
            $('#mapping img').attr("src", src);
        });
});
$(function() {
    $('#north_america')
        .mouseover(function() { 
            var src = $('#mapping img').attr("src").match(/[^\d{10}$^\.]+/) + "_north_america.jpg";
            $('#mapping img').attr("src", src);
        })
        .mouseout(function() {
            var src = $('#mapping img').attr("src").replace("_north_america", "");
            $('#mapping img').attr("src", src);
        });
});
$(function() {
    $('#south_america')
        .mouseover(function() { 
            var src = $('#mapping img').attr("src").match(/[^\d{10}$^\.]+/) + "_south_america.jpg";
            $('#mapping img').attr("src", src);
        })
        .mouseout(function() {
            var src = $('#mapping img').attr("src").replace("_south_america", "");
            $('#mapping img').attr("src", src);
        });
});
$(function() {
    $('#inactif')
        .mouseover(function() { 
            var src = $('#mapping img').attr("src").match(/[^\d{10}$^\.]+/) + "_inactif.jpg";
            $('#mapping img').attr("src", src);
        })
        .mouseout(function() {
            var src = $('#mapping img').attr("src").replace("_inactif", "");
            $('#mapping img').attr("src", src);
        });
});
$(function() {
    $('#europe')
        .mouseover(function() { 
            var src = $('#mapping img').attr("src").match(/[^\d{10}$^\.]+/) + "_europe.jpg";
            $('#mapping img').attr("src", src);
        })
        .mouseout(function() {
            var src = $('#mapping img').attr("src").replace("_europe", "");
            $('#mapping img').attr("src", src);
        });
});
