// capa flotante activa con mouseover

var moz = document.getElementById && !document.all;
var difX = -50
var difY = 15

var maxstarts = 5;
var estrellas = new Array (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
function limpia_estrellas (n) {
	for (i=1; i<=maxstarts; i++) {
		document.getElementById('vot'+n+i+'neg').src = "/images/stargray.gif";
		document.getElementById('vot'+n+i).src = "/images/stargray.gif";
	}
	// pintamos por defecto lo que tengamos seleccionado
	if (estrellas[n] != 0) {
		var star = (estrellas[n] > 0) ? "/images/starpos.gif" : "/images/starneg.gif";
		var neg = (estrellas[n] > 0) ? "" : "neg";
		var max = (estrellas[n] > 0) ? estrellas[n] : estrellas[n]*-1;
		for (i=1; i<=max; i++) document.getElementById('vot'+n+i+neg).src = star;
	}
}
function cambia_estrellas (n,num,cual) {
	var star = (cual > 0) ? "/images/starpos.gif" : "/images/starneg.gif";
	var neg = (cual > 0) ? "" : "neg";	
	for (i=1; i<=num; i++) document.getElementById('vot'+n+i+neg).src = star;
	for (j=i; j<=maxstarts; j++) document.getElementById('vot'+n+j+neg).src = "/images/stargray.gif";
	for (i=1; i<=maxstarts; i++) {
		if (cual>0) document.getElementById('vot'+n+i+'neg').src = "/images/stargray.gif";
		else document.getElementById('vot'+n+i).src = "/images/stargray.gif";
	}	
}
function selecciona_estrella (field,n,value) {
	field.value = value
	estrellas[n] = value
}

function getMouseXY(e) {
	var tempX = moz ? e.clientX : event.clientX;
	var tempY = moz ? e.clientY : event.clientY;
	document.getElementById("ticket").style.left = tempX+difX
	document.getElementById("ticket").style.top = tempY+difY
	return true
}

function ticketon(valor,estilo) {
	txt1 = '<table border=0 cellpadding=0 cellspacing=0 style="'+estilo+'"><tr><td class=ne1>'+unescape(valor)+'</td></tr></table>'
	document.getElementById("ticket").innerHTML = txt1
	document.getElementById("ticket").style.visibility = 'visible'
}
   
function ticketoff() {
	document.getElementById("ticket").style.visibility = 'hidden'
	document.getElementById("ticket").innerHTML = ''
}
   
// SlideMenu ...I've changed timer function adding by default open default tab on mouseover
var slideMenu=function(){
	var sp,st,t,m,sa,l,w,sw,ot,ma;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s; st=sw; t=mt;
			m=document.getElementById(sm);
			sa=m.getElementsByTagName('li');
			l=sa.length; w=m.offsetWidth; sw=w/l;
			ot=Math.floor((w-st)/(l-1)); var i=0;
			for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)}
			if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t); ma=sl;}
			m.style.visibility = 'visible';
		},
		timer:function(s){
			s.onmouseover=function(){clearInterval(m.htimer);clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}
			s.onmouseout=function(){clearInterval(m.timer);clearInterval(m.htimer);m.htimer=setInterval(function(){slideMenu.slide(sa[ma-1],true)},t)}
		},
		slide:function(s){
			var cw=parseInt(s.style.width,'10');
			if(cw<st){
				var owt=0; var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10');
						if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'}
						owt=owt+(ow-oi)}}
				s.style.width=(w-owt)+'px';
			}else{clearInterval(m.timer)}
		}
	};
}();

/*
DezinerFolio.com Simple Accordians.

Author  : G.S.Navin Raj Kumar
Website : http://dezinerfolio.com

*/

/*
* The Variable names have been compressed to achive a higher level of compression.
*/

// Prototype Method to get the element based on ID
function $(d){
	return document.getElementById(d);
}

// set or get the current display style of the div
function dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
}

// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(dsp(d)!='none'&& dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=10;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = $(d);
	if(sh(d)>0){
		v = Math.round(sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		sh(d,v+'px');
		//d.style.opacity = (v/d.maxh);
		//d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,0);
		dsp(d,'none');
		clearInterval(d.t);
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	d = $(d);
	if(sh(d)<d.maxh){
		v = Math.round((d.maxh-sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)+v);
		sh(d,v+'px');
		//d.style.opacity = (v/d.maxh);
		//d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
	}
}

// Collapse Initializer
function cl(d){
	if(dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('et("'+d.id+'")',t);
	}
}

// Removes Classname from the given div.
function cc(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			//alert(n.className);
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc){
	// get all the elements that have id as content
	l=$(d).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	sel=null;
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=$(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=$(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.
			h.onclick = function(){
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					if((n+'-header')==this.id){
						ex($(n+'-content'));
						n=$(n+'-header');
						cc(n,'');
						n.className=n.className+' '+n.tc;
					}else{
						cl($(n+'-content'));
						cc($(n+'-header'),'');
					}
				}
			}
			if(h.className.match(/header_highlight/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}

// add load window as an iframe added onload
function load_wnd(iname,h,url) {
	//<IFRAME id="shopping" name="shopping" style="OVERFLOW: hidden; WIDTH: 100%;HEIGHT: hpx" src="url" frameBorder=0 scrolling="no"></IFRAME>
	var frm=document.createElement("IFRAME");
	frm.id=iname; frm.name=iname; frm.src=url;
	frm.width="100%"; frm.height=h+"px";
	frm.marginWidth="0"; frm.marginHeight="0"; frm.frameBorder="0";
	frm.scrolling="no"; frm.overflow="hidden";
	//frm.style.position=”absolute”;frm.style.left=”10px”; frm.style.top=”10px”;
	var td = document.getElementById("loadwnd");
	td.appendChild(frm);
	frames[iname].name = iname;
}	
// change iframe height
function ifrheight(ifr,h) {
	document.getElementById(ifr).style.height = h+'px'
}	

// add to favorites
function addtofavorites() {
	title = document.title; 
	url = window.location.href;
	if (document.all) window.external.AddFavorite(url,title);
	if (window.sidebar) window.sidebar.addPanel(title, url,'');
}

function valorate (valoration,cluster) {
	ifrheight('shopping','150');
	document.location.href='#info'
	document.fvaloration.val.value = valoration;
	document.fvaloration.cluster.value = cluster;
	document.fvaloration.submit();
}

function uservalorate (ac,rw,id_cluster) {
	if (ac == 'user_newop.php') h = '390';
	else h = '200'
	ifrheight('shopping',h);
	document.location.href='#info'
	document.fuservaloration.edit.value=rw; // Write / Read MODE
	if (id_cluster > 0) document.fuservaloration.cluster.value=id_cluster; // Show cluster valoration
	document.fuservaloration.action = "/users/"+ac; // user_sugurl.php OR user_newop.php
	document.fuservaloration.submit();
}

function wnd(url) {
	window.open(url,'privacy','height=400,width=600,scrollbars=yes,status=1');
}

function abrir(url,w,h) {
	window.open(url,'privacy','height='+h+',width='+w+',scrollbars=yes,status=1');
}

function reg_valida (lang) {
	if (document.freg.name.value == "" ||
		document.freg.surname.value == "" ||
		document.freg.password.value == "" ||
		document.freg.passwordchk.value == "" ||
		document.freg.capt.value == "" ||
		document.freg.email.value == "") {
		if (lang == "en")
			alert ("You must fill all fields to register");
		else
			alert ("Debes rellenar todos los campos obligatorios");
	}
	else if (document.freg.password.value != document.freg.passwordchk.value) {
		if (lang == "en")
			alert ("Password check error");
		else
			alert ("El password no se ha reescrito correctamente");
	}
	else if (document.freg.termschk.checked == false) {
		if (lang == "en")
			alert ("You must accept service terms to continue");
		else
			alert ("Debes aceptar los terminos de servicio para continuar");
	}
	else {
		document.freg.submit();
	}
}

function edit_valida (lang) {
	if (document.fedit.name.value == "" ||
		document.fedit.surname.value == "" ||
		document.fedit.email.value == "") {
		if (lang == "en")
			alert ("You must fill all fields to save account data");
		else
			alert ("Debes rellenar todos los campos obligatorios para guardar los cambios");
	}
	else if (document.fedit.newpassword.value != document.fedit.newpasswordchk.value) {
		if (lang == "en")
			alert ("Password check error");
		else
			alert ("El nuevo password no se ha reescrito correctamente");
	}
	else {
		document.fedit.submit();
	}
}

function opsubmit (lang) {
	if (document.fComenta.op.value.length > "300") {
		if (lang == "en")
			alert ("Opinion is too long");
		else
			alert ("La opinion es demasiado larga");
	}
	else
		document.fComenta.submit();
}

function submit_urls (str,lang) {
	var err = 0;
	error = str.indexOf(' ');
	if (error >= 0) {
		if (lang == 'es')
			alert ("Los links no pueden contener espacios en blanco");
		else
			alert ("Incorrect format of links");
		err = 1;
	}
	
	urls = str.split("\n");	
	for (i=0; i<urls.length; i++)
		if (!urls[i].match('http://.+') && urls[i] != '') {
			if (lang == 'es')
				alert ("No se han escrito bien los links: "+urls[i]);
			else
				alert ("Incorrect format of links: "+urls[i]);
			err = 1;
		}
	
	if (!err) document.fnewop.submit();
}

function formsubmit(f,txt) {
	if (confirm(txt)) {
		f.submit();
	}	
}
function nuevoCaptcha(f){
	var rand_no = Math.random();
	document.getElementById(f).setAttribute('src','/antispam.php?aux=' + rand_no);
}
