var sServerName = "http://www.oifotos.com";

function Album() {
	var album_id = "";
	if(frmAlbuns.album) {
		if(frmAlbuns.album.length) {
			for(var x=0; x<frmAlbuns.album.length; x++) {
				if (frmAlbuns.album[x].checked) {
					album_id = frmAlbuns.album[x].value;
					break;
				}
			}
		} else if (frmAlbuns.album.checked) {
			album_id = frmAlbuns.album.value;
		}
	}
	if (album_id!="") location.href="/album.asp?a="+album_id;
}
function AtualizaSelecao(ps,pf) {
	document.getElementById('revelarFotos').style.display = 'none'; 
	document.getElementById('loading').style.display = 'block';	
	document.getElementById('compartFotos').style.display = 'none'; 
	document.getElementById('loading2').style.display = 'block';	
	ifroifselec.location.href="/custom/selection.asp?f="+pf+"&op="+((ps)?"add":"remove");
}

function CheckAllAlbums(bln) {
	var count = 0;
	var frm = document.frmAlbumList;
	if (frm) {
		if (frm.a.length) {
			for (var x=0; x<frm.a.length; x++) {
				frm.a[x].checked = bln;
			}
		} else {
			frm.f.checked = bln;
		}
	}
}

function CheckAllPhotos(bln) {
	var count = 0;
	var frm = document.frmPhotoList;
	if (frm) {
		if (frm.f.length) {
			for (var x=0; x<frm.f.length; x++) {
				frm.f[x].checked = bln;
			}
		} else {
			frm.f.checked = bln;
		}
	}
}
function ClearAllPhotos() {
	var frm = document.frmPhotoList;
	frm.target = "ifroifselec";
	document.getElementById('revelarFotos').style.display = 'none'; 
	document.getElementById('loading').style.display = 'block';	
	document.getElementById('compartFotos').style.display = 'none'; 
	document.getElementById('loading2').style.display = 'block';	
	SendForm(frm, "/custom/selection.asp?op=remove");
	CheckAllPhotos(false);
}
function SelectAllPhotos() {
	CheckAllPhotos(true);
	var frm = document.frmPhotoList;
	frm.target = "ifroifselec";
	document.getElementById('revelarFotos').style.display = 'none'; 
	document.getElementById('loading').style.display = 'block';	
	document.getElementById('compartFotos').style.display = 'none'; 
	document.getElementById('loading2').style.display = 'block';	
	SendForm(frm, "/custom/selection.asp?op=add");
}


function ClearSelection() {
	try { CheckAllPhotos(false); } catch(e) { }
	try { CheckAllAlbums(false); } catch(e) { }
	ifroifselec.location.href="/custom/selection.asp?op=clearall";
}
function Edit()
{
}

function Paginacao(frm,pgcount,pg) {
	for(x=1;x<=pgcount;x++) {
		pos = frm.pg.options.length++;
		frm.pg.options[pos].value = x;
		frm.pg.options[pos].text = x+" de "+pgcount;
		if (x==''+pg) frm.pg.options[pos].selected = true;
	}
}

function ApplyEffects() {
	effects.style.display=(effects.style.display!='inline')?'inline':'none';
}
function SlideShow() {
	if (ValidateSelectGo("Nenhuma foto foi selecionada. Deseja visualizar todas as fotos do álbum?", "/custom/albumselect.asp?a="+arguments[0]+"&url_destino=/slideshow.asp", "slideshow", "width=600,height=600", "Você possui um bloqueador de pop-ups ativo em seu navegador.\nDesabilite esta opção para abrir o slideshow.")) {
		j = window.open("/slideshow.asp", "slideshow", "width=600,height=600");
		if (j==null) alert("Você possui um bloqueador de pop-ups ativo em seu navegador.\nDesabilite esta opção para abrir o slideshow.");
		else j.focus();
	}
}

