var __hovers=[];
function __hover_mouseover(ev)
{
	var h=__hovers[this.id];if(!h)return;
	h.o.attributes["class"].value=h.new_class;
}
function __hover_mouseout(ev)
{
	var h=__hovers[this.id];if(!h)return;
	h.o.attributes["class"].value=h.old_class;
}
function attachHover(id,hoverClass)
{
	var o=document.getElementById(id);if(!o)return;
	if(__hovers[id])removeHover(id);
	__hovers[id]={
		id:id,
		o:o,
		old_class:o.attributes["class"].value,
		new_class:hoverClass,
		f_mouseover:__hover_mouseover,
		f_mouseout:__hover_mouseout
	};
	YAHOO.util.Event.addListener(o,"mouseover",__hover_mouseover);
	YAHOO.util.Event.addListener(o,"mouseout",__hover_mouseout);
}
function removeHover(id)
{
	var o;
	if(__hovers[id]&&(o=document.getElementById(id)))
	{
		YAHOO.util.Event.removeListener(o,"mouseover",__hovers[id].f_mouseover);
		YAHOO.util.Event.removeListener(o,"mouseout",__hovers[id].f_mouseout);
		__hovers[id]=null;
	}
}

function Trim(str) {
    str = str.replace(/^\s+/g, "");
    str = str.replace(/\s+$/g, "");
    return str;
}

function ValidateRequiredField(source, arguments) {
    arguments.Value = Trim(arguments.Value);
    arguments.IsValid = (arguments.Value != "");
    source.parentNode.parentNode.className = arguments.IsValid ? "" : "invalid";
}
function ValidateEmail(source, arguments) {
    var rgEmail = /^[0-9a-z_\-\.\+]+@([0-9a-z_\-]+\.)*[0-9a-z_\-]{2,}$/i;
    arguments.IsValid = (arguments.Value.match(rgEmail) != null);
    source.parentNode.parentNode.className = arguments.IsValid ? "" : "invalid";
}
function ValidatePhone(source, arguments) {
    if (Trim(arguments.Value) != "") {
        var rgPhone = /^\s*(\+38)?\(\d{3}\)\s*\d((\s|\-)*\d){6}\s*$/i;
        arguments.IsValid = (arguments.Value.match(rgPhone) != null);
    }
    else
        arguments.IsValid = true;
    source.parentNode.parentNode.className = arguments.IsValid ? "" : "invalid";
}
function ValidateYear(source, arguments) {
    if (Trim(arguments.Value) != "") {
        arguments.IsValid = (arguments.Value > 1900 && arguments.Value < 2010);
    }
    else
        arguments.IsValid = false;
    source.parentNode.parentNode.className = arguments.IsValid ? "" : "invalid";

}
function ValidateZip(source, arguments) {
    if (Trim(arguments.Value) != "") {
        arguments.IsValid = (arguments.Value.length == 5 && arguments.Value > 0 && arguments.Value <= 99999);
    }
    else
        arguments.IsValid = false;
    source.parentNode.parentNode.className = arguments.IsValid ? "" : "invalid";

}
function ValidatePassword(source, arguments) {
    var s = new String(arguments.Value);
    arguments.IsValid = (s.length == 0) || (s.length >= 3);
    source.parentNode.parentNode.className = arguments.IsValid ? "" : "invalid";
}

