/*** Redirection ***/
/*$(window).load(
	function(){
		$('a.link_out').bind("click", function(){
				alert("click");
				url = $(this).attr("href");
				window.location = "link.php?link=" + url;
				return false;
			}
		);
	}
);*/
/************* INDEX FUNCTIONS **************/
bo1 = 0;
bo2 = 0;
Reload = 0;
available = false;
desc = 0;
stopped = false;
cnt_bo = 0;
function mueveReloj(){
  if(eval("document.form_clock")){
	if(bo1==0){
		bo1 = 1;
		year = document.form_clock.host_year.value;
		month = document.form_clock.host_month.value;
		day = document.form_clock.host_day.value;
		hour = document.form_clock.host_hour.value;
		minute = document.form_clock.host_minute.value;
		second = document.form_clock.host_second.value;
	}
	if((year%4 == 0 && year%100 != 0) || year%400 == 0){
			mf = 29;
	}else{
			mf = 28;
	}
	mlen = new Array(31,mf,31,30,31,30,31,31,30,31,30,31);
	mstr = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	//mstr = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	if(second<59){
		second++;
	}else{
		second = 0;
		if(minute<59){
			minute++;
		}else{
			minute = 0;
			if(hour<23){
				hour++;
			}else{
				hour = 0;
				if(day<mlen[month-1]){
					day++;
				}else{
					day = 1;
					if(month!=12){
						month++;
					}else{
						month = 1;
						year++;
					}
				}
			}
		}
	}
    if (second < 10){
       second = "0" + second*1;
    }
    if (minute < 10){
       minute = "0" + minute*1;
    }
    if (hour < 10){
       hour = "0" + hour*1;
    }
	/*if(day==1||day==11||day==21||day==31){
		term = "st";
	}else if(day==2||day==12||day==22){
		term = "nd";
	}else if(day==3||day==13||day==23){
		term = "rd";
	}else{
		term = "th";
	}*/
    dTime = hour + " : " + minute + " : " + second;
	dDate = day*1 + " de " + mstr[month-1] + " de " + year;
	//dDate = day*1 + term + " of " + mstr[month-1] + " " + year;
    document.form_clock.host_time.value = dTime;
	document.form_clock.host_date.value = dDate;
  }
  if(eval("document.f1")){
/******* Auction Time Counter *******/
	if(bo2==0){
		bo2 = 1;
		var c = document.f1.jinitial.value;
		var lt = 0;
		var ct = 0;
		rank = new Array();
		days = new Array();
		hours = new Array();
		minutes = new Array();
		seconds = new Array();
		for(c=document.f1.jinitial.value*1;c<=document.f1.jfinal.value*1;c++){
			if(hours_ev = eval("document.f1.hours"+c)){
				days_ev = eval("document.f1.days"+c);
				minutes_ev = eval("document.f1.minutes"+c);
				seconds_ev = eval("document.f1.seconds"+c);
				rank[lt] = c;
				days[lt] = days_ev.value;
				hours[lt] = hours_ev.value;
				minutes[lt] = minutes_ev.value;
				seconds[lt] = seconds_ev.value;
				lt++;
			}
		}
		//CANCEL PAYMENT & CHECK PAID OFFER
		if(eval("document.f1.stop") && canc==false){
			canc = true;
			//CANCEL
			if(document.f1.logged_client.value!=window.parent.document.f1.logged_user.value){
				document.f1.cancel.value = "cancel";
			}
			disableOffer();
			//PAID OFFER
			//alert("if("+document.f1.last_candidate.value+"=="+window.parent.document.f1.current_candidate.value+" && "+document.f1.last_offerdate.value+"=="+window.parent.document.f1.current_offerdate.value+" && "+window.parent.document.f1.newOffer_status.value+"!="+document.f1.last_offerdate.value+" && "+document.f1.new_offer_candidate.value+"=="+document.f1.logged_client.value+"){");
			// && window.parent.document.f1.newOffer_status.value!=document.f1.last_offerdate.value && 
			if(document.f1.new_offer_candidate.value==document.f1.logged_client.value && document.f1.last_valid1_candidate.value==window.parent.document.f1.first_valid0_candidate.value && document.f1.last_valid1_offerdate.value==window.parent.document.f1.first_valid0_offerdate.value){
				newAuctionOffer();
			}
		}		
	}
	cd = false;
	for(var p=0;p<rank.length;p++){
		if(ev = eval("document.f1.pdays" + rank[p])){
			cd = true;
			cd_num = rank[p];
		}
	}
	if(ev = eval("document.f1.hours01")){
		al = true;
		r = rank.length+1;
		days[rank.length] = document.f1.days01.value;
		hours[rank.length] = document.f1.hours01.value;
		minutes[rank.length] = document.f1.minutes01.value;
		seconds[rank.length] = document.f1.seconds01.value;
	}else if(cd){
		if(eval("document.f1.stop")){
			al = true;
			cd = true;
			r = rank.length+1;
			days[rank.length] = eval("document.f1.pdays" + cd_num).value;
			hours[rank.length] = eval("document.f1.phours" + cd_num).value;
			minutes[rank.length] = eval("document.f1.pminutes" + cd_num).value;
			seconds[rank.length] = eval("document.f1.pseconds" + cd_num).value;
		}
	}else{
		al = false;
		r = rank.length;
		//alert(r);
	}
	for(var ct=0;ct<r;ct++){
		if(al){
			if(ct==(r-1)){
				if(cd){
					ldays_ev = eval("document.f1.pdays" + cd_num);
					lhours_ev = eval("document.f1.phours" + cd_num);
					lminutes_ev = eval("document.f1.pminutes" + cd_num);
					lseconds_ev = eval("document.f1.pseconds" + cd_num);
				}else{
					ldays_ev = eval("document.f1.days01");
					lhours_ev = eval("document.f1.hours01");
					lminutes_ev = eval("document.f1.minutes01");
					lseconds_ev = eval("document.f1.seconds01");
				}
			}else{
				ldays_ev = eval("document.f1.days"+rank[ct]);
				lhours_ev = eval("document.f1.hours"+rank[ct]);
				lminutes_ev = eval("document.f1.minutes"+rank[ct]);
				lseconds_ev = eval("document.f1.seconds"+rank[ct]);
			}
		}else{
			ldays_ev = eval("document.f1.days"+rank[ct]);
			lhours_ev = eval("document.f1.hours"+rank[ct]);
			lminutes_ev = eval("document.f1.minutes"+rank[ct]);
			lseconds_ev = eval("document.f1.seconds"+rank[ct]);
		}
		if(!(ldays_ev.value==0 && lhours_ev.value==0 && lminutes_ev.value==0 && lseconds_ev.value==0) || !eval("document.f1.reload")){
			seconds[ct]--;
		}else{
			if(eval("document.f1.stop")){
				/* Constants */
				Price = window.parent.document.f1.Price;
				incr = window.parent.document.f1.incr;
				decr = window.parent.document.f1.decr;
				btn = window.parent.document.f1.submitOffer;
				status = window.parent.document.f1.status;
				tick = window.parent.document.f1.tick;
				client = window.parent.document.f1.logged_user;
				notify = window.parent.document.f1.notify;
				notify_left = window.parent.document.f1.notify_left;
				label1 = window.parent.document.f1.label1;
				label2 = window.parent.document.f1.label2;
				label3 = window.parent.document.f1.label3;
				candidate1 = document.f1.candidate1;
				candidate2 = document.f1.candidate2;
				display_ev2 = window.parent.document.f1.displayLeftTime;
				/*************/
				if(client.value==candidate1.value){
					available = true;
					if(window.parent.document.f1.pay_status.value==0){
						Price.disabled = true;
						incr.disabled = true;
						decr.disabled = true;
						incr.style.backgroundColor = "#999999";
						decr.style.backgroundColor = "#999999";
					}
					btn.disabled = true;
					btn.style.backgroundColor = "#999999";
					status.value = "Se ha terminado el plazo para realizar el pago.";
					label1.style.color = "#999999";
					label2.style.color = "#999999";
					display_ev2.value = "0 días 00:00:00";
					display_ev2.style.color = "#999999";
					tick.src = "image/cross.gif";
					document.getElementById("loader1").style.width = "0%";
					document.location.reload();
				}else if(client.value==candidate2.value){
					btn.disabled = false;
					btn.style.backgroundColor = "#56748C";
					status.value = "Usted ya puede realizar su oferta vía PayPal.";
					notify_left.disabled = true;
					label1.style.color = "#999999";
					label2.style.color = "#999999";
					label3.style.color = "#999999";
					notify.disabled = true;
					tick.src = "image/tick.gif";
				}else{
					btn.disabled = true;
					btn.style.backgroundColor = "#999999";
				}
				document.location.reload();
			}
		}
		if(seconds[ct]>=0){
			lseconds_ev.value = seconds[ct];
		}else{
			lseconds_ev.value = 59;
			seconds[ct] = 59;
			minutes[ct]--;
			if(minutes[ct]>=0){
				lminutes_ev.value = minutes[ct];
			}else{
				lminutes_ev.value = 59;
				minutes[ct] = 59;
				hours[ct]--;
				if(hours[ct]>=0){
					lhours_ev.value = hours[ct];
				}else{
					lhours_ev.value = 23;
					hours[ct] = 23;
					days[ct]--;
					if(days[ct]>=0){
						ldays_ev.value = days[ct];
					}else{
						ldays_ev.value = 0;
						Reload = 1;
						document.location.reload();
					}
				}
			}
		}
		//mail notifying
		notify_opt = window.parent.document.f1.notify_left;
		client = window.parent.document.f1.logged_user;
		if(eval("window.parent.document.f1.notify") && nd && al){
			if(ct<rank.length){
				candidate = eval("document.f1.candidate" + rank[ct]);
			}
			if(client.value==candidate.value){				
				for(var n=0;n<notify_opt.options.length;n++){
					if((notify_opt.options[n].value*1>lminutes_ev.value*1) && (lhours_ev.value*1==0)){
						if(notify_opt.options.length>1){
							if(notify_opt.value==notify_opt.options[n].value*1){
								notify_opt.value = notify_opt.options[n-1].value*1;
							}
							notify_opt.options[n] = null;
						}
					}
				}
				if(window.parent.document.f1.notify.checked==true && window.parent.document.f1.send_email.value==0){
					sec = lminutes_ev.value*60 - (-1)*lseconds_ev.value;
					if((Math.abs(sec - notify_opt.value*60)<10) && (lhours_ev.value*1==0)){
						window.parent.document.f1.send_email.value = 1;
						notify = window.parent.document.f1.notify;
						notify_left = window.parent.document.f1.notify_left;
						label1 = window.parent.document.f1.label1;
						label2 = window.parent.document.f1.label2;
						label3 = window.parent.document.f1.label3;
						notify_left.disabled = true;
						label1.style.color = "#999999";
						label2.style.color = "#999999";
						label3.style.color = "#999999";
						notify.disabled = true;
						pday = new Date();
						id = pday.getTime();
						URL = "aviso.php?client=" + client.value + "&left=" + notify_opt.value + "&offer=" + window.parent.document.f1.amount.value + "&rank=" + window.parent.document.f1.rank.value;
						eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=450,height=300,left=240,top=180');");
					}
				}
			}
		}
		if(lhours_ev.value<10){
			lhours_ev.value = "0"+lhours_ev.value*1;
		}
		if(lminutes_ev.value<10){
			lminutes_ev.value = "0"+lminutes_ev.value*1;
		}
		if(lseconds_ev.value<10){
			lseconds_ev.value = "0"+lseconds_ev.value*1;
		}
		if(ldays_ev.value==1){
			days_str = "día";
		}else{
			days_str = "días";
		}
		if(al){
			if(ct==(r-1)){
				if(cd){
					display_ev = eval("window.parent.document.f1.displayLeftTime");
				}else{
					display_ev = eval("document.f1.displayLeftTime01");
				}
			}else{	
				display_ev = eval("document.f1.displayLeftTime"+rank[ct]);
			}
		}else{	
			display_ev = eval("document.f1.displayLeftTime"+rank[ct]);
		}
		if(Reload==0){
			if(eval("document.f1.stop")){
				display_ev.value = ldays_ev.value + " " + days_str + " " + lhours_ev.value + ":" + lminutes_ev.value + ":" + lseconds_ev.value;
				if(!cd){
					candidateX = eval("document.f1.candidate" + rank[ct]);
					if(client.value==candidateX.value){
						display_ev2 = eval("window.parent.document.f1.displayLeftTime");
						display_ev2.value = ldays_ev.value + " " + days_str + " " + lhours_ev.value + ":" + lminutes_ev.value + ":" + lseconds_ev.value;
					}
				}
			}else{
				if(eval("document.f1.nocountdown")){
				}else{
					display_ev.value = ldays_ev.value + " " + days_str + " " + lhours_ev.value + ":" + lminutes_ev.value + ":" + lseconds_ev.value;
				}
			}
		}else{
			if(eval("document.f1.stop")){
				display_ev2.value = "Recargando!";
			}else{
				display_ev.value = "Recargando!";
			}
		}
	}
	nd = true;
  }
  main_to = window.setTimeout("mueveReloj()",1000);
}
function newAuctionOffer(){
	min_offer = document.f1.last_price.value*1 + document.f1.inc.value*1;
	new_offer = prompt("AVISO DE NUEVA OFERTA en subasta de rank " + document.f1.rank.value + ":\n\n" + document.f1.last_valid1_candidate.value + " ha realizado una oferta de €" + document.f1.last_price.value + " EUR.\n\nPor favor introduzca su nueva oferta.\n(el valor debe ser igual o superior a " + min_offer + "€)",min_offer);
	if(new_offer*1>=min_offer){
		//new offer
		window.parent.document.f1.newOffer_status.value = 1;
		window.parent.document.f1.first_valid0_candidate.value = document.f1.first_valid0_candidate.value;
		window.parent.document.f1.first_valid0_offerdate.value = document.f1.first_valid0_offerdate.value;	
		newOffer2(new_offer*1,document.f1.inc.value*1,document.f1.percent.value*1);
		with(window.parent.document.f1){
			if(pay_status.value==0){
				pay_status.value = 1;
			}
			Price.disabled = true;
			incr.disabled = true;
			decr.disabled = true;
			incr.style.backgroundColor = "#999999";
			decr.style.backgroundColor = "#999999";
		}
		document.location = "cola.php?id=" + new Date().getTime() + "&rank=" + document.f1.rank.value + "&newoffer=" + new_offer;
	}else{
		if(confirm("Debe incrementar su oferta " + document.f1.inc.value + "€ como mínimo.\n\nPara reintroducir el valor de su nueva oferta pulse \"Aceptar\".\nSi de lo contrario quiere cancelar su oferta y abandonar esta subasta, pulse \"Cancelar\".")){
			newAuctionOffer();
		}else{
			CancelPayment(document.f1.logged_client.value,document.f1.logged_num.value);
		}
	}
}
function disableOffer(){
	cancel_cand = document.f1.cancel.value;
	
	//disable
	if(cancel_cand!="" || cancel_cand=="cancel"){
		window.parent.document.f1.Price.disabled = true;
		if(cancel_cand==window.parent.document.f1.logged_user.value || cancel_cand=="cancel"){
			with(window.parent.document.f1){
				if(pay_status.value==0){
					Price.disabled = true;
					incr.disabled = true;
					decr.disabled = true;
					incr.style.backgroundColor = "#999999";
					decr.style.backgroundColor = "#999999";
				}
				submitOffer.disabled = true;
				submitOffer.style.backgroundColor = "#999999";
				if(cancel_cand=="cancel"){
					status.value = "Inicie sesión correctamente. Gracias.";
					tick.src = "image/alert.gif";
				}else{
					status.value = "Su oferta ha sido cancelada con éxito.";
					tick.src = "image/cross.gif";
				}
				label1.style.color = "#999999";
				label2.style.color = "#999999";
				displayLeftTime.value = "0 días 00:00:00";
				displayLeftTime.style.color = "#999999";
				back_btn.style.backgroundColor = "#999999";
				back_btn.disabled = true;
				label1.style.color = "#999999";
				label2.style.color = "#999999";
				if(eval("window.parent.document.f1.notify_left")){
					notify_left.disabled = true;
					label3.style.color = "#999999";
					notify.disabled = true;
				}
			}
		}
	//enable
	}else{		
		client = window.parent.document.f1.logged_user;
		candidate1 = document.f1.candidate1;
		/*************/
		with(window.parent.document.f1){
			if(pay_status.value==0){
				Price.disabled = false;
				incr.disabled = false;
				decr.disabled = false;
				incr.style.backgroundColor = "#56748C";
				decr.style.backgroundColor = "#56748C";
			}
			if(submitOffer.disabled){
				if(client.value==candidate1.value){
					submitOffer.disabled = false;
					submitOffer.style.backgroundColor = "#56748C";
					status.value = "Usted ya puede realizar su oferta vía PayPal.";
					tick.src = "image/tick.gif";
					label1.style.color = "#999999";
					label2.style.color = "#999999";
					if(eval("window.parent.document.f1.notify_left")){
						notify_left.disabled = true;
						label3.style.color = "#999999";
						notify.disabled = true;
					}
				}else{
					//status.value = "Su oferta ha sido reanudada con éxito.";
					//tick.src = "image/cross.gif";
					if(eval("window.parent.document.f1.notify_left")){
						notify_left.disabled = false;
						notify.disabled = false;
						label1.style.color = "#000000";
						label2.style.color = "#000000";
						label3.style.color = "#000000";
					}
				}
				displayLeftTime.style.color = "#888888";
				back_btn.style.backgroundColor = "#56748C";
				back_btn.disabled = false;
			}
		}	
	}
}
inic = 0;
function refreshQueue(){
	document.location = "cola.php?id=" + new Date().getTime() + "&rank=" + document.f1.rank.value;
	window.clearTimeout(refresh_queue);
}
nd = false;
function Queue(m){
	//current
	cCandidate = document.f1.currentCandidate.value;
	if(cCandidate!="-"&&cCandidate!=""&&cCandidate!="Null"&&cCandidate!="NULL"){
		window.parent.document.f1.currentOffer.style.color = "#000000";
	}else{
		window.parent.document.f1.currentOffer.style.color = "#888888";
	}
	window.parent.document.f1.currentOffer.value = document.f1.currentOffer.value;
	window.parent.document.f1.currentCandidate.value = cCandidate;
	//last
	window.parent.document.f1.lastOffer.value = document.f1.lastOffer.value;
	window.parent.document.f1.lastCandidate.value = document.f1.lastCandidate.value;
	if(document.f1.ast.value==1){
		window.parent.document.f1.ast.value = "*";
	}else{
		window.parent.document.f1.ast.value = "";
	}
	if(inic==0){
		inic = 1;
		canc = false;
		mueveReloj();
		showProgress(m);
	}
	refresh_queue = window.setTimeout("refreshQueue()",1000*window.parent.document.f1.refresh_sel.value);
}
function setCookie(name,values,path,domain,exp_years){
	now = new Date();
	expires = new Date(now.getFullYear()+exp_years, now.getMonth(), now.getDay());
	document.cookie=name+ "=" +escape(values)+((path==null)?"":";path=" + path)+((domain==null)?"":";domain="+domain)+((expires==null)?"":";expires="+expires.toGMTString());
}
function delCookie(name,path,domain){
	if(getCookie(name)){
		document.cookie=name+"="+((path==null)?"":";path="+path)+((domain==null)?"":";domain="+domain)+";expires=Thu,01-Jan-70 00:00:01 GMT";
	}
}
function getCookie(name){
	var cname=name + "=";
	var dc=document.cookie;
	if(dc.length>0){
		begin=dc.indexOf(cname);
		if(begin!=-1){
			begin+=cname.length;
			end=dc.indexOf(";",begin);
			if(end==-1){
				end=dc.length;
			}
			return(dc.substring(begin,end));
		}
	} 
}	
function showProgress(m){
	init = document.f1.jinitial.value;
	fin = document.f1.jfinal.value;
	for(var i=init;i<=fin;i++){
		status = eval("document.f1.status" + i);
		total = eval("document.f1.total" + i);
		bdays = eval("document.f1.days" + i);
		bhours = eval("document.f1.hours" + i);
		bminutes = eval("document.f1.minutes" + i);
		bseconds = eval("document.f1.seconds" + i);
		sec = bdays.value*24*3600 + bhours.value*3600 + bminutes.value*60 + bseconds.value*1;
		if(status.value==1){
			percent = (sec/total.value)*100;
			document.getElementById("loader" + i).style.width = percent + "%";
		}else if(status.value==0){
			sec -= m*60;
			percent = (1 - sec/total.value)*100;
			document.getElementById("loader" + i).style.width = percent + "%";
		}
	}
	spto = window.setTimeout("showProgress("+m+")",1000);
}
//cancel from the frame button
function CancelPayment(ord,num){
	if(confirm("¿Está seguro que quiere cancelar su oferta?")){
		url_ev = "cola.php?id=" + new Date().getTime() + "&rank=" + document.f1.rank.value + "&cancel=" + ord;
		document.location = url_ev;
		with(window.parent.document.f1){
			if(pay_status.value==0){
				Price.disabled = true;
				incr.disabled = true;
				decr.disabled = true;
				incr.style.backgroundColor = "#999999";
				decr.style.backgroundColor = "#999999";
			}
			displayLeftTime.value = "0 días 00:00:00";
			status.value = "Su oferta ha sido cancelada con éxito."
			tick.src = "image/cross.gif";
			submitOffer.style.backgroundColor = "#999999";
			submitOffer.disabled = true;
			back_btn.style.backgroundColor = "#999999";
			back_btn.disabled = true;
			label1.style.color = "#999999";
			label2.style.color = "#999999";
			if(eval("window.parent.document.f1.notify_left")){
				notify_left.disabled = true;
				label3.style.color = "#999999";
				notify.disabled = true;
			}
		}
		if(num!=0){
			offer_ev = eval("document.f1.offer" + num);
			candidate_ev = eval("document.f1.candidate" + num);
			window.parent.document.f1.lastOffer.value = offer_ev.value;
			window.parent.document.f1.lastCandidate.value = candidate_ev.value;
		}else{
			window.parent.document.f1.lastOffer.value = "0.00";
			window.parent.document.f1.lastCandidate.value = "-";
		}
	}
}
//cancel from the document button
function CancelPayment2(ord,num){
	if(confirm("¿Está seguro que quiere cancelar su oferta?")){
		url_ev = "cola.php?id=" + new Date().getTime() + "&rank=" + document.f1.rank.value + "&cancel=" + ord;
		window.parent.if1.document.location = url_ev;
		with(document.f1){
			if(pay_status.value==0){
				Price.disabled = true;
				incr.disabled = true;
				decr.disabled = true;
				incr.style.backgroundColor = "#999999";
				decr.style.backgroundColor = "#999999";
			}
			displayLeftTime.value = "0 días 00:00:00";
			status.value = "Su oferta ha sido cancelada con éxito."
			tick.src = "image/cross.gif";
			submitOffer.style.backgroundColor = "#999999";
			submitOffer.disabled = true;
			back_btn.style.backgroundColor = "#999999";
			back_btn.disabled = true;
			label1.style.color = "#999999";
			label2.style.color = "#999999";
			if(eval("document.f1.notify_left")){
				notify_left.disabled = true;
				label3.style.color = "#999999";
				notify.disabled = true;
			}
		}
		if(num!=0){
			offer_ev = eval("window.parent.if1.document.f1.offer" + num);
			candidate_ev = eval("window.parent.if1.document.f1.candidate" + num);
			document.f1.lastOffer.value = offer_ev.value;
			document.f1.lastCandidate.value = candidate_ev.value;
		}else{
			document.f1.lastOffer.value = "0.00";
			document.f1.lastCandidate.value = "-";
		}
	}
}
function InfoPayment(rank,candidate){
	id = new Date().getTime();
	URL = "info.php?rank=" + rank + "&candidate=" + candidate;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=420,height=390,left=240,top=180');");
}
function inc(b,d){
	if(b!=0){
		val1 = eval("document.f1.val"+b);
		val1.value -= -d;
		document.f1.K.value = b;
	}else{
		document.f1.Price.value -= -d;
		newOffer(document.f1.Price,d,percent);
	}
}
function dec(b,d){
	val2 = eval("document.f1.val"+b);
	min2 = eval("document.f1.price"+b);
	if(val2.value != min2.value){
		val2.value -= d;
		document.f1.K.value = b;
	}else{
		alert("No puede realizar una oferta inferior al precio inicial.");
	}
}
function inc2(percent,inc){
	if(document.f1.newOffer_status.value==0){
		document.f1.Price.value -= -inc;
		newOffer(document.f1.Price,inc,percent);
	}else{
		document.f1.Price.value -= -inc;
		//diff = document.f1.previous_offer.value - document.f1.Price.value;
		newOffer(document.f1.Price,inc,percent);
	}
}
function dec2(percent,inc){
	val2 = eval("document.f1.Price");
	min2 = eval("document.f1.initPrice");
	if(val2.value != min2.value){
		val2.value -= inc;
		newOffer(document.f1.Price,inc,percent);
	}else{
		alert("No puede realizar una oferta inferior al precio inicial.");
	}
}
function calc(rank,X){
	val3 = eval("document.f1.price"+rank);
	field = eval("document.f1.val"+X);
	val4 = eval("document.f1.mowner"+rank);
	owner = eval("document.f1.owner"+X);
	field.value = val3.value;
	if(val4.value != "NULL"){
		owner.value = val4.value;
	}else{
		owner.value = "Ninguno";
	}
	document.f1.K.value = rank;
}
function Offer(rank,inc,phase){
  if(document.f1.logged_user.value!="" && document.logout_form.error.value!=1){
   if(confirm("¿Desea realmente realizar una oferta en el rank " + rank + "?")){
	if(inc!=0){
		min2 = eval("document.f1.price"+rank);
		if(phase==1){
			val = eval("document.f1.val"+rank);
			if(((val.value-min2.value) >= inc)){
				if(val.value != undefined && val.value != ""){
					document.f1.K.value = rank;
					document.f1.submit();
				}else{
					alert("Introduzca su nueva oferta por favor.");
				}
			}else{
				alert("Debe incrementar su oferta "+inc+" € como mínimo.");
			}
		}else if(phase==2){
			val = document.f1.Price.value;
			if(((val - min2.value) >= inc)){
				if(val != undefined && val != ""){
					document.f1.K.value = rank;
					document.f1.amount.value = val;
					document.f1.Price.value = val;
					if(so_ev=eval("document.f1.submitOffer")){
						so_ev.style.backgroundColor = "#999999";
						so_ev.disabled = true;
					}
					document.f1.submit();
				}else{
					alert("Introduzca su nueva oferta por favor.");
				}
			}else{
				alert("Debe incrementar su oferta "+inc+" € como mínimo.");
			}
		}			
	}else{
		if(phase==1){
			val = eval("document.f1.val"+rank);
			if(val.value != undefined && val.value != ""){
				document.f1.K.value = rank;
				document.f1.submit();
			}else{
				alert("Introduzca su nueva oferta por favor.");
			}
		}else if(phase==2){
			val = document.f1.Price.value;
			val2 = document.f1.initPrice.value;
			if(val*1 >= val2*1){
			  if(!document.f1.noemail.checked && document.f1.billemail[1].checked && document.f1.other.value==""){
			  	alert("Introduzca su nueva cuenta de email o seleccione la opción\n\"Registro\" para seleccionar el email con el que se registró.");
			  }else{
				if(val != undefined && val != ""){
					document.f1.Price.value = val;
					if(so_ev=eval("document.f1.submitOffer")){
						so_ev.style.backgroundColor = "#999999";
						so_ev.disabled = true;
					}
					document.f1.submit();
				}else{
					alert("Introduzca su nueva oferta por favor.");
				}
			  }
			}else{
				alert("No puede realizar una oferta inferior al precio inicial.");
			}
		}else if(phase==-2){
			val = eval("document.f1.test"+rank);
			document.f1.K.value = rank;
			document.f1.submit();
		}
	}
   }//end confirm
  }else{
  	if(ev=eval("document.f1.test"+rank)){
		oper = "poder adquirir este rank.";
	}else{
		oper = "realizar una oferta.";
	}
  	alert('Debe identificarse con su nombre de usuario\ny contraseña para '+oper);
  }
}
function number_format(a){
	b = Math.round(a*100)/100;
	return b;
}
function newOffer(newoffer,inc,percent){
	newoffer = newoffer.value;
	if(document.f1.newOffer_status.value==1){
		deposit = (newoffer*(percent/100)).toFixed(2);
	}else if(document.f1.newOffer_status.value==2){
		deposit = ((newoffer*1 - document.f1.previous_offer.value*1)*(percent/100)).toFixed(2);
	}else if(document.f1.newOffer_status.value==0){
		deposit = (newoffer*(percent/100)).toFixed(2);
	}
	ideposit = deposit;
	setiva = false;
	if(document.f1.setiva.value==1){
		setiva = true;
		document.f1.iva.value = (deposit*document.f1.ivavalue.value/100).toFixed(2);
		if(setiva){
			deposit = (deposit - (-1)*document.f1.iva.value).toFixed(2);
		}
	}
	if(document.f1.newOffer_status.value==1){
		with(document.f1){
			Deposit.value = deposit;
			subDeposit.value = ideposit;
			amount.value = deposit;
			c4.value = deposit;
			if(billemail[0].checked){
				c5.value = registered_email.value;
			}else if(billemail[1].checked){
				c5.value = other.value;
			}
			bill = "";
			if(!noemail.checked){
				bill =  "-" + c5.value;
			}
			c0.value = newoffer;
			custom.value = c0.value + "-" + 2 + "-" + c2.value + "-" + c3.value + "-" + c4.value + bill;
		}
	}else if(document.f1.newOffer_status.value==2){
		document.f1.diff.value = (newoffer*1 - document.f1.previous_offer.value*1).toFixed(2);
		with(document.f1){
			Deposit.value = deposit;
			subDeposit.value = ideposit;
			amount.value = deposit;
			c4.value = deposit;
			if(billemail[0].checked){
				c5.value = registered_email.value;
			}else if(billemail[1].checked){
				c5.value = other.value;
			}
			bill = "";
			if(!noemail.checked){
				bill =  "-" + c5.value;
			}
			c0.value = newoffer;
			custom.value = c0.value + "-" + 2 + "-" + c2.value + "-" + c3.value + "-" + c4.value + bill;
		}
	}else if(document.f1.newOffer_status.value==0){
		with(document.f1){
			Deposit.value = deposit;
			subDeposit.value = ideposit;
			amount.value = deposit;
			c4.value = deposit;
			if(billemail[0].checked){
				c5.value = registered_email.value;
			}else if(billemail[1].checked){
				c5.value = other.value;
			}
			bill = "";
			if(!noemail.checked){
				bill =  "-" + c5.value;
			}
			c0.value = newoffer;
			custom.value = c0.value + "-" + c1.value + "-" + c2.value + "-" + c3.value + "-" + c4.value + bill;
		}
	}
	document.f1.submitOffer.value = "Realizar paga y señal de €"+deposit+" EUR vía PayPal";
}
function newOffer2(newoffer,inc,percent){
	newoffer = newoffer.value;
	setiva = false;
	if(window.parent.document.f1.setiva.value==1){
		setiva = true;
		window.parent.document.f1.iva.value = deposit*window.parent.document.f1.ivavalue.value/100;
		iva = document.f1.iva.value;
	}
	if(window.parent.document.f1.newOffer_status.value==1){
		deposit = (newoffer*(percent/100)).toFixed(2);
		with(window.parent.document.f1){
			Price.value = newoffer;
			Deposit.value = deposit;
			subDeposit.value = deposit;
			amount.value = deposit;
			c4.value = deposit;
			if(billemail[0].checked){
				c5.value = registered_email.value;
			}else if(billemail[1].checked){
				c5.value = other.value;
			}
			bill = "";
			if(!noemail.checked){
				bill =  "-" + c5.value;
			}
			c0.value = newoffer;
			custom.value = c0.value + "-" + 2 + "-" + c2.value + "-" + c3.value + "-" + c4.value + bill;
		}
	}else if(window.parent.document.f1.newOffer_status.value==2){
		deposit = ((newoffer*1 - window.parent.document.f1.previous_offer.value*1)*(percent/100)).toFixed(2);
		window.parent.document.f1.diff.value = (newoffer*1 - window.parent.document.f1.previous_offer.value*1).toFixed(2);
		with(window.parent.document.f1){
			Price.value = newoffer;
			Deposit.value = deposit;
			subDeposit.value = deposit;
			amount.value = deposit;
			c4.value = deposit;
			if(billemail[0].checked){
				c5.value = registered_email.value;
			}else if(billemail[1].checked){
				c5.value = other.value;
			}
			bill = "";
			if(!noemail.checked){
				bill =  "-" + c5.value;
			}
			c0.value = newoffer;
			custom.value = c0.value + "-" + 2 + "-" + c2.value + "-" + c3.value + "-" + c4.value + bill;
		}
	}else if(window.parent.document.f1.newOffer_status.value==0){
		deposit = (newoffer*(percent/100)).toFixed(2);
		with(window.parent.document.f1){
			Price.value = newoffer;
			Deposit.value = deposit;
			subDeposit.value = deposit;
			amount.value = deposit;
			c4.value = deposit;
			if(billemail[0].checked){
				c5.value = registered_email.value;
			}else if(billemail[1].checked){
				c5.value = other.value;
			}
			bill = "";
			if(!noemail.checked){
				bill =  "-" + c5.value;
			}
			c0.value = newoffer;
			custom.value = c0.value + "-" + c1.value + "-" + c2.value + "-" + c3.value + "-" + c4.value + bill;
		}
	}
	window.parent.document.f1.submitOffer.value = "Realizar paga y señal de €"+deposit+" EUR vía PayPal";
}
function Pages(page,form){
	Initialpage_eval = eval("document.pag"+form+".p");
	if(page*1!=1){
		Initialpage_eval.value = page;
	}else{
		document.location = "http://www.top100anuncios.com/";
	}
	submit_eval = eval("document.pag"+form);
	submit_eval.submit();
}
function Title(temp){
	submit_ev = eval("document.f1.submit"+temp);
	price_ev = eval("document.f1.val"+temp);
	submit_ev.title = "Hacer una oferta de €"+price_ev.value+" EUR";
}
function popUp(URL) {
	pday = new Date();
	id = pday.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=580,height=420,left=240,top=180');");
}
function popUp2(URL,X,Y) {
	if(X==""&&Y==""){
		X = 600;
		Y = 500;
	}
	pday = new Date();
	id = pday.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=" + X +",height=" + Y + ",left=240,top=180');");
}
function popUp3(URL,X,Y) {
	if(X==""&&Y==""){
		X = 800;
		Y = 600;
	}
	pday = new Date();
	id = pday.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=" + X +",height=" + Y + ",left=0,top=0');");
}
/*************** END INDEX FUNCTIONS **************/

