//funzione di creazione dinamica di iframes
//Flash side code:
//	import flash.external.ExternalInterface;
//	var result:String = ExternalInterface.call("openFrame", "myiframeName", );
//align 
// Sets or returns how to align the iframe according to the surrounding text 
// contentDocument 
//  Returns the document the iframe contains 
// frameBorder 
//  Sets or returns whether to display a border for the iframe 
// height 
//  Sets or returns the height of the iframe 
// id 
//  Sets or returns the id of the iframe (In IE 4 this property is read-only) 
// longDesc 
//  Sets or returns a URL to a long description of the iframe 
// marginHeight 
//  Sets or returns the top and bottom margins of the iframe 
// marginWidth 
//  Sets or returns the left and right margins of the frame 
// name 
//  Sets or returns the name of the iframe 
// scrolling 
//  Sets or returns whether the iframe can be scrolled 
// src 
//  Sets or returns the URL to be loaded by the iframe 
// tabIndex 
//  Sets or returns the index that defines the tab order for the iframe 
// width 
//  Sets or returns the width of the iframe
 
 
function getFlashMovie(movieName) {
  	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? parent.window[movieName] : parent.document[movieName];
} 
function alertTagsIn(tgt, filterArray)
{
    var tag, tags;
	if(filterArray==undefined){
		var i;
		tags = "The tags in the page are:"
		for(i = 0; i < tgt.all.length; i++){
			tag = tgt.all(i).tagName;
			tags += "\r" + tag;
		}
	}else{
		var x, i, j;
		for(x in filterArray){
			tags = "The properties in tag "+filterArray[x]+":"
			for(i = 0; i < tgt.all.length; i++){
				tag = tgt.all(i).tagName;
				if(tag==filterArray[x]){
					for(j in tgt.all(i)){
						tags+="\r--->"+j+":"+tgt.all(i)[j];
					}
				}
			}
		}
	}
    alert(tags);
}

function alertPropsIn(tgt, id)
{
    var tag, tags;
	var x, i, j;
	var obj= tgt.getElementById? tgt.getElementById(id): tgt.all? tgt[id]: null;
	tags = "The properties in id:"+id+":"
	for(j in obj){
		tags+="\r--->"+j+":"+obj[j];
	}
	
		
	
    alert(tags);
}
//{cbWin:cbWin,cbId:cbId,cbF:cbF,params:{xid:xid,php:php,xml:xml,qry:qry}}
function swfCall(obj) {
	var iframeName=obj.cbWin, swfname=obj.cbId, functionName=obj.cbF, parameters=obj.params
	//params = "swfCall invoked from "+document.title;
	//for ( var i = 0; i < arguments.length; i++){
	//params = params+"\r\n"+i+":"+arguments[i];
	//}
	//alert(params);
	//alert(parameters);
	if(iframeName==""){
	var td = top.document;
	var swf= td.getElementById? td.getElementById(swfname): td.all? td[swfname]: null;
	}else{
	var td = top.document;
	var obj= td.getElementById? td.getElementById(iframeName): td.all? td[iframeName]: null;
	var tgt = obj.contentWindow.document;
	var swf= tgt.getElementById? tgt.getElementById(swfname): tgt.all? tgt[swfname]: null;
	}
	//alert("swf id is: "+swf.id);
	swf.js(functionName, parameters);
};


function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];
}
activeIframes=[];
function buildiframe (iframeNamesArray) {
	//alert("buildiframe invoked :"+iframeNamesArray);
	var iframeNames =(iframeNamesArray==undefined) ? ["_banner","_iFrame"] : iframeNamesArray;
	//var iframeNames = ["_iFrame","_banner"];
	for(var i in iframeNames){
		//alert(iframeNames[i]);
		var iframe;
		
		if (document.createElement && (iframe = document.createElement('iframe'))) {
			
			iframe.frameBorder="no" ;		
			//iframe.width=0; 
			//iframe.height=0;
			//iframe.scrolling="yes";
			iframe.marginWidth=0;
			iframe.marginHeight=0;
			//iframe.allowTransparency="true";
			iframe.name = iframeNames[i];
			iframe.id = iframeNames[i];
			//iframe.style.zoom = "100%";
			iframe.style.border="0px";
			iframe.style.position ="absolute"; 
			iframe.style.left="0px"; 
			iframe.style.top="0px"; 
			iframe.style.width="0px"; 
			iframe.style.height="0px"; 
			iframe.style.zIndex=i; 
			iframe.style.visibility="hidden";
			iframe.style.backgroundColor="#535353";

			
			//iframe.style.filter = "alpha(opacity=0)";
			//var opacity = 50;
			//iframe.style.filter="alpha(opacity=" + opacity + ")"; 
			//iframe.opacity="50";
			//iframe.src='';
			activeIframes.push({name:iframe.name});
			document.body.appendChild(iframe);
		}
	}
}

