/*
 * POWERED BY EXPERTWEB
 * Inglaterra 1209 y Av Republica, Quito-Ecuador
 * (593 2) 246-1506, (593 9) 956-3284
 * www.expertweb.com.ec
 * info@expertweb.com.ec
 */
 
limit_multiple_users = true;
APP_context_path = "<%= request.getContextPath() %>";
DQM_codebase = "<%= request.getContextPath() %>/js/";

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 setChecked(form, name, value) {
	var len = form.elements.length;

	for (i=0; i<len; i++) {
		if (form.elements[i].name == name)
			form.elements[i].checked = value;
	}
}


function disableSubmit(formName) {
	var frm = document.forms[formName];
	var len = frm.elements.length;
	
	for (i=0; i<len; i++) {
		var tempobj = frm.elements[i];
		if (tempobj.type.toLowerCase()=="submit" || tempobj.type.toLowerCase()=="reset" || tempobj.type.toLowerCase()=="button")
			tempobj.disabled = true
	}
}

function populateSelect(selectObj, selectTarget, arrayList, search) {
	var val = selectObj.value;
	var frm = selectObj.form;
	var trg = frm.elements[selectTarget];
	
	var optionList = new Array();
	var index = 0;
	
	if (search == true) {
		var opt = new Array();
		opt[0] = 0;
		opt[1] = 'All';
		optionList[index] = opt;
		index ++;
	}
	for (var i=0; i<arrayList.length; i++) {
		if (arrayList[i][0] == val) {
			var opt = new Array();
			opt[0] = arrayList[i][1];
			opt[1] = arrayList[i][2];
			optionList[index] = opt;
			index ++;
		}
	}
	
	trg.length = index;
	for (var i=0; i<index; i++) {
		trg.options[i].value = optionList[i][0];
		trg.options[i].text = optionList[i][1];
	}
	trg.selectedIndex = 0;
}


function winStatus(msg) {
	window.status = msg;
}

function setLocation(url) {
	location = url;
}


function getOpenerUrl() {
    var sPath = location.pathname;
    var i = sPath.indexOf ('/:');
    var j = sPath.indexOf ('/', ++i);
    if (i != -1) sPath = sPath.substring (j, sPath.length);
	return escape(location.protocol + '//' + location.host + sPath + location.search);
}

function openWindow(url, title, w, h, x, y, scrollbars, location, directories, status, menubar, toolbar, resizable) {
	var settings='width='+w+',height='+h+',top='+x+',left='+y+',scrollbars='+scrollbars+',location='+location+',directories='+directories+',status='+status+',menubar='+menubar+',toolbar='+toolbar+',resizable='+resizable;
	nWin = open(url, title, settings);
	nWin.focus();
	return nWin;
}

// dialogWidth (cm, mm, in, pt, pc, or px)
// dialogHeight (cm, mm, in, pt, pc, or px)
// dialogLeft (cm, mm, in, pt, pc, or px)
// dialogTop (cm, mm, in, pt, pc, or px)
// center:{ yes | no | 1 | 0 | on | off }
// dialogHide:{ yes | no | 1 | 0 | on | off }
// edge:{ sunken | raised }
// help:{ yes | no | 1 | 0 | on | off }
// resizable:{ yes | no | 1 | 0 | on | off }
// scroll:{ yes | no | 1 | 0 | on | off }
// status:{ yes | no | 1 | 0 | on | off }
function modalDialog(url, args, dialogWidth, dialogHeight, dialogLeft, dialogTop, center, dialogHide, edge, help, resizable, scroll, status) {
	var sFeatures = "";
	if (center != 'yes' && center != '1' && center != 'on')
		sFeatures = "dialogWidth: "+dialogWidth+"px; dialogHeight: "+dialogHeight+"px; dialogLeft:"+dialogLeft+"px; dialogTop: "+dialogTop+"px; center: "+center+"; dialogHide: "+dialogHide+"; edge: "+edge+"; help: "+help+"; resizable: "+resizable+"; scroll: "+scroll+"; status: "+status+";";
	else
		sFeatures = "dialogWidth: "+dialogWidth+"px; dialogHeight: "+dialogHeight+"px; center: "+center+"; dialogHide: "+dialogHide+"; edge: "+edge+"; help: "+help+"; resizable: "+resizable+"; scroll: "+scroll+"; status: "+status+";";
	return window.showModalDialog(url, args, sFeatures);
}

