/*var banners_feading_number = 0;
var banners_feading_number2 = 0;*/
var banner_state = 0;
var phone_selected = false;

$(document).ready(function () {
    //If there is a form we set the rules for telephone code autocomplete
    if ($('form')) prepareCountryCode();

    //initiation fading banners in right column
    if ($('.banner_box_right')) {

        for (var i = 0; i <= $('.middle_line').length - 1; i++) {
            if ($('.middle_line:nth(' + i + ') > strong > span').height() < 24) {
                $('.middle_line:nth(' + i + ') > strong > span').css({ 'line-height': '42px' });
            }
            if ($('.bottom_line:nth(' + i + ') > span').height() < 24) {
                $('.bottom_line:nth(' + i + ') > span').css({ 'line-height': '46px' });
            }
            if ($('.bottom_line:nth(' + i + ') > span').height() < 34) {
                $('.bottom_line:nth(' + i + ') > span').css({ 'padding-top': '7px' });
            }

            if ($('.banner_box_right:nth(' + i + ')').parent().hasClass('small')) {
            }
        }

        $(".banner_box_right > a:nth-child(2)").hide();
        setTimeout('start_banners_fading()', 6000);
    }

    //new language menu
    $("#lang_nav_box").hover(
		function () {
		    $('#lang_nav:hidden').stop(true, true).slideDown('faster');
		},
		function () {
		    $('#lang_nav:visible').stop(true, true).slideUp('faster');
		}
	);

	$("#call-options-box2").hover(
		function () {
		    $('#call-options:hidden').stop(true, true).slideDown('faster');
		},
		function () {
		    $('#call-options:visible').stop(true, true).slideUp('faster');
		}
	);
	
	
	$("#dropdown-box").hover(
		function () {
		    $('.dropdown:hidden').stop(true, true).slideDown(400);
		},
		function () {
		    $('.dropdown:visible').stop(true, true).slideUp(300);
		}
	);

    $("div.nav_item_blue_01, #topBtn1, #topBtn2").hover(function () {
        $(this).find('ul:first:hidden').fadeIn('faster');
        $(this).find('ul > li.parent').mouseover(function () {
            $(this).addClass('active');

            if ($(this).hasClass('left_alignment')) {
                $(this).find('ul').css({ 'left': $(this).position().left - $(this).width() });
            }
            else {
                $(this).find('ul').css({ 'left': $(this).position().left + $(this).width() });
            }
            $(this).find('ul:first:hidden').fadeIn('faster');

        });
        $(this).find('ul > li.parent').mouseleave(function () {
            $(this).removeClass('active');
            $(this).find('ul').stop(true, true).fadeOut(10, function() {
				$(this).find('ul').attr('style','');
			});
        });
    },
    function () {
        $(this).find('ul').stop(true, true).fadeOut(10, function() {
			$(this).find('ul').attr('style','');
		});
    });


    // Prepare glossary linked words
    prepare_glossary_tips();

    // Prepare admin linked words
    prepare_admin_tips();

    prepare_hover_tips();

    // Register global error handler
    window.onerror = function (message, uri, line) {
        // An unplanned exception occured, it should not stop
        // the form working however, as we've caught it here.  We know
        // that typically it is a cosmetic UI error in JQuery on IE8.
        // Return true to prevent the browser from raising an exception.
        return true
    }

    //initialization custom toggle boxes
    if ($('.custom_toggle_title')) {
        $('.custom_toggle_title').bind('click', function () {
            var obj = $(this).next('.custom_toggle_box');

            if (obj.hasClass('active')) {
                obj.css({ 'padding-bottom': '0px' });
                obj.animate({
                    height: 1
                }, 500, function () {
                    obj.removeClass('active');
                });
            }
            else {
                obj.css({ 'padding-bottom': '18px' });
                obj.animate({
                    height: obj.find('.custom_toggle_content').height()
                }, 500, 'linear', function () {
                    obj.addClass('active');
                });
            }
        });
    }

 
    /*if ($('#show_homepage_row1')) {
        $('#bottom_box_parent').removeClass('hidden_box');
    }*/
	
	$("li.parent > a").click(function(){
    	return false;
	});
});

function start_banners_fading(){
	
	var state = banner_state + 1;
	if ($("#banner_line" + state + " > a:nth(0)").hasClass('active')) {
		$("#banner_line" + state + " > a:nth(0)").fadeOut(400, function() {
			
		}).removeClass('active');
		
		$("#banner_line" + state + " > a:nth(1)").fadeIn(400).addClass('active');
	} else {
		$("#banner_line" + state + " > a:nth(1)").fadeOut(400, function() {
			
		}).removeClass('active');
		
		$("#banner_line" + state + " > a:nth(0)").fadeIn(400).addClass('active');
	}

	banner_state = (banner_state + 1) % $('.banner_box_right').size();
	setTimeout('start_banners_fading()', 6000);
}

