/*
* Created on 11/07/2007
*
* Author: Acacio Fagundes
* Company: DBR Entretenimento
*/

function addOption(selectId, txt, val, selected) {
	var objOption = new Option(txt, val, selected);
	parent.document.getElementById(selectId).options.add(objOption);
}

function addSWF(URL, WIDTH, HEIGHT, TRANSPARENT) {
	document.write (' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
	document.write (' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ');
	document.write (' width="'+ WIDTH +'" height="'+ HEIGHT +'">');
	document.write (' <param name="movie" value="'+ URL +'" />');
	document.write (' <param name="menu" value="false" />');
	document.write (' <param name="quality" value="high" />');

	if ( TRANSPARENT ) {
  		document.write (' <param name="Wmode" value="Transparent" />'); 
	}
	document.write (' <embed src="'+ URL +'" quality="high" ');
	if ( TRANSPARENT ) {
		document.write (' Wmode = "transparent" ');
	}
	document.write (' pluginspage="http://www.macromedia.com/go/getflashplayer" ');
	document.write (' type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');
	document.write (' </object>');
}

function GET_Request(str_request){
	try {
		var head = document.getElementsByTagName('head')[0];
		var scriptElement = document.createElement('script');
		scriptElement.type = 'text/javascript';
		scriptElement.src = str_request;
		head.appendChild(scriptElement);
		return true;
	}
	catch(e){
		return false;
	}
}

function AtivaOnline(cod) {
	GET_Request('<?=HOST?>incs/PHPs/online.php?cod='+cod);
}


function Votar(id,nt) {
	try {
		GET_Request('votar.php?id='+id+'&nt='+nt); 
		alert('PARABENS!!!\n\n - Seu voto foi computado com sucesso.\n\n');
	}
	catch(e){}
}

function ValidLink(Link, Msg) {
  var is_confirmed = confirm(Msg + '\n\nClique OK para confirmar');
  if (is_confirmed) { Link.href += '&is_js_confirmed=1'; }
  return is_confirmed;
}

function limita(area_texto,max) {
  if(area_texto.value.length>=max){
  	area_texto.value=area_texto.value.substring(0,max);
  }
}

function keyNumber(e) {
  var keyChar = String.fromCharCode(e.which ? e.which : e.keyCode);
  filteredValues = "1234567890";
  if ((filteredValues.indexOf(keyChar) == -1) &&
     ((keyChar.charCodeAt(0) != 8)&&(keyChar.charCodeAt(0) != 46)&&(keyChar.charCodeAt(0) != 37)&&(keyChar.charCodeAt(0) != 38)&&(keyChar.charCodeAt(0) != 39)&&(keyChar.charCodeAt(0) != 40))
     ) return false;
}

function keyMoeda(e) {
  var keyChar = String.fromCharCode(e.which ? e.which : e.keyCode);
  filteredValues = "1234567890.";
  if ((filteredValues.indexOf(keyChar) == -1) &&
     ((keyChar.charCodeAt(0) != 8)&&(keyChar.charCodeAt(0) != 46)&&(keyChar.charCodeAt(0) != 37)&&(keyChar.charCodeAt(0) != 38)&&(keyChar.charCodeAt(0) != 39)&&(keyChar.charCodeAt(0) != 40))
     ) return false;
}

function abre(Arquivo, Local, WWidth,WHeight){
  largura1 = ((screen.width/2)-(WWidth/2));
  altura1 = ((screen.height/2)-(WHeight/2));

  window.open(Arquivo, Local,"alwaysRaised=yes,toolbar=0,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=" + WWidth + ",height=" + WHeight+",top="+altura1+",left="+largura1);
}

function abreScroll(Arquivo, Local, WWidth,WHeight){
  largura1 = ((screen.width/2)-(WWidth/2));
  altura1 = ((screen.height/2)-(WHeight/2));

  window.open(Arquivo, Local,"alwaysRaised=yes,toolbar=0,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=" + WWidth + ",height=" + WHeight+",top="+altura1+",left="+largura1);
}

function replay()  {
    open("http://www.amorproibido.com.br/", "New_Window"); 
}

// *** Pagamentos ***
function isCreditCard(st){
    if (st.length > 19) return false;
    sum = 0; mul = 1; l = st.length;
    for (i = 0; i < l; i++) {
      digit = st.substring(l-i-1,l-i);
      tproduct = parseInt(digit ,10)*mul;
      if (tproduct >= 10) sum += (tproduct % 10) + 1; else sum += tproduct;
      if (mul == 1) mul++; else mul--;
    }
    if ((sum % 10) == 0) return (true); else return (false);
  }
  function isVisa(cc){
  	if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4)) return isCreditCard(cc);
    return false;
  }
  function isMasterCard(cc){
  	firstdig = cc.substring(0,1);
  	seconddig = cc.substring(1,2);
  	if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))	return isCreditCard(cc);
  	return false;
  }
  function isAmericanExpress(cc){
    firstdig = cc.substring(0,1);
    seconddig = cc.substring(1,2);
    if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))	return isCreditCard(cc);
    return false;
  }
  function isDinersClub(cc){
    firstdig = cc.substring(0,1);
    seconddig = cc.substring(1,2);
    if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))	return isCreditCard(cc);
    return false;
  }
  function ValidaCartao(cc){
    if(isVisa(cc)){
      if (document.form_pagto.forma1.checked == false) return false;
      return;
    }
    if(isMasterCard(cc)){
      if (document.form_pagto.forma2.checked == false) return false;
      return;
    }
   /* if(isAmericanExpress(cc)){ 
    	if (document.form_pagto.forma1.value != "999") return false;
    	return;
    }*/
    if(isDinersClub(cc)){
    	if (document.form_pagto.forma1.checked == false) return false;
    	return;
    }
    return false;
  }

  /*
  function valida_form() {
    msg = "";
    DataAtual = new Date();
    if (document.form_pagto.cartao.value == "") msg += "\n - Voc� n�o escolheu o seu cart�o de cr�dito!";
    if (document.form_pagto.numero.value == "") msg += "\n - Preencha o n�mero do cart�o de cr�dito!";
    else {
      if (ValidaCartao(document.form_pagto.numero.value) == false) msg += "\n - O n�mero do cart�o de Cr�dito � inv�lido!";
    }
    if (document.form_pagto.titular.value == "") msg += "\n - Nome do titular n�o preenchido!";
    if (document.form_pagto.cod_seg.value == "") msg += "\n - C�digo de seguran�a n�o informado!";
    else {
       if (document.form_pagto.cod_seg.value.length != 3) msg += "\n - O c�digo de seguran�a deve conter 3 digitos!";
    }
    if (document.form_pagto.mes.value == "") msg += "\n - Mes de expira��o n�o preenchido!";
    if (document.form_pagto.ano.value == "") msg += "\n - Ano de expira��o n�o preenchido!";
    if (document.form_pagto.mes.value != "" && document.form_pagto.ano.value != "") {
    	if (document.form_pagto.ano.value == DataAtual.getFullYear() && document.form_pagto.mes.value < (DataAtual.getMonth()+1))
    	   msg += "\n - Este cart�o j� esta vencido!";
    }



    if (msg == "") {
    	document.form_pagto.submit();
    } else alert("Os seguintes erros foram encontrados:\n " + msg);
    
  }
  */
  
