var controller = '/sales/salesToolController.php';
var solutions = '';
var channels = '';
var defaultState = '';
var defaultCountry = '';
var excludes = '';
var devEnvironment = ['http://hidcorp.dev/sales/','http://dev.hidglobal.com/main/sales/'];

var urls = window.location.href;
var urls_array = urls.split('#');

if (urls_array[1]) {
    var split_url = urls_array[1];

    var split_urls_array = split_url.split('&');
    var country_var = split_urls_array[1].split('=');
    var state_var = split_urls_array[2].split('=');
    var solution_var = split_urls_array[3].split('=');
    var channels_var = split_urls_array[4].split('=');

    var country_value = country_var[1];
    var state_value = state_var[1];
    var solution_value = solution_var[1];
    var channels_value = channels_var[1];
}

$(document).ready(function() {
    //store default state
    defaultState = $('#states').html();

    if ($.inArray(location.href.substring(0,location.href.indexOf('#')), devEnvironment) > -1)
        $('#movedata').html('<h4 align="right" style="color:#0066CC;"><a href="#" onclick=movesalesdatatostaging("staging")  >Push data to QA</a> &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick=movesalesdatatoproduction("production")>Push data to Production</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="#" onclick=movesalesdatatomovable("s_to_m")>Refresh Data</a></h4>');
    //load country drop-down
    $.getJSON(controller + "?d=countries&lang=" + lang,
             function (data) {
                 defaultCountry = $('#countries').html();
                 $('#countries').html('');
                 for (var i = 0; i < data.length; i++) {
                     var selected = '';
                     if (data[i].id !== '1') {

                         if (country_value == data[i].id) {

                             $('#countries').append('<option value="' + data[i].id + '" selected="selected" >' + data[i].country + '</option>');

                             $.getJSON(controller + "?d=states&v=" + country_value,
                                      function (data) {

                                          $('#states').html(defaultState);
                                          if ($('#countries').val() == 43) {
                                              $("#statelabel").html("Province");
                                              $("#stateTitle").html('<select id="states"><option value="">' + phrases['province'] + '</option></select>');
                                          }
                                          else {
                                              $("#statelabel").html("State");
                                          }

                                          if (!data) {
                                              $('#states, .channel-dropdown').hide();
                                              $('#channels').get(0).selectedIndex = 0;
                                              $("label[for='state']").hide();
                                              $('#states').html('');
                                          } else { //show states or provinces
                                              $('#states, .channel-dropdown').show();
                                              $("label[for='state']").show();
                                              $('#states').show();
                                              for (var i = 0; i < data.length; i++) {
                                                  if (i == 0)
                                                      $('#states').append('<option value="">------------------</option>');
                                                  if (state_value == data[i].id) {
                                                      $('#states').append('<option value="' + data[i].id + '" selected="selected" >' + data[i].state + '</option>');
                                                  } else {
                                                      $('#states').append('<option value="' + data[i].id + '">' + data[i].state + '</option>');
                                                  }
                                              }
                                          }
                                      });


                         } else {
                             $('#countries').append('<option value="' + data[i].id + '" ' + selected + '>' + data[i].country + '</option>');
                         }
                     } else {
                         $('#countries').prepend('<option value="">------------------</option>');

                         if (country_value == data[i].id) {

                             $('#countries').append('<option value="' + data[i].id + '" selected="selected" >' + data[i].country + '</option>');


                             $.getJSON(controller + "?d=states&v=" + country_value,
                                      function (data) {

                                          $('#states').html(defaultState);
                                          if ($('#countries').val() == 43) {
                                              $("#statelabel").html("Province");
                                              $("#stateTitle").html('<select id="states"><option value="">' + phrases['province'] + '</option></select>');
                                          }
                                          else {
                                              $("#statelabel").html("State");
                                          }

                                          if (!data) {
                                              $('#states, .channel-dropdown').hide();
                                              $('#channels').get(0).selectedIndex = 0;
                                              $("label[for='state']").hide();
                                              $('#states').html('');
                                          } else { //show states or provinces
                                              $('#states, .channel-dropdown').show();
                                              $("label[for='state']").show();
                                              $('#states').show();
                                              for (var i = 0; i < data.length; i++) {
                                                  if (i == 0)
                                                      $('#states').append('<option value="">------------------</option>');
                                                  if (state_value == data[i].id) {
                                                      $('#states').append('<option value="' + data[i].id + '" selected="selected" >' + data[i].state + '</option>');
                                                  } else {
                                                      $('#states').append('<option value="' + data[i].id + '">' + data[i].state + '</option>');
                                                  }
                                              }
                                          }
                                      });


                         } else {
                             $('#countries').prepend('<option value="' + data[i].id + '" ' + selected + '>' + data[i].country + '</option>');

                         }
                         $('#countries').prepend(defaultCountry);
                     }
                 }
                 if (!country_value) {
                     $('#countries').get(0).selectedIndex = 0;
                 }
                 $("label[for='state']").hide();
                 $('#states').hide();
             });

    //load solutions drop-down
    $.getJSON(controller + "?d=solutions&lang=" + lang,
             function (data) {
                 solutions = data;
                 for (var i = 0; i < data.length; i++) {
                     if (i == 0)
                         $('#solutions').append('<option value="">------------------</option>');


                     if (solution_value == data[i].id) {
                         $('#solutions').append('<option value="' + data[i].id + '" selected="selected">' + data[i].solution + '</option>');
                     } else {
                         $('#solutions').append('<option value="' + data[i].id + '">' + data[i].solution + '</option>');
                     }
                 }
                 $('#search-button').show();
             });

    //get channels
    $.getJSON(controller + "?d=channels&lang=" + lang,
             function (data) {
                 for (var i = 0; i < data.length; i++) {
                     if (i == 0)
                         $('#channels').append('<option value="">------------------</option>');
                     if (channels_value == data[i].id) {
                         $('#channels').append('<option value="'+data[i].id+'" title="'+data[i].channelDescription+'" selected="selected">' + data[i].channel + '</option>');
                     } else {
                         $('#channels').append('<option value="'+data[i].id+'" title="'+data[i].channelDescription+'">' + data[i].channel + '</option>');
                     }
                 }
             });

    //countries drop-down
    $('#countries').change(function() {
        if ($('#colorbox').is(':visible'))
            parent.jQuery.fn.colorbox.close();
        //populate state drop-down
        $.getJSON(controller + "?d=states&v=" + this.value,
                 function (data) {

                     $('#states').html(defaultState);
                     if ($('#countries').val() == 43) {
                         $("#statelabel").html("Province");
                         $("#stateTitle").html('<select id="states"><option value="">' + phrases['province'] + '</option></select>');
                     }
                     else {
                         $("#statelabel").html("State");
                     }

                     if (!data) {
                         $('#states, .channel-dropdown').hide();
                         $('#channels').get(0).selectedIndex = 0;
                         $("label[for='state']").hide();
                         $('#states').html('');
                     } else { //show states or provinces
                         $('#states, .channel-dropdown').show();
                         $("label[for='state']").show();
                         $('#states').show();
                         for (var i = 0; i < data.length; i++) {
                             if (i == 0)
                                 $('#states').append('<option value="">------------------</option>');
                             $('#states').append('<option value="' + data[i].id + '">' + data[i].state + '</option>');
                         }
                     }
                 });
    });


    //states drop-down
    $('#states').change(function() {
    });

    $('#solutions').keyup(function() {
        $('#solutions').triggerHandler("change");
    });

    $('#channels').keyup(function() {
        $('#channels').triggerHandler("change");
    });

    if (!$.browser.msie) {
        $('#solutions').mousedown(function() {
            $('#solutions').mousemove(function() {
                $('#solutions').triggerHandler("change");
            })
        });
        $('#directory').css('border-collapse', 'collapse');

//        $('#solutions').mouseover(function() {
//            $('#solutions').triggerHandler("change");
//        })

        $('#solutions').blur(function() {
            parent.jQuery.fn.colorbox.close();
            $('#solutions').unbind("mousemove");
        })

        $('#channels').mousedown(function() {
            $('#channels').mousemove(function() {
                $('#channels').triggerHandler("change");
            })
        });

//        $('#channels').mouseover(function() {
//            $('#channels').triggerHandler("change");
//        })

        $('#channels').blur(function() {
            parent.jQuery.fn.colorbox.close();
            $('#channels').unbind("mousemove");
        })

    } else {
        $('#channels').mousedown(function() {
            if ($('.solution-pop-up').is(':visible'))
                parent.jQuery.fn.colorbox.close();
        });

        $('#solutions').mousedown(function() {
            if ($('.channel-pop-up').is(':visible'))
                parent.jQuery.fn.colorbox.close();
        });

    }

    //channels drop-down
    $('#channels').change(function() {

        if ($(this).children(':selected').val() != '') {
            if ($('#colorbox').is(':hidden')) {
                $.fn.colorbox({
                    transition: 'none',
                    title: $(this).children(':selected').text(),
                    initialWidth:545,
                    initialHeight:120,
                    innerWidth:545,
                    innerHeight:120,
                    inline: true,
                    href:'.channel-pop-up',
                    onLoad: function() {
                        $('link[title=colorbox]').attr('href', '/sales/colorbox.css');
                        $('.channel-pop-up .channel-description .col1 .description').html($('#channels option:selected').attr('title'));
                        $('#cboxTitle').css({'color':'#1f58a4','font-size':'18px'});
                        $('#cboxClose').css({'text-transform':'capitalize','padding':'3px 25px 3px 0','background':'url(/sales/images/close-button.gif) right no-repeat'});
                        $('#cboxBottomCenter').html('<div>' + phrases['HIDToolTip'] + '</div>');
                        $('#cboxBottomCenter div').css({'color':'#fff','position':'absolute','right':'30px','bottom':'10px'});
                    },
                    onComplete: function() {
                        $('.form select').css('visibility', 'inherit');
                        $('#colorbox').css('top', '230px');
                        $('.channel-pop-up').show();
						$('#colorbox').css('display','block');
                        var imgClass=getChannelsClass($('#channels option:selected').val());
                        $('.'+imgClass).show();
                    },
                    onCleanup: function() {
                        $('.channel-content, .channel-pop-up').hide();
                    }
                });
            } else {
                $('.channel-content').hide();
                $('#cboxTitle').html($(this).children(':selected').text());
                var imgClass=getChannelsClass($('#channels option:selected').val());
                $('.'+imgClass).show();
                $('#cboxTitle').html($(this).children(':selected').text());
                $('.channel-pop-up .channel-description .col1 .description').html($('#channels option:selected').attr('title'));
            }
        } else {
            if ($('.channel-pop-up').is(':visible'))
                parent.jQuery.fn.colorbox.close();
        }
    });

    //solutions drop-down
    $('#solutions').change(function() {

        if ($(this).children(':selected').val() != '') {
            if ($('#colorbox').is(':hidden')) {
                $.fn.colorbox({
                    transition: 'none',
                    title: $(this).children(':selected').text(),
                    initialWidth:580,
                    initialHeight:290,
                    innerWidth:580,
                    innerHeight:290,
                    inline: true,
                    href:'.solution-pop-up',
                    onLoad: function() {
                        $('link[title=colorbox]').attr('href', '/sales/colorbox.css');
                        $('.solution-pop-up .solution-description .col1 .description').html(solutions[parseInt($('#solutions').val()) - 1].solutionDescription);
                        $('#cboxTitle').css({'color':'#1f58a4','font-size':'18px'});
                        $('#cboxClose').css({'text-transform':'capitalize','padding':'3px 25px 3px 0','background':'url(/sales/images/close-button.gif) right no-repeat'});
                        $('#cboxBottomCenter').html('<div>HID Global Solution Tool Tip</div>');
                        $('#cboxBottomCenter div').css({'color':'#fff','position':'absolute','right':'30px','bottom':'10px'});
                    },
                    onComplete: function() {
                        $('.form select').css('visibility', 'inherit');
                        $('#colorbox').css('top', '196px');
                        if ($('#channels').is(':visible'))
                            $('#colorbox').css('top', '263px');

						$('#colorbox').css('display','block');
                        $('.solution-pop-up').show();
                        var className = getSolutionsClass($('#solutions option:selected').val());
                        //var imgClass=$('#cboxTitle').text().replace(/ /g,'').replace(/&/g,'');
                        $('.' + className).show();
                    },
                    onCleanup: function() {
                        $('.solution-pop-up, .solution-content').hide();
                    }
                });
            } else {
                $('.solution-pop-up .solution-content').hide();
                $('#cboxTitle').html($(this).children(':selected').text());
                var className = getSolutionsClass($('#solutions option:selected').val());
                $('.' + className).show();
                $('.solution-pop-up .solution-description .col1 .description').html(solutions[parseInt($('#solutions').val()) - 1].solutionDescription);
            }
        } else {
            if ($('.solution-pop-up').is(':visible'))
                parent.jQuery.fn.colorbox.close();
        }
    });

    //help pop-up
    $('.help-button').click(function() {
        if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
            $('link[title=colorbox]').attr('href', '/sales/colorboxIE2.css')
        } else {
            $('link[title=colorbox]').attr('href', '/sales/colorbox2.css')
        }
        $.fn.colorbox({
            transition: 'none',
            title: phrases['HIDSalesSupport'],
            initialWidth:544,
            initialHeight:245,
            innerWidth:544,
            innerHeight:245,
            inline: true,
            href:'.help-pop-up',
            onLoad: function() {

                $('#cboxTitle').css({'color':'#1f58a4','font-size':'18px'});
                $('#cboxClose').css({'text-transform':'capitalize','padding':'3px 25px 3px 0','background':'url(/sales/images/close-button.gif) right no-repeat'});
            },
            onComplete: function () {
                $('.help-pop-up').show();
				$('#colorbox').css('display','block');
            },
            onCleanup: function() {
                $('.help-pop-up').hide();
            }
        });
    });

    //search buton
    $('#search-button').click(function() {
        //display breadcrumb
        $('#country').html($('#countries').children(':selected').text() + ' >  ');
        if ($('#states').children(':selected').val() > 1)
            $('#state').html($('#states').children(':selected').text() + ' >  ');
        if ($('#channels').children(':selected').val() > 1)
            $('#channel').html($('#channels').children(':selected').text() + ' >  ');
        if ($('#solutions').children(':selected').val() > 1)
            $('#solution').html($('#solutions').children(':selected').text() + ' >  ');

        if ($('#countries option:selected').val() == 1 || $('#countries option:selected').val() == 43)
            $('#insideSales').show();
        else
            $('#insideSales').hide();

        if ($('#countries option:selected').val() == 1 && $('#channels option:selected').val() == '') {
            alert(phrases['channel'])
            return;
        }

        if ($('#countries option:selected').val()) {
            $('#directory').hide();
            $('#loading').show();
            $('#loading').css('display', 'block');
            $('#solution').html('');

            if ($('#solutions option:selected').val())
                $('#solution').html($('#solutions option:selected').text());
            //getPeople()
            var types = $('#type').val();
            getPeople(types);
        } else {
            alert(phrases['country'])
        }
    })

    //service search buton
    $('#service-search-button').click(function() {
        if ($('#countries option:selected').val() == 1 && $('#channels option:selected').val() == '') {
            alert(phrases['channel'])
            return;
        }

        if ($('#countries option:selected').val()) {
            $('#directory').hide();
            $('#loading').show();
            $('#loading').css('display', 'block');
            $('#solution').html('');

            if ($('#solutions option:selected').val())
                $('#solution').html($('#solutions option:selected').text());
            //getPeople()
            var types = $('#type').val();
            getPeople(types);
        } else {
            alert(phrases['country'])
        }
    })

    $('.deeplink').click(function() {
        var link = $(this).attr('href');
        $('#solutions option').each(function(index, value) {
            if ($(this).text().toLowerCase().replace(/ /ig, "_").indexOf(link)) {
                $('#solutions').val(index).change();
                return;
            }

        })
    })

});


