var numb = '0123456789.,';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 
function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}
 
function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}


function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function duplicarItem(ipid){
	if (form = document.getElementById('formPedidos')){
		form.action2.value = "dplCart";
		form.ipid.value = ipid;
		form.submit();
	}
}
function removerItem(ipid){
	if (form = document.getElementById('formPedidos')){
		form.action2.value = "rmvCart";
		form.ipid.value = ipid;
		form.submit();
	}
}
function actualizar(){
	if (form = document.getElementById('formPedidos')){
		form.action2.value = "refresh";
		form.submit();
	}
}
function changeImgEstampado(src,id){
	img = document.getElementById('img_estampado'+id);
	img.src = 'showImg2.php?i='+src;
	return true;
}
function ubicarStamps(idp,idc,stamps){
	win = window.open("templates/stamps.php?idp="+idp+"&idc="+idc+"&prenda="+stamps,"stamps","width=550,height=400");
}
function admin_ubicarStamps(idp,idc,stamps){
	win = window.open("../templates/stamps.php?idp="+idp+"&idc="+idc+"&prenda="+stamps,"stamps","width=550,height=400");
}
function showStamps(id){
	div = document.getElementById(id);
	div.style.display = "block";
}
function closeStamps(){
	/*btn = opener.document.getElementById('img_estampado'+id);*/
	self.close();
}

function recalcular(){
	if (form = document.getElementById('formFactura')){
		var itemsTotal = form.itemsTotal.value;
		var subtotal;
		var totales;
		var precio = 0;
		totales = 0;
		for (x=1;x<=itemsTotal;x++){
			eval('precio = document.forms[\'formFactura\'].precioU__'+x+'.value;');
			eval('cantidad = document.forms[\'formFactura\'].cantidad__'+x+'.value;');
			precio = precio.replace(eval("/,/"),".");
			precio *= 1;
			cantidad *= 1;
			cantidad = Math.floor(cantidad);
			subtotal = precio * cantidad;
			html = document.getElementById('subtotal__'+x);
			html.innerHTML = "Subtotal: $"+subtotal.toFixed(2);
			s = document.getElementById('precioU__'+x);
			s.value = precio.toFixed(2);
			s = document.getElementById('cantidad__'+x);
			s.value = cantidad;
			totales += subtotal;
		}
		html = document.getElementById('total');
		html.innerHTML = "TOTAL: $"+totales.toFixed(2)+".-";
	}
}

function pedidoAprobacion(){
	if (form = document.getElementById('formFactura')){
		form.action.value = "aprobar";
		form.submit();
	}
}
function pedidoConfirmacion(){
	if (form = document.getElementById('formFactura')){
		form.action.value = "confirmar";
		form.submit();
	}
}

function pedidoPrint(id){
	win = window.open("admin_printOrd.php?pid="+id,"colores","width=635,height=600,scrollbars=yes");
}

function printNow(){
	window.print();
}

function deleteProd(idp){
	if (confirm("¿Está seguro que desea eliminar este producto?")){
		document.location = "edit_productos_e.php?action=delete&idp="+idp;
	}
}

function editColoresOpen(){
	win = window.open("edit_colores_popup.php","colores","width=530,height=520,scrollbars=yes");
}

function editTallesOpen(){
	win = window.open("edit_talles_popup.php","talles","width=530,height=520,scrollbars=yes");
}

function cerrarPopEdicion(){
	window.opener.location.reload();
	self.close();
}

function preBuildProd(form){
	dataDoc = document.frames['editColores'].document;
	totalColores = dataDoc.getElementById('total').value;
	valores = "";
	for (x=0;x<totalColores;x++){
		if (dataDoc.getElementById('colores__'+x).checked){
			valores += dataDoc.getElementById('colores__'+x).value + ";";
		}
	}
	form.coloresSel.value  = valores;
	
	dataDoc = document.frames['editTalles'].document;
	totalTalles = dataDoc.getElementById('total').value;
	valores = "";
	for (x=0;x<totalTalles;x++){
		if (dataDoc.getElementById('talles__'+x).checked){
			valores += dataDoc.getElementById('talles__'+x).value + ";";
		}
	}
	form.tallesSel.value  = valores;
	form.submit();
	return true;
}

function showImage(img,content){
	document.getElementById(content).src = img;
}

function bderecho(e) {
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
alert(" Copyright © 2006 - JV Publicidad");
return false;
}
return true;
}

if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=bderecho;
document.onmousedown=bderecho; 