var isIE = document.all?true:false;
var dragobjeto;
var xcord = 0;
var ycord = 0;
document.cursorX = 0;
document.cursorY = 0;

document.onmousemove = getMousePosition;
function getMousePosition(e) {
	if(!isIE){
    	document.cursorX = window.pageXOffset;
    	document.cursorY = window.pageYOffset;
    	document.cursorX = e.pageX;
    	document.cursorY = e.pageY;
	}
	if(isIE){
    	document.cursorX = event.clientX + document.body.scrollLeft;
    	document.cursorY = event.clientY + document.body.scrollTop;
	}
  	mover(dragobjeto);
	return true;

}

function mover(objeto){
	if(objeto!=null){
		if(objeto.sidownaqui==true){
			if(document.cursordown==true){
				objeto.style["top"]= document.cursorY - ycord + 'px';
				objeto.style["left"]= document.cursorX - xcord + 'px';
			}
		}
	}
}
var zmaximo=6;
function establece(objeto){
	var protege = document.getElementById('protege');
	var valor;
	var matriz;
	xcord = document.cursorX - objeto.style.left.NumPx();
	ycord = document.cursorY - objeto.style.top.NumPx();
	objeto.sidownaqui=true;
    document.onselectstart = Function('return false;');
    protege.style['display']='inline';
    objeto.style.zIndex= ++zmaximo;
    if(document.siEsta==true){
		dragobjeto=objeto;
	}
	valor=getCookie(objeto.id);
	matriz = valor.split('/');
	matriz[5]=objeto.style.zIndex;
	valor = Implode(matriz,"/");
	setCookie(objeto.id,valor);
	//document.title = objeto.id + ":" + objeto.tag;
}

function desestablece(objeto){
	var protege = document.getElementById('protege');
	objeto.sidownaqui=false;
	valor = getCookie(objeto.id);
	matriz = valor.split("/");
	matriz[3] = objeto.style['left'];
	matriz[4] = objeto.style['top'];
	valor = Implode(matriz,"/");
	setCookie(objeto.id,valor);
	document.onselectstart = Function('return true;');
	protege.style['display']='none';
	dragobjeto=null;

}

document.cursordown=false;

document.onmousedown=function(){
	document.cursordown=true;
}
document.onmouseup=function(){
	document.cursordown=false;
}


//cerrar objetos
function Cierra(num){
	var VenFlo;
	var VenCont;
	VenFlo=document.getElementById('VenFlo' + num);
	VenCont=document.getElementById("VenCont" + num);
	VenFlo.style['display']='none';
	VenFlo.style['top']= 70 + (num * 20) + 'px';
	VenFlo.style['left']= 70 + (num * 20) + 'px';
	setCookie('VenFlo' + num, 'cerrada');
	VenFlo.tag=null;
	VenFlo.typ=null;
	VenCont="";
	if(num<=2){
		setCookie("VenCont" + num, "");
	}
}
//---------------

function CierraMin(num){
	var MinFlo;
	var VenFlo;
	var VenCont;
	VenCont=document.getElementById("VenCont" + num);
	MinFlo=document.getElementById('MinFlo' + num);
	VenFlo=document.getElementById('VenFlo' + num);
	MinFlo.style['display']='none';
	VenFlo.style['display']='none';
	VenFlo.style['visibility']='visible';
	VenFlo.style['top']= 70 + (num * 20) + 'px';
	VenFlo.style['left']= 70 + (num * 20) + 'px';
	VenFlo.tag=null;
	VenFlo.typ=null;
	VenCont="";
	setCookie('VenFlo' + num, 'cerrada');
	if(num<=2){
		setCookie("VenCont" + num, "");
	}
}
//abrir modulos


/**
 *
 * @access public
 * @return void
 **/
