var changedbool = 0;

function change_password(user_id, msg){
	if(confirm(msg))
		window.location.href='?reset_id=' + user_id;	
}

function setOptionsForSubDropDownList(ddl,sddl){
	//getOptionStr(tbl,val,currVal,capt,ord,cond)
	var xmlhttp=null;	
	xmlhttp=ajax();
	xmlhttp.open('GET', 'getCourseDropDownList.asp?learnFieldId=' + learnFieldId + '&r=' + Math.random()*1000000, false);
	
	xmlhttp.onreadystatechange = function(sddl) {
			
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			var o=document.createElement('option');
			o.value='0'
			o.text='fsdfsdafsda'
			if(sddl){
				sddl.add(o);		
			}	
		}
	}

	xmlhttp.send(null);
	
}


// Vadim, 05/05/2008 (don't work in firefox) placed in examExecution.asp



// Vadim, 06/05/2008
var currLessonFile;
function regLessonEnter(lessonFile,lessonId,currUserId){
	var xmlhttp=null;
	
	xmlhttp=ajax();
	currLessonFile=lessonFile;
	
	xmlhttp.open('GET', '../student/updateLessonCount.asp?lessonId=' + lessonId + "&userId=" + currUserId + '&r=' + Math.random()*1000000, false);
	xmlhttp.onreadystatechange = function() {			
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			if(xmlhttp.responseText=="launch"){
				window.open(currLessonFile,'_SELF');
			}
			else{
				alert('ERROR');			
			}
		}
	}
	xmlhttp.send(null);	
}

// Vadim, 16/06/2009
function fillSubThemesSelectOptions(selThemeId){
	var xmlhttp=null;
	
	xmlhttp=ajax();
	xmlhttp.open('GET', '../exam/getSubThemeListByThemeId.asp?themeId=' + selThemeId.options[selThemeId.selectedIndex].value + '&r=' + Math.random()*1000000, false);
	xmlhttp.onreadystatechange = function() {			
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			if(xmlhttp.responseText!="ERROR"){
				selSubThemeId=document.getElementById("subThemeId");
				arrOptionPairs=xmlhttp.responseText.split("---");
				selSubThemeId.options.length=0;
				for(var i=0; i<arrOptionPairs.length;i++){
					arrOnePair=arrOptionPairs[i].split(":::");
					selSubThemeId.options[selSubThemeId.options.length] = new Option(arrOnePair[1], arrOnePair[0]);
				}				
			}
			else{
				alert('ERROR');			
			}
		}
	}
	xmlhttp.send(null);	
}


function deleteItem(itemId, itemIdName, loc){
	if(delete_act()){
		if(window.location.href.match(/\?/)){
			window.location.href+='&del' + itemIdName + '=' + itemId;	
		}
		else {
			window.location.href+='?del' + itemIdName + '=' + itemId;
		}
	}
}



function deleteUser(Id,FId,LId,LIdd){
	if(delete_act())
		window.location.href='?DelId=' + Id + '&FId=' + FId + '&LId=' + LId + '&LIdd=' + LIdd;	
}


function $(id){
	var obj=document.getElementById(id);
	
	if(!obj)
		alert('Cant find object: ' + id);
		
	return obj;
}

function ajax(){
	var xmlhttp=null;
	try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(e){
	try{xmlhttp=new ActiveXobject("Msxml2.XMLHTTP");}
	catch(e){xmlhttp=new XMLHttpRequest();}}
	return xmlhttp;
}

function color_row(){
	
	var table=document.getElementsByTagName('table');
	var bg=null, obj=null;
	
	for(var i=0; i<table.length; i++){
		if(table[i].className.indexOf('list')!=-1){
			obj=table[i];
			break;
		}
	}

	if(obj){
		tr=obj.getElementsByTagName('tr');
		for(var i=1; i<tr.length; i++){
			bg=(i%2==0)?'#f3f3f3':'#dddddd';
			
			tr[i].setAttribute('color', bg);
			
			tr[i].bgColor=bg; 
			
			tr[i].onmouseover=function(){
				//this.bgColor='#F4F4F4';
			};
			
			tr[i].onmouseout=function(){
				//this.bgColor=this.getAttribute('color');
			};	
		}
	}
	

	
	//input = new Image(); 
	//input.src='../images/bg_input_sel.gif';
}

function initButtons(){
	var input=document.getElementsByTagName('input');
	
	for(var i=0; i<input.length; i++){
		if(input[i].className=='Btn'){
			
			input[i].onmouseover=function(){
				this.style.backgroundImage='url(../images/btn_bg_sel.gif)';	
			}
			
			input[i].onmouseout=function(){
				this.style.backgroundImage='url(../images/btn_bg.gif)';
			}
		}
	}
}