function searchClick() {


    //display breadcrumb
    $('#country').html($('#countries').children(':selected').text() + ' >  ');
    if ($('#states').children(':selected').val() > 1)
        $('#state').html($('#states').children(':selected').text() + ' >  ');
    if ($('#channels').children(':selected').val() > 1)
        $('#channel').html($('#channels').children(':selected').text() + ' >  ');
    if ($('#solutions').children(':selected').val() > 1)
        $('#solution').html($('#solutions').children(':selected').text() + ' >  ');

    if ($('#countries option:selected').val() == 1 || $('#countries option:selected').val() == 43)
        $('#insideSales').show();
    else
        $('#insideSales').hide();

    if ($('#countries option:selected').val() == 1 && $('#channels option:selected').val() == '') {
        alert(phrases['channel'])
        return;
    }

    if ($('#countries option:selected').val()) {
        $('#directory').hide();
        $('#loading').show();
        $('#loading').css('display', 'block');
        $('#solution').html('');

        if ($('#solutions option:selected').val())
            $('#solution').html($('#solutions option:selected').text());
        //getPeople()
        var types = $('#type').val();
        getPeople(types);
    } else {
        alert(phrases['country'])
    }
}

function checkdropvalue(){

		if ($('#countries option').length<2 || $('#states option').length <2 || $('#channels option').length <2 || $('#solutions option').length<2)
			setTimeout("checkdropvalue()",1000);
        else
            searchClick();

}


