// ###########################################################################################################	
//     INICIALIZAÇÕES 
// ###########################################################################################################	

// --> FIX FLASH OBJECT

theObjects = document.getElementsByTagName("object");
for (var i = 0; i < theObjects.length; i++)
{
	theObjects[i].outerHTML = theObjects[i].outerHTML;
}
		

// --> PNG FIX

	$(document).ready(function(){
		$('#principal').pngFix( );
	});
	



function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<a href="' + item.lk + '"><img src="' + item.url + '" width="181" height="143" alt="' + item.title + '" /></a>';
};


// --> FULL BANNER

$(function() {
		   
    $('#fade').cycle({
       fx:     'blindX',
       speed:   1000,
       timeout: 10000,
       delay:  -4000,
	   pager:   '#nav',
	   pagerAnchorBuilder: pagerFactory
    });
	
	function pagerFactory(idx, slide) {

        var s = idx > 4 ? ' style="display:none"' : '';

        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';

    };

});




// --> MODAL PANEL



$(function() {
		   
		function preloadImg(image) {
			var img = new Image();
			img.src = image;
		}

		preloadImg('imgs/ajaxLoader.gif');
		preloadImg('imgs/prev.gif');
		preloadImg('imgs/next.gif');

	});

// --> BANNERS

$(function() {
    $('#banners').cycle({
		speed:   5000
    });

});


// --> BENEFÍCIOS

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// --> FLASH TOPO

function flash_topo() {
  var obj_str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="778" height="92" id="topo" align="middle">';
  obj_str += '<param name="movie" value="topo.swf" />';
  obj_str += '<param name="quality" value="high" />';
  obj_str += '<param name="wmode" value="transparent" />';
  obj_str += '<param name="bgcolor" value="#f8f8f8" />';
  obj_str += '<embed src="topo.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="778" height="92" name="topo" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
  obj_str += '</object>';
  document.write(obj_str);
}

// --> VALIDA LOGIN


function PermiteApenasNumeros(e, campo)
{
	var Digit = parseInt(eval(((navigator.appName == "Netscape")?"e.which":"e.keyCode" )))

	if (!(Digit>47 && Digit<58 || Digit == 8 || Digit == 0 || Digit == 13))				
	{
		alert ("Favor digitar somente caracteres numéricos");
	    document.login.edtcodigo.focus();
		return false;	
	}
	
	return true;
}

function conta_senha(campo) {
	vr = campo.value;
	tam = vr.length;
	

	if ( tam <= 6) {
		document.login.area[0].checked = 'checked';
	}
	
	if ( tam >= 8) {
		document.login.area[1].checked = 'checked';
	}
	
}

function check_login() {
	
	// ÁREA
	var j = 0;
	if (document.login.area.length != null) {
		for (var i=0; i<document.login.area.length; i++) {
			if (document.login.area[i].checked == true) {
				j = 1;
				
					// SE FOR SCPC
					if (document.login.area[0].checked == true) {
						// CÓDIGO SCPC
						if (document.login.edtcodigo.value == "") {
							alert("Preencha o Campo CÓDIGO SCPC.");
							document.login.edtcodigo.focus();
							return (false);
						}
						// SENHA SCPC
						if (document.login.edtsenha.value == "") {
							alert("Preencha o Campo SENHA.");
							document.login.edtsenha.focus();
							return (false);
						}
						document.login.action="http://www.acirp.com.br/recic/scripts/pscpc.exe/login";
                    	document.login.submit(); 
					}
					
					// SE FOR ACIRP
					if (document.login.area[1].checked == true) {
						// CÓDIGO ACIRP
						if (document.login.edtcodigo.value == "") {
							alert("Preencha o Campo CÓDIGO ACIRP.");
							document.login.edtcodigo.focus();
							return (false);
						}
						// SENHA ACIRP
						if (document.login.edtsenha.value == "") {
							alert("Preencha o Campo SENHA.");
							document.login.edtsenha.focus();
							return (false);
						}
						
						if (document.login.edtsenha.value != "") {
							vr = document.login.edtsenha.value;
							tam = vr.length;
								if ( tam < 8 || tam > 32) {
									alert("A senha de acesso para a ACIRP é diferente da senha do SCPC \n e deve conter no mínimo \"8\"  CARACTERES. \n\n Inicialmente a senha da ACIRP é o CNPJ da empresa");
									document.login.edtsenha.focus();
									return(false);
								}
						}
						document.login.action="valida.php";
                    	document.login.submit(); 
					}
			}
			
		}
	} else {
		if (document.login.area.checked)
			j = 1;
	}
	
	if (j != 1) {
		alert('Selecione uma area de acesso SCPC ou ACIRP');
		return (false);
	}	

  return (true);
}


//--> FAQ

function panel_down(y) {
        document.getElementById('pd' + y).className = "panel_down";
	
        for (var i=1; i<=numero_itens; i++) {
        	if (i != y) {
	            document.getElementById('pd' + i.toString()).className = "panel_down_off";
	        }
        }
    }
	
// --> JUMP MENU

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// --> POPUP

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// --> CARREGA PÁGINA

function caregaPagina(bla, ble){
var page = bla;
var id_div = ble;

//alert(paragrafo);
   
  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });
  
 $.ajax({
   type: "GET",
   url: page,
   data: "",
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });


}


// --> AJAX EVENTO 1

function evento(bla, ble){
var page = bla;
var id_div = ble;

   
  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });
  
 $.ajax({
   type: "POST",
   url: page,
   data: "",
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });

}

// --> AJAX EVENTO 2

function evento2(bla, ble, bli){
var page = bla;
var id_div = ble;
var destino = bli;

var paragrafo = destino.value;

//alert(paragrafo);
   
  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });
  
 $.ajax({
   type: "GET",
   url: page,
   data: "valor="+paragrafo+"",
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });


}

// --> AJAX CPF

function Verifica_CPF(bla, ble, bli){
var page = bla;
var id_div = ble;
var destino = bli;

var paragrafo = destino.value;

//alert(paragrafo);
   
  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });
  
 $.ajax({
   type: "GET",
   url: page,
   data: "recebe="+paragrafo+"",
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });


}

// --> AJAX GERAL

function AJAX_Geral(bla, ble, bli){
var page = bla;
var id_div = ble;
var destino = bli;
var paragrafo = destino.value;

//alert(paragrafo);
   
  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });
  
 $.ajax({
   type: "GET",
   url: page,
   data: "recebe="+paragrafo+"",
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });


}

// --> AJAX email

function Verifica_EMAIL(bla, ble, bli){
var page = bla;
var id_div = ble;
var destino = bli;

var paragrafo = destino.value;

//alert(paragrafo);
   
  $().ajaxStart(function() { $('#loading').show(); });
  $().ajaxStop(function() { $('#loading').hide(); });
  
 $.ajax({
   type: "GET",
   url: page,
   data: "recebe="+paragrafo+"",
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });


}

// ------------------------------- AJAX CONTEÚDO2 -----------------------------------
function Cargo(bla, ble, bli){
var page = bla;
var id_div = ble;
var destino = bli;



 $().ajaxStart(function() { $('#loading').show(); });
 $().ajaxStop(function() { $('#loading').hide(); });

 $.ajax({
   type: "GET",
   url: page,
   data: "recebe="+destino.options[destino.selectedIndex].value,
   success: function(msg){
     $('#'+id_div+'').html(msg);
   }
 });

}







//--------------------------------------------------------------------------------------------------
//        PNG FIX         
//--------------------------------------------------------------------------------------------------

/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[@src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[@src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);