function prepare_glossary_tips() {
    // Iterate over each glossary item
    $("span[class='glossary_tip']").each(function(index) {
        // Get the tooltip text
        tip_text = $(this).attr("title");

        // Remove the title element to prevent ei and chrome showing two tips
        $(this).attr("title", "");

        // Add the tool tip, using text passed via the class attribute
        $(this).qtip({
            content: tip_text,
            show: { when: { event: 'click' }, effect: { type: 'fade', length: 300} },
            hide: { when: { event: 'mouseout' }, effect: { type: 'fade', length: 300} },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                }
            },
            style: {
                border: {
                    width: 5,
                    radius: 10
                },
                padding: 10,
                textAlign: 'center',
                tip: true, // Give it a speech bubble tip with automatic corner detection
                name: 'dark' // Style it according to the preset 'cream' style
            }
        });
    });
}

function prepare_admin_tips() {
    // Iterate over each glossary item
    $("span[class='admin_tip']").each(function(index) {
        // Get the tooltip text
        tip_text = $(this).attr("title");

        // Remove the title element to prevent ei and chrome showing two tips
        $(this).attr("title", "");

        // Add the tool tip, using text passed via the class attribute
        $(this).qtip({
            content: tip_text,
            show: { when: { event: 'mouseover' }, effect: { type: 'fade', length: 300} },
            hide: { when: { event: 'mouseout' }, effect: { type: 'fade', length: 300} },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                }
            },
            style: {
                width: 400,
                border: {
                    width: 1,
                    radius: 1
                },
                padding: 10,
                textAlign: 'center',
                tip: true, // Give it a speech bubble tip with automatic corner detection
                name: 'green' // Style it according to the preset 'cream' style
            }
        });
    });
}

function prepare_hover_tips() {
	// Iterate over each glossary item
    $("span[class='glossary_tip_hover']").each(function(index) {
        // Get the tooltip text
        tip_text = $(this).attr("title");

        // Remove the title element to prevent ei and chrome showing two tips
        $(this).attr("title", "");

        // Add the tool tip, using text passed via the class attribute
        $(this).qtip({
            content: tip_text,
            show: { when: { event: 'mouseover' }, effect: { type: 'fade', length: 300} },
            hide: { when: { event: 'mouseleave' }, effect: { type: 'fade', length: 300} },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                },
				adjust: { 
					x: 0, 
					y: 1 
				} 
            },
			style: {
				  border: {
					 width: 3,
					 radius: 5,
					 color: '#324466'
				  },
				  classes: {
					  content: 'hover_tips_content',
					  tip: 'hover_qtip-tip'
				  },
				  background: '#212e46',
				  textAlign: 'center',
				  padding: 3,
				  textAlign: 'center',
				  tip: 'bottomMiddle',
				  name: 'dark' // Inherit the rest of the attributes from the preset dark style
		   	}
        });
    });
}

function prepareCountryCode() {
    if ($("#country") && $("#phone")) {
        if ($("#country").val()) $("#phone").val(getCountryCode($("#country").val()));
        $("#phone").keyup(function() { if ($(this).val() != "") phone_selected = true; else phone_selected = false; });
        $("#country").keyup(function() { if (!phone_selected) $("#phone").val(getCountryCode($(this).val())); });
        $("#country").change(function () { if (!phone_selected) $("#phone").val(getCountryCode($(this).val())); });
    }
}



function faq_toggle(id){
    $("p[id$='i_A_" + id + "']").toggle("slow");
    
    // Prevent anchor being followed
    return(false);
}

function toggle(id) {
    $("[id$='" + id + "']").toggle("slow");

    // Prevent anchor being followed
    return (false);
}

function hide(id) {
    $("[id$='" + id + "']").hide();

    // Prevent anchor being followed
    return (false);
}

