 jQuery.noConflict();

/**
 * Javascript para tratamento das telas de THESHOT.COM.BR
 *
 * @author André Coura
 * @since 1.0 - 02/01/2008
 * @since 2.0 - 06/08/2008
 * @since 3.0 - 05/01/2009
 */

var myLightbox;
function chamaPag(strParam){
	preloader('corpo');
	jQuery.getJSON('prototype.php?p='+escape(strParam)+'&paramT=ajax&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,pag){
			jQuery('#corpo').hide();
			jQuery('#corpo').html(pag);
			jQuery('#corpo').fadeIn("slow");
			var el;
			switch(strParam){
			  	case'home':
					el = $("Scroller-1");
					scroller = new Scrolling.Scroller(el, 400, 200);
					var so = new SWFObject("html/flash/portfolio_series.swf", "portfolio_series", "607", "493", "8", "#000000");
					so.write("portfolio");
					break;
				case 'yourshot':
					el = null;
					yourShot('0','4');
				break;
		}
		try{
			var navegador = navigator.userAgent;
			if(navegador.indexOf('MSIE')>0)
				IE7.CSS.init();IE7.HTML.init();IE7.HTML.apply();IE7.CSS.apply();IE7.recalc();
		}catch(e){ }//tratamento para o internet explorer
		return false;
		});
	});
}

function chamaIntGall(strParam,pag){
	preloader('corpo');
	jQuery.getJSON("prototype.php?p=gallery&subPag=subGallery&id="+strParam+"&pag="+parseInt(pag)+'&paramT=ajax&num='+randomNum(),
		function(data){
			jQuery.each(data, function(i,pag){
			jQuery('#corpo').hide();
			jQuery("#boddy_gallery").css("heigth","500px");
			jQuery('#corpo').html(pag);
			jQuery('#corpo').fadeIn("slow");
			myLightbox = new Lightbox();
			return false;
		});
	});
}

function chamaSearch(){
	return verificaKeyWords();
}

function getTagsSearch(){
	var strParam = jQuery("#localizar_fotos").val();
	return escape(strParam);
}

function verificaKeyWords(){
	var retorno = true;
	var strMens = String();
	if(jQuery("#localizar_fotos").val() == "Enter keyword"){
		strMens = "Please, write a keyword.";
		retorno = false;
	}else if(jQuery("#localizar_fotos").val().length < 3){
		jQuery("#localizar_fotos").val("Enter keyword");
		strMens = "The Keywords invalid! Please, try again.";
		retorno = false;
	}
	if(jQuery("#searchAthlete").select().val() != "null" || jQuery("#searchKind").select().val() != "null" || jQuery("#searchALocation").select().val() != "null")
		retorno = true;
	if(!retorno)
		writeMensageSearch(strMens);
	return retorno;
}

function writeMensageSearch(strMens){
	jQuery("#mensErroSearch").html(strMens);
	jQuery("#mensErroSearch").fadeIn("slow");
}

function limpaCampo(obj,valor){
	if(obj.value==valor)
		obj.value = "";
}

function resetForm(){
	if(confirm("Are you sure reset form?")){
		defaultFileds('nomeMail');
		defaultFileds('emailMail');
		defaultFileds('msgMail');
		$('erroFields').innerHTML ="";
		document.contact_theshot.reset()
	}
}

function validaFormContact(){
	var retorno = true;
	defaultFileds('nomeMail');
	defaultFileds('emailMail');
	defaultFileds('msgMail');
	if($('nomeMail').value == ""){
		retorno = false;
		erroField('nomeMail');
	}
	if($('emailMail').value == "" || $('emailMail').value.indexOf('@')==-1){
		retorno = false;
		erroField('emailMail');
	}
	if($('msgMail').value == ""){
		var retorno = false;
		erroField('msgMail');
	}
	if(!retorno){
		$('erroFields').innerHTML = 'Invalid data fields';
		return;
	}
	enviaEmail();
}

function defaultFileds(idCampo){
	$(idCampo).style.borderColor="#555";
	$(idCampo).style.backgroundColor="#000";
}

function erroField(idCampo){
	$(idCampo).style.borderColor="#990000";
	$(idCampo).style.backgroundColor="#444";
	return false;
}

function enviaEmail(){
	var strNome = '&nome='+encodeURI($('nomeMail').value);
	var strEmail = '&email='+encodeURI($('emailMail').value);
	var strMsg = '&msg='+encodeURI($('msgMail').value);
	var strUrl = 'prototype.php?p=sendMail'+strNome+strEmail+strMsg;
	new Ajax.Request(strUrl,{
    method:'get',
    onCreate: function(){ preloader2('dirContact'); },
    onSuccess: function(httpResp){
      try{
	      var arrResult = httpResp.responseText.evalJSON();
	      $('dirContact').innerHTML = arrResult['pag'];
      }catch(e){ alert('erro ' + e); }
    },
    onFailure: function(){ alert('Erro na requisicao ajax!') }
  });
}

