// JQuery box_search
$(document).ready(function () {
    $(".box_search").hide();
    $(".ico_search").click(function () {
        $(".box_search").toggle(0);
        $(".box_search .searchinput").focus();
        return false;
    });

    // Form error message
    $('.AxFormLine input').each(function () {
        var getAxrequiredmsg = $(this).parent('div').find('.AxRequiredMessage').length;
        var getAxvalidationmsg = $(this).parent('div').find('.AxValidationMessage').length;
        if (getAxrequiredmsg > 0 || getAxvalidationmsg > 0) {
            $(this).addClass('reqInputfield');
        }
    });
    $('.AxFormLine textarea').each(function () {
        var getAxrequiredmsg = $(this).parent('div').find('.AxRequiredMessage').length;
        if (getAxrequiredmsg > 0) {
            $(this).addClass('reqInputfield');
        }
    });

    $('.formindent input').blur(function () {
        var getError = $(this).parent('div').find('span:visible').length;
        if (getError > 0) {
            $(this).addClass('reqInputfield');
            $(this).parent('div').find('span:visible').css('position', 'absolute').css('top', '-99999em');
        }
        else {
            $(this).removeClass('reqInputfield');
            $(this).parent('div').find('span:visible').css('position', 'relative').css('top', '0');
        }
    });

    $('#form_memberreg :submit').click(function () {
        $('.formindent input').each(function () {
            var getError = $(this).parent('div').find('span:visible').length;
            if (getError > 0) {
                $(this).addClass('reqInputfield');
                $(this).parent('div').find('span:visible').css('position', 'absolute').css('top', '-99999em');
            }
            else {
                $(this).removeClass('reqInputfield');
                $(this).parent('div').find('span:visible').css('position', 'relative').css('top', '0');
            }
        });
    });

    $('#loginbtn :submit').click(function () {
        $('.userinput input').each(function () {
            var getError = $(this).parent('div').find('span:visible').length;
            if (getError > 0) {
                $(this).addClass('reqInputfield');
                $(this).parent('div').find('span:visible').css('position', 'absolute').css('top', '-99999em');
            }
            else {
                $(this).removeClass('reqInputfield');
                $(this).parent('div').find('span:visible').css('position', 'relative').css('top', '0');
            }
        });
    });

    // JQuery clickable portal buttons

    var block = $("#btns_portal li");
    block.click(function () {
        window.location = $(this).find("a:first").attr("href")
    });

    // Login bar

    $(".login-link, .logout-link").click(function () {
        $("#loginwrapper").animate({ opacity: 'toggle' });
        $("#loginwrapper input#ctl00_ctl00_ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_SiteBody_Login_3_Login1_UserName").focus();
        return false;
    });

    // Download icons

    $("a[href$='.pdf']:not(:has(img))").addClass("pdf");
    $("a[href$='.doc']:not(:has(img))").addClass("doc");
    $("a[href$='.ppt']:not(:has(img))").addClass("ppt");
    $("a[href$='.png']:not(:has(img)), a[href$='.bmp']:not(:has(img))").addClass("png");
    $("a[href$='.txt']:not(:has(img)), a[href$='.rft']:not(:has(img))").addClass("txt");
    $("a[href$='.zip']:not(:has(img)), a[href$='.rar']:not(:has(img))").addClass("zip");

    // Products

    $('#box_img').each(function () {
        setHeight();
    });   

    $('#WorldMap a').hover(function () {
        $(this).parent('li').find('div').show();
    }, function () {
        $(this).parent('li').find('div').hide();
    });

});     // End Ready function

function setHeight() {	
	var leftHeight = $("#box_left").height();
	var rightHeight = $("#box_right").height();
	if (leftHeight < 1) {
		setTimeout(setHeight, 100);
	}
	else if (leftHeight > rightHeight) {
		$('#box_img').height(leftHeight);
	}
	else {
		$('#box_img').height(rightHeight);
	}
}

// Search box clear input
$.fn.clearOnFocus = function(){
 
	return this.focus(function(){
        var v = $(this).val();
        $(this).val( v === this.defaultValue ? '' : v );
    }).blur(function(){
        var v = $(this).val();
        $(this).val( v.match(/^\s+$|^$/) ? this.defaultValue : v );
    });
 
};

$(document).ready(function() { 
	$('#box_search input').clearOnFocus(); 

	$("#rmapage ul li a[href$='.pdf']").addClass("pdf");
	$("#rmapage ul li a[href$='.doc']").addClass("doc");
	$("#rmapage ul li a[href$='.ppt']").addClass("ppt");
//	$("#rmapage ul li a[href$='.png']").addClass("png");
	$("#rmapage ul li a[href$='.txt'], #rmapage ul li a[href$='.rft']").addClass("txt");
	$("#rmapage ul li a[href$='.zip'], #rmapage ul li a[href$='.rar']").addClass("zip"); 

	$("#rmapage ul").css('margin','0');
	$("#rmapage ul li").css('list-style-type','none');

});

$(function(){
	if (document.location.href.indexOf('loginstatus=failed') > 0)
	$("#loginwrapper").show();

	$("#mainmenu li").addClass("mainmenu-border");
 });

$(function(){
	if (document.location.href.indexOf('login=true') > 0)
	$("#loginwrapper").show();
 });


jQuery.fn.hint = function (blurClass) {
    if (!blurClass) {
        blurClass = 'blur';
    }

    return this.each(function () {
        // get jQuery version of 'this'
        var $input = jQuery(this),

        // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

        function remove() {
            if ($input.val() === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) {
            // on blur, set value to title attr if text is blank
            $input.blur(function () {
                if (this.value === '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title

            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};


// safari fix
$(window).unload(function () { });
