// JavaScript Document

function selection(obj, set_text_default){   
    /* @author Bernardo Rufino  
     * @license Creative Commons Developing Nations: http://creativecommons.org/licenses/devnations/2.0/  
     * @description Function to manipulate the actual selection  
     * @returns It returns an object with an attribute *text* with the current selection text and  
     *        a method *setText()* that receives one argument, the text to be set in the selection.  
     * @parameters The first is the object where you want the selection (DOM or String with id), and  
     *           the second (optional), a boolean, if is true then the *setText()* method will  
     *           append the text if there's no way to replace the selection.  
     *  
     *     !Nao retire essas informacoes!  
     *     !Do not drop this information!  
    */  
    if(obj.constructor == String){
	
		obj = document.getElementById(obj);
	
	}   
	
    var set_text = (set_text_default) ? function(text){obj.value += text;} : function(){return false;};   
    var selection = {text: null, setText: set_text};   
    if(document.selection){   
        
		var range = document.selection.createRange();   
		if (range.text !=""){
		
		selection.text = range.text;   
		selection.setText = function(text){   
		range.text = text.replace(/\\r?\\n/g, "\\r\\n");   
			
		}
		}
    } else if(typeof(obj.selectionStart) != "undefined"){   
        
		selection.text = obj.value.substring(obj.selectionStart, obj.selectionEnd);   
        selection.setText = function(text){   
			if(text != null && text != ""){
            obj.value = obj.value.substring(0, obj.selectionStart) + text + obj.value.substring(obj.selectionEnd);   
			}
        }   
    } else if(window.getSelection){   
        selection.text = window.getSelection().toString();   
		 
    }   
	
    return selection;   
}  

function handleEnter (field, event) {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if (keyCode == 13) {
            field.value += "<br>"
        } 
    }      


function SetBold(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<b>" + selected.text + "</b>");  
	}
}

function SetItalic(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<i>" + selected.text + "</i>");  
	}
}

function SetUnderline(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<u>" + selected.text + "</u>");  
	}
}
function SetCenter(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<center>" + selected.text + "</center>");  
	}
}
function SetRight(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<div align='right'>" + selected.text + "</div>");  
	}
}
function SetLeft(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<Div align='left'>" + selected.text + "</div>");  
	}
}







function ajaxInit() {
	var req;
	try {
		 req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		 try {
			  req = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch(ex) {
		 try {
		   req = new XMLHttpRequest();
	     } catch(exc) {
	 		  alert("Esse browser não tem recursos para uso do Ajax");
	  		 req = null;
	     }
	 }
}
return req;
}

function PreviewPanel(texto) {
	ajax = ajaxInit();
	
	if(ajax) {
			ajax.open("GET","PreviewPanel.asp?texto=" + texto, true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						
						document.getElementById("PreviewPanel").innerHTML = ajax.responseText;
						
					}else{	
						alert(ajax.statusText)
					}
				}
			}
			ajax.send(null);
		
	}
}

function verificaEmail(email) {
	ajax = ajaxInit();
	if(ajax) {
		ajax.open("GET","verifica_email.asp?email=" + email, true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					
					document.getElementById("alerta").value = ajax.responseText;
					if(document.getElementById("alerta").value == 'N'){
						document.getElementById("textoAlerta").style.display = "";
					}
					
				}else{	
					alert(ajax.statusText)
				}
			}
		}
		ajax.send(null);		
	}
}

function Confirm(text, url) {
	var answer = confirm(text)
	if (answer){
		location.href = url;
		
	}
	else{
		
	}
}

function ConfirmForm(text) {
	var answer = confirm(text)
	if (answer){
		return true;
		
	}
	else{
		return false;
	}
}

var win = null;
function NewWindowPanel(valor){
	
	LeftPosition = (screen.width) ? (screen.width-400)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-300)/2 : 0;
	settings =
	'height=300,width=400,top='+TopPosition+',left='+LeftPosition+',scrollbars=Yes,resizable'
	win = window.open("PreviewPanel.asp?texto="+valor,"",settings)
}



var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

function foco(){
	document.forms[0].elements[0].focus();
}


// JavaScript Document
var altMax = 0
function showBanner(imagem, url)
{
	objImg = new Image()
	objImg.src = 'imagens/'+imagem 
	var img_b = 'imagens/'+imagem
	var url
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;


	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	pageWidth = parseInt(pageWidth)-25
	
	
	if (document.all)
	{
		//var wtop = parseInt(document.documentElement.scrollTop) + 20
		var wtop = ( (parseInt(screen.height) - 450) / 2 ) - 50
		
	}
	else
	{
		//var wtop = parseInt(window.scrollY) + 20
		var wtop = ( (parseInt(screen.height) - 450) / 2 ) - 50
	}
	
	
	var wleft = ( (parseInt(pageWidth) - 1000) / 2 ) 
	wleft = parseInt(wleft) + ( (1000-parseInt(477)) / 2)
	wleft = parseInt(wleft)
	
	$("#caixaCores").remove()
	$("#fundoOpacoBannner").remove()	
	str = "<div id='caixaCores'>"				
	str += "<label onclick='"+url+"'><img src='"+img_b+"' alt='' border='0'></label>"
	//str += "<img src='"+img_b+"' alt='' border='0'>"
	str += "<div id='div_fecharCor'><img src='imagens/fecha_cartaz.jpg' id='btn_fechar' title='Fechar' alt='Fechar'></div>"
	str +="</div>"

	
	$(str).css("left",wleft).css("top",wtop).appendTo("body")	
	
	$("#btn_fechar").click(function(){
		$("#caixaCores").remove()		
		$("#fundoOpacoBannner").remove()
		foto_atual = 0;
		id_foto_atual = "#img_0"
	})

	
	
	$("<div id='fundoOpacoBannner'>&nbsp;</div>").appendTo("body")		
	
	objF = document.getElementById('fundoOpacoBannner')
	objF.style.width = pageWidth + "px"
	
	objF.style.height = (pageHeight+100) + "px"
	$("#fundoOpacoBannner").click(function(){
		$("#div_fecharCor").remove()		
		$("#caixaCores").remove()		
		$("#fundoOpacoBannner").remove()		
		foto_atual = 0;
		id_foto_atual = "#img_0"
		
		
	})
	
}