function preloader(idHTML){
	var strHtml = '<div id="preloader">';
	strHtml += '<img src="html/images/loaderBarr.gif" />';
	strHtml += '<br /><br />Loading...';
	strHtml += '</div>';
	jQuery("#"+idHTML).html(strHtml);
}

function preloader2(idHTML){
	var strHtml = '<div id="msgConclusaoEmail">';
	strHtml += '<img src="html/images/loader2.gif" />';
	strHtml += '</div>';
	jQuery("#"+idHTML).html(strHtml);
}

function preloader3(idHTML){
	var strHtml = '<div id="loaderYS">';
	strHtml += '<img src="html/images/loader3.gif" />';
	strHtml += '</div>';
	jQuery("#"+idHTML).html(strHtml);
}

function preload(idHTML,strImg,strClass){
	var strHtml = '<div class="'+strClass+'">';
	strHtml += '<img src="html/images/'+strImg+'" />';
	strHtml += '</div>';
	jQuery("#"+idHTML).html(strHtml);
}

function reescreveFormMail(){
  jQuery.getJSON('prototype.php?p=Contact&paramT=reescreve&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,pag){
			jQuery('#dirContact').hide();
			jQuery('#dirContact').html(pag);
			jQuery('#dirContact').fadeIn("slow");
		    return false;
		});
	});
}


function yourShot(intPag,pagLimit){
	var pagAtual = parseInt(intPag)?parseInt(intPag):0;
	var ultPag = parseInt(pagLimit)?parseInt(pagLimit):1;
	var strUrl = 'prototype.php?p=yourshot&paramT=corpo&pag='+pagAtual+'&num='+randomNum();
	var idCorpoYourShot = 'yourShotBody';
	window.onload = null;
	new Ajax.Request(strUrl,{
    method:'get',
    onCreate: function(){preloader3(idCorpoYourShot);},
    onSuccess: function(transport){
      try{
	      var response = transport.responseText.evalJSON();
	      $(idCorpoYourShot).innerHTML = response['pag'];
	      /*
	      if((pagAtual+1)<ultPag){
	      	$('ProxPag').href="javascript:void(yourShot('"+(pagAtual+1)+"','"+ultPag+"'))";
	      }else{
	      	$('ProxPag').href="javascript:void(0)";
	      }
	      if((pagAtual-1)>=0){
	      	 $('PagAnt').href="javascript:void(yourShot('"+(pagAtual-1)+"','"+ultPag+"'))";
	      }else{
	      	$('PagAnt').href="javascript:void(0)";
	      }
	      $('pagAtualHtml').innerHTML = pagAtual+1;
	      */
      }catch(e){
      	alert('erro '+e);
      }
    },
    onFailure: function(){ alert('Erro na requisicao ajax!') }
  });
}


function consisteForm(objForm){
	var arrElem = new Array();
	var retorno = true;
	for(var i=0;i<objForm.length;i++){
		if(objForm[i].lang=="obrigatorio")
			arrElem.push(objForm[i]);
	}
	for(var j=0;j<arrElem.length;j++){
		defaultFileds(arrElem[j].id);
		if(arrElem[j].value=="" || !arrElem[j].value){
			erroField(arrElem[j].id);
			try{$('mensErro').innerHTML='Invalid data fields'}catch(e){};
			retorno = false;
		}
	}
	return retorno;
}
function cancelForm(){
	$('corpoRestrictArea').innerHTML ="";
}
function limpaForm(objForm){
	for(var i=0;i<objForm.length;i++){
		if(objForm[i].type!='button' && objForm[i].type!='submit' && objForm[i].type!='reset' && objForm[i].type!='hidden')
		objForm[i].value="";
	}
}

function datasForm(strIdForm){
	var dpck	= new DatePicker({
		relative	: strIdForm,
		language	: 'en',
		enableCloseEffect : false,
		enableShowEffect : false
	});
	dpck.setDateFormat([ "dd","mm", "yyyy" ], "/");
}

function randomNum(){
	return parseInt(Math.random()*9999999999);
}


