var timerlen = 5;
var slideAniLen = 250;
var direction = new Array();
var timers = new Array();
var startingTime = new Array();
var myObj = new Array();
var endHeight = new Array();
var animInProgressLogin = false;


function login(form) {
           var hcb = /^503/;
           if(hcb.test(form.user.value) && form.user.value.length==8) {
              if(confirm('You will be redirected to the login page on Hawkeye Commodity Brokers Inc website.'))
                 window.location="https://www.futuresorders.com/hcb/cgi-bin/GetFrames";
              return;
           }
           var dch = /^501/;
           if(dch.test(form.user.value) && form.user.value.length==8) {
              if(confirm('You will be redirected to the login page on Discount Commodity House Inc website.'))
                 window.location="https://www.futuresorders.com/dch/cgi-bin/GetFrames";
              return;
           }
           if(form.user.value.toUpperCase() == 'TRIAL') {
              form.action = 'https://www.lindsimulated.com/ticket/create/simtrade';
              form.request_uri.value = '/connect/jsp/index.jsp';
           }
           form.submit();
        }

	document.onkeypress = onEnter;
	if (document.layers)
		document.captureEvents(Event.KEYPRESS);
	function onEnter(e){
      	var keycode;
		var evtobj = window.event? event : e;
      	if(evtobj .which) {
			keycode = evtobj.which;
		}
		else if (evtobj .keyCode) {
    			keycode = evtobj.keyCode;
		}
      	if(keycode==13) {
                if(document.ssoForm.userPassport.value && document.ssoForm.passwordPassport.value) {
                        login(document.ssoForm);
                }
                else if(document.ssoForm2.userClient.value && document.ssoForm2.passwordClient.value) {
                        login(document.ssoForm2);
                }
				else if(document.ssoForm3.userSimTrade.value && document.ssoForm3.passwordSimTrade.value) {
                        login(document.ssoForm3);
                }
        }
	}



function loginBoxRollOver(passedObj){
		if(document.getElementById(passedObj).style.display == "none")
		{
		var x = passedObj.indexOf("Div");
		document.getElementById(passedObj.substr(0,x) + "Img").src = "/image/" + passedObj.substr(0,x) + "Hover.gif";
		}
}
function loginBoxRollOut(passedObj){
		if(document.getElementById(passedObj).style.display == 'none' )
		{
		var x = passedObj.indexOf("Div");
		document.getElementById(passedObj.substr(0,x) + "Img").src = "/image/" + passedObj.substr(0,x) + ".gif";
		}
}

function slidingDown(passedObj){
	
		if(animInProgressLogin)
				return;
		else if(document.getElementById(passedObj).style.display != "none")
                return;
		else
				animInProgressLogin = true;

        direction[passedObj] = "down";
        startslide(passedObj);
		if(passedObj == 'clientBarDiv')
		{
			slidingUp('passportBarDiv');
			slidingUp('simtradeBarDiv');
			document.getElementById('clientBarImg').src = "/image/clientBarSelected.gif";
		}else if(passedObj == 'passportBarDiv'){
			slidingUp('clientBarDiv');
			slidingUp('simtradeBarDiv');
			document.getElementById('passportBarImg').src = "/image/passportBarSelected.gif";
		}else{
			slidingUp('clientBarDiv');
			slidingUp('passportBarDiv');
			document.getElementById('simtradeBarImg').src = "/image/simtradeBarSelected.gif";
		}
}

function slidingUp(passedObj){
        if(document.getElementById(passedObj).style.display == "none")
                return;
        direction[passedObj] = "up";
        startslide(passedObj);
		var x = passedObj.indexOf("Div");
		document.getElementById(passedObj.substr(0,x) + "Img").src = "/image/" + passedObj.substr(0,x) + ".gif";
}

function startslide(passedObj){
        myObj[passedObj] = document.getElementById(passedObj);
        endHeight[passedObj] = parseInt(myObj[passedObj].style.height);
        startingTime[passedObj] = (new Date()).getTime();
        if(direction[passedObj] == "down"){
                myObj[passedObj].style.height = "1px";
        }
        myObj[passedObj].style.display = "block";
        timers[passedObj] = setInterval('slidetick(\'' + passedObj + '\');',timerlen);
}

function slidetick(passedObj){
        var elapsed = (new Date()).getTime() - startingTime[passedObj];
        if (elapsed > slideAniLen)
                endSlide(passedObj)
        else {
                var d =Math.round(elapsed / slideAniLen * endHeight[passedObj]);
                if(direction[passedObj] == "up")
                        d = endHeight[passedObj] - d;
                myObj[passedObj].style.height = d + "px";
        }
        return;
}

function endSlide(passedObj){
        clearInterval(timers[passedObj]);
        if(direction[passedObj] == "up")
                myObj[passedObj].style.display = "none";
        myObj[passedObj].style.height = endHeight[passedObj] + "px";
        delete(timers[passedObj]);
        delete(startingTime[passedObj]);
        delete(endHeight[passedObj]);
        delete(myObj[passedObj]);
        delete(direction[passedObj]);
		animInProgressLogin = false;
        return;
}
