
var time = 600;
var time_started = false;
var timer = null;
	
function decrementar() 
{
	time--;
	if (time == 0) 
	{
		ShowTimeout();
		//componentBlock.actions.cancelOrders();
		return;
	}
	var spn = document.getElementById('time');
	if (spn) 
	{
		var minutes = parseInt(time/60);
		var seconds = (time % 60 < 10)?"0"+(time % 60):(time % 60);
		spn.innerHTML = minutes+":"+seconds;
	}
	timer = setTimeout('decrementar()',1000);
}

function resetTimer()
{
	if (!time_started)
	{
		document.getElementById('showTimer').style.display = "";
		time = 600;
		time_started = true;
		timer = setTimeout('decrementar()',1000);				
	}
	else
		time = 600;
}

function stopTimer()
{
	clearTimeout(timer);
	document.getElementById('ticketArea').style.display = 'none';
	document.getElementById('wizardBar').style.display = 'none';
	document.getElementById('showTimer').style.display = 'none';	
}


var checked_count = 0;

function restartChecking()
{
	checked_count = 0;
}

function checking()
{
	checked_count++;
	if (checked_count>0)
		document.getElementById('forwardButton').innerHTML = 'agregar boletos';
}

function unchecking()
{
	checked_count--;
	if ((checked_count==0)&&(varBlock.ticketsInCart()))
		document.getElementById('forwardButton').innerHTML = 'continuar';
}

function selecting(obj)
{
	if ((parseInt(obj.value)==0)&&(varBlock.ticketsInCart()))
		document.getElementById('forwardButton').innerHTML = 'continuar';
	else
		document.getElementById('forwardButton').innerHTML = 'agregar boletos';
}

function trimString(sInString) 
{
	sInString = sInString.replace( /^\s+/g, "" );// strip leading
	return sInString.replace( /\s+$/g, "" );// strip trailing
}

function complete_callback(response)
{
	var block = response.responseText.split('[newBlock]');
	var data = null;
	var div = null;
	var i = 0;
	var len = block.length;
	while (i < len)
	{
		data = block[i].split('[elemName]:=');
		div = document.getElementById(trimString(data[1]));
//		alert(trimString(data[1]) + ': ' + div);
		data = data[0].split('[evalBlock]:=');
		if (data.length > 1)
		{
			if (trimString(data[1]) == '1')
				eval(data[0]);
			else if (div)
				div.innerHTML = data[0];
		}
		else if (div)
			div.innerHTML = data[0];
		i++;
	}
	killQuickTip();
}

function failure_callback(response)
{
	alert('failure: ' + response.responseText);
}

function exception_callback(request, exception)
{
	alert('exception: ' + exception.message);
}

var ajaxConn = 
{
	ajaxCalls: 0,
	send: function(params)
	{
		this.ajaxCalls++;
		//Kiji.Debug.trace(http + '?' + params + '&call=' + uid + this.ajaxCalls);
		new Ajax.Request( http + '?' + params + '&call=' + uid + this.ajaxCalls, 
							{
								method: 'GET', 
								contenType: 'text/plain',
								onComplete: complete_callback,
								onFailure: failure_callback,
								onException: exception_callback
							}
						);	
	},
	sendAction: function(params, callback)
	{
		this.ajaxCalls++;
//		Kiji.Debug.trace(http + '?' + params + '&call='  + uid + this.ajaxCalls);
		new Ajax.Request( http + '?' + params + '&call=' + uid + this.ajaxCalls, 
							{
								method: 'GET', 
								contenType: 'text/plain',
								onComplete: callback,
								onFailure: failure_callback,
								onException: exception_callback
							}
						);	
	}
}


