  function pago(){

  $("<div id='demo'></div>").html('Boleto ainda não foi pago').dialog({
  modal: true,
  height:400,
  width:450,
  title:'Instalar Loja'
  });
  }

  function instalarLoja(){
  var aleatorio = Math.random();
  aleatorio = aleatorio+'';
  tis = aleatorio.substr(2);


  $("<div id='demo"+tis+"'></div>").load('templates/dados_instalar.html').dialog({
  modal: true,
  height:400,
  width:450,
  title:'Instalar Loja',
  buttons: {"Instalar": function(){
  concluirLoja2();
  }}
  });
 }

 /*function concluirLoja(){
 formdata = $('#instalar').serialize();

 $("#progressbar").progressbar({ value: 0 });

 $.ajax({
  type: "POST",
  async: true,
  cache:false,
  data:formdata,
  url: 'includes/res.php',
  //url: 'index.php?c=cliente&m=instalarLoja',
  beforeSend: function(){
  //$('#listar_noticias').html('<table align=\"center\"><tr><td><img src="images/carregando.gif"></td</tr></table>');
  },
  complete: function(){
  //$('#listar_notas').fadeIn("slow");
  },
  success: function(msg){
  //$('#teste').html(msg);
  var res = msg;
  res = res.split("-");
  alert(res[res.length-2]);
  //alert(msg);
  },
  error: function(){
  alert('Erro');
  }
  });

}*/


function mudaTemplate(tema){

$("#foto1").attr("src", "templates/images/"+tema+"_m.jpg");
$("#foto2").attr("src", "templates/images/"+tema+"1_m.jpg");
$("#foto3").attr("src", "templates/images/"+tema+"2_m.jpg");
$("#foto4").attr("src", "templates/images/"+tema+"3_m.jpg");
$("#foto5").attr("src", "templates/images/"+tema+"4_m.jpg");
$("#foto6").attr("src", "templates/images/"+tema+"5_m.jpg");

$(".afoto1").attr("href", "templates/images/"+tema+".jpg");
$(".afoto2").attr("href", "templates/images/"+tema+"1.jpg");
$(".afoto3").attr("href", "templates/images/"+tema+"2.jpg");
$(".afoto4").attr("href", "templates/images/"+tema+"3.jpg");
$(".afoto5").attr("href", "templates/images/"+tema+"4.jpg");
$(".afoto6").attr("href", "templates/images/"+tema+"5.jpg");

$("#templates").val(tema);


/*
$.ajax({
  type: "GET",
  async: true,
  cache:false,
  url: 'includes/fotos.php?tema='+tema,
  beforeSend: function(){
  //$('#listar_noticias').html('<table align=\"center\"><tr><td><img src="images/carregando.gif"></td</tr></table>');
  },
  complete: function(){
  
  },
  success: function(msg){
  
  $('#fotos').html(msg);
 
  //alert(msg);
  },
  error: function(){
  alert('Erro');
  }
  });
  */
}

function ajaxobj() {
try {
_ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
_ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
_ajaxobj = false;
}
}

if (!_ajaxobj && typeof XMLHttpRequest!="undefined") {
_ajaxobj = new XMLHttpRequest();
}

return _ajaxobj;
}


function concluirLoja2(){
  formdata = $('#instalar').serialize();
  tes = formdata.split("=");
  $("#teste").html('instalando loja....');
  $("#progressbar").progressbar({value: 10});
  ajax = ajaxobj();
  ajax.open("GET", "index.php?c=cliente&m=instalarLoja&nome="+tes[1], true);
  ajax.onreadystatechange=function() {
  $("#teste").html('copiando arquivos....');
  $("#progressbar").progressbar({value: 10});
  if(ajax.readyState == 2){
  $("#teste").html('configurando loja...');
  $("#progressbar").progressbar({value: 40});
  }else if (ajax.readyState == 3) {
  $("#teste").html('criando banco de dados...');
  $("#progressbar").progressbar({value: 70});
  }else if (ajax.readyState == 4) {
  $("#teste").html('Loja Instalada!');
  $("#progressbar").progressbar({value: 100});
  $("#link").html('<a href="http://127.0.0.1/Sites/CriarTecnlogia/temp/'+tes[1]+'" target="_blank">Link da loja</a>');
  }
  }

  // Enviamos algo para que o processo funcione
  ajax.send(null);
  //settimeout(concluirLoja, 500);
}


function contratar(plano){
  var aleatorio = Math.random();
  aleatorio = aleatorio+'';
  tis = aleatorio.substr(2);
  tema = $("#templates").val();
  if(tema == ""){
  alert("Escolha um tema!")
  exit();
  }

  $("<div id='demo"+tis+"'></div>").load('includes/contratar.php?tema='+tema+'&tis='+tis+'&plano='+plano).dialog({
  modal: false,
  height:720,
  width:1020,
  title:'Contratar'
  });
 }


 function abrePagamento(pagamento,tis){
 $("#metodoPagamento"+tis).val(pagamento);
 $("#pagamento"+tis).attr("src","includes/"+pagamento+".php");
 }


 function escolheDominio(value,tis){

 $.ajax({
  type: "GET",
  async: true,
  cache:false,
  url: 'includes/dominio.php?value='+value+'&tis='+tis,
  beforeSend: function(){
  $('#recebeDominio'+tis).html('<table align=\"center\"><tr><td><img src="images/carregando.gif"></td</tr></table>');
  },
  complete: function(){
  //$('#listar_notas').fadeIn("slow");
  },
  success: function(msg){
  $('#recebeDominio'+tis).html(msg);
  },
  error: function(){
  alert('Erro');
  }
  });
 }


 function salvarPagamentos(tis){
  formdata = $("#contratar"+tis).serialize();

  $.ajax({
  type: "POST",
  async: true,
  cache:false,
  data:formdata,
  url: 'includes/salvaPagamento.php',
  beforeSend: function(){
  //$('#listar_noticias').html('<table align=\"center\"><tr><td><img src="images/carregando.gif"></td</tr></table>');
  },
  complete: function(){
  //$('#listar_notas').fadeIn("slow");
  },
  success: function(msg){
  alert("Cadastro Efetuado com sucesso!!!")
  $("#demo"+tis).dialog('close');
  },
  error: function(){
  alert('Erro');
  }
  });

  }


jQuery.fn.toggleText = function(a,b) {
return   this.html(this.html().replace(new RegExp("("+a+"|"+b+")"),function(x){return(x==a)?b:a;}));
}

$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide();

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("h2.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});

});


function pagamento(pagamento,modo,plano,pagamento_id,user_id){
  var aleatorio = Math.random();
  aleatorio = aleatorio+'';
  tis = aleatorio.substr(2);
  
//alert(plano)
  $("<div id='demo"+tis+"'></div>").load('includes/'+pagamento+'.php?tis='+tis+'&modo='+modo+'&plano='+plano+'&pagamento_id='+pagamento_id+'&user_id='+user_id).dialog({
  modal: false,
  height:720,
  width:1020,
  title:'Pagamento'
  });
 }
