// JavaScript Document

window.onload = function(){
	size=getCookie("fontsize");             //reperisce il cookie
	if(size!=null) SetFontSize('normal');       //setta le impostazioni	
	imgBgTool= new Image(1182,490);
	imgBgTool.src="i/bgTool.jpg";
	
	checkingURL();
}
	
function SetFontSize(type){
	if(type=='high'){
		s='1.1';
	}
	else if(type=='medium'){
		s='1.05';
	}
	else{
		s='1.0';	
	}	
	document.getElementsByTagName('body')[0].style.fontSize = s+'em';
	setCookie("fontsize",s,30);
}

function setCookie(name, value, expdays) {   //memorizza il cookie
	var now = new Date();
	var exp = new Date(now.getTime() + (1000*60*60*24*expdays));
	document.cookie = name + "=" + escape(value) + ";" + "expires=" + exp.toGMTString() + ";" + "path=/";
}

function getCookie(name) {    //restituisce il cookie
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		var start = dc.indexOf(cname);
		if (start != -1) {
			start += cname.length;
			var stop = dc.indexOf(";", start);
			if (stop == -1) stop = dc.length;
			return unescape(dc.substring(start,stop));
			}
		}
	return null;
}
//EO RESIZE TEXT



function addFlash(u, w, h, t, s, va, ha, n, b, v){
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + w + '" height="' + h + '" id="' + n + '" align="middle" >');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="allowFullScreen" value="false" />');
    document.write('<param name="movie" value="' + u + '" />');
    document.write('<param name="quality" value="high" />');
    if (s == 'y') {
        document.write('<param name="scale" value="noscale" />');
        var vaPar = '', haPar = '';
        if (va == 'top') {
			vaPar = 't';
        }
        if (va == 'bottom') {
            vaPar = 'b';
        }
        if (va == 'middle') {
            vaPar = '';
        }
        if (ha == 'left') {
            haPar = 'l';
        }
        if (ha == 'right') {
            haPar = 'r';
        }
        if (ha == 'middle') {
            haPar = '';
        }        
        document.write('<param name="salign" value="' + vaPar + '' + haPar + '" />');        
    }
    if (b != '') {
        document.write('<param name="bgcolor" value="' + b + '" />');
    }
    if (t == 'y') {
        document.write('<param name="wmode" value="transparent">');
    }
    if (v != 'n') {
        document.write('<param name="flashvars" value="' + v + '">');
    }
    document.write('<embed src="' + u + '" quality="high"');	
	if (s == 'y') {
        document.write(' scale="noscale"');
        var vaPar = '', haPar = '';
        if (va == 'top') {
            vaPar = 't';
        }
        if (va == 'bottom') {
            vaPar = 'b';
        }
        if (va == 'middle') {
            vaPar = '';
        }
        if (ha == 'left') {
            haPar = 'l';
        }
        if (ha == 'right') {
            haPar = 'r';
        }
        if (ha == 'middle') {
            haPar = '';
        }        
        document.write(' "salign="' + vaPar + '' + haPar + '"');        
    };
	if (b != '') {	
		document.write(' bgcolor="' + b + '"');
	};	
	if (t == 'y') {
        document.write(' wmode="transparent"');
    };
    if (v != 'n') {
        document.write(' flashvars="' + v + '"');
    };
    document.write(' width="' + w + '" height="' + h + '" name="' + n + '"');
    document.write(' align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

function openTool(e){
	window.scrollTo(0,0);
	
	if (!$('tool_bg')) {
		if(e.name.substr(0,2)=='i_'){
			urlImage = '../i/bgTool.jpg';
			position = 'index';
		}else{
			urlImage = '../../i/bgTool.jpg';
			position = 'internal';
		}
		var tool_shadow1 = Builder.node('div', {className: 'sh1'});
		var tool_shadow2 = Builder.node('div', {className: 'sh2'});
		var tool_shadow3 = Builder.node('div', {className: 'sh3'});
		var tool_shadow4 = Builder.node('div', {className: 'sh4'});
		var tool_shadow5 = Builder.node('div', {className: 'sh5'});
		var tool_contShad = Builder.node('div', {className: 'contShad', id: 'contShad'});
		var tool_cont = Builder.node('div', {className: 'tool_cont',id: 'tool_cont'});
		var tool_bg = Builder.node('div', {className: 'tool_bg',id: 'tool_bg'});		
		var tool_btnClose = Builder.node('div', {id: 'btnClose'});
		var tool_btnCloseHref = Builder.node('a', {onclick: 'closeTool(this,\''+position+'\');',href: 'javascript:void(0);'}, 'CLOSE');
		tool_contShad.appendChild(tool_shadow1);
		tool_contShad.appendChild(tool_shadow2);
		tool_contShad.appendChild(tool_shadow3);
		tool_contShad.appendChild(tool_shadow4);
		tool_contShad.appendChild(tool_shadow5);
		$('toolbar').appendChild(tool_contShad);		
		tool_bg.appendChild(tool_cont);		
		$('toolbar').appendChild(tool_bg);		
		$$('div.cont')[0].getElementsByTagName('UL')[0].className = "open";
		$('toolbar').style.background = 'url('+urlImage+') top center no-repeat #98000e';
		$('tool_bg').style.display = "none";
		$$('A.t').each(function(a){a.target = "frame";});		
		$$('A.r')[0].parentNode.className = "";
		new Effect.SlideDown('tool_bg', {duration:.6,afterFinishInternal:function(){			
			var tool_iframe = Builder.node('iframe', {src: e.href,id: 'frame',
				name: 'frame',				height: '420',
				width: '960',
				frameborder: '0',
				marginwidth: '0',
				marginheight: '0',
				align: 'middle',
				scrolling: 'no',
				allowtransparency:'true'
			});
			$('tool_cont').appendChild(tool_iframe);
		}});
		tool_btnClose.appendChild(tool_btnCloseHref);
		$('headLogo').appendChild(tool_btnClose);
		$('btnClose').style.display = "none";
		new Effect.Appear($('btnClose'),{duration:.6});
		e.className = "t on";
		e.parentNode.className = "on";		
	}else{
		$$('A.t').each(
			function(b){
				b.className = "t";
				b.parentNode.className = "";
			}
		);
		e.className = "t on";
		e.parentNode.className = "on";		
		$('frame').src = e.href; 
	}
	
}

function closeTool(e,b){
	
	if(b=='index'){
		urlImage='../i/tb_bg.gif';
	}else{
		urlImage='../../i/tb_bg.gif';	
	}
	
	Element.remove('frame');
	new Effect.SlideUp('tool_bg',{
		duration:.7,
		afterFinishInternal:function(){
			$$('div.cont')[0].style.display = "block";
			Element.remove('tool_bg');	
			$('toolbar').style.background = 'url('+urlImage+') #e6e6e6 repeat-x bottom left';
			var li = $('menuTool').getElementsByTagName('LI');
			for (var i=0; i<li.length; i++) {
				if(li[i].firstChild.className!='r'){
					li[i].className = "";
					li[i].firstChild.className = "t";
				}
				else{
					li[i].className = "linkTopRed";	
				}
			};
			Element.remove('contShad');
			$$('div.cont')[0].getElementsByTagName('UL')[0].className = "";		
		}
	});

	new Effect.Fade(e.parentNode,{
		duration:.6,
		afterFinishInternal: function(){
			Element.remove(e.parentNode);
		}});	
}

function openAcc(coll){
	var li = coll.parentNode;
	var idDiv = li.id.replace("tit","txt");
	if (li.className=='row'){
		
		var li_aperto = $$('div.row.open')[0];
		if(li_aperto){
			li_aperto.className='row';
			var idDiv_aperto = li_aperto.id.replace("tit","txt");
			$(idDiv_aperto).style.display='none';
		}
		li.className='row open';
		$(idDiv).style.display='block';
	}
	else{
		li.className='row';
		$(idDiv).style.display='none';	
	}
}

function openNews(idNews){
	
	if($(idNews).className=='rowContEl opened'){
		
		$(idNews).className='rowContEl close';
	}
	else{
		newsAperta = $$('div.rowContEl.opened')[0];
		if(newsAperta){
			newsAperta.className='rowContEl close';
		}
	
		$(idNews).className='rowContEl opened';
	}
}

function openPers(idDiv){
	if($(idDiv).style.height=='0px' || $(idDiv).style.height==''){
		if(idDiv=='double') h=160;
		else h=70;
		$(idDiv).morph('height:'+h+'px;overflow:visible;');
		return false;
	}
	else{
		$(idDiv).morph('height:0px;overflow:hidden;');
		return false;	
	}
	
}
function openDiv(idDiv){
	if($(idDiv).className=='hide'){
		$(idDiv).className='show';
			
	}
	else{
		$(idDiv).className='hide';
	}
	
}

function mailtoJS(linko){
	
	if($('privacy').checked==true){
		invio=true;
		text = '';
		if ( $('name_p').value!='') text+='nome: '+$('name_p').value+'%0A';
		else{invio=false;}
		if ( $('qualifica_p').value!='') text+='qualifica: '+$('qualifica_p').value+'%0A';
		else{invio=false;}
		if ( $('name_a').value!='') text+='nome azienda: '+$('name_a').value+'%0A';
		else{invio=false;}
		if ( $('piva').value!='') text+='partita iva: '+$('piva').value+'%0A';
		else{invio=false;}
		if ( $('mail').value!='') text+='mail: '+$('mail').value+'%0A';
		else{invio=false;}
		if ( $('tel').value!='') text+='telefono: '+$('tel').value+'%0A';
		else{invio=false;}
		
		if(invio==false){
			alert('tutti i campi sono obbligatori');
		}
		else{
			window.location.href="mailto:Reclami.unicreditfactoring.it@unicreditgroup.eu?subject=Richiesta di adesione&body="+text;
		}
	}
	else
	{	
		alert('Devi accettare le norme di trattamento dei dati e prendere visione della normativa sulla privacy ');	
	}
}

function checkingURL(){
	uerel = ' '+document.location;
	percorso = uerel.split("?");
	sezione = percorso[1];
	
	if(sezione == 'contatti'){
		
		openTool(openTool($('btncontatti')));
		
			
	}
}
