
/*
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//Usage: str.trim();
*/
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function CheckForm()
{
    var validForm = true;
    if (CheckTextField("ad") == false) { validForm = false; }
    if (CheckEmailField("email") == false) { validForm = false; }
    if (CheckTextField("mesaj") == false) { validForm = false; }
    
    if (validForm == true)
    {
        document.getElementById("formDiv").style.display = "none";
        document.getElementById("resultDiv").style.display = "block";
        ajaxPost("ajaxMail.asp", "contactForm", "resultDiv");
        //return false;
    }
    return false;    
}

function CheckTextField(eID)
{
    if (document.getElementById(eID).value == "") {
        document.getElementById("_" + eID).src = "images/redstar.png";
        return false;
    } else {
        document.getElementById("_" + eID).src = "images/nostar.png";
        return true;
    }
}

function CheckEmail(strEmail)
{
	if (strEmail.length < 5 || strEmail.length > 255) return false;
	if (strEmail.indexOf(" ") != -1) return false;
	if (strEmail.indexOf(".") <= 2) return false;
	var lastChar = strEmail.substr(strEmail.length - 1, 1);
	if (lastChar == "." || lastChar == "@") return false;
	if (strEmail.indexOf("@") < 1) return false;
	//also validate all characters
	return true;
}

function CheckEmailField(eID)
{
	if (CheckEmail(document.getElementById(eID).value) == false) {
        document.getElementById("_" + eID).src = "images/redstar.png";
        return false;
    } else {
        document.getElementById("_" + eID).src = "images/nostar.png";
        return true;
    }
}

