<!--
function isDefined(variable)
{
	return eval('(typeof('+variable+') != "undefined" && typeof('+variable+') != "unknown");');
}

function ClearCombo(combo)
{
	while (combo.options.length > 0)
		combo.remove(0);
}
		
function FillCombo(combo, response, defaultString,selected)
{
	ClearCombo(combo);		
	var itemArray = http_request.responseText.split('~');
	
	
	AddComboItem(combo,defaultString,"");
	
	for (thisIndex=0; thisIndex<itemArray.length; thisIndex++)
	{
		var itemValues=itemArray[thisIndex].split('|');
		if(itemValues.length>1)
		{
			var item=AddComboItem(combo,itemValues[1],itemValues[0]);
			if(itemValues[1]==selected)
				item.selected=true;
		}
	}
}

function AllowObjectsRun()
{
	var theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
	theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}


//Get Element (Object) found by its ID
function General_getElementById(tagId) 
{
	var obj = document.all[tagId];
	if(obj && obj.length && obj[0].id==tagId)
		obj=obj[0];
	return obj;
}

//Verificar si una direccion de correo esta escrita correctamente
function isEmailValid(email) 
{ 
    return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(email); 
} 

function CleanHTMLToClient(textToClean, ControlToStore)
{
	Resultat=""
	Resultat = textToClean.replace(/<br>/gi, String.fromCharCode(10));
	if(ControlToStore!=null && ControlToStore.value!=null)
		ControlToStore.value = Resultat;
}

function EncodeHTMLToServer(textToEncode, ControlToStore)
{
	Resultat=""
	for (i=0;i<textToEncode.length;i++)
	{
		numer=textToEncode.charCodeAt(i);
		if((numer==13)&&(textToEncode.charCodeAt(i+1)==10))
			{
				i++;
				Resultat += '<br>';
			}
		else
			Resultat += String.fromCharCode(numer);			
	}
	if(ControlToStore!=null && ControlToStore.value!=null)
		ControlToStore.value = Resultat;
}

function AddComboItem(comboListObject, newItemString, newItemValue)
{
	//Agregar elementos intermedios
	var lclObjOpt 	= window.document.createElement("OPTION");
	lclObjOpt.text 	= newItemString;
	lclObjOpt.value = newItemValue;
	try {
      comboListObject.add(lclObjOpt, null);
    }
    catch(ex) {
      comboListObject.add(lclObjOpt);
    }
    return lclObjOpt;
}

function openModal(){
if (window.showModalDialog('mensajes/modalControl.asp','dialogHeight: 160px; dialogWidth: 600px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;'))
	document.location.href = 'controlModule.asp';
}