var taber = 
{
	tab: 'event',
	subtab: 'section',
	params: '',
	lasttab: '',
	setParams: function(newParams)
	{
		this.params = newParams;		
	},
	
	startTabs: function()
	{
		componentBlock.loadEventBar(this.params);
		componentBlock.loadTicketArea(this.params);
		this.changeTab('event');
	},
	
	changeTab: function(newTab)
	{
		this.lasttab = this.tab;
		this.tab = newTab;
		if (this.tab == 'sit')
			showWaitingWindow(1);		
		if ( (this.tab == 'checkout') && ($($('loginTable')).style.display=='none') )
		{
			ShowMessage('Tienes que ingresar tu usuario y contrase&ntilde;a para proseguir.');
			this.tab = this.lasttab;
			return;
		}

		componentBlock.loadActionArea(this.tab, '', this.params);		
		//alert('task=loadTab&tab=' + this.tab + '&' + this.params);		
		ajaxConn.send('task=loadTab&tab=' + this.tab + '&' + this.params);		
		
		
	},
	
	changeSubtab: function(newSubtab)
	{
		this.lasttab = this.tab;
		this.subtab = newSubtab;
		componentBlock.loadActionArea(this.tab, this.subtab, this.params);
		ajaxConn.send('task=loadSubTab&tab=' + this.tab + '&subtab=' + this.subtab);		
	},
	
	changeTabs: function(newTab, newSubtab)
	{
		this.lasttab = this.tab;
		this.tab = newTab;
		this.subtab = newSubtab;
		if (this.tab == 'sit')
			showWaitingWindow(1);
		componentBlock.loadActionArea(this.tab, this.subtab, this.params);
		ajaxConn.send('task=loadTab&tab=' + this.tab + '&subtab=' + this.subtab + '&' + this.params);		
	},
	
	goBack: function()
	{
		if (this.lasttab != '')
			this.changeTab(this.lasttab);
	}
}

var componentBlock = 
{
	loadEventBar: function(params)
	{
		//alert('task=loadEventBar&' + params);
		ajaxConn.send('task=loadEventBar&' + params);
		ajaxConn.send('task=loadBannerPanel&' + params);
	},
	
	loadTicketArea: function(params)
	{
		//alert('task=loadTicketArea&' + params);
		ajaxConn.send('task=loadTicketArea&' + params);
	},
	
	loadActionArea: function(tab, subtab, params)
	{
		var extend = '';
		if (tab != '')
			extend = '&tab=' + tab;
		if (subtab != '')
			extend += '&subtab=' + subtab;
		//alert('task=loadActionArea&' + params + extend);
		ajaxConn.send('task=loadActionArea&' + params + extend);
		
	},
	
	reloadSitMap: function(params)
	{
		//showWaitingWindow(1);
		ajaxConn.send('task=reloadSitMap&' + params);
	}
}

function addTickets_callback(response)
{	
	//alert(response.responseText);
	
	/*var div =  document.getElementById('ticketWindow');
	div.innerHTML =response.responseText;*/
	
	var blocks = response.responseText.split('[newBlock]');	
	var id_order = parseInt(blocks[0]);
	varBlock.appendOrder(id_order);	
	showWaitingWindow(-1);	
	if (blocks[1].indexOf('-', 0) != 0)
		if (blocks[1].indexOf('+', 0) == 0)
			showTakenTickets('Limite de Boletos', 'El maximo de boletos permitido por orden es: ' + blocks[2] + '. Si desea mas boletos debera crear ordenes separadas.');	
		else
			showTakenTickets('Boletos Reservados', 'Otra persona apart&oacute; los boletos un instante antes que usted. los siguientes boletos no fueron apartados: ' + blocks[1] + '. Sentimos las molestias.');	
}

//belinda adapted
function checkBines_callback(response)
{	
	//alert(response.responseText);
	
	/*var div =  document.getElementById('ticketWindow');
	div.innerHTML =response.responseText;*/
	
	var blocks = response.responseText.split('[newBlock]');	
	//alert(blocks[1]);
	//showWaitingWindow(-1);
	if (blocks[0]==1)
	{
		var form = document.getElementById('formCheckout');
		ShowMessage('El numero de tarjeta que ingreso no concuerda con el banco emisor que selecciono, por favor intente con otro banco.');	
		form.tar_bcoe.focus();
	}else
	{
		checkout();
	}
	
	
	
		
}