function WinNamOpen(IdCont,tipo,minimizado,x,y,z,num,usecookie){
	var VenFlo;
	var VenCont;
	var minicont;
	var ajax = nuevoAjax();
	minicont = document.getElementById("MinFloCont" + num);
	if(usecookie==null)usecookie=false;
	VenFlo=document.getElementById("VenFlo" + num);
	VenCont=document.getElementById("VenCont" + num);
	VenCont.innerHTML = '<div class="cargando_ventana">Cargando<font style="text-decoration:blink">...</font></div>';
	minicont.innerHTML = 'Cargando<font style="text-decoration:blink">...</font>';
	VenFlo.tag=IdCont;
	VenFlo.typ=tipo;
	if(x!=null && y!=null){
		VenFlo.style.top = y;
		VenFlo.style.left = x;
	}
	if(z!=null){
		VenFlo.style.zIndex = z;
	}
	if(!usecookie){
		ajax.open("POST", "librerias/php-ajax/php-ajax-" + tipo + ".php", true);// revizar la asincronia de ajax
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send('id_contenido=' + IdCont + '&tipo=' + tipo);
		ajax.onreadystatechange = function(){
			if(ajax.readyState==4){
				VenCont.innerHTML = ajax.responseText;
				setCookie("VenFlo" + num, IdCont + "/" + tipo + "/" + minimizado + "/" + VenFlo.style['left'] + "/" + VenFlo.style['top'] + "/" + VenFlo.style.zIndex);
				if(VenCont.innerText == null){
					minicont.innerHTML = '<small style="text-transform:capitalize; !important">[' + tipo + ']</small> ' + VenCont.textContent.substr(0,10) + "...";
				}else{
					minicont.innerHTML = '<small style="text-transform:capitalize; !important">[' + tipo + ']</small> ' + VenCont.innerText.substr(0,10) + "...";
				}
				if(num<=2){
					setCookie("VenCont" + num,ajax.responseText);
				}
			}
		}

	}else{
		VenCont.innerHTML = getCookie("VenCont" + num);
		if(VenCont.innerText == null){
			minicont.innerHTML = '<small style="text-transform:capitalize; !important">[' + tipo + ']</small> ' + VenCont.textContent.substr(0,10) + "...";
		}else{
			minicont.innerHTML = '<small style="text-transform:capitalize; !important">[' + tipo + ']</small> ' + VenCont.innerText.substr(0,10) + "...";
		}
	}


	if(minimizado == true){
		VenFlo.style.visibility = "hidden";
		VenFlo.style["display"]="inline";
		Minimiza(num,usecookie);
	}else{
		VenFlo.style["display"]="inline";
	}

}
/**
 *
 * @access public
 * @return void
 **/
function buscaWin(IdCont,tipo,minimizado,x,y,z){
	var obj;
	var obj2;
	var declarado=false;
	if(minimizado==null)minimizado=false;
	for(i=1;i<7;i++){
		obj = document.getElementById("VenFlo" + i);
		if(obj.style.display != "inline"){
			for(e=1;e<7;e++){
				obj2 = document.getElementById("VenFlo" + e);
				if(obj2.tag == IdCont && obj2.typ == tipo){
					declarado=true;
					break;
				}
			}
			if(!declarado){
				WinNamOpen(IdCont,tipo,minimizado,x,y,z,i);
				return;
			}
		}
	}
}
String.prototype.NumPx = function(){
	return Number(this.substr(0,this.length - 2));
}
function getCookie(name){
	var cname = name + "=";
	var dc = document.cookie;
	if(dc.length > 0){
		begin = dc.indexOf(cname);
		if(begin != -1){
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if(end == -1){
				end = dc.length;
			}
			return unescape(dc.substring(begin, end));
		}
	}
	return null;
}
function setCookie(name, value, expires,camino){
	var temp='';
	if(camino==null)camino='';
	temp = name + "=" + escape(value) + "; path=/" + camino;
	if(expires!=null){
		temp += "; expires=" + expires.toGMTString();
	}
	document.cookie=temp;
}

function Minimiza(num){
	var matriz = Array();
	var valor = '';
	var VenFlo;
	var mini;
	var minicont;
	var VenCont;
	VenFlo = document.getElementById("VenFlo" + num);
	mini = document.getElementById("MinFlo" + num);
	minicont = document.getElementById("MinFloCont" + num);
	VenCont=document.getElementById("VenCont" + num);
	mini.style['display']='inline';
	VenFlo.style.visibility = 'hidden';
	valor = getCookie("VenFlo" + num);
	matriz = valor.split("/");
	matriz[2] = '1';
	valor = Implode(matriz,"/");
	setCookie("VenFlo" + num,valor);
}

function Maximiza(num){
	var matriz = Array();
	var valor = '';
	var ventana;
	var objeto;
	objeto=document.getElementById('MinFlo' + num);
	ventana=document.getElementById('VenFlo' + num);
	ventana.style.visibility ='visible';
	objeto.style['display']='none';
	valor = getCookie("VenFlo" + num);
	matriz = valor.split("/");
	matriz[2] = '0';
	valor = Implode(matriz,"/");
	setCookie("VenFlo" + num,valor);
}


function Implode(arr, separator) {
	fixedImplode = "";
	separator = new String(separator);
	if(separator == null){
		separator = " ";
	}
	for(x = 0; x < arr.length; x++){
		fixedImplode += (separator + String(arr[x]));
	}
	fixedImplode = fixedImplode.substring(separator.length,fixedImplode.length);
	return fixedImplode;
}
function recuerda(){
	var valor;
	var matriz;
	for(i=1;i<7;i++){
		valor = getCookie("VenFlo" + i);
		if(valor!=null && valor != 'cerrada'){
			matriz = valor.split("/");
			if(i == 1 || i == 2){
				WinNamOpen(matriz[0],matriz[1],matriz[2],matriz[3],matriz[4],matriz[5],i,true);
			}else{
				WinNamOpen(matriz[0],matriz[1],matriz[2],matriz[3],matriz[4],matriz[5],i);
			}
		}
		}
}

	var textoin="";
