

//<![CDATA[

<!--

function BrowserCheck() {
	var justor = navigator.appName
	this.mac = (navigator.appVersion.indexOf('Mac') != -1)
	if (justor=="Netscape") this.justor = 'ns'
	else if (justor=="Microsoft Internet Explorer") this.justor = 'ie'
	else this.justor = justor
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.justor=="ns" && this.v>=5)
	this.ns5 = (this.justor=="ns" && this.v==5)
	this.ns6 = (this.justor=="ns" && this.v==5)
	this.ie = (this.justor=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	if (this.mac) this.ie = this.ie5
	this.ie5mac = (this.ie5 && this.mac);
	this.min = (this.ns||this.ie)
}

is = new BrowserCheck();

if (is.min == false){
	PopIt('Parece que hay alguna dificultad con el navegador.');
	history.back();
}

function Card(ID){
	this.elm=document.getElementById(ID);
	this.name=ID;
	this.css=this.elm.style;
	this.elm.style.left = 0 +'px';
	this.elm.style.top = 0 +'px';
	this.HomeL = 0;
	this.HomeT = 0;
	this.tag=-1;
	this.index=-1;


}

function CardGetL(){return parseInt(this.css.left)}
Card.prototype.GetL=CardGetL;

function CardGetT(){return parseInt(this.css.top)}
Card.prototype.GetT=CardGetT;

function CardGetW(){return parseInt(this.elm.offsetWidth)}
Card.prototype.GetW=CardGetW;

function CardGetH(){return parseInt(this.elm.offsetHeight)}
Card.prototype.GetH=CardGetH;

function CardGetB(){return this.GetT()+this.GetH()}
Card.prototype.GetB=CardGetB;

function CardGetR(){return this.GetL()+this.GetW()}
Card.prototype.GetR=CardGetR;

function CardSetL(NewL){this.css.left = NewL+'px'}
Card.prototype.SetL=CardSetL;

function CardSetT(NewT){this.css.top = NewT+'px'}
Card.prototype.SetT=CardSetT;

function CardSetW(NewW){this.css.width = NewW+'px'}
Card.prototype.SetW=CardSetW;

function CardSetH(NewH){this.css.height = NewH+'px'}
Card.prototype.SetH=CardSetH;

function CardInside(X,Y){
	var Compro=false;
	if(X>=this.GetL()){if(X<=this.GetR()){if(Y>=this.GetT()){if(Y<=this.GetB()){Compro=true;}}}}
	return Compro;
}
Card.prototype.Inside=CardInside;

function CardSwapColours(){
	var hor25=this.css.backgroundColor;
	this.css.backgroundColor=this.css.color;
	this.css.color=hor25;
}
Card.prototype.SwapColours=CardSwapColours;

function CardHighlight(){
	this.css.backgroundColor='#FFFFFF';
	this.css.color='#990000';
}
Card.prototype.Highlight=CardHighlight;

function CardUnhighlight(){
	this.css.backgroundColor='#990000';
	this.css.color='#FFFFFF';
}
Card.prototype.Unhighlight=CardUnhighlight;

function CardOverlap(OtherCard){
	var datcra=(this.GetR()<(OtherCard.GetR()+10))? this.GetR(): (OtherCard.GetR()+10);
	var datcrb=(this.GetL()>OtherCard.GetL())? this.GetL(): OtherCard.GetL();
	var datcrc=datcra-datcrb;
	if (datcrc<1){return 0;}
	var datcrd=(this.GetB()<OtherCard.GetB())? this.GetB(): OtherCard.GetB();
	var datcre=(this.GetT()>OtherCard.GetT())? this.GetT(): OtherCard.GetT();
	var datcrf=datcrd-datcre;
	if (datcrf<1){return 0;}
	return (datcrc*datcrf);	
}
Card.prototype.Overlap=CardOverlap;

function CardDockToR(OtherCard){
	this.SetL(OtherCard.GetR() + 5);
	this.SetT(OtherCard.GetT());
}

Card.prototype.DockToR=CardDockToR;

function CardSetHome(){
	this.HomeL=this.GetL();
	this.HomeT=this.GetT();
}
Card.prototype.SetHome=CardSetHome;

function CardGoHome(){
	this.SetL(this.HomeL);
	this.SetT(this.HomeT);
}

Card.prototype.GoHome=CardGoHome;

var revitemb = '<table width="80%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FF9900"><tr><td align="center"><justor>¡Muy bien!</justor></td></tr></table>';
var revitemm = '<table width="60%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FF9900"><tr><td align="center"><justor>No es conforme, continúe.</justor></td></tr></table>';
var clveco = '<justor>Ha obtenido: </justor>';
var busrem = '[strCorrection]';
var solbb = 400; 
var eura = 200; 
var eurb = '#333333';
var eurc = '#333000';
var eurd = '#FFFFFF';
var eure = '#FFFFFF';
var eurf = 0;