function openiframe (iframeUrl,iframeName,xx,yy,ww,hh,tw,th) {
//	params = "openiframe invoked!";
//	for ( var i = 0; i < arguments.length; i++){
//	params = params+"\r\n"+i+":"+arguments[i];
//	}
//	alert(params);
//alert("<"+iframeUrl+">");

	var Wdims = getWindowSize();
	(tw==undefined)?(tw=Wdims[0]):null;
	(th==undefined)?(th=Wdims[1]):null;
	var rx=tw/Wdims[0];
	var ry=th/Wdims[1];
	//
	var iframe = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	if (iframe) {
		if(iframeUrl==undefined){	
		}else{
			iframe.src = iframeUrl;
		}
		iframe.frameborder=0;
		//iframe.style.zoom = "100%";
		iframe.style.left = (xx*rx) + "px";
		iframe.style.top = (yy*ry) + "px";
		iframe.style.width = (ww*rx) +"px";
		iframe.style.height = (hh*ry) +"px";
		iframe.style.visibility = "visible";
	}
	//fadeIn(iframeName, 1000);
		
}
//
//
function setiframeurl (iframeUrl,iframeName) {
//	params = "setiframeurl invoked!";
//	for ( var i = 0; i < arguments.length; i++){
//	params = params+"\r\n"+i+":"+arguments[i];
//	}
//	alert(params);

	var iframe = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	if (iframe) {
		iframe.style.visibility = "visible";
		iframe.src = iframeUrl;
	}
	//fadeIn(iframeName, 1000);
		
}
//
//
//per aiuto
//http://arielsommeria.com/blog/2009/04/22/firefoxs-zoom-messes-up-iframes-with-flex-heres-the-fix/
function setiframe(iframeName,xx,yy,ww,hh,tw,th) {
	//params = "setiframe invoked!";
	//for ( var i = 0; i < arguments.length; i++){
	//params = params+"\r\n"+i+":"+arguments[i];
	//}
	//alert(params);
//alert(iframeName);
	var Wdims = getWindowSize();
	(tw==undefined)?(tw=Wdims[0]):null;
	(th==undefined)?(th=Wdims[1]):null;
	var rx=Wdims[0]/tw;
	var ry=Wdims[1]/th;
	//alert("rx:"+rx+" tw:"+tw+" Wdims[0]:"+Wdims[0]);
	//alert("Width is:"+Wdims[0]+" Height is:"+Wdims[1]);
	//
	var iframe = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	if (iframe) {
		
		iframe.frameborder=0;
		//iframe.style.zoom = "100%";
		iframe.style.left = (xx*rx) + "px";
		iframe.style.top = (yy*ry) + "px";
		//alert("ww:"+ww+" rx:"+rx+" ww*rx:"+(ww*rx));
		iframe.style.width = (ww*rx) +"px";
		iframe.style.height = (hh*ry) +"px";
	}
}


//window.onresize = resize;
//zFactor=1;
function resize(){
	//resizer.onResize
 	//alert("resize event detected!");
	swfCall({cbWin:"",cbId:"ABDR",cbF:"resizer.onResize",params:""});
 //studiati questo
 //http://novemberborn.net/2007/12/javascriptpage-zoom-ff3-128
 //var txt="";
 //for(var i in activeIframes){
 //txt+=activeIframes[i].name;
 //}
 //alert("activeIframes:"+txt);
}

//
//
function closeiframe(iframeName, blankwin) {
	//alert("closeiframe invoked on: "+iframeName+" blankwin:"+blankwin);
	//alert([iframeName,xx,yy,ww,hh]);
	//alert(blankwin);
	var iframe = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	if (iframe) {
		iframe.style.visibility = "hidden";
		(blankwin!=false)?iframe.src = "":null;
	}
}




//
//
// 1 parametro: id dell’oggetto sul quale applicare l’effetto
// 2 parametro: tempo dell’animazione
//
//
// 1 parametro: id dell’oggetto sul quale applicare l’effetto
// 2 parametro: tempo dell’animazione
function fadeIn(identificator, time) { 
//alert("fadeIn invoked on"+identificator+" time"+time);
  var speed = Math.round(time / 100); //arrotonda il valore della divisione
  var frame = 0;

  for(fade = 0; fade < 50; fade++) { 
   setTimeout("setOpacity(\""+identificator+"\", "+fade+")", (speed * frame));
    frame++;
  }

}
//
//
// 1 parametro: id dell’oggetto sul quale applicare l’effetto
// 2 parametro: valore di opacità
function setOpacity(identificator, opacity) { 
//alert("setOpacity invoked on"+id+" opacity:"+opacity);
  var element = document.getElementById(identificator);
 element.style.filter = "alpha(opacity=" + opacity + ")"; 
}
