/*
.........................
::   Javascript a medida.  ::
:: www.httpcomunicacio.com ::
.........................
*/

/*
.........................
:: Tab Login ::
.........................
*/

function openTab() {
	theTab=document.getElementById('scrollTab');
	theTab.style.display='block';
	document.getElementById('tabStrip').style.display="block";
	startT();
	scrollTheTab('168', '90');
	
}

function closeTab() {
	theTab=document.getElementById('scrollTab');
	if(theTab.style.display=='block'){
		scrollTheTab('168', '39');
		document.getElementById('tabForm').style.display="none";
		/*document.getElementById('scrollTab').style.display='none';*/
	}
}

/*
.........................
:: formThing ::
.........................
*/

function formError() {
	document.getElementById('youBad').style.display='block';
}

function seeForm(yeah, right) {
	document.getElementById('youBad').style.display='none';
	document.getElementById(yeah).style.display='none';
	document.getElementById(right).style.display='block';
}

function formColor(yepa) {
	if(yepa.value=='') {
		yepa.style.background="#ffd";
	}else{
		yepa.style.background="#fff";
	}
}

function formBack(yepa) {
	yepa.style.borderTop="1px solid #aaa";
	yepa.style.borderRight="1px solid #ddd";
	yepa.style.borderBottom="1px solid #ddd";
	yepa.style.borderLeft="1px solid #aaa";
}

function checkBack(yepa) {
	yepa.style.border="0";
}


/*
.........................
:: Map ::
.........................
*/

function map(agencia) {
	clearMap();
	document.getElementById(agencia).style.display="block";
}

function clearMap() {
	for (n=1; n<document.getElementById("selEsp").length+document.getElementById("selPort").length+2; n++) {
		document.getElementById('m'+n).style.display="none";
	}
}

function switchCombo(x) {
	if(x=="p") {
		document.getElementById("selPort").style.display="inline";
		document.getElementById("iconPort").src="img/mportugalIcon.png";
		document.getElementById("selEsp").style.display="none";
		document.getElementById("iconEsp").src="img/mspainIcoff.png";
		map(document.getElementById('selPort').value);
	}else{
		document.getElementById("selPort").style.display="none";
		document.getElementById("iconPort").src="img/mportugalIcoff.png";
		document.getElementById("selEsp").style.display="inline";
		document.getElementById("iconEsp").src="img/mspainIcon.png";
		map(document.getElementById('selEsp').value);
	}
}

function anotherOne(x) {
	if(document.getElementById("selPort").style.display=="inline") {
		docID=document.getElementById("selPort");
	}else{
		docID=document.getElementById("selEsp");
	}
	for (n=0; n<docID.length; n++) {
		if(docID[n].value==x) {
			docID.selectedIndex=n;
			map(x);
		}
	}
}

/*
.........................
:: The Spriter ::
.........................
*/

var cronos=0;
var theScrollDiv=0;
var thisXBit=0;
var thisYBit=0;
var thisWBit=0;
var thisHBit=0;

function scrollTheSprite(thaX, thaY, text) {
	clearTimeout(cronos);
	thisXBit=thaX;
	thisYBit=thaY;
	theScrollDiv=document.getElementById('spriter');
	document.getElementById('spriteText').innerHTML=text;
	if (parseInt(theScrollDiv.style.top)!=thisYBit || parseInt(theScrollDiv.style.left)!=thisXBit){
		hereDoWeGo();
	}
}

function scrollTheText(thaX, thaY) {
	clearTimeout(cronos);
	thisXBit=thaX;
	thisYBit=thaY;
	theScrollDiv=document.getElementById('scrollPaq');
	if (parseInt(theScrollDiv.style.top)!=thisYBit || parseInt(theScrollDiv.style.left)!=thisXBit){
		hereDoWeGo();
	}
}

function scrollTheTab(thaX, thaY) {
	clearTimeout(cronos);
	thisXBit=thaX;
	thisYBit=thaY;
	theScrollDiv=document.getElementById('scrollTab');
	if (parseInt(theScrollDiv.style.height)!=thisYBit || parseInt(theScrollDiv.style.width)!=thisXBit){
		tabDoWeGo();
	}
}

