var _global = new Array();
var credFields = new Array("req","lang","name","surname","email","loginname");

var b;
var fieldBorderColor = "#56adc6";
var fieldBorderWarningColor = "#FF0000";
var fieldLabelColor = "#43484a";
var fieldLabelWarningColor = "#FF0000";

/*************** CONTROLLER ***************/
function toggleInfo(str,show,success) {
	if ( !show )
		display.hideElement("infobox");
	else {
		if ( success ) {
			display.hideElement("loader");
			display.hideElement("warning");
			xGetElementById("imsg").innerHTML = str;
			display.showElement("info");
		}
		else {
			display.hideElement("loader");
			display.hideElement("info");
			xGetElementById("wmsg").innerHTML = str;
			display.showElement("warning");
		}
		display.showElement("infobox");
	}
}
function toggleLoader(show,str) {
	if ( !show ) {
		display.hideElement("loader");
		display.hideElement("infobox");
	}
	else {
		display.hideElement("info");
		display.hideElement("warning");
		if ( str != undefined ) xGetElementById("lmsg").innerHTML = "<strong>" + str + "</strong>";
		display.showElement("loader");
		display.showElement("infobox");
	}
}
/****************** FORM ******************/

function submitFRM() {
	if ( PRFValidated() ) {
		toggleLoader(true,"<strong>" + _global["validating_your_data"] + "...</strong>");
		checkCredentials();
	}
}

function PRFValidated() {
	var isValid = true;
	//	Name
	if ( trim(xGetElementById("name").value) == '' ) isValid = elementValidator('name','',false,'form',fieldBorderWarningColor,fieldBorderColor);
	else b = elementValidator('name','',true,'form',fieldBorderWarningColor,fieldBorderColor);
	//	Surname
	if ( trim(xGetElementById("surname").value) == '' ) isValid = elementValidator('surname','',false,'form',fieldBorderWarningColor,fieldBorderColor);
	else b = elementValidator('surname','',true,'form',fieldBorderWarningColor,fieldBorderColor);
	//	Email
	if ( trim(xGetElementById("email").value) == '' || !testEmail(trim(xGetElementById("email").value)) ) isValid = elementValidator('email','',false,'form',fieldBorderWarningColor,fieldBorderColor);
	else b = elementValidator('email','',true,'form',fieldBorderWarningColor,fieldBorderColor);
	//	Login
	if ( trim(xGetElementById("loginname").value) == '' ) isValid = elementValidator('loginname','',false,'form',fieldBorderWarningColor,fieldBorderColor);
	else b = elementValidator('loginname','',true,'form',fieldBorderWarningColor,fieldBorderColor);
	//	Password
	if ( trim(xGetElementById("password1").value) == '' || trim(xGetElementById("password1").value) != trim(xGetElementById("password2").value) || !testPWD(xGetElementById("password1").value) ) { 
		isValid = elementValidator('password1','',false,'form',fieldBorderWarningColor,fieldBorderColor);
		isValid = elementValidator('password2','',false,'form',fieldBorderWarningColor,fieldBorderColor);
	}
	else {
		b = elementValidator('password1','',true,'form',fieldBorderWarningColor,fieldBorderColor);
		b = elementValidator('password2','',true,'form',fieldBorderWarningColor,fieldBorderColor);
	}
	return isValid;
}

function checkCredentials() {
	xGetElementById("req").value = "CHECK_EMAIL_LOGIN";
	var loader = new net.ContentLoader(CI_AJAX_PATH + "registration.cfm",onCheckCredentialsResult,onCheckCredentialsError,"POST",net.CreatePostString(null,credFields));
}
function onCheckCredentialsResult() {
	response = net.CleanResponse(this.req.responseText);
	if ( response.length > 0 && response.indexOf("ERROR") != 0 ) {
		xGetElementById("abox_div").innerHTML = response;
		display.showElement("abox_tr");
		try {
			eval ( xGetElementById("jsreturn").innerHTML );
			xGetElementById("jsreturn").innerHTML = "";
		}
		catch (e) { }
		toggleLoader(false,"");
	}
	else if ( response.indexOf("ERROR") == 0 )
		toggleInfo("There was a problem validating the Data. The pre-registration can not be completed. If the problem persists please contact the Webmaster.",true,false);
	else {
		toggleLoader(false,"");
		document.prFRM.submit();
	}
}
function onCheckCredentialsError() {
	response = net.CleanResponse(this.req.responseText);
	xGetElementById("error").innerHTML = response;
}
