function toggle(div_id) {
	var el = parent.document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar, myPageY) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = parent.window.innerHeight;
	} else {
		viewportheight = parent.document.documentElement.clientHeight;
	}
	if ((viewportheight > parent.document.body.parentNode.scrollHeight) && (viewportheight > parent.document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (parent.document.body.parentNode.clientHeight > parent.document.body.parentNode.scrollHeight) {
			blanket_height = parent.document.body.parentNode.clientHeight;
		} else {
			blanket_height = parent.document.body.parentNode.scrollHeight;
		}
	}
	var blanket = parent.document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = parent.document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-142;
	//150 is half popup's height
	popUpDiv_top_pos = myPageY + 142;
	popUpDiv.style.top = popUpDiv_top_pos + 'px';
}

function window_position(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = parent.window.innerHeight;
	} else {
		viewportwidth = parent.document.documentElement.clientHeight;
	}
	if ((viewportwidth > parent.document.body.parentNode.scrollWidth) && (viewportwidth > parent.document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (parent.document.body.parentNode.clientWidth > parent.document.body.parentNode.scrollWidth) {
			window_width = parent.document.body.parentNode.clientWidth;
		} else {
			window_width = parent.document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = parent.document.getElementById(popUpDivVar);
	window_width=window_width/2-200;
	//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}

function popup(windowname, myPageY) {
	blanket_size(windowname, myPageY);
	window_position(windowname);
	toggle('blanket');
	toggle(windowname);	
	setTimeout("setCoords(0,myPageY)",1);
	if(parent.document.body.style.overflow == "hidden"){
		parent.document.body.style.overflow = "visible";
	} else {
		parent.document.body.style.overflow = "hidden";
	}
	
}


function NuevoAjax(){
    var xmlhttp=false;
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }

    if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function ajaxReportar(url,destination){
	var aleatorio=Math.random();
    ajaxreportar=NuevoAjax(); 
//    ajaxreportar.open("GET", url + "&rmd="+aleatorio,true); 
    ajaxreportar.open("GET", url,true); 
    ajaxreportar.onreadystatechange=function(){
        if(ajaxreportar.readyState==1){
            //Sucede cuando se esta cargando la pagina
            parent.document.getElementById(destination).innerHTML = "<img src='csspopup/images/ajax-loader.gif'  class='tloader' />";
        }else if(ajaxreportar.readyState==4){
            //Sucede cuando la pagina se cargó
            if(ajaxreportar.status==200){
                //Todo OK
                parent.document.getElementById(destination).innerHTML = ajaxreportar.responseText;
                //agregar_accion();

            }else if(ajaxreportar.status==404){
                //La pagina no existe
                parent.document.getElementById(destination).innerHTML = "La página no existe";
            }else{
                //Mostramos el posible error
                parent.document.getElementById(destination).innerHTML = "Error:".ajaxreportar.status; 
            }
        }
    }
    ajaxreportar.send(null);
}

function sendReporte(str){
	if(document.report_form.remr.value == ""){
		alert("ERROR: Su mensaje es requerido.");
	} else {
		text_str = document.report_form.remr.value;
		text_length = text_str.length;
//		alert(text_str);
		send_string = str + text_str;
//		alert(send_string);
//		ajaxReportar('sendreport_email.php?cid=' + document.report_form.cid.value + '&amp;csec=' + document.report_form.csec.value + '&amp;remr=' + text_str,'reportar_box_content_div');
		if(text_length < 25){
			alert("ERROR: Su mensaje es muy corto.");
		} else {
			ajaxReportar(send_string,'reportar_box_content_div');
		}
	}
}

function openModalBox(){
	myPageY = getCoords();
	popup('popUpDiv', myPageY);
	//setTimeout("setCoords(myPageX,myPageY)",1);
}

function setCoords(x, y){
	parent.window.scrollTo(x, y);
}

function getCoords(){
	if (document.all){
		myPageX = parent.document.documentElement.scrollLeft;
		myPageY = parent.document.documentElement.scrollTop;
	}else{
		myPageX = parent.window.pageXOffset;
		myPageY = parent.window.pageYOffset;
	}
	return myPageY
}