function writeResultVoteGraphic(ris, size)
{  		
  var votestars = '';
  var on=0;
  var off=5;
  if((ris>0)&&(ris<16)){
  	on=1;
  	off=4;
  }else if((ris>15)&&(ris<31)){
  	on=2;
  	off=3;
  }else if((ris>30)&&(ris<46)){
  	on=3;
  	off=2;
  }else if((ris>45)&&(ris<61)){
  	on=4;
  	off=1;
  }else if(ris>60){
  	on=5;
  	off=0;
  }  
  for(var i=0;i<on;i++){
   votestars += (size == 'big') ?'<span class="stellaon"></span>' : '<span class="stellaon2"></span>';
  }
  for(var i=0;i<off;i++){
   votestars +=  (size == 'big') ?'<span class="stellaoff"></span>' : '<span class="stellaoff2"></span>';
  }  
  return(votestars);
}



function staticLoadScript(url_js)
{		
   document.write('<script src="'+ url_js +'" type="text/JavaScript"><\/script>');   
}

function getResultVote(id_videotalent)
{
  staticLoadScript('/video/vote/v'+id_videotalent+'.js');	
}

function getVoteOffline(id_videotalent)
{
  //restituisce 1 se il video è offline cioè non è votabile	
  var vote_offline = eval("offline"+id_videotalent);	
  return vote_offline;
}

function getInfoVideotalent(id_videotalent)
{
  staticLoadScript('/video/info/i'+id_videotalent+'.js');	
}	

function getResultView(id_ReferenceDBimport)
{
  document.write(id_ReferenceDBimport);
}	

function writeObjectVideoLaunch(id_videotalent, vote_offline, vote_value, id_profile, nickname_profile, category, title_videotalent,minute,second)
{		    
	var size = 'small';	
	var durata = (minute != '' & second!= '') ? ('<p>Durata:<strong>'+minute+':'+second+'</strong></p>') : (''); 

	return '<div class="containercolor">'+
	'<div class="contleft">'+	
	'<a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video"><img src="/amici/bin/C_2_videotalent_'+id_videotalent+'_videoThumbnail_1.jpg" width="117" height="88"></a>'+
	'<p class="category">Categoria: <strong>'+category+'</strong></p>'+
	'<h4><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video">'+TitleBoxManager(title_videotalent,20)+'</a></h4>'+
	'</div>'+
	'<div class="contright">'+
	'<p>Autore</p>'+
	'<h4><a href="/profilo/profilotalent.shtml?id='+id_profile+'&amp;program=amici">'+nickname_profile+'</a></h4>'+
	'<p>Voti: <strong>'+vote_value+'</strong></p>'+
	'<div class="stars2">'+writeResultVoteGraphic(vote_value, size)+'</div>'+
	durata +
	'</div>'+	
	'</div>';	
}	

function writeObjectVideoLaunchVisti(id_videotalent, vote_offline, view_value, id_profile, nickname_profile, category, title_videotalent,minute,second)
{		    
	var size = 'small';	
	var durata = (minute != '' & second!= '') ? ('<p>Durata:<strong>'+minute+':'+second+'</strong></p>') : (''); 

	return '<div class="containercolor">'+
	'<div class="contleft">'+	
	'<a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video"><img src="/amici/bin/C_2_videotalent_'+id_videotalent+'_videoThumbnail_1.jpg" width="117" height="88"></a>'+
	'<p class="category">Categoria: <strong>'+category+'</strong></p>'+
	'<h4><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video">'+TitleBoxManager(title_videotalent,20)+'</a></h4>'+
	'</div>'+
	'<div class="contright">'+
	'<p>Autore</p>'+
	'<h4><a href="/profilo/profilotalent.shtml?id='+id_profile+'&amp;program=amici">'+nickname_profile+'</a></h4>'+
	'<p>Visto: <strong>'+view_value+'</strong></p>'+
	durata +
	'</div>'+	
	'</div>';	
}	


function writeObjectVideoLaunchOrizzontal(id_videotalent, vote_value, title_videotalent, durata)
{		    
  	var size = 'small';	
	return '<div class="thumbnail"><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video"><img src="/amici/bin/C_2_videotalent_'+id_videotalent+'_videoThumbnail_1.jpg" width="100" height="75"></a><h4 class="titolo"><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'">'+TitleBoxManager(title,10)+'</a></h4><p class="durata">'+durata+'</p><p class="number_view">voti <strong>'+vote_value+'</strong></p><p class="stars2">'+writeResultVoteGraphic(vote_value, size)+'</p></div>';
}	

function writeObjectVideoLaunchOrizzontalVisti(id_videotalent, view_value, title_videotalent, durata)
{		    
  	var size = 'small';	
	return '<div class="thumbnail"><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video"><img src="/amici/bin/C_2_videotalent_'+id_videotalent+'_videoThumbnail_1.jpg" width="100" height="75"></a><h4 class="titolo"><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'">'+TitleBoxManager(title,10)+'</a></h4><p class="durata">'+durata+'</p><p class="number_view">visto <strong>'+view_value+'</strong></p></div>';
}	


