var d=document;
var efilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
var bkp;
var cv_link;
var xmlhttp = new XMLHttpRequest();
var position_t = 0;
var timestep_t = 10;
var pixstep_t = 1;
var scrolling_t;
var viewed = new Array();
function lang_menu_show() {
	d.getElementById('flag_bg').style.display='';
	d.getElementById('flag_div').style.display='';
	d.getElementById('ln_flag').onclick = function () {lang_menu_hide()}
}

function lang_menu_hide() {
	d.getElementById('flag_bg').style.display='none';
	d.getElementById('flag_div').style.display='none';
	d.getElementById('ln_flag').onclick = function () {lang_menu_show()}
}

function in_array(what,where) {
  var a=false;
  for (var i=0;i<where.length;i++) {
    if(what == where[i]){
      a=true;
      break;
    }
  }
  return a;
}

function pre_resize(name,width,height,num) {
  //detect screen size
    if (!d.all) {
	  w = window.innerWidth;
	  h = window.innerHeight;
	} else {
	  w = d.documentElement.clientWidth;
	  h = d.documentElement.clientHeight;
	}
	//resize for viewable area of browser
	if ((width < w) && (height < h)) {
	  newwidth = width;
	  newheight = height;
	}
	if ((width>=w) && (height>=h)) {
	  ratio = width/height;
	  if (ratio<w/h) {
		newheight = h-30;
		newwidth = width*newheight/height; 
	  }
	  if (ratio>=w/h) {
		newwidth = w-60;
		newheight = newwidth*height/width; 
	  }
	}
	if ((width>=w) && (height<h)) {
	  newwidth = w-60;
	  newheight = newwidth*height/width; 
	}
	if ((width<w) && (height>h)) {
	  newheight = h-30;
   	  newwidth = width*newheight/height; 
	}
    photo_view(name,newwidth,newheight,num);
}

function photo_view(name,width,height,num) {
  ipath = 'images/photos';
  var shadow = d.getElementById("shadow");
  var photo = d.getElementById("photo");
  var gest = d.getElementById('gest');
  var count = d.getElementById('count');
  var loading = d.getElementById('loading');
  var lx = d.getElementById('lx');
  var dx = d.getElementById('dx');
  var cl = d.getElementById('cl');
	//inital src assign while loading img
	photo.src = '../../images/spacer.png';
	loading.style.display = 'none';
	//object layout
	shadow.style.top = '0px';
	shadow.style.left = '0px';
    shadow.style.width = d.body.scrollWidth+'px';
    shadow.style.height = d.body.scrollHeight+'px';
	shadow.style.display = '';
    if (!d.all) {
	  w = window.innerWidth;
	  h = window.innerHeight;
	} else {
	  w = d.documentElement.clientWidth;
	  h = d.documentElement.clientHeight;
	}
	photo.width = width;
	photo.height = height;
	photo.style.left = (w - width)/2+"px";
    if (!d.all) photo.style.top = (h-height)/2+window.pageYOffset+"px"; else photo.style.top = (h-height)/2+d.documentElement.scrollTop+"px";
	photo.style.display = '';
	loading.style.top = (height-148)/2 + parseInt(photo.style.top)+'px';
	loading.style.left = (width-148)/2 + parseInt(photo.style.left)+'px';
	loading.style.display = '';
	gest.style.top = parseInt(photo.style.top) + photo.height*0.8 + "px";
	gest.style.left = photo.width/2 + parseInt(photo.style.left) - 75 + "px";
	gest.style.display = '';
	cl.onclick = function () {delpw(rf);img_close()};
	count.style.top = parseInt(photo.style.top) + photo.height - 13 + 'px';
	count.style.left = parseInt(photo.style.left) + photo.width - 38 + 'px';
	count.style.display = '';
  count.firstChild.innerHTML = 1 + num + ' di ' + Images.length/3;
	rf = Math.round(Math.random()*999999)+1; 
	photo.src = '../../images/photos/'+name+'?'+rf; 
  if (num == 0) 
    lx.onclick = function() {pre_resize(Images[Images.length-3],Images[Images.length-2],Images[Images.length-1],Images.length/3-1);}
  else 
    lx.onclick = function() {pre_resize(Images[3*num-3],Images[3*num-2],Images[3*num-1],num-1);}
  if (num == Images.length/3-1) 
    dx.onclick = function() {pre_resize(Images[0],Images[1],Images[2],0);}
  else 
    dx.onclick = function() {pre_resize(Images[3*num+3],Images[3*num+4],Images[3*num+5],num+1);}
}	
    
function delpw(rf) {
   var params = 'action=delpw&rf='+rf;
   xmlhttp.open("POST",'index.php',true);
   xmlhttp.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
   xmlhttp.setRequestHeader("Content-length", params.length);
   xmlhttp.setRequestHeader("Connection", "close");
   xmlhttp.send(params);
   viewed = new Array();
}

