// JavaScript Document

// JavaScript Document
function borracampo(campo){
	if (campo.defaultValue==campo.value){
	campo.value = "";
	}
}

function checkSearch(form){
	for (i = 0; i < form.elements.length; i++) { 
		if (form.elements[i].value == "") { 
			alert("Por favor Seleccione una Opción"); 
			form.elements[i].focus(); 
			return false; 
		} 
	} 

}

function moveSelectedOptions(from,to){
	for (var i=0; i<from.options.length; i++) 
	{
	  var o = from.options[i];
	  if (o.selected) {
	     to.options[to.options.length] = new Option( o.text, o.value, false, false);
	  }
	}
	for (var i=(from.options.length-1); i>=0; i--) {
	  var o = from.options[i];
	  if (o.selected) {
	    from.options[i] = null;
	  }
	}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}

function bloqDesbloq(activo,desactivo){
	a = activo;
	if ((parseInt(a)!=0 && a != "")){desactivo.value = "";}else if((parseInt(a)==0 || a == "")&& desactivo.value == ""){  }else{return false;}
    if (a != "" && parseInt(a)!=0) {  a = true; }
    else { a = false; }
    if (a == true) { frmJAMM21.promocion.disabled = false; }
    else { 
	frmJAMM21.promocion.checked = false;
	frmJAMM21.promocion.disabled = true; 
	frmJAMM21.tachar.checked = false;
	frmJAMM21.tachar.disabled = true;
	}
}

function maximaLongitud(texto,maxlong) { 
  var tecla, in_value, out_value; 

  if (texto.value.length > maxlong) { 
    in_value = texto.value; 
    out_value = in_value.substring(0,maxlong); 
    texto.value = out_value; 
    return false; 
  } 
  return true; 
} 

function select_all(strForm, strElement) {
var L = document.forms[strForm].elements[strElement];
//alert("adadaddsadsad");
if (L.options.length == 0){
	//alert('Selecciona una categoría.');
	frmJAMM21.menuitems.focus()
	return false;
}
for(var a=0;a < L.options.length;a++){
 L.options[a].selected = true;
 }
 //document.forms[strForm].submit();
}

function select_all2(strForm, strElement, msg) {
var L = document.forms[strForm].elements[strElement];
//alert("adadaddsadsad");
if (L.options.length == 0){
	alert(msg);
	frmJAMM21.menuitems.focus()
	return false;
}
for(var a=0;a < L.options.length;a++){
 L.options[a].selected = true;
 }
 document.forms[strForm].submit();
}

function select_all3(strForm, strElement, msg) {
var L = document.forms[strForm].elements[strElement];
//alert("adadaddsadsad");
if (L.options.length == 0){
	alert(msg);
	frmJAMM21.menuitems.focus()
	return false;
}
for(var a=0;a < L.options.length;a++){
 L.options[a].selected = true;
 }
}

function ConfirmDel(Msg,Id,trs){
	if(confirm(Msg)){
		document.location.href = 'transaction.php?trs='+trs+'&ID_DEPTO='+Id;
	}
}


var j;
var strValidChars = '0123456789.';
var returnbol = true;
function IsNumeric(strString){
	//  check for valid numeric strings	
	var strChar;
	var blnResult = true;
	if (strString.length == 0) return returnbol;
		//  test strString consists of valid characters listed above
	for (j = 0; j < strString.length && blnResult == true; j++)
		{
		strChar = strString.charAt(j);
		if (strValidChars.indexOf(strChar) == -1)
			{
			blnResult = false;
			}
		}
	return blnResult;
}

//Muestra las fotos de la galería a detalle
/*function showPic (whichpic) { 
	if (document.getElementById) { 
		document.getElementById('placeholder').src = whichpic.href; 
		document.getElementById('placeholder').src = whichpic.title;
		return false; 
	} else { 
		return true;
	} 
}*/