function CopyPhotos() {
	if (ValidateSelectGo("Nenhuma foto foi selecionada. Deseja copiar todas as fotos do álbum?", "/custom/albumselect.asp?a="+arguments[0]+"&url_destino=/photocopy.asp", "_self", "")) {
		location.href = "/photocopy.asp";
	}
}
function MovePhotos() {
	if (ValidateSelectGo("Nenhuma foto foi selecionada. Deseja mover todas as fotos do álbum?", "/custom/albumselect.asp?a="+arguments[0]+"&url_destino=/photomove.asp", "_self", "")) {
		location.href = "/photomove.asp";
	}
}
function EditPhotos() {
	if (arguments.length>0) {
		location.href = "/photoedit.asp?f="+arguments[0]+"&url_destino=/photo.asp?f="+arguments[0];
	} else if (ValidateCountGo(document.frmPhotoList.f, "Nenhuma foto foi selecionada", "Selecione apenas uma foto")) {
		SendForm(document.frmPhotoList, "/photoedit.asp?url_destino=/custom/thumbnail.asp?f="+FindAny(document.frmPhotoList.f));
	}
}
function DeletePhotos() {
	if (arguments.length>0) {
		location.href = "/custom/photodelete.asp?f="+arguments[0];
		return;
	}
	
	var count = 0;
	if (ifroifselec) count = ifroifselec.selectedphotos;

	if (count==0) {
		alert("Nenhuma foto foi selecionada");
		return;
	} else if(confirm("Você tem "+count+" foto(s) selecionada(s). Tem certeza que deseja excluí-la(s)?")) {
		//SendForm(document.frmPhotoList, "/custom/photodelete.asp", "_self");
		location.href = "/custom/photodelete.asp";
	}
}
function SharePhotos() {
	if (ValidateSelectGo("Nenhuma foto foi selecionada. Deseja compartilhar todas as fotos do álbum?", "/custom/albumselect.asp?a="+arguments[0]+"&url_destino=/share.asp", "_self", "")) {
		location.href = "/share.asp"
	}
}

function ChangeAlbumCover() {
	if (arguments.length>0) {
		location.href = "/custom/albumcover.asp?f="+arguments[0];
	} else if (ValidateCountGo(document.frmPhotoList.f, "Nenhuma foto foi selecionada", "Selecione apenas uma foto")) {
		location.href = "/custom/albumcover.asp?f="+FindAny(document.frmPhotoList.f);
	}
}
function NewAlbum() {
	location.href = "/albumedit.asp";
}
function CopyAlbums() {
	var frm = document.frmAlbumList;
	var album_count = 0;
	if (frm.a) {
		if (frm.a.length) {
			for(x=0; x<frm.a.length; x++) {
				if (frm.a[x].checked) {
					album_count++;
					if (album_count>1) break;
				}
			}
		} else if (frm.a.checked) album_count = 1;
	}
	if (album_count==0) { alert("Selecione um álbum"); }
	else if (album_count>1) { alert("Selecione apenas um álbum") }
	else {
		SendForm(frm, "/albumcopy.asp");
	}
}

function EditAlbums() {
	if (ValidateCountGo(document.frmAlbumList.a, "Nenhum álbum foi selecionado", "Selecione apenas um álbum")) {
		SendForm(document.frmAlbumList, "/albumedit.asp");
	}
}
function DeleteAlbums() {
	if (!IsChecked(document.frmAlbumList.a)) {
		alert("Nenhum álbum foi selecionado.");
		return;
	}
	if(confirm("Tem certeza que deseja excluir o(s) álbun(s) selecionado(s)?")) {
		url_action = "/custom/albumdelete.asp"
		if (arguments.length>0) if (arguments[0]=="S") url_action += "?url_destino=/sharedalbumlist.asp"
		SendForm(document.frmAlbumList, url_action);
	}
}

function RotateForm(p1,a) {
	//alert("Esta ferramenta está temporariamente fora do ar.\nEm alguns minutos ela será reestabelecida.");
	if (document.frmPhotoList) {
		if (!IsChecked(document.frmPhotoList.f)) {
			alert("Nenhuma foto foi selecionada");
		} else {
			SendForm(document.frmPhotoList, "/custom/imgtrans.asp?op=rotate&p1="+p1+"&url_destino=/album.asp?a="+a, "_self");
		}
	}
}
function Rotate90CCWForm(a) { RotateForm(3,a); }
function Rotate180CWForm(a) { RotateForm(2,a); }
function Rotate90CWForm(a) { RotateForm(1,a); }

