/***************
**** Popups ****
****************/

function changeSheets(whichSheet){
  whichSheet=whichSheet-1;
  if(document.styleSheets){
    var c = document.styleSheets.length;
//    if (doAlerts) alert('Change to Style '+(whichSheet+1));
    for(var i=0;i<c;i++){
      if(i!=whichSheet){
        document.styleSheets[i].disabled=true;
      }else{
        document.styleSheets[i].disabled=false;
      }
    }
  }
}

function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
    } else {
	return false;
    }
} 

function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	//return true;
    } else {
	//return false;
    }
} 

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	return false;
    }
}

function showPopup (targetObjectId, eventObj) {
    if(eventObj) {
	hideCurrentPopup();
	eventObj.cancelBubble = true;
//	var newXCoordinate = document.body.clientWidth / 2 - 210;
//	var newYCoordinate = document.body.clientHeight / 2 - 10;
//	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
		//changeSheets(1);
	    window.currentlyVisiblePopup = targetObjectId;
	 //   return true;
	} else {
	   // return false;
	}
    } else {
	//return false;
    }
}

function hideCurrentPopup() {
    if(window.currentlyVisiblePopup) {
//	changeSheets(2);
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
}


window.onload = initializeHacks;

//document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

var tiempo_refresh=2;
var displaycountdown="no";
var starttime;
var nowtime;
var reloadseconds=0;
var secondssinceloaded=0;

function gracias_registro()  { 
	nowtime= new Date();
	nowtime=nowtime.getTime();
	secondssinceloaded=(nowtime-starttime)/1000;
	reloadseconds=Math.round(tiempo_refresh-secondssinceloaded);
	if (tiempo_refresh>=secondssinceloaded){ 
		var timer=setTimeout("gracias_registro()",1000);
	} 
	else { 
		clearTimeout(timer);
		changeObjectVisibility('registro_ok', 'visible');
		changeObjectVisibility('registro', 'hidden');
		window.open('#top','_self');	
	} 
} 

function empezar_timer() { 
	starttime = null;
	starttime=new Date();
	starttime=starttime.getTime();
	gracias_registro();
} 

function registrado_ok(){
	empezar_timer();
	ancho_pantalla = screen.width;
	alto_pantalla = screen.height;
	resize_ancho = ancho_pantalla - 20;
	window.resizeTo("800","500");
	mover_ancho = ancho_pantalla/2 - 400;
	mover_alto = alto_pantalla/2 - 240;
	window.moveTo(mover_ancho,mover_alto);
}

function registrado_retry(){
	changeObjectVisibility('registro_ok', 'hidden');
	changeObjectVisibility('registro', 'visible');
}
function fallo_popup(){
	changeObjectVisibility('registro', 'hidden');
	changeObjectVisibility('fallo_popup', 'visible');
}
