/**
 * Extend the DOM with get element by classname
 */
function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) 
	{
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}
/**
 * Function to show/hide the loginbox
 */
/*function showHideLogin() {
	var loginBox = getElementsByClass('tx-felogin-pi1');
	loginBox = loginBox[0];
	if (loginBox == '[object HTMLDivElement]' || loginBox == '[object]') {
		if (loginBox.style.display == 'none') {
			loginBox.style.width = '207px';
			loginBox.style.display = 'block';
		} else {
			loginBox.style.display = 'none';
			loginBox.style.width = '1px';
		}
	}
}
*/
/**
 * Checks if there is any errors in the login, if so displays the box 
 */
function checkLogin() {
	var status = document.getElementById('loginstatus');
	if (status == '[object HTMLInputElement]' || loginBox == '[object]') {
		if (status.value == 'error' || status.value == 'forgot' || status.value == 'change') {
			showHideLogin();
		} else if (status.value == 'logout' || status.value == 'success') {
			//showHideLogin();
			//setTimeout("showHideLogin()", 500);
		}
	}	
}

Ext.onReady(function() {
    
//    var tip_container = Ext.get('loginwindow').parent('div.tx-felogin-pi1',true);
//    var new_container = '<div id="tipafriend_wrapper" class="frame_white_theme">'+tip_container.innerHTML+'</div>'
//    Ext.get(tip_container).remove();
    
//    Ext.DomHelper.append(document.body,new_container);
    //tipafriend mouseoverevent
    
    if(Ext.get('loginstatus') != null){
      if(Ext.get('loginstatus').getValue() == 'forgot')
      {
           var popup = Ext.query('#loginwindow')[0].parentNode;    
           Ext.get(popup).show();
      }
    }
    Ext.get('loginbox_link').on('click', function(e) {
       var popup = Ext.query('#loginwindow')[0].parentNode;
	   //alert(e.getTarget().parentNode.parentNode.offsetTop)
       if (Ext.isIE7) {
            popup.style.top = (e.getTarget().offsetTop+e.getTarget().parentNode.offsetTop+e.getTarget().parentNode.parentNode.offsetTop+30)+'px';
            popup.style.left = (e.getTarget().offsetLeft+e.getTarget().parentNode.offsetLeft+e.getTarget().parentNode.parentNode.offsetLeft-133)+'px';
       } else {
            popup.style.top = (e.getTarget().offsetTop+e.getTarget().parentNode.offsetTop+e.getTarget().parentNode.parentNode.offsetTop+28)+'px';
            popup.style.left = (e.getTarget().offsetLeft+e.getTarget().parentNode.offsetLeft+e.getTarget().parentNode.parentNode.offsetLeft-133)+'px';
       }
       Ext.get(popup).show();
    },this);
    
    Ext.select('body').on('click', function(e) {
        if ((typeof(this) != 'undefined' || Ext.get('loginwindow') != null) && (!e.within(Ext.get('loginwindow')) && !e.within(Ext.get('loginbox_link').parent()))) {
            Ext.get('loginwindow').parent().hide(true);
        }
    },this);
});