function OpenModalWindow(windowURL, width, height)
{
	window.showModalDialog(  windowURL, "",   "dialogHeight:"+height+"px;dialogWidth:"+width+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
}

function OpenWindow(target){ 
popupWin = window.open(target, "Impresiones", "toolbar=yes,directories=no,status=no,menubar=yes,width=850,height=450,left=30,top=30"); 
popupWin.focus(); 
}

function OpenWindow2(target){ 
popupWin = window.open(target, "Impresiones", "toolbar=yes,directories=no,status=no,scrollbars=yes,menubar=yes,width=750,height=450,left=30,top=30"); 
popupWin.focus(); 
}

//Get Element (Object) found by its ID. If its a list, get the first one
function GetElement(tagId) 
{
	var lclObj = document.getElementById(tagId);
	if(lclObj && lclObj.length && lclObj[0].id==tagId)
		lclObj=lclObj[0];
	return lclObj;
}

//Get Element (Object) found by its ID. If its a list, get all
function GetRawElement(tagId) 
{
	return document.getElementById(tagId);
}

//Get form element value
function GetTagValue(elementID)  //obj,use_default,delimiter
{
	var use_default = false;
	var delimiter = ',';
	
	if (elementID == '')
		return null;
	
	var lclObj = GetElement(elementID);
	
	if(null==lclObj)
		return null;
		
	switch(lclObj.type)
	{
		case 'radio': 
		case 'checkbox': 
			return(((use_default)?lclObj.defaultChecked:lclObj.checked)?lclObj.value:null);
		
		case 'text': 
		case 'hidden': 
		case 'textarea': 
			return(use_default)?lclObj.defaultValue:lclObj.value;
		
		case 'password': 
			return((use_default)?null:lclObj.value);
		case 'select-one':
			if(lclObj.options==null)
			{
				return null;
			}
			if(use_default)
			{
				var o=lclObj.options;
				for(var i=0;i<o.length;i++)
				{
					if(o[i].defaultSelected)
					{
						return o[i].value;
					}
				}
				return o[0].value;
			}
			if(lclObj.selectedIndex<0)
			{
				return null;
			}
			return (lclObj.options.length>0)?lclObj.options[lclObj.selectedIndex].value:null;
			
		case 'select-multiple':
			if(lclObj.options==null)
			{
				return null;
			}
			var values=new Array();
			for(var i=0;i<lclObj.options.length;i++)
			{
				if((use_default&&lclObj.options[i].defaultSelected)||(!use_default&&lclObj.options[i].selected))
				{
					values[values.length]=lclObj.options[i].value;
				}
			}
			
			return(values.length==0)?null:CommifyArray(values,delimiter);
	}
			
	//alert("FATAL ERROR: Field type "+lclObj.type+" is not supported for this function");
	return null;
}




function switchRowColor(objectID, highlightcolor)
{
		var object = GetElement(objectID);
		if (object.tagName == "TD")
			var row = object.parentElement;
		else
			var row =object;

		if (!row.highlighted)
		{
			row.highlighted = true;
			row.originalBackgroundColor=row.style.backgroundColor;
			row.style.backgroundColor=highlightcolor;
		}
		else
		{
			row.highlighted = false;
			row.style.backgroundColor=row.originalBackgroundColor;
		}
}

function highlightRowColor(objectID, highlightcolor, on)
{
		var row = GetElement(objectID);
			
		if (on)
		{
			row.originalBackgroundColor2=row.style.backgroundColor;
			row.style.backgroundColor=highlightcolor;
		}
		else
		{
			row.style.backgroundColor=row.originalBackgroundColor2;
		}
}

//Hides and appears description and editable elements, to activate EDIT pages.
function switchEditElements(startEdit){	
	var elements = document.getElementsByTagName('span')
	if (startEdit)
	{
		for (i=0; i<elements.length; i++){
			if(elements[i].id.substr(0,5)=='show_')
				elements[i].style.display = 'none';
			if(elements[i].id.substr(0,5)=='edit_')
				elements[i].style.display = '';
		}
	}
	else
	{
		for (i=0; i<elements.length; i++){
			if(elements[i].id.substr(0,5)=='edit_')
				elements[i].style.display = 'none';
			if(elements[i].id.substr(0,5)=='show_')
				elements[i].style.display = '';
		}
	}
}


//function onKeyPress(DataType, MinValue, MaxValue){
function onKeyPress(event,DataType){
	//TAB and ENTER keys accepted
	if (event.keyCode==9||event.keyCode==13)
		return;
	if (DataType==3&&event.keyCode==46)
		return;
	//digits accepted
	if (event.keyCode<48 || event.keyCode>57)
		event.returnValue = false;
}

function onKeyDown(event, element){
	//switch enter for tab
	if (event.keyCode==13)
		event.keyCode=9;
}

function getArticlePrice(ArticleCode, RowId){
		var FactorLocal = 1;
		if (Factor)
			FactorLocal = Factor;
		if (ArticleCode.length==0)
			return;
		if (PriceList[ArticleCode])
		{
			var price = PriceList[ArticleCode] * FactorLocal;
			price = Math.round(price*100)/100;
			price = price.toString();
			splitprice = price.split('.');
			if (splitprice[1])
			{
					for (i=0; i<(2-splitprice[1].length); i++)
						price = price + '0';
			}
			else
				price = price + '.00';
			eval('document.formaminisuper.costo_'+RowId+'.value = price');
		}
		else
		{
			eval('document.formaminisuper.costo_'+RowId+'.value = \'inválido\'');
			eval('document.formaminisuper.costo_'+RowId+'.select()');
		}
}

//restrict user input to only numbers
function RestrictUserInput(elem) {
    if (/[^\d]/g.test(elem.value))
       elem.value = elem.value.replace(/[^\d]/g, '');
}

//get DateFormat in english - month/day/year, considering parameter comes in spanish - day/month/year
function EnglishDateFormat(dateParam)
{
	if (dateParam == '')
	{
		return (dateParam);
	}
	else
	{
		var paramArray = dateParam.split("/");
		return (paramArray[1] + "/" + paramArray[0] + "/" + paramArray[2]);
	}
}

//get DateFormat in spanish - day/month/year, considering parameter comes in english
function SpanishDateFormat(dateParam)
{
	//remover hora
	var noHourArray	= dateParam.split(" ");
	
	if (noHourArray[0] == '')
	{
		return (dateParam);
	}
	else
	{
		var paramArray = noHourArray[0].split("/");
		return (paramArray[1] + "/" + paramArray[0] + "/" + paramArray[2]);
	}
}

function GetDateObject(dateParam)
{
	var newDateObj 	= new Date();
	var paramArray 	= dateParam.split("/");
	
	newDateObj.setFullYear(paramArray[2]*1, paramArray[0]*1-1, paramArray[1]*1);
	
	return newDateObj;
}

//input date as yyyy/mm/dd, and number of days to add
//output yyyy/mm/dd
function AddDays(strDate,iDays)
{
strDate = Date.parse(strDate);
strDate = parseInt(strDate, 10);
strDate = strDate + iDays*(24*60*60*1000);
strDate = new Date(strDate);
returnValue = strDate.getFullYear() + "/" + strDate.getMonth()*1+1 + "/" + strDate.getDate();

return returnValue;
}

function DateAdd(interval,n,dt)
{
	if(!interval||!n||!dt) return;	
	
	var s=1,m=1,h=1,dd=1,i=interval;
	
	if(i=='month'||i=='year')
	{
		dt=new Date(dt);
		if(i=='month')
		{
			newMonth = dt.getMonth() + n;
			if (newMonth > 11)
				newMonth = newMonth - 12;
			dt.setMonth(dt.getMonth()+n);
			if(dt.getMonth() != newMonth)
			{
				//overshot month due to date, so go to last day of previous month 
				dt.setDate(0);
			}
		}
		if(i=='year') dt.setFullYear(dt.getFullYear()+n);		
	}
	else if (i=='second'||i=='minute'||i=='hour'||i=='day'){
		dt=Date.parse(dt);
		if(isNaN(dt)) return;
		if(i=='second') s=n;
		if(i=='minute'){s=60;m=n}
		if(i=='hour'){s=60;m=60;h=n};
		if(i=='day'){s=60;m=60;h=24;dd=n};
		dt+=((((1000*s)*m)*h)*dd);
		dt=new Date(dt);
	}
	return dt;
}

//-------------- new Validation Functions

//Validates a value against a regular expression and limit values
function ValueValidator(stringRegExp, inputValue, selectionRange, OldValue, DecimalSeparator, MinValue, MaxValue){
	var validation = true;
	var objRegExp = new RegExp(stringRegExp.toString());
	var endIndex = selectionRange.text.length;
	while(selectionRange.expand("character")){}
	var startIndex = OldValue.length - selectionRange.text.length;
	endIndex = endIndex + startIndex;
	var newValueCandidate = OldValue.substring(0,startIndex) + inputValue + OldValue.substring(endIndex,OldValue.length);
	if(!objRegExp.test(newValueCandidate))
		return false;
	else
	{
		//Validate for MinValue and MaxValue
		if (MinValue!=null || MaxValue!=null)
		{
			var CompareNum = parseFloat(newValueCandidate.replace(DecimalSeparator,'.'));
			if (MinValue!=null && CompareNum < MinValue) validation = false;
			if (MaxValue!=null && CompareNum > MaxValue) validation = false;
			return validation;
		}
		else
			return true;
	}
}

//Validates Currency Values
function ValidateCurrency(InputObj, minvalue, maxvalue){
	var key = window.event.keyCode;
	var selectionRange = document.selection.createRange ();
	var TextBoxValue = InputObj.value;
	
	var DecimalSeparator = '.';
	var DecimalDigits = 2;
	var MinValue = minvalue;
	var MaxValue = maxvalue;
	var NegativeSign = "";
	if (MinValue < 0) var NegativeSign = "-?";
	
	var stringRegExp = "(^"+NegativeSign+"\\d*\\"+DecimalSeparator+"?\\d{0,"+DecimalDigits+"}$)";
	if (!ValueValidator(stringRegExp, String.fromCharCode(key), selectionRange, TextBoxValue, DecimalSeparator, MinValue, MaxValue))
	{
		if (event.keyCode)
			event.keyCode = 0;	
		else
			event.which = 0;
			
		return false;
	}
}

//Validates Clipboard against a regular expression to allow or deny pasting it in the TextBox
function ValidateClipboard(InputObj, minvalue, maxvalue, DataType){
//	var Clipboard = igtbl_trim(window.clipboardData.getData("Text"));
	var ClipBoard = window.clipboardData.getData("Text");
	if (!event || Clipboard.length==0 || Clipboard == undefined) return;
	
	var selectionRange = document.selection.createRange ();
	var TextBoxValue = this.value;
		
	var MinValue = minvalue;
	var MaxValue = maxvalue;
		var NegativeSign = "";
	// Allow for negative sign to be approved by Regular Expression
	if (MinValue < 0) var NegativeSign ="-?";
	
	switch(DataType){
		case 3: //Currency
			var stringRegExp = "(^-?\\d*\\.?\\d{0,2}$)";
			if (!ValueValidator(stringRegExp, Clipboard, selectionRange, TextBoxValue, Culture.CurrencyDecimalSeparator, MinValue, MaxValue))
				event.returnValue = false;
			break;
	}	
	return;
}

function Format(num,decimaldigits,symbol,dot,groupseparator,groupdigits, percentFormat){
		var DecimalDigits = 1;
		for (var i=0; i<decimaldigits; i++)
			DecimalDigits = DecimalDigits * 10;
		var RegularExp = new RegExp("/\\" + symbol + "|\\" + groupseparator + "/g");
		num = num.toString().replace(RegularExp,'');
		num = num.replace(dot,'.');	//replace decimal separator with '.' for Math class properties
		if(isNaN(num)) return "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*DecimalDigits+0.50000000001);
		cents = num%DecimalDigits;
		centsStr = cents.toString();
		num = Math.floor(num/DecimalDigits).toString();
		for (var i=0; i<decimaldigits-centsStr.length; i++)
			centsStr = "0" + centsStr;
		cents = centsStr;
		for (var i = 0; i < Math.floor((num.length-(1+i))/groupdigits); i++)
			num = num.substring(0,num.length-((groupdigits+1)*i+groupdigits))+groupseparator+num.substring(num.length-((groupdigits+1)*i+groupdigits));
		if (percentFormat)
			return (((sign)?'':this.NegativeSign) + num + dot + cents + symbol);
		else
			return (((sign)?'':this.NegativeSign) + symbol + num + dot + cents);
}

function FormatCurrency(InputObj){
	InputObj.value = Format(InputObj.value, 2, '$', '.' , ',', 3, false);
}

function CleanFormat(InputObj,DataType){
	if (InputObj.value.substring(0,1)=='$')
		InputObj.value = InputObj.value.substring(1,InputObj.value.length);
	InputObj.value = InputObj.value.replace(',','');
}


function Navigate(Module){
eval("document.location='" + Module + "'");
}



function replaceAll(oldStr,findStr,repStr) {
  var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                    // of oldStr are we searching.
  var newStr = "";  // newStr will hold the altered version of oldStr.
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
                    // As long as there are strings to replace, this loop
                    // will run. 
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
                    // Put it all the unaltered text from one findStr to
                    // the next findStr into newStr.
    newStr += repStr;
                    // Instead of putting the old string, put in the
                    // new string instead. 
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
                    // Now jump to the next chunk of text till the next findStr.           
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
                    // Put whatever's left into newStr.             
  return newStr;
}

//Obtener un numero al azar entre cero y cinco mil
function get_random()
{
    var ranNum= Math.floor(Math.random()*5000);
    return ranNum;
}

//Get an element's absolute position, from 'Left' or 'Top'
function getRelativePosition(e,where)
{
	var adjustX = 0;
	var adjustY = 0;
			
	display = true;
	var doneDIV = false;
	
	if(where=="Left")
	{
		equivWhere = "offsetWidth";
		adjustZ = adjustX;
	}
	else
	{
		equivWhere = "offsetHeight";
		adjustZ = adjustY;
	}
		
	var offs = "offset"+where;
	var bw = "border"+where+"Width";
	var crd = e[offs];
	var parent=e.offsetParent;
	var divPos = 0;
	
	while(!(parent==null || parent.style.position=="relative"))
	{
		if(parent.style.position=="absolute")
			break;
		crd+=parent[offs];
		divPos+=parent[offs];
		
		if((parent.tagName=="DIV" || parent.tagName=="TD") && parent.style[bw])
			crd+=parseInt(parent.style[bw],10);
		if(parent.tagName=="DIV" && !doneDIV)
		{
			crd-=parent["scroll"+where];
			if(crd<0) display = false;
			doneDIV = true;
			var parentDIV = parent;
			divPos = parent[offs];
		}
		parent=parent.offsetParent;
	}
	if(doneDIV)
	{
		var scrollbarWidth = 0;
		//get scrolls appeared
		if(parentDIV.children[0] && parentDIV.children[0][equivWhere]>parentDIV[equivWhere])
			scrollbarWidth = 14;
			
		if(crd+adjustZ<divPos || crd+adjustZ+e[equivWhere]>divPos+parentDIV[equivWhere]-scrollbarWidth) display = false;
	}
	return crd;
}

function GetWindowClientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function GetWindowClientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function GetWindowScrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function GetWindowScrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

//--------------- COVER LAYERS

function ShowConnectionMessage(showValue, useAllScreen)
{
	if (useAllScreen)
	{
		ShowCoverLayer(showValue);
		ShowMessage(showValue);
	}
	else
	{
		ShowConfirmMessage(showValue, 'Estableciendo conexión con servidor...');
	}
}

function ShowCoverLayer(showValue){
	docu	= document.body;
	coscura	= GetElement('iCoverLayer');
	coscura.style.height=docu.scrollHeight+'px';
	if(showValue) 
		coscura.style.visibility = "visible";
	else 
		coscura.style.visibility = "hidden";
}

function ShowMessage(showValue) {
	var tableObj = GetElement("iMessageTable");
	
	var left = ((document.body.clientWidth - tableObj.width) / 2) + GetWindowScrollLeft();
	var top  = ((document.body.clientHeight - tableObj.height) / 2) + GetWindowScrollTop();
		
	objLayer = GetElement("iMessageLayer");	
	objLayer.style.left = parseInt(left);
	objLayer.style.top 	= parseInt(top);
	
	if(showValue) 
		objLayer.style.visibility = "visible";
	else 
		objLayer.style.visibility = "hidden";	
}

function ShowConfirmMessage(showValue, messageStr)
{
	if (messageStr != '')
		GetElement("TopMessageString").innerHTML = messageStr;
	
	if(showValue) 
		GetElement("TopMessageTable").style.display = '';
	else 
		GetElement("TopMessageTable").style.display = 'none';
}

//------------------------- PRELOAD IMAGES
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_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_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];}
}

-->
