function goTo(url) {
	  document.location.href= url;
	}
function goToConfirm(url,msg) {
    if(confirm(msg)){
        document.location.href= url;
    }
}

function errores() {
    var errorsTag = getElementsByClass('error',null,'span');

    for (var i = 0; i < errorsTag.length; i++) {
        var errorTag = errorsTag[i];
        var componente = errorTag.parentNode;
        if(componente.className == "componente"){
            componente.className = "componente_error";
        }
    }
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function verImagen(url) {
	window.open(url, '', 'scrollbars=no', 'resizable=yes', 'width=400', 'height=200');
}


function openPop(url, x, y) {
    return window.open(url, 'Backoffice Sindicatura de Comptes','resizable=no, width=' + x + ',height=' + y);
}

/* Method GET to POST
 * http://www.gettopost.com/gettopost.html
 * © 2007 Steve Chambers (stec77@gmail.com)
 */
function convertGetToPost(url) {

    //var url = document.getElementById('url').value;
    var qMarkPos = url.indexOf('?');

    if (qMarkPos >= 0) {
      var urlBase = url.substring(0, qMarkPos);
      var getRequest = url.substring(qMarkPos + 1);
    } else {
      var urlBase = url;
      var getRequest = '';
    }

    // If no protocol is specified (i.e. no colon in URL), prepend the HTTP protocol
    /*if (urlBase.indexOf(':') < 0) {
      urlBase = 'http://' + urlBase;
    } */

    var hiddenForm = document.getElementById('hiddenForm');
    hiddenForm.action = './' + urlBase;
    hiddenForm.method = "post";

    var equalsPos = getRequest.indexOf('=');
    while (equalsPos >= 0) {
      var ampersandPos = getRequest.indexOf('&');
      if ((ampersandPos < 0) || (equalsPos < ampersandPos)) {
        var input = document.createElement("input");
        input.type = "hidden";
        input.name = getRequest.substring(0, equalsPos);
        input.value = (ampersandPos >= 0) ? getRequest.substring(equalsPos + 1, ampersandPos) : getRequest.substring(equalsPos + 1);
        hiddenForm.appendChild(input);
      }
      getRequest = (ampersandPos >= 0) ? getRequest.substring(ampersandPos + 1) : '';
      equalsPos = getRequest.indexOf('=');
    }
    hiddenForm.submit();
}

function subcadena (texto,maxLong) {
    return (texto.length > maxLong ? texto.substring(0,maxLong-1) : texto);
}
