
function setupLoginForm(){
	if (document.getElementById('Login') != null)
		document.getElementById('Login').action = constructLoginFormUrl();
}

function setupContactForm(){
	if (document.getElementById('contact_form') != null)
		document.getElementById('contact_form').action = constructEmailFormUrl();
}

function parseUrl(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};
    
    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }
    
    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }
    
    return uri;
}

function constructLoginFormUrl()
{
	var url = parseUrl(document.location);
	
	return 'https://' + url['authority'] + '/AWE/Login_j_acegi_security_check';
}

function constructEmailFormUrl()
{
	var url = parseUrl(document.location);
	
	return 'http://' + url['authority'] + '/AWE/MarketingContact.action';
}

function requireJs(libraryName) {
    document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
}

function loadGoogleAnalytics()
{	
	_uacct = "UA-2730543-1";
	urchinTracker();
}

onload = function()
{ 
   loadGoogleAnalytics();
}

requireJs("http://www.google-analytics.com/urchin.js");

function popup(page,width,height) {
  remote = window.open(page,"popup","width=" + width + ",height=" + height + ",top=10,left=10,resizable=1,status=1,menubar=1,toolbar=1,scrollbars=1,location=1,directories=1");
  remote.opener = self;
	if (window.focus) {remote.focus();}
 }
 
function bindEnterKeySubmit()
{
	if (arguments.length < 1) return;
	
	var elem = arguments[0];
	
	var handler = ((arguments.length >= 2) ? arguments[1] :
		  function(e){
			var keynum;
			if(window.event) // IE
			{
			keynum = e.keyCode
			}
			else if(e.which) // Netscape/Firefox/Opera
			{
			keynum = e.which
			}
			
			if (keynum == 13)
			{
				var form = Event.element(e).up('form');
				
				if (form != null)		
					form.submit();
				
				Event.stop(e);
			}
		});
	
	Event.observe(elem, 'keypress', handler);
}
    
function setLang(lang) {
  $("idioma").value = lang;
	$("lang_form").submit();
}
//							setupLangForm();
