var loader_str = "<img src=\"/img/ajax-loader.gif\" width=\"48\">";
/*		
		function Hide(Cell){
		var myCell = document.getElementById(Cell);
		myCell.style.display = "none"
		}
		function Show(Cell){
		var myCell = document.getElementById(Cell);
		myCell.style.display = "";
}
function ChangeCell(Cell)
{
var myCell = document.getElementById(Cell);
myCell.style.background="gainsboro"
}
function ChangeBack(Cell)
{
var myCell = document.getElementById(Cell);
myCell.style.background="none"
}



// AJAX STAFF
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}


var http = createRequestObject();

function changeSStory() // formNumber -y arajzhm chenq ogtagorcum
{
	http.open('get', '/ajax/changeSStory.php?cahkiller=' + Math.floor(Math.random( ) * 5 - 15 + 1) + 15 );
	http.onreadystatechange = changeSStoryReady;
	http.send(null);
	
	setTimeout( "changeSStory()", 20000 );
}

function changeSStoryReady()
{
	if(http.readyState == 4)
	{
		if( http.responseText != '' )
		{
			document.getElementById('sStoryContainer').innerHTML = http.responseText;
		}
	}
}

function siteMap() // formNumber -y arajzhm chenq ogtagorcum
{
	document.getElementById('siteMap').style.display = 'block';

}*/

function DisplayCat(id)
{
	
	var catids = document.getElementById('catids').value;	
	ids=catids.split("***");	
	var length = ids.length;
	
	
	
	for(i=0; i<length; i++)
	{
		if(ids[i]!='')
		{
			document.getElementById('id_'+ids[i]).style.display='none';
			document.getElementById('im_'+ids[i]).style.fontWeight     = "normal";			
			if(ids[i]!=id)
			{
				document.getElementById('open'+ids[i]).value=0;
			}
		}
	}
	
	var open = document.getElementById('open'+id).value;	
	if(open==0)
	{
		document.getElementById('open'+id).value=1;
		document.getElementById('im_'+id).style.fontWeight     = "bold";
		document.getElementById('id_'+id).style.display = 'block';	
		
	
	}
	else if(open==1)
	{
		document.getElementById('open'+id).value=0;
		document.getElementById('im_'+id).style.fontWeight     = "normal";
		document.getElementById('id_'+id).style.display = 'none';
	}	
}

function Visiblepopup(id)
{
	document.getElementById(id).style.display = 'block';
}
function Hiddenpopup(id)
{
	document.getElementById(id).style.display = 'none';
}

function getDeleteConfirm(a,b)
 {
 
 	var confresult = window.confirm(a);
 	if(confresult)
 	{
 		$("client_action").value=b;
 	}
 	return confresult;
 }
 
 function replay_to_messages()
 {
 	var replay_tbl = document.createElement("table");
 		replay_tbl.cellpadding  = "0"; 
 		replay_tbl.cellspacing  = "0" ;
 		replay_tbl.width        ="100%" ;
 		
 	
 	/*Subject Label*/
 	var replay_tbl_row=replay_tbl.insertRow(-1);
 	
 	var label  = document.createElement("label");
 		label.setAttribute("for","subject");
 		label.innerHTML = "subject";
 	    
 	/*Subject Label*/	
 		
 	/*Subject*/
 	var subject  = document.createElement("input");
 	
 		subject.name = "subject";
 		subject.type = "text";
 		subject.id   = "subject";
 		subject.style.width = "350px";
 		var subject_td = document.getElementById("subject_td").innerHTML;
 		var subject_d = document.getElementById("subject_d").innerHTML;
 		subject.value = "RE:  "+subject_td+"   /  "+subject_d+"  /";
 	    var replay_tbl_cell = replay_tbl_row.insertCell(-1);
		replay_tbl_cell.colspan = "2";
 	    replay_tbl_cell.appendChild(subject);
 		replay_tbl_cell.appendChild(label);
 	
 	/*Subject*/
 	
 	/*Text Area*/ 	

 	var replay_tbl_row=replay_tbl.insertRow(-1);
 	var replay_tbl_cell = replay_tbl_row.insertCell(-1);
    	replay_tbl_cell.colspan = "2";
 	var textArea      = document.createElement("textarea");
 		textArea.name = "replay_txt";
 		textArea.id   = "replay_txt";
 		textArea.cols = 45;
 		textArea.rows = 10;
 		replay_tbl_cell.appendChild(textArea);
 	/*Text Area*/ 	
 	
 	/*Text replay Btn*/ 	
 	var replay_tbl_row=replay_tbl.insertRow(-1);
 	var replay_tbl_cell = replay_tbl_row.insertCell(-1);
 		replay_tbl_cell.colspan = "2";
 	var replay_btn = document.createElement("input");
 		replay_btn.type     = "button";
 		replay_btn.id       = "send_button";
 		replay_btn.name     = "send_button";
 		replay_btn.value    = "Send";
 		
 		replay_btn.onclick = function()
 		{
 			test_and_send();
 		}
 		replay_tbl_cell.appendChild(replay_btn);
 		
 	var replay_tbl_cell = replay_tbl_row.insertCell(-1);
 	var replayed = $("replayed");
 	
 	var close_btn = document.createElement("input");
 		close_btn.type     = "button";
 		close_btn.id       = "close_button";
 		close_btn.name     = "close_button";
 		close_btn.value    = "Cancel";
 		
 		close_btn.onclick = function()
 		{
 			replayed.removeChild(replay_tbl)
 		}
 		replay_tbl_cell.appendChild(close_btn);	
 	
 	
 	//alert(replay_tbl.innerHTML);
 	replayed.appendChild(replay_tbl);
 }
 
 
 function test_and_send(){
 	var textArea = $("replay_txt").value;
 	var subject = $("subject").value;
 	if(subject == "")
 	{
 		alert("Fill The Subject Fild");
 		return;
 	}
 	if(textArea == "")
 	{
 		alert("Fill The Text can't be empty");
 		return;
 	}
 	var client_action = $("client_action");
 	client_action.value = "sendMessageFromStudent";
 	//alert(client_action.value);
 	document.forms['posting'].submit();
 }