if (country_value) {
	setTimeout("checkdropvalue()",1000);
}

// ascending order
function SortByOrder(x, y) {
    return x.sortorder - y.sortorder;
}

//function getPeople()
function getPeople(type) {
    var state = ($('#states').val()) ? $('#states').val() : '';

    $.getJSON(controller + "?d=" + type + "&c=" + $('#countries').val() + "&p=" + state + "&s=" + $('#solutions').val() + "&l=" + $('#channels').val() + "&lang=" + lang,
             function(data) {
                 location.href = "#d=" + type + "&c=" + $('#countries').val() + "&p=" + state + "&s=" + $('#solutions').val() + "&l=" + $('#channels').val() + "&lang=" + lang
                 if ($('#colorbox').is(':visible')) parent.jQuery.fn.colorbox.close();
                 if (!data) {
                     $('#loading').delay(400).fadeOut(100);
                     $('#directory table:first').html('<tr><td>No results found</td></tr>');
                     $('#directory').delay(400).fadeIn(400);
                 } else {

                     var htmloutput = '';

                     data.sort(SortByOrder);
                     //TODO: add js sort function to sort data by data.sortorder to display custom sorting
                     for (var i = 0; i < data.length; i++) {
                         $('#directory table:first').html('<tr><th class="person">' + phrases['representative'] + '</th><th class="contact">' + phrases['ContactInformation'] + '</th><th class="solution-cell">' + phrases['Solutions'] + '</th><th class="bio-row"></th></tr>');
                         if (data[i].exclude == 1) {
                             htmloutput += '<tr class="result-row"><td colspan=3><a href="#" onclick="return unexclude(' + data[i].id + ')">[ UnExclude ]</a> ' + data[i].name + '</td></tr>';
                         } else {
                             //HID sales rep
                             htmloutput += '<tr class="result-row"><td class="person">';
                             htmloutput += '<img src="/sales/images/wwsales_headshots/' + data[i].photo + '" class="photo">';
                             htmloutput += '<div class="name-title"><strong>' + data[i].name + '</strong><br>';

                             if (data[i].title)
                                 htmloutput += data[i].title + '<br>';
                             if (data[i].subtitle)
                                 htmloutput += data[i].subtitle + '<br>';
                             if (data[i].bio)
                                 htmloutput += '<a href="#view-bio" class="view-bio">' + phrases['more'] + '</a>';

                             htmloutput += '</div>';
                             if ($.inArray(location.href.substring(0,location.href.indexOf('#')), devEnvironment) > -1) {
                                 htmloutput += (data[i].exclude == 1) ? '<br clear="all"><br><a href="#" onclick="return unexclude(' + data[i].id + ')">[ ' + phrases['UnExclude'] + ' ]</a>' : '<br clear="all"><br><a href="#" onclick="return exclude(' + data[i].id + ')">[ ' + phrases['Exclude'] + ' ]</a>';
                                 var sortDropDown = createSortDropDown(data.length, data[i].sortorder);
                                 htmloutput += '<br>Sort order: <select class="sortorder" id="pid' + data[i].id + '">' + sortDropDown;
                             }
                             htmloutput += '</td><td class="contact">';
                             //Contact
                             htmloutput += phrases['Tel'] + ' ' + data[i].phone + '<br>';
                             if (data[i].fax)
                                 htmloutput += phrases['Fax'] + ' ' + data[i].fax + '<br>';
                             htmloutput += phrases['Email'] + ' <a href="mailto:' + data[i].email + '">' + data[i].email + '</a><br>';
                             htmloutput += '</td><td class="solutions-products"><div class="solutions">';
                             var s = '';
                             if (data[i].solutions) {
                                 for (var j = 0; j < data[i].solutions.length; j++) {
                                     s += data[i].solutions[j].solution + ', ';
                                 }
                                 htmloutput += s.replace(/, $/, '');
                             }
                             s = '';
                             htmloutput += '</div><div class="products">';
                             if (data[i].products) {
                                 for (var k = 0; k < data[i].products.length; k++) {
                                     s += data[i].products[k].product + ', ';
                                 }
                                 htmloutput += s.replace(/, $/, '');
                             }
                             htmloutput += '</div>';
                             if (data[i].specialty) {
                                 htmloutput += '<br><strong>' + phrases['Specializes'] + '</strong><br>' + data[i].specialty;
                             }
                             htmloutput += '</td><td class="bio-row">' + data[i].bio + '</td></tr>';
                         }
                     }
                 }
                 $('#directory table:first').append(htmloutput).ready(function() {
					
                     $('#loading').delay(400).fadeOut(100);
                     $('#directory').delay(400).fadeIn(400);
					 	
                     $('.sortorder').change(function() {
						 var states = ($('#states').val()) ? $('#states').val() : '';
                         $.getJSON(controller + "?d=addsortorder&pid=" + $(this).attr('id').replace('pid', '') + "&order=" + $(this).val() + "&c=" + $('#countries').val() + "&p=" + states + "&s=" + $('#solutions').val() + "&l=" + $('#channels').val(), function() {
                             $('#service-search-button').click();
                             $('#search-button').click();
                         })
                     })
                 });
                 $('#directory table:first .result-row:last td').css('border', '0')
                 $('.view-bio').colorbox({
                     opacity: .5,
                     transition: 'none',
                     initialWidth:425,
                     initialHeight:350,
                     innerWidth:425,
                     innerHeight:350,
                     inline:true,
                     href:".bio-pop-up",
                     onLoad: function() {
                         $('link[title=colorbox]').attr('href', '/sales/colorbox1.css');
                         $('.bio-pop-up .bio-solution').html($(this).parent().parent().parent().children('.solutions-products').children('.solutions').html());
                         var area = $('#state').html().replace(' &gt;', '');
                         if (area.length < 1) area = $('#country').html().replace(' &gt;', '');
                         $('.bio-pop-up .bio-area').html(area);
                         $('.bio-pop-up .text').html('<div class="bio-contact">' + $(this).parent().parent().parent().children('.person').html() + '</div><br clear="all"><br>');
                         $('.bio-contact .name-title').append('<br>' + $(this).parent().parent().parent().children('.contact').html());
                         $('.bio-pop-up .text').append('<div class="bio-title">' + phrases['Area'] + ':</div><br>' + $(this).parent().parent().parent().children('.bio-row').html());
                         $('.bio-pop-up .top')
                     },
                     onComplete: function () {
                         $('.bio-pop-up').show();
                     },
                     onCleanup: function() {
                         $('.bio-pop-up').hide();
                     }

                 });
             });

}

