$(function(){
	runResize();
});

var runResize = function(){
	h=$('#head');
	c=$('#content');
	f=$('footer');
	// if($('#loginMsg').hasClass('hide')==false){
		resizeWindow(h,c,f);
		$('body').mousemove(function(e){
			// console.log($('#loginMsg').hasClass('hide'));
			resizeWindow(h,c,f);
		});
		$('body').mouseup(function(e){
			resizeWindow(h,c,f);
		});
	// }
}

var resizeWindow = function(){
		windowHeight=window.innerHeight;
		topHeight=arguments[0].outerHeight();
		contentHeight=arguments[1].outerHeight();
		footerHeight=arguments[2].outerHeight();
		
		if(contentHeight<windowHeight-topHeight-footerHeight){
			arguments[2].css({'position':'absolute','bottom':0,'width':'100%'});
			$('.bgDiv').css({'height':$('footer')[0].offsetTop-topHeight});
		}else{
			arguments[2].css({'position':''});
		}
}		





// $(function(){
// 	windowHeight = window.innerHeight;
// 	topHeight = $('#head').outerHeight();
// 	contentHeight = $('#content').outerHeight();
// 	footerHeight = $('footer').outerHeight();

// 	if(contentHeight < windowHeight - topHeight - footerHeight){
// 			$('footer').css({'position': 'absolute','bottom': 0,'width':'100%'});
// 			// $('#content').css({'height': $('footer')[0].offsetTop - topHeight});
// 	}
// 	else{
// 		$('footer').css({'position': ''});
// 	}
// });




// $(window).resize(function(){
//    	windowHeight = window.innerHeight;
// 	topHeight = $('#head').outerHeight();
// 	contentHeight = $('#content').outerHeight();
// 	footerHeight = $('footer').outerHeight();

// 	if(contentHeight < windowHeight - topHeight - footerHeight){
// 			$('footer').css({'position': 'absolute','bottom':0,'width':'100%'});
// 			$('#content').css({'height': $('footer')[0].offsetTop - topHeight});
// 	}
// 	else{
// 		$('footer').css({'position': ''});
// 	}
// });






// $(function(){
// 	windowHeight=window.innerHeight;
// 	topHeight=$('#head').outerHeight();
// 	contentHeight=$('#content').outerHeight();
// 	footerHeight=$('footer').outerHeight();
// 	bodyHeight=topHeight+contentHeight+footerHeight;
// 	if(bodyHeight<windowHeight){
// 		$('#content').css('height',contentHeight+(windowHeight-bodyHeight));
// 	}
// });











$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
    $('select.selectpicker').selectpicker();
});



function showAppAdv(){
	var oSel = document.getElementById("projectType");
	var oValue = oSel.options[oSel.selectedIndex].value;
	if(oValue == 1){
		document.getElementById("andoridAdvID").classList.toggle("show");
		document.getElementById("iOSAdvID").classList.remove("show");
	}
	else if(oValue == 2){
		document.getElementById("iOSAdvID").classList.toggle("show");
		document.getElementById("andoridAdvID").classList.remove("show");
	}
	else{
		document.getElementById("andoridAdvID").classList.remove("show");
		document.getElementById("iOSAdvID").classList.remove("show");
	}
}




function showBankTypeAdv(){
	var oSel = document.getElementById("bankType");
	var oValue = oSel.options[oSel.selectedIndex].value;
	if(oValue == 1){
		document.getElementById("chinaTrustAdvID").classList.toggle("show");
		document.getElementById("taishinAdvID").classList.remove("show");
	}
	else if(oValue == 2){
		document.getElementById("taishinAdvID").classList.toggle("show");
		document.getElementById("chinaTrustAdvID").classList.remove("show");
	}
	else{
		document.getElementById("chinaTrustAdvID").classList.remove("show");
		document.getElementById("taishinAdvID").classList.remove("show");
	}
}

function showMaskSettingsAdv() {
	var oSel = document.getElementById("maskType");
	var oValue = oSel.options[oSel.selectedIndex].value;
	var maskSettingsAdvID = document.getElementById("maskSettingsAdvID");

	if (oValue == 0 && !maskSettingsAdvID.classList.contains("show")) {
		maskSettingsAdvID.classList.add("show");
	} else if (oValue != 0 && maskSettingsAdvID.classList.contains("show")) {
		maskSettingsAdvID.classList.remove("show");
	}
}






///////copy to clipboard/////

// function myFunction() {
//   var copyText = document.getElementById("myInput");
//   copyText.select();
//   document.execCommand("copy");
  
//   var tooltip = document.getElementById("myTooltip");
//   tooltip.innerHTML = "Copied: " + copyText.value;
// }

// function outFunc() {
//   var tooltip = document.getElementById("myTooltip");
//   tooltip.innerHTML = "Copy to clipboard";
// }




function deleteProject(r){
	if(confirm("是否確定要刪除專案?")){
 		var i=r.parentNode.parentNode.rowIndex;
  		document.getElementById('memberGoTbl_newProjec').deleteRow(i);
	}
	else{
		return false;
	}
}

function deleteApp(r){
	if(confirm("是否確定要刪除App?")){
 		var i=r.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex;
  		document.getElementById('memberGoTbl_app').deleteRow(i);
	}
	else{
		return false;
	}
}

function deleteAh(r){
	var elem = document.getElementById("ahID");
	
	if(confirm("是否確定要刪除SHA-1指紋憑證?")){
 		elem.parentNode.removeChild(elem);
	}
	else{
		return false;
	}
}

// var elem = document.getElementById("myDiv");
// elem.parentNode.removeChild(elem);



function closeAhCell(){
	document.getElementById("ahListID").classList.remove("in");
}



//////add a row for new ah//////
function newAhRow(){

	var divAhList = document.getElementById("ahListID");

	var divAh = document.createElement("div");
	divAh.className = "ah"
	divAh.id = "ahID"

	var divSha = document.createElement("div");
	divSha.className = "sha"

	var divSha_input = document.createElement("input");
	divSha_input.type = 'text';
	divSha_input.placeholder= '例如: AA:BB:CC:DD:EE:00:11:22:33:44:FF:GG:HH:II:JJ:55:66:77:88:99';

	var divRemark = document.createElement("div");
	divRemark.className = "remark"
		
	var divRemark_input = document.createElement("input");
	divRemark_input.type = 'text';

	var divDelAh = document.createElement("div");
	divDelAh.className = "delAh";

	var divDelAh_a = document.createElement("a");
	divDelAh_a.type = 'button';
	divDelAh_a.title = "刪除SHA-1指紋憑證";
	// divDelAh_a.data-toggle = "modal";
	divDelAh_a.onclick = "deleteAh(this)";
	divDelAh_a.addEventListener("click", deleteAh);



	var times_i = document.createElement("i");
	times_i.className = "fa fa-times fa-2x";





	divSha.appendChild(divSha_input);

	divRemark.appendChild(divRemark_input);

	divDelAh_a.appendChild(times_i);
	divDelAh.appendChild(divDelAh_a);


	divAh.appendChild(divSha);

	divAh.appendChild(divRemark);

	divAh.appendChild(divDelAh);

	divAhList.appendChild(divAh);

	}



//管理使用者頁面 - 刪除使用者確認/取消
function confirmDelete(){
  confirm("是否確定要刪除?");
}