function TitleBoxManager(str, size)
{
	var strcut = str;
	if(strcut.length > size){
	strcut = (str.substring(0,size));
	strcut += '...';
	}
	return strcut;
}


function initFieldSearch(objform){
	var url;
	if(readUrl('q') !=''){
		for(i=0; i<objform.length; i++){
					if(objform.elements[i].id =='q'){
					url = readUrl('q');
					url = url.replace("+"," ");
					objform.elements[i].value = url;
					}
		}
	}
}

function readUrl(param){
	var theurl=window.location.toString()+"&";
	var posparam=theurl.indexOf(param+"=");
	if(posparam==-1)return"";
	var sottostringa=theurl.substring(posparam);
	var start=sottostringa.indexOf("=");
	var end=sottostringa.indexOf("&");
	var val=sottostringa.substring(start+1,end);
	return val;

}

function goSearch(obj) {
	if (obj.q.value.length > 0) {
		if (tok(obj.q) == true) return true;       
	} else
		alert("Inserire il parametro di ricerca!");     
	return false; 
}

var ALPHANUMERICS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890àèéìòù"
function tok(theObj){
	var text=theObj.value+" ";
	var pos,pos1=0;
	var finale,word,ch=" ";
	var find=true;
	var fword=false;
	for(var i=0;i<text.length;i++){
		ch=text.charAt(i);
		if(ch==" "){
			if(find!=true){
				find=true;
				pos1=i;
				word=text.substring(pos,pos1);
				if(word.substring(0,1)==" ")word=word.substring(1,word.length);
				var wU=word.toUpperCase();
				if(wU=="AND"||wU=="OR"||wU=="NOT"){
						alert("La parola ' "+wU+" ' non è ammessa");
					theObj.focus();
					return false;
				}
				pos=pos1;
				if(fword==false){
					finale=word;
					fword=true;
				}else
					finale=finale+" "+word;
			}else
				pos=i+1;
			}else{
				if(ALPHANUMERICS.indexOf(ch)==-1){
					alert("Il carattere ' "+ch+" ' non è ammesso");
				theObj.focus();
				return false;
			}
			find=false;
			}//end if
	}//end for
	if(fword==false){
		if(lang=='it')
			alert("Inserisci la/e parola/e che vuoi ricercare!");
		else
			alert("Insert the word that you want to search!");
		theObj.value="";
		theObj.focus();
		return false;
	}
	theObj.value=finale;
	return true;
}
function writeObjectVideoLaunchClassifica(id_videotalent, vote_offline, vote_value, id_profile, nickname_profile, category, title_videotalent,minute,second)
{		    
	var size = 'small';	
	var durata = (minute != '' & second!= '') ? ('<p>Durata:<strong>'+minute+':'+second+'</strong></p>') : (''); 
	
	return '<div class="containercolorS">'+
	'<a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video"><img src="/amici/bin/C_2_videotalent_'+id_videotalent+'_videoThumbnail_1.jpg" width="100" height="75"></a>'+
	'<h4><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video">'+TitleBoxManager(title_videotalent,20)+'</a></h4>'+	
	'<p>Autore:<a href="/profilo/profilotalent.shtml?id='+id_profile+'&amp;program=amici"><strong>'+nickname_profile+'</strong></a></p>'+	
	'<p>Categoria: <strong>'+category+'</strong></p>'+durata+	
	'<p class="votiS">Voti: <strong>'+vote_value+'</strong></p>'+
	'<p class="stars2S">'+writeResultVoteGraphic(vote_value, size)+'</p>'+	
	'</div>';			
}	

function writeObjectVideoLaunchVisto(id_videotalent, vote_offline, visto_value, id_profile, nickname_profile, category, title_videotalent,minute,second)
{		    
	var size = 'small';	
	var durata = (minute != '' & second!= '') ? ('<p>Durata:<strong>'+minute+':'+second+'</strong></p>') : (''); 
	
	return '<div class="containercolorS">'+
	'<a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video"><img src="/amici/bin/C_2_videotalent_'+id_videotalent+'_videoThumbnail_1.jpg" width="100" height="75"></a>'+
	'<h4><a href="/amici/video/videotalent.shtml?id='+id_videotalent+'" title="guarda il video">'+TitleBoxManager(title_videotalent,20)+'</a></h4>'+	
	'<p>Autore:<a href="/profilo/profilotalent.shtml?id='+id_profile+'&amp;program=amici"><strong>'+nickname_profile+'</strong></a></p>'+	
	'<p>Categoria: <strong>'+category+'</strong></p>'+durata+	
	'<p class="votiS">Visto: <strong>'+visto_value+'</strong></p>'+
	'<p class="stars2S">'+writeResultVoteGraphic(visto_value, size)+'</p>'+	
	'</div>';					
}	