/************* REGISTRATION FUNCTIONS *************/
function imageReload(){
	document.f.security_code.src = "securimage_show.php?id=" + new Date().getTime();
}
function check(limit) {
   if(document.f.title.value.length > limit) {
     alert('Demasiadas letras. Recorte la descripción por favor.');
     document.f.title.focus();
     return false; }
   else
     return true;
}
function update(limit) {
   var old = document.f.counter.value;
   document.f.counter.value=document.f.title.value.length;
   if(document.f.counter.value > limit && old <= limit) {
     alert('Demasiados caracteres en la descripción del sitio. Por favor borre '+(document.f.counter.value-limit)+' caracteres.');
     if(document.styleSheets) {
       document.f.counter.style.fontWeight = 'bold';
       document.f.counter.style.color = '#cc0000'; } }
   else if(document.f.counter.value <= limit && old > limit && document.styleSheets ) {
       document.f.counter.style.fontWeight = 'normal';
       document.f.counter.style.color = '#000000'; 
	} 
}
function check_http(inst){
	with(inst){
		if(value.indexOf("http://")!=-1){
			value = value.substr(value.indexOf("http://")+7);
		}
		if(value.indexOf("/")==0){
			value = "";
		}
	}
}
function check_url(inst){
	with(document.f){
		url_ev = eval("url"+inst);
		url_temp = url_ev.value;
		if(url_ev.value.indexOf("/")!=-1){
			Url = prompt("Debe introducir su sitio web solo con el dominio y no con secciones o subcarpetas. (p.e: \"www.google.com\" es correcto pero en cambio \"www.google.com/news/\" no lo es). La dirección de su sitio web se guardará como:",url_ev.value.substr(0,url_ev.value.indexOf("/")));
			url_ev.value = Url;
			if(Url!=""&&Url!=null&&url_ev.value.indexOf("/")==-1){
				return true;
			}else{
				url_ev.value = url_temp;
				return false;
			}
		}else{
			return true;
		}
	}
}
function send(limit,checked_urls){
	with(document.f){
		if(nickname.value!=""&&password.value!=""&&password2.value!=""&&email.value!=""&&realname.value!=""&&address.value!=""&&city.value!=""&&postalcode.value!=""&&country.value!=0&&telephonenumber.value!=""&&secretquiz.value!=""&&answer.value!=""&&code.value!=""){
			if(password.value==password2.value){
				c = 0;
				if(section.value=="register"){
					if(check_url(1)){
						c++;
					}
					if(c==1){
						if(terms.value==0){
							submit();
						}else{
							if(eval(accept)){
								if(accept.checked==true){
									submit();
								}else{
									alert("Debe aceptar las condiciones de uso para poder registrarse.");
								}
							}
						}
					}
				}else if(section.value=="affiliates"){
					for(i=1;i<=checked_urls;i++){
						if(check_url(i)){
							c++;
						}
					}
					if(c==checked_urls){
						if(terms.value==0){
							submit();
						}else{
							if(eval(accept)){
								if(accept.checked==true){
									submit();
								}else{
									alert("Debe aceptar las condiciones de uso para poder registrarse.");
								}
							}
						}
					}
				}
			}else{
				alert("Las contraseñas introducidas no coinciden entre si. Por favor reescríbalas otra vez.");
			}
		}else{
			alert("Rellene los campos obligatorios (*) antes de continuar con el registro.");
		}
	}
}
function Display(){
	window.parent.if1.document.location = "clientes/banner.php?link=" + document.f.bannerlink.value;
}
/*
function clearList(select,from,num)
  {
        var i;
        for(i=from+num-1; i>=from; i--) {
          select.options[i].text = '  ';
          select.options[i].value = 'va';
          select.options[i] = null;
        }
  }

  function fillAttrList(myselect)
  {
        var i,r,colNum,tbIndex;
        var tempCol= new String("");

        clearList(document.f.colnames,0,document.f.colnames.length);
        w = 0;
        for (k = 0; k < myselect.length; k++) { 
          if (myselect.options[k].selected) {
            tbIndex = k;
            colNum = eval("document.f.tb"+tbIndex.toString()+"_colnum.value");
            for (i=0; i<colNum; i++) {
              tempCol = eval("document.f.tb"+tbIndex.toString()+"_col"+i.toString()+".value");
              document.f.colnames.options[w]= new Option(tempCol, tempCol);
              w++;
            }
          }
        } 
  }
function add_to_list() {
	var origen = document.f.colnames;
	var destino = document.f.category;
	var j = origen.options.selectedIndex;
	while(j >= 0) {
		var len=destino.length;
		encontrado=0;
		for(var x = 0; x < destino.length; x++){
			if (origen.options[j].value==destino.options[x].value) {
				encontrado=1;
			}
		}
		if (!encontrado) {
			destino.options[destino.options.length] = new Option(origen.options[j].text,origen.options[j].value);
		}
		origen.options[j].selected = false;
		j = origen.options.selectedIndex;
	}
	return(true);
}
function del_of_list(destino) {
	for(var i = (destino.options.length-1); i >= 0; i--) {
		if (destino.options[i] != null && destino.options[i].selected) {
			destino.options[i] = null;
		}
	}
	return true;
}
function sel_all_list(lista) {
	for(var i = 0; i < lista.length; i++) {
		lista.options[i].selected=true;
	}
}
*/
/*********** END REGISTRATION FUNCTIONS ***********/

