/**
 * Created by IntelliJ IDEA.
 * User: martindyrby
 * Date: Dec 16, 2010
 * Time: 5:55:22 PM
 * To change this template use File | Settings | File Templates.
 */

function signupValidate(inputName, operator, value, customErrorDiv) {
    if(customErrorDiv == null) {
        customErrorDiv = "errorDivSignup";
    }
    input = $(inputName);
    removeError(inputName + "_label", input, customErrorDiv);
    if(operator == "==") {
        if( input.value == value ) {
            showError(inputName + "_label", input, customErrorDiv);
            return false;
        }
    } else {
        if( input.value != value ) {
            showError(inputName + "_label", input, customErrorDiv);
            return false;
        }
    }

    return true;
}

function signupRegValidate(inputName, regularExpression, customErrorDiv) {
    if(customErrorDiv == null) {
        customErrorDiv = "errorDivSignup";
    }
    var input = $(inputName);
    removeError(inputName + "_label", input, customErrorDiv);
    var re = new RegExp(regularExpression);
    if(!re.test(input.value) ) {
        showError(inputName + "_label", input, customErrorDiv);
        return false;
    }
    return true;
}

function signupValidateRadio(inputName1, inputName2, labelName, customErrorDiv) {
    if(customErrorDiv == null) {
        customErrorDiv = "errorDivSignup";
    }
	var input1 = $(inputName1);
	var input2 = $(inputName2);
    removeError(labelName, input1, customErrorDiv);
	if(input1.checked == true || input2.checked == true) {
		return true;
	}

	showError(labelName, input1, customErrorDiv);
	return false;
}


function showError(labelName, inputObj, customErrorDiv) {
    if(customErrorDiv == null) {
        customErrorDiv = "errorDivSignup";
    }
    var errorDiv = $(customErrorDiv);
    errorDiv.innerHTML = "* De markerede felter er ikke udfyldt<br />korrekt!";
    errorDiv.style.display = "block";
    $(labelName).style.color = "red";
	if(inputObj.type == "text" || inputObj.type == "password") {
		inputObj.style.border = "thin solid red";
	}
}

function removeError(labelName, inputObj, customErrorDiv) {
    $(labelName).style.color = "black";
	if(inputObj.type == "text" || inputObj.type == "password") {
		inputObj.style.border = "";
	}
}

function removeErrorDiv(customErrorDiv) {
    if(customErrorDiv == null) {
        customErrorDiv = "errorDivSignup";
    }
    var errorDiv = $(customErrorDiv);
    errorDiv.innerHTML = "";
    errorDiv.style.display = "none";
}

