

var doLoginActionOnSucess;
var current_block_id;



function doLoginWindow(actionOnSuccess){
    window.overLibY=cursor.y;
    window.overLibX=cursor.x;

    if (actionOnSuccess) {
        doLoginActionOnSucess=actionOnSuccess;
    } else {
        doLoginActionOnSucess=function(){
            loadScript("/include/user.js.php");
            if (window.translations["XOOPS__MD_SW_LOGIN_OK"]) {
                showOverlib(window.translations["XOOPS__MD_SW_LOGIN_OK"],'');
            } else {
                cClick();
            }
            setTimeout("cClick()", 1000);
            refresh_block(220);
                
        };
    }

    doAJAXGetCall(window.login_path, drawLoginForm);
}




function refresh_block(id){
    current_block_id=id;
    b=document.getElementById("blockContent_"+id);
    if (!b){
    	return;
    }

    myadmin_menu='<table width=182 cellpadding=0 cellspacing=0>';
    myadmin_menu+='<td><a href="/modules/shoppingWorld/admin/entry_manager.php?op=list_entries">myAdmin</a> | <a href="/user.php?op=logout">Logout</a> | <a href=http://www.worldsoft-downloads.info/shoppingworld/kunden/faq.html target=_sw_help>Help</a></td></table>';

    b.innerHTML=myadmin_menu;
    return;
}

function drawLoginForm(){
    if (xmlHttp.readyState == 4) {  
        result=xmlHttp.responseText;
        result=parse_and_replace_constants(result);
        showOverlib(result, 'LogIn');
    }
}



function runFunc(){
    args=arguments;
    fname=args.shift();
    alert(func);
}


function checkLoginStatus(){
    if (xmlHttp.readyState == 4) {  
        result=xmlHttp.responseText;

        if (result=="LOGIN_FAILED") {
            alert(window.translations["XOOPS__US_INCORRECTLOGIN"]);
        }
        if (result=="LOGIN_OK") {


            doLoginActionOnSucess();


            /*
            if (doLoginActionOnSucess=="selfReload") {
                //self.location.reload();
                self.location=self.location;
            } else {
                doLoginActionOnSucess();
                loadScript("/include/user.js.php");
                cClick();

            }
            //alert("Login OK.");
            */

        }

    }
}

function doSendPasswordWindow(){
    doAJAXGetCall(window.send_pass_path, drawSendPasswordForm);
}

function drawSendPasswordForm(){
    if (xmlHttp.readyState == 4) {  
        result=xmlHttp.responseText;
        result=parse_and_replace_constants(result);
        showOverlib(result, window.translations['XOOPS__US_SENDPASSWORD']);
    }
}


    function checkPasswordStatus(){
        if (xmlHttp.readyState == 4) {  
            result=xmlHttp.responseText;
            showOverlib(result, '');
        }
        return false;
    }


    function doSendPassword(f){
        uname=f.uname.value;
        url="/lostpass.php?embedded=1&login="+uname;
        doAJAXGetCall(url, checkPasswordStatus);
        return false;
    }



    function doLogin(f){
        //
        //loadOverlibContent("/test.php");

        uname=f.uname.value;
        pass=f.pass.value;
      	if (f.rememberme && f.rememberme.checked){
				rememberme=true;
			} else {
				rememberme=false;
			}
		  





        if (uname && pass) {
            url="/user.php?embedded=true&direct_execute=true&op=login&uname="+uname+"&pass="+pass;
            if(rememberme){
                url+="&rememberme=1";
            }

            loadOverlibContent(url, checkLoginStatus);
        }
        return false;
    }

    function doRegisterWindow(){
        window.overlibCaption="New user registration";
        loadOverlibContent("/register.php?op=register_embedded&direct_execute=1");
    }


    /*
    function onClickSubmitButton(){
        if (checkRegistrationFormFields()){
            form_query_string=getFormDataAsQueryString("userinfo");
        }
        // All is ok. Lets send the request to the server
        doAJAXPostCall("/register.php", form_query_string, checkRegistrationStatus);
        return false;

        //alert(form_query_string.length);





        //alert(getFormDataAsQueryString("userinfo"));
    }
    */

    function xoopsFormValidate_userinfo() { 
        return true;
        //return onClickSubmitButton();
    }


    function checkRegistrationStatus(){
        if (xmlHttp.readyState == 4) {  
            result=xmlHttp.responseText;
            if (result.match("REGISTRATION_OK") || result.match("LOGIN_OK")) {
                doLoginActionOnSucess();
                /*
                showOverlib(result,'');
                if (current_entry_id) {
                    //tab2Remove=tabViews[current_entry_id].getTab(3);
                    //tabViews[entry_id].removeTab(tab2Remove);
                }*/


            } else {
                alert(result);
            }

        }

    }


