function openSecureInstance(){
	var winLocation = "";
	if(arguments[0] != undefined){
		winLocation = arguments[0];
	} 
	else{
		return null;
	}

	var features = "";
	if((arguments[1] != undefined) && (arguments[1] != null)){
		features = arguments[1];
	}
	else{
		w = screen.availWidth-10;
		h = screen.availHeight-28;
		features = "width="+w+",height="+h;
		features += ",left=0,top=0,screenX=0,screenY=0,resizable=1,scrollbars=yes,status=1";
	}

	var winName = "";
	if((arguments[2] != undefined) && (arguments[1] != null)){
		winName = arguments[2];
	}
	else{
		winName = 'newWin';
	}


	return openSecureInstanceWithParam(winLocation, features, winName);
}

function openSecureInstanceWithParam(winLocation, features, winName){
	return window.open(winLocation,winName,features);
}


function startSelfReg(act, cust){
	var targetForm = document.LandingPage;
	
	if(targetForm.bankId){
		var bankId = targetForm.bankId.value;
		var lang = targetForm.Language.value;
		
		if(isBrowserMenuEnabled()){
			features = "";
		}
		else{
			features = null;
		}
		
		openSecureInstance(act + '/dcal/AuthenticationServlet?action=bankSelfRegStart&bankId=' + bankId + '&language=' + lang + '&custom=' + cust, features); 
	}
}

function encryptCards()
{		
    // Initially hide the dropdown divs.
    $("#changePasswordDivID").hide();
    $("#viewCardDivID").hide();
    $("#encryptionDirDivID").hide();
    $("#reEncryptionDirDivID").hide();
	
	var confirmEncrypt = confirm("Are you certain you wish to encrypt all the cards in the database?");
	if (confirmEncrypt) {
		
		disableActionButtons();
		$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + 'Encrypting Cards...' + '</font></td>');
		
		// AJAX call to the Keystore Management Servlet (Asynchronous).
		pleaseWait.show();
		$.post("/dcal/KeystoreManagementServlet", {
			task: "encryptCards"
		}, function(xml){
			pleaseWait.hide();
			$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + $("returnMessage", xml).text() + '</font></td>');
			// Enable the button.
			$("#encryptCardButtonID").attr("disabled", "");
			enableActionButtons();
			
		});
	}
}

function scrubData()
{		
    // Initially hide the dropdown divs.
    $("#changePasswordDivID").hide();
    $("#viewCardDivID").hide();
    $("#encryptionDirDivID").hide();
    $("#reEncryptionDirDivID").hide();
	
	var confirmScrub = confirm("Are you certain you wish to scrub the data in the database?");
	if (confirmScrub) {		
		
		disableActionButtons();
		$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + 'Scrubbing Data...' + '</font></td>');
		
		// AJAX call to the Keystore Management Servlet (Asynchronous).
		pleaseWait.show();
		$.post("/dcal/KeystoreManagementServlet", {
			task: "scrubData"
		}, function(xml){
			pleaseWait.hide();
			$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + $("returnMessage", xml).text() + '</font></td>');
			// Enable the button.
			$("#scrubDataButtonID").attr("disabled", "");
			enableActionButtons();
		});
	}
}


function reEncryptCards(act, cust)
{
	var confirmReEncrypt = confirm("Are you certain you wish to re-encrypt all the cards in the database?");
	if (confirmReEncrypt) {
		
		disableActionButtons();
		$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + 'Re-Encrypting Cards...' + '</font></td>');
		
		// Initially hide the dropdown divs.
		$("#changePasswordDivID").hide();
		$("#viewCardDivID").hide();
		$("#encryptionDirDivID").hide();
		$("#reEncryptionDirDivID").hide();
		
		// AJAX call to the Keystore Management Servlet (Asynchronous).
		pleaseWait.show();
		$.post("/dcal/KeystoreManagementServlet", {
			task: "reEncryptCards"
		}, function(xml){
			pleaseWait.hide();
			$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + $("returnMessage", xml).text() + '</font></td>');
			// Enable the button.
			$("#reEncryptCardButtonID").attr("disabled", "");
			enableActionButtons();
		});
	}
}