function exclude(people_id) {
    var state = ($('#states').val()) ? $('#states').val() : '';
    var query = "&c=" + $('#countries').val() + "&p=" + state + "&s=" + $('#solutions').val() + "&l=" + $('#channels').val() + "&lang=" + lang;

    $.getJSON(controller + "?d=exclude&pid=" + people_id + query, function() {
        $('#search-button').click();
    });

    return false;
}


function movesalesdatatoproduction(opration) {
    var query = "op=" + opration;
    if (confirm("are you want to insert sales data to production database.")) {

        $.ajax({
            type: "GET",
            url: "datainsert.php?" + query,
            success: function(msg) {
                alert("your data has been inserted");
            }
        });

    }

}


function movesalesdatatostaging(opration) {
    var query = "op=" + opration;
    if (confirm("are you want to insert sales data to staging database.")) {

        $.ajax({
            type: "GET",
            url: "datainsert.php?" + query,
            success: function(msg) {
                alert("your data has been inserted");
            }
        });


    }

}


function movesalesdatatomovable(opration) {
    var query = "op=" + opration;
    if (confirm("are you want to insert sales data to moveable database.")) {

        $.ajax({
            type: "GET",
            url: "datainsert.php?" + query,
            success: function(msg) {
                alert("your data has been inserted");
            }
        });


    }

}


function unexclude(people_id) {
    var state = ($('#states').val()) ? $('#states').val() : '';
    var query = "&c=" + $('#countries').val() + "&p=" + state + "&s=" + $('#solutions').val() + "&l=" + $('#channels').val() + "&lang=" + lang;

    $.getJSON(controller + "?d=unexclude&pid=" + people_id + query, function() {
        $('#service-search-button').click();
        $('#search-button').click();
    });

    return false;
}

function createSortDropDown(length, sortorderval) {
    var html = '';

    for (var i = 0; i < length; i++) {
        if (sortorderval == i) {
            html += '<option value=' + i + ' selected>' + i + '</option>';
        } else {
            html += '<option value=' + i + ' >' + i + '</option>';
        }

    }
    return html + '</select>';
}

function getSolutionsClass(value) {
    var cssClassArray = ['','PhysicalAccess','LogicalAccess','PrintingEncoding','OEMEmbeddedSolutions','CashlessPayments','eGovernment','FoodAnimal','IndustryLogistics'];

    return cssClassArray[value];
}

function getChannelsClass(value) {
    var cssClassArray = ['','OEM','Distributor','IntegratorInstaller','End-User','','Government','FinancialServices','HealthCare','Consultants'];

    return cssClassArray[value];
}
