function submitForm() {
	if(document.forms[0].usernamevar.value == "" ){
         alert("Debe ingresar el usuario");
         return;
    }               
    document.forms[0].login.value = document.forms[0].usernamevar.value;
    document.forms[0].action=location.protocol+"//"+document.domain+"/identity/oblix/apps/lost_pwd_mgmt/bin/lost_pwd_mgmt.cgi?backUrl="+ ObEncodeURIComponent(document.URL);
    document.forms[0].submit();
}

// wrapper for encodeURIComponent
function ObEncodeURIComponent(str)
{
    var okURIChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.!~*'()";
	if ( str == "" )
    return "";
         
    if (typeof encodeURIComponent == "function") {
    	// encodeURIComponent is defined, so use it.
        return encodeURIComponent(str);
    }
    else {
	    // old version of JavaScript, no encodeURIComponent, so use our wrapper
	    // first encode Unicode string into UTF-8
	    var s = utf8(str);
        var enc = "";
         
        // Now make %xx encoded string
        for ( var i = 0; i < s.length; i++ ) {
	        if ( okURIChars.indexOf( s.charAt(i) ) == -1 )
	        	enc += "%" + toHex( s.charCodeAt(i) );
	        else
	            enc += s.charAt(i);
        }
     return enc;
     }
}
         
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function delCookie(name,path,domain) {
	var today = new Date();
	var deleteDate = new Date(today.getTime() - 48 * 60 * 60 * 1000); // minus 2 days
	var cookie = name + "="
		+ ((path == null) ? "" : "; path=" + path)
		+ ((domain == null) ? "" : "; domain=" + domain)
		+ "; expires=" + deleteDate;
	document.cookie = cookie;
}

function errorMessage(element1) {
   element1 = document.getElementById(element1);
   invalid_credentials = readCookie('INVALID_CREDENTIALS'); 
   if (invalid_credentials!=null && invalid_credentials=='true'){
   		delCookie('INVALID_CREDENTIALS','/');
   		element1.style.display = 'block';
   }else{
      element1.style.display = 'none';
   }
   return;
}

function getPort() {
	var url = window.location.href;
	var nohttp = url.split('//')[1];
	var hostPort = nohttp.split('/')[0]
	if(hostPort.split(':').length>1){
		var hostPort2 = hostPort.split(':')[1]
		//alert ('tiene puerto ' + hostPort2)
		return ':'+hostPort2;
	}else{
		//alert ('no tiene puerto ' + hostPort+ ' ' + hostPort.split(':').length)
		return '';	
	}
}

function sessionMessage(element1) {
   element1 = document.getElementById(element1);
   user_auth_once = readCookie('USER_AUTH_ONCE'); 
   if (user_auth_once!=null && user_auth_once=='true'){
   		delCookie('USER_AUTH_ONCE','/');
   		element1.style.display = 'block';
   }else{
      element1.style.display = 'none';
   }
   return;
}