function Rotate(p1,f) {
	location.href = "/custom/imgtrans.asp?op=rotate&p1="+p1+"&f="+f;
	//alert("Esta ferramenta está temporariamente fora do ar.\nEm alguns minutos ela será reestabelecida.");
}
function Rotate90CCW(f) { Rotate(3,f); }
function Rotate180CW(f) { Rotate(2,f); }
function Rotate90CW(f) { Rotate(1,f); }
function Effect(op,f) {
	//alert("Esta ferramenta está temporariamente fora do ar.\nEm alguns minutos ela será reestabelecida.");
	location.href = "/custom/imgtrans.asp?op="+op+"&f="+f;
}
function Original(f) {
	//alert("Esta ferramenta está temporariamente fora do ar.\nEm alguns minutos ela será reestabelecida.");
	location.href = "/custom/original.asp?f="+f;
}

function FindAny(fld) {
	if (fld) {
		if (fld.length) {
			for(x=0;x<fld.length;x++) {
				if (fld[x].checked) return fld[x].value;
			}
			return fld[0].value;
		} else {
			return fld.value;
		} 
	}
}
function Thumbnails() {
	if (document.frmAlbumList) {
		var a = FindAny(document.frmAlbumList.a);
		if (""+a=="undefined") {
			window.open("/send/photo.asp", "_self");
		} else {
			var dir = ""
			if (arguments.length>0) {
				if (arguments[0]!="") dir = "/" + arguments[0];
			}
			window.open(dir+"/album.asp?a=" + a, "_self");
		}
	} else {
		if (arguments.length>1) {
			if (arguments[1]!="") {
				window.open("/custom/thumbnail.asp?f="+arguments[1], "_self");
			}
		}
	}
}
function Details() {
	if (document.frmPhotoList) {
		var f = FindAny(document.frmPhotoList.f)
		var dir = ""
		if (arguments.length>0) {
			if (arguments[0]!="") dir = "/" + arguments[0];
		}
		window.open(dir+"/photo.asp?f=" + f, "_self");
	} else {
		if (document.frmAlbumList) {
			var a = FindAny(document.frmAlbumList.a)
			if (""+a=="undefined") {
				window.open("/send/photo.asp", "_self");
			} else {
				window.open("/custom/details.asp?a=" + a, "_self");
			}
		}
	}
}

function SendForm(frm, url) {
	frm.action = url;
	if (arguments.length>2) frm.target = arguments[2];
	frm.submit();
	frm.action = "";
}
function SelectAlbum(a, bln) {
	document.getElementById('revelarFotos').style.display = 'none'; 
	document.getElementById('loading').style.display = 'block';	
	document.getElementById('compartFotos').style.display = 'none'; 
	document.getElementById('loading2').style.display = 'block';	
	ifroifselec.location.href="/custom/albumselect.asp?a="+a+"&op="+((bln)?"add":"remove");
}

function IsChecked(c) {
	if (c) {
		if (c.length) {
			for (x=0;x<c.length;x++) {
				if (c[x].checked) return true;
			}
		} else {
			if (c.checked) return true;
		}
	}
	return false;
}
function CountChecked(c) {
	var count=0;
	if (c) {
		if (c.length) {
			for (x=0;x<c.length;x++) {
				if (c[x].checked) count++;
			}
		} else {
			if (c.checked) count++;
		}
	}
	return count;
}

function Previous(frm) {
	if (frm.pg.selectedIndex>0) {
		frm.pg.selectedIndex--;
		frm.submit();
	}
}
function Next(frm) {
	if (frm.pg.selectedIndex<frm.pg.length-1) {
		frm.pg.selectedIndex++;
		frm.submit();
	}
}

