<!--
//replace line breeaks for whitespaces in Query Textfield
function encodito(texte){
	var Resultat=""
	for (i=0;i<texte.length;i++)
	{
		numer=texte.charCodeAt(i);
		if((numer==13)&&(texte.charCodeAt(i+1)==10))
		{
			i++;
			Resultat += '<br>';
		}
		else
			Resultat += String.fromCharCode(numer);
	}
	return Resultat;
}

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_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];}
}

//Get Element (Object) found by its ID
function tamsa_getElementById(tagId) 
{
	var obj = document.all[tagId];
	if(obj && obj.length && obj[0].id==tagId)
		obj=obj[0];
	return obj;
}

function AllowObjectsRun()
{
	var theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
	theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

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 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 OpenModalWindow(target,width,height){
	window.showModalDialog( target, "dialogHeight:"+height+"px;dialogWidth:"+width+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
}

//format digit to two decimals. Imput string
function formatDecimals(inputData)
{
	if(inputData.indexOf('.',0)!=-1)
	{
		var decimals = inputData.split('.')[1];
		if(decimals && decimals.length==1)
			inputData = inputData+ '0';
	}
	else
		inputData = inputData + '.00';
		
return inputData;
}



function switchRowColor(objectID, highlightcolor)
{
		var object = document.getElementById(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 = document.getElementById(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(event,DataType){
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)
function onKeyDown(event, element){
	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.formatamsa.costo_'+RowId+'.value = price');
		}
		else
		{
			eval('document.formatamsa.costo_'+RowId+'.value = \'inválido\'');
			eval('document.formatamsa.costo_'+RowId+'.select()');
		}
}


function tamsa_getArticlePrice(ArticleCode, RowId){
		//var itemCost = eval('document.formatamsa.costo_'+RowId+'.value');
		
		if (ArticleCode.length==0)
			return;
		if (PriceList[ArticleCode])
		{
			eval('document.formatamsa.costo_'+RowId+'.value = PriceList[ArticleCode]');
		}
		else
		{
			eval('document.formatamsa.costo_'+RowId+'.value = \'inválido\'');
			eval('document.formatamsa.costo_'+RowId+'.select()');
		}
		
		var article_description = document.getElementById('article_description_'+RowId);
		if(article_description)
			if(ArticleList && ArticleList[ArticleCode])
				article_description.innerHTML = ArticleList[ArticleCode];
			else
				article_description.innerHTML = 'Artículo no encontrado';
}


function RestrictUserInput(elem) {
    if (/[^\d]/g.test(elem.value))
       elem.value = elem.value.replace(/[^\d]/g, '');
}


//-------------- 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))
		event.keyCode = 0;	
}

//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(',','');
}
//------------Functions

function Navigate(Module){
eval("document.location='" + Module + "'");
}


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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una dirección de email válida.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- La casilla '+nm+' debe contener sólo valores numéricos.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- Llenar la casilla '+nm+'.\n'; }
  } if (errors) alert('Favor de corregir los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='remisiones.asp?action=chgamount&newval="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// MENU FUNCTIONS

var wait = 500;
var hideTimer;

function keepOpen(){
	if (hideTimer != null)
		clearTimeout(hideTimer);
}

function hide(){
	hideTimer = setTimeout("hideAll()", wait);
}

function hideAll()
{
	var i;
	for (i=1; i<=4; i++)
	{
		document.all['menuItem'+i].style.visibility = "hidden";
	}
}

function showMenu(menuItem,show,x,y){
	for(var i=1; i<=4;i++)
	{
		menuString = 'menuItem' + i.toString();
		if(menuString != menuItem)
			document.all[menuString].style.visibility = "hidden";
	}
	if (show)
	{
		document.all[menuItem].style.top = y.toString() + 'px';
		document.all[menuItem].style.left = x.toString() + 'px';
		document.all[menuItem].style.visibility = "visible";
	}
	else
		document.all[menuItem].style.visibility = "hidden";
}


function tamsa_insertRow(tableID){
	var table = document.getElementById(tableID);
	var row=document.createElement("tr");
		
	var rows=table.rows;
	var lastRow,lrObj;
	if(rows.length>0)
		lastRow=rows[rows.length-1];
	rowIndex = rows.length;

		var bgcolor = rows[rows.length-2].style.backgroundColor;
		row.style.backgroundColor = bgcolor;
		
		row.id = 'row_'+rowIndex.toString();
		
		var cell=document.createElement("td");
		cell.style.textAlign="center";
		cell.innerHTML="<input onKeyDown=\"onKeyDown(event, this)\" onKeyPress=\"onKeyPress(event,1)\" name=\"cantidad_"+rowIndex+"\" type=\"text\" class=\"forma\" id=\"cantidad_"+rowIndex+"\" size=\"5\" maxlength=\"4\">";
		row.appendChild(cell);
		
		var cell2=document.createElement("td");
		cell2.style.textAlign="center";
		cell2.innerHTML = "<input onKeyDown=\"onKeyDown(event, this)\" onKeyPress=\"onKeyPress(event,1)\" onBlur=\"tamsa_getArticlePrice(this.value, '"+rowIndex+"')\" name=\"codigo_"+rowIndex+"\" type=\"text\" class=\"forma\" id=\"codigo_"+rowIndex+"\" size=\"9\" maxlength=\"7\">";
		row.appendChild(cell2);
		
		var cell3=document.createElement("td");
		cell3.style.textAlign="center";
		cell3.className = "negro";
		cell3.innerHTML = "$ <input class=\"forma\" onKeyDown=\"onKeyDown(event, this)\" onKeyPress=\"onKeyPress(event,3)\" name=\"costo_"+rowIndex+"\" type=\"text\" id=\"costo_"+rowIndex+"\" size=\"12\" maxlength=\"10\" style=\"text-align:right\">";
		row.appendChild(cell3);
		
		var cell4=document.createElement("td");
		cell4.style.textAlign="left";
		cell4.style.overflow = "hidden";
		cell4.style.textOverflow = "ellipsis";
		cell4.innerHTML = "<NOBR class=\"negro_small\"><span id=\"article_description_"+rowIndex.toString()+"\">&nbsp;</span></NOBR>";
		row.appendChild(cell4);		
		
		table.tBodies[0].appendChild(row);
}


-->

