/* -------------------------------------------------
      EMedia Web Design - All Rights Reserved
--------------------------------------------------*/


var dataJsHost = "" 
if(location.href.lastIndexOf("catalogo-snow")==-1){dataJsHost+="catalogo-snow/";}

// ************************ // offline
//var artJsHost = "" 
//if(location.href.lastIndexOf("catalogo-snow")==-1){artJsHost+="catalogo-snow/";}
// *******************************************************************************
var artJsHost = "http://www.settimosport.com/catalogo-snow/" // online
document.write(unescape("%3Cscript src='" + artJsHost + "datascript/archivio.js' type='text/javascript'%3E%3C/script%3E"));
document.write(unescape("%3Cscript src='" + artJsHost + "datascript/reparti.js' type='text/javascript'%3E%3C/script%3E"));



// ########### REPORT  E VIDEO #####################

function Ck_listReport(xrep){
	
	PakAD00352 = new Array()
	PakAD00352[0] = xrep
	outbiz = DrawCookieApice(PakAD00352);
	SetCookieFly(ceck_pp352, outbiz);
 	//Display_menu_iframe(dataJsHost+'list_report.htm')
	location.href=dataJsHost+'list_report.htm'
	return;
		
}


function Ck_listVideo(xrep, xxrep){
	
	PakAD00353 = new Array()
	PakAD00353[0] = xrep; PakAD00353[1] = xxrep
	outbiz = DrawCookieApice(PakAD00353);
	SetCookieFly(ceck_pp353, outbiz);
	//alert(dataJsHost+'list_video.htm')
	location.href=dataJsHost+'list_video.htm'
 	//Display_menu_iframe(dataJsHost+'list_video.htm')
	return;

}

// ###### REPORT E VIDEO end #####################

// ########### DISPLAY ###########################


function Ck_display(name){         // effettua trova rep e sottorep avendo un solo dato (mane)
	
	
	for(n=0; n<sottorep.length; n++){
	 	for(x=0; x<sottorep[n].length; x++){
			
		  if(sottorep[n][x][0]=="ON"){
			for(s=2; s<sottorep[n][x].length; s++){
			
			if(sottorep[n][x][s]==name){    // restituisce sottorep[n][x]
		//	alert(n+","+x+","+name)
			
			eval("PakAD00350=new Array("+n+","+x+","+name+")")
			outbiz = PakAD00350; SetCookieFly(ceck_pp350, outbiz);
 			location.href=dataJsHost+'display.htm'
			//Display_menu_iframe(dataJsHost+'display.htm')
			return;
			}  
		   }
		  }
	   }
    }
}



function Ck_display_ID(n,x,name){     
	
//	alert(n+","+x+","+name)
			
	eval("PakAD00350=new Array("+n+","+x+","+name+")")
	outbiz = PakAD00350; SetCookieFly(ceck_pp350, outbiz);
 	location.href=dataJsHost+"display.htm"
	return;
			
}


// ###### DISPLAY  end #############################




// ###### VARIE COMUNI #############################


function dueDecimali(valore){
	
		numero=valore
		numero=numero.toString()
   		for (rt=(numero.length-7);rt>0;rt-=3)
      	numero=numero.substring(0,rt)+"."+numero.substr(rt)
		
		valore=numero
			
		valore = valore.toString()
		posVirgola = valore.lastIndexOf(".")
		newValore = valore.substring(0,(posVirgola+3))
		return newValore		
}