function paginacao(strParam, destino, idDestPag, pagAtual,idSessao){
	if(strParam=="Subgallery" || strParam=="Yourshot" || strParam=="Search")
		preloaderPaginacao2(destino);
	else
		preloaderPaginacao(destino);
	jQuery.getJSON('prototype.php?p='+escape(strParam)+'&id='+idSessao+'&pagAtual='+pagAtual+'&paramT=paginacao&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,paginacao){
			jQuery('#'+idDestPag).hide();
			jQuery('#'+idDestPag).html(paginacao);
			jQuery('#'+idDestPag).fadeIn("slow");
		return false;
		});
	});
	jQuery.getJSON('prototype.php?p='+escape(strParam)+'&id='+idSessao+'&pagAtual='+pagAtual+'&paramT=ajax&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,pag){
			jQuery('#'+destino).hide();
			jQuery('#'+destino).html(pag);
			jQuery('#'+destino).fadeIn("slow");
		return false;
		});
	});
}

function setTamSubGaleryYs(){
	jQuery("#yourShot").height(460);
}

function preloaderPaginacao(idHTML){
	var strHtml = '<div id="preloaderPaginacao">';
	strHtml += '<img src="html/images/loader3.gif" />';
	strHtml += '<br /><br />Loading...';
	strHtml += '</div>';
	jQuery("#"+idHTML).html(strHtml);
}
function preloaderPaginacao2(idHTML){
	var strHtml = '<div id="preloaderPaginacao">';
	strHtml += '<img src="html/images/loader4.gif" />';
	strHtml += '<br /><br />Loading...';
	strHtml += '</div>';
	jQuery("#"+idHTML).html(strHtml);
}

function alteraFoto(enderecoImagem){
	//jQuery("#fotoNewsUps").hide();
	showImage(enderecoImagem);
	//jQuery("#fotoNewsUps").fadeIn("slow");
}

function alteraFoto(src){
	jQuery("#carregadorImgs img").fadeOut("slow").remove();
	var largeImage = new Image();
	jQuery(largeImage).load(function(){
		jQuery(this).hide();
	    jQuery("#carregadorImgs").append(this);//.removeClass("carregadorImgs");
	    jQuery(this).fadeIn("slow");
	});
	jQuery(largeImage).attr("src", src);
}


function alteraFoto2(src){
	jQuery("#fotoNewsUps").hide();
	jQuery("#fotoNewsUps img").fadeOut("normal").remove();
	var largeImage = new Image();
	jQuery(largeImage).attr("src", src);
	jQuery(largeImage).load(function(){
	    jQuery(this).hide();
	    jQuery("#fotoNewsUps").append(this);
		jQuery(this).fadeIn("slow");
	});
}
function ocultaErrosProaccess(){
	jQuery("#asteriscoErroPAPW").fadeOut();
	jQuery("#asteriscoErroPALO").fadeOut();
}


function validationFormProAccess(){
	ocultaErrosProaccess();
	var erro = false;
	if(jQuery("#loginProAcess").val()==""){
		erro = true;
		jQuery("#asteriscoErroPALO").fadeIn("slow");
	}
	if(jQuery("#paswordProAccess").val()==""){
		erro = true;
		jQuery("#asteriscoErroPAPW").fadeIn("slow");
	}
	if(erro)
		jQuery("#mensErroProAccess").html("Invalid data fields *").show("slow");
	return !erro;
}

function registraMascaraTelas(){
	jQuery('.mascaraNum').numeric("");
	jQuery('.mascaraNum').floatnumber("",0);
}

function chamaProdStore(pagAtual,strParamT,idProd){
	preloaderPaginacao('intesStore');
	jQuery.getJSON('prototype.php?p=Store&idProd='+idProd+'&pagAtual='+pagAtual+'&paramT='+strParamT+'&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,paginacao){
			if(idProd=="show")
				jQuery('#paginacaoStore').fadeIn("slow");
			else
				jQuery('#paginacaoStore').hide();
			jQuery('#intesStore').hide();
			jQuery('#intesStore').html(paginacao);
			jQuery('#intesStore').fadeIn("slow");
			registraMascaraTelas();
		return false;
		});
	});
}
//Subyourshot&id=14

function chamaProdYourShot(pagAtual,strParamT,idProd){
	preloaderPaginacao('intesStore');
	jQuery.getJSON('prototype.php?p=Subyourshot&idProd='+idProd+'&pagAtual='+pagAtual+'&paramT='+strParamT+'&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,paginacao){
			jQuery('#corpo').hide();
			jQuery('#corpo').html(paginacao);
			jQuery('#corpo').fadeIn("slow");
			registraMascaraTelas();
		return false;
		});
	});
}