componentBlock.actions = 
{
	
	descuentoBelinda: function(params)
	{				
		//alert('componentBlock');
		resetTimer();
		ajaxConn.send('task=descuentoBelinda&' + params);
		showWaitingWindow(1);
	},
	
	addTickets: function(params)
	{
		resetTimer();
		showWaitingWindow(1);
		ajaxConn.sendAction('task=addTickets&' + params, addTickets_callback);
	},
	
	addTicketAmount: function(params)
	{
		resetTimer();
		showWaitingWindow(1);
		ajaxConn.sendAction('task=addTicketAmount&' + params, addTickets_callback);	
	},
	
	addTicketsFromTables: function(params)
	{
		resetTimer();
		showWaitingWindow(1);
		ajaxConn.sendAction('task=addTicketsFromTables&' + params, addTickets_callback);	
	},
	
	//belinda adapted
	checkBines:function(params) 
	{
		//alert('task=checkBines');
		//resetTimer();
		//showWaitingWindow(1);		
		ajaxConn.sendAction('task=checkBines&' + params + '&' + varBlock.buildParams(), checkBines_callback);	
	},
	
	deleteTickets: function(params)
	{		
		resetTimer();
		ajaxConn.send('task=deleteTickets&' + params + '&tab=' + taber.tab);
		showWaitingWindow(1);
	},
	
	login: function(user, pass, params)
	{
		//resetTimer();
		ajaxConn.send('task=login&usr=' + user + '&ssd=' + pass + '&' + params);
	},
	
	changePass: function(pass, pass2)
	{
		resetTimer();
		ajaxConn.send('task=changePass&pass=' + pass + '&pass2=' + pass2);
	},
	
	forgot: function(mail)
	{
		resetTimer();
		ajaxConn.send('task=sendUser&ml=' + mail);
	},
	
	register: function(params)
	{
		showWaitingWindow(1);
		resetTimer();				
		ajaxConn.send('task=register&' + params + '&' + varBlock.buildParams());		
	},
	
	update_data: function(params)
	{
		resetTimer();
		ajaxConn.send('task=registerUpdate&' + params + '&' + varBlock.buildParams());		
	},
	
	applyDiscount: function(params)
	{
		resetTimer();
		ajaxConn.send('task=applyDiscount&' + params);		
	},
	
	checkout: function(params)
	{
		//alert('task=checkout');
		
		showWaitingWindow(1);
		ajaxConn.send('task=checkout&' + params + '&' + varBlock.buildParams());
//		alert('expecting metadata!!!');
	},
	
			
	cancelOrders: function()
	{
		ajaxConn.send('task=cancelOrders&' + varBlock.buildParams());
	},
	
	logout: function()
	{
		ajaxConn.send('task=logout&' + varBlock.buildParams());
	},
	
	nexusCheckout: function(params)
	{
		//showWaitingWindow(1);
		ajaxConn.sendAction(params + '&' + varBlock.buildParams(), null);
	}
}

