dojo.require("dojo.window");

var domovanje = {};

var newContactMode = false;

domovanje.popup = {
	HOSTING_FORM: "prestepHosting",
	DOMAIN_FORM: "prestepDomain",
	VPS_FORM: "prestepVps",
	WEBSITE_FORM: "prestepWebsite",
	CONTACT_FORM: "prestepContact",
	WEBSERVICE_FORM: "prestepWebservice",
	SSL_FORM: "prestepSsl",
	HOSTINGDOMAIN_FORM: "prestepHostingDomain",
	TERMSANDCONDITIONS_FORM: "prestepTermsandconditions",
	WAITING_PRESTEP: "prestepWaiting",
	NOTICE_PRESTEP: "prestepNotice",
	ALERT_PRESTEP: "prestepAlert",
	NOHOSTING_PRESTEP: "prestepNoHosting",
	showModal: function(divNode) {
		dojo.style(divNode, "display", "block");
		if(dojo.isIE < 7) {
			dojo.style(divNode, "position", "absolute"); // IE6 hack
		}
		var b = dojo.position(divNode);
		var wb = dojo.window.getBox();
		dojo.style(divNode, "top", (wb.h/2 - b.h/2) + "px");
		dojo.style(divNode, "left", (wb.w/2 - b.w/2) + "px");
        
		dojo.style(dojo.byId("overlayDiv"), "display", "block");
		dojo.style(dojo.byId("overlayDiv"), "height", wb.h + "px");
		if(dojo.isIE < 7) {
			scroll(0,0); // go to the top of the page in IE6
		}
	},
	hideModal: function(divNode) {
		dojo.style(divNode, "display", "none");
		dojo.style(dojo.byId("overlayDiv"), "display", "none");
	},
	showPrestepRadio: function(prestepFunction, idService, packagePeriod) {
		// example call: showPrestepRadio('showHosting', 'HostingCreateMesto', 'periodMesto')
		var period = 12;
		if ( dojo.byId(packagePeriod+"1")  != null && dojo.byId(packagePeriod+"1").checked )  period = 1;
		if ( dojo.byId(packagePeriod+"3")  != null && dojo.byId(packagePeriod+"3").checked )  period = 3;
		if ( dojo.byId(packagePeriod+"6")  != null && dojo.byId(packagePeriod+"6").checked )  period = 6;
		if ( dojo.byId(packagePeriod+"24") != null && dojo.byId(packagePeriod+"24").checked ) period = 24;
		domovanje.popup[prestepFunction](idService, period);
	},
	showDomain: function(idServiceType, itemIdx, hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.DOMAIN_FORM));
			return;
		}

		dojo.query(".idServiceType").attr("value", idServiceType);
		dojo.query(".itemIdx").attr("value", itemIdx);
		this.showModal(dojo.byId(this.DOMAIN_FORM));
	},
	showHosting: function(idServiceType, period, itemIdx, hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.HOSTING_FORM));
			return;
		}
        
		dojo.query(".idServiceType").attr("value", idServiceType);
		dojo.query(".period").attr("value", period);
		dojo.query(".itemIdx").attr("value", itemIdx);

		// package name:
		dojo.byId("hosting-package-name").innerHTML = hostingPackageNames[idServiceType];

		// scripting language
		scriptingLanguageOptions = dojo.query("#HostingScriptingLanguage_amount option");		
		if (idServiceType=='HostingCreateHiska') {
			dojo.query("#HostingScriptingLanguage_selected")[0].removeAttribute("disabled");
			scriptingLanguageOptions[1].removeAttribute("disabled");
			scriptingLanguageOptions[2].removeAttribute("disabled");
			scriptingLanguageOptions[3].removeAttribute("disabled");
			dojo.query("#label-HostingScriptingLanguage_selected").removeClass("disabled");
		} else
		if (idServiceType=='HostingCreateHiskaPlus') {
			dojo.query("#HostingScriptingLanguage_selected")[0].removeAttribute("disabled");
			scriptingLanguageOptions[1].setAttribute("disabled", true);
			scriptingLanguageOptions[2].removeAttribute("disabled");
			scriptingLanguageOptions[3].removeAttribute("disabled");
			dojo.query("#label-HostingScriptingLanguage_selected").removeClass("disabled");
		} else
		if (idServiceType=='HostingCreateVila') {
			dojo.query("#HostingScriptingLanguage_selected")[0].removeAttribute("disabled");
			scriptingLanguageOptions[1].setAttribute("disabled", true);
			scriptingLanguageOptions[2].removeAttribute("disabled");
			scriptingLanguageOptions[3].setAttribute("disabled", true);
			dojo.query("#label-HostingScriptingLanguage_selected").removeClass("disabled");
		} else {
			dojo.query("#HostingScriptingLanguage_selected")[0].setAttribute("disabled", true);
			scriptingLanguageOptions[1].setAttribute("disabled", true);
			scriptingLanguageOptions[2].setAttribute("disabled", true);
			scriptingLanguageOptions[3].setAttribute("disabled", true);
			dojo.query("#label-HostingScriptingLanguage_selected").addClass("disabled");
		}

		// FTP accounts, Alias domains
		ftpOptions = dojo.query("#HostingFtp_amount option");
		aliasDomainsOptions = dojo.query("#HostingAttachedDomain5_amount option");
		subDomainsOptions = dojo.query("#HostingSubdomain5_amount option");
		emailAccountsOptions = dojo.query("#HostingEmail10_amount option");
		domainsOptions = dojo.query("#HostingDomain_amount option");
		mysqlOptions = dojo.query("#HostingDatabase_amount option");
		if (idServiceType=='HostingCreateMesto') {
			// FTP accounts
			dojo.query("#HostingFtp_selected")[0].setAttribute("disabled", true);
			ftpOptions[1].setAttribute("disabled", true);
			ftpOptions[2].setAttribute("disabled", true);
			ftpOptions[3].setAttribute("disabled", true);
			ftpOptions[4].setAttribute("disabled", true);
			ftpOptions[5].setAttribute("disabled", true);
			dojo.query("#label-HostingFtp_selected").addClass("disabled");
			// Alias domains
			dojo.query("#HostingAttachedDomain5_selected")[0].setAttribute("disabled", true);
			aliasDomainsOptions[1].setAttribute("disabled", true);
			aliasDomainsOptions[2].setAttribute("disabled", true);
			aliasDomainsOptions[3].setAttribute("disabled", true);
			aliasDomainsOptions[4].setAttribute("disabled", true);
			aliasDomainsOptions[5].setAttribute("disabled", true);
			dojo.query("#label-HostingAttachedDomain5_selected").addClass("disabled");
			// Sub domains
			dojo.query("#HostingSubdomain5_selected")[0].setAttribute("disabled", true);
			subDomainsOptions[1].setAttribute("disabled", true);
			subDomainsOptions[2].setAttribute("disabled", true);
			subDomainsOptions[3].setAttribute("disabled", true);
			subDomainsOptions[4].setAttribute("disabled", true);
			subDomainsOptions[5].setAttribute("disabled", true);
			dojo.query("#label-HostingSubdomain5_selected").addClass("disabled");
			// e-mail accounts
			dojo.query("#HostingEmail10_selected")[0].setAttribute("disabled", true);
			emailAccountsOptions[1].setAttribute("disabled", true);
			emailAccountsOptions[2].setAttribute("disabled", true);
			emailAccountsOptions[3].setAttribute("disabled", true);
			emailAccountsOptions[4].setAttribute("disabled", true);
			dojo.query("#label-HostingEmail10_selected").addClass("disabled");
			// Domains
			dojo.query("#HostingDomain_selected")[0].setAttribute("disabled", true);
			domainsOptions[1].setAttribute("disabled", true);
			domainsOptions[2].setAttribute("disabled", true);
			domainsOptions[3].setAttribute("disabled", true);
			domainsOptions[4].setAttribute("disabled", true);
			domainsOptions[5].setAttribute("disabled", true);
			dojo.query("#label-HostingDomain_selected").addClass("disabled");
			// Mysql databases
			mysqlOptions[1].setAttribute("disabled", true);
			mysqlOptions[2].setAttribute("disabled", true);
		} else {
			// FTP accounts
			dojo.query("#HostingFtp_selected")[0].removeAttribute("disabled");
			ftpOptions[1].removeAttribute("disabled");
			ftpOptions[2].removeAttribute("disabled");
			ftpOptions[3].removeAttribute("disabled");
			ftpOptions[4].removeAttribute("disabled");
			ftpOptions[5].removeAttribute("disabled");
			dojo.query("#label-HostingFtp_selected").removeClass("disabled");
			// Alias domains
			dojo.query("#HostingAttachedDomain5_selected")[0].removeAttribute("disabled");
			aliasDomainsOptions[1].removeAttribute("disabled");
			aliasDomainsOptions[2].removeAttribute("disabled");
			aliasDomainsOptions[3].removeAttribute("disabled");
			aliasDomainsOptions[4].removeAttribute("disabled");
			aliasDomainsOptions[5].removeAttribute("disabled");
			dojo.query("#label-HostingAttachedDomain5_selected").removeClass("disabled");
			// Sub domains
			dojo.query("#HostingSubdomain5_selected")[0].removeAttribute("disabled");
			subDomainsOptions[1].removeAttribute("disabled");
			subDomainsOptions[2].removeAttribute("disabled");
			subDomainsOptions[3].removeAttribute("disabled");
			subDomainsOptions[4].removeAttribute("disabled");
			subDomainsOptions[5].removeAttribute("disabled");
			dojo.query("#label-HostingSubdomain5_selected").removeClass("disabled");
			// e-mail accounts
			dojo.query("#HostingEmail10_selected")[0].removeAttribute("disabled");
			emailAccountsOptions[1].removeAttribute("disabled");
			emailAccountsOptions[2].removeAttribute("disabled");
			emailAccountsOptions[3].removeAttribute("disabled");
			emailAccountsOptions[4].removeAttribute("disabled");
			dojo.query("#label-HostingEmail10_selected").removeClass("disabled");
			// Domains
			dojo.query("#HostingDomain_selected")[0].removeAttribute("disabled");
			domainsOptions[1].removeAttribute("disabled");
			domainsOptions[2].removeAttribute("disabled");
			domainsOptions[3].removeAttribute("disabled");
			domainsOptions[4].removeAttribute("disabled");
			domainsOptions[5].removeAttribute("disabled");
			dojo.query("#label-HostingDomain_selected").removeClass("disabled");
			// Mysql databases
			mysqlOptions[1].removeAttribute("disabled");
			mysqlOptions[2].removeAttribute("disabled");
		}

		dojo.query(".hostingupgrade-select").attr("value", "");
		dojo.query(".hostingupgrade-checkbox").attr("checked", false);
		dojo.byId("hostingType-basic").click();
		dojo.byId("ctrlHostingConfirm").style.display = "none";
		dojo.byId("ctrlHostingAddToCart").style.display = "inline";
		
		if (itemIdx!=null) {
			if (itemsArray[itemIdx]["upgradesCount"]) {
				dojo.byId("hostingType-advanced").click();
			}

			for (var i in itemsArray[itemIdx]["upgrades"]) {
				if (dojo.byId(this.HOSTING_FORM+"Frm").elements[i+"_amount"]) {
					dojo.byId(this.HOSTING_FORM+"Frm").elements[i+"_amount"].value = itemsArray[itemIdx]["upgrades"][i];
				}
				if (dojo.byId(this.HOSTING_FORM+"Frm").elements[i+"_selected"]) {
					dojo.byId(i+"_selected").checked = true;
				}
				if (i.substring(0, 14)=='HostingTraffic') {
					dojo.byId("HostingTraffic_selected").checked = true;
					dojo.byId(this.HOSTING_FORM+"Frm").elements["HostingTraffic_amount"].value = i;
				}
				if (i.substring(0, 16)=='HostingDiskSpace') {
					dojo.byId("HostingDiskSpace_selected").checked = true;
					dojo.byId(this.HOSTING_FORM+"Frm").elements["HostingDiskSpace_amount"].value = i;
				}
				if (i.substring(0, 15)=='HostingDatabase') {
					dojo.byId("HostingDatabase_selected").checked = true;
					dojo.byId(this.HOSTING_FORM+"Frm").elements["HostingDatabase_amount"].value = 'HostingDatabase'+itemsArray[itemIdx]["upgrades"][i];
				} else
				if (i.substring(0, 12)=='HostingMSSQL') {
					dojo.byId("HostingDatabase_selected").checked = true;
					dojo.byId(this.HOSTING_FORM+"Frm").elements["HostingDatabase_amount"].value = i;
				}
				if (i=="HostingAsp" || i=="HostingPhp" || i=="HostingCgi") {
					dojo.byId("HostingScriptingLanguage_selected").checked = true;
					dojo.byId(this.HOSTING_FORM+"Frm").elements["HostingScriptingLanguage_amount"].value = i;
				}
				if (i=="SslCreateRapidSSL" || i=="SslCreateQuickSSLPremium" || i=="SslCreateRapidSSLWildcard") {
					dojo.byId("HostingSsl_selected").checked = true;
					dojo.byId(this.HOSTING_FORM+"Frm").elements["HostingSsl_amount"].value = i;
				}
			}

			if (itemsArray[itemIdx]["details"]["ftpType"]=="FPSE") {
				dojo.byId("HostingFpse_selected").checked = true;
			}

			dojo.byId("ctrlHostingConfirm").style.display = "inline";
			dojo.byId("ctrlHostingAddToCart").style.display = "none";
		}
		if (dojo.query("#"+this.HOSTING_FORM+" form").length != 0) {
			dojo.body().appendChild(dojo.byId(this.HOSTING_FORM));
		}

		this.showModal(dojo.byId(this.HOSTING_FORM));
	   
	},
	showVps: function(idServiceType, period, itemIdx, hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.VPS_FORM));
			return;
		}

		dojo.query(".idServiceType").attr("value", idServiceType);
		dojo.query(".period").attr("value", period);
		dojo.query(".itemIdx").attr("value", itemIdx);

		dojo.query(".vpsupgrade-select").attr("value", "");
		dojo.query(".vpsupgrade-checkbox").attr("checked", false);
		dojo.byId("vpsType-basic").click();
		dojo.byId("ctrlVpsConfirm").style.display = "none";
		dojo.byId("ctrlVpsAddToCart").style.display = "inline";

		if (itemIdx!=null) {
			if (itemsArray[itemIdx]["upgradesCount"]) {
				dojo.byId("vpsType-advanced").click();
			}

			for (var i in itemsArray[itemIdx]["upgrades"]) {
				if (dojo.byId(this.VPS_FORM+"Frm").elements[i+"_amount"]) {
					dojo.byId(this.VPS_FORM+"Frm").elements[i+"_amount"].value = itemsArray[itemIdx]["upgrades"][i];
				}
				if (dojo.byId(this.VPS_FORM+"Frm").elements[i+"_selected"]) {
					dojo.byId(i+"_selected").checked = true;
				}
				if (i=='VpsRam256' || i=='VpsRam1024') {
					dojo.byId("VpsRam_selected").checked = true;
					dojo.byId(this.VPS_FORM+"Frm").elements["VpsRam_amount"].value = i;
					if (itemsArray[itemIdx]["upgrades"][i] == 2) {
						if (i=='VpsRam256') dojo.byId(this.VPS_FORM+"Frm").elements["VpsRam_amount"].value = 'VpsRam512';
						if (i=='VpsRam1024') dojo.byId(this.VPS_FORM+"Frm").elements["VpsRam_amount"].value = 'VpsRam2048';
					}
				}
				if (i=='VpsTraffic10' || i=='VpsTraffic50' || i=='VpsTraffic200') {
					dojo.byId("VpsTraffic_selected").checked = true;
					dojo.byId(this.VPS_FORM+"Frm").elements["VpsTraffic_amount"].value = i;
				}
				if (i=='VpsDiskSpace10' || i=='VpsDiskSpace50') {
					dojo.byId("VpsDiskSpace_selected").checked = true;
					dojo.byId(this.VPS_FORM+"Frm").elements["VpsDiskSpace_amount"].value = i;
				}
				if (i=="SslCreateRapidSSL" || i=="SslCreateQuickSSLPremium" || i=="SslCreateRapidSSLWildcard") {
					dojo.byId("VpsSsl_selected").checked = true;
					dojo.byId(this.VPS_FORM+"Frm").elements["VpsSsl_amount"].value = i;
				}
				if (i=='VpsControlPanel' || i=='VpsControlPanelUnlimited' || i=='VpsControlPanelPowerPack') {
					dojo.byId("VpsControlPanel_selected").checked = true;
					dojo.byId(this.VPS_FORM+"Frm").elements["VpsControlPanel_amount"].value = i;
				}
			}

			if (itemsArray[itemIdx]["details"]["distribution"]=="windows") {
				dojo.byId("operatingSystem-windows").click();
			} else {
				dojo.byId("operatingSystem-linux").click();
			}

			if (itemsArray[itemIdx]["details"]["distribution"]) {
				dojo.byId(this.VPS_FORM+"Frm").elements["linuxDistribution"].value = itemsArray[itemIdx]["details"]["distribution"];
			}

			dojo.byId("ctrlVpsConfirm").style.display = "inline";
			dojo.byId("ctrlVpsAddToCart").style.display = "none";
		}
		if (dojo.query("#"+this.VPS_FORM+" form").length != 0) {
			dojo.body().appendChild(dojo.byId(this.VPS_FORM));
		}
		this.showModal(dojo.byId(this.VPS_FORM));
	},
	showWebsite: function(idServiceType, period, itemIdx, hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.WEBSITE_FORM));
			return;
		}
        
		dojo.query(".idServiceType").attr("value", idServiceType);
		dojo.query(".period").attr("value", period);
		dojo.query(".itemIdx").attr("value", itemIdx);

		dojo.query(".websiteupgrade-select").attr("value", "");
		dojo.query(".websiteupgrade-checkbox").attr("checked", false);
		dojo.byId("websiteType-basic").click();
		dojo.byId("ctrlWebsiteConfirm").style.display = "none";
		dojo.byId("ctrlWebsiteAddToCart").style.display = "inline";
		
		if (idServiceType=='WebsiteCreateSmall') {
			dojo.byId("prestepWebsiteTitle").innerHTML = smallTitle;
		} else
		if (idServiceType=='WebsiteCreateMedium') {
			dojo.byId("prestepWebsiteTitle").innerHTML = mediumTitle;
		} else
		if (idServiceType=='WebsiteCreateLarge') {
			dojo.byId("prestepWebsiteTitle").innerHTML = largeTitle;
		}
		
		if (itemIdx!=null) {
			if (itemsArray[itemIdx]["upgradesCount"]) {
				dojo.byId("websiteType-advanced").click();
			}

			for (var i in itemsArray[itemIdx]["upgrades"]) {
				if (dojo.byId(this.WEBSITE_FORM+"Frm").elements[i+"_amount"]) {
					dojo.byId(this.WEBSITE_FORM+"Frm").elements[i+"_amount"].value = itemsArray[itemIdx]["upgrades"][i];
				}
				if (dojo.byId(this.WEBSITE_FORM+"Frm").elements[i+"_selected"]) {
					dojo.byId(i+"_selected").checked = true;
				}

				if (i.substring(0, 16)=='WebsiteDiskSpace') {
					dojo.byId("WebsiteDiskSpace_selected").checked = true;
					dojo.byId(this.WEBSITE_FORM+"Frm").elements["WebsiteDiskSpace_amount"].value = itemsArray[itemIdx]["upgrades"][i];
				}
				if (i.substring(0, 14)=='WebsiteTraffic') {
					dojo.byId("WebsiteTraffic_selected").checked = true;
					dojo.byId(this.WEBSITE_FORM+"Frm").elements["WebsiteTraffic_amount"].value = i;
				}
			}

			dojo.byId("ctrlWebsiteConfirm").style.display = "inline";
			dojo.byId("ctrlWebsiteAddToCart").style.display = "none";
		}
		if (dojo.query("#"+this.WEBSITE_FORM+" form").length != 0) {
			dojo.body().appendChild(dojo.byId(this.WEBSITE_FORM));
		}

		this.showModal(dojo.byId(this.WEBSITE_FORM));
	},
	showContact: function(idPerson, mode, caller, hide) {
		if (hide) {
			dojo.byId(this.CONTACT_FORM+'Frm').elements["formShown"].value = 0;
			this.hideModal(dojo.byId(this.CONTACT_FORM));
			return;
		}

		dojo.byId(this.CONTACT_FORM+'Frm').elements["formShown"].value = caller;
		if (mode=='edit') {
			dojo.byId(this.CONTACT_FORM+'Frm').elements["idPerson"].value = idPerson;
			dojo.byId(this.CONTACT_FORM+'Frm').elements["taxNumber"].value = contactsArray[idPerson]['taxNumber'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["firstName"].value = contactsArray[idPerson]['firstName'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["name"].value = contactsArray[idPerson]['name'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["address"].value = contactsArray[idPerson]['address'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["postalCode"].value = contactsArray[idPerson]['postalCode'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["phone"].value = contactsArray[idPerson]['phone'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["email"].value = contactsArray[idPerson]['email'];
			dojo.byId(this.CONTACT_FORM+'Frm').elements["idCountry"].value = contactsArray[idPerson]['idCountry'];
			if (contactsArray[idPerson]['personType'] == 'PERSON') {
				dojo.byId(this.CONTACT_FORM+'Frm').elements["personType-PERSON"].checked = true;
			} else {
				dojo.byId(this.CONTACT_FORM+'Frm').elements["personType-ORGANIZATION"].checked = true;
			}
		} else
		if (mode=='new') {
			dojo.byId(this.CONTACT_FORM+'Frm').elements["idPerson"].value = '0';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["taxNumber"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["firstName"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["name"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["address"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["postalCode"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["phone"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["email"].value = '';
			dojo.byId(this.CONTACT_FORM+'Frm').elements["idCountry"].value = 'SI';
			//dojo.byId(this.CONTACT_FORM+'Frm').elements["personType-PERSON"].checked = true;
			newContactMode = true;
		}

		if (mode=='edit' || mode=='editnotice') {
			editModeReadOnly(true);
		} else {
			editModeReadOnly(false);
		}
		
		if (mode=='new' || mode=='newnotice') {
			dojo.style("contactTitle", "display", "none");
			dojo.style("registrationTitle", "display", "inline");
			dojo.style("personType-div", "display", "block");
		} else {
			dojo.style("contactTitle", "display", "inline");
			dojo.style("registrationTitle", "display", "none");
			dojo.style("personType-div", "display", "none");
		}

		dojo.byId("personType-PERSON").checked
			? dojo.byId("personType-PERSON").click()
			: dojo.byId("personType-ORGANIZATION").click();

		registerFrmUpdatePostalName();

		this.showModal(dojo.byId(this.CONTACT_FORM));
	},
	showWebservice: function(idServiceType, hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.WEBSERVICE_FORM));
			return;
		}

		dojo.query(".idServiceType").attr("value", idServiceType);
		this.showModal(dojo.byId(this.WEBSERVICE_FORM));
	},
	showSsl: function(idServiceType, hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.SSL_FORM));
			return;
		}

		dojo.query(".idServiceType").attr("value", idServiceType);
		this.showModal(dojo.byId(this.SSL_FORM));
	},
	showHostingDomain: function(hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.HOSTINGDOMAIN_FORM));
			return;
		}

		this.showModal(dojo.byId(this.HOSTINGDOMAIN_FORM));
	},
	showTermsandconditions: function(hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.TERMSANDCONDITIONS_FORM));
			return;
		}

		this.showModal(dojo.byId(this.TERMSANDCONDITIONS_FORM));
	},
	showPrestepWaiting: function(hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.WAITING_PRESTEP));
			return;
		}
		
		this.showModal(dojo.byId(this.WAITING_PRESTEP));
		
		// IE hack:
		var animGif = document.getElementById('animGifImage');
		setTimeout(function() { animGif.src = animGif.src + "?rnd" + new Date().getTime() }, 300);
	},
	showPrestepNotice: function(hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.NOTICE_PRESTEP));
			return;
		}
		this.showModal(dojo.byId(this.NOTICE_PRESTEP));
	},
	showPrestepAlert: function(hide, otherId) {

		var alertNode = dojo.byId(this.ALERT_PRESTEP);
		if (otherId) alertNode = dojo.byId(otherId);
		if (hide) {
			this.hideModal(alertNode);
			return;
		}
		this.showModal(alertNode);
	},
	showPrestepNoHosting: function(hide) {
		if (hide) {
			this.hideModal(dojo.byId(this.NOHOSTING_PRESTEP));
			return;
		}
		this.showModal(dojo.byId(this.NOHOSTING_PRESTEP));
	}
};