function tabDoWeGo() {
	if (parseInt(theScrollDiv.style.height)!=thisYBit){
		theScrollDiv.style.height=Math.round(parseInt(theScrollDiv.style.height)+((thisYBit-parseInt(theScrollDiv.style.height))/10))+"px";
		if (parseInt(theScrollDiv.style.height)>thisYBit) {
			theScrollDiv.style.height=parseInt(theScrollDiv.style.height)-1+"px";
		}else{
			theScrollDiv.style.height=parseInt(theScrollDiv.style.height)+1+"px";
		}
	}

	if (parseInt(theScrollDiv.style.width)!=thisXBit){
		theScrollDiv.style.width=Math.round(parseInt(theScrollDiv.style.width)+((thisXBit-parseInt(theScrollDiv.style.width))/10))+"px";
		if (parseInt(theScrollDiv.style.width)>thisXBit) {
			theScrollDiv.style.width=parseInt(theScrollDiv.style.width)-1+"px";
		}else{
			theScrollDiv.style.width=parseInt(theScrollDiv.style.width)+1+"px";
		}
	}
	
	if (parseInt(theScrollDiv.style.width)!=thisXBit || parseInt(theScrollDiv.style.height)!=thisYBit){
		cronos=setTimeout('tabDoWeGo()',5);
	}else{
		if (parseInt(theScrollDiv.style.height)<40) {
			theScrollDiv.style.display="none";
			document.getElementById('tabStrip').style.display="none";
		}else{
			document.getElementById('tabForm').style.display="block";
		}
	}
}
	
/*
function scrollTheHistory(thaX, thaY) {
	clearTimeout(cronos);
	thisXBit=thaX;
	thisYBit=thaY;
	theScrollDiv=document.getElementById('cronos');
	if (parseInt(theScrollDiv.style.top)!=thisYBit || parseInt(theScrollDiv.style.left)!=thisXBit){
		hereDoWeGo();
	}
}
*/

function hereDoWeGo() {
	if (parseInt(theScrollDiv.style.top)!=thisYBit){
		theScrollDiv.style.top=Math.round(parseInt(theScrollDiv.style.top)+((thisYBit-parseInt(theScrollDiv.style.top))/10))+"px";
		if (parseInt(theScrollDiv.style.top)>thisYBit) {
			theScrollDiv.style.top=parseInt(theScrollDiv.style.top)-1+"px";
		}else{
			theScrollDiv.style.top=parseInt(theScrollDiv.style.top)+1+"px";
		}
	}

	if (parseInt(theScrollDiv.style.left)!=thisXBit){
		theScrollDiv.style.left=Math.round(parseInt(theScrollDiv.style.left)+((thisXBit-parseInt(theScrollDiv.style.left))/10))+"px";
		if (parseInt(theScrollDiv.style.left)>thisXBit) {
			theScrollDiv.style.left=parseInt(theScrollDiv.style.left)-1+"px";
		}else{
			theScrollDiv.style.left=parseInt(theScrollDiv.style.left)+1+"px";
		}
	}

	if (parseInt(theScrollDiv.style.left)!=thisXBit || parseInt(theScrollDiv.style.top)!=thisYBit){
		cronos=setTimeout('hereDoWeGo()',5);
	}
}




function scrollTheSquare(thaX, thaY, thaW, thaH) {
	clearTimeout(cronos);
	thisXBit=thaX;
	thisYBit=thaY;
	theScrollDiv=document.getElementById('cronos');
	thisWBit=thaW;
	thisHBit=thaH;
	theScrollDov=document.getElementById('historySquare');
	if (parseInt(theScrollDiv.style.top)!=thisYBit || parseInt(theScrollDiv.style.left)!=thisXBit || parseInt(theScrollDov.style.height)!=thisHBit || parseInt(theScrollDov.style.width)!=thisWBit){
		squareDoWeGo();
	}
}

function scrollTheSkuare(thaX, thaY, thaW, thaH) {
	clearTimeout(cronos);
	thisXBit=thaX;
	thisYBit=thaY;
	theScrollDiv=document.getElementById('kronos');
	thisWBit=thaW;
	thisHBit=thaH;
	theScrollDov=document.getElementById('historySquare');
	if (parseInt(theScrollDiv.style.top)!=thisYBit || parseInt(theScrollDiv.style.left)!=thisXBit || parseInt(theScrollDov.style.height)!=thisHBit || parseInt(theScrollDov.style.width)!=thisWBit){
		squareDoWeGo();
	}
}

