var isMobile = false;

$(document).ready(function() 
{
    if(false == isIE6)
    {
        $('#footer').mouseover(function(){
            $('#FooterFader').stop(true, false);
            $('#FooterFader').animate({opacity: "1"}, 200);
        });
        
        $('#footer').mouseout(function(){
            $('#FooterFader').stop(true, false);
            $('#FooterFader').animate({opacity: "0.5"}, 200);
        });
    }
    
    $('#headloginform').keypress(function(e)
	{
      	if(e.which == 13)
 		{
       		document.headloginform.submit();
       	}
 	});
    
    $('#pagelang_sellang').blur(function(){
        
        Header_HideLangSelect();
    });
    
    if(navigator)
    {
        if(navigator.userAgent)
        {
            if( navigator.userAgent.match(/Android/i) ||
                navigator.userAgent.match(/webOS/i) ||
                navigator.userAgent.match(/iPhone/i) ||
                navigator.userAgent.match(/iPod/i)
            )
            {
                isMobile = true;
            }
        }
    }

    $('body').children('iframe').hide();
});


function Header_ShowLangSelect()
{
    $('#popup_lang').css('display', 'block');
    $('#pagelang_sellang').focus();
}

function Header_HideLangSelect()
{
    $('#popup_lang').hide();
}


function RowEffect($row, $color)
{
	$($row).css("background-color", $color);
}

function ConfirmClick($url, $message)
{
	if(confirm($message))
	{
		location.href=$url;	
	}
}

function ForgotPassword(formdata)
{
    var data = {'popup':'true'};
    $.extend(data, formdata);
    
    dWindow(false, {
		ajaxUrl: httpdir + '/lostpassword.php',
        ajaxData: data,
		cacheAjaxResult: false,
        overlayHide: true,
        fitcontent:true,
        fitcontent_marginheight:0,
        fitcontent_marginwidth:0,
        fitminwidth:100,
        fitminheight:100,
        onClose: function(Wnd, status) {
            
            if(1 == status)
            {
                var lp_email = Wnd.window.find('#lp_usr_inp').val();
                ForgotPassword({'l_usr_inp': lp_email, 'sendinfo' : 'true'});
            }
            
        }
    });
    
    return false;
}

function ShowTooltipRel(obj, Text)
{
    var position = $(obj).offset();
    var width = $(obj).width();
    ShowTooltip(position.left+((width/2)-11),position.top, Text);
}

function ShowTooltip(Left, Top, Text)
{
    if(isIE6) return;
    
    $('#rt_innerwin').html(Text);
    $('#ToolTip').show();
    var LeftOffSet = $('#rt_innerwin').width() * 0.5;
    var LeftX = -LeftOffSet + Left;
    var ScrollTop = $(window).scrollTop();
    var TopY = -30 + Top - ScrollTop;
    $('#ToolTip').css('top', TopY + "px" );
    $('#ToolTip').css('left', LeftX + "px" );
}

function HideTooltip()
{
    $('#ToolTip').hide();
}

function htmlspecialchars (string, quote_style, charset, double_encode) 
{
    var optTemp = 0,
        i = 0,
        noquotes = false;
    if (typeof quote_style === 'undefined' || quote_style === null) {
        quote_style = 2;
    }
    string = string.toString();
    if (double_encode !== false) { // Put this first to avoid double-encoding
        string = string.replace(/&/g, '&amp;');
    }
    string = string.replace(/</g, '&lt;').replace(/>/g, '&gt;');

    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE': 1,
        'ENT_HTML_QUOTE_DOUBLE': 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE': 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i = 0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'ENT_IGNORE' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/'/g, '&#039;');
    }
    if (!noquotes) {
        string = string.replace(/"/g, '&quot;');
    }

    return string;
}

