var qsFocus = false;

function SetDisplay(id,visibility)
{
    var f = document.getElementById(id);

    if (visibility==0) {
    	f.style.display = 'none';
    	f.style.visibility = 'hidden';
    }else{
		f.style.display = 'block';
		f.style.visibility = 'visible';
	}
    return false;
}

// quick search focus handler
function QsearchFocus()
{
	if (qsFocus) return;
	FocusTextBox(gid('user_fname'), true);
	FocusTextBox(gid('user_lname'), true);
	qsFocus = true;
}

function gid(id)
{
	return document.getElementById(id);
}
function FocusTextBox(o,isRtl)
{
	o.style.color = '#000';
	o.value = '';

	if (isRtl)
	{
		o.style.direction = "rtl";
		o.style.textAlign = 'right';

	}
	else
	{
		o.style.direction = "ltr";
		o.style.textAlign = 'left';

	}
}


function ValidateQSearchForm()
{
	if ((trim(gid('user_fname').value) == '' && trim(gid('user_lname').value) == '') || !qsFocus)
	{
		alert ('יש למלא שם פרטי או שם משפחה');
		gid('user_fname').focus();
		return false;
	}
	return true;
}

// Trims spaces from right and left of a given string
function trim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}

	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}

	return sString;
}

function SetCheckBoxes (id, is_checked)
{
	var el = document.getElementById(id);
	for (var i = 0; i < el.elements.length; i++)
	{
		el.elements[i].checked = is_checked;
	}
}

function SetDivPos(event, div_id)
{
    var el, x, y;

    el = document.getElementById(div_id);
    if (window.event)
    {
        x = window.event.clientX + document.documentElement.scrollLeft
                                 + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop +
                                 + document.body.scrollTop;
    }
    else
    {
      x = event.clientX + window.scrollX;
      y = event.clientY + window.scrollY;
    }

    x += 2; y += 2;
    el.style.left = x + "px";
    el.style.top  = y + "px";

}
// Client side form validation
function validate_reg_form()
{
	var f = document.formRegistration;

	// Check first name
	if (trim(f.user_fname.value) == '')
	{
		alert("נא מלא/י את שמך הפרטי");
		return false;
	}

	// Check last name
	if (trim(f.user_lname.value) == '')
	{
		alert("נא מלא/י את שם משפחתך");
		return false;
	}

	// Validate email:
	if (!isValidEmail(f.user_email.value))
	{
		alert('אנא הזן/י כתובת דוא"ל תקנית');
		return false;
	}

	// Make sure the two emails match
	if (f.user_email.value != f.user_email2.value)
	{
		alert('אנא וודא/י שנית את כתובת הדוא"ל.');
		return false;
	}

	// Check password
	if (f.user_password.value.length < 6)
	{
		alert('נא הכנס סיסמא של לפחות 6 תווים');
		return false;
	}

	// Make sure passwords match
	if (f.user_password.value != f.user_password2.value)
	{
		alert('אנא וודא/י שהסיסמאות תואמות.');
		return false;
	}

	return true;
}

function Select_Value_Set(selectId, Value)
	{
		SelectObject = document.getElementById(selectId);
		for(index = 0; index < SelectObject.length; index++)
		{
			if(SelectObject[index].value == Value)
				SelectObject.selectedIndex = index;
		}
	}