var varBlock = 
{
	id_account: cuenta,
	id_country: country,
	currency: currency,
	id_event: null,
	id_function: null,
	id_locality: null,
	order_list: [],
	ticket_list: null,
	ticket_count: null,
	mail: null,
	id_section_type: 1,
	discounted: null,
	id_forma_entrega: null,
	delivery_address: null,
	delivery_phone: null,
	delivery_sector: null,
	delivery_observations: null,
	delivery_address_type: null,
	delivery_mode: null,
	
	start: function(idEvent, idFunction)
	{
		
		this.id_event = idEvent;
		this.id_function = idFunction;
		taber.setParams(this.buildParams());
		
		taber.startTabs();		
	},
	
	setEvent: function(idEvent)
	{
		this.id_event = idEvent;
		this.id_function = null;
		this.id_locality = null;
		var parameters = this.buildParams(); 
		
		componentBlock.loadEventBar(parameters);
		taber.setParams(parameters);
		taber.changeTab('event');
	},
	
	setFunction: function(idFunction)
	{
		this.id_function = idFunction;
		this.id_locality = null;
		var parameters = this.buildParams(); 
		
		componentBlock.loadEventBar(parameters);
		taber.setParams(parameters);
		taber.changeTab('event');
		/*taber.changeSubtab('section');*/
	},
	
	setLocality: function(idLocality)
	{
		this.id_locality = idLocality;
		taber.setParams(this.buildParams());
		//showWaitingWindow(1);
		taber.changeTab('sit');		
	},

	setTickets: function(ticketList)
	{
		this.ticket_list = ticketList;
		componentBlock.actions.addTickets(this.buildParams());		
		this.ticket_list = null;
	},
	
	addTicketsFromTables: function(ticketList)
	{
		this.ticket_list = ticketList;
		componentBlock.actions.addTicketsFromTables(this.buildParams());
		this.ticket_list = null;
	},

	addTicketAmount: function(ticketCount)
	{
		this.ticket_count = ticketCount;
		componentBlock.actions.addTicketAmount(this.buildParams());
		this.ticket_count = null;
	},
	
	clearTickets: function(ticketList)
	{
		this.ticket_list = ticketList;
		componentBlock.actions.deleteTickets(this.buildParams());		
		this.ticket_list = null;
	},

	descuentoBelinda:function()
	{
		//alert('varBlock');
		componentBlock.actions.descuentoBelinda(this.buildParams());		
	},

	appendOrder: function(idOrder)
	{
		if (idOrder > 0)
			this.order_list.push(idOrder);
		var parameters = this.buildParams();
		componentBlock.loadTicketArea(parameters);
		taber.setParams(parameters);
		taber.changeTab('registration');		
	},

	reloadMap: function()
	{
		componentBlock.reloadSitMap(this.buildParams());
	},

	buildParams: function()
	{		
		var str = '';
		if (this.id_account != null) str += 'id_account=' + this.id_account;
		if (this.id_country != null) str += ((str.length > 0)?'&':'') + 'id_country=' + this.id_country;
		if (this.currency != null) str += ((str.length > 0)?'&':'') + 'currency=' + this.currency;
		if (this.id_event != null) str += ((str.length > 0)?'&':'') + 'id_event=' + this.id_event;
		if (this.id_function != null) str += ((str.length > 0)?'&':'') + 'id_function=' + this.id_function;
		if (this.id_locality != null) str += ((str.length > 0)?'&':'') + 'id_locality=' + this.id_locality;
		if (this.mail != null) str += ((str.length > 0)?'&':'') + 'mail=' + this.mail;
		if (this.discounted != null) str += ((str.length > 0)?'&':'') + 'discounted=' + this.discounted;
		if (this.id_forma_entrega != null) str += ((str.length > 0)?'&':'') + 'id_forma_entrega=' + this.id_forma_entrega;
		if (this.delivery_address != null) str += ((str.length > 0)?'&':'') + 'delivery_address=' + this.delivery_address;
		if (this.delivery_phone != null) str += ((str.length > 0)?'&':'') + 'delivery_phone=' + this.delivery_phone;
		if (this.delivery_sector != null) str += ((str.length > 0)?'&':'') + 'delivery_sector=' + this.delivery_sector;
		if (this.delivery_observations != null) str += ((str.length > 0)?'&':'') + 'delivery_observations=' + this.delivery_observations;
		if (this.delivery_address_type != null) str += ((str.length > 0)?'&':'') + 'delivery_address_type=' + this.delivery_address_type;
		if (this.delivery_mode != null) str += ((str.length > 0)?'&':'') + 'delivery_mode=' + this.delivery_mode;
		if (this.order_list.length > 0)
		{
			str += (str.length > 0)?'&':'';
			var orders = this.order_list.inject	(
									'',
									function buildQuery(accumulator, value, index)
									{
										return accumulator + ',' + value;
									}
								);
			orders = orders.substr(1);
			str += 'order_list=' + orders;
		}
		if (this.ticket_list != null) str += ((str.length > 0)?'&':'') + 'ticket_list=' + this.ticket_list;
		if (this.ticket_count != null) str += ((str.length > 0)?'&':'') + 'ticket_count=' + this.ticket_count;		
		return str;
	},

	ticketsInCart: function()
	{
		return (this.order_list.length>0);
	}
}


/*
	validation funcs
*/


function validate_user(obj, div_name)
{
	
}

/*
	eventBar events
*/
function eventBar_select()
{
	var list = document.getElementById('eventBar_events');
	if (list.value > 0)
	{
		window.location = livesite + '/index.php?option=com_todoticket_ventas&task=start&id_event=' + list.value;
	//	varBlock.setEvent(list.value);
	}
}

/*
	sitSelection events
*/

function sitSelection_functions_select()
{
	var list = document.getElementById('sitSelection_functions');
	if (list.value > 0)
		varBlock.setFunction(list.value);
}

function sitSelection_localities_select()
{
	var list = document.getElementById('sitSelection_locality');
	if (list.value != '0')
		varBlock.setLocality(list.value);
}

function sitSelection_localitiesByMap_select(idLocality)
{
	varBlock.setLocality(idLocality);
}