function modelessDialog(url, args, dialogWidth, dialogHeight, dialogLeft, dialogTop, center, dialogHide, edge, help, resizable, scroll, status) {
	var sFeatures = "";
	if (center != 'yes' && center != '1' && center != 'on')
		sFeatures = "dialogWidth: "+dialogWidth+"px; dialogHeight: "+dialogHeight+"px; dialogLeft:"+dialogLeft+"px; dialogTop: "+dialogTop+"px; center: "+center+"; dialogHide: "+dialogHide+"; edge: "+edge+"; help: "+help+"; resizable: "+resizable+"; scroll: "+scroll+"; status: "+status+";";
	else
		sFeatures = "dialogWidth: "+dialogWidth+"px; dialogHeight: "+dialogHeight+"px; center: "+center+"; dialogHide: "+dialogHide+"; edge: "+edge+"; help: "+help+"; resizable: "+resizable+"; scroll: "+scroll+"; status: "+status+";";
	return window.showModelessDialog(url, args, sFeatures);
}

function openCalendar(url, field) {
	url = APP_CONTEXT_PATH + url;
	return modalDialog(url, field, 270, 240, 0, 0, 'yes', 'no', 'raised', 'no', 'no', 'no', 'no');
}

function openSearch(url, f, p, l, i) {
    var url = APP_CONTEXT_PATH + url;

    url = url + '?parent=' + getOpenerUrl();
    url = url + '&form=' + f;
    url = url + '&value=' + p;
    url = url + '&label=' + l;
	url = url + '&index=' + i;

	var x = Math.floor((screen.width - 600) / 2);
	var y = Math.floor((screen.height - 400) / 2);
    
    var wup = openWindow(url, 'Search', 600, 400, x, y, 'yes', 'no', 'no', 'yes', 'no', 'no', 'no');
    
    if (wup.opener == null) wup.opener = self;
	wup.focus();
}

function openUpload(url, base, f, p, l, i) {
    var url = APP_CONTEXT_PATH + url;

    url = url + '?parent=' + getOpenerUrl();
    url = url + '&base=' + base;
    url = url + '&form=' + f;
    url = url + '&value=' + p;
    url = url + '&label=' + l;
	url = url + '&index=' + i;

	var x = Math.floor((screen.width - 600) / 2);
	var y = Math.floor((screen.height - 400) / 2);
    
    var wup = openWindow(url, 'Upload', 600, 400, x, y, 'yes', 'no', 'no', 'yes', 'no', 'no', 'no');
    
    if (wup.opener == null) wup.opener = self;
	wup.focus();
}

function submitForm(obj, status) {
	var frm = obj.form;
	
	disableSubmit(frm.name);
	frm.newStatusCode.value = status;
	frm.submit();
}

function hiLightRow(obj) {
	if (obj.className.toLowerCase() == 'normal' || obj.className == '') {
		obj.className = 'hi';
	} else {
		obj.className = 'normal';
	}
}



// Variables Gloabales
admin_inputBorderColor = '#A5ACB2';
admin_inputBorderColor_hi = '#6DB2F5';

input_BgColor = '#FFFFFF';
input_BgColor_hi = '#F6FBFB';

function swapFocus(obj) {
    if (obj.style.backgroundColor.toUpperCase() == input_BgColor || obj.style.backgroundColor == "") {
        obj.style.backgroundColor = input_BgColor_hi;
    } else {
        obj.style.backgroundColor = input_BgColor;
    }
}

function swapFocusAdmin(obj) {
    if (obj.style.borderColor.toUpperCase() == admin_inputBorderColor || obj.style.borderColor == "") {
        obj.style.borderColor = admin_inputBorderColor_hi;
    } else {
        obj.style.borderColor = admin_inputBorderColor;
    }
}


function trim(str) {
	if ((typeof str == 'undefined') || (str == null)) return '';

	var ln = str.length;
	var st = 0;

	while ((st < ln) && (str.charAt(st) <= ' ')) {
	    st++;
	}
	while ((st < ln) && (str.charAt(ln - 1) <= ' ')) {
	    ln--;
	}
	return ((st > 0) || (ln < str.length)) ? str.substring(st, ln) : str;
}

function isEmpty(str) {
	if ((typeof str == 'undefined') || (str == null)) return true;
	var s = trim(str);
	return s.length == 0 ? true: false;
}



/*  Chequea que el arreglo de cantidades o el campo de cantidades
 	sea diferente de cero en al menos un campo
 	Autor: Gabriel Eguiguren P.
*/ 
function validateQty(frm) {

	var count = 0;
		
	for (i=0; i< frm.quantities.length ; i++){
		if ( frm.quantities[i].value == 0 ) {
			count++;
		}
	}
		
	if (count == frm.quantities.length ) {
		alert("Al menos una cantidad debe ser diferente de Cero");
		return false;
	}
	else {
	
		if ( frm.quantities.value == 0 ) {
			alert('El campo de Cantidad es requerido');
			return false;
		} else {
			frm.submit();
		}
	}
}

/*
* Show a confirmation windows in order to delete a registry
* @autor dracines
*/

function deleteConfirm(registry, url) {
	if (window.confirm("Está a punto de eliminar '" + registry + "'\n¿Desea continuar?")) {
		window.location=url;
	}
}

