//Copyright 2000-2002 PortugalGay.PT - All Rights Reserved
var error_found=false;
var g_lang='';

//function errortrap(msg,url,line){error_found=true;return false;}onerror=errortrap;

function sv_r0(id) {
	var t = "; " + document.cookie + ";";
	var t2 = '; PG_VOTES' + id + '='
	var p1 = t.indexOf(t2);
	if (p1>=0) {
		var p2 = t.indexOf(";", p1+1);
		return t.substring(p1+t2.length, p2);
	}
	return '';
}

function sv_idx(id) {
	if (parseInt(id)!=id) return 'A';
	if (id<500) return 'A';
	if (id<1000) return 'B';
	if (id<1500) return 'C';
	if (id<2000) return 'D';
}

function sv_r(id) {
	var t1 = sv_r0(sv_idx(id))+"*";
	t2 = '*' + id + ":"
	var p1 = t1.indexOf(t2);
	if (p1>=0) {
		var p2 = t1.indexOf("*", p1+1);
		return t1.substring(p1+t2.length, p2);
	}
	return '';
}

function sv_w(id, v) {
	var t0 = sv_r0(sv_idx(id))+"*";
	var t1 = "PG_VOTES"+sv_idx(id);
	var t2 = "*" + id + ":";
	var tx = ""
	var p1 = t0.indexOf(t2);
	if (p1>=0) {
		var p2 = t0.indexOf("*", p1+1);
		tx = t0.substring(0, p1)+t0.substring(p2, t0.length-1) + t2 + v
	} else {
		tx = t0.substring(0, t0.length-1) + t2 + v
	}
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = t1+"="+tx+expires+"; path=/";
}

function sv_xall() {
	var date = new Date();
	var expires = "; expires="+date.toGMTString();
	document.cookie = "PG_VOTESA=;"+expires+"; path=/";
	document.cookie = "PG_VOTESB=;"+expires+"; path=/";
	document.cookie = "PG_VOTESC=;"+expires+"; path=/";
	document.cookie = "PG_VOTESD=;"+expires+"; path=/";
}

function sv_x(id) {
	var t0 = sv_r0(sv_idx(id))+"*";
	var t1 = "PG_VOTES"+sv_idx(id);
	var t2 = "*" + id + ":";
	var tx = ""
	var p1 = t0.indexOf(t2);
	if (p1>=0) {
		var p2 = t0.indexOf("*", p1+1);
		tx = t0.substring(0, p1)+t0.substring(p2, t0.length-1)
	  	var date = new Date();
	  	date.setTime(date.getTime()+(24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	  	document.cookie = t1+"="+tx+expires+"; path=/";
	}
}

function sv5(id){g_lang=id;document.write('<img src=/g_v_'+id+'.gif class="noprint" style="float:right;position:relative;left:10px;" /><br style=\"clear:right;\" />');}

function sv4(id2){
	var id0 = Math.floor(id2/10); var id1 = id2%10; var v=parseInt(sv_r(id0));
	for (var i=1;i<=5;i++) {
		var s = 'document.v' + id0 + i + '.src=\'/x_';
		if (v == i) s= s+'yes';
		else s= s+'no';
		s = s+ '.gif\';'; eval(s);
	}}
function sv3(id2){
	id0 = Math.floor(id2/10);id1 = id2%10;
	sv_w(id0,id1);
	for (var i=1;i<=5;i++) {
		var s = 'document.v' + id0 + i + '.src=\'/x_';
		if (id1 == i) {
			if (sv_r(id0)!=i) {s=s+'yes';}
			else {s=s+'no';}
		} else {s=s+'no';}
		s = s+ '.gif\';';	eval(s);
	}
	if (sv_r('F')=='') {
		if (g_lang=='') alert('Escolheu o seu primeiro voto.\n\nSelecione os votos que pretender em todo o directório e no final escolha o link [Guardar Votos] no topo de qualquer uma das páginas do directório.\n\n\Só nessa altura é que os seus votos são enviados para o nosso servidor, e não os poderá modificar a partir desse momento.');
		if (g_lang=='uk') alert('You have made your first selection.\n\nYou may browse the directory and mark your selections, after that click the [Register Votes] link at the top of any of the directory pages.\n\n\Only then your choices will be sent to our servers and you will not be able to change them afterwards.');
		if (g_lang=='es') alert('Has hecho tu primera selección.\n\nPuedes hojear el directorio y marcar tus selecciones, después pincha el enlace [Registrar Voto] en la parte superior de cualquier página en el directorio.\n\n\Solamente entonces tus opciones serán enviadas a nuestros servidores y no podrás cambiarlas después.');
		sv_w('F',1);
	}
	}
function sv2(id2){
	id0 = Math.floor(id2/10);id1 = id2%10;
	for (var i=1;i<=5;i++) {
		var s = 'document.v' + id0 + i + '.src=\'/x_';
		if (id1 == i) s= s+'yes'; else s= s+'no';
		s = s+ '.gif\';'; eval(s);
	}}

function sv6(id) {
	sv_x(id);
}

function sv1(id,curV,n){
	var p = location + '';px = p.indexOf('print.asp');
	var v = parseInt(sv_r(id));
	var m=parseInt(sv_r('m'));
	if (isNaN(m)) {
		m=3;
		sv_w('m','3');
	}
	if (!sv_test()) m=2;

	document.write('<div class="noprint" id="vx_' + id + '" style="float:right;width:50px;height:31px;border:1px;background:url(/x_');
	if (m==2) {
		document.write('l');
	} else {
		document.write('b');
	}
	document.write('.gif);overflow:hidden;padding: 13px 0px 6px 1px; font: 8pt arial;">');
	if (curV>0) {
	document.write('<div style="width:' + (curV*4) + 'px;height:9px;background:url(/x_1.gif); margin-bottom: 1px;"></div>');
	} else {
	document.write('<div style="width:1px;height:9px; margin-bottom: 1px;"></div>');
	}

	for (var i=1;i<=5;i++) {
	if (m==3) document.write('<a href=\'javascript:\' onmouseout=\'sv4('+((id*10)+i)+')\' onDblclick=\'sv6('+(id)+');return false;\' onclick=\'sv3('+((id*10)+i)+');return false;\' onmouseover=\'sv2('+((id*10)+i)+')\'>');
	document.write('<img name="v'+((id*10)+i)+'" src="/x_')
	if (v==i)
		document.write ('yes');
	else
		document.write ('no');
	document.write ('.gif" />');
	document.write('</a>');
	}
	document.write('<div style="text-align: center;');
	if (n==0) document.write('color:#808080;');
	document.write('">');
	if (g_lang=='' || g_lang=='es') {	if (n==1) document.write('1 voto'); else document.write( n + ' votos'); }
	if (g_lang=='uk') {	if (n==1) document.write('1 vote'); else document.write( n + ' votes'); }
	document.write('</div></div>');
}

function sv_test() {
	sv_w('T',1);
	var t=sv_r('T');
	if (typeof(t)=='undefined') return false;
	if (t!=1) return false;
	return true;
}
