/**
 * Altera a imagem de um respectivo link de imagem
 * @param Object 	objImage		= Objeto da imagem que sera alterada
 * @param String 	urlNewImage		= URL da nova imagem
 */
function changeImageOnMouseOver(objImage, urlNewImage){
	objImage.src = urlNewImage;
}

/**
 * Functions of DW
 */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/**
 * Changes the ADS for users that want show SU in them sites
 * @param format String
 * @return void
 */
function changeSuAds(format){
	if(format == 'img'){
		document.getElementById('divSuAdsText').style.display = 'none';
		document.getElementById('divSuAdsSourceText').style.display = 'none';
		document.getElementById('divSuAdsImg').style.display = 'table-cell';
		document.getElementById('divSuAdsSourceImg').style.display = 'table-cell';
		document.getElementById('divSuAdsSourceImg').select();
		
	}
	else{
		document.getElementById('divSuAdsImg').style.display = 'none';
		document.getElementById('divSuAdsSourceImg').style.display = 'none';
		document.getElementById('divSuAdsText').style.display = 'table-cell';
		document.getElementById('divSuAdsSourceText').style.display = 'table-cell';
		document.getElementById('divSuAdsSourceText').select();
	}
}

/**
 * Creates a FLOATER DIV, above website
 * @param {string} divInsert
 * @return
 */
function createDivFloater(divInsert, widthSize, heightSize){
	this.idOfDivADS = 'FloaterADS';
	this.idDivBackground = "";
	this.body = "";
	this.myDivADS = "";
	
	this.myDivADS = document.createElement("div");
	var docWidth = 0;
	var docHeight = 0;
	
	this.createsButtonClose();
	this.myDivADS.innerHTML = divInsert;
	
	this.myDivADS.setAttribute("id",this.idOfDivADS);
	this.myDivADS.style.zIndex = "99";
	this.myDivADS.id = this.idOfDivADS;
	this.myDivADS.style.position = "absolute";
	
	if(getAgent() == "Netscape"){
		docWidth = window.innerWidth;
		docHeight = window.innerHeight;
	}else{
		docWidth = window.screen.availWidth;
		docHeight = window.screen.availHeight;
	}

	docWidth = parseInt((docWidth - widthSize) / 2);
	docHeight = parseInt((docHeight - heightSize) / 2);
	this.myDivADS.style.left = String(docWidth + "px");
	this.myDivADS.style.top = String(docHeight + "px");
	
	body = document.getElementsByTagName("body")[0];
	html = document.getElementsByTagName("html")[0];
	
	var bgDIV = this.createsSecondDIV('#000000');

	body.appendChild(bgDIV);
	body.appendChild(this.myDivADS);
	
	//this.disableScrollWindow();
	
	this.bodyDocument = body;
	
}

function getAgent(){
	return navigator.appName;
}

/**
 * Creates the Background DIV for clean the other objects
 * @return {Object}
 */
function createsSecondDIV(bgColor){
	if(bgColor == '')
		bgColor = '#FFFFFF';
		
	var secDIV = document.createElement("div");
	secDIV.id = "FloaterAdsBg";
	this.idDivBackground = "FloaterAdsBg";
	secDIV.style.left = "0px";
	secDIV.style.top = "0px";
	secDIV.style.position = "absolute";
	secDIV.style.width = window.screen.availWidth + "px";
	secDIV.style.height = window.screen.availHeight + "px";
	secDIV.style.zIndex = 98;
	secDIV.style.backgroundColor = bgColor;
	secDIV.style.opacity = 0.8;
	secDIV.style.filter = "alpha(opacity='80')";
	return secDIV;
}

/**
 * Creates The Close Button of ADS
 */
function createsButtonClose(){
	var text = document.createElement("a");
	var divButtonClose = document.createElement("div");
	divButtonClose.onclick = this.closeADS; 
	
	text.style.backgroundColor = "#000000";
	text.style.color = "#FFFFFF";
	text.style.cursor = "pointer";
	text.onclick = this.closeADS;
	text.appendChild(document.createTextNode("[X] Fechar"));
	divButtonClose.appendChild(text);
	this.myDivADS.appendChild(divButtonClose);
}

function closeADS(){
	
	var myDivFirst = document.getElementById("FloaterADS");
	var myDivSecond = document.getElementById("FloaterAdsBg");
	document.body.removeChild(myDivFirst);
	document.body.removeChild(myDivSecond);
	//enableScrollWindow();
	
	if(document.getElementById('divLogin')){
		var divLogin = document.getElementById('divLogin');
		divLogin.style.visibility = 'visible';
	}
}

/**
 * Enable scrolls of window
 */
function enableScrollWindow(){
	body.style.overflow = "auto";
	html.style.overflow = "auto";
}

/**
 * Disable scrolls of window
 */
function disableScrollWindow(){
	//bodyDocument.style.overflow = "hidden";
	body.style.overflow = "hidden";
	html.style.overflow = "hidden";
	
}

