/**
 * @author rochadel
 */
 
function SimpleSwap(el,which){
        el.src = el.getAttribute(which||"origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

//Funcao para inclusao de script 
function includeDomNode(script_filename) {
	    if (document.getElementById('id_'+script_filename) != null) {
	    	//var roll = document.getElementsByTagName('head').item(0);
	    	//roll.removeChild(true);
	    	return false;
	    }
	    var html_doc = document.getElementsByTagName('head').item(0);
	    var js = document.createElement('script');
	    js.setAttribute('src', '../js/'+script_filename);
	    js.setAttribute('type', 'text/javascript');
	    js.setAttribute('id', 'id_'+script_filename);
	    html_doc.appendChild(js);
	    semaf = 1;
	    return false;
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}		

function validaFormCartoes(name){
	var caminho = "http://www.sodexobeneficios.com.br/main/portalvr/site/posto_beneficios/saldo_extrato/consultar_extrato.cfm?area=paravoce&convenio="+document.getElementById(name).frmConnsultaSelect.value;
	document.getElementById(name).action = caminho;
	newWindow(caminho, "posto_beneficio", "700", "535", "scrollbars=no, statusbar=no");
	return true;
}

function checkEmail(id){
	var str=document.getElementById(id).value;

	var filter=/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
	
	if (filter.test(str))
		return true
	else{
		//alert("Por favor, preencha o email corretamente!")
		return false;
	}
	return true;
}

function validateFormCdvr(frm){
	if(document.getElementById(frm).upload.value=="") { 
		alert('Selecione o arquivo a ser enviado \nclicando no botão "Arquivo"!'); 
		return false; 
	}
	if(document.getElementById(frm).email.value=="" || !checkEmail('email')) { 
		alert('Por favor, preencha o campo "Email"!'); 
		return false; 
	} 
	if(document.getElementById(frm).email_conf.value=="" ||
		document.getElementById(frm).email_conf.value!=document.getElementById(frm).email.value ||
		!checkEmail('email_conf')) { 
		alert('Por favor, preencha o campo "Confirmação de Email" corretamente!'); 
		return false; 
	}
	return true;
}

function newWindow(mypage,myname,w,h,features) {
	var win = null;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}

/*function redirect(){ 
	window.open('http://www.seriousgames.com.br/consumidorconsciente/planilha/');
	document.getElementById('redirectRespSoc').style.display='none';
}*/

function limparCadEmail() {
	document.forms['cadEmail'].reset();

	/*document.getElementById('cadEmail').nome.value='';
	document.getElementById('cadEmail').email.value='';
	document.getElementById('cadEmail').emailConfirm.value='';
	document.getElementById('cadEmail').mensagem.value='';*/
	return false;
}

function popup(){
	//pega a resolução do visitante
	w = screen.width;
	h = screen.height;
	
	//divide a resolução por 2, obtendo o centro do monitor
	meio_w = w/2;
	meio_h = h/2;
		
	//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
	altura2 = 100/2;
	largura2 = 250/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	window.open('../../comum/telefone_cdvr.htm','IMPORTANTE','height=100, width=250, top='+meio1+', left='+meio2+'', "location = no", "toolbar = no", "status=no", "scrollbars = no", "menubar=no", "directories = no")
}