function checkMailForm()
{
	
	return false;
}


function openAnswer(task_id,lng_id)
{
	
	var URL = "/includes/ajax.php?action=loadAnswerContent&lng="+lng_id;
	$('items_'+task_id).innerHTML = loader_str;
	new Ajax.Updater('items_'+task_id, URL, {
	  parameters: { taskid: task_id ,lng:lng_id},
	  
	  metod:'get'

});

}

function closeThis(td)
{
		$('items_'+td).innerHTML = "&nbsp;";
}

function loadTest(test_id,lng_id)
{
	var URL = "/includes/ajax.php?action=loadTest&lng="+lng_id;
		$('items_Test').innerHTML = loader_str;
	new Ajax.Updater('items_Test', URL, {
	  parameters: { test: test_id ,lng:lng_id},
	  metod:'get',
	  evalScripts:true


});
}
var intGlobalSeconds = 0;
function startTiming(id,start)
{
	start++;
	intGlobalSeconds=start;
	var strTime = SecondsToTime(start);
	var plase = document.getElementById(id);
	var UsedTime = document.getElementById("UsedTime");
	UsedTime.value =start; 
	plase.innerHTML = strTime;
	setTimeout("startTiming('"+id+"',"+start+")",1000);
}

function SecondsToTime(seconds)
{
	seconds = parseInt(seconds);
	var intHours =Math.floor( seconds /(24*60*60));
	var intMintes =Math.floor((seconds-intHours*24*60*60)/60);
	var intSecs = seconds -intHours*24*60*60 -intMintes*60;
	
	var strHours = (intHours < 10 ? "0":"")+intHours;
	var strMintes= (intMintes < 10 ? "0":"")+intMintes;
	var strSecs= (intSecs < 10 ? "0":"")+intSecs;
	return strHours+":"+strMintes+":"+strSecs;
}

function ShowLesson(lid,elem){
		var lessonsContent = document.getElementById("lessonsContent");
		var lid_el = document.getElementById(lid);

		var rows = lessonsContent.rows;
		
		for(var i =0 ; i <rows.length;i++ )
		{
			rows[i].cells[0].style.display='none';
		}
		lid_el.style.display = "";
		var subMenuLinks = document.getElementsByClassName('subMenues_act', $('links_conneten'));/*links_conneten*/
		for(var i = 0 ; i < subMenuLinks.length;i++)
		{
			subMenuLinks[i].className = "subMenues";
		}
		elem.className= "subMenues_act";
}

