// Title: Tigra Form Validator
// URL: http://www.softcomplex.com/products/tigra_form_validator/
// Version: 1.3
// Date: 08/25/2005 (mm/dd/yyyy)
// Notes: This script is free. Visit official site for further details.
// Modificated & Cuztomizated By Ricardo Ramírez Muñoz(rickaramirez@gmail.com)
// Date: 08/04/2006 (dd/mm/yyyy)
// regular expressions or function to validate the format
var re_dt = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/,
re_tm = /^(\d{1,2})\:(\d{1,2})\s(\am|\AM|\pm|\PM)$/,
re_tm2 = /^(\d{1,2})\:(\d{1,2})$/,
re_tm3 = /^(\d{1,2})\:(\d{1,2})\:(\d{1,2})$/,
re_dttm =/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s(\d{1,2})\:(\d{1,2})\s(\am|\AM|\pm|\PM)$/,
a_formats = {
	'company'	 : /^[áéíóúÁÉÍÓÚÑñ\s\w\-.,\/]*$/,
	'countrystatecity': /^[.áéíóúÁÉÍÓÚÑñ\s\a-zA-Z]*$/,
	'adress'     : /^[-.#áéíóúÁÉÍÓÚÑñ\s\w]*$/,
	'www'      	 : /^[\w\-._\/]*$/,
	'alpha'   	 : /^[a-zA-Z\s]*$/,
	'alphamx'  	 : /^[áéíóúÁÉÍÓÚÑñ\s\a-zA-Z\.]*$/,
	'alphanum'   : /^[s\w]*$/,
	'alphanummx' : /^[áéíóúÁÉÍÓÚÑñ\s\w\.:-]*$/,
	'fbxorders'  : /^[\,\w]*$/,
	'alphanumext': /^[\-\w]+$/,
	'coment'     : /^[\-\w\Ñ\ñ\s]+$/,
	'unsigned'   : /^\d+$/,
	'integer'    : /^[\+\-]?\d*$/,
	'real+-'     : /^[\+\-]?\d*\.?\d*$/,
	'real'       : /^\d*\.?\d*$/,
	'email'      : /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/,
	'phone'      : /^[\d\.\s\-()\a-zA-Z]+$/,
	'phonenum'   : /^[\d\-()]+$/,
	'phonenextel'   : /^[\d\-()*]+$/,
	'service'     : function (serv) {
		// check format mm/dd/yyyy
		if (serv!= null && serv!='0.00'){
			return true;
		}else{
			return false;
		}		
	},
	'dateUS'     : function (s_date) {
		// check format mm/dd/yyyy
		if (!re_dt.test(s_date))
			return false;
		// check allowed ranges
		if (RegExp.$1 > 12 || RegExp.$2 > 31)
			return false;
		// check number of day in month
		var dt_test = new Date(RegExp.$3, Number(RegExp.$1-1), RegExp.$2);
		if (dt_test.getMonth() != Number(RegExp.$1-1))
			return false;
		return true;
	},
	'dateMX'     : function (s_date) {
		// check format dd/mm/yyyy
		if (!re_dt.test(s_date))
			return false;
		// check allowed ranges
		if (RegExp.$1 > 31 || RegExp.$2 > 12)
			return false;
		// check number of day in month
		var dt_test = new Date(RegExp.$3, Number(RegExp.$2-1), RegExp.$1);
		if (dt_test.getMonth() != Number(RegExp.$2-1))
			return false;
		return true;
	},
	'time'    : function (s_time) {
		// check format hh:mm (am||pm||AM||PM) time 12H
		if (!re_tm.test(s_time))
			return false;
		// check allowed ranges
		if (RegExp.$1 > 12 || RegExp.$1 > 59 || RegExp.$2 > 59)
			return false;
		return true;
	},
	'time2'    : function (s_time2) {
		// check format hh:mm time 24H
		if (!re_tm2.test(s_time2))
			return false;
		// check allowed ranges
		if (RegExp.$1 > 23 || RegExp.$2 > 59)
			return false;
		return true;
	},
	'time3'    : function (s_time3) {
		// check format hh:mm:ss time 24H
		if (!re_tm3.test(s_time3))
			return false;
		// check allowed ranges
		if (RegExp.$1 > 23 || RegExp.$2 > 59 || RegExp.$3 > 59)
			return false;
		return true;
	},
	'datetimeMX' : function (s_datetime) {
		// check format dd/mm/yyyy hh:mm [am||pm||AM||PM] time 12H
		if (!re_dttm.test(s_datetime))
			return false;
		// check allowed ranges	for date
		if (RegExp.$1 > 31 || RegExp.$2 > 12)
			return false;
		// check number of day in month
		var dt_test = new Date(RegExp.$3, Number(RegExp.$2-1), RegExp.$1);
		if (dt_test.getMonth() != Number(RegExp.$2-1))
			return false;
		// check allowed ranges	for time
		if (RegExp.$4 > 12 || RegExp.$4 < 1 || RegExp.$5 > 59)
			return false;
		return true;
	}
},
a_messages_es = [
	'No form name passed to validator construction routine',
	'No array of "%form%" form fields passed to validator construction routine',
	'Form "%form%" can not be found in this document',
	'Incomplete "%n%" form field descriptor entry. "l" attribute is missing',
	'Can not find form field "%n%" in the form "%form%"',
	'Can not find label tag (id="%t%")',
	'Can not verify match. Field "%m%" was not found',
	'"%l%" es un dato requerido',
	'El valor para "%l%" debe ser de %mn% caracteres o mas',
	'El valor para "%l%" no debe ser mas largo de %mx% caracteres',
	'"%v%" no es un valor valido para "%l%"',
	'"%l%" debe ser igual a "%ml%"'
],
a_messages_en = [
	'No form name passed to validator construction routine',
	'No array of "%form%" form fields passed to validator construction routine',
	'Form "%form%" can not be found in this document',
	'Incomplete "%n%" form field descriptor entry. "l" attribute is missing',
	'Can not find form field "%n%" in the form "%form%"',
	'Can not find label tag (id="%t%")',
	'Can not verify match. Field "%m%" was not found',
	'"%l%" is a required field',
	'Value for "%l%" must be %mn% characters or more',
	'Value for "%l%" must be no longer than %mx% characters',
	'"%v%" is not valid value for "%l%"',
	'"%l%" must match "%ml%"'
]

// validator counstruction routine
function validator(s_form, a_fields, o_cfg, lang) {
	if (lang=='en'){
		this.a_messages=a_messages_en;
	}
	else{
		this.a_messages=a_messages_es;
	}
	this.f_error = validator_error;
	this.f_alert = o_cfg && o_cfg.alert
		? function(s_msg) { alert(s_msg); return false }
		: function() { return false };

	// check required parameters
	if (!s_form)
		return this.f_alert(this.f_error(0));
	this.s_form = s_form;

	if (!a_fields || typeof(a_fields) != 'object')
		return this.f_alert(this.f_error(1));
	this.a_fields = a_fields;

	this.a_2disable = o_cfg && o_cfg['to_disable'] && typeof(o_cfg['to_disable']) == 'object'
		? o_cfg['to_disable']
		: [];

	this.exec = validator_exec;
}

// validator execution method
function validator_exec() {
	var o_form = document.forms[this.s_form];
	if (!o_form)
		return this.f_alert(this.f_error(2));

	b_dom = document.body && document.body.innerHTML;

	// check integrity of the form fields description structure
	for (var n_key in this.a_fields) {
		// check input description entry
		this.a_fields[n_key]['n'] = n_key;
		if (!this.a_fields[n_key]['l'])
			return this.f_alert(this.f_error(3, this.a_fields[n_key]));
		o_input = o_form.elements[n_key];
		if (!o_input)
			return this.f_alert(this.f_error(4, this.a_fields[n_key]));
		this.a_fields[n_key].o_input = o_input;
	}

	// reset labels highlight
	if (b_dom)
		for (var n_key in this.a_fields)
			if (this.a_fields[n_key]['t']) {
				var s_labeltag = this.a_fields[n_key]['t'], e_labeltag = get_element(s_labeltag);
				if (!e_labeltag)
					return this.f_alert(this.f_error(5, this.a_fields[n_key]));
				this.a_fields[n_key].o_tag = e_labeltag;

				// normal state parameters assigned here
				e_labeltag.className = 'tfvNormal';
			}

	// collect values depending on the type of the input
	for (var n_key in this.a_fields) {
		var s_value = '';
		o_input = this.a_fields[n_key].o_input;
		if (o_input.type == 'checkbox') // checkbox
			s_value = o_input.checked ? o_input.value : '';
		else if (o_input.value) // text, password, hidden
			s_value = o_input.value;
		else if (o_input.options) // select
			s_value = o_input.selectedIndex > -1
				? o_input.options[o_input.selectedIndex].value
				: null;
		else if (o_input.length > 0) // radiobuton
			for (var n_index = 0; n_index < o_input.length; n_index++)
				if (o_input[n_index].checked) {
					s_value = o_input[n_index].value;
					break;
				}
		this.a_fields[n_key]['v'] = s_value.replace(/(^\s+)|(\s+$)/g, '');
	}

	// check for errors
	var n_errors_count = 0,
		n_another, o_format_check;
	for (var n_key in this.a_fields) {
		o_format_check = this.a_fields[n_key]['f'] && a_formats[this.a_fields[n_key]['f']]
			? a_formats[this.a_fields[n_key]['f']]
			: null;

		// reset previous error if any
		this.a_fields[n_key].n_error = null;

		// check reqired fields
		if (this.a_fields[n_key]['r'] && !this.a_fields[n_key]['v']) {
			this.a_fields[n_key].n_error = 1;
			n_errors_count++;
		}
		// check length
		else if (this.a_fields[n_key]['mn'] && this.a_fields[n_key]['v'] != '' && String(this.a_fields[n_key]['v']).length < this.a_fields[n_key]['mn']) {
			this.a_fields[n_key].n_error = 2;
			n_errors_count++;
		}
		else if (this.a_fields[n_key]['mx'] && String(this.a_fields[n_key]['v']).length > this.a_fields[n_key]['mx']) {
			this.a_fields[n_key].n_error = 3;
			n_errors_count++;
		}
		// check format
		else if (this.a_fields[n_key]['v'] && this.a_fields[n_key]['f'] && (
			(typeof(o_format_check) == 'function'
			&& !o_format_check(this.a_fields[n_key]['v']))
			|| (typeof(o_format_check) != 'function'
			&& !o_format_check.test(this.a_fields[n_key]['v'])))
			) {
			this.a_fields[n_key].n_error = 4;
			n_errors_count++;
		}
		// check match
		else if (this.a_fields[n_key]['m']) {
			for (var n_key2 in this.a_fields)
				if (n_key2 == this.a_fields[n_key]['m']) {
					n_another = n_key2;
					break;
				}
			if (n_another == null)
				return this.f_alert(this.f_error(6, this.a_fields[n_key]));
			if (this.a_fields[n_another]['v'] != this.a_fields[n_key]['v']) {
				this.a_fields[n_key]['ml'] = this.a_fields[n_another]['l'];
				this.a_fields[n_key].n_error = 5;
				n_errors_count++;
			}
		}

	}

	// collect error messages and highlight captions for errorneous fields
	var s_alert_message = '',
		e_first_error;

	if (n_errors_count) {
		for (var n_key in this.a_fields) {
			var n_error_type = this.a_fields[n_key].n_error,
				s_message = '';

			if (n_error_type)
				s_message = this.f_error(n_error_type + 6, this.a_fields[n_key]);

			if (s_message) {
				if (!e_first_error)
					e_first_error = o_form.elements[n_key];
				s_alert_message += s_message + "\n";
				// highlighted state parameters assigned here
				if (b_dom && this.a_fields[n_key].o_tag)
					this.a_fields[n_key].o_tag.className = 'tfvHighlight';
			}
		}
		alert(s_alert_message);
		// set focus to first errorneous field
		if (e_first_error.focus && e_first_error.type != 'hidden'  && !e_first_error.disabled)
			eval("e_first_error.focus()");
		// cancel form submission if errors detected
		return false;
	}

	for (n_key in this.a_2disable)
		if (o_form.elements[this.a_2disable[n_key]])
			o_form.elements[this.a_2disable[n_key]].disabled = true;

	return true;
}

function validator_error(n_index) {
	var s_ = this.a_messages[n_index], n_i = 1, s_key;
	for (; n_i < arguments.length; n_i ++)
		for (s_key in arguments[n_i])
			s_ = s_.replace('%' + s_key + '%', arguments[n_i][s_key]);
	s_ = s_.replace('%form%', this.s_form);
	return s_
}

function get_element (s_id) {
	return (document.all ? document.all[s_id] : (document.getElementById ? document.getElementById(s_id) : null));
}

/*****************************VALIDA LA FORMA DE SOLICITUD DE ALIMENTOS***********************************************/
/******************************modificacion*******************************************************************************/
//onkeypress="return isNumeric(event)"
function isNumeric2(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true;
    patron = /\d/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function val(forma)
{
var valor = forma.flag.value;
var valor2 = forma.flag2.value;
 //alert(forma.E_Nombre.value);
 if(forma.E_Nombre.value=='')
 {alert('"Nombre del Encargado" es un dato requerido');
  document.getElementById('t_E_Nombre').className = 'tfvHighlight';
  forma.E_Nombre.focus();
  return false;
 }else{document.getElementById('t_E_Nombre').className = 'tfvNormal';}
 //E_Puesto.E_Comercial.E_Stand
 if(forma.E_Puesto.value=='')
 {alert('"Puesto" es un dato requerido');
  document.getElementById('t_E_Puesto').className = 'tfvHighlight';
  forma.E_Puesto.focus();
  return false;
 }else{document.getElementById('t_E_Puesto').className = 'tfvNormal';}
 if(forma.E_Stand.value=='')
 {alert('"No. de Stand" es un dato requerido');
  document.getElementById('t_E_Stand').className = 'tfvHighlight';
  forma.E_Stand.focus();
  return false;
 }else{document.getElementById('t_E_Stand').className = 'tfvNormal';}
 if(forma.E_Comercial.value=='')
 {alert('"Nombre Comercial" es un dato requerido');
  document.getElementById('t_E_Comercial').className = 'tfvHighlight';
  forma.E_Comercial.focus();
  return false;
 }else{document.getElementById('t_E_Comercial').className = 'tfvNormal';}
 if(valor==0)
 {alert("No se a realizado compra");
//  forma.E_Comercial.focus();
  return false;
 }
//if(document.getElementById("cantidad_2"))
//{
// alert("existe");
// alert("valor2: "+valor2);
//}
//   alert("valor: "+valor);
  for (i=1;i<=valor2;i++)
	 {
	  //alert(document.getElementById("cantidad_"+i).value);
	  if(document.getElementById("tr_"+i)&&document.getElementById("cantidad_"+i))
	  {
       if(document.getElementById("cantidad_"+i).value=="")
       {
	    alert("Falta Cantidad en Fila ");
	 		document.form.submit.disabled = false;
			document.getElementById("cantidad_"+i).focus();
			document.getElementById("tr_"+i).style.backgroundColor = "#DB261D";
			return false
       }
       else
       {
        document.getElementById("tr_"+i).style.backgroundColor = "#FFFFFF";
       }
      }
     }

 return true;
}

/***************************************************************************************************************/
/***************************************************************************************************************/
function cargaTable(cat,opc,price,id){
//modificacion

if(opc==0)
{
var valor;
var flag;
var flag2;

	flag = document.getElementById("flag").value;
	flag2 = document.getElementById("flag2").value;
 if(flag==0)
 {
  document.getElementById("flag").value = 1;
  document.getElementById("flag2").value= 1;
  flag  = document.getElementById("flag").value;
  flag2 = document.getElementById("flag2").value;
  var temp='<select id="select_'+flag2+'" name="select_'+flag2+'"><option value="1" id="option_'+flag2+'">1</option><option value="2" id="option_'+flag2+'">2</option><option value="3" id="option_'+flag2+'">3</option><option value="4" id="option_'+flag2+'">4</option><option value="5" id="option_'+flag2+'">5</option><option value="6" id="option_'+flag2+'">6</option><option value="7" id="option_'+flag2+'">7</option><option value="8" id="option_'+flag2+'">8</option><option value="9" id="option_'+flag2+'">9</option><option value="10" id="option_'+flag2+'">10</option><option value="11" id="option_'+flag2+'">11</option><option value="12" id="option_'+flag2+'">12</option><option value="13" id="option_'+flag2+'">13</option><option value="14" id="option_'+flag2+'">14</option><option value="15" id="option_'+flag2+'">15</option><option value="16" id="option_'+flag2+'">16</option><option value="17" id="option_'+flag2+'">17</option><option value="18" id="option_'+flag2+'">18</option><option value="19" id="option_'+flag2+'">19</option><option value="20" id="option_'+flag2+'">20</option><option value="21" id="option_'+flag2+'">21</option><option value="22" id="option_'+flag2+'">22</option><option value="23" id="option_'+flag2+'">23</option><option value="24" id="option_'+flag2+'">24</option><option value="25" id="option_'+flag2+'">25</option><option value="26" id="option_'+flag2+'">26</option><option value="27" id="option_'+flag2+'">27</option><option value="28" id="option_'+flag2+'">28</option><option value="29" id="option_'+flag2+'">29</option><option value="30" id="option_'+flag2+'">30</option><option value="31" id="option_'+flag2+'">31</option></select> ';
 // alert(flag);
	obDiv = document.getElementById("thirdParty");
	document.getElementById("thirdfeature").innerHTML="<b>Para realizar una compra adicional vuelva a dar click al carrito de compra</b>";
	obDiv.innerHTML="";
	obTab = document.createElement("table");
	obDiv.appendChild(obTab);
	obTab.cellspacing="0";
	obTab.border="1";
	obTab.bordercolor="#000000";
	obTab.width="100%";
    obTab.id="tableThird";


    /**********************************Servicio de alimentos*****************************************************************************/
	var tr = obTab.insertRow(-1);
	var td = document.createElement("td");
	td.align="center";
	td.width="15%";
	td.innerHTML="Servicio de alimentos y/o bebidas";
	tr.appendChild(td);
    /**********************************Cantidad*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
	td.width="5%";
	td.innerHTML="Cantidad";
	tr.appendChild(td);
    /**********************************Fecha de entrega*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
	td.width="20%";
	td.innerHTML="Fecha de entrega";
	tr.appendChild(td);
    /**********************************Hora de entrega*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
	//td.id="correo";
	//td.name="correo";
	td.width="15%";
	td.innerHTML="Hora de Entrega";
	tr.appendChild(td);
    /**********************************Costo*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
	td.width="7%";
	td.innerHTML="Costo";
	tr.appendChild(td);

    /**********************************Borrar*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
	td.width="5%";
	td.innerHTML="Borrar";
	tr.appendChild(td);
/***********************************primera impresion******************************************************************/
/***********************************************************************************************************************/
/**********************************Servicio de alimentos*****************************************************************************/
	var tr = obTab.insertRow(-1);
  	tr.id="tr_"+flag2;
 	tr.name="tr_"+flag2;

 	var td = document.createElement("td");
	td.align="center";
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.width="25%";
	td.innerHTML=''+cat+'<input type="hidden" id="id_'+flag2+'" name="id_'+flag2+'" value="'+id+'" />';
	tr.appendChild(td);
    /**********************************Cantidad*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="5%";
	td.innerHTML='<input id="cantidad_'+flag2+'" maxlength="3"   name="cantidad_'+flag2+'"   size="3" width="15%" type="text" onkeypress="return isNumeric2(event)"  onchange="javascript:this.value=this.value.toUpperCase();" >';
	tr.appendChild(td);
    /**********************************Fecha de entrega*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="20%";
	td.innerHTML=''+temp+'/ '+month(flag2)+' / 2009';
	//td.innerHTML='<div width="2px" id="div_'+flag2+'"><select></select></div> / '+month(flag2)+' / 2009 ';	tr.appendChild(td);
	tr.appendChild(td);
    /**********************************Hora de entrega*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.width="20%";
	td.innerHTML=""+hour(flag2)+' : '+min(flag2)+" / "+ampm(flag2);
	tr.appendChild(td);
    /**********************************Costo*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="5%";
	td.innerHTML="$ "+price+".00";
	tr.appendChild(td);

    /**********************************Borrar*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="5%";
	td.innerHTML='<IMG SRC="./img/incomplete.gif" onclick="cargaTable(this.value,'+flag2+')">';
	tr.appendChild(td);

	//flag2=1;//se encarga de llevar el indice de los renglones para evitar el problema de ya no poder borrar renglones
/***********************************************************************************************************************/
/***********************************************************************************************************************/
 }
 else
 {

/***********************************siguientes impresiones******************************************************************/
/***********************************************************************************************************************/
/**********************************Servicio de alimentos*****************************************************************************/
   flag++;
   flag2++;
	var temp='<select id="select_'+flag2+'" name="select_'+flag2+'"><option value="1" id="option_'+flag2+'">1</option><option value="2" id="option_'+flag2+'">2</option><option value="3" id="option_'+flag2+'">3</option><option value="4" id="option_'+flag2+'">4</option><option value="5" id="option_'+flag2+'">5</option><option value="6" id="option_'+flag2+'">6</option><option value="7" id="option_'+flag2+'">7</option><option value="8" id="option_'+flag2+'">8</option><option value="9" id="option_'+flag2+'">9</option><option value="10" id="option_'+flag2+'">10</option><option value="11" id="option_'+flag2+'">11</option><option value="12" id="option_'+flag2+'">12</option><option value="13" id="option_'+flag2+'">13</option><option value="14" id="option_'+flag2+'">14</option><option value="15" id="option_'+flag2+'">15</option><option value="16" id="option_'+flag2+'">16</option><option value="17" id="option_'+flag2+'">17</option><option value="18" id="option_'+flag2+'">18</option><option value="19" id="option_'+flag2+'">19</option><option value="20" id="option_'+flag2+'">20</option><option value="21" id="option_'+flag2+'">21</option><option value="22" id="option_'+flag2+'">22</option><option value="23" id="option_'+flag2+'">23</option><option value="24" id="option_'+flag2+'">24</option><option value="25" id="option_'+flag2+'">25</option><option value="26" id="option_'+flag2+'">26</option><option value="27" id="option_'+flag2+'">27</option><option value="28" id="option_'+flag2+'">28</option><option value="29" id="option_'+flag2+'">29</option><option value="30" id="option_'+flag2+'">30</option><option value="31" id="option_'+flag2+'">31</option></select> ';
   document.getElementById("flag").value=flag;
   document.getElementById("flag2").value=flag2;
	//alert(flag);
	//alert(flag2);
	var tr = obTab.insertRow(-1);
  	tr.id="tr_"+flag2;
 	tr.name="tr_"+flag2;

	var td = document.createElement("td");
	td.align="center";
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.width="25%";
	td.innerHTML=''+cat+'<input type="hidden" id="id_'+flag2+'" name="id_'+flag2+'" value="'+id+'" />';
	tr.appendChild(td);
    /**********************************Cantidad*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="5%";
	td.innerHTML='<input id="cantidad_'+flag2+'" maxlength="3"   name="cantidad_'+flag2+'"   size="3" width="15%" type="text"  onkeypress="return isNumeric2(event)"  onchange="javascript:this.value=this.value.toUpperCase();" >';
	tr.appendChild(td);
    /**********************************Fecha de entrega*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="20%";
	td.innerHTML=''+temp+'/ '+month(flag2)+' / 2009';
	tr.appendChild(td);
    /**********************************Hora de entrega*****************************************************************************/
	var td = document.createElement("td");
	td.align="center";
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.width="20%";
	td.innerHTML=""+hour(flag2)+' : '+min(flag2)+" / "+ampm(flag2);
//	td.innerHTML='<input id="name_'+flag2+'"   name="name_'+flag2+'"   size="20" width="15%" type="text"   onchange="javascript:this.value=this.value.toUpperCase();" >';
	tr.appendChild(td);
    /**********************************Costo*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="5%";
	td.innerHTML="$ "+price+".00";
	tr.appendChild(td);

    /**********************************Borrar*****************************************************************************/
	var td = document.createElement("td");
  	td.id="td_"+flag2;
  	td.name="td_"+flag2;
	td.align="center";
	td.width="5%";
	td.innerHTML='<IMG SRC="./img/incomplete.gif" onclick="cargaTable(this.value,'+flag2+')">';
	tr.appendChild(td);
/***********************************************************************************************************************/
/***********************************************************************************************************************/
  }
 }
/*********************BORRADO DE LINEAS**********************************************************************************/
else
 {
 	flag = document.getElementById("flag").value;
	flag2 = document.getElementById("flag2").value;
	for(i=0;i<6;i++)
	{
	  var d = document.getElementById("tr_"+opc);
	  var d_nested = document.getElementById("td_"+opc);
	  d.removeChild(d_nested);
	}
   flag--;
   document.getElementById("flag").value=flag;


 }
}
/***************************************************************************************************************/
/***************************************************************************************************************/
function hour(flag2)
{
 var h='<select id="hour_'+flag2+'" name="hour_'+flag2+'">';
 for(i=1;i<=12;i++)
 {
  h+='<option>'+i+'</option>';
 }
 h+='</select>';
return h;
}

function min(flag2)
{
 var m='<select id="min_'+flag2+'" name="min_'+flag2+'">';
 for(i=1;i<=59;i++)
 {
  m+='<option>'+i+'</option>';
 }
 m+='</select>';
return m;
}

function ampm(flag2)
{
 var hor='<select id="ampm_'+flag2+'" name="ampm_'+flag2+'">';
  hor+='<option>AM</option>';
  hor+='<option>PM</option>';
  hor+='</select>';
return hor;
}

function month(flag2)
{
 var h='<select id="month_'+flag2+'" name="month_'+flag2+'">';
 for(i=3;i<=12;i++)
 {
  h+='<option value='+i+'>'+i+'</option>';
 }
 h+='</select>';
return h;
}


function actday(val,flag2)
{
 alert(val.value);


	 if(val.value==3||val.value==5||val.value==7||val.value==8||val.value==10||val.value==12)
	 {
	  for(i=1;i<=31;i++)
	  {
 		var opt = document.createElement("option");
 		opt.setAttribute("value",""+i);
 		opt.setAttribute("id","option_"+i);
 		opt.appendChild(document.createTextNode(""+i));
 		document.getElementById("select_"+flag2).appendChild(opt);
 		//alert(document.getElementById("select_"+flag2).value);
	  }
	 }
	 else
	 {
	  for(i=1;i<=30;i++)
	  {
 		var opt = document.createElement("option");
 		opt.setAttribute("value",""+i);
 		opt.setAttribute("id","option_"+i);
 		opt.appendChild(document.createTextNode(""+i));
 		document.getElementById("select_"+flag2).appendChild(opt);
 		//alert(document.getElementById("select_"+flag2).value);
	  }
	 }

}

/*************************************************************************************************************************/
/*************************************************************************************************************************/
function validacion2(lang){
if (document.getElementById("id_TipoPago_3").checked){
	if (lang=="En"){
		if (document.getElementById("DP_TipoTarjeta_1").checked==false && document.getElementById("DP_TipoTarjeta_2").checked==false && document.getElementById("DP_TipoTarjeta_3").checked==false && document.getElementById("DP_TipoTarjeta_4").checked==false){
			alert('Choose a card type');
			document.getElementById("DP_TipoTarjeta_1").focus();
			return false
		}
		if (document.form.DP_NumeroTarjeta.value == ""){
			alert('Write your card number');
			document.form.DP_NumeroTarjeta.focus();
			return false
		}
		if(IsNumeric(document.form.DP_NumeroTarjeta.value) == false){
			alert('Your card number must be numeric');
			document.form.DP_NumeroTarjeta.focus();
			return false
	  	}
		if (document.form.DP_CodigoSeguridad.value == ""){
			alert('Write your code');
			document.form.DP_CodigoSeguridad.focus();
			return false
		}
		if(IsNumeric(document.form.DP_CodigoSeguridad.value) == false){
			alert('Your code must be numeric');
			document.form.DP_CodigoSeguridad.focus();
			return false
	  	}
		if (document.form.DP_NombreTarjetahabiente.value == ""){
			alert('Write the printed name of card holder');
			document.form.DP_NombreTarjetahabiente.focus();
			return false
		}
		if (document.form.DP_FechaVencimiento.value == ""){
			alert('Write the expiration date');
			document.form.DP_FechaVencimiento.focus();
			return false
		}
		if (document.form.DP_AceptoTerminos.checked == false){
			alert('Please aceppt terms and conditions');
			document.form.DP_AceptoTerminos.focus();
			return false
		}
	}else{
		//alert('funciona!!!!!!');
		if (document.getElementById("DP_TipoTarjeta_1").checked==false && document.getElementById("DP_TipoTarjeta_2").checked==false && document.getElementById("DP_TipoTarjeta_3").checked==false && document.getElementById("DP_TipoTarjeta_4").checked==false){
			alert('Seleccione el tipo de tarjeta');
			document.getElementById("DP_TipoTarjeta_1").focus();
			return false
		}
		if (document.form.DP_NumeroTarjeta.value == ""){
			alert('Escriba Número de su tarjeta');
			document.form.DP_NumeroTarjeta.focus();
			return false
		}
		if(IsNumeric(document.form.DP_NumeroTarjeta.value) == false){
			alert('El Número de su tarjeta debe ser numérico');
			document.form.DP_NumeroTarjeta.focus();
			return false
	  	}
		if (document.form.DP_CodigoSeguridad.value == ""){
			alert('Escriba el codigo importante de su tarjeta');
			document.form.DP_CodigoSeguridad.focus();
			return false
		}
		if(IsNumeric(document.form.DP_CodigoSeguridad.value) == false){
			alert('El  codigo importante de su tarjeta debe ser numérico');
			document.form.DP_CodigoSeguridad.focus();
			return false
	  	}
		if (document.form.DP_NombreTarjetahabiente.value == ""){
			alert('Escriba la el nombre del tarjetahabiente (como aparece en la tarjeta)');
			document.form.DP_NombreTarjetahabiente.focus();
			return false
		}
		if (document.form.DP_FechaVencimiento.value == ""){
			alert('Escriba la fecha de vencimiento de su tarjeta');
			document.form.DP_FechaVencimiento.focus();
			return false
		}
		if (document.form.DP_AceptoTerminos.checked == false){
			alert('Acepte términos y condiciones');
			document.form.DP_AceptoTerminos.focus();
			return false
		}
	}
}else{
	//alert('NO funciona o no deberia entrar!!!!!!');
}
		
	//document.form.siguiente.disabled=true;
  return true

}
//copia de validacion 3 con una tarjeta de credito mas para ormex
function validacion3(lang){
	if (document.getElementById("id_TipoPago_3").checked){
		if (lang=="En"){
			if (document.getElementById("DP_TipoTarjeta_1").checked==false && document.getElementById("DP_TipoTarjeta_2").checked==false && document.getElementById("DP_TipoTarjeta_3").checked==false && document.getElementById("DP_TipoTarjeta_4").checked==false && document.getElementById("DP_TipoTarjeta_5").checked==false){
				alert('Choose a card type');
				document.getElementById("DP_TipoTarjeta_1").focus();
				return false
			}
			if (document.form.DP_NumeroTarjeta.value == ""){
				alert('Write your card number');
				document.form.DP_NumeroTarjeta.focus();
				return false
			}
			if(IsNumeric(document.form.DP_NumeroTarjeta.value) == false){
				alert('Your card number must be numeric');
				document.form.DP_NumeroTarjeta.focus();
				return false
		  	}
			if (document.form.DP_CodigoSeguridad.value == ""){
				alert('Write your code');
				document.form.DP_CodigoSeguridad.focus();
				return false
			}
			if(IsNumeric(document.form.DP_CodigoSeguridad.value) == false){
				alert('Your code must be numeric');
				document.form.DP_CodigoSeguridad.focus();
				return false
		  	}
			if (document.form.DP_NombreTarjetahabiente.value == ""){
				alert('Write the printed name of card holder');
				document.form.DP_NombreTarjetahabiente.focus();
				return false
			}
			if (document.form.DP_FechaVencimiento.value == ""){
				alert('Write the expiration date');
				document.form.DP_FechaVencimiento.focus();
				return false
			}
			if (document.form.DP_AceptoTerminos.checked == false){
				alert('Please aceppt terms and conditions');
				document.form.DP_AceptoTerminos.focus();
				return false
			}
		}else{
			//alert('funciona!!!!!!');
			if (document.getElementById("DP_TipoTarjeta_1").checked==false && document.getElementById("DP_TipoTarjeta_2").checked==false && document.getElementById("DP_TipoTarjeta_3").checked==false && document.getElementById("DP_TipoTarjeta_4").checked==false && document.getElementById("DP_TipoTarjeta_5").checked==false){
				alert('Seleccione el tipo de tarjeta');
				document.getElementById("DP_TipoTarjeta_1").focus();
				return false
			}
			if (document.form.DP_NumeroTarjeta.value == ""){
				alert('Escriba Número de su tarjeta');
				document.form.DP_NumeroTarjeta.focus();
				return false
			}
			if(IsNumeric(document.form.DP_NumeroTarjeta.value) == false){
				alert('El Número de su tarjeta debe ser numérico');
				document.form.DP_NumeroTarjeta.focus();
				return false
		  	}
			if (document.form.DP_CodigoSeguridad.value == ""){
				alert('Escriba el codigo importante de su tarjeta');
				document.form.DP_CodigoSeguridad.focus();
				return false
			}
			if(IsNumeric(document.form.DP_CodigoSeguridad.value) == false){
				alert('El  codigo importante de su tarjeta debe ser numérico');
				document.form.DP_CodigoSeguridad.focus();
				return false
		  	}
			if (document.form.DP_NombreTarjetahabiente.value == ""){
				alert('Escriba la el nombre del tarjetahabiente (como aparece en la tarjeta)');
				document.form.DP_NombreTarjetahabiente.focus();
				return false
			}
			if (document.form.DP_FechaVencimiento.value == ""){
				alert('Escriba la fecha de vencimiento de su tarjeta');
				document.form.DP_FechaVencimiento.focus();
				return false
			}
			if (document.form.DP_AceptoTerminos.checked == false){
				alert('Acepte términos y condiciones');
				document.form.DP_AceptoTerminos.focus();
				return false
			}
		}
	}else{
		//alert('NO funciona o no deberia entrar!!!!!!');
	}
			
		//document.form.siguiente.disabled=true;
	  return true

	}
//validacionpara la forma de modificaciones de stand de Ormex
function validacion4(lang){	
	if (lang=="En"){
		if (document.form.AO_Marquesina.value == "" && document.form.AO_ParedIzquierda.value == "" && document.form.AO_ParedDerecha.value == "" && document.form.AO_ParedTrasera.value == ""&& document.form.AO_Alfombra.value == ""){
			alert('No changes were specify');
			document.form.AO_Marquesina.focus();
			return false
		}
	}else{
		if (document.form.AO_Marquesina.value == "" && document.form.AO_ParedIzquierda.value == "" && document.form.AO_ParedDerecha.value == "" && document.form.AO_ParedTrasera.value == ""&& document.form.AO_Alfombra.value == ""){
			alert('No ha especificado ninguna modificacion');
			document.form.AO_Marquesina.focus();
			return false
		}			
	}			
		//document.form.siguiente.disabled=true;
	  return true

}

/*************************************************************************************************************************/
/*************************************************************************************************************************/

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

/*************************************************************************************************************************/
/*************************************************************************************************************************/
function habilitar()
{

 if(document.getElementById("caja").checked == true)
 {

   document.getElementById("boton").disabled=false;
 }
 else
 {

 document.getElementById("boton").disabled=true;
 }
}
/*************************************************************************************************************************/
/*************************************************************************************************************************/

function Abrir_ventana (pagina) {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=800, height=430, top=85, left=140";
window.open(pagina,"",opciones);
}

/*************************************************************************************************************************/
/*************************************************************************************************************************/

function Abrir_ventana2 (pagina) {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=400, height=230, top=85, left=140";
window.open(pagina,"",opciones);
}
/*************************mio de mi para abastur tipo-pago*****************************************************************/
//funciones que controlan el disable y enable de los radios cuando se elige o no tarjeta de credito para Centro Banamex
function R_readonlyF(){
	document.getElementById("DP_NumeroTarjeta").readOnly = false;
	document.getElementById("DP_CodigoSeguridad").readOnly = false;
	document.getElementById("DP_NombreTarjetahabiente").readOnly = false;
	document.getElementById("DP_FechaVencimiento").readOnly = false;
	
	document.getElementById("DP_AceptoTerminos").disabled = false;
	document.getElementById("DP_TipoTarjeta_1").disabled = false;
	document.getElementById("DP_TipoTarjeta_2").disabled = false;
	document.getElementById("DP_TipoTarjeta_3").disabled = false;
	document.getElementById("DP_TipoTarjeta_4").disabled = false;
}
function R_readonlyT(){
	document.getElementById("DP_NumeroTarjeta").readOnly = true;
	document.getElementById("DP_CodigoSeguridad").readOnly = true;
	document.getElementById("DP_NombreTarjetahabiente").readOnly = true;
	document.getElementById("DP_FechaVencimiento").readOnly = true;
	
	document.getElementById("DP_AceptoTerminos").disabled = true;
	document.getElementById("DP_TipoTarjeta_1").disabled = true;
	document.getElementById("DP_TipoTarjeta_2").disabled = true;
	document.getElementById("DP_TipoTarjeta_3").disabled = true;
	document.getElementById("DP_TipoTarjeta_4").disabled = true;
	
	document.getElementById("DP_NumeroTarjeta").value = '';
	document.getElementById("DP_CodigoSeguridad").value = '';
	document.getElementById("DP_NombreTarjetahabiente").value = '';
	document.getElementById("DP_FechaVencimiento").value = '';
	
	document.getElementById("DP_AceptoTerminos").checked = false;
	document.getElementById("DP_TipoTarjeta_1").checked = false;
	document.getElementById("DP_TipoTarjeta_2").checked = false;
	document.getElementById("DP_TipoTarjeta_3").checked = false;
	document.getElementById("DP_TipoTarjeta_4").checked = false;
}
//funciones que controlan el disable y enable de los radios cuando se elige o no tarjeta de credito para Ormex
function R_readonlyFO(){
	document.getElementById("DP_NumeroTarjeta").readOnly = false;
	document.getElementById("DP_CodigoSeguridad").readOnly = false;
	document.getElementById("DP_NombreTarjetahabiente").readOnly = false;
	document.getElementById("DP_FechaVencimiento").readOnly = false;
	
	document.getElementById("DP_AceptoTerminos").disabled = false;
	document.getElementById("DP_TipoTarjeta_1").disabled = false;
	document.getElementById("DP_TipoTarjeta_2").disabled = false;
	document.getElementById("DP_TipoTarjeta_3").disabled = false;
	document.getElementById("DP_TipoTarjeta_4").disabled = false;
	//document.getElementById("DP_TipoTarjeta_5").disabled = false;
}
function R_readonlyTO(){
	document.getElementById("DP_NumeroTarjeta").readOnly = true;
	document.getElementById("DP_CodigoSeguridad").readOnly = true;
	document.getElementById("DP_NombreTarjetahabiente").readOnly = true;
	document.getElementById("DP_FechaVencimiento").readOnly = true;
	
	document.getElementById("DP_AceptoTerminos").disabled = true;
	document.getElementById("DP_TipoTarjeta_1").disabled = true;
	document.getElementById("DP_TipoTarjeta_2").disabled = true;
	document.getElementById("DP_TipoTarjeta_3").disabled = true;
	document.getElementById("DP_TipoTarjeta_4").disabled = true;
	//document.getElementById("DP_TipoTarjeta_5").disabled = true;
	
	document.getElementById("DP_NumeroTarjeta").value = '';
	document.getElementById("DP_CodigoSeguridad").value = '';
	document.getElementById("DP_NombreTarjetahabiente").value = '';
	document.getElementById("DP_FechaVencimiento").value = '';
	
	document.getElementById("DP_AceptoTerminos").checked = false;
	document.getElementById("DP_TipoTarjeta_1").checked = false;
	document.getElementById("DP_TipoTarjeta_2").checked = false;
	document.getElementById("DP_TipoTarjeta_3").checked = false;
	document.getElementById("DP_TipoTarjeta_4").checked = false;
	//document.getElementById("DP_TipoTarjeta_5").checked = false;
}
function VerificarJavascript() {
	//alert('si entra');
	//document.form.Bandera_Javascript.value = 1;
	//document.getElementById('Bandera_Javascript').value=1;
	//window.location="asignar_bandera_javascript.php";
//alert('aquihhhh'+document.getElementById('Bandera_Javascript').value);
}

//funcion para radiobuton que controla propiedad readOnly=false elemento otro indicado
function R_readonlyFC(id){
	document.getElementById(id).readOnly = false;
}
//funcion para radiobuton que controla propiedad readOnly=true elemento otro indicado
function R_readonlyTC(id){
 	document.getElementById(id).readOnly = true;
	document.getElementById(id).value = '';
}