// start cookies
// The parameters of the function getCookie hold the name of the cookie, the value of the cookie, and the number of days until the cookie expires.
// In the function above we first convert the number of days to a valid date, then we add the number of days until the cookie should expire.
// After that we store the cookie name, cookie value and the expiration date in the document.cookie object.
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

//The function setCookie first checks if a cookie is stored at all in the document.cookie object. 
function initImage(imagem) {
	imageId = imagem;
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}


//If the document.cookie object holds some cookies, then check to see if our specific cookie is stored. 
//If our cookie is found, then return the value, if not - return an empty string.
function setCookie(c_name,value,expiredays){
	var exdate = new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie = c_name + "=" + escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ';path=/';
}


function DeleteCookie(name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = getCookie(name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
// end cookies


//mostra pub grande 728x300 na homepage:
function mostraPub(){
	dias = 2;	// duracao do cookie em dias
	//DeleteCookie('jaMostrouPub');
	jaMostrouPub = getCookie('jaMostrouPub');
	if (jaMostrouPub == "sim"){
		//alert(jaMostrouPub);
		//se já mostrou entao nao fazemos nada...
	}else{
		//alert('Vamos mostrar a Pub!' + jaMostrouPub);
		mostraDiv(pubNova);
		escondeDiv(banner);
		initImage('pubGrande') //faz o fade da imagem
		setCookie('jaMostrouPub','sim',dias);
    }
}
//esconde pub grande 728x300 na homepage:
function escondePub(){
	escondeDiv(pubNova);
	mostraDiv(banner);
}


// no right click on images: //
// Disable right click script III- By Renigade (renigade@mediaone.net)
// For full source code, visit http://www.dynamicdrive.com
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// no right click //



/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

//Sample usages
//coloquei no include footer.asp
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"





function MM_displayStatusMsg(msgStr) //v1.0
{
  status=msgStr;
  document.MM_returnValue = true;
}


function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}


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 YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('Dados incompletos ou com erros:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}



function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=args[i+1]; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' dever ser um endereço de email válido.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' deve ser um Número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' deve ser um Número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é de preenchimento obrigatório.\n'; }
  } if (errors) alert('Ocorreram os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  if (selObj.options[selObj.selectedIndex].value != ''){
  	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 	if (restore) selObj.selectedIndex=0;
  }
}

function displayWindow(theURL,winName,width,height,features) { //v3.1
// Made by Eddie Traversa modified from Macromedia Code
// http://nirvana.media3.net/
    var window_width = width;
    var window_height = height;
    var newfeatures= features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;
    newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + '');
    newWindow.focus();
}



function verificaApostador(){
	if (document.form1.idApostador.selectedIndex == 0){
		alert('Seleccione um Apostador!');
		return false;
	}else{
		document.form1.submit();
	}
}


function apagar(label,url){

	if(confirm(label))
	{
		self.location = url;
	}
}


function confirma(registo,url){

	if(confirm('Tem a certeza que deseja remover o registo "' + registo + '" ? '))
	{
		self.location = url;
	}
}




function mudaClasse(obj,srv){ 
	obj.className = srv; 
} 


function mostraDiv(camada){
	if (camada.style.display == 'none')
		{camada.style.display = ''}
}


function escondeDiv(camada){
	if (camada.style.display == '')
		{camada.style.display = 'none'}
}


function trocaDiv(camada){
	if (camada.style.display == 'none')
		{camada.style.display = ''}
	else
		{camada.style.display = 'none'}
}


function troca(camada)
{
	if (camada.style.visibility == "hidden")
		{camada.style.visibility = "visible"}
	else
		{camada.style.visibility = "hidden"}
}


function mostra(camada)
{
	if (camada.style.visibility == "hidden")
		{camada.style.visibility = "visible"}
	else
		{return false}
}


function esconde(camada)
{
	if (camada.style.visibility == "visible")
		{camada.style.visibility = "hidden"}
	else
		{return false}
}



function mudaTamanho(id,tam)
{
	id.style.fontSize = tam + "px";
}




function load(formName) {
  var list = document[formName].list;
  var str = list.options[list.selectedIndex].value;
  if (str != "") location.href = str;
}



function setImage(imagem)
{
	document.form.imagem.value = imagem;
}



function Maiusculas()
{
 	var cidade=document.form.CIDADE.value;
 	cid=cidade.toUpperCase();
 	document.form.CIDADE.value=cid;
}

function redimensiona(){

	var isNav, isIE, nVer = parseInt(navigator.appVersion.charAt(0));
	
	if (nVer >= 4) {
		isNav = (navigator.appName == "Netscape") ? 1 : 0;
		isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
	}

	// netscape 6.x
	if (isNav) {
		var w = document.img_recortes.width + 30;
		var h = document.img_recortes.height + 133;
		w = w - window.innerWidth;
		h = h - window.innerHeight;
		window.resizeBy(w, h);
		window.moveTo((screen.availWidth - window.outerWidth) / 2, (screen.availHeight - window.outerHeight) / 2);
   		return;
   }
	// i.e.
	if (isIE) {
		var w = document.img_recortes.width + 26;
		var h = document.img_recortes.height + 140;
		if (w > screen.availWidth) w = screen.availWidth;
		if (h > screen.availHeight) h = screen.availHeight;
		window.resizeTo(w, h);
		window.moveTo((screen.availWidth - w) / 2, (screen.availHeight - h) / 2);
   }
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
   window.onload = func;
 } else {
   window.onload = function() {
     if (oldonload) {
       oldonload();
     }
     func();
   }
 }
}