function Display_minifoto(){ 

	// *************** verifica caricamento archivio *****
	CeckRete=0
 	try{arresta = sottorep}   
 	catch(e){CeckRete=1}
	if(CeckRete==1){return;}
	// ****************************************************

	if(Ay_aoias==""){AOIAS()}//else{alert("esiste")}
//	AOIAS() // restituisce Ay_aoias, Array contenente tutti gli articoli in offerta
	
	u=Math.floor(Math.random() * Ay_aoias.length); 
//	alert(Ay_aoias[u][0])
	if(Ay_aoias[u][5]>0){valor=Ay_aoias[u][0]} 
	

	document.getElementById("displaySpot").src=dataJsHost+"foto-prodotti/"+ART[valor][4]
	document.getElementById("displayHref").href="javascript:Ck_display(\""+valor+"\")"

//	ART[valor][5]>0 ? setOfferta="<font color='#FF0000'><b>€. "+dueDecimali(ART[valor][5]+0.001)+"</b></font>&nbsp;<strike>"+dueDecimali(ART[valor][3]+0.001)+"</strike>" : setOfferta="€. "+dueDecimali(ART[valor][3]+0.001)
	ART[valor][5]>0 ? setOfferta="€ <strike>"+dueDecimali(ART[valor][3]+0.001)+"</strike><font color='#FF0000'><b>&nbsp;"+dueDecimali(ART[valor][5]+0.001)+"</b></font>" : setOfferta="€. "+dueDecimali(ART[valor][3]+0.001)
	
	if(ART[valor][5]>0){
	perc_scnt_x = parseInt((eval(ART[valor][5])*100)/eval(ART[valor][3])-100)
 	setSconto="<font color='#FF0000'><b>Sconto "+perc_scnt_x+"%</b></font>"}
 	
	document.getElementById("displayText0").innerHTML="<font color='#666666'><b>"+ART[valor][2]+"</b></font>"
	document.getElementById("displayText1").innerHTML="<font color='#666666'><b>"+des[valor][0]+"</b></font>"
	document.getElementById("displayText2").innerHTML=setOfferta
	document.getElementById("displayText3").innerHTML=setSconto
		
}



var Ay_aoias=""
function AOIAS(){       // All Offerte In All Sottorep
	
	txtext=""
	cnt=0  // tot articoli nei sottorep
	din=0  // tot articoli in offerta trovati
	
	Ay_aoias=new Array()  // Array di AOIAS
	
	for(n=1; n<15; n++){      // 'n<15' esclude lettura 'sottorep usato' per annullare restrizione sostituire '15' con 'sottorep.length'
	 	for(x=0; x<sottorep[n].length; x++){
			
		  if(sottorep[n][x][0]=="ON"){
			for(s=2; s<sottorep[n][x].length; s++){cnt++
			
			if(ART[sottorep[n][x][s]][5]!=0.00 && ART[sottorep[n][x][s]][0]=="ON"){    // restituisce sottorep[n][x]
			Ay_aoias[din]=new Array(sottorep[n][x][s],ART[sottorep[n][x][s]][2],des[sottorep[n][x][s]][0],ART[sottorep[n][x][s]][4],ART[sottorep[n][x][s]][3],ART[sottorep[n][x][s]][5])
//			txtext += Ay_aoias[din][0]+" "+Ay_aoias[din][1]+" "+Ay_aoias[din][2]+" "+Ay_aoias[din][3]+" "+Ay_aoias[din][4]+" "+Ay_aoias[din][5]+"\n"
			din++
			}}}}}
// 	alert(txtext)
//	alert(Ay_aoias)
	return(Ay_aoias)   // restituisce Ay_aoias, Array contenente tutti gli articoli in offerta
}


var TMP_sfois=new Array(); var diff=0; var doppiovalore=0;
function SFOIS(){	      
	
	selector = 5 	//  Select (n) Random Offerte In Sottorep
	
	if(Ay_aoias==""){AOIAS()}
	
//	u=Math.floor(Math.random() * Ay_aoias.length); 
//	alert(Ay_aoias[u][0])
//	if(Ay_aoias[u][5]>0){Display_minifoto(Ay_aoias[u][0])} //  minifoto


	if(TMP_sfois.length>50){TMP_sfois=new Array(); TMP_sfois[0]=""; diff=0}
	Ay_sfois=new Array(); Ay_sfois[0]=""; g=0;  
	
	
	for(i=0;i<20;i++){r=Math.floor(Math.random() * Ay_aoias.length); 
       	stop=0;		
  		
 //		alert(TMP_sfois.length+" "+TMP_sfois+" \n"+Ay_sfois)

   		for(f=0;f<TMP_sfois.length;f++){if(TMP_sfois[f]==r){doppiovalore++;stop=1}}
		
		TMP_sfois[diff]=r;diff++
		if(stop==0){Ay_sfois[g]=Ay_aoias[r][0]; g++}
		if(g==selector){break;}  // return(Ay_sfois)
   	}
//	alert(Ay_sfois)
	if(Ay_sfois.length<selector){SFOIS()}
	return(Ay_sfois);   // restituisce Ay_sfois, Array contenente 4 articoli random estratti da tutti gli articoli in offerta

} 