function getCountryCode(country) {
    var code = '+';
    switch (country) {
        case "Afghanistan": code = "+93"; break;
        case "Albania": code = "+355"; break;
        case "Algeria": code = "+213"; break;
        case "American Samoa": code = "+684"; break;
        case "Andorra": code = "+33"; break;
        case "Anguilla": code = "+264"; break;
        case "Antigua and Barbuda": code = "+268"; break;
        case "Argentina": code = "+54"; break;
        case "Angola": code = "+244"; break;
        case "Antarctica": code = "+672"; break;
        case "Armenia": code = "+374"; break;
        case "Aruba": code = "+297"; break;
        case "Australia": code = "+61"; break;
        case "Austria": code = "+43"; break;
        case "Azerbaijan": code = "+994"; break;
        case "Bahamas": code = "+242"; break;
        case "Bahrain": code = "+973"; break;
        case "Bangladesh": code = "+880"; break;
        case "Barbados": code = "+1246"; break;
        case "Belarus": code = "+375"; break;
        case "Belgium": code = "+32"; break;
        case "Belize": code = "+501"; break;
        case "Benin": code = "+229"; break;
        case "Bermuda": code = "+441"; break;
        case "Bhutan": code = "+975"; break;
        case "Bolivia": code = "+591"; break;
        case "Bonaire": code = "+599"; break;
        case "Bosnia and Herzegovina": code = "+387"; break;
        case "Botswana": code = "+267"; break;
        case "Bouvet Island": code = ""; break;
        case "Brazil": code = "+55"; break;
        case "British Virgin Islands": code = "+1284"; break;
        case "Brunei": code = "+673"; break;
        case "Bulgaria": code = "+359"; break;
        case "Burkina Faso": code = "+226"; break;
        case "Burma": code = "+95"; break;
        case "Burundi": code = "+257"; break;
        case "Cambodia": code = "+855"; break;
        case "Cameroon": code = "+237"; break;
        case "Canada": code = "+1250"; break;
        case "Canary Islands": code = "+34"; break;
        case "Cape Verde": code = "+238"; break;
        case "Caroline Islands": code = "+680"; break;
        case "Cayman Islands": code = "+345"; break;
        case "Central African Republic": code = "+236"; break;
        case "Chad": code = "+235"; break;
        case "Chile": code = "+56"; break;
        case "China": code = "+86"; break;
        case "Christmas Island": code = "+61"; break;
        case "Cocos (Keeling) Islands": code = "+61"; break;
        case "Colombia": code = "+57"; break;
        case "Comoros": code = "+269"; break;
        case "Congo": code = "+225"; break;
        case "Cook Islands": code = "+682"; break;
        case "Costa Rica": code = "+506"; break;
        case "Côte d’Ivoire": code = ""; break;
        case "Croatia": code = "+385"; break;
        case "Cuba": code = "+53"; break;
        case "Curacao": code = "+599"; break;
        case "Cyprus": code = "+357"; break;
        case "Czech Republic": code = "+420"; break;
        case "Congo": code = "+242"; break;
        case "Democratic Republic of the Congo": code = "+242"; break;
        case "Denmark": code = "+45"; break;
        case "Djibouti": code = "+253"; break;
        case "Dominica": code = "+599"; break;
        case "Dominican Republic": code = "+809"; break;
        case "Ecuador": code = "+593"; break;
        case "Egypt": code = "+20"; break;
        case "El Salvador": code = "+503"; break;
        case "England": code = "+44"; break;
        case "Guinea": code = "+240"; break;
        case "Eritrea": code = "+291"; break;
        case "Estonia": code = "+372"; break;
        case "Ethiopia": code = "+251"; break;
        case "Falkland Islands": code = "+500"; break;
        case "Faroe Islands": code = "+298"; break;
        case "Fiji": code = "+679"; break;
        case "Finland": code = "+358"; break;
        case "France": code = "+33"; break;
        case "French Guiana": code = "+594"; break;
        case "French Polynesia": code = "+689"; break;
        case "Gabon": code = "+241"; break;
        case "Gambia": code = "+220"; break;
        case "Georgia": code = "+995"; break;
        case "Germany": code = "+49"; break;
        case "Ghana": code = "+233"; break;
        case "Gibraltar": code = "+350"; break;
        case "Great Britain": code = "+44"; break;
        case "Greece": code = "+30"; break;
        case "Greenland": code = "+299"; break;
        case "Grenada": code = "+599"; break;
        case "Guadeloupe": code = "+590"; break;
        case "Guam": code = "+671"; break;
        case "Guatemala": code = "+502"; break;
        case "Guinea Republic": code = "+224"; break;
        case "Guinea-Bissau": code = "+245"; break;
        case "Guyana": code = "+592"; break;
        case "Haiti": code = "+509"; break;
        case "Holland": code = "+31"; break;
        case "Honduras": code = "+504"; break;
        case "Hong Kong S.A.R., China": code = "+852"; break;
        case "Hungary": code = "+36"; break;
        case "Iceland": code = "+354"; break;
        case "India": code = "+91"; break;
        case "Indonesia": code = "+62"; break;
        case "Iran": code = "+98"; break;
        case "Iraq": code = "+964"; break;
        case "Ireland": code = "+353"; break;
        case "Israel": code = "+972"; break;
        case "Italy": code = "+39"; break;
        case "Ivory Coast": code = "+225"; break;
        case "Jamaica": code = "+876"; break;
        case "Japan": code = "+81"; break;
        case "Jordan": code = "+962"; break;
        case "Kampuchea": code = "+855"; break;
        case "Kazakhstan": code = "+7"; break;
        case "Kenya": code = "+254"; break;
        case "Kingdom of Cambodia": code = "+855"; break;
        case "Kiribati": code = "+686"; break;
        case "Korea": code = "+82"; break;
        case "Kuwait": code = "+965"; break;
        case "Kyrgyzstan": code = "+996"; break;
        case "Laos": code = "+856"; break;
        case "Latvia": code = "+371"; break;
        case "Lebanon": code = "+961"; break;
        case "Lesotho": code = "+266"; break;
        case "Liberia": code = "+231"; break;
        case "Libya": code = "+218"; break;
        case "Liechtenstein": code = "+41"; break;
        case "Lithuania": code = "+370"; break;
        case "Luxembourg": code = "+352"; break;
        case "Macao S.A.R., China": code = "+853"; break;
        case "Macedonia": code = "+389"; break;
        case "Madagascar": code = "+261"; break;
        case "Malawi": code = "+265"; break;
        case "Malaysia": code = "+60"; break;
        case "Maldives": code = "+960"; break;
        case "Mali": code = "+223"; break;
        case "Malta": code = "+356"; break;
        case "Marshall Islands": code = "+692"; break;
        case "Martinique": code = "+596"; break;
        case "Mauritania": code = "+222"; break;
        case "Mauritius": code = "+230"; break;
        case "Mayotte": code = "+262"; break;
        case "Mexico": code = "+52"; break;
        case "Micronesia": code = "+691"; break;
        case "Moldova": code = "+373"; break;
        case "Monaco": code = "+33"; break;
        case "Mongolia": code = "+976"; break;
        case "Montenegro (Yugoslavia)": code = "+382"; break;
        case "Montserrat": code = "+664"; break;
        case "Morocco": code = "+212"; break;
        case "Mozambique": code = "+258"; break;
        case "Myanmar": code = "+95"; break;
        case "Namibia": code = "+264"; break;
        case "Nauru": code = "+674"; break;
        case "Nepal": code = "+977"; break;
        case "Netherlands": code = "+31"; break;
        case "Netherlands Antilles": code = "+599"; break;
        case "Nevis": code = "+869"; break;
        case "New Caledonia": code = "+687"; break;
        case "New Zealand": code = "+64"; break;
        case "Nicaragua": code = "+505"; break;
        case "Niger": code = "+227"; break;
        case "Nigeria": code = "+234"; break;
        case "Niue": code = "+683"; break;
        case "Norfolk Island": code = "+672"; break;
        case "North Korea": code = "+850"; break;
        case "Northern Ireland": code = "+353"; break;
        case "Northern Mariana Islands": code = "+1670"; break;
        case "Norway": code = "+47"; break;
        case "Oman": code = "+968"; break;
        case "Pakistan": code = "+92"; break;
        case "Palau": code = "+680"; break;
        case "Panama": code = "+507"; break;
        case "Papua New Guinea": code = "+675"; break;
        case "Paraguay": code = "+595"; break;
        case "Peru": code = "+51"; break;
        case "Philippines": code = "+63"; break;
        case "Pitcairn": code = "+570"; break;
        case "Poland": code = "+48"; break;
        case "Portugal": code = "+351"; break;
        case "Puerto Rico": code = "+1787"; break;
        case "Qatar": code = "+974"; break;
        case "Réunion": code = "+262"; break;
        case "Romania": code = "+40"; break;
        case "Russia": code = "+7"; break;
        case "Rwanda": code = "+250"; break;
        case "Saipan": code = "+670"; break;
        case "Saint Helena": code = "+290"; break;
        case "Samoa": code = "+685"; break;
        case "Sao Tome and Principe": code = "+239"; break;
        case "San Marino": code = "+39"; break;
        case "Saudi Arabia": code = "+966"; break;
        case "Senegal": code = "+221"; break;
        case "Serbia": code = "+381"; break;
        case "Seychelles": code = "+248"; break;
        case "Sierra Leone": code = "+232"; break;
        case "Singapore": code = "+65"; break;
        case "Slovakia": code = "+421"; break;
        case "Slovenia": code = "+386"; break;
        case "Solomon Islands": code = "+677"; break;
        case "Somalia": code = "+252"; break;
        case "South Africa": code = "+27"; break;
        case "South Georgia and the South Sandwich Islands": code = "+44"; break;
        case "South Korea": code = "+82"; break;
        case "Spain": code = "+34"; break;
        case "Sri Lanka": code = "+94"; break;
        case "Saint Kitts and Nevis": code = "+869"; break;
        case "Saint Lucia": code = "+758"; break;
        case "Saint Pierre and Miquelon": code = "+508"; break;
        case "Saint Vincent and the Grenadines": code = "+784"; break;
        case "Sudan": code = "+249"; break;
        case "Suriname": code = "+597"; break;
        case "Svalbard and Jan Mayen": code = "+47"; break;
        case "Swaziland": code = "+268"; break;
        case "Sweden": code = "+46"; break;
        case "Switzerland": code = "+41"; break;
        case "Syria": code = "+963"; break;
        case "Tahiti": code = "+689"; break;
        case "Taiwan": code = "+886"; break;
        case "Tajikistan": code = "+7"; break;
        case "Tanzania": code = "+255"; break;
        case "Timor-Leste": code = "+670"; break;
        case "Thailand": code = "+66"; break;
        case "Togo": code = "+228"; break;
        case "Tokelau": code = "+690"; break;
        case "Tonga": code = "+676"; break;
        case "Trinidad and Tobago": code = "+868"; break;
        case "Tunisia": code = "+216"; break;
        case "Turkey": code = "+90"; break;
        case "Turkmenistan": code = "+993"; break;
        case "Turks and Caicos Islands": code = "+649"; break;
        case "Tuvalu": code = "+688"; break;
        case "Uganda": code = "+256"; break;
        case "Ukraine": code = "+380"; break;
        case "United Arab Emirates": code = "+971"; break;
        case "United Kingdom": code = "+44"; break;
        case "United States": code = "+1"; break;
        case "Uruguay": code = "+598"; break;
        case "Uzbekistan": code = "+7"; break;
        case "Vanuatu": code = "+678"; break;
        case "Venezuela": code = "+58"; break;
        case "Vietnam": code = "+84"; break;
        case "Virgin Islands (British)": code = "+284"; break;
        case "U.S. Virgin Islands": code = "+1340"; break;
        case "Wallis and Futuna": code = "+681"; break;
        case "Western Samoa": code = "+685"; break;
        case "Western Sahara": code = ""; break;
        case "Yemen": code = "+967"; break;
        case "Yugoslavia": code = "+381"; break;
        case "Zaire": code = "+243"; break;
        case "Zambia": code = "+260"; break;
        case "Zimbabwe": code = "+263"; break;
    }

    return code;
}


