/*------------------------------------------------------------------------------------------------------27/05/2008
Ag. Dotes - Otimizando seus dons - http://www.dotes.com.br - +55(62)3514.1227 | url: http://www.novonorteimoveis.com.br  
Criado por : Luiz Jr. Fernandes | email: contato@dotes.com.br / luizbox@msn.com
---------------------------------------------------------------------------------------------------------------*/

window.addEvent("domready",function(){
	new imgFader({	
		list:"contimage",
		delay:50000,
		transition: "opacity"
	});

	var window_width = window.getWidth();
	$("body").setStyles({"overflow-x":"hidden","overflow-y":"auto !important"});	
	if (window_width < 1000){	$("body").setStyles({"overflow-x":"auto","overflow-y":"auto"});	}
	
	
	$("backslide").fade(.65)
	$$("#form span").fade(0);	$('nxt').fade(.6);$('prv').fade(.6);	

	var fxscroll = new Fx.Scroll('cont_produtos', {			wait: true,			duration: 1500,			offset: {'x': 0, 'y': 0}, 			transition: Fx.Transitions.Back.easeInOut	});
	var increment=280;
	var fxcont = new Fx.Morph("cont_produtos", {duration: 1500, wait:false});
	//Backing to begin
	if ($("cont_produtos").getScroll().y > 50){		fxcont.start({'opacity':.3}).chain(function(){	fxscroll.toTop().chain(function(){	fxcont.start({'opacity':1})	});	});	}


function slideShow(){
	var fxscroll = new Fx.Scroll('cont_produtos', {			wait: true,			duration: 1500,			offset: {'x': 0, 'y': 0}, 			transition: Fx.Transitions.Back.easeInOut	});
	var increment=280;var yCoord = $("cont_produtos").getScroll().y;	var yTotal = $("cont_produtos").getScrollSize().y;			
	var fxcont = new Fx.Morph("cont_produtos", {duration: 1500, wait:false});
	//Backing to begin
	if ((yTotal-yCoord-increment)<(increment)){	
		fxcont.start({'opacity':.3}).chain(function(){	fxscroll.toTop().chain(function(){	fxcont.start({'opacity':1})	});	});	
	}else{
		
		fxcont.start({'opacity':.3}).chain(function(){	fxscroll.start(0,yCoord + increment).chain(function(){	 	fxcont.start({'opacity':1});	 });	});			
	}
}
var slidePeriodical = slideShow.periodical(10000);


$("nxt").addEvent("click",function(event){
								   $clear(slidePeriodical);
			event = new Event(event).stop();			
			var yCoord = $("cont_produtos").getScroll().y;			
			var yTotal = $("cont_produtos").getScrollSize().y;			
			fxcont.start({'opacity':.3});

			if ((yTotal-yCoord-increment)<(increment)){
				fxcont.start({'opacity':.3}).chain(function(){	
															fxscroll.toTop().chain(function(){				
																							 fxcont.start({'opacity':1});		
																							 });			
															});	
			}else{	
				fxcont.start({'opacity':.3}).chain(function(){	
															fxscroll.start(0,yCoord + increment).chain(function(){		
																												 fxcont.start({'opacity':1})		
																												 });	
															});			
				}			   
});
$("nxt").addEvents({		'mouseenter':function(){this.fade(1);this.setProperty("src","images/nxt_on.png")},'mouseleave':function(){this.fade(.6);this.setProperty("src","images/nxt.png")}				   	})
$("prv").addEvent("click",function(event){
								   $clear(slidePeriodical);
			event = new Event(event).stop();
			var yCoord = $("cont_produtos").getScroll().y;
			var yTotal = $("cont_produtos").getScrollSize().y;
			if ( yCoord > 0 ){
				fxcont.start({'opacity':.3}).chain(function(){			fxscroll.start(0,yCoord - increment).chain(function(){				fxcont.start({'opacity':1});			});					});								   
			}
});
$("prv").addEvents({		'mouseenter':function(){this.fade(1);this.setProperty("src","images/prv_on.png")},'mouseleave':function(){this.fade(.6);this.setProperty("src","images/prv.png")}				   });
	//Validating and send contact
	$("btncontato").addEvent("click",function(){
		var stats = true;
	
		var fx = new Fx.Morph("area", {duration: 700});
		if ($("area").value=="ERRO"){			stats = false;			fx.start({'color': ["#FF0000"],'border-color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_area").set('html',' (Selecione uma de nossas op&ccedil;&otilde;es de contato)').fade(1);	}else{			fx.start({'color': ["#98C063"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});	$("v_area").fade(0);	}
		
		var fx1 = new Fx.Morph("nome", {duration: 700});
		if ($("nome").value.length<6){			stats = false;			fx1.start({'color': ["#FF0000"],'border-color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_nome").set('html',' (Insira um nome v&aacute;lido)').fade(1);	}else{			fx1.start({'color': ["#98C063"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});	$("v_nome").fade(0);	}
		
		var fx2 = new Fx.Morph("endereco_mail", {duration: 700});
		if ($("endereco_mail").value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){			stats = false;fx2.start({'color': ["#FF0000"],'border-color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_endereco_mail").set('html',' (Insira um email v&aacute;lido) ').fade(1);	}else{			fx2.start({'color': ["#FFFFFF"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});	$("v_endereco_mail").fade(0);}		
		
		var fx3 = new Fx.Morph("DDD", {duration: 700});
		if ($("DDD").value.length<2){			stats = false;fx3.start({'color': ["#FF0000"],'border-color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_telefone").set('html',' (Campo inv&aacute;lido)').fade(1);	}else{		fx3.start({'color': ["#98C063"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});		$("v_telefone").fade(0);	}		
		
		var fx4 = new Fx.Morph("telefone", {duration: 700});
		if ($("telefone").value.length<8){			stats = false;fx4.start({'color': ["#FF0000"],'border-color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_telefone").set('html',' (Inv&aacute;lido)').fade(1);	}else{		fx4.start({'color': ["#98C063"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});	$("v_telefone").fade(0);	}		
		
		var fx5 = new Fx.Morph("comment", {duration: 700});
		if ($("comment").value.length<15){		$("comment").set("style","border:1px solid #FF0000 !important ");	stats = false;fx5.start({'color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_comment").set('html',' (Escreva aqui sua mensagem)').fade(1);	}else{		fx5.start({'color': ["#98C063"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});	$("comment").set("style","border:1px solid #98C063 !important ");	$("v_comment").fade(0);	}		
		
		var fx6 = new Fx.Morph("titulo", {duration: 700});
		if ($("titulo").value.length<6){			stats = false;			fx6.start({'color': ["#FF0000"],'border-color': ["#FF0000"],'background-color':["#FFCCCC"]});	$("v_titulo").set('html',' (Inv&aacute;lido)').fade(1);}else{			fx6.start({'color': ["#98C063"],'border-color': ["#98C063"],'background-color':["#FFFFFF"]});	$("v_titulo").fade(0);}
		
		if (stats){		
			$("results").set('html',"Aguarde...");
			querysearch = $('form').toQueryString();
			new Request({
						url: 'functions/contatos.php', 
						method: 'get',
						onSuccess:function(resp){
							$('form').reset();
							$("results").set('html',"Enviado com sucesso. Entraremos em contato em breve!");
						}
					}).send(querysearch);	
			
		}
		
	});

	if (!(Browser.Engine.trident)){
		var fxdc = new Fx.Morph("download_catalogo",{wait:false});
		fxdc.start({'opacity':.7});
		$("download_catalogo").addEvents({
			'mouseenter':function(){    fxdc.start({'opacity':.4}).chain(function(){        this.src="images/caixa_download_on.png";fxdc.start({'opacity':1})    });},
			'mouseleave':function(){ 	fxdc.start({'opacity':1}).chain(function(){        this.src="images/caixa_download.png";fxdc.start({'opacity':.7})    });}
		});	
	}else{
		$("main").setStyle("height", $("main").getStyle("height").toInt() - 30)	
		$("body").setStyle("height", $("body").getStyle("height").toInt() - 30)	
	}
	
});


//Block Letters in the contact form
function blockLetters(e)
{	var key;
	var keychar;
	var reg;
	if(window.event) {		key = e.keyCode; 	}
	else if(e.which) {		key = e.which; 		}
	else {		return true;	}
  if((key>=48 && key<=57) || (key==8) || (key==66) ) return true;
  return false;
}

function Abrir(sUrl, iWidth, iHeight){
	var newWin = window.open( sUrl, 'popup', 'scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no, copyhistory=no, height='+iHeight+', width='+iWidth+', top='+(screen.height - iHeight)/2+', left='+(screen.width - iWidth)/2);
}
/*--------------------------------------------*/
/*------|Formatacao de Campos numericos|------*/
function txtBoxFormat(objeto, sMask, evtKeyPress) {

var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
if(document.all){nTecla = evtKeyPress.keyCode;} 
else if(document.layers) {nTecla = evtKeyPress.which;} 
else {
	nTecla = evtKeyPress.which;
    if (nTecla == 8) {return true;}
}
sValue = objeto.value;
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( ")", "" );
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) == "/") || (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++;
}
objeto.value = sCod;
if (nTecla != 8) {
	 if (nTecla==0){return true;}
  if (sMask.charAt(i-1) == "9") { return ((nTecla > 47) && (nTecla < 58)); }
  else { return true;  }
}
else {  return true;}
}


//sIFR Confs.
var gentilis = {
  src: 'gentilis_regular.swf'
};

sIFR.activate(gentilis); // From revision 209 and onwards

sIFR.replace(gentilis, {
  selector: 'h5',css: { '.sIFR-root': { 'color': '#067729', 'letter-spacing':1 } } ,wmode: 'transparent' ,transparent: true
});
sIFR.replace(gentilis, {
  selector: 'h6',css: { '.sIFR-root': { 'color': '#067729', 'letter-spacing':2 } } ,wmode: 'transparent' ,transparent: true
});