function showPic (whichpic,title) { 
	if (document.getElementById) { 
		document.getElementById('placeholder').src = whichpic; 
		document.getElementById('placeholder').title = title;
		return false; 
	} else { 
		return true;
	} 
}

function MM_swapImgRestore() { //v3.0
  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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function expandCollapse() {
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

// Quita los enpacios vacios a la izquierda de la cadena
function LTrim( value ) { 
	var re = /\s*((\S+\s*)*)/; 
	return value.replace(re, "$1"); 
} 
         
// Quita los enpacios vacios a la derecha de la cadena
function RTrim( value ) { 
	var re = /((\s*\S+)*)\s*/; 
	return value.replace(re, "$1");          
}

// Quita los enpacios vacios al principio y al final de la cadena
function trim( value ) { 
	return LTrim(RTrim(value));           
}

function Envia_Email_To_Boletin(){
	if(Boletin.AddMyEmail.value == "" || Boletin.AddMyEmail.value == "Agrega tu email"){
		Boletin.AddMyEmail.focus();
		return false;
	} else{ 
		window.open('','ventana','toolbar=no,directories=no,scrollbar=yes,height=300,width=395,resizable=no,Top=100,Left=100')
		document.Boletin.submit();
	}
}

function MDM_openWindow(theURL,winName,features,WidthPopup,HeightPopup){
	var _W=window.open(theURL,winName,features);
	_W.focus();
	WidthPopup = parseInt(WidthPopup);
	HeightPopup = parseInt(HeightPopup);
	iz=(screen.width-WidthPopup) / 2;
    de=(screen.height-HeightPopup) / 2;
    _W.moveTo(iz,de);
}

function fotoGrande(theURL,winName,features){ 
  	var _W=window.open(theURL,winName,features);
 	_W.focus();
    _W.moveTo(100,100); 
} 

//-----------------------------------Imagenes Adicionales-----------------------------------------
function agregaradicional(id){
	document.getElementById('pop_agregarimg').innerHTML='<table style="border:#0066FF; border-width:1px" width="270" bgcolor="#B9B9B9"><tr><td class="celdaencabezado"><img src="../../../images/filenew.gif" border="0" />  Agregar imagen adicional</td></tr><tr><td bgcolor="#FFFFFF"><iframe src="iframe.agregarimg.php?id='+id+'" width="270" height="70" frameborder="0" id="iframeAgregarfoto" name="iframeAgregarfoto"></iframe></td></tr></table>';
}
function agregaradicional_cat(id){
	document.getElementById('pop_agregarimg_cat').innerHTML='<table style="border:#0066FF; border-width:1px" width="270" bgcolor="#B9B9B9"><tr><td class="celdaencabezado"><img src="../../../images/filenew.gif" border="0" />  Agregar imagen adicional</td></tr><tr><td bgcolor="#FFFFFF"><iframe src="iframe.agregarimg_cat.php?id='+id+'" width="270" height="70" frameborder="0" id="iframeAgregarfoto" name="iframeAgregarfoto"></iframe></td></tr></table>';
}


function cancelarAgregarFoto(){
	document.getElementById('pop_agregarimg').innerHTML='';
}
function cancelarAgregarFoto_cat(){
	document.getElementById('pop_agregarimg_cat').innerHTML='';
}

function ampliar(img,ancho,alto){
  elalto=550;
  elancho=550;
	
  var theURL="ampliar.foto.php?img="+img;
  var winName="AmpliarFoto";
  var features="scrollbars=yes,width="+elancho+",height="+elalto;
  var _W=window.open(theURL,winName,features); 
  iz=(screen.width-elancho) / 2;
  de=(screen.height-elalto) / 2;
  _W.moveTo(iz,de);
}

function borrarIMG_a(idi,id_prod){
	if(confirm("ATENCIÓN: Esta acción no se puede deshacer\nConfirme que desea eliminar esta imagen")){
			//InfoDivCarga("Eliminando");
			xajax_borrarImg_a(idi,id_prod);
	}
}
function borrarIMG_a_cat(id_prod){
	if(confirm("ATENCIÓN: Esta acción no se puede deshacer\nConfirme que desea eliminar esta imagen")){
			//InfoDivCarga("Eliminando");
			xajax_borrarImg_a_cat(id_prod);
	}
}


function FotoAgregada(id,ins,imagen,newimage,imagench,ancho,largo){
document.getElementById('pop_agregarimg').innerHTML='';
$r='<span ID="img_a_'+ins+'" style="margin:4px; display:inline"><table style="display:inline" border="0" cellspacing="0" cellpadding="0"><tr><td><span style="position:absolute; padding-top: 5px;" id="ampliarimg"><a class="ampliar" href="javascript:ampliar(\'../../../../imagenes/'+imagen+'\','+ancho+','+largo+');" title="Ver imagen ampliada"><img src="../../../images/ampliar.gif" border="0" /></a><a class="ampliar" href="javascript:borrarIMG_a('+ins+','+id+');" title="Eliminar imagen"><img src="../../../images/borrar_img.gif" border="0" /></a><a class="ampliar" onclick="if(confirm(\'Desea Rotar la imagen a 90°???\')){document.location=\'rotar.php?imagen='+newimage+'&angulo=90&id_p='+ins+'&id='+id+'\';}" style="cursor:pointer;"  title="Rotar imagen"><img src="../../../images/rotar.png" border="0" /></a></span></td></tr><tr><td><img src="../../../../imagenes/'+imagench+'" border="0" /></td></tr></table></span>';
document.getElementById('imagenessecundarias').innerHTML=document.getElementById('imagenessecundarias').innerHTML+$r;
actual=parseInt(document.getElementById('num_Adicionales').innerHTML);
//total=parseInt(document.getElementById('num_Total_Adicionales').innerHTML);
actual=actual+1;
/*if(actual>=total){
	document.getElementById('agregarSecundaria').innerHTML=" Imagenes adicionales completas ";
}*/
document.getElementById('num_Adicionales').innerHTML=actual;
//InfoDivDone('Se agregó la imagen');
}

function FotoAgregada_cat(id,ins,imagen,imagench,ancho,largo){
document.getElementById('pop_agregarimg_cat').innerHTML='';
$r='<span ID="img_a_cat" style="margin:4px; display:inline">';
$r+='		<table style="display:inline" border="0" cellspacing="0" cellpadding="0">';
$r+='			<tr>';
$r+='				<td>';
$r+='					<span style="position:absolute; padding-top: 5px;" id="ampliarimg">';
$r+='						<a class="ampliar" href="javascript:ampliar(\'../../../../imagenes/'+imagen+'\','+ancho+','+largo+');" title="Ver imagen ampliada">';
$r+='							<img src="../../../images/ampliar.gif" border="0" /></a>';

$r+='						<a class="ampliar" href="javascript:borrarIMG_a_cat('+id+');" title="Eliminar imagen">';
$r+='							<img src="../../../images/borrar_img.gif" border="0" /></a>';
				
$r+='					</span>';
$r+='				</td>';
$r+='			</tr>';
$r+='			<tr>';
$r+='				<td>';
$r+='					<img src="../../../../imagenes/'+imagench+'" border="0" />';
$r+='				</td>';
$r+='			</tr>';
$r+='		</table>';
$r+='	</span>';

document.getElementById('imagenessecundarias_cat').innerHTML=$r;
//actual=parseInt(document.getElementById('num_Adicionales').innerHTML);
//total=parseInt(document.getElementById('num_Total_Adicionales').innerHTML);
//actual=actual+1;
/*if(actual>=total){
	document.getElementById('agregarSecundaria').innerHTML=" Imagenes adicionales completas ";
}*/
//document.getElementById('num_Adicionales').innerHTML=actual;
//InfoDivDone('Se agregó la imagen');
}