var RadioOption ="series";

function GID(id){
	return document.getElementById(id);
}

function popupPrint(filename){
	var winLocation, winName, winParam, winObj;
	var winPos, winPosTop, winPosLeft, winWidth, winHeight;
	
	winWidth = 800;
	winHeight = 600;
	
	winPosTop = (screen.height / 2) - winHeight / 2;
	winPosLeft = (screen.width / 2) - winWidth / 2;
	winPos = ',top=' + winPosTop + ',left=' + winPosLeft;
	
	winLocation=filename;
	winName = 'Print';

	winParam = 'status=0,toolbars=0,menubar=0,scrollbars=yes,history=0,resizable=0,width=' + winWidth + ',height=' + winHeight + winPos;
	winObj = window.open(winLocation, winName, winParam);
	winObj.focus();
}

function showZoom(iddiv,filename,top,left,width,height,chiudi,loading){
	GID(iddiv).style.top=top;
	GID(iddiv).style.left=left;
	GID(iddiv).style.display="block";
	GID(iddiv).innerHTML="<table id=\"loading\" style=\"width:"+width+";height:"+height+";\"><tr><td align=\"center\"><img src=\"../images/loading.gif\"><br><span style=\"color:#888888;font-family:Verdana;font-size:12px;\">"+loading+"...</span>\n</td></tr></table>\n";
	GID(iddiv).innerHTML+="<div id=\"zoomimage\" style=\"text-align:center;display:none;\"><a href=\"javascript:GID('zoom').style.display='none';void(0);\" style=\"font-family:Verdana;color:#333333;font-size:11px;text-decoration:none;\"><img src=\""+filename+"\" onLoad=\"javascript:GID('loading').style.display='none';GID('zoomimage').style.display='block';\" border=\"0\"><br>[X] "+chiudi+"</a></div>";
}

function CheckRadio(number){

	switch(number)
	{
	   case 1:
		RadioOption ="series";
		break;
		
	   case 2:
		RadioOption ="all";
		break;
	}
	return RadioOption;
}

/*
Abbreviazione per document.getElementById(nomediv)
*/
function GID(id){
	if( document.getElementById(id) )
		RES=document.getElementById(id);
	else
		RES="";
	return RES;
}

function getRelativeIMG(iddiv){
	var SO="";
	SRC=GID(iddiv).src;
	for(i=SRC.length-1;i>0;i--){
		if( SRC[i]=="/" )
			i=-1;
		else
			SO=SRC[i]+SO;
	}
	return SO;
}

function switchIMG(iddiv){
	if( getRelativeIMG(iddiv)=='left_menu.gif' )
		GID(iddiv).src='images/left_menuON.gif';
	else
		GID(iddiv).src='images/left_menu.gif';
}


/*
Mostra un div dato l'id
*/
function show(div){
	/*if( parent.pagina.document.getElementById(div).style.display=="none" ){ */
		parent.pagina.document.getElementById(div).style.display="block"; 
	/*}
	else{ 
		parent.pagina.document.getElementById(div).style.display="none";	
	}*/	
}

/*
ID=id da "aprire"
IDPARENT=id del div in cui c'è il javascript toggleDiv
H=profondità
*/
function toggleDiv(id,idparent,h){
	DIV=document.getElementById(id);
	if(idparent){ DIVPARENT=document.getElementById(idparent); }
	if( DIV.style.display=="none" ){
		DIV.style.display="block";
		if(idparent)
			if( h==1000 )
				DIVPARENT.className="VoceMenuFamigliaHover";
			else
				DIVPARENT.className="VoceMenuRamo"+h+"Hover";
	}
	else{
		DIV.style.display="none";
		if(idparent)
			if( h==1000 )
				DIVPARENT.className="VoceMenuFamiglia";
			else
				DIVPARENT.className="VoceMenuRamo"+h;
	}
}


function isNumeric(str){
	var RegExp = /^(\d*)$/;
	var result = str.match(RegExp);
	return result;
}

function updateQuantita(idofferta,idprodotto,idcontatto,quantita,tipo,note){
	if( isNumeric(quantita) && quantita>0 ){
		note=note.replace("\n","<br>");
		getURL("carrello.asp?op=updatequantita&idofferta="+idofferta+"&idprodotto="+idprodotto+"&idcontatto="+idcontatto+"&quantita="+quantita+"&tipo_pacchetto="+tipo+"&note="+note,"carrello");
	}
	else
		alert("La quantità inserita non è valida!");
}



function toggleBar(id){
	DIV=document.getElementById(id);
	BUTTONBAR=document.getElementById('buttonbar');
	if( DIV.style.display=="none" ){
		DIV.style.display="block";
		BUTTONBAR.src="images/btn_riduci.gif";
	}
	else{
		DIV.style.display="none";
		BUTTONBAR.src="images/btn_apri.gif";
	}
}

function NextPage(pagenumber,IDFAMIGLIA,IDSERIE,suffix){
	var NuovaPagina='';
	var checkoption='';
	NuovaPagina = 'serie.asp?f='+IDFAMIGLIA+'&s='+IDSERIE;

	NuovaPagina = NuovaPagina + '&checkoption=';

	for(i=0;i<10;i++){
		if (document.getElementById('CheckOption'+i)){ 
			if (document.getElementById('CheckOption'+i).checked){ 
				if(checkoption!=''){
					checkoption = checkoption + ',';
				}
				checkoption = checkoption + document.getElementById('CheckOption'+i).value; 
			}	
		}
	}	
	if( !GID('suffix') )
		SUF="";
	else
		SUF="&suffix="+suffix;
	NuovaPagina = NuovaPagina + checkoption + '&page='+pagenumber+'&search='+GID('search').value+'&searchoption='+RadioOption+SUF;
	location.href = NuovaPagina;
}

function ControllaFormRicerca(){	
	if(document.getElementById('search').value==''){
		alert('Please insert a valid Part Number!');
		return false;
	}
}