var percsonto=0
var diffrisp=0

function Display_show(){

 	SFOIS(); //  alert(Ay_sfois)
 
	outText = ""
 	outText += "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"
	outText += "<tr>"
	contacelle = 0
	presenza = 0
	n_celle= 5        // numero di celle visualizzate
	minifoto = ""
		
	if(Ay_sfois.length==0){alert("Questa sezione non contiene articoli!"); return;}
//	ZZ=document.getElementById("display_iframe").height
	YY=""
//	ZZ<=601 ? YY="" : YY=" style='display: none'"
	
	
	for(d=0; d<n_celle; d++){

	target_list="catalogo-snow/listino.htm"
	contacelle++
	presenza++
	if(contacelle == n_celle+1){outText += "<tr>"}
	outText += "<td valign='top'>" //width='20%'
	ART[Ay_sfois[d]][5]>0 ? inOfferta="€ <strike>"+dueDecimali(ART[Ay_sfois[d]][3]+0.001)+"</strike><font color='#FF0000'><b>&nbsp;"+dueDecimali(ART[Ay_sfois[d]][5]+0.001)+"</b></font>" : inOfferta="€. "+dueDecimali(ART[Ay_sfois[d]][3]+0.001)
	ART[Ay_sfois[d]][4] == "" ? minifoto = "catalogo-snow/foto-prodotti/nofotomini.gif" : minifoto = "catalogo-snow/foto-prodotti/"+ART[Ay_sfois[d]][4]
      	
	
	outText += "<div id='vediphoto"+d+"'"+YY+">"
	outText += "<p align='center' style='margin-top: 5; margin-bottom: 0'><a href='javascript:Ck_display("+Ay_sfois[d]+")'><img style='border-right: 1px solid #C0C0C0; border-bottom: 1px solid #C0C0C0' border='0' src="+minifoto+" width='150' height='150' alt='vedi scheda\n  prodotto'></a>"
	outText += "</div>"
	outText += "<p align='center' class='ver-1' style='margin-top: 0; margin-bottom: 0'><a class=\"serra\" href='javascript:Ck_display("+Ay_sfois[d]+")'><b>"+ART[Ay_sfois[d]][2]+"</b></a></p>"
	outText += "<p align='center' class='ver-1' style='margin-top: 0; margin-bottom: 0'><a class=\"serra\" href='javascript:Ck_display("+Ay_sfois[d]+")'>"+des[Ay_sfois[d]][0]+"</a></p>"
//	if(des[CLIENT_ordine[d][1]][3]!=""){outText += "<p align='center' class='ver-0' style='margin-top: 0; margin-bottom: 0'><a class=\"serra\" href='javascript:Ck_display("+Ay_sfois[d]+")'>size: "+des[Ay_sfois[d]][3]+"</a></p>"}
	outText += "<p align='center' class='ver-1' style='margin-top: 0; margin-bottom: 0'>"+inOfferta+"</p>"
	
	if(ART[Ay_sfois[d]][5]>0){
   	percsonto = parseInt((eval(ART[Ay_sfois[d]][5])*100)/eval(ART[Ay_sfois[d]][3])-100)
 	diffrisp = eval(ART[Ay_sfois[d]][3])-eval(ART[Ay_sfois[d]][5])
 	diffrisp = dueDecimali(diffrisp+0.001)

 	outText+= "<center><table border='0' cellpadding='0' cellspacing='0' width='150' style='margin-left: 0; margin-top: 5; margin-bottom: 5'>"
   //	outText+= "<tr><td class='ver-1' align='center' style='border: 1px solid #E5E5E5; background-color: #FFFFCC'><b><font color='#800000'>Sconto "+percsonto+"% &nbsp;<br>Risparmi "+diffrisp+" Euro!</font></b></td>"
   	outText+= "<tr><td class='ver-1' align='center' style='border-top: 1px solid #E5E5E5'><b><font color='#FF0000'>Sconto "+percsonto+"% &nbsp;<br>Risparmi "+diffrisp+" Euro!</font></b></td>"
	outText+= "</tr></table></center>"
	}
	
	outText += "</td>"
    
	if(contacelle == n_celle){outText += "</tr>"; contacelle = 0}
 }

  	if(contacelle < n_celle){
 	  for(x=0; x<(n_celle-contacelle); x++){
 	  outText += "<td width='20%' valign='top'></td>"
 	  }
	outText += "</tr>"
	}
 	outText += "</table>"
  	
	document.getElementById("anteprimaH200").innerHTML = outText
		
}


