
function AderirServico(name, urlText, how){
    var path = window.location.pathname;
    var pathParts = path.split("/");
	var site = pathParts[1];
	var tipo = pathParts[2];
	if (tipo == "")
	    tipo = "Servicos";
	
	var idProblema = "";
	if (tipo.toLowerCase() == "esmspro")
	    idProblema = "5";
	if (tipo.toLowerCase() == "esms")
	    idProblema = "5";
	
    if (how == 'Middleware') {
        window.location.href = '/Particulares/Movel/GestaoConta/PagamentosCarregamentos/Extra/' + escape(urlText);
    }
    if (how == 'ServiceRequest') {
        divMain=document.getElementById("maincol");
        myForm=document.createElement("form");
        myForm.setAttribute("method", "post");
        myForm.setAttribute("action", "/" + site + "/ApoioAoCliente/ServiceRequest");
        inputIdProblema = document.createElement("input");
        inputIdProblema.setAttribute("type", "hidden");
        inputIdProblema.setAttribute("name", "idProblema");
        inputIdProblema.setAttribute("value", idProblema);
        inputServico = document.createElement("input");
        inputServico.setAttribute("type", "hidden");
        inputServico.setAttribute("name", "servico");
        inputServico.setAttribute("value", name);
        myForm.appendChild(inputIdProblema);
        myForm.appendChild(inputServico);
        divMain.appendChild(myForm);
        myForm.submit();
    }
}

var iframeId = 'OptimusExternalFrame';

function setFrameHeight() {
	setIframeHeight(iframeId);
}

function getDocHeight(doc) 
{
  try {
     var docHt = 0, sh, oh;
     if (doc.height) docHt = doc.height;
     else if (doc.body) {
        if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
        if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
        if (sh && oh) docHt = Math.max(sh, oh);
     }
  
     return docHt;
  } 
  catch(e) {
	return 1330;
  }
}

function setIframeHeight(iframeName) 
{
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto";
    var docHt = getDocHeight(iframeWin.document);
    if (docHt) {
		iframeEl.style.height = docHt + 30 + "px";
	}
  }
}