function onclick_livesupport(){
    // Open new window for live support
    window.open('https://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=4228439601009322029&url=' + escape(document.location.href), 'Chat1523280939266028415', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}

function onclick_livesupport_ru(){
    // Open new window for live support
    window.open('http://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=1603801252837302750&amp;wdid=3049459864703230357&url=' + escape(document.location.href), 'Chat1523280939266028415', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}

function onclick_livesupport_fr(){
    // Open new window for live support
    window.open('http://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=3199847756505366535&amp;wdid=2058479748395369722&url=' + escape(document.location.href), 'Chat173215363199817963', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}



function onclick_livesupport_de(){
    // Open new window for live support
    window.open('http://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=3233062141124868109&amp;wdid=1569738142702589724&url=' + escape(document.location.href), 'Chat3707696612872094173', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}


function onclick_livesupport_it(){
    // Open new window for live support
    window.open('http://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=3599441386353503126&amp;wdid=2509405180294476454&url=' + escape(document.location.href), 'Chat3707696612872094173', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}

function onclick_livesupport_pt(){
    // Open new window for live support
    window.open('http://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=1139823224587501353&amp;wdid=1013264928071206916&url=' + escape(document.location.href), 'Chat3707696612872094173', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}

function onclick_livesupport_es(){
    // Open new window for live support
    window.open('http://livechat.boldchat.com/aid/3426580264338971474/bc.chat?cwdid=3715133479103582207&amp;wdid=523741975120474408&url=' + escape(document.location.href), 'Chat3707696612872094173', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=800'); 
    return false;    
}

