function wSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
	}
		return(myWidth);
}
		 
function rSize(){
var w = 0;
var modx = 0;
w = wSize();
if ( w > 960 ) {
modx = (w-960) / 2;
} else {
modx = 0;
}
return(modx);	 
}

function reSize(elem,val){
var w = 0;
var v = 0;
var rez = 0;
w = rSize();
v = val + w;
document.getElementById(elem).style.left = v+"px";
}


// functiile pt adunarea si scaderea atributelor la pagina create_captain.php

function mod_stats(elem,val){
var x = 0;
var puncte = 0;
x = document.getElementById(elem).value;
puncte = document.getElementById('remaining_points').value;

	
	if ( val == 'plus' ) {
		if ( puncte > 0 ) {

		if ( x < 15 ) { 
		  x++;	
		  puncte--;
		  document.getElementById(elem).value = x;
		  document.getElementById('remaining_points').value = puncte;
		}
		}
	} else if ( val == 'minus' ) {

		if ( x > 5 ) {
		  x--;
		  puncte++;
		  document.getElementById(elem).value = x;
		  document.getElementById('remaining_points').value = puncte;
		}
		}



}

// functia de resetare a variabileleor

function reset_stats(){
var x = 7;
var y = 30;

document.getElementById('strength').value = x;
document.getElementById('dexterity').value = x;
document.getElementById('intelligence').value = x;
document.getElementById('vitality').value = x;
document.getElementById('fight').value = x;
document.getElementById('cannonade').value = x;
document.getElementById('ship_handling').value = x;
document.getElementById('leadership').value = x;
document.getElementById('charisma').value = x;
document.getElementById('luck').value = x;
document.getElementById('remaining_points').value = y;




}
//functiile pt mouse-over

function swapimgrestore() { // pune imaginea lveche
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadimages() { // incarca imaginile
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length; for(i=0; i<arguments.length; i++)
    if (arguments[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=arguments[i];}}
}

function findobj(n, d) { // cauta obiectul
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findobj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapimage() { // schimba imaginea
  var i,j=0,x; document.MM_sr=new Array; for(i=0;i<(arguments.length-2);i+=3)
   if ((x=findobj(arguments[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=arguments[i+2];}
}


// Compas


function ascunde_compas(elem) {
document.getElementById(elem).style.visibility = "hidden";
setTimeout('arata_compas(\''+elem+'\')',600);
}


function arata_compas(elem) {
document.getElementById(elem).style.visibility = "visible";
}


// functia pt preload harta



function preload_map(x,y,dir_map) {
var j,vari;
x -= 5;
y -= 4;

//navigatie nord
for ( j = 1; j <= 9; j++ ) {
	    vari = dir_map + 'x' + x + 'y' + y + '.jpg';
		preloadimages(vari);
		y++;

}



x += 1;
y -= 10;
//navigatie vest
for ( j = 1; j <= 9; j++ ) {
	    vari = dir_map + 'x' + x + 'y' + y + '.jpg';

		preloadimages(vari);
		x++;

}

x -= 9;
y += 10;
//navigatie est
for ( j = 1; j <= 9; j++ ) {
	    vari = dir_map + 'x' + x + 'y' + y + '.jpg';
		preloadimages(vari);
		x++;

}

y -= 9;
//navigatie sud
for ( j = 1; j <= 9; j++ ) {
	    vari = dir_map + 'x' + x + 'y' + y + '.jpg';
		preloadimages(vari);
		y++;

}

}


// sfarsit functie pt preload harta