/*************** AFFILIATE FUNCTIONS **************/
function logIn(b,inst){
	if(inst==1){
		term = "_user";
	}else{
		term = "_affiliate";
	}
	if(b){
		logged_ev = eval("document.redirect_form"+inst+".logged"+term);
		logged_ev.value = 1;
		logout_ev = eval("document.redirect_form"+inst+".logout"+term);
		logout_ev.value = 1;
	}else{
		logged_ev = eval("document.redirect_form"+inst+".logged"+term);
		logged_ev.value = 0;
		logout_ev = eval("document.redirect_form"+inst+".logout"+term);
		logout_ev.value = 0;
	}
	form_ev = eval("document.redirect_form"+inst);
	form_ev.submit();
}
function logOut(){
	document.logout_form2.submit();
}
function linkTo(dest){
	location.href = dest;
}
/**************************************************/

function showLinearGraph(){
	document.f1.linear_graphic.src = "../line.php?user=" + document.f1.user.value + "&client=" + document.f1.linear_id.value;
	prompt("Orly?",document.f1.linear_graphic.src);
}
function ventanaSecundaria(URL){
window.open(URL,"ventana1","width=500, height=350, scrollbars=no, menubar=no, location=no, resizable=no")
}

//CONTACT FUNCTIONS
function showEmail(){
	document.f1.email_img.src = "image/" + document.f1.destination.value + ".jpg";
}
//
function descargar(url) {
window.onfocus = finalizada;
document.location = url;
}
function finalizada() {
window.onfocus = vacia;
// Modificar a partir de aquí
alert();
}
function vacia(){}
//
function showSearch(id){
	bannerlink = eval("document.search_form.search_bannerlink" + id);
	document.getElementById("search_img").src = "http://" + bannerlink.value;
}
/************* STYLE FUNCTIONS **************/
function cambiar_color_over(celda,id,idname,sel){
  if(eval(celda)){
	if(sel==2){
		sel = 0;
	}
	if(sel==1){
		bgcolor = "#FFFFFF";
		tcolor = "#DDDDDD";
	}else{
		bgcolor = "#DDDDDD";
		tcolor = "#56748C";
	}
	document.getElementById("table"+id).style.backgroundColor = bgcolor;
	celda.style.backgroundColor = bgcolor;
	document.getElementById(idname+id).style.color = tcolor;
  }
}
function cambiar_color_out(celda,id,idname,sel){
  if(eval(celda)){
	if(sel==2){
		sel = 0;
	}
	if(sel==1){
		bgcolor = "#FCFCF6";
		tcolor = "#BD484B";
	}else{
		bgcolor = "#38566E";
		tcolor = "#FFFFFF";
	}
   document.getElementById("table"+id).style.backgroundColor = bgcolor;
   celda.style.backgroundColor = bgcolor;
   document.getElementById(idname+id).style.color = tcolor;
  }
}
function showLight(){
	cell = document.getElementById('header_cell');
	//alert(cell.style.background);
	//cell.style.background = '#FFFFFF';
}
function hideLight(){
	cell = document.getElementById('header_cell');
	//cell.style.background = 'image/header.jpg';
}