/**
 * Put on screen a floater banner 
 * 
 * @param {int} withSize
 * @param {int} heightSize
 * @param {string} srcFile
 * @param {bool} IsSWF
 * @param {string} titleValue
 */
function createsFloater(widthSize ,heightSize, srcFile, IsSWF, titleValue, linkUrlImg, urlFrom, idAds){
	srcFile = '/images/publicidade/' + srcFile;
	if(IsSWF){
		
		this.myDivADS = document.createElement("div");
		var noscript = document.createElement("noscript");
		var SWFObject = document.createElement("object");
		var param1 = document.createElement("param");
		var param2 = document.createElement("param");
		var param3 = document.createElement("param");
		var SWFembed = document.createElement("embed");
		var docWidth = 0;
		var docHeight = 0;
		
		SWFembed.setAttribute("src",srcFile);
		SWFembed.setAttribute("width",widthSize);
		SWFembed.setAttribute("height",heightSize);
		SWFembed.setAttribute("pluginspage","http://www.macromedia.com/go/getflashplayer");
		SWFembed.setAttribute("type","application/x-shockwave-flash");
		SWFembed.setAttribute("scale","exactfit");
		SWFembed.setAttribute("quality","high");
		
		this.createsButtonClose();
		this.myDivADS.appendChild(SWFembed);
		
		this.myDivADS.setAttribute("id",this.idOfDivADS);
		this.myDivADS.style.zIndex = "99";
		this.myDivADS.style.position = "absolute";
		
		if(this.getAgent() == "Netscape"){
			docWidth = window.innerWidth;
			docHeight = window.innerHeight;
		}else{
			docWidth = window.screen.availWidth;
			docHeight = window.screen.availHeight;
		}

		docWidth = parseInt((docWidth - widthSize) / 2);
		docHeight = parseInt((docHeight - heightSize) / 2);
		this.myDivADS.style.left = String(docWidth + "px");
		this.myDivADS.style.top = String(docHeight + "px");
		
		body = document.getElementsByTagName("body")[0];
		html = document.getElementsByTagName("html")[0];
		
		var bgDIV = this.createsSecondDIV();

		body.appendChild(bgDIV);
		body.appendChild(this.myDivADS);
		this.loadFlash(srcFile,widthSize,heightSize);
		
		//this.disableScrollWindow();
		
		this.bodyDocument = body;
		
		countSeconds();
	}else{
	
		this.myDivADS = document.createElement("div");
		
		var divMask = document.createElement("div");
		var IMG = document.createElement("img");
		var linkImg = document.createElement("a");
		var docWidth = 0;
		var docHeight = 0;
		
		IMG.setAttribute("src",srcFile);
		IMG.setAttribute("width",widthSize);
		IMG.setAttribute("height",heightSize);
		IMG.setAttribute("alt", titleValue);
		IMG.setAttribute("title", titleValue);
		IMG.setAttribute("border", '0');
		
		linkImg.setAttribute("href", linkUrlImg);
		linkImg.setAttribute("target", '_blank');
		
		var execAjaxFcn = "countVisits('" + urlBaseJS + "','" + urlFrom + "', '" + idAds + "'," + (IsSWF ? "true" : "false") + ")";
		divMask.setAttribute("onmouseup", execAjaxFcn);
		
		this.createsButtonClose();
		linkImg.appendChild(IMG);
		divMask.appendChild(linkImg);
		this.myDivADS.appendChild(divMask);
		
		this.myDivADS.setAttribute("id",this.idOfDivADS);
		this.myDivADS.style.zIndex = "99";
		this.myDivADS.style.position = "absolute";
		
		if(this.getAgent() == "Netscape"){
			docWidth = window.innerWidth;
			docHeight = window.innerHeight;
		}else{
			docWidth = window.screen.availWidth;
			docHeight = window.screen.availHeight;
		}

		docWidth = parseInt((docWidth - widthSize) / 2);
		docHeight = parseInt((docHeight - heightSize) / 2);
		this.myDivADS.style.left = String(docWidth + "px");
		this.myDivADS.style.top = String(docHeight + "px");
		
		var body = document.getElementsByTagName("body")[0];
		
		//body.style.overflow = "hidden";
		
		var bgDIV = this.createsSecondDIV();

		body.appendChild(bgDIV);
		body.appendChild(this.myDivADS);
		this.loadFlash(srcFile,widthSize,heightSize);
		
		if(document.getElementById('divLogin')){
			var divLogin = document.getElementById('divLogin');
			divLogin.style.visibility = 'hidden';
		}
		
		bodyDocument = body;
		
		countSeconds();
		
	}
}

function countSeconds(){
	if (milisec>=9){
		milisec = 0;
		seconds += 1;
	}else
		milisec += 1;
	if(seconds<12)
		setTimeout("countSeconds()",100);
	else
		closeADS();
}
