
function writeImg(img)
{
document.getElementById("preview").src=img;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
	if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
	if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}



//var diaboHeight = 423*getWindowHeight()/screen.availHeight;
//var caixaHeight = (windowHeight-diaboHeight)/2;

function setMoldura()
{
var detect = document.getElementById("detectJava");
detect.style.visibility="hidden";
var caixa = document.getElementById("caixa");
var moldura = document.getElementById("moldura");
var topmenu = document.getElementById("topmenu");
var footer = document.getElementById("footer");
var diabo = document.getElementById("diabo");
var caixaFixa = document.getElementById("bkg");
var windowHeight = 0.93*getWindowHeight();
var windowWidth = getWindowWidth();

diabo.height = 423*windowHeight/screen.availHeight;

if (windowHeight<1000) {
   caixa.height = windowHeight;
   } else caixa.height = 1000;
   
caixa.style.marginTop = ((windowHeight-caixa.height)/2)+"px";
topmenu.height = 0.05*caixa.height;
footer.height = 0.05*caixa.height;
moldura.height = 0.9*caixa.height;
caixaFixa.style.left = ((windowWidth-diabo.width)/8)+"px";
caixaFixa.style.top = ((caixa.height-diabo.height)/2)+"px";

var splash = window.self.frames["corp"].document.getElementById("tabela"); //dá erro no chrome
splash.style.top = ((caixa.height-diabo.height)/2)-100 + "px";
//alert("moldura.height " + moldura.height + ", caixa.height" + caixa.height);
}

function setFilme()
{
var filme = document.getElementById("filme");
filme.width = 0.5*getWindowWidth(); 
filme.height =  0.56*filme.width;
}

function setSplash()
{
//var tabela = document.getElementById("tabela");
//tabela.style.top = parent.getElementById("bkg").style.top + "px"; 
//alert(tabela.style.top);
}


function setCenter(tema)
{
//var cont = document.getElementById(tema);
//cont.style.width = "98%"
//cont.style.position = "absolute";
//cont.style.top = caixaHeight-100 + "px"; 

//alert(windowHeight);
//startOver();

}

function mostra(){
if ($('#checkTarara').is(':checked')) {
   $('#tararaQty').removeAttr('disabled');
   $('#tararaQty').attr('value',1);
   } else {
   		$('#tararaQty').attr('disabled', true);
		$('#tararaQty').removeAttr('value');
		}

if ($('#checkParainfernalia').is(':checked')) {
   $('#parainfernaliaQty').removeAttr('disabled');
   $('#parainfernaliaQty').attr('value',1);
   } else {
   		$('#parainfernaliaQty').attr('disabled', true);
		$('#parainfernaliaQty').removeAttr('value');
		}
}



function validaEncomenda(){

n=document.forms["encomendacds"]["nome"].value;
tar=document.forms["encomendacds"]["Ntarara"].value;
par=document.forms["encomendacds"]["Nparainfernalia"].value;
morada1=document.forms["encomendacds"]["morada1"].value;
pagamento=document.forms["encomendacds"]["modoPag"].value;

if (pagamento==null || pagamento=="")
  {
  document.getElementById("modoPag").innerHTML="Por Favor, introduza um modo de pagamento";
  document.getElementById("erros").innerHTML="Há erros no formulário. <br> Corrija-os e submeta de novo.";
  return false;
  } else {
  	document.getElementById("Paga").innerHTML="";
	document.getElementById("erros").innerHTML="";
	}

if (n==null || n=="")
  {
  document.getElementById("nom").innerHTML="Por Favor, introduza o seu nome";
  document.getElementById("erros").innerHTML="Há erros no formulário. <br> Corrija-os e submeta de novo.";
  return false;
  } else {
  	document.getElementById("nom").innerHTML="";
	document.getElementById("erros").innerHTML="";
	}
if (morada1==null || morada1=="")
  {
   document.getElementById("morada").innerHTML="Por favor, introduza a sua morada";
   document.getElementById("erros").innerHTML="Há erros no formulário. <br> Corrija-os e submeta de novo.";
   return false;
   } else document.getElementById("morada").innerHTML="";
  var mail=document.forms["encomendacds"]["email"].value;
  var atpos=mail.indexOf("@");
  var dotpos=mail.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=mail.length)
    {
     document.getElementById("cor").innerHTML="Endereço de e-mail inválido";
	 document.getElementById("erros").innerHTML="Há erros no formulário. <br> Corrija-os e submeta de novo.";
     return false;
   } else{
   	  document.getElementById("cor").innerHTML="";
	  document.getElementById("erros").innerHTML="";
	}
   
if ((tar == 0 || tar == null || tar == "") && (par == 0 || par == null || par == ""))
   {
   document.getElementById("erros").innerHTML="Há erros no formulário. <br> Corrija-os e submeta de novo.";
   document.getElementById("cdQty").innerHTML="Por favor, encomende pelo menos um cd";
   return false;
   } else{
   	  document.getElementById("cdQty").innerHTML="";
	  document.getElementById("erros").innerHTML="";
	}

}

function goBack(){
  window.history.back();
}

function directToIndex(){
		  if (window.top==window.self) window.location = "http://www.diaboasete.com"; 
}
