﻿function InitZipSync() {
	if (RLdesign.Utils.DefineObject(sZipID) != null) {
		RLdesign.Utils.SyncronizedCityZip.Dynamic(sZipID, sCityID, ZipAjaxPath);
	}
}
RLdesign.Events.SetEventHandler(window, "load", InitZipSync);



function ShowStep(step) {
	for (var i = 0; i < Steps.length; i++) {
		var o = RLdesign.Utils.DefineObject(Steps[i]);
		if (o != null) {
			o.style.display = (i === (step-1)) ? "block" : "none";
		}
	}
	window.scrollTo(0,0);
}

function ValidateUserNameEmail(source, arguments) {
	var objEmail = RLdesign.Utils.DefineObject(sTxtVolunteerEmailID);

	var valid = false;

	if (objEmail.value != "") {
		valid = true;
	}
	else if (arguments.Value != "") {
		valid = true;
	}

	arguments.IsValid = valid;

	objEmail = null;
}

function ValidateUserNameLength(source, arguments) {
	arguments.IsValid = (arguments.Value.length >= 5 && arguments.Value.length <= 256);
}




ValidateRequired = function(o) {
	this.Init = function(o) {
		var rv = true;
		switch (o.tagName.toLowerCase()) {
			case "input":
				rv = ValidateInput(o);
				break;
			case "span":
				oList = o.getElementsByTagName("input");
				rv = ValidateRadioList(oList);
				break;
		}
		return rv;
	}
	this.ValidateInput = function(o) {
		var r = true;
		switch (o.type.toLowerCase()) {
			case "text":
			case "hidden":
				r = (o.value != "");
				break;
			case "checkbox":
			case "hidden":
				break;
		}
		return r;
	}
	this.ValidateRadioList = function(oList) {
		var r = true;
		for (var i = 0; i < oList.length; i++) {
			if (oList[i].checked) {
				r = true;
				break;
			}
			else {
				r = false;
			}
		}
		return r;
	}
	return this.Init(o);
}

function HandleStep1Ajax(sJSON, Nextstep) {
	var aJSON = (sJSON != null && typeof(sJSON) == "string") ? eval(sJSON) : sJSON;
	
	var Authorized = aJSON[0];
	
	if (Authorized) {
		SerializeChildren();
		ShowStep(Nextstep);
	}
	else {
		alert("Det indtastede kodeord er forkert.\r\nIndtast venligst kodeordet igen, eller tilmeld dig med en anden email-adresse.");
		RLdesign.Utils.DefineObject(sTxtVolunteerEmailID).focus();
	}
}

function ValidateStep2(nextstep, validate) {
//	if (arguments.length == 2 && arguments[1] == true) {
//		var o = (hidSerializedWatchesID) ? RLdesign.Utils.DefineObject(hidSerializedWatchesID) : null;
//		if (o == null) return true;
//		
//		var valid = (o.value != null && o.value != "");

//		if (valid) ShowStep(nextstep);
//		else alert("Du skal huske at vælge en vagt.");
//	}
//	else {
		ShowStep(nextstep);
//	}
	return false; // return false to disable asp.net postback
}

function ValidateStep3(nextstep) {
	// validation

	if (!nextstep) return true;
	ShowStep(nextstep);
	return false; // return false to disable asp.net postback
}

function ResetForm() {
	document.forms[0].reset();
	RLdesign.Utils.ClearChildElements(document.getElementById(sVolunteerChildrenListID));
	var watches = document.getElementById(divWatchesID).getElementsByTagName("a");
	for (var i = 0; i < watches.length; i++) {
		watches[i].className = "";
	}
	return false;
}