function ValidaLogin(frm) {
	if (frm.cd_login.value=="") {
		alert("Email não foi informado")
		frm.cd_login.focus();
		return false;
	}
	if (frm.cd_senha.value=="") {
		alert("Senha não foi informada")
		frm.cd_senha.focus();
		return false;
	}
	return true;
}
function SavePhotos(a) {
	if (ValidateSelectGo("Nenhuma foto foi selecionada. Deseja salvar todas as fotos do álbum?", "/custom/albumselect.asp?a="+arguments[0]+"&url_destino=/photocopy.asp?op=save", "_self", "")) {
		location.href = "/photocopy.asp?op=save"
	}
}
function Order() {
	if (ValidateSelectGo("Nenhuma foto foi selecionada. Deseja revelar todas as fotos do álbum?", "/custom/albumselect.asp?a="+arguments[0]+"&url_destino=/order.asp", "_self", "")) {
		location.href = "/order.asp"
	}
}

function ValidateSelectGo(msg, url, target, params) {
	if (ifroifselec) {
		if (ifroifselec.selectedphotos<1) {
			if (document.frmPhotoList) {
				if(confirm(msg)) {
					j = window.open(url, target, params);
					if (j==null) alert(arguments[4]);
					else j.focus();
					return false;
				} else { return false; }
			} else if (document.frmAlbumList) {
				alert("Nenhuma foto foi selecionada. Selecione pelo menos um álbum.");
				return false;
			}
		}
	} 
	return true;
}

function ValidateCountGo(c, msg1, msg2) {
	var count = CountChecked(c);
	if (count==0) {
		alert(msg1);
		return false;
	} else {
		if (count>1) {
			alert(msg2);
			return false;
		}
	}
	return true;
}

function Help() {
}

function LoginOi() {
	var url_retorno = (arguments.length>0)?arguments[0]:sServerName+"/custom/loginoi.asp";
		
	//var j = window.open("http://ww2.oiloja.com.br/wb/POi/POi_popup_de_login_para_parceiros?logout=true&urlretorno="+url_retorno, "_blank", "height=250,width=250,top=40,left=50,statusbar=yes,scrollbars=no,resizeble=no,toolbar=no,menubar=no,location=no");
	var j = window.open("http://www.oiloja.com.br/portal/site/OiLoja/menuitem.b1964e6212cd212c275aa872835d02a0?logout=true&urlretorno="+url_retorno, "_blank", "height=250,width=250,top=40,left=50,statusbar=yes,scrollbars=no,resizeble=no,toolbar=no,menubar=no,location=no");
	if (j==null) {
		alert("Você possui um bloqueador de pop-ups ativo em seu navegador.\nDesabilite esta opção para abrir a tela de login.");
		return;
	}
	j.focus();
}

function ExcluiOi() {
	if(confirm("Deseja realmente desassociar o número Oi de sua conta?")) {
		location.href = "/custom/assocoi.asp?op=remove&ispostback=true";
	}
}
function SendMMS() {
	if (ValidateCountGo(document.frmPhotoList.f, "Nenhuma foto foi selecionada", "Selecione apenas uma foto")) {
		SendForm(document.frmPhotoList, "/sendmms.asp?f="+FindAny(document.frmPhotoList.f));
	}
}

function ChamaAjuda(conteudo){
window.open('/popajuda.asp?conteudo='+ conteudo +' ','ajuda',"width=384px height=480px scroll=no adress=no status=no resizable=no")
}


function PopupAjuda(c) {
	window.open("/popupajuda.asp?conteudo="+c, "_blank", "width=385,height=500");
}


/* validacao de numero Oi */
var ddds = new Array("21","22","24","27","28","31","32","33","34","35","37","38","71","73","74","75","77","79","81","82","83", "84","85","86","87","88","89","91","92","93","94","95","96","97","98","99");	
var prefixos = new Array("88", "87", "86");
function OiNumber(number) {		
	var hasDDD = false;
	var hasPrefix = false;	
	if(number == null || number.length < 4) {
		return false;
	}
		
	for(i=0; i<ddds.length; i++) {
		if(number.substring(0,2) == ddds[i]) {
			hasDDD = true;
			break;
		}
	}		
	for(i=0; i<prefixos.length; i++) {		
		if(number.substring(2,4)==prefixos[i]) {
			hasPrefix = true;
			break;
		}
	}
	return hasPrefix && hasDDD;
}