function openReplay(id,lngi,st)
{
	var mySt = st;
	var replay = $("replay");
	replay.style.display = "";
	var topic = $("topic");
	var topic_id = $("topic_id");
	topic_id.value = id;
	if(st < 0)
	topic_id.value = 0;
	var loader_str = "<img src=\"/img/ajax-loader.gif\" width=\"48\">";
	topic.innerHTML = loader_str;
/*	new Ajax.Updater('topic', '/includes/ajax.php?action=getReplayById&lng='+lngi, {
		
  		parameters: { action: 'getReplayById',top_id:id, lng:lngi, status:mySt },
	});*/
	
	
	new Ajax.Request('/includes/ajax.php?action=getReplayById&lng='+lngi+"&top_id="+id+"&status="+mySt, {

  onComplete: function(transport) {

    if (200 == transport.status)
    {
    	//alert(transport.responseText);
		var topic_id = $("topic_id");
		topic.innerHTML = transport.responseText;
    	
    }
      

  }

});

	replay.style.display = "";

	
}

function getOne(v,c)
{
	alert(v+c);
}

function saveDiscusion()
{
	var topicAnswerTitle =$("topicAnswerTitle");
	var topicAnswerBody =$("topicAnswerBody");
	
	if(topicAnswerTitle.value !="" && topicAnswerBody.value!="")
	{
		return true;
	}else
	{
		alert("Fill All(temp)");
	}
	return false;
}


function displayHint(id,mode,e)
{
	var loc =getMouseXY(e);
	var elem = $(id);
	if(mode){
		
		
		//elem.style.top = (loc.x-400)+"px";
		//elem.style.left = (loc.y-400)+"px";
	elem.style.display = "";
	}
	else
	elem.style.display = "none";
}

var IE = document.all?true:false
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  var m_location ={x:tempX,y:tempY} 
  return m_location;
}



function checkToSend(errorMessage,errorFile,confirmSEND,extsStr, client_action)
{
	var allowSubmit = false;
	var exts_1 =extsStr.split(";") 
	var extArray = new Array(exts_1.length);
	for(var i = 0 ; i < exts_1.length;i++)
	{
		extArray[i] = exts_1[i].substr(1);
	}
	if (client_action !="")
	{
		var client_action_el = $("client_action");
		client_action_el.value = client_action;
	}
	//alert(extArray);
	
	var msgSubject = $("msgSubject");
	var msgBody = $("msgBody");
	if(msgSubject.value != "" && msgBody.value!="")
	{
		 allowSubmit=true;
	}else
	{
		alert(errorMessage);
		return false;
	}
	var files = document.getElementsByName("attached[]");
	var removingArrays = new Array();
	for(var i = 0 ; i < files.length ; i ++)
	{
		if(files[i].value != "")
		{
			if(!LimitAttach(files[i].value,extArray))
			{
				alert(files[i].value+" "+errorFile+" ("+extArray.join(" ")+")");
				files[i].value ="";
				
			}
		}
	}
	var attaches = document.getElementById("attaches");
	
	
	var conf = confirm(confirmSEND);
	
	return conf;
}

function add_file()
			{
					var attaches = document.getElementById("attaches");
					var newFile = document.createElement("input");
					newFile.name ="attached[]";
					newFile.type = "file";
					var newRow =attaches.insertRow(-1) ;
					newRow.id="FILE_"+attaches.rows.length-1;
					var newCell = newRow.insertCell (-1);
					newCell.innerHTML = attaches.rows.length;
					var newCell = newRow.insertCell (-1);
					newCell.appendChild(newFile);
			}
			
			



//extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(file,extArray)
{
		allowSubmit = false;
		if (!file) return;
		while (file.indexOf("\\") != -1)
		file = file.slice(file.indexOf("\\") + 1);
		
		var last_idex_of_dot = file.lastIndexOf(".")
		ext=file.substr(last_idex_of_dot);
		//ext = file.slice(file.indexOf(".")).toLowerCase();
		
		for (var i = 0; i < extArray.length; i++) 
		{
		if (extArray[i] == ext) {
			allowSubmit = true; break;
			}
		}
		return allowSubmit;
}

function mypopup(URL)
 {
   mywindow = window.open (URL,  "Edit","location=0,status=1,scrollbars=1,  width=1024,height=768");
   mywindow.moveTo(0,0);
   mywindow.focus( );
 } 
 
var count=0;
function OpenPop(id, iter){
	
	if (count==0){
		
	document.getElementById(id+iter).style.display = 'block';
	
	if(id == 'open')
	document.getElementById('close').style.display = 'none';
	
	//if(id == 'playdiv')
	//document.getElementById('prevdiv').style.display = 'none';
	
	count++;
	}
    else
	{
	count--;
	document.getElementById(id+iter).style.display = 'none';
	if(id == 'open')
	document.getElementById('close').style.display = 'block';
	}

}