/*
 * WebMa HotCall js
 */

// Attaching function to actionhandler
function addEvent(obj, evType, fn){
    if (obj.addEventListener){
	obj.addEventListener(evType, fn, false);
	return true;
    } else if (obj.attachEvent){
	return obj.attachEvent("on"+evType, fn);
    }
    return false;
}

// On which event which function to run
function loadEvents () {
    addEvent(document.getElementById('hotcall_submit'), 'click', hotcallSubmit);
}

// On document load, run load events
addEvent(window, 'load', loadEvents);


function isValidName (name) {
    if (name.toString().match(/^.{4,}$/i)) {
	return true;
    }
    return false;
}

function isValidEmail (email) {
    if (email.toString().match(/^[-\w@\._]+\.[\w]{2,6}$/i)) {
	return true;
    }
    return false;
}

function hotcallSubmit (e) {
    var error = false;
    document.getElementById('hotcall_name_block').className = "valid";
    document.getElementById('hotcall_phone_block').className = "valid";
    document.getElementById('hotcall_domain_block').className = "valid";
    if (!isValidName(document.getElementById('hotcall_name').value)) {
	document.getElementById('hotcall_name_block').className = "error";
	error = true;
    }
    if (!isValidName(document.getElementById('hotcall_phone').value)) {
	document.getElementById('hotcall_phone_block').className = "error";
	error = true;
    }
    if (!isValidName(document.getElementById('hotcall_domain').value)) {
	    document.getElementById('hotcall_domain_block').className = "error";
	    error = true;
    }
    if (error) {
	alert(lang_str['missing_data']);
	if (e && e.preventDefault)
	    e.preventDefault();
	return false;
    }
    document.getElementById('hotcall_form').submit();
}
