// JScript source code
document.onkeypress=checkKey

function checkKey()
{
	if (event.keyCode == 13)
	{
		if (document.activeElement.id == "username" || document.activeElement.id == "password")
			{return check_LoginFields()}
		else
			if (document.activeElement.id == "TxtSearch" )
				{return checkFldSearch()}
			else 
				if (document.activeElement.id == "typeId" 
					|| document.activeElement.id == "groupId"
					|| document.activeElement.id == "courseId"
					|| document.activeElement.id == "coursetypeId")
				{return checkFldcourseSearch()}
	}
	else 
		return true
}		

//Check text search form fields required
function checkFldSearch() 
{
	if (document.fTxtSearch.elements("TxtSearch").value == '')
	{
		alert("אין קריטריונים לחיפוש")
		return false
	}
	return true
}

//Check text search form fields required
function checkFldcourseSearch()
{
	if (document.fCourseSearch.elements("typeId").options.selectedIndex==0 && document.fCourseSearch.elements("coursetypeId").options.selectedIndex==0)
	{
		alert("אנא בחר/י מסלול לימודים")
		return false
	}
	//if (document.fCourseSearch.elements("groupId").options.selectedIndex==0 && document.fCourseSearch.elements("coursetypeId").options.selectedIndex==0)
	if (document.fCourseSearch.elements("groupId").options.selectedIndex==0)
	{
		alert("אנא בחר/י מחזור לימודים")
		return false
	}
	if (document.fCourseSearch.elements("courseId").options.selectedIndex!=0) //directly go to selected course
		document.fCourseSearch.action=strURL + "courses/course.asp?courseId="+document.fCourseSearch.elements("courseId").options[document.fCourseSearch.elements("courseId").options.selectedIndex].value
	return true
}

//Fill combobox after change previouse combo selection
function FillFormSelElement(ObjSelected,SelFilledName,SelFilledFirstStr,urlExe,AdditionalObjSelected)
{
	if(window.document.fCourseSearch.elements(SelFilledName).options)
	{
		window.document.fCourseSearch.elements(SelFilledName).options.length = 0;
		window.document.fCourseSearch.elements(SelFilledName).options[0] = new Option(SelFilledFirstStr,"");
		window.document.fCourseSearch.elements(SelFilledName).options.selectedIndex=0;
		
	}
	//if (ObjSelected.options.selectedIndex>0)
	//{
		postStrVal = ObjSelected.options[ObjSelected.options.selectedIndex].value;
		var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		var postURL=strURL+urlExe
   		xmlHTTP.open("POST", postURL, false);
   		if (AdditionalObjSelected)
   		{
			xmlHTTP.send('<?xml version="1.0" encoding="UTF-8"?><request><'+AdditionalObjSelected.name+'>'+ AdditionalObjSelected.options[AdditionalObjSelected.options.selectedIndex].value + '</'+AdditionalObjSelected.name+'><'+ObjSelected.name+'>' + postStrVal + '</'+ObjSelected.name+'></request>');	 
		}
		else
			xmlHTTP.send('<?xml version="1.0" encoding="UTF-8"?><request><'+ObjSelected.name+'>' + postStrVal + '</'+ObjSelected.name+'></request>');	 
		result = new String(xmlHTTP.ResponseText);
		//alert(result)
		arr_Options= result.split("#")			
 		for (i=0; i < arr_Options.length; i++)
		{
			arr_Values = arr_Options[i].split("~")									
			window.document.fCourseSearch.elements(SelFilledName).options[window.document.fCourseSearch.elements(SelFilledName).options.length] = new Option(arr_Values[1],arr_Values[0]); 
		}
	//}
}

//Clear combo box 
function clearFormSelElement(SelFilledName,SelFilledFirstStr)
{
	if(window.document.fCourseSearch.elements(SelFilledName).options)
	{
		window.document.fCourseSearch.elements(SelFilledName).options.length = 0;
		window.document.fCourseSearch.elements(SelFilledName).options[0] = new Option(SelFilledFirstStr,"");
		window.document.fCourseSearch.elements(SelFilledName).options.selectedIndex=0;
	}
}

/*Check LOGIN FORM*/
function check_LoginFields(){	
  if (document.frmLoginForm.password.value.trim() == '' && document.frmLoginForm.username.value.trim() == ''){
    //document.all("messErr").innerText='"חובה למלא שדות "סיסמא" ו"שם משתמש'
        alert('"חובה למלא שדות "סיסמא" ו"שם משתמש')
    document.frmLoginForm.username.focus();
     return false;
  }   
  if (document.frmLoginForm.username.value.trim() == '' ){
     //document.all("messErr").innerText='"חובה למלא שדה "שם משתמש'
     alert('"חובה למלא שדה "שם משתמש')
     document.frmLoginForm.username.focus();
     return false;
  }
  if (document.frmLoginForm.password.value.trim() != ''){
	   var l=document.frmLoginForm.password.value.trim();
	   var lg=l.length;   
	   if (lg<9){
	      //????????for (j=lg+1;j<10;j++){document.frmLoginForm.password.value='0' + document.frmLoginForm.password.value.trim()}
	   }
  }else { 
  //if (document.frmLoginForm.password.value.trim() == ''){
      //document.all("messErr").innerText='"חובה למלא שדה "סיסמא'
       alert('"חובה למלא שדה "סיסמא')
    document.frmLoginForm.username.focus();
      return false;
  }
  
  if (document.frmLoginForm.password.value.trim() != '' && document.frmLoginForm.username.value.trim() != ''){
	document.all("messErr").innerText=''
	document.frmLoginForm.submit()
     return false;
  }
 return false;
}