function TelaAssPagto(Obj) {
	//alert('Obj:'+Obj);	
	//alert('valor:'+Obj.value);
	if (Obj.value == 3) {
		self.document.getElementById('telaBoleto').className 	= 'TelaAssVisivel';
		self.document.getElementById('telaCartao').className 	= 'TelaAssInvisivel';
		self.document.getElementById('telaDeposito').className 	= 'TelaAssInvisivel';
	}
	else {
		if (Obj.value == 4) {
			self.document.getElementById('telaDeposito').className 	= 'TelaAssVisivel';
			self.document.getElementById('telaCartao').className 	= 'TelaAssInvisivel';
			self.document.getElementById('telaBoleto').className 	= 'TelaAssInvisivel';
		}
		else {
			self.document.getElementById('telaCartao').className 	= 'TelaAssVisivel';
			self.document.getElementById('telaDeposito').className 	= 'TelaAssInvisivel';
			self.document.getElementById('telaBoleto').className 	= 'TelaAssInvisivel';
		}
	}
}  

function ValFormPagto() {
	msg = "";
	DataAtual = new Date();

	if (document.form_pagto.plano.value == "") msg += "\n - Você não escolheu o seu plano de pagamento!";
    if (document.form_pagto.forma.value == "") msg += "\n - Você não escolheu a forma de pagamento!";
    else {
    	if (document.form_pagto.forma3.checked == false && document.form_pagto.forma4.checked == false) { // Escolhido cartao
			if (document.form_pagto.NuCart.value == "") msg += "\n - Preencha o número do cartão de crédito!";
			else {
				if (ValidaCartao(document.form_pagto.NuCart.value) == false) msg += "\n - O número do cartão de Crédito é inválido!";
			}
			if (document.form_pagto.TitCart.value == "") msg += "\n - Nome do titular não preenchido!";
			if (document.form_pagto.codSeg.value == "") msg += "\n - Código de segurança não informado!";
			else {
				if (document.form_pagto.codSeg.value.length != 3) msg += "\n - O código de segurança deve conter 3 digitos!";
			}
			if (document.form_pagto.mesVencto.value == "") msg += "\n - Mês de expiração não preenchido!";
			if (document.form_pagto.anoVencto.value == "") msg += "\n - Ano de expiração não preenchido!";
			if (document.form_pagto.mesVencto.value != "" && document.form_pagto.anoVencto.value != "") {
				if (document.form_pagto.anoVencto.value == DataAtual.getFullYear() && document.form_pagto.mesVencto.value < (DataAtual.getMonth()+1))
				msg += "\n - Este cartão já esta vencido!";
			}
    	}
    }
    
    if (msg == "") {
    	document.form_pagto.submit();
    } else alert("Os seguintes erros foram encontrados:\n " + msg);
}

//*******************

// PRE-LOADER IMAGENS
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//*********************************