function sitSelection_sitMap_refresh()
{
	componentBlock.reloadSitMap(varBlock.buildParams());
}

function sitSelection_sitMap_addTickets()
{
	var s = '';
	var locality;
	switch (varBlock.id_section_type)
	{
		case 1: // Numbered Sits
			var x = document.getElementsByTagName('span');
			var sits_taken = 0;
			for (var i = 0; i < x.length; i++) 			
				if (x[i].getAttribute('type') != null && x[i].id.indexOf('chkMapa_') == 0 && 
					x[i].innerHTML != '' && x[i].getAttribute("idBoleto") != null)
					{
						s += ','+x[i].getAttribute("idBoleto");
						sits_taken++;
					}
						
			if (s.length > 0)
			{
				s = s.substr(1);
				locality = varBlock.id_locality.split('-');
				if ((parseInt(varBlock.id_event)==209)&&(parseInt(varBlock.id_country)==1))
				{
					if ((parseInt(locality[2])>=1181)&&(parseInt(locality[2])<=1214))
					//if ((parseInt(locality[2])==1228))
					{
						if (sits_taken>=4)
							varBlock.setTickets(s);
						else
							showInfoMsg('Selecci&oacute;n de Platea', 'Los palcos solo se pueden vender completos.');
					}
					else
						varBlock.setTickets(s);
				}
				else if ((parseInt(varBlock.id_event)==38)&&(parseInt(varBlock.id_country)==2))
				{
					if ((parseInt(locality[3])>=421)&&(parseInt(locality[3])<=454))
					//if ((parseInt(locality[2])==1228))
					{
						if (sits_taken>=4)
							varBlock.setTickets(s);
						else
							showInfoMsg('Selecci&oacute;n de Platea', 'Los palcos solo se pueden vender completos.');
					}
					else
						varBlock.setTickets(s);
				}
				else
					varBlock.setTickets(s);
			}
			else
			{	
				if (varBlock.ticketsInCart())
					taber.changeTab('registration');
				else
					showInfoMsg('Selecci&oacute;n de Boletos', 'No ha seleccionado boletos.');
			}
		break;
		case 2: // No Numbered Sits	
			var x = document.getElementById('ddlNumeroBoletos');
			s = x.value;					
			if (s>0)
			{
				varBlock.addTicketAmount(s);
			}
			else
			{	
				if (varBlock.ticketsInCart())
					taber.changeTab('registration');
				else
					showInfoMsg('Selecci&oacute;n de Boletos', 'No ha seleccionado boletos.');
			}
		break;
		case 3: // Sits with tables
						    
			var x = document.getElementsByName('ddlBoletosMesa');
			for (var i=0; i<x.length; i++)					
				if (x[i].options[x[i].selectedIndex].value>0 
	                && x[i].getAttribute('numeroMesa') != null)                
                	s += '-'+(x[i].getAttribute('numeroMesa')+','+x[i].options[x[i].selectedIndex].value);
                	
           	if (s.length > 0)
			{
				
				s = s.substr(1);				
				varBlock.addTicketsFromTables(s);
			}
			else
			{	
				if (varBlock.ticketsInCart())
					taber.changeTab('registration');
				else
					showInfoMsg('Selecci&oacute;n de Boletos', 'No ha seleccionado boletos.');
			}
                                                                					
		break;
	}
}


/*
	ticketArea
*/

function ticketArea_checkAll(event)
{
	var cks = document.getElementsByTagName('input');
	var value = Event.element(event).checked;
	for (var i = 0; i< cks.length; i++)			
		if (cks[i].type == 'checkbox' && cks[i].getAttribute('idBoleto') != null && cks[i].id.indexOf('del_') == 0)
			cks[i].checked = value;
}


function ticketArea_deleteTickets()
{
	var cks = document.getElementsByTagName('input');
	var s = '';
	for (var i = 0; i< cks.length; i++)			
		if (cks[i].type == 'checkbox' && cks[i].getAttribute('idBoleto') != null && cks[i].id.indexOf('del_') == 0 && cks[i].checked == true)
			s += ',' + cks[i].getAttribute('idBoleto');

	if (s.length > 0)
	{
		s = s.substr(1);
		varBlock.clearTickets(s);
	}
}

function ticketArea_cancelOrders()
{
	ShowDropOrder();
}

