function $e(elm) {
    return document.getElementById(elm);
}

var usernameText = "Enter Your Username";
function loginText(focus) {
    var login = $e('username');
    if (focus) {
        if (login.value == usernameText) {
            login.value = "";
        }
    } else {
        if (login.value == "") {
            login.value = usernameText;
        }
    }
}
var loc;
function bodyLoad() {
    var loginForm = document.forms[0];
    if (loginForm) {
        loginForm.onsubmit = function() {return ValidUnamePwd();};
    }

    var accordian = $e('accordianContainer');
    if (accordian) {
        slider.init('accordianContainer',1)
    }

    loc = window.location.href;
    loc = loc.substring(0,loc.lastIndexOf("/"))
    var returnURL = $e('ReturnURL');
    if (returnURL) {
        returnURL.value = loc + "/error.html";
    }

    loginText(false);
    var infoTmp = "";
    for (var i=0;i<info.length;i++) {
        infoTmp += $c(info[i]);
    }
    $e('info').onclick = function() {
        var m = new Array(':','o','t','l','i','a','m');
        window.location = m.reverse().join("") + infoTmp;
    }
    errors();
}

var mTimeOut = 500;
var mCloseTimer = 0;
var menuItem = 0;

function menuOpen(elm) {
    var sub = $e(elm.id + 'sub');
    menuCancelClose();
    menuClose();
    menuItem = sub;
    if (menuItem)
        menuItem.style.visibility = 'visible';
}
function menuClose() {
    if (menuItem)
        menuItem.style.visibility = 'hidden';
}
function menuCloseTime() {
    mCloseTimer = window.setTimeout(menuClose, mTimeOut);
}
function menuCancelClose() {
    if (mCloseTimer) {
        window.clearTimeout(mCloseTimer);
        mCloseTimer = null;
    }
}

function debug(s) {
    d = $e('debug');
    if (!d) {
        var div = document.createElement("DIV");
        div.id = 'debug';
        div.innerHTML = "";
        document.body.appendChild(div);
        d = $e('debug');
    }
    d.innerHTML += s;
}
var info = new Array(105,110,102,111,64,104,101,97,108,116,104,112,108,117,115,105,110,99,46,110,101,116);
function $c(n) {
    return String.fromCharCode(n);
}

function errors() {
//    var errorContainer = $e('errorContainer');
errorContainer = true;
    if (errorContainer) {
        var found = false;
        var err = window.location.search.substring(1);
        var errArr = err.split("&");
        for (var i=0;i<errArr.length;i++) {
            var tmp = errArr[i].split("=");
            if (tmp[0] == "Error") {
                try {
                    $e('errorContainer').innerHTML += decodeURIComponent(tmp[1]);
                } catch (e) {

                }
            } else if (tmp[0].indexOf("a1-content") != -1) {
                found = true;
            } else if(tmp[0].indexOf("-content") != -1) {
                found=true;
                slider.process($e(tmp[0].replace("-content","-header")));
            }
        }
        if (!found) {
            var a1 = $e('a1-content');
            if (a1)
                a1.style.display = 'none';
        }

    }
}

// HR360 Login box code start
function ValidUnamePwd() {
    var valid = true;
    if (trim($e("username").value) == "" || $e("username").value == usernameText) {
        $e("username").className += " error";
        valid = false;
    }
    else
        $e("username").className = $e("username").className.replace("error","");
    if (trim($e("password").value) == "") {
        $e("password").className += " error";
        valid = false;
    }
    else
        $e("password").className = $e("password").className.replace("error","");
    return valid;
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}

// HR360 Login box code end

var slider=function(){
	var array=[]; var speed=10; var timer=10;
	return{
		init:function(t,c){
			var s,ds,l,i,y;
			s=document.getElementById(t); ds=s.getElementsByTagName('div'); l=ds.length; i=y=0;
			for(i=0;i<l;i++){
				var d,did; d=ds[i]; did=d.id;
				if(did.indexOf("header")!=-1){
					y++; d.onclick=new Function("slider.process(this)");
                                        d.title="Click to expand";
				}else if(did.indexOf("content")!=-1){
					array.push(did.replace('-content','')); d.maxh=d.offsetHeight;
					if(c!=y){d.style.height='0px'; d.style.display='none'}
					else{d.style.display='block'}
				}
			}
		},
		process:function(d){
			var cl,i; cl=array.length; i=0;
			for(i;i<cl;i++){
				var s,h,c,cd;
				s=array[i]; h=document.getElementById(s+'-header');
				c=s+'-content'; cd=document.getElementById(c); clearInterval(cd.timer);
				if(h==d&&cd.style.display=='none'){
					cd.style.display='block'; this.islide(c,1);
				}else if(cd.style.display=='block'){this.islide(c,-1)}
			}
		},
		islide:function(i,d){var c,m; c=document.getElementById(i); m=c.maxh; c.direction=d; c.timer=setInterval("slider.slide('"+i +"')",timer)},
		slide:function(i){
			var c,m,h,dist; c=document.getElementById(i); m=c.maxh; h=c.offsetHeight;
			dist=(c.direction==1)?Math.round((m-h)/speed):Math.round(h/speed);
			if(dist<=1){dist=1}
			c.style.height=h+(dist*c.direction)+'px'; c.style.opacity=h/c.maxh; c.style.filter='alpha(opacity='+(h*100/c.maxh)+')';
			if(h<2&&c.direction!=1){
				c.style.display='none'; clearInterval(c.timer);
			}else if(h>(m-2)&&c.direction==1){clearInterval(c.timer)}
		}
};}();

function register() {
    var infoTmp = ":";
    for (var i=0;i<info.length;i++) {
        infoTmp += $c(info[i]);
    }
    var m = new Array('o','t','l','i','a','m');
    var s = "Request to Register for HR360";
    var b = "Requesting registration to HR360";
    var qs = "?subject=" + s + "&body=" + b;
    window.location = m.reverse().join("") + infoTmp + qs;

}
