<!-- ************************************************************************************************* -->
<!--  Gestión para mostrar una Imagen en el centro de la pantalla. Con posibilidad de cerrar el div    -->		
<!-- ************************************************************************************************* -->

function getScreenSize(){
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" 
	    && parseInt(navigator.appVersion)==3
	    && navigator.javaEnabled()
	   ) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}
	screenSize = new Array();
	screenSize[0] = screenW;
	screenSize[1] = screenH;
	return screenSize;
}

function showImg(nameImg,idImg,idField,imgW,imgH){			
	var current = getScreenSize();
	screenW = current[0];
	screenH = current[1];				
	document.getElementById('idLoading').style.visibility = 'visible';
	document.getElementById('idTextLoading').style.visibility = 'visible';
	document.getElementById('idTextLoading').style.left = screenW/2 + imgW;
	document.getElementById('idTextLoading').style.top = screenH/2 + imgH;
	var divimg = document.getElementById('idDivimgPop');
	divimg.innerHTML='<img style="margin:5px" id="imgPop" src="'+nameImg+'"/>';				
	var img = document.getElementById('imgPop');
	img.onload=function(){
		document.getElementById('idImagePopup').style.width= imgW+10+"px";		
		document.getElementById('idImagePopup').style.left = screenW/2 - imgW/2 + "px";
		document.getElementById('idImagePopup').style.top = screenH/2 - imgH + "px";
		document.getElementById('idTextLoading').style.visibility = 'hidden';
		document.getElementById('idLoading').style.visibility = 'hidden';
		document.getElementById('idImagePopup').style.visibility = 'visible';
	}
}

function closePopup(){
	document.getElementById('idImagePopup').style.visibility = 'hidden';
}

function delPage(page){
	if(confirm('Esto eliminará el registro. ¿Estás seguro?')){
		location.href=page;
	}
}

function editarItem(idItem){
	document.location.href = 'index.php?aptd=1&edit='+idItem;
}

function deleteColeccio(idItem){
	if(confirm('Esto eliminará el registro. ¿Estás seguro?')){
		document.location.href = 'delColeccions.php?edit='+idItem;
	}
}

function editarMayorista(id,pag){
	document.location.href = 'index.php?aptd=4&edit='+id+'&pag='+pag;
}

function editarUsuari(id,pag){
	document.location.href = 'index.php?aptd=9&edit='+id+'&pag='+pag;
}

function editarProducte(id,pag){
	document.location.href = 'index.php?aptd=3&edit='+id+'&pag='+pag;
}

function editarPuntVenda(id,pag){
	document.location.href = 'index.php?aptd=5&edit='+id+'&pag='+pag;
}

function editarCategoria(id,pag){
	document.location.href = 'index.php?aptd=2&edit='+id+"&pag="+pag;
}

function editarColor(id,pag){
	document.location.href = 'index.php?aptd=6&edit='+id+"&pag="+pag;
}

function deleteProducte(id){
	if(confirm('Esto eliminará el registro. ¿Estás seguro?')){
		document.location.href = 'delProductes.php?edit='+id;
	}
}

function deletePuntVenda(id){
	if(confirm('Esto eliminará el registro. ¿Estás seguro?')){
		document.location.href = 'delPuntVenda.php?edit='+id;
	}
}

function deleteCategoria(id){
	if(confirm('Esto eliminará el registro. ¿Estás seguro?')){
		document.location.href = 'delCategoria.php?edit='+id;
	}
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	//fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='_img/boto_blanc.png';	
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'cl_inp_amag';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			//this.relatedElement.value = this.value;
		}
	}
}
function resaltarRosa(aptd){	
	document.getElementById('aptd'+aptd).style.color = '#CC0066';
}