function load_div(id){
	var msg_enroll=document.getElementById(id);
	
	msg_enroll.style.left=((screen.width-100)/2) + 'px';
	msg_enroll.style.top=((screen.height-150)/2) + 'px';
	
	msg_enroll.style.display='';
}

function findPosX(obj){
	var curleft = 0;
	
	if(obj.offsetParent)
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
		
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
		
	return curtop;
}

function validatorPlus(plusFormId,courseOrgId,questionPoolId){
	var v = new validator(plusFormId, a_fields, o_config);
								v.a_messages=a_messages;
	return v.exec()		
}


function recreateExam(msg,examId){
	
	if(confirm(msg)){
		window.location.href='examDetails.asp?examId=' + examId + '&recreate=yes';
	}
	else {
		window.location.href='examDetails.asp?examId=' + examId + '&recreate=no';
	}
}

// Dima, 26/05/2008
function IsNumeric(sText){
	 var ValidChars = "0123456789";
	 var IsNumber=true;
	 var Char;
		 
	 for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		 {
		 return false;
		 }
		}
	 return IsNumber;	 
 }

// Vadim, 01/06/2008
function showExamDetails(obj){
	var div=document.getElementById('divExamDetails');
	
	div.style.left=findPosX(obj) + 'px';
	div.style.top=(findPosY(obj) + 16) + 'px';
	
	div.style.display='';
}

//Vadim, 02/06/2008	
function searchByUserCode(uc){
	var loc=window.location.href;
	arrLoc=loc.split("&");
	//alert(arrLoc[arrLoc.length-1].indexOf('searchUserCode='));
	if(arrLoc.length>1){
		
		if(arrLoc[arrLoc.length-1].indexOf('searchUserCode=')>=0){
			
			window.location=loc.substr(0,loc.length-arrLoc[arrLoc.length-1].length)+'searchUserCode=' +uc;
		}
		else  window.location=window.location.href+'&searchUserCode=' +uc;
	}
}

//Vadim, 04/06/2008
function printExamQuestions(){
	document.getElementById("tdMenu").style.display="none";
	document.getElementById("trBanner").style.display="none";
	document.getElementById("tblSubBunner").style.visibility="hidden";
	document.getElementById("tblTabs").style.display="none";
	document.getElementById("trButtonPanel").style.display="none";
	document.getElementById("trFooter").style.display="none";
	if(document.getElementById("trNavigationBar"))document.getElementById("trNavigationBar").style.display="none";
	
	document.getElementById('theScrollDiv').className='scrollDiv1';
	window.print();
	document.getElementById('theScrollDiv').className='scrollDiv';
	
	document.getElementById("tdMenu").style.display="";
	document.getElementById("trBanner").style.display="";
	document.getElementById("tblSubBunner").style.visibility="visible";
	document.getElementById("tblTabs").style.display="";
	document.getElementById("trButtonPanel").style.display="";
	document.getElementById("trFooter").style.display="";
	if(document.getElementById("trNavigationBar"))document.getElementById("trNavigationBar").style.display="";
}

//Vadim, 12/02/2009
function printExamQuestionsForAll(){
	document.getElementById("tdMenu").style.display="none";
	document.getElementById("trBanner").style.display="none";
	document.getElementById("tblSubBunner").style.visibility="hidden";
	document.getElementById("tblTabs").style.display="none";
	document.getElementById("tblButtonPanel").style.display="none";
	document.getElementById("trFooter").style.display="none";
	
	var divs=document.getElementsByTagName('DIV');
	for(var i=0;i<divs.length;i++){
		if (divs[i].className=='ScrollDiv')divs[i].className='ScrollDiv1';
	}
	
	window.print();
	
	for(var i=0;i<divs.length;i++){
		if (divs[i].className=='ScrollDiv1')divs[i].className='ScrollDiv';
	}
	
	document.getElementById("tdMenu").style.display="";
	document.getElementById("trBanner").style.display="";
	document.getElementById("tblSubBunner").style.visibility="visible";
	document.getElementById("tblTabs").style.display="";
	document.getElementById("tblButtonPanel").style.display="";
	document.getElementById("trFooter").style.display="";
}

//Vadim, 12/06/2008 (http://www.htmlcodetutorial.com/forms/index_famsupp_157.html)
function submitEnter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
		 {
		 myfield.form.submit();
		 return false;
		 }
	else
		 return true;
}