function squareDoWeGo() {
		if (parseInt(theScrollDiv.style.top)!=thisYBit){
		theScrollDiv.style.top=Math.round(parseInt(theScrollDiv.style.top)+((thisYBit-parseInt(theScrollDiv.style.top))/10))+"px";
		if (parseInt(theScrollDiv.style.top)>thisYBit) {
			theScrollDiv.style.top=parseInt(theScrollDiv.style.top)-1+"px";
		}else{
			theScrollDiv.style.top=parseInt(theScrollDiv.style.top)+1+"px";
		}
	}

	if (parseInt(theScrollDiv.style.left)!=thisXBit){
		theScrollDiv.style.left=Math.round(parseInt(theScrollDiv.style.left)+((thisXBit-parseInt(theScrollDiv.style.left))/10))+"px";
		if (parseInt(theScrollDiv.style.left)>thisXBit) {
			theScrollDiv.style.left=parseInt(theScrollDiv.style.left)-1+"px";
		}else{
			theScrollDiv.style.left=parseInt(theScrollDiv.style.left)+1+"px";
		}
	}
	
	if (parseInt(theScrollDov.style.height)!=thisHBit){
		theScrollDov.style.height=Math.round(parseInt(theScrollDov.style.height)+((thisHBit-parseInt(theScrollDov.style.height))/10))+"px";
		if (parseInt(theScrollDov.style.height)>thisHBit) {
			theScrollDov.style.height=parseInt(theScrollDov.style.height)-1+"px";
		}else{
			theScrollDov.style.height=parseInt(theScrollDov.style.height)+1+"px";
		}
	}

	if (parseInt(theScrollDov.style.width)!=thisWBit){
		theScrollDov.style.width=Math.round(parseInt(theScrollDov.style.width)+((thisWBit-parseInt(theScrollDov.style.width))/10))+"px";
		if (parseInt(theScrollDov.style.width)>thisWBit) {
			theScrollDov.style.width=parseInt(theScrollDov.style.width)-1+"px";
		}else{
			theScrollDov.style.width=parseInt(theScrollDov.style.width)+1+"px";
		}
	}

	if (parseInt(theScrollDiv.style.left)!=thisXBit || parseInt(theScrollDiv.style.top)!=thisYBit || parseInt(theScrollDov.style.width)!=thisWBit || parseInt(theScrollDov.style.height)!=thisHBit){
		cronos=setTimeout('squareDoWeGo()',5);
	}
}

function doIt() {
	x=document.getElementById('spriter');
	x.style.top='0px';
	x.style.left='0px';
	document.getElementById('spriteControl01').style.display="none";
	document.getElementById('spriteControl02').style.display="none";
	document.getElementById('spriteControl03').style.display="none";
}

function switchControl(thisOne) {
	document.getElementById('spriteControl01').style.display="none";
	document.getElementById('spriteControl02').style.display="none";
	document.getElementById('spriteControl03').style.display="none";
	document.getElementById(thisOne).style.display="block";
}

function spriterMenu(thisOne) {
	document.getElementById('spriteSelector01').style.border="1px solid #fff";
	document.getElementById('spriteSelector02').style.border="1px solid #fff";
	document.getElementById('spriteSelector03').style.border="1px solid #fff";
	document.getElementById('spriteSelector'+thisOne).style.border="1px solid #013a6a";
}

function startSpriter() {
	document.getElementById('superLoader').style.display="none";
	document.getElementById('superContainer').style.visibility="visible";
}

function startHistory() {
	document.getElementById('superLoader').style.display="none";
	document.getElementById('superHistory').style.visibility="visible";
}

function start() {
	doIt();
	spriterMenu('01');
	switchControl('spriteControl01');
	scrollTheSprite('0', '0', 'El veh&iacute;culo de recogidas se dirige al almac&eacute;n del cliente.');
	startSpriter();
}

function startH() {
	startHistory();
	x=document.getElementById('cronos');
	x.style.top='0px';
	x.style.left='0px';
	x=document.getElementById('historySquare');
	x.style.width='476px';
	x.style.height='250px';
	document.getElementById('firstLink').focus();
}

function startE() {
	startHistory();
	x=document.getElementById('cronos');
	x.style.top='0px';
	x.style.left='0px';
	x=document.getElementById('historySquare');
	x.style.width='476px';
	x.style.height='370px';
	document.getElementById('firstLink').focus();
}

function startI() {
	startHistory();
	x=document.getElementById('kronos');
	x.style.top='0px';
	x.style.left='0px';
	x=document.getElementById('historySquare');
	x.style.width='476px';
	x.style.height='650px';
	document.getElementById('firstLink').focus();
}

function startS() {
	//startServices();
	x=document.getElementById('scrollPaq');
	x.style.top='-4px';
	x.style.left='0px';
}

function startT() {
	x=document.getElementById('scrollTab');
	x.style.width='168px';
	x.style.height='29px';
}




