function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
	  if(a.getAttribute("media") == "print") a.disabled = false;
    }
  }
  if (reset == 1) {
  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
var style = readCookie("wstyle");
if (style != null) {
setActiveStyleSheet(style, 0);
}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+escape(value)+expires+"; path=/;";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
  }
  return null;
}

if (window.addEventListener) window.addEventListener("load",setStyle,false);
else if (window.attachEvent) window.attachEvent("onload",setStyle);

function adicionaClipping(iddetalhe,idusuario,pagina){
	if (idusuario!=0){
		window.open("addclipping.aspx?pagina="+pagina+"&idusuario="+idusuario+"&id_detalhe="+iddetalhe,"addclipping","status=no,width=2,height=2,left=10000,top=0");
	}
	else
	{
		alert("Por favor cadastre-se para acessar esta área do site.");
		location.href="cadastro.aspx";
	}
}

function abreDoc(URL,idusuario,logado,interna){
	if (logado==1) {
		if (idusuario!=0){
			if (interna==1) {
				location.href=URL;
			}
			else
			{
				window.open(URL,"AMI_Pop","menubar=yes,resizable=yes,scrollbars=yes,toobar=yes,status=yes,width=500,height=300,left=0,top=0");
			}
		}
		else
		{
			alert("Você deve ser associar-se para acessar esta seção do site. Caso você já seja um associado execute o 'login'.");
			location.href="cadastro.aspx";
		}
	}
	else
	{
		if (interna==1) {
			location.href=URL;
		}
		else
		{
			window.open(URL,"AMI_Pop","menubar=yes,resizable=yes,scrollbars=yes,toobar=yes,status=yes,width=500,height=300,left=0,top=0");
		}
	}
}

function trim(vString){
    return vString.replace(/^\s+|\s+$/ig, '');
}
 
function clickInText(obj){
    var valorinicial = trim(obj.getAttribute('valorInicial'));
    if ( trim(obj.value) == valorinicial ) {
        obj.value = '';     
    }
}
 
function clickOutText(obj){
    var valorinicial = trim(obj.getAttribute('valorInicial'));
    if ( trim(obj.value) == '' ) {
        obj.value = valorinicial;     
    }
}
 
function clickInPass(obj1, obj2){
    var valorinicial = trim(obj1.getAttribute('valorInicial'));
    if ( trim(obj1.value) == valorinicial ) {
        obj1.style.display = 'none';
        obj2.style.display = 'inline';
        obj2.value = '';
        obj2.focus();
    }
}
 
function clickOutPass(obj1, obj2){
    var valorinicial = trim(obj1.getAttribute('valorInicial'));
    if ( trim(obj2.value) == '' ) {
        obj2.style.display = 'none';
        obj1.value = valorinicial;
        obj1.style.display = 'inline';
    }
}



/* Barra de botões */
function MM_openBrWindow(theURL,winName,features){
  window.open(theURL,winName,features);
}

function MM_openIndique(id){ 
  location.href='indique.aspx?id_detalhe='+id;
}

function MM_openIndique(id){ 
  location.href='indique.aspx?id_detalhe='+id;
}

function fonteMais(){
	var cx = document.getElementById('lblTexto');
	var cx1 = document.getElementById('lblTexto2');
	var cx2 = document.getElementById('lblTextoUnico');
    var cx3 = document.getElementById('lblTexto3');
	var tam = cx.style.fontSize;
	switch (tam){
		case '':
			tam='120%'
			break;
		case '100%':
			tam='120%'
			break;
		case '120%':
			tam='140%'
			break;
		case '140%':
			tam='160%'
			break;
	}
	cx.style.fontSize = tam;
	cx1.style.fontSize = tam;
	cx2.style.fontSize = tam;
    cx3.style.fontSize = tam;
}
function fonteMenos(){
	var cx = document.getElementById('lblTexto');
	var cx1 = document.getElementById('lblTexto2');
	var cx2 = document.getElementById('lblTextoUnico');
    var cx3 = document.getElementById('lblTexto3');
	var tam = cx.style.fontSize;
	switch (tam){
		case '':
			tam='100%'
			break;
		case '160%':
			tam='140%'
			break;
		case '140%':
			tam='120%'
			break;
		case '120%':
			tam='100%'
			break;
	}
	cx.style.fontSize = tam;
	cx1.style.fontSize = tam;
	cx2.style.fontSize = tam;
    cx3.style.fontSize = tam;
}
function fonteNormal(){
	var cx = document.getElementById('lblTexto');
	cx.style.fontSize = '100%';
	var cx1 = document.getElementById('lblTexto2');
	cx1.style.fontSize = '100%';
	var cx2 = document.getElementById('lblTextoUnico');
	cx2.style.fontSize = '100%';
    var cx3 = document.getElementById('lblTexto3');
	cx3.style.fontSize = '100%';
}


// JavaScript Document
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(document.all) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(document.layers) { // Nestcape
       nTecla = evtKeyPress.which;
     }

     sValue = objForm[strField].value;

     // Limpa todos os caracteres de formatação que
     // já estiverem no campo.
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( " ", "" );
     sValue = sValue.toString().replace( " ", "" );
     fldLen = sValue.length;
     mskLen = sMask.length;

     i = 0;
     nCount = 0;
     sCod = "";
     mskLen = fldLen;

     while (i <= mskLen) {
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

       if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++; }
       else {
         sCod += sValue.charAt(nCount);
         nCount++;
       }

       i++;
     }

     objForm[strField].value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
   }//txtBoxFormat

function abrePop(URL,paginaOrigem){
	alert(URL);
	alert(paginaOrigem);
	//window.open(URL,'pop','toolbar=true,titlebar=true,scrollbars=true,menubar=true,resizable=true,status=no,width=500,height=200,left=0,top=0');
	//location.href=paginaOrigem;
}