// show tips in text fields:
dojo.addOnLoad(function(){
	dojo.query("[placeholder]").forEach(function(node, index, arr){
		if (node.value == "") {
			dojo.attr(node, "value", node.getAttribute("placeholder"));
			dojo.addClass(node, "placeholder");
		}
		dojo.connect(node,"onfocus",function(){
			if (node.getAttribute("placeholder") == node.value) {
				dojo.removeClass(node, "placeholder");
				dojo.attr(node, "value", "");
			}
		});
		dojo.connect(node,"onblur",function(){
			if (node.value == "") {
				dojo.addClass(node, "placeholder");
				dojo.attr(node, "value", node.getAttribute("placeholder"));
			}
		});
	});
});


// delete (any remaining) tips from text fields:
function removePlaceholders() {
	dojo.query("[placeholder]").forEach(function(node, index, arr){
		if (node.value == node.getAttribute("placeholder")) {
			dojo.attr(node, "value", "");
		}
	});
}

function registerFrmInit() {
	dojo.connect(dojo.byId("personType-PERSON"), "click", function(e){
		dojo.query('.taxNumber-label').style('display','none');
		dojo.style("taxNumber", "display", "none");
		dojo.style("ctrlAutoFill", "display", "none");
		dojo.style("firstName", "display", "block");
		dojo.query('.firstName-label').style('display','block');
		if (contactRegisterMode) {
			// here we do not need "contact person":
			dojo.style("contactPersonFirstName", "display", "none");
			dojo.query('.contactPersonFirstName-label').style('display', 'none');
			dojo.style("contactPersonLastName", "display", "none");
			dojo.query('.contactPersonLastName-label').style('display', 'none');
		}
		dojo.style("dottedLine", "display", "none");
		dojo.query('.name-label')[0].innerHTML = translateLastName;
	});
	dojo.connect(dojo.byId("personType-ORGANIZATION"), "click", function(e){
		dojo.query('.taxNumber-label').style('display', 'block');
		dojo.style("taxNumber", "display", "block");
		if (newContactMode || contactRegisterMode || contactCtrlAutoFill == 'force') {
			dojo.style("ctrlAutoFill", "display", "block");
		} else {
			dojo.style("ctrlAutoFill", "display", "none");
		}
		dojo.style("firstName", "display", "none");
		dojo.query('.firstName-label').style('display', 'none');
		if (contactRegisterMode) {
			// here we collect "contact person":
			dojo.style("contactPersonFirstName", "display", "block");
			dojo.query('.contactPersonFirstName-label').style('display', 'block');
			dojo.style("contactPersonLastName", "display", "block");
			dojo.query('.contactPersonLastName-label').style('display', 'block');
		}
		dojo.style("dottedLine", "display", "block");
		dojo.query('.name-label')[0].innerHTML = translateName;
	});

	dojo.connect(dojo.byId("postalCode"), "keyup", registerFrmUpdatePostalName);
	dojo.connect(dojo.byId("postalCode"), "change", registerFrmUpdatePostalName);
	dojo.connect(dojo.byId("idCountry"), "keyup", registerFrmUpdatePostalName);
	dojo.connect(dojo.byId("idCountry"), "change", registerFrmUpdatePostalName);

	dojo.byId("personType-PERSON").checked
		? dojo.byId("personType-PERSON").click()
		: dojo.byId("personType-ORGANIZATION").click();

	registerFrmUpdatePostalName();
}

function registerFrmUpdatePostalName() {
	if (dojo.byId("idCountry").value=='SI') {
		dojo.style("postalName", "color", "gray");
		dojo.byId("postalName").setAttribute("readonly", true);
	} else {
		dojo.style("postalName", "color", "inherit");
		dojo.byId("postalName").removeAttribute("readonly");
	}

	if (postalNamesArray[dojo.byId("idCountry").value] && postalNamesArray[dojo.byId("idCountry").value][dojo.byId("postalCode").value]) {
		dojo.byId("postalName").value = postalNamesArray[dojo.byId("idCountry").value][dojo.byId("postalCode").value];
	} else
	if (dojo.byId("idCountry").value=='SI') {
		dojo.byId("postalName").value = "";
	}
}

