function isEmail(cadena)  {
var a = cadena.value;
var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+.[A-Za-z0-9_.]+[A-za-z]{2,4}$/;
	if (a.length == 0 )
	  return true;
	if (filter.test(a))
	  return true;
	else
	  return false;
return false;
}

function isNumeric(e,formObj) {//alert('aqui');	
    var cad=/^([0-9])*$/;
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true; 
    patron = cad;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function isNumericServ(e,id) {
	//validar caracteres que entran
	var temp=document.getElementById('matrix_servicios');
	var arrInputs = temp.getElementsByTagName('input');
	var temp2=document.getElementById('menu_servicios');
	var arrInputs2 = temp2.getElementsByTagName('input');
	var arrMenu = new Array();
	var arrMenuId = new Array();
	var arrMenuBloq = new Array();
	var j=0;
	var st='';
	var numrows=0;
	///ciclo separado para poder controlar que solo inserten valores cuando el menu tiene dichos valores
	for(var i=0; i<arrInputs2.length/3; i++){		  
		  if(arrInputs2[i].getAttribute('type')=='hidden'){		  
			   if(arrInputs2[i].value!=''){
				   arrMenu[j] = arrInputs2[i].id;					   
				   j++;
			   }
		  }
	}
	for(var i=0; i<arrInputs2.length; i++){	
		if(arrInputs2[i].getAttribute('type')=='text'){	
			numrows++;
		}
	}
	//ciclo para definir casos de uso para la validacion generica de cada forma
	var minval=-1;
	var maxval=-1;
	for(var k=1; k<=numrows; k++){
		if(k==1){
			minval= document.getElementById('IdServ'+k).childNodes[0].nodeValue;
			maxval= document.getElementById('IdServ'+k).childNodes[0].nodeValue;
		}else{
			maxval=null;
			maxval= document.getElementById('IdServ'+k).childNodes[0].nodeValue;
		}		
		var SE_id_Servicio=document.getElementById('SE_id_Servicio'+k);
		//alert(SE_id_Servicio.value);
		if((SE_id_Servicio.value!='' && SE_id_Servicio.value!=0) && (document.getElementById('CantServ'+k).value!='')){
			arrMenuId[k-1]=document.getElementById('IdServ'+k).childNodes[0].nodeValue;
		}else{
			arrMenuBloq[k-1]=document.getElementById('IdServ'+k).childNodes[0].nodeValue;
		}
	}
	   tecla = (document.all)?e.keyCode:e.which;
		   var cad=/\D/;   
		   patron = cad;		  
		   te = String.fromCharCode(tecla);
		   //alert('checando matrix arrMenuBloq->'+arrMenuBloq);
		   //alert('checando matrix arrMenuId->'+arrMenuId);
		   if(patron.test(te)==false || id.value<minval || id.value>maxval){//alert('A');
			   if(id.value!=''){ //  alert('B');
				   document.getElementById(id.id).value = "";
				   document.getElementById(id.id).style.backgroundColor = "#FFFFFF";				  
		   	   }
		   }else{//alert('B');
				   //caso de uso cuando no hay valor del menu por lo tanto el id de dicho servicio es invalido
				  /* for(var k=0; k<numrows; k++){
					   if(arrMenuId[k]==id.value){					   
						   actualizaMenuServ();
					   }
					   if(arrMenuBloq[k]==id.value){					   
						   actualizaMenuServ();
					   }
				   }*/ actualizaMenuServ();
			   
		   }	 
}

function isLetter(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true;
    patron = /\D/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function calcularTotal(e,id,precio,numeroregistros) {//alert('si entra');
	if (e == '' || e == 0){
	  document.getElementById(id).value = '';
//////alternativa 1 plano servicios
	  var tempz = document.getElementById('plano_servicios');
	  if(tempz){
		  var z= id.substring(8);
		  document.getElementById('CantServ'+z).value = '';
	  }
	}else{
	 var TotalRows=e*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	  //////alternativa 1 plano servicios
	  var tempz = document.getElementById('plano_servicios');
	  if(tempz){
		  var z= id.substring(8);
		  document.getElementById('CantServ'+z).value = e;
	  }
	}
	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	//alert (numeroregistros);
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
		//alert (temp);
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var IVA = subtotal*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA;
	document.getElementById('BC_Total').value = total.toFixed(2);
	//////llamada a funcion para plano servicios
	var tempz = document.getElementById('plano_servicios');
	  if(tempz){
		  actualizaMenuServ();
	  }
	//var tempserv = 'CantServ'+i
	
}

function calcularTotalPatrocinios(e,id,precio,numeroregistros) {//alert('si entra');
	if (e == '' || e == 0){
	  document.getElementById(id).value = '';
	}else{
	 var TotalRows=e*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}
	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	//alert (numeroregistros);
	for(i=10; i<= 13; i++){
		var temp = 'SE_TotalPatrocinios'+i;
		//alert (temp);
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalPatrocinios').value = subtotal.toFixed(2);
	var IVA = subtotal*0.16;
	document.getElementById('BC_TAXPatrocinios').value = IVA.toFixed(2);
	var total = subtotal+IVA;
	document.getElementById('BC_TotalPatrocinios').value = total.toFixed(2);
}

function changeColor(e,id) {
	//alert(e);
	if(document.getElementById(id).value==''){
		document.getElementById(id).style.backgroundColor = "#FFFFFF";
	}else{
		document.getElementById(id).style.backgroundColor = "#D8D8D8";
	}
	//document.getElementById(id).value = "";
	
	/*switch(e){
		case "0":
			document.getElementById(id).style.backgroundColor = "#F5A9A9";
		break;
		case "1":
			document.getElementById(id).style.backgroundColor = "#F5D0A9";
		break;
		case "2":
			document.getElementById(id).style.backgroundColor = "#F2F5A9";
		break;
		case "3":
			document.getElementById(id).style.backgroundColor = "#D0F5A9";
		break;
		case "4":
			document.getElementById(id).style.backgroundColor = "#A9F5F2";
		break;
		case "5":
			document.getElementById(id).style.backgroundColor = "#A9A9F5";
		break;
		case "6":
			document.getElementById(id).style.backgroundColor = "#F5A9F2";
		break;
		case "7":
			document.getElementById(id).style.backgroundColor = "#D8D8D8";
		break;
		default:
			document.getElementById(id).style.backgroundColor = "#FFFFFF";
			document.getElementById(id).value = "";
	}*/
}

function calcularTotal2(e,id,precio,numeroregistros) {
	var metros = document.getElementById('SE_m2').value;
	if (e == '' || e == 0){
	  document.getElementById(id).value = '';
	}else{
	  var TotalRows=e*precio*metros;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}
	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var IVA = subtotal*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total=subtotal+IVA;
	document.getElementById('BC_Total').value = total.toFixed(2);
}

function calcularTotal3(e,id,precio,numeroregistros) {
	var metros = document.getElementById('SE_Quantify1').value;
	if (e == '' || e == 0){
	  document.getElementById(id).value = '';
	}else{
	  var TotalRows=e*precio*metros;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}
	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var IVA = subtotal*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total =  subtotal+IVA;
	document.getElementById('BC_Total').value = total.toFixed(2);
}
//funcion para calcular el total de citas de cada expositor dependiendo de los agentes
function calcularTotalCitas(e,id) {
	if (e == '' || e == 0)
	  document.getElementById(id).value = '';
	else
	  document.getElementById(id).value = e*21*3;

}
//funci�n para calcular el total de la cantidad dependiendo de las cantidades de cada dia
function calcularCantidad(day1,day2,day3,field,id,precio,numeroregistros) {
	var dia2=document.getElementById(day2).value;
	var dia3=document.getElementById(day3).value;
	if (day1==''){
		day1=0;
	}
	if (dia2==''){
		dia2=0;
	}
	if (dia3==''){
		dia3=0;
	}
		document.getElementById(field).value = parseInt(day1)+parseInt(dia2)+parseInt(dia3);
/////esto es de la funcion de calcularTotal
	//if (e == '' || e == 0)
	if (document.getElementById(field).value == '' || document.getElementById(field).value == 0){
	  document.getElementById(id).value = '';
	}else{
	  var TotalRows = document.getElementById(field).value*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}

	var cont = 0;
	var contAlimentos = 0;
	var contBebidas = 0;
	var contOtros = 0;
	var subtotal = 0;
	var subtotalAlimentos = 0;
	var subtotalBebidas = 0;
	var subtotalOtros = 0;
	var arreglo = new Array();
	var arregloAlimentos = new Array();
	var arregloBebidas = new Array();
	var arregloOtros = new Array();
	//alert (numeroregistros);
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
		//alert (temp);
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  		//para subtotal alimentos
	  		if(i>0 && i<=20){
	  		contAlimentos=contAlimentos+1;
	  		arregloAlimentos[contAlimentos]= document.getElementById(temp).value;
	  		}
	  		if(i>20 && i<=46){
	  			contBebidas=contBebidas+1;
		  		arregloBebidas[contBebidas]= document.getElementById(temp).value;
	  		}
	  		if(i>46){
	  			contOtros=contOtros+1;
		  		arregloOtros[contOtros]= document.getElementById(temp).value;
	  		}
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	for(j=1; j<= contAlimentos; j++){
	  			subtotalAlimentos = parseFloat(subtotalAlimentos) + parseFloat(arregloAlimentos[j]);
	  		}
	for(j=1; j<= contBebidas; j++){
	  			subtotalBebidas = parseFloat(subtotalBebidas) + parseFloat(arregloBebidas[j]);
	  		}
	for(j=1; j<= contOtros; j++){
	  			subtotalOtros = parseFloat(subtotalOtros) + parseFloat(arregloOtros[j]);
	  		}
	document.getElementById('BC_SubtotalAlimentos').value = subtotalAlimentos.toFixed(2);
	document.getElementById('BC_SubtotalBebidas').value = subtotalBebidas.toFixed(2);
	document.getElementById('BC_SubtotalOtros').value = subtotalOtros.toFixed(2);
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var Servicio = subtotal*0.15;
	document.getElementById('BC_Servicio').value = Servicio.toFixed(2);
	var IVA = (subtotal+Servicio)*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA+Servicio;
	document.getElementById('BC_Total').value = total.toFixed(2);
/////

}

//funci�n para calcular el total de la cantidad dependiendo de las cantidades de cada dia para forma D
function calcularCantidad2(day1,day2,day3,field,id,precio,numeroregistros) {
	var dia2=document.getElementById(day2).value;
	var dia3=document.getElementById(day3).value;
	if (day1==''){
		day1=0;
	}
	if (dia2==''){
		dia2=0;
	}
	if (dia3==''){
		dia3=0;
	}
		document.getElementById(field).value = parseInt(day1)+parseInt(dia2)+parseInt(dia3);
/////esto es de la funcion de calcularTotal
	if (document.getElementById(field).value == '' || document.getElementById(field).value == 0){
	  document.getElementById(id).value = '';
	}else{
	  var TotalRows = document.getElementById(field).value*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}

	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}

	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var IVA = subtotal*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA;
	document.getElementById('BC_Total').value = total.toFixed(2);
}

//funci�n para calcular el total de la cantidad dependiendo de las cantidades de cada dia
function calcularCantidad3(day1,day2,day3,field,id,precio,numeroregistros) {
	var dia2=document.getElementById(day2).value;
	var dia3=document.getElementById(day3).value;
	if (day1==''){
		day1=0;
	}
	if (dia2==''){
		dia2=0;
	}
	if (dia3==''){
		dia3=0;
	}
		document.getElementById(field).value = parseInt(day1)+parseInt(dia2)+parseInt(dia3);
/////esto es de la funcion de calcularTotal
	if (document.getElementById(field).value == '' || document.getElementById(field).value == 0){
	  document.getElementById(id).value = '';
	}else{
	  var TotalRows = document.getElementById(field).value*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}

	var cont = 0;
	//var contAlimentos = 0;
	var contBebidas = 0;
	var contOtros = 0;
	var subtotal = 0;
	var subtotalAlimentos = 0;
	var subtotalBebidas = 0;
	var subtotalOtros = 0;
	var arreglo = new Array();
	var arregloAlimentos = new Array();
	var arregloBebidas = new Array();
	var arregloOtros = new Array();
	//alert (numeroregistros);
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
		//alert (temp);
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  		if(i>0 && i<=4){
	  			contBebidas=contBebidas+1;
		  		arregloBebidas[contBebidas]= document.getElementById(temp).value;
	  		}
	  		if(i>4){
	  			contOtros=contOtros+1;
		  		arregloOtros[contOtros]= document.getElementById(temp).value;
	  		}
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	for(j=1; j<= contBebidas; j++){
	  			subtotalBebidas = parseFloat(subtotalBebidas) + parseFloat(arregloBebidas[j]);
	  		}
	for(j=1; j<= contOtros; j++){
	  			subtotalOtros = parseFloat(subtotalOtros) + parseFloat(arregloOtros[j]);
	  		}
	document.getElementById('BC_SubtotalBebidas').value = subtotalBebidas.toFixed(2);
	document.getElementById('BC_SubtotalOtros').value = subtotalOtros.toFixed(2);
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var Servicio = subtotal*0.15;
	document.getElementById('BC_Servicio').value = Servicio.toFixed(2);
	var IVA = (subtotal+Servicio)*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA+Servicio;
	document.getElementById('BC_Total').value = total.toFixed(2);
/////

}

//funci�n para calcular el total de la cantidad dependiendo de las cantidades de cada dia
function calcularCantidad4(day1,day2,day3,field,id,precio,numeroregistros) {
	var dia2=document.getElementById(day2).value;
	var dia3=document.getElementById(day3).value;
	if (day1==''){
		day1=0;
	}
	if (dia2==''){
		dia2=0;
	}
	if (dia3==''){
		dia3=0;
	}
		document.getElementById(field).value = parseInt(day1)+parseInt(dia2)+parseInt(dia3);
/////esto es de la funcion de calcularTotal
	if (document.getElementById(field).value == '' || document.getElementById(field).value == 0){
	  document.getElementById(id).value = '';
	}else{
	   var TotalRows = document.getElementById(field).value*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	}

	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	//alert (numeroregistros);
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
		//alert (temp);
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var Servicio = subtotal*0.15;
	document.getElementById('BC_Servicio').value = Servicio.toFixed(2);
	var IVA = (subtotal+Servicio)*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA+Servicio;
	document.getElementById('BC_Total').value = total.toFixed(2);
/////

}

function calcularTotalO1(e,id,precio,numeroregistros) {//alert('si entra');
	if (e == '' || e == 0){
	  document.getElementById(id).value = '';
//////alternativa 1 plano servicios
	  var tempz = document.getElementById('plano_servicios');
	  if(tempz){
		  var z= id.substring(8);
		  document.getElementById('CantServ'+z).value = '';
	  }
	}else{
	 var TotalRows=e*precio;
	  document.getElementById(id).value = TotalRows.toFixed(2);
	  //////alternativa 1 plano servicios
	  var tempz = document.getElementById('plano_servicios');
	  if(tempz){
		  var z= id.substring(8);
		  document.getElementById('CantServ'+z).value = e;
	  }
	}
	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	//alert (numeroregistros);
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
		//alert (temp);
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var IVA = subtotal*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA;
	document.getElementById('BC_Total').value = total.toFixed(2);
	//////llamada a funcion para plano servicios
	var tempz = document.getElementById('plano_servicios');
	  if(tempz){
		  actualizaMenuServ();
	  }
	//var tempserv = 'CantServ'+i
	
}

//funcion para calcular el total de la cantidad dependiendo de las cantidades de cada dia
function calcularCantidadO2(day1,day2,day3,field,id,precio,precioevento,numeroregistros) {
	var flagprecioevento=1;
	var dia2=document.getElementById(day2).value;
	var dia3=document.getElementById(day3).value;
	if (day1=='' || day1==0){
		day1=0;
		flagprecioevento=0;
	}
	if (dia2=='' || dia2==0){
		dia2=0;
		flagprecioevento=0;
	}
	if (dia3=='' || dia3==0){
		dia3=0;
		flagprecioevento=0;
	}
		document.getElementById(field).value = parseInt(day1)+parseInt(dia2)+parseInt(dia3);
/////esto es de la funcion de calcularTotal
	if (document.getElementById(field).value == '' || document.getElementById(field).value == 0){
	  document.getElementById(id).value = '';
	}else{
		if(flagprecioevento==0){
			var TotalRows = document.getElementById(field).value*precio;
			document.getElementById(id).value = TotalRows.toFixed(2);
		}else{
			//var multiplos = (document.getElementById(field).value/3)|0;///castear int javascript
			//sacamos el numero menor de los 3 dias
			if(day1<dia2){
				if(day1<dia3){
					var diamenor=day1;
				}else{
					var diamenor=dia3;
				}
			}else{
				if(dia2<dia3){
					var diamenor=dia2;
				}else{
					var diamenor=dia3;
				}
			}
			var multiplos=diamenor*3;
			var restantes=(document.getElementById(field).value)-multiplos;
			var Totalmultiplos=diamenor*precioevento;
			var Totalrestantes=restantes*precio;
			var Totalmulrest=Totalmultiplos+Totalrestantes;
			document.getElementById(id).value = Totalmulrest.toFixed(2);
			//document.getElementById(id).value = diamenor;
			//alert('multiplos-> '+multiplos);
		}	  
	}

	var cont = 0;
	var subtotal = 0;
	var arreglo = new Array();
	for(i=1; i<= numeroregistros; i++){
		var temp = 'SE_Total'+i;
	  	if (document.getElementById(temp).value != ''){
	  		cont=cont+1;
	  		arreglo[cont]= document.getElementById(temp).value;	  		
	  	}
	}
	for(j=1; j<= cont; j++){
	  			subtotal = parseFloat(subtotal) + parseFloat(arreglo[j]);
	  		}
	document.getElementById('BC_SubtotalComplete').value = subtotal.toFixed(2);
	var IVA = (subtotal)*0.16;
	document.getElementById('BC_TAX').value = IVA.toFixed(2);
	var total = subtotal+IVA;
	document.getElementById('BC_Total').value = total.toFixed(2);
/////
}


function IsAlpha(str){
  var re = /[^a-zA-Z]/g
  if (re.test(str))
  	return false;
  return true;
}

function isEmpty(str){
  return (str == null) || (str.length == 0);
}

function isAlphaNumeric(str){
  var re = /[^a-zA-Z0-9]/g
  if (re.test(str)) return false;
  return true;
}

function isMatch(str1, str2){
  return str1 == str2;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function postwith (to,p) {
	  var myForm = document.createElement("form");
	  myForm.method="post" ;
	  myForm.action = to ;
	  for (var k in p) {
	    var myInput = document.createElement("input") ;
	    myInput.setAttribute("name", k) ;
	    myInput.setAttribute("value", p[k]);
	    myForm.appendChild(myInput) ;
	  }
	  document.body.appendChild(myForm) ;
	  myForm.submit() ;
	  document.body.removeChild(myForm) ;
}

function valor_pagina(var1){
	 document.body.innerHTML += '<form id="dynForm" action="start.php" method="post"><input type="hidden" name="nextstep" value=2><input type="hidden" name="pantalla" value='+var1+'></form>';
	 document.getElementById("dynForm").submit();
	}

function actualizaMenuServ(){//alert('llega a funcion actualizaMenuServ');
	var temp=document.getElementById('menu_servicios');
	var menuItems = temp.getElementsByTagName('input');
	//var menuItems = temp.getElementsByType('text');
	var temp2=document.getElementById('matrix_servicios');
	var matrixServ = temp2.getElementsByTagName('input');
	//para sacar numero de renglones estandarizados en todos los browsers
	var numrows=0;
	for(var i=0; i<menuItems.length; i++){	
		if(menuItems[i].getAttribute('type')=='text'){	
			numrows++;
		}
	}
	for(var i=1; i<=numrows; i++){				 		  
	   CantServ = document.getElementById('CantServ'+i).value;
	   IdServ = document.getElementById('IdServ'+i).childNodes[0].nodeValue;
	   var cant=0;
	   for(var j=0;j<matrixServ.length;j++){
		   if(matrixServ[j].value==IdServ){
			   cant+=1;
			   //alert(cant);
			   if(cant>CantServ){
				   matrixServ[j].value='';
				   document.getElementById(matrixServ[j].id).style.backgroundColor = "#FFFFFF";	
			   }
		   } 
	   }
	}	
}

function titleonoff(flag){
	if(flag){
		document.form.DSE_NombreEmpresa.readOnly = false;
	}
	else{
		document.form.DSE_NombreEmpresa.value = "";
		document.form.DSE_NombreEmpresa.readOnly = true;
	}
}

function enabledisablecs(){
	if(document.form.DI_Opcion4.checked == false){
		document.form.DI_Cantidad.readOnly = true;
		document.form.DI_Cantidad.value="";
		document.form.DI_Nombre.readOnly = true;
		document.form.DI_Nombre.value="";
		document.form.DI_Empresa.readOnly = true;
		document.form.DI_Empresa.value="";
		document.form.DI_Direccion.readOnly = true;
		document.form.DI_Direccion.value=""
		document.form.DI_Colonia.readOnly = true;
		document.form.DI_Colonia.value="";
		document.form.DI_Ciudad.readOnly = true;
		document.form.DI_Ciudad.value="";
		document.form.DI_Estado.readOnly = true;
		document.form.DI_Estado.value="";
		document.form.DI_Pais.readOnly = true;
		document.form.DI_Pais.value="";
		document.form.DI_CP.readOnly = true;
		document.form.DI_CP.value="";
		document.form.DI_Lada.readOnly = true;
		document.form.DI_Lada.value="";
		document.form.DI_Tel.readOnly = true;
		document.form.DI_Tel.value="";
		document.form.DI_Fax.readOnly = true;
		document.form.DI_Fax.value="";
		document.form.DI_Email.readOnly = true;
		document.form.DI_Email.value="";
	}else{
		document.form.DI_Cantidad.readOnly = false;
		document.form.DI_Cantidad.value="";
		document.form.DI_Nombre.readOnly = false;
		document.form.DI_Nombre.value="";
		document.form.DI_Empresa.readOnly = false;
		document.form.DI_Empresa.value="";
		document.form.DI_Direccion.readOnly = false;
		document.form.DI_Direccion.value="";
		document.form.DI_Colonia.readOnly = false;
		document.form.DI_Colonia.value="";
		document.form.DI_Ciudad.readOnly = false;
		document.form.DI_Ciudad.value="";
		document.form.DI_Estado.readOnly = false;
		document.form.DI_Estado.value="";
		document.form.DI_Pais.readOnly = false;
		document.form.DI_Pais.value="";
		document.form.DI_CP.readOnly = false;
		document.form.DI_CP.value="";
		document.form.DI_Lada.readOnly = false;
		document.form.DI_Lada.value="";
		document.form.DI_Tel.readOnly = false;
		document.form.DI_Tel.value="";
		document.form.DI_Fax.readOnly = false;
		document.form.DI_Fax.value="";
		document.form.DI_Email.readOnly = false;
		document.form.DI_Email.value="";
	}
}

function enabledisablecs2(){
	if(document.form.DI_Opcion5.checked != true){
		document.form.DID_Cantidad.readOnly = true;
		document.form.DID_Nombre.readOnly = true;
		document.form.DID_Empresa.readOnly = true;
		document.form.DID_Direccion.readOnly = true;
		document.form.DID_Colonia.readOnly = true;
		document.form.DID_Ciudad.readOnly = true;
		document.form.DID_Estado.readOnly = true;
		document.form.DID_Pais.readOnly = true;
		document.form.DID_CP.readOnly = true;
		document.form.DID_Lada.readOnly = true;
		document.form.DID_Tel.readOnly = true;
		document.form.DID_Fax.readOnly = true;
		document.form.DID_Email.readOnly = true;
		///////////
		document.form.DID_Cantidad.value = '';
		document.form.DID_Nombre.value = '';
		document.form.DID_Empresa.value = '';
		document.form.DID_Direccion.value = '';
		document.form.DID_Colonia.value = '';
		document.form.DID_Ciudad.value = '';
		document.form.DID_Estado.value = '';
		document.form.DID_Pais.value = '';
		document.form.DID_CP.value = '';
		document.form.DID_Lada.value = '';
		document.form.DID_Tel.value = '';
		document.form.DID_Fax.value = '';
		document.form.DID_Email.value = '';
		
	}else{
		document.form.DID_Cantidad.readOnly = false;
		document.form.DID_Nombre.readOnly = false;
		document.form.DID_Empresa.readOnly = false;
		document.form.DID_Direccion.readOnly = false;
		document.form.DID_Colonia.readOnly = false;
		document.form.DID_Ciudad.readOnly = false;
		document.form.DID_Estado.readOnly = false;
		document.form.DID_Pais.readOnly = false;
		document.form.DID_CP.readOnly = false;
		document.form.DID_Lada.readOnly = false;
		document.form.DID_Tel.readOnly = false;
		document.form.DID_Fax.readOnly = false;
		document.form.DID_Email.readOnly = false;
	}
}

function toCount(entrance,exit,text,characters) {
	  var entranceObj=getObject(entrance);
	  var exitObj=getObject(exit);
	  var length=characters - entranceObj.value.length;
	  if(length <= 0) {
	    length=0;
	    text='<span class="disable"> '+text+' </span>';
	    entranceObj.value=entranceObj.value.substr(0,characters);
	  }
	  exitObj.innerHTML = text.replace("{CHAR}",length);
	}

function DesignSelected(idservicio,clave,precio){
	//alert("clave->"+clave+" __precio->"+precio);
	document.form.SE_id_Servicio.value = idservicio;
	document.form.SE_Clave.value = clave;
	document.form.SE_Precio.value = precio;
	
	document.form.SE_Total.value = precio;
	document.form.EF_Subtotal.value = precio;
	document.form.EF_IVA.value = precio*0.16;
	document.form.EF_Total.value = precio+(precio*0.16);
	
}