var eurg = -1;
var eurh = 100;

function PageDim(){

	this.W = 600;
	this.H = 400;
	if (is.ns) this.W = window.innerWidth;
	if (is.ie) this.W = document.body.clientWidth;
	if (is.ns) this.H = window.innerHeight;
	if (is.ie) this.H = document.body.clientHeight;
}

var solba = null;
var solbb = 600;
var solbc = 200;
var solbd = 100;
var solbe = 500;
var solbf = 120;

FC = new Array();
DC = new Array();

function doDrag(e) {
	if (eurg == -1) {return};
	if (is.ie){var Ev = window.event}else{var Ev = e}
	var compa = Ev.clientX-window.lastX; 
	var compb = Ev.clientY-window.lastY; 
	var compc = DC[eurg].GetL()+compa; 
	var compd = DC[eurg].GetT()+compb; 
	DC[eurg].SetL(compc); 
	DC[eurg].SetT(compd);
	window.lastX = Ev.clientX; 
	window.lastY = Ev.clientY; 
	return false;
} 


function beginDrag(e, DragNum) { 
	eurg = DragNum;
	if (is.ie){
		var Ev = window.event;
		document.onmousemove=doDrag;
		document.onmouseup=endDrag;
	}
	else{
		var Ev = e;
		window.onmousemove=doDrag; 
		window.onmouseup=endDrag;
	} 
	DC[eurg].Highlight();
	eurh++;
	DC[eurg].css.zIndex = eurh;
	window.lastX=Ev.clientX; 
	window.lastY=Ev.clientY;
	return true;  
} 

function endDrag(e) { 
	if (eurg == -1) {return};
	DC[eurg].Unhighlight();
	if (is.ie){document.onmousemove=null}else{window.onmousemove=null;}
	onEndDrag();	
	eurg = -1;
	return true;
} 

function onEndDrag(){ 

	var econa = false;
	var econb = DroppedOnFixed(eurg);
	if (econb > -1){

		for (var plendd=0; plendd<DC.length; plendd++){
			if (DC[plendd].tag == econb+1){
				DC[plendd].GoHome();
				DC[plendd].tag = 0;
				D[plendd][2] = 0;
			}
		}

		DC[eurg].DockToR(FC[econb]);
		D[eurg][2] = F[econb][1];
		DC[eurg].tag = econb+1;
		econa = true;
	}

	if (econa == false){
		DC[eurg].GoHome();
		DC[eurg].tag = 0;
		D[eurg][2] = 0;
	}
} 

function DroppedOnFixed(DNum){
	var Compro = -1;
	var elecca = 0;
	var eleccb = 0;
	for (var plendd=0; plendd<FC.length; plendd++){
		eleccb = DC[DNum].Overlap(FC[plendd]);
		if (eleccb > elecca){
			elecca = eleccb;
			Compro = plendd;
		}
	}
	return Compro;
}

function StartUp(){
	solba = new PageDim();
	solbb = Math.floor((solba.W*4)/5);
	solbc = Math.floor((solbb*3)/10);
	solbd = Math.floor(solba.W/10);
	solbe = solba.W - (solbc + solbd);
	solbf = parseInt(document.getElementById('TitleDiv').offsetHeight) + 10;


	var felpgon = document.getElementById('FeedbackDiv');
	felpgon.style.top = solbf + 5 + 'px';
	felpgon.style.left = Math.floor((solba.W)/3) + 'px';
	felpgon.style.width = Math.floor(solba.W/3) + 'px';
	felpgon.style.display = 'none';
	D = Shuffle(D);
	var felgonb = solbf;
	var felgonc = 0;
	var felgond = 0;
	var felgone = 0;
	for (var plendd=0; plendd<F.length; plendd++){
		FC[plendd] = new Card('F' + plendd);
		FC[plendd].elm.innerHTML = F[plendd][0] + '<br clear="all" />'; 
		if (FC[plendd].GetW() > felgone){
			felgone = FC[plendd].GetW();
		}
	}

	if (felgone > solbc){felgone = solbc;}

	felgonb = solbf;

	solbc = Math.floor((solbb-felgone)/2) - 24;
	solbe = solbb + solbd - (solbc + 14);
	var felgonh = 0;
	var felgoni = 0;

	for (plendd=0; plendd<D.length; plendd++){
		DC[plendd] = new Card('D' + plendd);
		DC[plendd].elm.innerHTML = D[plendd][0] + '<br clear="all" />'; 
		if (DC[plendd].GetW() > solbc){DC[plendd].SetW(solbc);}
		DC[plendd].css.cursor = 'move';
		DC[plendd].css.backgroundColor = '#990000';
		DC[plendd].css.color = '#FFFFFF';
		felgonc = DC[plendd].GetH();
		if (felgonc > felgonh){felgonh = felgonc;}
		felgonc = DC[plendd].GetW();
		if (felgonc > felgoni){felgoni = felgonc;}
	}

	var felgonj = felgonh;
	if (is.ns||is.ie5mac){felgonj -= 12;}
	var felgonk = felgoni;
	if (is.ns||is.ie5mac){felgonk -= 12;}

	for (plendd=0; plendd<D.length; plendd++){
		DC[plendd].SetT(felgonb);
		DC[plendd].SetL(solbe);
		if (DC[plendd].GetH() < felgonh){
			DC[plendd].SetH(felgonj);
		}
		if (DC[plendd].GetW() < felgoni){
			DC[plendd].SetW(felgonk);
		}
		DC[plendd].SetHome();
		DC[plendd].tag = -1;
		felgonb = felgonb + DC[plendd].GetH() + 5;
	}

	felgonb = solbf;

	for (var plendd=0; plendd<F.length; plendd++){
		FC[plendd].SetW(felgone);
		if (FC[plendd].GetH() < felgonh){
			FC[plendd].SetH(felgonj);
		}
		FC[plendd].SetT(felgonb);
		FC[plendd].SetL(solbd);
		FC[plendd].SetHome();
		felgonc = FC[plendd].GetH();
		felgonb = felgonb + felgonc + 5;
	}


}



