function godoc(doc) {
	document.location.href = doc;
}

function wclose() {
	window.close();
	window.opener.location.href=window.opener.location.href;
}

function wopen(page,id,action,wname,wancho,walto) {
	var ancho = wancho;
	var alto = walto;
	var derecha=(screen.width-ancho)/2;
	var parameters="toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width="+ancho+",height="+alto+",left="+derecha+",top=50";
	var url = page+'?id='+id+'&action='+action;
	newwindow = window.open(url,wname,parameters);
	newwindow.focus();
}

function ver(strId) {
	var id = strId;
	if(eval("div"+id+".style.display")=="inline") {
		eval("div"+id+".style.display='none'");
	} else {
		eval("div"+id+".style.display='inline'");
	}
}




function checkforblanks() {
	for (var i=0; i<arguments.length; i+=2) {
		if (!arguments[i]) {
			alert("El campo " + arguments[i+1] + " es obligatorio.");
			return false;
		}
	}
	return true;
}

function displaynew(campo,valor) {
	if(valor == 1) {
		document.getElementById("myfile"+campo).style.visibility = 'visible';
		if(document.getElementById("myfile"+campo).value!="") {
			document.getElementById("myimg"+campo).src = document.getElementById("myfile"+campo).value;
		}
	} else {
		document.getElementById("myimg"+campo).src = document.getElementById("myhid"+campo).value;
		document.getElementById("myfile"+campo).style.visibility = 'hidden';
	}
}


function URLactual(pagina) {
	if (document.location != pagina)
	{
		document.location.href = pagina;
	}
}

function showrank(dato) {
	for(var i=1;i<6;i++) {
		if(dato==i) {
			document.getElementById("rank_"+i).style.display = 'inline';
			document.getElementById("rank_p"+i).className = 'rankactivo';
		} else {
			document.getElementById("rank_"+i).style.display = 'none';
			document.getElementById("rank_p"+i).className = 'rankgris';
		}
	}
}

function displaymenu(id) {
	//var z = document.getElementById("admenu").getElementsByTagName("ul").length;
	var z = 4;
	if(document.getElementById("m"+id)) {
		if(document.getElementById("m"+id).style.display=='block') {
			document.getElementById("p"+id).style.backgroundColor= '#FFFFFF';
			document.getElementById("m"+id).style.display='none';
		} else {
			//document.getElementById("p"+id).style.backgroundColor = '#FF0000';
			//document.getElementById("p"+id).style.borderBottom = '1px solid #000000';
			document.getElementById("m"+id).style.display= 'block';
		}
	}
	for (var i=1; i<z; i++) {
		if(id!=i) {
			if(document.getElementById("p"+i)) {
				document.getElementById("p"+i).style.backgroundColor = '#FFFFFF';
				
			}
			if(document.getElementById("m"+i)) {
				document.getElementById("m"+i).style.display = 'none';
			}
		}
	}
}

function hidediv(strdiv) {
	var divname=strdiv;
	document.getElementById(divname).style.display='none';
}

function showdiv(strdiv) {
	var divname=strdiv;
	document.getElementById(divname).style.display='inline';
}


//FUNCIONES AJAX

function URLEncode(strEncode) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = strEncode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
	return false;
}

function URLDecode(strDecode) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = strDecode;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
   return false;
}


function cargaw(id,pic,action) {
	var ancho = 500;
	var alto = 200;
	var derecha=(screen.width-ancho)/2;
	var parameters="toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width="+ancho+",height="+alto+",left="+derecha+",top=50";
	var url = 'imgmod1.asp?id='+id+'&pic='+pic+'&action='+action;
	newwindow = window.open(url,'wimg',parameters);
	newwindow.focus();
}

function showhelp(obj1,num) {
	var obj2 = document.getElementById('help'+num);
	var y = 0;
	var x = 0;
	while (obj1.offsetParent) {
		x += obj1.offsetLeft;
		y += obj1.offsetTop;
		obj1 = obj1.offsetParent;
	}
    obj2.style.left = x+50+'px';
	obj2.style.top = y+'px';
	obj2.style.display = 'inline';
}

function hidehelp(num) {
	var obj2 = document.getElementById('help'+num);
	obj2.style.display = 'none';
}