function treureRosa(aptd,menu){
	if(aptd!=menu){
		document.getElementById('aptd'+aptd).style.color = '#FFFFFF';
	}
}
function registrarCompte(lang){
	document.location.href = "index.php?aptd=11&lang="+lang;
}
function veureInformacioPersonal(lang){
	document.location.href = "index.php?aptd=12&seccio=0&lang="+lang;
}
function veureInformacioPersonalCompte(lang){
	document.location.href = "index.php?aptd=12&seccio=0&inf=0&lang="+lang;
}
function veureInformacioPersonalPassword(lang){
	document.location.href = "index.php?aptd=12&seccio=0&inf=1&lang="+lang;
}
function veureInformacioEnviament(lang){
	document.location.href = "index.php?aptd=12&seccio=1&lang="+lang;
}
function veureInformacioEnviamentFacturacio(lang){
	document.location.href = "index.php?aptd=12&seccio=1&inf=0&lang="+lang;
}
function veureInformacioEnviamentDades(lang){
	document.location.href = "index.php?aptd=12&seccio=1&inf=1&lang="+lang;
}
function veureInformacioComanda(lang){
	document.location.href = "index.php?aptd=12&seccio=2&lang="+lang;
}
function anarDadesPassword(lang){
	document.location.href = "index.php?aptd=12&seccio=0&inf=1&lang="+lang;
}
function desloggin(aptd,lang,edit){
	if(edit==0){
		document.location.href = "f_desloggin.php?aptd="+aptd+"&lang="+lang;
	}else{
		document.location.href = "f_desloggin.php?aptd="+aptd+"&lang="+lang+"&edit="+edit;
	}				
}
function tornarInformacioPersonal(lang){
	document.location.href = "index.php?aptd=12&lang="+lang;
}
function tornarInformacio(lang){
	document.location.href = "index.php?aptd=12&lang="+lang+"&seccio=1";
}
function paginarTenda(pag){
	document.formulari.pag.value = pag;
	document.formulari.submit();
}
function llistarProductesSegons(){
	document.formulari.pag.value = 0;
	document.formulari.submit();
}
function anarGaleriaFlash(idCol){
	document.location.href = "index.php?aptd=7&edit="+idCol;
}
function borraImgFlash(edit, idImage){
	if(confirm('Esto eliminará la imágen. ¿Estás seguro?')){
		document.location.href = "delImgFlash.php?edit="+edit+"&id_img="+idImage;
	}
}
function mostraDisplay(){
	if(document.getElementById('id_check').checked == true){
		document.getElementById('id_display').style.display = 'block';
	}else{
		document.getElementById('id_display').style.display = 'none';
	}

}
function borraImgFlashHome(idImage){
	if(confirm('Esto eliminará la imágen. ¿Estás seguro?')){
		document.location.href = "delImgFlashHome.php?edit="+idImage;
	}
}
function deleteMayorista(idUsuari){
	if(confirm('Esto eliminará el usuario mayorista. ¿Estás seguro?')){
		document.location.href = "delMayorista.php?edit="+idUsuari;
	}
}
function pasarAProfesional(idUsuari){
    if(confirm('Esto transformará el usuario en profesional. ¿Estás seguro?')){
		document.location.href = "f_pasarAProfesional.php?edit="+idUsuari;        
	}
}
function deleteUsuari(idUsuari){
	if(confirm('Esto eliminará el usuario. ¿Estás seguro?')){
		document.location.href = "delMayorista.php?edit="+idUsuari+"&user=1";
	}
}
function deleteColor(idColor){
	if(confirm('Esto eliminará el color. ¿Estás seguro?')){
		document.location.href = "delColor.php?edit="+idColor;
	}
}
function canviaFlashColeccio(lang){
	document.location.href = "index.php?lang="+lang+"&aptd=13&edit="+document.getElementById('id_coleccio').value;
}
function anarCarretCompra(lang){
	document.location.href = "index.php?lang="+lang+"&aptd=16";
}
function treureCompra(idPosArray,lang){
	document.location.href = "f_treureCompra.php?lang="+lang+"&edit="+idPosArray;
}
function actualitzaCantitat(lang,pos){
	document.location.href = "f_actualitzaCantitat.php?lang="+lang+"&edit="+pos;
}
function tornarCompra(lang){
	document.location.href = "index.php?lang="+lang+"&aptd=2";
}
function ferCompraPayPal(comprar,text){
	//alert("Compra desactivada");
	if(comprar == 1){
		document.f1.submit();
	}else{
		alert(text);	
	}
}
function ferCompraTPV(comprar,text){
	//alert("Compra desactivada");
	if(comprar == 1){
		document.f2.submit();
	}else{
		alert(text);	
	}
}
function ferCompraTransf(comprar,text){
	if(comprar == 1){
		document.f3.submit();
	}else{
		alert(text);	
	}
}
function ferCompraEsp(comprar,text){
	if(comprar == 1){
		document.f4.submit();
	}else{
		alert(text);	
	}
}
function clicaCheckInf(comprar){
	
	if(document.formulari.check_inf.checked==true){
		document.getElementById("inf_env").style.display = "none";
		document.formulari.nom_env.value = document.formulari.nom_fact.value;
		document.formulari.cognoms_env.value = document.formulari.cognoms_fact.value;
		document.formulari.telefon_env.value = document.formulari.telefon_fact.value;
		document.formulari.fax_env.value = document.formulari.fax_fact.value;
		document.formulari.domicili_env.value = document.formulari.domicili_fact.value;
		document.formulari.ciutat_env.value = document.formulari.ciutat_fact.value;
		document.formulari.postal_env.value = document.formulari.postal_fact.value;
		document.formulari.prov_env.value = document.formulari.prov_fact.value;
		document.formulari.pais_env.value = document.formulari.pais_fact.value;
		prova();
		
	}else{
		document.getElementById("inf_env").style.display = "block";
		prova();
	}
}
function prova(){
	marge = document.getElementById("idTop").offsetHeight + document.getElementById("idTop2").offsetHeight;
	document.getElementById("idTiraBase").style.top = marge+"px";
}
function canviarEstatComanda(idComanda){
	var valor = eval('document.getElementById("select_comanda_'+idComanda+'").value');
	document.location.href = "f_canviarEstatComanda.php?edit="+idComanda+"&valor="+valor;
	
}