// ###### CONTROLLER ALTEZZA FRAME ###################


var TMP_Data=new Array(); diff=0; doppiovalore=0;
function creaRandom(Data){

	
	selector = Data.length 	//  Select (n) Random Offerte In Sottorep
	

	if(TMP_Data.length>50){TMP_Data=new Array(); TMP_Data[0]=""; diff=0}
	Ay_Data=new Array(); Ay_Data[0]=""; g=0;  
	
	
	for(i=0;i<20;i++){r=Math.floor(Math.random() * Data.length); 
        stop=0;		
  		
 //	alert(TMP_Data.length+" "+TMP_Data+" \n"+Ay_Data)

   		for(f=0;f<TMP_Data.length;f++){if(TMP_Data[f]==r){doppiovalore++;stop=1}}
		
		TMP_Data[diff]=r;diff++
		if(stop==0){Ay_Data[g]=Data[r]; g++} // sostituire Data[r] con Data[r][2] per vedere l'orine creato
		if(g==selector){break;}  // return(Ay_Data)
   	}
//	alert(Ay_Data)
	return(Ay_Data);   // restituisce Ay_Data, Array contenente tutti articoli random estratti da l'Array passato



}



var BOX_top = new Array();  // declare 
var BOX_155 = new Array();  // declare
var rnd_BOX_155 = new Array() // declare
var tmp_BOX_155 = new Array() // declare


function creaBOX(){  

	// vincolo posizione : 0=nn 1=sx 2=dx
	// FLAG[x] =(attivo si/no , elemento html , posizione nn/sx/dx , priorità 0-10 , altezza) 
	

	try{vuoto=BOX_top[2][1]}    // control exist BOX_top
		
	catch(e){	
	BOX_top[0] = new Array(true,Flag_menu_shop(),1,10,240);
	BOX_top[1] = new Array(true,Flag_miniofferte(),2,10,250);
	BOX_top[2] = new Array(true,"Flag_car_display()",2,10,150);      // Flag_car_display() espresso in stringa per non farlo caricare prima del necessario *** 
	BOX_top[3] = new Array(true,Flag_assistenza_clienti(),1,10,180);
	BOX_top[4] = new Array(true,Flag_link_aziende(),1,10,180);
	}

	try{vuoto=BOX_155[2][1]}    // control exist BOX_155
		
	catch(e){
	
	//BOX_155 = new Array()
	BOX_155[0] = new Array("img/file_comuni/promo_06.gif","service_dovesiamo.htm")
	BOX_155[1] = new Array("img/file_comuni/promo_02.gif","javascript:Ck_listVideo(7,1)")
	BOX_155[2] = new Array("img/file_comuni/promo_01.gif","javascript:Ck_listVideo(15,0)")
	BOX_155[3] = new Array("img/file_comuni/promo_07.gif","javascript:Ck_listVideo(4,0)")
	BOX_155[4] = new Array("img/file_comuni/promo_08.gif","javascript:Ck_listVideo(8,2)")
	BOX_155[5] = new Array("img/file_comuni/promo_09.gif","javascript:Ck_listVideo(7,0)")
	BOX_155[6] = new Array("img/file_comuni/promo_10.gif","javascript:Ck_listVideo(8,1)")
	BOX_155[7] = new Array("img/file_comuni/promo_11.gif","javascript:Ck_listReport(6)")
	BOX_155[8] = new Array("img/file_comuni/promo_12.gif","service_school_0.htm")
	BOX_155[9] = new Array("img/file_comuni/promo_13.gif","javascript:Ck_listVideo(10,4)")

	
	for(r=0; r<BOX_155.length; r++){tmp_BOX_155[r]=r}
	rnd_BOX_155 = creaRandom(tmp_BOX_155)
	//alert(rnd_BOX_155)
	
	}
	
}


