// EXIBE FLASH

function ExibeFlash(w,h,wmode,movie,flashVars) {
	var isFlashVars = arguments.length==5;
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	if (isFlashVars){
		document.write('<param name="FlashVars" value="'+flashVars+'"/>');
	}
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="'+wmode+'" width="'+w+'" height="'+h+'" ');
	if (isFlashVars){
		document.write(' FlashVars="'+flashVars+'"');
	}
	document.write('></embed>');
	document.write('</object>');
}
// ABRIR POPUPS
function OpenWindow(windowHeight, windowWidth, windowName, windowUri)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);

    newWindow.focus();
    return newWindow.name;
}

// APARECE DIV
function displayDiv(name){
	/*if (document.all[name].style.display ==''){
		document.all[name].style.display ='none';
	}else{
		document.all[name].style.display ='';
	}*/
	var obj = document.getElementById(name);
	if (obj.style.display!='none'){
		obj.style.display='none';
	}else{
		obj.style.display='block';
	}
}


// MUDA FONTE

var tam = 12;

function mudaFonte( tipo ){
	if( tipo == 'mais' ){
		if( tam < 16 ) tam += 2 ;
	}else{
		if( tam > 9 ) tam -= 2 ;
	}
	if( document.getElementById( 'mudaFonte' ) )
		mudaFonteRecursiva( tipo , document.getElementById( 'mudaFonte' ) ) ;

	if( document.getElementById( 'mudaFoto' ) )
	mudaFonteRecursiva( tipo , document.getElementById( 'mudaFoto' ) ) ;
}

function mudaFonteRecursiva( tipo , domElement ){
	for( var i = 0 ; i < domElement.childNodes.length ; i++ ){
		mudaFonteRecursiva( tipo , domElement.childNodes.item( i ) ) ;
	}
	if( domElement.style )
	domElement.style.fontSize = tam+'px';
}


// MENU PRINCIPAL
function menuOver(menu){
	Spry.Utils.removeClassName(menu.id,'change-mouse-out');
	Spry.Utils.addClassName(menu.id,'change-mouse-over');
}
function menuOut(menu){
	Spry.Utils.addClassName(menu.id,'change-mouse-out');
	Spry.Utils.removeClassName(menu.id,'change-mouse-over');
}


function writeRandom(html,array,limit){
	var out = "";
	// ordem aleatória
	array.sort(function(){return 0.5 - Math.random()})
	// exibe a lista
	for(var i=0;i<array.length;i++){
		if(limit == i){
			break;
		}
		var item = array[i];
		var htmlItem = html;
		for (var j=0;j<item.length;j++){
			htmlItem = htmlItem.replace(new RegExp("\\{"+j+"\}","g"),item[j]);
		}
		out+=htmlItem;
	}
	document.write(out);
}


//
// validação indique
//

function validateonsubmitindiquecontent(form){
	if (Spry.Widget.Form.validate(form) == true){
		form.url.value = location.href;
		Spry.Utils.submitForm(form, function(req){
			Spry.Utils.setInnerHTML('motix-response-indique', req.xhRequest.responseText);
			form.reset();
		});
	}
	return false;
}


//
// validação indique
//

function validateonsubmitcomment(form){
	if (Spry.Widget.Form.validate(form) == true){
		Spry.Utils.submitForm(form, function(req){
			location.href = location.href;
		});
	}
	return false;
}


function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
	cntfield.value = maxlimit - field.value.length;
}




// validação flash do player de video
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}