function searchValidate()
{
	if(document.all.Destination.value=="0")
	{
		alert("Please fill the destination form");
		return false;
	}
	else
	document.form1.submit();
}

function isFormValid() 
{
	if(document.all.username.value != '' && document.all.password.value != '') return true;
	else return false;
}

function submitFormLogin() 
{
	if (! isFormValid()) return;
	var iRes = ValidateLogin();
	if ( typeof(iRes)=='object' ) 
	{
		var lid = iRes.selectSingleNode("//AppUser").getAttribute("LanguageId");
		document.location.replace("../Main/Nav/Nav.htm?" + lid)
	}
	else
	{
		alert("משתמש לא קיים");
	}
}

function ValidateLogin()
{
	var loginAspPage = "../Main/Login/asp/login.aspx";
	var tmpXml = new ActiveXObject("Microsoft.XmlDom");
	tmpXml.async = false;
	
	tmpXml.loadXML("<Login/>");
	tmpXml.documentElement.setAttribute("u",document.all.username.value);
	tmpXml.documentElement.setAttribute("p",document.all.password.value);

	var x = SyncXMLHttpReq(loginAspPage,tmpXml);
	if (x && typeof(x) == 'object' ) 
	{	
		return x;
	}
	else
	{
		return false;
	}
	
}

function SyncXMLHttpReq(sURL, xmlSend)
{
	try
	{
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.Open("POST", sURL, false);
		xmlhttp.Send(xmlSend);	
		
		if(xmlhttp.responseXML.documentElement)
		{
			var xmlResult = xmlhttp.responseXML;
			
			if (checkErrors(xmlResult)) return false;
			else return xmlhttp.responseXML.documentElement;
		}
		xmlhttp = null;
		return true;
	}
	catch(e){
		throw e;
	}
}

//**************************************************************************************
function checkErrors(xmlResult)
{
	var xmlError = xmlResult.documentElement;
	if (xmlResult.documentElement.tagName != "Error") return false;
	return true;
}