function setFrameKtrl(){

	document.getElementById('flag_sx').innerHTML="<p class='ver-1' style='margin-top: 5'>loading..</p>"
	document.getElementById('flag_dx').innerHTML="<p class='ver-1' style='margin-top: 5'>loading..</p>"

	// Explorer
	if(document.all){
	var KK=window.document.all.PublicTable.scrollHeight
//	alert("Explorer\necomm "+KK)
	FrameKtrl(KK)
	return;
	}  

	//Netscape 4.x Mozzilla
	if(document.getElementById){
	KK=document.getElementById('PublicTable').scrollHeight;
//	alert("Netscape 4.x\necomm "+KK)
	FrameKtrl(KK)
	return;
	}
}


var inizia_da=4
var Tmp_box=inizia_da   // conserva memoria dei box inseriti (parte dal 3)
function FrameKtrl(HH){  
	

	
	creaBOX() // solo se nn già caricato all'apertura della pagina
	
	base_sx= BOX_top[0][1]+BOX_top[3][1]+Flag_spot_155(rnd_BOX_155[3]); //+BOX_top[4][1]
	base_dx= BOX_top[1][1]+Flag_spot_155(rnd_BOX_155[1])+Flag_spot_155(rnd_BOX_155[2]);


	out_sx= base_sx
	out_dx= base_dx

	if(LifeCookieControl(ceck_car) == true){
	readUrl=unescape(String(this.location));
	
	kit=1
	if(readUrl.indexOf("carcontrol")>0){kit=0} 
	if(readUrl.indexOf("datiac")>0){kit=0}
	if(kit==1){
	BOX_top[2][1]=Flag_car_display()   // carica Flag_car_display() in memoria
	out_dx=BOX_top[2][1]+BOX_top[1][1]+Flag_spot_155(rnd_BOX_155[2])
	}
	}
	
	n_box=parseInt((HH-570)/155)
	max_box=parseInt(((rnd_BOX_155.length)-inizia_da)/2)

//	alert(max_box)
		
	if(n_box>=1){	
	if(n_box>max_box){n_box=max_box};Tmp_box=inizia_da;
	for(n=0; n<n_box; n++){out_sx+=Flag_spot_155(rnd_BOX_155[Tmp_box]);Tmp_box++;out_dx+=Flag_spot_155(rnd_BOX_155[Tmp_box]);Tmp_box++;}
	}

	document.getElementById('flag_sx').innerHTML=out_sx
	document.getElementById('flag_dx').innerHTML=out_dx
	

	// ----------------------------------
	setTimeout('Display_minifoto()', 100) // non cancellare!!!
	// ----------------------------------		

	return;

}



// ###### CONTROLLER ALTEZZA FRAME end   ################

// ###### FINE VARIE COMUNI ######################################




// ############ All Cookie Control ##############################################


var ceck_scv = "AD00300";		// AD00300 =   val articolo carrello, da visualizzare su listino
var ceck_art = "AD00345";                // AD00345 =   val articolo ricevuto, da aggiungere al carrello
var ceck_car = "AD00346";                // AD00346 = x,y,z  var carrello, tutti gli articoli del carrello
var ceck_qta = "AD00347";                // AD00347 = x,y,z  var carrello, tutte le qta degli articoli
var ceck_pos = "AD00348";               // AD00348 = x,y,z  var carrello, posizione dell'articoli nei listini
var ceck_spe = "AD00349";              // AD00349 = x,y,z  var dati per spedizione, tutti i dati spedizione
var ceck_pp350 = "AD00350";              // AD00350 = x  var apertura display
var ceck_pp351 = "AD00351";              // AD00351 = x  var apertura ricerca
var ceck_pp352 = "AD00352";              // AD00352 = x,y,z  var apertura list_report
var ceck_pp353 = "AD00353";              // AD00353 = x,y,z  var apertura list_video
var ceck_pp354 = "AD00354";              // AD00354 = x  var blocco art con codice
var ceck_endorder = "PP00001";          // PP00001 =  x   var respond order paypal



