// JavaScript Document

$.fn.SelectCustomizer = function() {
    // Select Customizer jQuery plug-in
    // based on customselect by Ace Web Design http://www.adelaidewebdesigns.com/2008/08/01/adelaide-web-designs-releases-customselect-with-icons/
    // modified by David Vian http://www.ildavid.com/dblog
    return this.each(function() {
        var obj = $(this);
        var name = obj.attr('id');
        var id_slc_options = name + '_options';
        var id_icn_select = name + '_select';
        var id_holder = name + '_holder';
        var custom_select = name + '_customselect';
        obj.after("<div id=\"" + id_slc_options + "\"> </div>");
        obj.find('option').each(function(i) {
            $("#" + id_slc_options).append("<div title=\"" + $(this).html() + "\" id=\"" + $(this).attr("value") + "\" class=\"selectitems\"><span>" + $(this).html() + "</span></div>");
        });
        obj.before("<input type=\"hidden\" value =\"" + this.title + "\" name=\"" + this.name + "\" id=\"" + custom_select + "\"/><div id=\"" + id_icn_select + "\"><span>" + this.title + "</span></div><div id=\"" + id_holder + "\"> </div>").remove();
        $("#" + id_icn_select).click(function() {
            $("#" + id_holder).slideToggle(200);
        });
        $("#" + id_holder).append($("#" + id_slc_options)[0]);
        $("#" + id_holder + " .selectitems").mouseover(function() {
            $(this).addClass("hoverclass");
        });
        $("#" + id_holder + " .selectitems").mouseout(function() {
            $(this).removeClass("hoverclass");
        });
        $("#" + id_holder + " .selectitems").click(function() {
            $("#" + id_holder + " .selectedclass").removeClass("selectedclass");
            $(this).addClass("selectedclass");
            var thisselection = $(this).html();
            $("#" + custom_select).val(this.title);
            $("#" + id_icn_select).html(thisselection);
            $("#" + id_holder).slideToggle(250);
            var titletag = this.id;            
            if (id_holder == 'globalweb_holder') {
                if (titletag != 'Global Websites') {
                    dropdownredirect(titletag);
                }
            }
            if (id_holder == 'sign-upcountry_holder') {
                if (titletag != 'Select an Country') {
                    countrydropdown();
                }
            }

            if (id_holder == 'archive_holder') {
                if (titletag != 'Year') {
                    newsddChangepg(titletag, $('#hdnHieId').val());
                }
            }
            if (id_holder == 'sign-upcity_holder') {
                if (titletag != 'Select an City') {
                    citydropdown();
                }
            }
            if (id_holder == 'billingcity_holder') {
                if (titletag != 'Select an City') {
                    billingcitydropdown();
                }
            }
            if (id_holder == 'billingCountry_holder') {
                if (titletag != 'Select an Country') {
                    billingcountrydropdown();
                }
            }
            if (id_holder == "year1_holder") {

                areportchange(titletag);
            }
            if (id_holder == "year2_holder") {
                quchange(titletag);
            }
            if (id_holder == "year3_holder") {
                shchange(titletag);
            }
            if (id_holder == "usertype_holder") {
             document.getElementById("ctl00_ContentPlaceHolder1_hfusertype").value=titletag;
            }
        });
        $("#" + id_holder + "").mouseleave(function() {
            if (id_icn_select == 'sign-upcountry_select') {
                mouseoutcountry();
            }
            if (id_icn_select == 'sign-upcity_select') {
                mouseoutcity();
            }
            if (id_icn_select == 'billingCountry_select') {
                mouseoutbillcountry();
            }
            if (id_icn_select == 'billingcity_select') {
                mouseoutbillcity();
            }
        });
        $("#" + id_icn_select).hover(function() {
            $(this).parent().hover(function() {
            }, function() {

                $("#" + id_holder).slideUp("fast");
            });
        });
    });
}

$(document).ready(function() {
	
	$('#globalweb, #archive, #year1, #year2, #year3,#usertype').SelectCustomizer();
	
});

function dropdownredirect(title) {
    var response = title.split("_PH_SPL");
    var s1 = response[0].toLowerCase().indexOf("www");
    var s2 = response[0].toLowerCase().indexOf("http");
    var s3 = response[0].toLowerCase().indexOf("https")
    if (s1 == -1 && s2 == -1 && s3 == -1)
        window.open(response[0], response[1]);
    else if(s2!=-1 || s3!=-1)
        window.open(response[0], response[1]);
    else if (s1 != -1)
        window.open("http://"+response[0], response[1]);
}





$(document).ready(function() {
    var pathname = window.location.pathname;
   
    $('li.mainLi a').each(function(index) {
   var aHref = $(this).attr('href');
   if(pathname==aHref){
   $('li.mainLi').find("a.mainLink").removeClass("thisPage")
   $(this).parents("li.mainLi").find("a.mainLink").addClass("thisPage");
   }
  });
});