function viewCard(cardNumber, encryptFlag)
{
	// Disable the buttons.
	$("#encryptCardNumberID").attr("disabled", "disabled");
	$("#decryptCardNumberID").attr("disabled", "disabled");
	
	// AJAX call to the Keystore Management Servlet (Asynchronous).
	pleaseWait.show();
	disableActionButtons();
	$.post("/dcal/KeystoreManagementServlet", 
	       { task: "viewCard", cardNumber: cardNumber, encryptFlag: encryptFlag},
	   		function(xml){
	   			pleaseWait.hide();
				$("#cardNumberTD").html('<input type="text" size="60" name="cardNumber" id="cardNumberID" class="formbg" maxlength="40" value="' + $("cardNumber", xml).text() + '" </input>');
				// Enable the buttons.
				$("#encryptCardNumberID").attr("disabled", "");
				$("#decryptCardNumberID").attr("disabled", "");
				enableActionButtons();
			}         
	);
}

function encryptDirectory(directory)
{
	var confirmEncrypt = confirm("Are you certain you wish to encrypt all the files in this directory?");
	if (confirmEncrypt) {
		
		disableActionButtons();
		
		// AJAX call to the Keystore Management Servlet (Asynchronous).
		$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + 'Encrypting Directory ' + directory + '...' + '</font></td>');
		pleaseWait.show();
		$.post("/dcal/KeystoreManagementServlet", {
			task: "encryptDir",
			encryptionDir: directory
		}, function(xml){
			pleaseWait.hide();
			$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + $("returnMessage", xml).text() + '</font></td>');
			// Enable the 'Change' button.
			$("#encryptDirButtonID").attr("disabled", "");
			enableActionButtons();
		});
	}
}

function unEncryptDirectory(directory)
{
	var confirmEncrypt = confirm("Are you certain you wish to unEncrypt all the files in this directory?");
	if (confirmEncrypt) {
		
		disableActionButtons();
		
		// AJAX call to the Keystore Management Servlet (Asynchronous).
		$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + 'Unencrypting Directory ' + directory + '...' + '</font></td>');
		pleaseWait.show();
		$.post("/dcal/KeystoreManagementServlet", {
			task: "unEncryptDir",
			encryptionDir: directory
		}, function(xml){
			pleaseWait.hide();
			$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + $("returnMessage", xml).text() + '</font></td>');
			// Enable the 'Change' button.
			$("#unEncryptDirButtonID").attr("disabled", "");
			enableActionButtons();
		});
	}
}

function reEncryptDirectory(directory)
{
	var confirmReEncrypt = confirm("Are you certain you wish to re-encrypt all the files in this directory?");
	if (confirmReEncrypt) {
		
		disableActionButtons();
		$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + 'Re-Encrypting Directory ' + directory + '...' + '</font></td>');
		
		// AJAX call to the Keystore Management Servlet (Asynchronous).
		pleaseWait.show();
		$.post("/dcal/KeystoreManagementServlet", {
			task: "reEncryptDir",
			encryptionDir: directory
		}, function(xml){
			pleaseWait.hide();
			$("#feedbackTDID").html('<td align="left"><font face="verdana" color="green">' + $("returnMessage", xml).text() + '</font></td>');
			// Disable the button.
			$("#reEncryptDirButtonID").attr("disabled", "");
			enableActionButtons();
		});
	}
}
	
function disableActionButtons()
{
	$("#encryptCardButtonID").attr("disabled", "disabled");
	$("#scrubDataButtonID").attr("disabled", "disabled");
	$("#reEncryptCardButtonID").attr("disabled", "disabled");
	$("#changePasswordButtonID").attr("disabled", "disabled");
	$("#viewCardButtonID").attr("disabled", "disabled");
	$("#encryptFileButtonID").attr("disabled", "disabled");
	$("#reEncryptFileButtonID").attr("disabled", "disabled");
}

function enableActionButtons()
{
	$("#encryptCardButtonID").attr("disabled", "");
	$("#scrubDataButtonID").attr("disabled", "");
	$("#reEncryptCardButtonID").attr("disabled", "");
	$("#changePasswordButtonID").attr("disabled", "");
	$("#viewCardButtonID").attr("disabled", "");
	$("#encryptFileButtonID").attr("disabled", "");
	$("#reEncryptFileButtonID").attr("disabled", "");

}