function ticketArea_applyDiscount()
{
	componentBlock.actions.applyDiscount(varBlock.buildParams() + '&id_ticket='+$('discount_code_ticket').value+'&d_value=' + $('discount_code_value').value);
}

function ticketArea_applyDiscountCancel()
{
	Element.hide($('discount_code'));
}

function ticketArea_askCodeTihany(id_boleto, obj)
{
	componentBlock.actions.applyDiscount(varBlock.buildParams() + '&id_ticket='+id_boleto+'&d_value=' + obj.value);
}

function ticketArea_askCode(id_boleto, obj)
{
	$('discount_code_ticket').value = id_boleto;
	Element.show($('discount_code'));
	Position.clone(obj, $('discount_code'), {setHeight: false, setWidth: false});
}

function ticketArea_remove(id_boleto)
{
	$('discount_code_ticket').value = id_boleto;
	componentBlock.actions.applyDiscount(varBlock.buildParams() + '&id_ticket='+$('discount_code_ticket').value+'&d_value=remover');
}
/*
	registration events
*/

function registration_login()
{
	var user = document.getElementById('sr');
	var pass = document.getElementById('ssd');
	
	componentBlock.actions.login(user.value, pass.value, varBlock.buildParams());
}

function register_register()
{
	var form = document.getElementById('formRegister');
	var rdbtn = document.getElementById('acceptedPol');
	if (rdbtn.value == 'yes')
		componentBlock.actions.register(Form.serialize( form ));
	else
		ShowNoPolicies();
}

function register_update()
{	
	var form = document.getElementById('formRegister');
	var rdbtn = document.getElementById('acceptedPol');
	if (rdbtn.value == 'yes')
		componentBlock.actions.update_data(Form.serialize( form ));
	else
		ShowNoPolicies();	
}

function register_changePass()
{
	var pass = document.getElementById('sw');
	var pass2 = document.getElementById('sw2');
	componentBlock.actions.changePass(pass.value, pass2.value);
}

function register_forgot()
{
	var mail = document.getElementById('ml');
	componentBlock.actions.forgot(mail.value);
}

function register_loadHistory(page)
{
	taber.setParams('page=' + page + '&' + varBlock.buildParams());
	taber.changeTabs('registration', 'orderHistory');
}

function register_loadHistoryDetail(page, id_orden)
{
	taber.setParams('page=' + page + '&id_orden=' + id_orden);
	taber.changeTabs('registration', 'orderHistory');
}

/*belinda adapted*/

function descuentoBelinda()
{
	//alert('function');
	varBlock.descuentoBelinda();
}


/*
	Checkout events
*/

function trycheckout(obj)
{
	switch ($('payment_mode').value)
	{
		case 'paynexus':
			checkout(obj);
			break;
		case 'cr_aval':
			var form = document.getElementById('formCheckout');
			if (form == null)
				showInfoMsg('Error', 'Ocurrio un error y no se pudo completar su compra. Porfavor intente mas tarde.');
			else
				form.submit();
			break;
		default:
		case 'freewill':
		case 'aval':
		case 'credomatic':
			if(CheckCardNumber(document.formCheckout)) checkout(obj);
			break;
	}
}




function setPayform(value)
{
	varBlock.id_forma_entrega = value;
	taber.setParams(varBlock.buildParams());
	if (value == '1')
		showDeliveryPolicies();
	else
		taber.changeTab('checkout');
}

function checkDelivery()
{
	//if valid
	varBlock.delivery_address = $('delivery_address').value;
	varBlock.delivery_phone = $('delivery_phone').value;
	varBlock.delivery_observations = $('delivery_observations').value;
	varBlock.delivery_sector = $('delivery_sector').value;
	varBlock.delivery_address_type = $('delivery_address_type').value;
	//varBlock.delivery_mode = $('delivery_mode').value;

	if ($('delivery_address_type').value==0)
		showInfoMsg('Mensaje', 'Debe elegir un tipo de direcci&oacute;n antes de continuar.');
	else if ($('delivery_sector').value==0)
		showInfoMsg('Mensaje', 'Debe elegir un Sector antes de continuar.');
	else if ($('delivery_address').value == '')
		showInfoMsg('Mensaje', 'Debe elegir una direcci&oacute;n.');
	else if ($('delivery_phone').value == '')
		showInfoMsg('Mensaje', 'Debe elegir un n&uacute;mero de tel&eacute;fono.');
	else
	{
		taber.setParams(varBlock.buildParams());
		taber.changeTab('checkout');
	}
}