function chamaSubYourShotMain(pagAtual,id){
	preloaderPaginacao('intesStore');
	jQuery.getJSON('prototype.php?p=Subyourshot&id='+id+'&pagAtual='+pagAtual+'&paramT=ajax&num='+randomNum(),
		function(data){
		  jQuery.each(data, function(i,paginacao){
			jQuery('#corpo').hide();
			jQuery('#corpo').html(paginacao);
			jQuery('#corpo').fadeIn("slow");
		return false;
		});
	});
}

function verificaValAtual(){
	var arrChkBox = new Array();
	arrChkBox = jQuery("input:checked");
	var dbValor = 0;
	var qtde = 0;
	var valorItem = 0;
	try{
		for(var i=0; i<arrChkBox.length;i++ ){
			valorItem = arrChkBox[i].value;
			qtde = jQuery("#txt_"+arrChkBox[i].id).val();
			dbValor+=valorItem*qtde;
		}
		if(dbValor == 0) dbValor = "0.00";
		jQuery("#valTotalCompras").html(dbValor);
		jQuery("#amountTotal").val(dbValor);
	}catch(e){
		alert("ERRO: " + e);
	}
}

function checkValoresPayPal(strPag){
	var strMensErro = "You must select at least one of the options to make the checkout.";
	try {
		if(Number(jQuery("#valTotalCompras").html()) != 0 && jQuery("#amountTotal").val() != "0.00"){
			switch (strPag) {
				case 'store':
					registraOpcaoSel('VendaStore');
					finalizaCompra('Store');
					break;
				case 'yourshot':
					registraOpcaoSel('VendaYourShot');
					finalizaCompra('Subyourshot');
					break;
			}
			return true;
		}else{
			alert(strMensErro);
			return false;
		}
	} catch (e) {}
}

function finalizaCompra(strClass){
	jQuery.getJSON('prototype.php?p='+strClass+'&paramT=finalizaCompra&num='+randomNum(), function(data){
		jQuery('#corpo').hide();
		jQuery('#corpo').html(data.pag);
		jQuery('#corpo').fadeIn("slow");
	});
}

function registraOpcaoSel(strClass){
	var arrChkBox = new Array();
	arrChkBox = jQuery("input:checked");
	var idItemSel = jQuery("#id_item_sel").val();
	var idCompra = jQuery("#itemNumber").val();
	for(var i=0; i<arrChkBox.length;i++ ){
		var strUrl = 'prototype.php?p='+strClass+'&paramT=registraCompra';
		strUrl+='&idItemComp='+jQuery("#id_"+arrChkBox[i].id).val();
		strUrl+='&qtdeComp='+jQuery("#txt_"+arrChkBox[i].id).val();
		strUrl+='&idItemSel='+idItemSel;
		strUrl+='&idCompra='+idCompra;
		strUrl+='&num='+randomNum();
		jQuery.getJSON(strUrl);
	}
}



/**
 * Override método do FW
 */
 /**
 * Definição da String de erros
 */
function setErroFieldPA(id,txt){
	jQuery('#campoErroPA').html(txt);
	setFieldErroCampoPA(id);
}

/**
 * destaca o campo com erro
 */
function setFieldErroCampoPA(id){
	jQuery('#'+id).css({background:"#222", border:"1px #770000 solid"});
}

/**
 * Define os campos defaults
 */
function setDefaultFieldsPA(){
	jQuery(':input:not(button)', this).each(function() {
		jQuery(this+":input:not(checkbox)").css({background:"#181818", border:"1px solid #186BA8"});
		jQuery('#campoErroPA').html("");
	});
}

function setThisCampoDefault(id){
	jQuery("#"+id+":not(checkbox)").css({background:"#181818", border:"1px solid #186BA8"});
}

var arrIdFieldsObrig = new Array();
var arrTxtFields = new Array();
var strTxtFields = new String();

function validaFormsPA(form){
	try{
		var erro = true;
		setDefaultFieldsPA();
		for(var i=0;i<this.arrIdFieldsObrig.length;i++){
			if(!verificaCampoSeVazio(this.arrIdFieldsObrig[i])){
				erro = false;
				setErroFieldPA(this.arrIdFieldsObrig[i],"Error! You need to fill up the * required fields.");
			}else{
				setThisCampoDefault(this.arrIdFieldsObrig[i]);
			}
		}
	}catch(e){ alert(e); }
	if(erro==true &&!verificaPasswords()){
		var strMens = "Error! Wrong fields for password.";
		setErroFieldPA('password_pa_usuario',strMens);
		setErroFieldPA('password_pa_usuario_confirm',strMens);
		erro = false;
	}
	return erro;
}

function verificaPasswords(){
	if(jQuery('#password_pa_usuario_confirm').val() == jQuery('#password_pa_usuario').val())
		return true;
	return false;
}