function DrawCookieApice(PakADxx){   // rutine di AggiornaCkSpedizione()
	  
	outpuz = ""
	sterk = ""
		
	for(nn=0; nn<PakADxx.length; ){
	if(nn==0){sterk="\""+PakADxx[0]+"\""} //PakADxx.length PakADxx.length==1
	else{sterk=",\""+PakADxx[nn]+"\""}
	outpuz += sterk
	nn++
	}
 //	alert("DrawCookie("+PakADxx+")PakADxx.length "+PakADxx.length+"\noutpuz: "+outpuz)
   	return outpuz;
}




function AggiornaVarCarrello(){
	

	GetCookie(ceck_car) 
	if(storn.indexOf(",")==-1){snip1=storn; PakAD00346=new Array(); PakAD00346[0]=storn}
	else{snip1=storn;	 eval("PakAD00346=new Array("+storn+")")}
	
	GetCookie(ceck_qta); 
	if(storn.indexOf(",")==-1){snip2=storn; PakAD00347=new Array(); PakAD00347[0]=storn}
	else{snip2=storn;	 eval("PakAD00347=new Array("+storn+")")}
// 	alert("storn ceck_car: "+snip1+"\nPakAD00346: "+PakAD00346+"\nPakAD00346[0]: "+PakAD00346[0]+"\n\nstorn ceck_qta: "+snip2+"\nPakAD00347: "+PakAD00347+"\nPakAD00347[0]: "+PakAD00347[0])
	
} 



function LifeCookieControl(name){

	storn=""; GetCookie(name);
	if(storn == ""){return(false)}
	return(true)
}




function GetCookie(name){
	
	var arg = name + "=";
	var alen = arg.length;  
	var clen = document.cookie.length;   
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	storn=getCookieVal(j)
//	alert(getCookieVal(j));                     // *** old: return getCookieVal(j)
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0)
	break;
	}
	return;  // null;
}




function getCookieVal(offset){
	
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
//	alert(unescape(document.cookie.substring(offset, endstr)))
	return unescape(document.cookie.substring(offset, endstr));
}
 


function SetCookie(name, value){ 

	stopcookie = 0   // usato da listino
	
	var t=new Date();
	var s=new Date()
	t1=t.getTime();
//+alert	t.setTime(t1)
	s.setTime(t1+(12 * 60 * 60 * 1000))
//-->	alert(t.toGMTString()+"\n"+s.toUTCString()) 
	

	document.cookie = name + "=" + escape (value) + "; expires=" + s.toGMTString() + "; path= /;";

//	alert(document.cookie)
	if(document.cookie.indexOf(name+"=")==-1){
//	alert("Attenzione! è necessario abilitare i cookies!")
	stopcookie = 1  // usato da listino
	}
}
 


function SetCookieFly(name, value){
	
	document.cookie = name + "=" + escape (value) + "; path= /;"
//	alert(unescape(document.cookie))
	if(document.cookie.indexOf(name+"=")==-1){alert("Attenzione! è necessario abilitare i cookies!")}
	
}



function ClearCookie(name) { 
	
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 3600);
	var cval = GetCookie (name); 
               document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()  + "; path= /;"
}





function Life_ckcar(){
	
	life=true; if(!LifeCookieControl(ceck_qta)||!LifeCookieControl(ceck_car)){life=false}
	if(!life){ClearCookie(ceck_car);ClearCookie(ceck_qta);location.href="error_ckcar.htm"}

}




// ############ Fine Cookie Control ##############################################








//---------------------   fine file js