F = new Array();
F[0] = new Array()
F[0][0]='<justor>Moneda española de cobre con peso de un octavo de onza, mandada labrar por Felipe III y que, se acuñó hasta mediados del siglo XIX.</justor>';
F[0][1] = 1;
F[1] = new Array()
F[1][0]='<justor>Recluta de gente para el servicio militar.</justor>';
F[1][1] = 2;
F[2] = new Array()
F[2][0]='<justor>Cultivo único o predominante de una especie vegetal en determinada región.</justor>';
F[2][1] = 3;
F[3] = new Array()
F[3][0]='<justor>Privilegio, gracia o exención que se concede a alguien para que goce de ello, anejo a un cargo.</justor>';
F[3][1] = 4;


D = new Array();
D[0] = new Array()
D[0][0]='<justor>Ochavo</justor>';
D[0][1] = 1;
D[0][2] = 0;
D[1] = new Array()
D[1][0]='<justor>Leva</justor>';
D[1][1] = 2;
D[1][2] = 0;
D[2] = new Array()
D[2][0]='<justor>Monocultivo</justor>';
D[2][1] = 3;
D[2][2] = 0;
D[3] = new Array()
D[3][0]='<justor>Prerrogativa</justor>';
D[3][1] = 4;
D[3][2] = 0;


function Shuffle(InArray){
	eleccb = new Array();
	var felgonl = InArray.length;

	var felgonk = felgonl;

	for (var plendd=0; plendd<felgonl; plendd++){
		eleccb[plendd] = InArray[plendd];
	}

	for (plendd=0; plendd<felgonl; plendd++){
		Num = Math.floor(felgonk  *  Math.random());
		InArray[plendd] = eleccb[Num];

		for (var k=Num; k < felgonk; k++) {
			eleccb[k] = eleccb[k+1];
		}
		felgonk--;
	}
	return InArray;
}

function TimerStartUp(){
	setTimeout('StartUp()', 300);
}

function CheckAnswer(){
	var felgonm = 0;
	var felgonn = 0;
	var felgonp = '';
	var plendd, felgonk;
	for (plendd=0; plendd<D.length; plendd++){
		if ((D[plendd][2] == D[plendd][1])&&(D[plendd][2] > 0)){
			felgonm++;
		}
		else{
			DC[plendd].GoHome();
		}
	}

	felgonn = Math.floor((100*(felgonm-eurf))/F.length);

	if (felgonm == F.length) {
		felgonp = clveco + ' ' + felgonn + '%.<br />' + revitemb;
		WriteFeedback(felgonp);

	}
	else {
		felgonp = revitemm + '<br />' + clveco + ' ' + felgonn + '%.';
		WriteFeedback(felgonp);
		eurf++; 
	}
}

function WriteFeedback(Feedback){
	var plena = Feedback + '<br /><br />';
	plena += '<form><input type="button" value="De acuerdo"';
	plena += ' onclick="HideFeedback()"></form>';
	var plenb = document.getElementById('FeedbackDiv');
	plenb.innerHTML = plena;
	eurh++;
	plenb.style.zIndex = eurh;
	document.getElementById('FeedbackDiv').style.borderStyle = 'solid';
	plenb.style.display='';
}

function HideFeedback(){
	var plenb = document.getElementById('FeedbackDiv');
	plenb.innerHTML = '';
	plenb.style.display='none';
}



//-->

//]]>

