// JavaScript Documentfunction finestraMax(){
function mida(w,h){	
	if(document.all){
		top.window.moveTo((screen.availwidth-w)/2,(screen.availheight-h)/2);
		top.window.resizeTo(w,h);
	}
}
function finestraMax() {
    var offset = (navigator.userAgent.indexOf("Mac") != -1 || 
                  navigator.userAgent.indexOf("Gecko") != -1 || 
                  navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;
    window.moveTo(-offset, -offset);
    window.resizeTo(screen.availWidth + (2 * offset), 
                   screen.availHeight + (2 * offset));
}

function obreFinestra(id_foto,url,nom,w,h,opcions) {
    var left = (parseInt((screen.availWidth/2) - (w/2)))-15;
    var top = parseInt((screen.availHeight/2) - (h/2) - 35);
    var caracteristiques = "width=" + w + ",height=" + ( h  )  + ",left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top +  opcions;
	url = "foto_ampli.php?id_foto=" + id_foto + "&alt=" + h + "&ample=" + w;
    myWindow = window.open(url, nom, caracteristiques);
}

function obraFinestra(url,nom,w,h,opcions) {
    var left = (parseInt((screen.availWidth/2) - (w/2)))-15;
    var top = parseInt((screen.availHeight/2) - (h/2) - 35);
    var caracteristiques = "scrollbars=yes, width=" + w + ",height=" + ( h + 20 )  + ",left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top +  opcions;
	//url = "foto_ampli.php?id_foto=" + id_foto + "&alt=" + h;
    myWindow = window.open(url, nom, caracteristiques);
}


function miraFoto(msg){
	document.getElementById('thum').src=msg; 
	//document.f1.borraImagen.value=''
}

function control(){
	if(document.f1.titol_serie.value == ""){
		alert("No se puede crear una nueva serie sin al menos un título!");
		return false;
	}
	if(document.f1.fotoNovaSerie.value == ""){
		alert("Sin foto no hay nueva serie!");
		return false;
	}
	if(document.f1.fotoNova.value == ""){
		alert("Sin foto no hay nueva serie!");
		return false;
	}
}
function winopen(url,nom,w,h,barra,resiz,tool,men,stat){
	l=(screen.availwidth-w)/2;t=(screen.availheight-h)/2
	features="width=" + w + " height=" + h + " left=" + l + " top=" + t + " scrollbars=" + barra + " resizable=" + resiz + " toolbar=" + tool + " menubar=" + men + " status=" + stat;
	newwin=window.open(url,nom,features)
}

//*******************************************
// VALIDA FORMULARI
//*******************************************
function IsNumeric(sText){
	
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}

function valida(frm){
	if(!frm.nom_producte.value)
		ferror='Introduzca el nombre del producto!';
		
	else if(!frm.concepto_producte.value)
		ferror='Introduzca un concepto para el producto!';
		
	else if(!frm.composicion_producte.value)
		ferror='Introduzca la composición del producto!';
		
	else if(!frm.utilizacion_producte.value)
		ferror='Introduzca la utilización del producto!';
		
	else if(!frm.presentacion_producte.value)
		ferror='Introduzca la presentación del producto!';
		
	else if(!frm.preu_producte.value)
		ferror='Introduzca el pecio del producto!';
		
	else if(!IsNumeric(frm.preu_producte.value))
		ferror='El precio del producto es incorrecto';
		
	else if(!IsNumeric(frm.stock_producte.value))
		ferror='Introduzca un stock válido.';
		
	else if(frm.select_familia.value=='')
		ferror='Seleccione una familia para el producto';
		
	else if(frm.select_marca.value=='')
		ferror='Seleccione una marca para el producto';
	
	if (ferror) {
		alert(ferror)
		ferror=''
		return false;
	//}else{
		//return true
	}

}

function borra_producte (url, nom_article) {
 segur = confirm("Seguro que quiere borrar el producto\r \'" + nom_article + "\' ?");
 if (segur == true) {
  //url = "index.php?treure_article=true&article_carro=" + element_carro;
  document.location = url;
 }
}


//****************************************************
//******************************* PRELOAD IMATGES
var i; 
var imatges = new Array("img/boto_hover.gif","img/carro_hover.gif","img/icon_borra_hover.gif","img/icon_edit_hover.gif","img/menuprincipal_hover.gif","img/fons_foto.gif","img/fons_foto.gif"); 
var llista_imatges = new Array(); 

function carregaImatges(){
	for(i in imatges){ 
	llista_imatges[i] = new Image(); 
	llista_imatges[i].src = imatges[i]; 
	} 
}

// ****************************************************
// email ocult 
// ****************************************************
var edress = 'tom_at_safarisandexpeditions_dot_com';
function get_edress(){
var re= /_at_/gi;
edress = edress.replace(re,'@');
var re= /_dot_/gi;
edress = edress.replace(re,'.');
var the_link="mai" + "lto" +":"+edress ;
window.location=the_link;
}