function copyDeliveryData()
{
	Element.show($('deliverySector'));
	Element.show($('deliveryObservations'));
	Element.show($('deliveryAddressType'));
	Element.show($('deliveryAddress'));
	Element.show($('deliveryPhone'));
	$('delivery_sector').value = 0;
	$('delivery_observations').value = '';
	$('delivery_address_type').value = 1;
	$('delivery_address').value = $('direccion').value;
	$('delivery_phone').value = $('telefono').value;
}

function dontSaveDeliveryData()
{
	Element.hide($('deliverySector'));
	Element.hide($('deliveryObservations'));
	Element.hide($('deliveryAddressType'));
	Element.hide($('deliveryAddress'));
	Element.hide($('deliveryPhone'));
	$('delivery_sector').value = 0;
	$('delivery_observations').value = '';
	$('delivery_address_type').value = 0;
	$('delivery_address').value = '';
	$('delivery_phone').value = '';
}

function saveDeliveryData()
{
	Element.show($('deliverySector'));
	Element.show($('deliveryObservations'));
	Element.show($('deliveryAddressType'));
	Element.show($('deliveryAddress'));
	Element.show($('deliveryPhone'));
	$('delivery_sector').value = 0;
	$('delivery_observations').value = '';
	$('delivery_address_type').value = 0;
	$('delivery_address').value = '';
	$('delivery_phone').value = '';
}

function deliverySaved()
{
	varBlock.delivery_mode = null;

	taber.setParams(varBlock.buildParams());
	taber.changeTab('delivery');
}

function deliveryCopy()
{
	varBlock.delivery_mode = null;
	$('delivery_sector').value = 0;
	$('delivery_address_type').value = 1;
	$('delivery_address').value = $('home_address').value;
	$('delivery_phone').value = $('home_phone').value;
	varBlock.delivery_mode = 2;
}

function deliveryNew()
{
	$('delivery_sector').value = 0;
	$('delivery_observations').value = '';
	$('delivery_address_type').value = 0;
	$('delivery_address').value = '';
	$('delivery_phone').value = '';
	varBlock.delivery_mode = 3;
}

function changePaymentForm(obj)
{
	switch (obj.value)
	{
		case 'credomatic':
			Element.show($('credomatic_form'));
			Element.hide($('paynexus_form'));
			$('payment_mode').value = obj.value;
			break;
		case 'paynexus':
			Element.show($('paynexus_form'));
			Element.hide($('credomatic_form'));
			$('payment_mode').value = obj.value;
			break;
		case 'aval':
			Element.show($('credomatic_form'));
			Element.hide($('paynexus_form'));
			$('payment_mode').value = obj.value;
			break;
		case 'freewill':
			Element.show($('credomatic_form'));
			Element.hide($('paynexus_form'));
			$('payment_mode').value = obj.value;
			break;
	}
}

function checkout(obj)
{
	if (!obj.disabled)
	{
		obj.disabled = true;
		var form = document.getElementById('formCheckout');
		componentBlock.actions.checkout(Form.serialize(form));
	}
}

function nexusCheckout()
{
	params = 'task=paynexusCheckout';
	componentBlock.actions.nexusCheckout(params);
}

//belinda adapted
function checkoutBelinda()
{
	
	var form = document.getElementById('formCheckout');
	
	idBanco = form.tar_bcoe.options[form.tar_bcoe.selectedIndex].value;
	
	if (idBanco > 0)
	{
		componentBlock.actions.checkBines(Form.serialize(form));	
	}else
	{
		ShowMessage('La preventa solo aplica para tarjetas emitidas por los bancos participantes');
	}
		
}


function buy_again()
{
	window.location = livesite + '/index.php?option=com_todoticket_ventas&task=start&id_event=' + varBlock.id_event;
}


function loadCart()
{
	varBlock.start(initialEvent, initialFunction);
	//initialFunction		
}
		
//Event.observe(window, 'load', loadCart, false);
loadFuncs.push(loadCart);

function testWS()
{
	ajaxConn.send('task=webservice');
}