function jsvotar(){
	var piscina = document.getElementById('piscina');
	var opcion_id_value;
	var ajax = nuevoAjax();
	if(document.encuesta != null){
		opcion_id_value = getRadioValue(document.encuesta.opcion_id);
		piscina.innerHTML = textoin;
		ajax.open("GET", "librerias/php-ajax/votar.lib.php?opcion_id=" + opcion_id_value);
	}else{
		ajax.open("GET", "librerias/php-ajax/votar.lib.php");
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(null);
	ajax.onreadystatechange = function(){
		if(ajax.readyState==1){
			piscina.innerHTML = "Cargando...";
		}
		if(ajax.readyState==4){
			piscina.innerHTML = ajax.responseText;
		}
	}

}

function getRadioValue(objeto){
	for(i=0;i<objeto.length;i++){
		if(objeto.item(i).checked){
		return objeto.item(i).value;
		}
	}
}
/**
 *
 * @access public
 * @return void
 **/
function ampliar(imagen){
	var VenIMG;
	var superVen;
	var VenFoto;
	var availesp;
	var topesp;
	var leftesp;
	var arrsize = Array();
	var locx;
	var locy;
	var loader;
	if(imagen.complete == false)return;
	VenIMG = document.getElementById("VenIMG");
	superVen = document.getElementById("superVen");
	VenFoto = document.getElementById("VenFoto");
	loader = document.getElementById("loader");
	//
	VenFoto.style.visibility = "hidden";
	superVen.style.visibility = "hidden";
	VenFoto.style.display = "inline";
	superVen.style.display = "inline";
	//VenIMG.style.background = "url('" + imagen.src + "')";
	arrsize = imagen.alt.split("|");
	VenIMG.style.width = Number(arrsize[0]) + "px";
	VenIMG.style.height = Number(arrsize[1]) + "px";
	VenFoto.style.width = (VenIMG.style.width.NumPx() + 8) + "px";
	VenFoto.style.height = (47 + VenIMG.style.height.NumPx()) + "px";

	if(window.innerHeight == null){
		window.innerHeight = superVen.clientHeight;
	}
	if(window.innerWidth == null){
		window.innerWidth = superVen.clientWidth;
	}

	if(window.innerHeight > VenFoto.style.height.NumPx()){
		availesp = window.innerHeight - VenFoto.style.height.NumPx();
		topesp = availesp / 2;
	}else{
		VenIMG.style.height = (window.innerHeight - 47) + "px";
		VenFoto.style.height = window.innerHeight + "px";
		topesp = 0;
	}

	if(window.innerWidth > VenFoto.style.width.NumPx()){
		availesp = screen.availWidth - VenFoto.style.width.NumPx();
		leftesp = availesp / 2;
	}else{
		VenIMG.style.width = (window.innerWidth - 8) + "px";
		VenFoto.style.width = window.innerWidth + "px";
		leftesp = 0;
	}
	/*
	locx = VenFoto.style.width.NumPx() * -1;
	locy = VenFoto.style.height.NumPx() * -1;
	VenFoto.style.top = locy + "px";
	VenFoto.style.left = locx + "px";
	*/
	availesp = VenIMG.style.height.NumPx() - loader.style.height.NumPx();
	loader.style.top = (availesp / 2) + "px";
	VenFoto.style.top = topesp + "px";
	VenFoto.style.left = leftesp + "px";
	superVen.style.filter = "alpha(opacity=30)"
	VenFoto.style.visibility = "visible";
	superVen.style.visibility = "visible";
	//VenIMG.style.background = "url('" + imagen.src + "')";
	imgin = VenIMG.innerHTML;
	setTimeout("document.getElementById('" + VenIMG.id + "').style.background = 'url(\"" + imagen.src +"\")';document.getElementById('" + VenIMG.id + "').innerHTML = '';", 2000);
	//inter = setInterval("arrastra(" + leftesp + ",'" + imagen.src + "')", 50);
}

/**
 *
 * @access public
 * @return void
 **/
 var imgin;
function cierraIMG(){
	var superVen;
	var VenIMG;
	var VenFoto;
	superVen = document.getElementById("superVen");
	VenFoto = document.getElementById("VenFoto");
	VenIMG = document.getElementById("VenIMG");
	//
	superVen.style.display = "none";
	VenFoto.style.display = "none";
	VenIMG.style.background = "none";
	VenIMG.innerHTML = imgin;
}