/*	commons javaclass method & initialization
	author: S2iWeb
*/

function loadThanks(){
	var divContent = dojo.widget.byId("divContent");
	divContent.setUrl("AjaxLoadThanksPages.action");
}
function loadUserHomePage(){
	var divContent = dojo.widget.byId("divContent");
	divContent.setUrl("AjaxLoadWelcome.action");
}
function initDialogConfirm(e,method,dialog){
	dialogConfirm = dojo.widget.byId(dialog);
	document.getElementById("method").value = method;
	//check if the cart is empty or not
	var cartSize = document.getElementById("cartSize").value;
	if(cartSize>0){		
		dialogConfirm.show();
	}else { // cart is empty
		yesFunction();
	}	
}
function resetValue(dialog){
	document.getElementById("countryList").value = document.getElementById("countrySelection").value;
	document.getElementById("currencyList").value = document.getElementById("currencySelection").value;
	hideDialogConfirm(dialog);
}
function hideDialogConfirm(dialog){
	dialogConfirm = dojo.widget.byId(dialog);
	dialogConfirm.hide();
}
function yesFunction()
{		
	var execFunction = document.getElementById("method").value;	
	eval(execFunction);
	//loadHomePage();
	
}

function loadHomePage(){
		dojo.widget.byId("divCurrency").addOnLoad(
		function(){
			if(document.getElementById("currencyList").value  == "" || document.getElementById("currencyList").value == 'undefined' ){
				document.location.href = "404.jsp";
			}else{				
				reLogin();					
			}
	});
	
	function reLogin(){
				showLoadingDialog();
				document.location.href = "/whitelabel";
	}
}
function countryChange() {
	countryId = document.getElementById("countryList").value;	
	setNewCountry(countryId);	
	loadCurrency(countryId);
}
function setNewCountry(countryId) {	
	document.getElementById("countrySelection").value = countryId;
}
function currencyChange() {	
	currencyId = document.getElementById("currencyList").value;
	hideDialogConfirm('confirmChangeProfile');
	showLoadingDialog();
	document.location.href = "index!currencyChange.action?currency=" + currencyId;	
}
function loadCurrency(countryId){
	currencyCode = document.getElementById("currencyList").value;
	hideDialogConfirm('confirmChangeProfile');
	showLoadingDialog();
	document.location.href = "index!loadCurrencyByCountry.action?country=" + countryId + "&currencyCode=" + currencyCode;
}
function setNewCurrency(currencyId) {	
	document.getElementById("currencySelection").value = currencyId;
}
createCookie = function (name, value, days) {
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
	} else {
		expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
};
readCookie = function (name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for (var i = 0; i < ca.length; i = i + 1) {
		var c = ca[i];
		while (c.charAt(0) == " ") {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) === 0) {
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
};
eraseCookie = function (name) {
	createCookie(name, "", -1);
};
function wipePassenger(divId) {
	divId.style.display = (divId.style.display == "none" ? "block" : "none");
	if (divId.style.display == "none") {
		document.getElementById("identify").src = "images/arrowIn.gif";
	} else {
		document.getElementById("identify").src = "images/arrowOut.gif";
	}
}
function alert(value) {
	alertForAllPage(value);
}

//dojo initialization
dojo.require("dojo.widget.ContentPane");
dojo.require("dojo.widget.Tooltip");
dojo.event.topic.subscribe("/confirmCancellationFees", function (data, type, request) {
	if (type == "before") {
		var cancellationFees = dojo.byId("fees").value;
		if (cancellationFees > 0) {
			if (confirm("<fmt:message key=\"confirm.delete.penaltyFee\"/>" + " '" + cancellationFees + "' " + "<fmt:message key=\"confirm.delete.penaltyFeeContinue\"/>")) {
				showLoadingDialog();
				return true;
			} else {
				hideLoadingDialog();
				request.cancel = true;
				return false;
			}
		}
	}
});
dojo.event.topic.subscribe("/confirmDeleteCurrent", function (data, type, request) {
	if (type == "before") {
		if (confirm("<fmt:message key=\"confirm.delete.current\"/>")) {
			showLoadingDialog();
			return true;
		} else {
			request.cancel = true;
			return false;
		}
	}
});
dojo.event.topic.subscribe("/confirmDeleteNew", function (data, type, request) {
	if (type == "before") {
		if (confirm("<fmt:message key=\"confirm.delete.new\"/>")) {
			showLoadingDialog();
			return true;
		} else {
			request.cancel = true;
			return false;
		}
	}
});
dojo.event.topic.subscribe("/confirmDelete", function (data, type, request) {
	if (type == "before") {
		if (confirm("<fmt:message key=\"confirm.delete.new\"/>")) {
			showLoadingDialog();
			return true;
		} else {
			request.cancel = true;
			return false;
		}
	}
});
dojo.event.topic.subscribe("/confirmClear", function (data, type, request) {
	if (type == "before") {
		if (confirm("<fmt:message key=\"confirm.clear\"/>")) {
			return true;
		} else {
			request.cancel = true;
			return false;
		}
	}
});

//method to set iframe url
var sessionId = 1;