function PromoCopa2006() {
	var frm, photoId;
	var c=0;
	if (document.frmPhotoList) {
		frm = document.frmPhotoList
		if (frm.f) {
			if (frm.f.length) {
				for (var i=0; i<frm.f.length; i++) {
					if (frm.f[i].checked) {
						photoId = frm.f[i].value;
						c++;
					}
				}
			} else {
				if (frm.f.checked) {
					photoId = frm.f.value;
					c++;
				}
			}
			if (c==0) alert("Selecione uma foto");
			else if (c>1) alert("Selecione apenas uma foto");
			else location.href = "/promo/copa2006.asp?f="+photoId;
		}
	}
}

//abrir popup centralizado
function openWinCenter(url, nome, x, y, scrollbar, status)	{
	L = (screen.width - x) / 2;
	T = (screen.height - y) / 2;
	newWin = window.open(url,nome,"scrollbars="+scrollbar+",status="+status+",width=" + x + ",height=" + y +",top=" + T+ ",left=" + L + ",toolbar=no,location=no,resizable=no,menubar=no");
	newWin.focus();
}

//Efeito Slide
var fadeOpacity  = new Array();
var fadeTimer    = new Array();

function fade(o,d,fadeInterval) {
  // o - Object to fade in or out.
  // d - Display, true =  fade in, false = fade out
  var obj = document.getElementById(o);

  if((fadeTimer[o])||(d&&obj.style.display!='block')||(!d&&obj.style.display=='block')) {
    if(fadeTimer[o])
      clearInterval(fadeTimer[o]);
    else
      if(d) fadeOpacity[o] = 0;
      else  fadeOpacity[o] = 9;
  
    obj.style.opacity = "."+fadeOpacity[o].toString();
    obj.style.filter  = "alpha(opacity="+fadeOpacity[o].toString()+"0)";
    
    if(d) {
      obj.style.display = 'block';
      fadeTimer[o] = setInterval('fadeAnimation("'+o+'",1);',fadeInterval);
    } else
      fadeTimer[o] = setInterval('fadeAnimation("'+o+'",-1);',fadeInterval);
  }
}

function fadeAnimation(o,i) {
  // o - o - Object to fade in or out.
  // i - increment, 1 = Fade In

  var obj = document.getElementById(o);
  fadeOpacity[o] += i;
  obj.style.opacity = "."+fadeOpacity[o].toString();
  obj.style.filter  = "alpha(opacity="+fadeOpacity[o].toString()+"0)";

  if((fadeOpacity[o]=='9')|(fadeOpacity[o]=='0')) {
    if(fadeOpacity[o]=='0')
      obj.style.display = 'none';
    else {
		if (obj.id == "FaderInativo"){
		  obj.style.opacity = "0.6";
		  obj.style.filter  = "alpha(opacity=60)";
		}else{
		  obj.style.opacity = "1";
  		  obj.style.filter  = "alpha(opacity=100)";
		}
    }

    clearInterval(fadeTimer[o]);
    delete(fadeTimer[o]);
    delete(fadeTimer[o]);
    delete(fadeOpacity[o]);
  }  
}

// Troca de Imagem Slide

function TrocaSlide(caminho,divcentro) {
  // caminho - caminho da imagem a ser inserida
  // divcentro - id da div do centro do slide
  
  var centro = document.getElementById('centerPopFade'+divcentro);  
  centro.style.backgroundImage = "url('../images/slides/"+caminho+"')";
}

// Abrir Slide

function AbrirSlide(nome) {
  // nome - Nome da div que vai ser aberta
  
  fade('FaderInativo',true,10);
  fade('popFade'+nome,true,100);
}