
// JavaScript Document



function checkNumTiquet(obj, obj2, obj3, obj4){
	sndReq('code='+obj.value+'&fecha='+obj3+'&clientID='+parseInt(obj2), 'codigoEan', obj4);
}


function registroOK(){
		
	if(myLightWindow == null)
	{
		setTimeout(registroOK, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_registroOK.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function activacionOK(){
		
	if(myLightWindow == null)
	{
		setTimeout(activacionOK, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_primeraParticipacionOK.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function openErrorLogin(){
		
	if(myLightWindow == null)
	{
		setTimeout(openErrorLogin, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_errorLogIn.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function participacionOK(){
		
	if(myLightWindow == null)
	{
		setTimeout(participacionOK, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_ParticipacionOK.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function notLogged(){
		
	if(myLightWindow == null)
	{
		setTimeout(notLogged, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_Identificacion.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function codigosRepetidos(){
		
	if(myLightWindow == null)
	{
		setTimeout(codigosRepetidos, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_codigoRepetido.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function codigoIncorrecto(){
		
	if(myLightWindow == null)
	{
		setTimeout(codigoIncorrecto, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_codigoIncorrecto.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function fechaIncorrecta(){
		
	if(myLightWindow == null)
	{
		setTimeout(fechaIncorrecta, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_fechaIncorrecta.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}

function faltacentro(){
		
	if(myLightWindow == null)
	{
		setTimeout(faltacentro, 100);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/popup_faltaEstablecimiento.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}



function openForgetPassword(){
if(myLightWindow == null)
	{
		setTimeout(openForgetPassword, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/popup_recordarPassword.html', title:'', caption:'', type:'external', width:'305', height:'321'});		
	}
}

function doWy(pag){
		
	if(myLightWindow == null)
	{
		setTimeout(doWy, 100, pag);
	}
	else
	{
myLightWindow.activateWindow({href:'popUps/'+pag+'.html', title:'', caption:'', type:'external', width:'305', height:'321'});
	}
}




function doEmailDuplicado(){
if(myLightWindow == null)
	{
		setTimeout(doEmailDuplicado, 100);
	}
	else
	{
			myLightWindow.activateWindow({href:'popUps/pop_email_duplicado.html', title:'', caption:'', type:'external', width:'305', height:'321'});	
	}
}

function doNIFDuplicado(){
	if(myLightWindow == null)
	{
		setTimeout(doNIFDuplicado, 100);
	}
	else
	{
	myLightWindow.activateWindow({href:'popUps/popup_nifDuplicado.html', title:'', caption:'', type:'external', width:'305', height:'205'});	
	}
	
}

function openLightWindow(pag, w, h){
	if(myLightWindow == null)
	{
		setTimeout(openLightWindow, 100);
	}
	else
	{
	myLightWindow.activateWindow({href:pag, title:'', caption:'', type:'external', width:w, height:h});		
	}
}
function openLightWindowGlobal(error){
	if(myLightWindow == null)
	{
		setTimeout(openLightWindowGlobal, 100);
	}
	else
	{
	myLightWindow.activateWindow({href:'popUps/pop_errorGenerico.asp?mensaje='+error, title:'', caption:'', type:'external', width:305, height:175});		
	}
}
function cosigeCodioGratis(){
	if(myLightWindow == null)
	{
		setTimeout(cosigeCodioGratis, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/popup_primeraParticipacion.html', title:'', caption:'', type:'external', width:'305', height:'321'});	
	}
}
function cosigeCodioGratisRegistro(){
	if(myLightWindow == null)
	{
		setTimeout(cosigeCodioGratisRegistro, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/popup_primeraParticipacion_registro.html', title:'', caption:'', type:'external', width:'305', height:'321'});	
	}
}



function popup_fechas(){
	if(myLightWindow == null)
	{
		setTimeout(popup_fechas, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/popup_fechas.html', title:'', caption:'', type:'external', width:'305', height:'321'});	
	}
}

function aviso_legal(){
	if(myLightWindow == null)
	{
		setTimeout(aviso_legal, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/aviso_legal.html', title:'', caption:'', type:'external', width:'478', height:'501'});	
	}
}

function aviso_legal_registro(){
	if(myLightWindow == null)
	{
		setTimeout(aviso_legal_registro, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/aviso_legal_registro.html', title:'', caption:'', type:'external', width:'478', height:'501'});	
	}
}
function bases_legales(){
	if(myLightWindow == null)
	{
		setTimeout(bases_legales, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/bases_legales.html', title:'', caption:'', type:'external', width:'478', height:'501'});	
	}
}
function politicaPrivacidad(){
	if(myLightWindow == null)
	{
		setTimeout(politicaPrivacidad, 100);
	}
	else
	{
		myLightWindow.activateWindow({href:'popUps/politicaPrivacidad.html', title:'', caption:'', type:'external', width:'478', height:'501'});	
	}
}



// cross-browser add-remove event to object
EventManager =
{
	addEvent: function(obj, e, func)
	{
		//W3C, Mozilla
		if(obj.addEventListener)
		{
			obj.addEventListener(e, func, false);
		}
		//IE
		else if(obj.attachEvent)
		{
			obj.attachEvent("on"+e, func);
		}
		//others
		else
		{
			obj["on"+e] = func;
		}
	},
	
	removeEvent: function(obj, e, func)
	{
		if(obj.removeEventListener)
		{
			obj.removeEventListener(e, func, false);
		}
		else if(obj.detachEvent)
		{
			obj.detachEvent("on"+e, func);
		}
		else
		{
			obj["on"+e] = null;
		}
	},
	
	delegate: function(o, f, inherit_args)
	{
		var a = new Array();
		for(var i=3; i<arguments.length; i++) a.push(arguments[i]);
		return function()
		{
			//se envían además los parámetros propios que el método devuelve
			if(inherit_args)
			{
				var ar = new Array();
				for(var i=0; i<arguments.length; i++) ar.push(arguments[i]); //arguments no se considera una array, por lo que no funciona 'concat'
				f.apply(o, ar.concat(a)); //suma a los valores retornados por la funcion por defecto los definidos por el usuario
			}
			else
			{
				f.apply(o, a);
			}
		}
	}
};

//--------------------------------------------------------------------------

// Permuta una imagen cuyo nombre acabe en "_on." o "_off." (versión 2.1)
function commuteImg()
{
	var sSrc = this.src,
		rSearch = new RegExp("_(on|off)\\.");
	sSrc.match(rSearch);
	var sSrc = sSrc.replace("_"+RegExp.$1+".", "_"+((RegExp.$1=="off") ? "on" : "off")+".");
	this.src = sSrc;
}

function prepareChangeImages()
{
	var allImg = document.getElementsByTagName("IMG");
	for(var i=0; i<allImg.length; i++)
	{
		var oAttr = String(allImg[i].getAttribute("src"));
		if(oAttr.toLowerCase().match("_off."))
		{
			var o = allImg[i];
				o.onmouseover	= commuteImg;
				o.onmouseout	= commuteImg;
		}
	}
}

EventManager.addEvent(window, "load", prepareChangeImages);

//--------------------------------------------------------------------------

var mac = (navigator.appVersion.indexOf("Mac") >0 )? true : false;

function getPos(w,h)
{
	var nW = (mac && document.all)? w-16 : w;
	var nH = h;
	var list = {
		x : Math.round((screen.availWidth/2) - (nW/2)),
		y : Math.round((screen.availHeight/2) - (nH/2)),
		w : nW,
		h : nH		
	}
	return list;
}

function existWin(oWindow)
{
	clearInterval(tmr);
	if(!oWindow) alert("Por favor, activa la opción de abrir ventanas emergentes de tu navegador para imprimir la información. Gracias.");
}

function openWin(pag,w,h,s)
{
	if(w == null) w = 650;
	if(h == null) h = 500;
	if(s == null) s = "yes";
	var pos = getPos(w,h);
	var w_pop = window.open(pag, "new_window","width=" + pos.w + ", height=" + pos.h + ", top=" + pos.y + ", left=" + pos.x + ", scrollbars=" + s);
	tmr = setInterval(existWin, 1000, w_pop);
}


//Check Available
function OnChangedUsername()
{
	if(document.form1.newuserid.value == "")
		{
			document.form1.btnCheckAvailability.disabled = true;
		}
	else
	{
		document.form1.btnCheckAvailability.disabled = false;
	}
}
function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = createRequestObject();

function sndReq(fvalue,page,base) {
	var contenedor;
	contenedor = document.getElementById(base);
	http.open('get', 'ajax/ajax_'+page+'.asp?'+fvalue);
	if (page=='codigoEan') http.onreadystatechange = function()	 {
							if(http.readyState == 4){
									var response = http.responseText;
									var update = new Array();
						
									if(response.indexOf('|' != -1)) {
										update = response.split('|');
										contenedor.innerHTML = update[0];			
									}
							}
	}
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4){
		var response = http.responseText;
		var update = new Array();

		if(response.indexOf('|' != -1)) {
			update = response.split('|');
			document.getElementById("username_chk").innerHTML = update[0];
		}
	}
}
function handleResponseNIF() {
	if(http.readyState == 4){
		var response = http.responseText;
		var update = new Array();

		if(response.indexOf('|' != -1)) {
			update = response.split('|');
			document.getElementById("nif_chk").innerHTML = update[0];
		}
	}
}
function handleResponseEMAIL() {
	if(http.readyState == 4){
		var response = http.responseText;
		var update = new Array();

		if(response.indexOf('|' != -1)) {
			update = response.split('|');
			document.getElementById("email_chk").innerHTML = update[0];
		}
	}
}

function doLogin(client_alias,client_password) {

	url = document.location.href ;
	
	// División en trozos con la barra como delimitador.

	partes = url.split('?');
	
	// Obtención del nombre de la página y sus parámetros.
	if (partes[0]!= url){
		if(partes[1].split('=')[0] == "rid") {
		document.frmlogin.action = '/asp/proxyflash.asp?cmd=cliente_login&client_alias='+client_alias+'&client_password='+client_password+'&vurl='+partes[0]+'&params='+partes[1]	
		}else{	
			document.frmlogin.action = '/asp/proxyflash.asp?cmd=cliente_login&client_alias='+client_alias+'&client_password='+client_password+'&vurl='+partes[0]
		}
	}else{
		document.frmlogin.action = '/asp/proxyflash.asp?cmd=cliente_login&client_alias='+client_alias+'&client_password='+client_password+'&vurl='+partes[0]
	}

	
	document.frmlogin.submit()

}

function clearCombos(combo) {
	
	var selObj = document.getElementById(combo);
	selObj.selectedIndex = 0;
}

function showHide(imgDiv){
	//create an object reference to the div containing images
	var oimageDiv=document.getElementById(imgDiv)
	var oimageLoadingDiv=document.getElementById("divloading")
	//set display to inline if currently none, otherwise to none
	oimageDiv.style.display=(oimageDiv.style.display=='none')?'inline':'none'
	oimageLoadingDiv.style.display=(oimageDiv.style.display=='none')?'inline':'none'

} 


function openCondiciones()
{
	myLightWindow.activateWindow({
		href: 'popup-condiciones-generales.asp',
		width: 399,
		height: 243
	});
}

function replaceT(obj){
	var newO=document.createElement('input');
	newO.setAttribute('type','password');
	newO.setAttribute('name',obj.getAttribute('name'));
	obj.parentNode.replaceChild(newO,obj);
	//setTimeout("newO.focus();", 10);
}