function video_view (vid) {
   var shadow = d.getElementById("shadow");
   var video = d.getElementById("video");
   var exit = d.getElementById('exit');
   shadow.style.top = '0px';
   shadow.style.left = '0px';
   shadow.style.width = d.body.scrollWidth+'px';
   shadow.style.height = d.body.scrollHeight+'px';
   shadow.style.display = '';
   if (!d.all) {
	 w = window.innerWidth;
	 video.style.top = (window.innerHeight-360)/2+window.pageYOffset+"px";
   } else {
	 w = d.documentElement.clientWidth;
	 video.style.top = (d.documentElement.clientHeight-360)/2+d.documentElement.scrollTop+"px";
   }
   video.style.left = (w-480)/2 + "px";
   video.style.width = "480px";
   video.style.height = "360px";
   d.getElementById("video").innerHTML = "<embed type='application/x-shockwave-flash' src='../../video/player.swf' width='480' height='360' name='player' allowfullscreen='true' allowscriptaccess='always' quality='high' pluginspage='http://get.adobe.com/flashplayer' flashvars='file="+vid+"&autostart=true&volume=100'></embed>";
   video.style.display = '';
   exit.style.top = parseInt(video.style.top) + 365 + "px";
   exit.style.left = parseInt(video.style.left) + 197 + "px";
   exit.style.display = '';
   exit.onclick = function () {
     d.getElementById('shadow').style.display='none';
	 d.getElementById('video').style.display='none';
	 d.getElementById('exit').style.display='none';
	  if (d.all) {d.getElementById("video").innerHTML = '';}
   };
}
	
function img_close() {
	d.getElementById('loading').style.display='none';
	d.getElementById('shadow').style.display='none';
	d.getElementById('photo').style.display='none';
	d.getElementById('gest').style.display='none';
	d.getElementById('count').style.display='none';
	d.getElementById('photo').src='';
}
function footer_mouseon() {
	  d.getElementById('last_item').style.backgroundColor='#D6E5F2';
	  d.getElementById('last_item').style.color='#0085CF';
	  d.getElementById('footer').innerHTML='<img src="images/support_imgs/little_box_footer_blue.png">';
}
function footer_mouseout() {
	d.getElementById('last_item').style.backgroundColor='';
	d.getElementById('last_item').style.color='';
	d.getElementById('footer').innerHTML='<img src="images/support_imgs/little_box_footer.png">';
}
 function checkmail(e){
      var returnval=efilter.test(e.value);
	  if (returnval) d.getElementById('dati').submit(); else alert(' Inserire indirizzo e-mail valido');
 }
 function pref_tel() {
   hdl = d.getElementById('phone').value;
   if (hdl.length == 3) d.getElementById('phone').value += '-';
 }
 
 function tel_ctrl() {
   hdl = d.getElementById('phone').value;
   allowed = new Array('0','1','2','3','4','5','6','7','8','9');
/*   if (hdl.length == 3) d.getElementById('phone').value += '-';*/
   if ((!in_array(hdl.substr(hdl.length-1,1),allowed)) && (hdl.substr(hdl.length-1,1) != '-')) {
/*     alert('Riprova');**/
     d.getElementById('phone').value = hdl.substr(0,hdl.length-1);
   }
 }
 function shad_act() {
   var shadow = d.getElementById('shadow').style;
   shadow.position = 'absolute';
   shadow.backgroundColor = '#000000';
   shadow.opacity = '0.4';
   shadow.filter = 'alpha(opacity=40)';
   shadow.zIndex = '900';
   shadow.top = '0px';
   shadow.left = '0px';
   shadow.width = d.body.scrollWidth+'px';
   shadow.height = d.body.scrollHeight+'px';
   shadow.display = '';
   var popup = d.getElementById('popup').style;
   popup.display = '';
   if (!d.all) {
	 w = window.innerWidth;
	 popup.top = (window.innerHeight-33)/2+window.pageYOffset+"px";
   } else {
	 w = d.documentElement.clientWidth;
	 popup.top = (d.documentElement.clientHeight-33)/2+d.documentElement.scrollTop+"px";
   }
   popup.left = (w-200)/2 + "px";
 }
 function anulla() {
   d.getElementById('shadow').style.display = 'none';
   d.getElementById('popup').style.display = 'none';
 }
 function startUpload() {
   if (d.getElementById('fname').innerHTML.length == 0) alert('Scelga prima il file'); else {
     d.getElementById('ul_form').submit();
     bkp = d.getElementById('ul_input').innerHTML;
     d.getElementById('ul_input').innerHTML = "Caricamento in corso...<img src='images/uploading.png'>";
     return true;
   }
 }
 function stopUpload(rand){
   d.getElementById('ul_input').innerHTML = bkp;
   d.getElementById('shadow').style.display = 'none';
   d.getElementById('popup').style.display = 'none';
   d.getElementById('link').innerHTML = basename(d.getElementById('fname').innerHTML);
   cv_link = 'http://netcongress.it/chi-siamo/cvs/'+ rand;
   d.getElementById('cv').value = cv_link;
   return true;   
 }
 function basename(path) {
    var b = path.replace(/^.*[\/\\]/g, '');
    return b;
 }
 function suite() {
   if (basename(d.getElementById('attach').value).length > 12) d.getElementById('fname').innerHTML = basename(d.getElementById('attach').value).substr(0,12)+'....'; else d.getElementById('fname').innerHTML = basename(d.getElementById('attach').value);
 }
 function ech() {
   alert('La richiesta è stata inviata.');
 }
 
 
 function year_move_right(next,year_act) {
 }

