/**
 * Created on 2008-11-06
 *
 * Copyright (c) 2008-2009 Lerkins Group. All rights reserved.
 * LinguaMemo SYSTEM IS NOT AN OPEN SOURCE APPLICATION.
 * Violation of the copyrights will be prosecuted.
 */

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

var getFunctionsUrl = "suggest.php?keyword=";
var phpHelpUrl = "http://lmt.linguahouse.com/searchLessons.php?id=";
var errorMessage = "Your information is incomplete or incorrect. Please correct the fields below and try again:";

var suggestions = 0;
var userKeyword = "";
var position = -1;
var isKeyUpDownPressed = false;
var suggestionMaxLength = 30;
var httRequestKeyword = "";
var hasResults=false;
var autocompletedPressed = false;
var autocompletedKeyword = "";
var hasResults = false;
var timeoutId = -1;
var id_input="";
var id="";
/* obiekt pamieci podrecznej zawierajacy podpowiedzi pobrane dla roznych slow kluczowych */
var oCache = new Object();

var minVisiblePosition = 0;
var maxVisiblePosition = 15;

var debugMode = true;
var xmlHttpGetSuggestions = createXmlHttpRequestObject();

var playButtonID = null;

function getElement(divName)
{
	if (isIE4) {
    objElement = document.all[divName];
  } else if (isIE5 || isNS6) {
    objElement = document.getElementById(divName);
  } else {
    objElement = document.getElementById(divName);
  }
  return objElement;
}


  function clearThisField(form, id, value, default_value)
  {

	if(form == "registration" && value == default_value)
  	{
  		obj=document.getElementById(id);
  		obj.value="";
  	}
  	if(form == "login" && value == default_value)
  	{
  		obj=document.getElementById(id);
  		obj.value="";
  	}
  	if(form == "formLSearch" && value == default_value)
  	{
  		obj=document.getElementById(id);
  		obj.value="";
  	}
  	if(form == "formTSearch" && value == default_value)
  	{
  		obj=document.getElementById(id);
  		obj.value="";
  	}
  	if(form == "formSearch" && value == default_value)
  	{
  		obj=document.getElementById(id);
  		obj.value="";
  	}

  }

  function newWindow()
  {
  	window.location='profile.php';
  }

  function changeWindow(web)
  {
  	window.location=web;
  }

  function showConfirmAlert(Prf_GUID, FirstName, LastName, web)
  {
  	var answer = confirm ("Do you want to delete " +' '+FirstName+ ' ' +LastName +' ')
	if (answer==true)
		changeWindow(web+'.php?id=delete&prf='+Prf_GUID+'&firstname='+FirstName+'&lastname='+LastName);
  }

  function changeSubscription(op, Bls_GUID, Prf_GUID, FirstName, LastName, web)
  {
	if(op==0)
	{
  		changeWindow(web+'&add=add&prf='+Prf_GUID+'&firstname='+FirstName+'&lastname='+LastName+'&bls='+Bls_GUID);
	}

	if(op==1)
	{
		var answer = confirm ("Do you want to uncheck subscription to " +' '+FirstName+ ' ' +LastName +' ?')
		if (answer==true)
			changeWindow(web+'&delete=delete&prf='+Prf_GUID+'&firstname='+FirstName+'&lastname='+LastName+'&bls='+Bls_GUID);
	}
  }

  function showStudentsSubscription(Bls_GUID) {

		changeWindow('profile.php?id=manageSubscription&bls='+Bls_GUID);
}

 function showRegistryForm(id) {

		changeWindow('schools.php?id='+id);
 }

 function showMoreComments(id, key, Lsn_GUID, Cmm_GUID)
 {
 	var id_img=document.getElementById(id);
	if(key==0)
	{
 		changeWindow('viewComments.php?cmm='+Cmm_GUID+'&k=1&lsn='+Lsn_GUID);
 	}
 	else
 	{
 		changeWindow('viewComments.php?cmm='+Cmm_GUID+'&k=0&lsn='+Lsn_GUID);
 	}
 }

 function checkCorrectData(form_id, col, line)
 {
 	var error=0;
 	var no=4;
 	var id_form=document.getElementById(form_id);

 	for(var i=0;i<col;i++)
 	{
		var id_select=document.getElementById('s'+i);

		if(id_select.value=='---select---')
		{
			error++;
		}

		if(id_select.value=='First Name')
		{
			no--;
		}

		if(id_select.value=='Last Name')
		{
			no--;
		}

		if(id_select.value=='Email')
		{
			no--;
		}

		if(id_select.value=='Occupation')
		{
			no--;
		}
 	}

	if(error<=(col-4) && no==0)
	{
 		id_form.form.submit();
 	}
 	else
 	{
 		alert('The options \'First Name\' and \'Last Name\' and \'Email\' and \'Occupation\' has to be selected.');
 		return false;
 	}
 }

 function checkCorrectSelect(id,amount_col, url, option, value)
 {
 	var id_select=document.getElementById(id);
	var error=false;

 	if(id_select.value!='---select---')
 	{
 		for(var i=0;i<amount_col;i++)
	 	{
	 		var id_select_prev=document.getElementById('s'+i);

	 		if(id_select.value==id_select_prev.value)
	 		{
	 			alert('This option has already selected.');
	 			id_select.value='---select---';
	 			error=true;
	 		}
	 	}

	 	if(error==false)
	 	{
	 		var another_par='&value=v_'+value;
			checked_delete_data(id, value, url, option, another_par);
		}
 	}
 }

function createXmlHttpRequestObject()
{
	var xmlHttp;

	try
	{
		xmlHttp = new XMLHttpRequest();

	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" );

		for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
				try
				{
					xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
				}
				catch (e) {}
		}

	}

	if(!xmlHttp)
		alert("error with creating xmlhttprequest");
		else
		return xmlHttp;
}

function init()
{
	var oKeyword = document.getElementById(id_input);
	oKeyword.setAttribute("autocomplete","off");
	oKeyword.value="";
	oKeyword.focus();
	//setTimeout("checkForChanges(id_input, id)", 500);
}

function addToCache (keyword, values)
{
	oCache[keyword] = new Array();
	for(i=0;i<values.length;i++)
	{
		oCache[keyword][i] = values[i];
	}
}

function checkCache(keyword)
{

	if(oCache[keyword])
		return true;
	for(i=keyword.length-2;i>=0;i--)
	{
		var currentKeyword = keyword.substring(0, i+1);

		if(oCache[currentKeyword])
		{
			var cacheResults = oCache[currentKeyword];
			var keywordResults = new Array();
			var keywordResultsSize = 0;

			for(j=0;j<cacheResults.length;j++)
			{
				if(cacheResults[j].indexOf(keyword) == 0)
					keywordResults[keywordResultsSize++] = cacheResults[j];
			}

			addToCache (keyword, keywordResults);
			return true;
		}
	}
	return false;
}

function getSuggestions(keyword)
{
	if(keyword !="" && !isKeyUpDownPressed)
	{
		isInCache = checkCache(keyword);
		if(isInCache == true)
		{
			httpRequestKeyword = keyword;
			userKeyword = keyword;
			displayResults(keyword, oCache[keyword]);
		}
		else
		{
			if(xmlHttpGetSuggestions)
			{
				try
				{
					if(xmlHttpGetSuggestions.readyState == 4 || xmlHttpGetSuggestions.readyState == 0)
					{
						httpRequestKeyword = keyword;
						userKeyword = keyword;
						xmlHttpGetSuggestions.open("GET", getFunctionsUrl + encode(keyword) + "&row=" + id, true);
						xmlHttpGetSuggestions.onreadystatechange = handleGettingSuggestions;
						xmlHttpGetSuggestions.send(null);
					}
					else
					{
						userKeyword = keyword;
						if(timeoutId != -1)
							clearTimeout(timeoutId);
						timeoutId = setTimeout("getSuggestions(userKeuword)",400);
					}
				}
				catch(e)
				{
					displayError("Was unable to connect whith server" + e.toString());
				}
			}
		}
	}
}

function xmlToArray(resultsXml)
{
	var resultsArray = new Array();

	for(i=0;i<resultsXml.length;i++)
		resultsArray[i]= resultsXml.item(i).firstChild.data;
		return resultsArray;
}


function handleGettingSuggestions()
{
	if(xmlHttpGetSuggestions.readyState == 4)
	{
		if(xmlHttpGetSuggestions.status == 200)
		{
			updateSuggestions();
		}
		else
		{
			displayError("error");

		}
	}
}

function updateSuggestions()
{
	var response = 	xmlHttpGetSuggestions.responseText;

	response = xmlHttpGetSuggestions.responseXML.documentElement;

	nameArray = new Array();

	if(response.childNodes.length)
	{
		nameArray = xmlToArray(response.getElementsByTagName("value"));
	}

	if(httpRequestKeyword == userKeyword)
	{
		displayResults(httpRequestKeyword, nameArray);
	}
	else
	{
		addToCache(httpRequestKeyword, nameArray);
	}
}




function displayResults(keyword, results_array)
{
		var div = "<table>";

		if(!oCache[keyword] && keyword)
			addToCache(keyword, results_array);

		if(results_array.length == 0)
		{
			//div += "<tr><td>Nie znaleziono dopasowania dla "+keyword+"</td></tr>";
			hasResults = false;
			suggestions = 0;
		}
		else
		{
			position = -1;
			isKeyUpDownPressed = false;
			hasResults = true;
			suggestions = oCache[keyword].length;

			for(var i=0; i<oCache[keyword].length;i++)
			{
				crtFunction = oCache[keyword][i];
				crtFunctionLink = crtFunction;
				while(crtFunctionLink.indexOf("_") !=-1)
					crtFunctionLink = crtFunctionLink.replace("_","-");

					div += "<tr id='tr" + i + "' onmouseover='handleOnMouseOver(this);' " + "onmouseout='handleOnMouseOut(this);'>" + "<td align='left'><a id='a"+ i + "' href='" + phpHelpUrl + crtFunctionLink;

				if(crtFunction.length <= suggestionMaxLength)
				{
					div +="'><b>" + crtFunction.substring(0, httpRequestKeyword.length, crtFunction.length) + "</b>";
					div += crtFunction.substring(httpRequestKeyword.length, crtFunction.length) + "</a></td></tr>";
				}
				else
				{
					if(httpRequestKeyword.length < suggestionMaxLength)
					{
						div += "'><b>" + crtFunction.substring(0, httpRequestKeyword.length) + "</b>"
						div +=crtFunction.substring(httpRequestKeyword.length, suggestionMaxLength) + "</a></td></tr>";
					}
					else
					{
						div +="'><b>" + crtFunction.substring(0, suggestionMaxLength) + "</b></td></tr>"
					}
				}

			}
		}

		div +="</table>";
		var oSuggest = document.getElementById("suggest"+id);
		var oScroll = document.getElementById("scroll"+id);
		oScroll.scrollTop = 0;
		oSuggest.innerHTML = div;
		oScroll.style.visibility = "visible";
		oScroll.className="show1";


		if(results_array.length > 0)
			autocompleteKeyword();
}


function checkForChanges()
{
	var keyword = document.getElementById(id_input).value;

	if(keyword =="")
	{
		window.onload=init();
		hideSuggestions();
		userKeyword ="";
		httpRequestKeyword="";
		setTimeout("checkForChanges()", 500);
	}

	if((userKeyword != keyword) && (autocompletedKeyword != keyword) && (!isKeyUpDownPressed))
		getSuggestions(keyword);

}

function handleKeyUp(e, id_input2, id2)
{
	//pobieramy zdarzenie
	id_input=id_input2;
	id=id2;
	e = (!e) ? window.event : e;

	//pobiera adresata zdarzenia
	target = (!e.target) ? e.srcElement : e.target;

	if(target.nodeType == 3)
	target = target.parentNode;

	//pobiera kod znaku wcisnietego

	code = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));

	//sprawdza czy zdazenie bylo typu keyup
	if(e.type == "keyup")
	{
		isKeyUpDownPressed = false;
		//
		//sprawdza czy pojawil sie ktorys z waznych dla aplikacji znakow
		if((code < 13 && code != 18) || (code >= 14 && code < 32) ||
			(code >= 33 && code <= 46 && code != 38 && code != 40) || (code >= 112 && code <=123))
		{

		}
		else

		if(code >=65 && code < 90)
		{
			checkForChanges(id_input, id);
		}

		if(code == 13)
		{
			//sprawdza czy jakas funkcja jest wlasnie wybrana
			if(position >= 0)
			{
				hideSuggestions();
			}
		}
		else
			if(code == 40)
			{

				newTR=document.getElementById("tr"+(++position));
				oldTR=document.getElementById("tr"+(--position));
				//usuwa stary wybor
				if(position>=0 && position < suggestions-1 )
					oldTR.className = "";

				//wybiera nowa podpowiedz i aktualizuje slowo kluczowe
				if(position < suggestions - 1)
				{

					newTR.className = "highlightrow";
					updateKeywordValue(newTR);
					position++;
				}
				e.cancelBubble = true;
				e.returnValue = false;

				idKeyUpDownPressed =  true;
				//przewija podpowiedz w dol, jesli widoczne okno nie jest juz aktualne
				if(position > maxVisiblePosition)
				{
					oScroll = document.getElementById("scroll"+id);
					oScroll.scrollTop += 18;
					maxVisiblePosition +=1;
					minVisiblePosition +=1;
				}
			}
			else
			//nacisniecie strzalki w gore przenosi nas do poprzedniej podpowiedzi
			if(code == 38)
			{
				newTR=document.getElementById("tr" + (--position));
				oldTR=document.getElementById("tr" + (++position));

				//usuwa stare zaznaczenie
				if(position>=0 && position <= suggestions -1)
				{
					oldTR.className = "";
				}

				if(position > 0)
				{
					newTR.className = "highlightrow";
					updateKeywordValue(newTR);
					position--;
					//przewija okno w gore jesli dane w nim sa juz niektualne
					if(position<minVisiblePosition)
					{
						oScroll = document.getElementById("scroll"+id);
						oScroll.scrollTop -= 18;
						maxVisiblePosition -= 1;
						minVisiblePosition -= 1;
					}
				}
				else
					if(position == 0)
						position--;
					e.cancelBubble = true;
					e.returnValue = false;
					idKeyUpDownPressed = true;
					}
				}

			}



function updateKeywordValue(oTr)
{
	var oKeyword = document.getElementById(id_input);
	var crtLink = document.getElementById("a" + oTr.id.substring(2,oTr.id.length)).toString();

	crtLink = crtLink.replace("-", "_");

	oKeyword.value = unescape(crtLink.substring(phpHelpUrl.length, crtLink.length));
}

function deselectAll()
{
	for(i=0; i<suggestions;i++)
	{
		var oCrtTr = document.getElementById("tr" + i);
		oCrtTr.className = "";
	}
}

function handleOnMouseOver(oTr)
{
	deselectAll();
	oTr.className = "highlightrow";
	position = oTr.id.substring(2,oTr.id.length);
}

function handleOnMouseOut(oTr)
{
	oTr.className = "";
	position = -1;
}


function encode(uri)
{
	if(encodeURIComponent)
	{
		return encodeURIComponent(uri);
	}

	if(escape)
	{
		return escape(uri);
	}
}

function hideSuggestions()
{
	var oScroll = document.getElementById("scroll"+id);
	oScroll.style.visibility = "hidden";
}

function selectRange(oText, start, length)
{
	if(oText.createTextRange)
	{
		//ie
		var oRange = oText.createTextRange();
		oRange.moveStart("character", start);
		oRange.moveEnd("character", length - oText.value.length);
		oRange.select();

	}
	else
	{
		//ff
		if(oText.setSelectionRange)
		{
			oText.setSelectionRange(start, length);
		}
		oText.focus();
	}
}

function autocompleteKeyword()
{
	var oKeyword = document.getElementById(id_input);
	position = 0;
	deselectAll();
	document.getElementById("tr0").className="highlightrow";
	updateKeywordValue(document.getElementById("tr0"));
	selectRange(oKeyword, httpRequestKeyword.length, oKeyword.value.length);
	autocompletedKeyword=oKeyword.value;
}

function displayError(message)
{
	alert("Error to connect with server" + (debugMode ? "\n" + message : ""));
}

//switchdiv is a tab of boolean value, index - is a unique id of div
//this tab helps to showDiv or hideDiv
var switchdiv= new Array();
var globalObject = '';

var checkSwitchCommentDiv = '';
var checkSwitchComment = '';
//this function draws comment in a given div id
//div_id is a id of div in which we want to draw a comment
//no is a max number of allowed comment that can be added
//no_answer is number of comments which has got current comment
//known_user is a variable which shows if the user is logged on
function drawComment(div_id, topic, comment, date, nick, no, no_answer, Cmm_GUID, Lsn_GUID, Com_Cmm_GUID, known_user, page)
{
	var url='comment.php';
	var another_param_to_url='&page='+page;
	var newUrl = getUrl(url, Lsn_GUID, Cmm_GUID, div_id, another_param_to_url);
	var url_answer = getUrl('addComment.php', Lsn_GUID, Cmm_GUID, div_id, another_param_to_url);
	var url_topic = getUrl('currentComment.php', Lsn_GUID, Cmm_GUID, div_id, '&keepThis=true&TB_iframe=true&height=120&width=250');

	var obj ="<div><table class='tab1' id='tab"+Cmm_GUID+"'>";
	obj +="<tr><td class='col_img'>";
		if(no_answer!=0)
			obj +="<img id='img"+Cmm_GUID+"' alt='images' src='images/plus.gif' class='img_plus' onclick='jsConnect(\""+url+"\", \""+Lsn_GUID+"\",\""+Cmm_GUID+"\", \""+Cmm_GUID+"\", \"img"+Cmm_GUID+"\", \"&page="+page+"\");'>";
		else
			obj +="&nbsp";
	obj +="</td><td class='col_img'><p id='pp_"+Cmm_GUID+"' class='p_pointer' title='"+topic+"' onclick='my_tb_show(this, \"currentComment.php?cmm="+Cmm_GUID+"&lsn="+Lsn_GUID+"&keepThis=true&TB_iframe=true&height=120&width=250\");'><img alt='images' src='images/text.gif' class='img_text'></p></td>";
	obj +="<td width='294' id='td1"+Cmm_GUID+"'> <p id='p_"+Cmm_GUID+"' class='link' title='"+topic+"' onmouseout='change_class(this.id, \"link\");' onmouseover='change_class(this.id, \"link_active\");' onclick='my_tb_show(this, \"currentComment.php?cmm="+Cmm_GUID+"&lsn="+Lsn_GUID+"&keepThis=true&TB_iframe=true&height=120&width=250\");'>"+topic+"</a></td>";
	obj +="<td class='col_data_right'>"+date+"</td></tr> ";
	obj +="<tr><td colspan='3' id='td2"+Cmm_GUID+"' class='col_comment'>"+comment+"</td>";
	obj +="<td class='col_data_right'> ~ "+nick+"</td></tr> ";
	if(known_user!='') {
		obj +="<tr><td colspan='4' class='col_answer'><img alt='images' src='images/arrow.png' class='img'>";
		obj +="<p id='p"+Cmm_GUID+"'  onclick='jsConnect(\""+url_answer+"\", \""+Lsn_GUID+"\",\""+Cmm_GUID+"\", \"comment"+Cmm_GUID+"\", \"comment\", \"&page="+page+"\");'>Answer</p>";
		obj +="</td></tr> ";
		obj +="<tr><td colspan='4' class='col_answer'>";
		obj +="<div id='comment_add"+Cmm_GUID+"'>";
		obj +="</div>";
		obj +="<div id='comment"+Cmm_GUID+"'>";
		obj +="</div>";
		obj +="</td></tr> ";
	}
	else
	{
		obj +="<tr><td colspan='4' class='col_answer'><img alt='images' src='images/arrow.png' class='img'>";
		obj +="<a href='login.phpgoBack=viewComments.php&lsn="+Lsn_GUID+"&page="+page+"'>Answer</a>";
		obj +="</td></tr> ";
	}
	obj +="</table></div>";
	obj +="<div id='"+Cmm_GUID+"'>";
	obj +="</div>";

	globalObject+=obj;
	var ocomment = document.getElementById(div_id);

	ocomment.innerHTML=globalObject;
}

//this function gets 4 params and return a new created a url
//div_id is a id of div in which we want to draw a comment
function getUrl(url, Lsn_GUID, Cmm_GUID, div_id, another_param_to_url)
{
	var newUrl=url+'?lsn='+Lsn_GUID+'&cmm='+Cmm_GUID+'&div='+div_id;

		if(another_param_to_url!='empty')
			newUrl+=another_param_to_url;
	return newUrl;
}

// this function creates a new js object, the needed value is drawn from php file
// chceck tab switchdiv and depending on the value show or hide div
//appendChild() method adds a node after the last child node of the specified element
//url is a url of php
//Lsn_GUID is a guid of current lesson
//Cmm_GUID is a guid og current comment
//div_id is a id of div in which we want to draw a comment
//div_id_action is a id of div in which we want to another action
//another_param_to_url is an another param to added to url

function jsConnect(url, Lsn_GUID, Cmm_GUID, div_id, div_id_action, another_param_to_url) {
	var oelem = '';
	var elemetByName;
	var newUrl=getUrl(url, Lsn_GUID, Cmm_GUID,div_id, another_param_to_url);
	
    if(switchdiv[div_id]==false || switchdiv[div_id]=='' || !switchdiv[div_id]) {

		switchdiv[div_id]= true;
        oelem=document.createElement("script");
	    oelem.src=newUrl;
	    oelem.type="text/javascript";
	    elemetByName =document.getElementById(div_id);
    	elemetByName.appendChild(oelem);
		globalObject='';
		//if(div_id_action!='comment')
			showDiv(div_id, div_id_action);

    } else {
    	switchdiv[div_id]= false;
		//if(div_id_action!='comment')
			hideDiv(div_id, div_id_action);
    }

	if(div_id_action=='comment')
    	checkShowComments(div_id, div_id_action);
    else {
	    if(checkSwitchCommentDiv!='') {
	    	hideDiv(checkSwitchCommentDiv, 'comment');
	    	checkSwitchCommentDiv='';
	    }
    }
}

// this function check if the form comment is showed
//div_id is a id of div in which we want to draw a comment
//div_id_action is a id of div in which we want to another action
function checkShowComments(div_id, div_id_action)
{
	if(checkSwitchCommentDiv!='' && checkSwitchCommentDiv != div_id) {
		hideDiv(checkSwitchCommentDiv, div_id_action);
		checkSwitchCommentDiv = div_id;
		showDiv(div_id, div_id_action);
	} else if (checkSwitchCommentDiv!='' && checkSwitchCommentDiv == div_id) {
		hideDiv(checkSwitchCommentDiv, div_id_action);
		checkSwitchCommentDiv='';
	} else {
		checkSwitchCommentDiv = div_id;
		showDiv(checkSwitchCommentDiv, div_id_action);
	}

	if(checkSwitchComment!='') {
		hideDiv(checkSwitchComment, div_id_action);
		checkSwitchComment='';
	}


}

// this function show div
//div_id is a id of div in which we want to draw a comment
//div_id_action is a id of div in which we want to another action
function showDiv(div_id, div_id_action)
{
	var obj = document.getElementById(div_id);

	if(div_id_action!='comment')
		document.getElementById(div_id_action).src='images/minus.gif';
	if(obj) {
		//obj.style.height = '';
		//obj.style.margin = '10px';
	    //obj.style.visibility = 'visible';
	    setCssStyle(div_id, false, false, false, false, false, false, 'inline' ,false, false, false);
	}
}

// this function hide div
//div_id is a id of div in which we want to draw a comment
//div_id_action is a id of div in which we want to another action
function hideDiv(div_id, div_id_action)
{
	var obj = document.getElementById(div_id);

	if(div_id_action!='comment')
		document.getElementById(div_id_action).src='images/plus.gif';
	if(obj) {
		//obj.style.height = '0px';
		switchdiv[div_id]='';
		//obj.innerHTML = '';
	    //obj.style.visibility = 'hidden';
	    setCssStyle(div_id, false, false, false, false, false, false, 'none' ,false, false, false);
   	}
}

//this function draws form to add a comment in a given div id
//div_id is a id of div in which we want to draw a form
function drawAddComment(div_id, Cmm_GUID, Lsn_GUID, Prf_GUID, page, page_url)
{
	var id_form;
	if(Cmm_GUID=='')
		id_form=Lsn_GUID;
	else
		id_form=Cmm_GUID;
	
	var ff_id_form = 'form'+id_form;
	var obj ="<div id='error"+ff_id_form+"'></div>";
	obj +="<form id='form"+id_form+"'>";
	obj +="<input type='hidden' name='form_name' value='"+div_id+"'/>";
	obj +="<input type='hidden' name='page' value='"+page+"'/>";
	obj +="<p style='cursor:text;' id='form_topic"+ff_id_form+"'>Topic:</p>";
	obj +="<input id='id_topic"+ff_id_form+"' type='text' name='topic' size='44'/>";
	obj +="<p style='cursor:text;' id='form_comment"+ff_id_form+"'>Comment:</p>";
	obj +="<textarea id='id_comment"+ff_id_form+"' name='comment' cols='50' rows='7'></textarea><br/>";
	obj +="<input type='image' src='images/add_button_com.gif' onclick='checkCorrectDataForm(this.form, \"id_topic\", \"id_comment\", \""+Cmm_GUID+"\", \""+Lsn_GUID+"\", \""+page_url+"\"); return false;' name='button' />";
	obj +="</form>";

	var ocomment = document.getElementById(div_id);

	ocomment.innerHTML=obj;
}


//this function check data from a form and if the data is correct send a form
function checkCorrectDataForm(form_obj, id_topic, id_comment, Cmm_GUID, Lsn_GUID, page_url)
 {
 	var topic;
 	var comment;
 	var error=0;
	div_id = 'error'+form_obj.id;

 	var id_form=document.getElementById(form_obj);

//	var obj_topic=document.getElementById(id_topic);
//	var obj_comment=document.getElementById(id_comment);
	var obj_topic=form_obj.topic;
	var obj_comment=form_obj.comment;
	var obj_page=form_obj.page;
 	
	if(obj_topic.value=='' || obj_topic.length<2) {
		error++;
		changeAttributeElement('form_topic'+form_obj.id, 'FF0000');
		changeAttributeElementBorder(id_topic+form_obj.id, 'input_red');
	}
	else {
		if(obj_topic.className == 'input_red') {
			changeAttributeElement('form_topic'+form_obj.id, '747474');
			changeAttributeElementBorder(id_topic+form_obj.id, 'input_grey');
		}
	}

 	if(obj_comment.value=='' || obj_comment.length<2) {
		error++;
		changeAttributeElement('form_comment'+form_obj.id, 'FF0000');
		changeAttributeElementBorder(id_comment+form_obj.id, 'input_red');
	}
	else {
		if(obj_comment.className == 'input_red') {
			changeAttributeElement('form_comment'+form_obj.id, '747474');
			changeAttributeElementBorder(id_comment+form_obj.id, 'input_grey');
		}
	}
 	
	if(error==0) {
 		var another_param_to_url='&topic='+obj_topic.value+'&comment='+obj_comment.value+'&page='+obj_page.value;

 		if(document.getElementById('res_comment')) {
 			removeObj('res_comment', div_id);
 		}
 		var url_tmp = page_url+'addCommentToDB.php';
 		jsConnect(url_tmp, Lsn_GUID, Cmm_GUID, 'comment_add'+Lsn_GUID+'', 'comment', another_param_to_url);
 	}
 	else {
 		if(!document.getElementById('res_comment'));
 			drawErrorComment(div_id, errorMessage, 'red');
 		return false;
 	}
 }

//this function change elements attribute
 function changeAttributeElement(id_element, color)
 {
 	var obj_element=document.getElementById(id_element);
 	 obj_element.style.color = '#'+color;
 }

 function changeAttributeElementBorder(id_element, class_name)
 {
 	var obj_element=document.getElementById(id_element);
 	obj_element.className = class_name;
 }

//this function draw a comment after reply to db server
function drawResultsComment(div_id, results_comment, class_name)
{
	var obj ="<h4 id='res_comment' class='"+class_name+"'>"+results_comment+"</h4>";
	checkSwitchComment=div_id;
	var ocomment = document.getElementById(div_id);

	ocomment.innerHTML=obj;
}

function show_advance_fields(div_id, form_id, Email, LastName, FirstName, option)
{
	var oelem = '';
	var elemetByName;

    if((switchdiv[div_id]==false || switchdiv[div_id]=='' || !switchdiv[div_id] || option=='1')) {

		switchdiv[div_id]= true;
        oelem=document.createElement("div");
	    oelem.value=show_adv_fields(div_id, form_id, Email, LastName, FirstName);
	    elemetByName =document.getElementById(div_id);
    	elemetByName.appendChild(oelem);

		showDiv2(div_id);
    } else {

    	switchdiv[div_id]= false;
		hideDiv2(div_id);
    }
}

function showDiv2(div_id)
{
	document.getElementById('img_arrow_activ').src='images/arrow_up.png';

	var obj = document.getElementById(div_id);
    obj.style.height = '';
	obj.style.margin = '10px';
    obj.style.visibility = 'visible';
}


function hideDiv2(div_id)
{
	document.getElementById('img_arrow_activ').src='images/arrow_down.png';

	var obj = document.getElementById(div_id);
	switchdiv[div_id]='';
	obj.innerHTML = '';
    obj.style.height = '';
    obj.style.visibility = 'hidden';
}

function show_adv_fields(div_id, form_id, Email, LastName, FirstName)
{
	var obj ="<br/><table>";
	obj +="<tr><td width='90'>First name</td><td width='90'>Last name</td><td width='90'>E-mail</td></tr>";
	obj +="<tr>";

	if(FirstName=='')
		obj +="<td><input id='filtr_first_name' type='text' name='filtr_first_name' size='5'/></td>";
	else
		obj +="<td><input id='filtr_first_name' type='text' name='filtr_first_name' value='"+FirstName+"' size='5'/></td>";

	if(LastName=='')
		obj +="<td><input id='filtr_last_name' type='text' name='filtr_last_name' size='5' /></td>";
	else
		obj +="<td><input id='filtr_last_name' type='text' name='filtr_last_name' value='"+LastName+"' size='5'/></td>";

	if(Email=='')
		obj +="<td><input id='filtr_email' type='text' name='filtr_email' size='5' /></td>";
	else
		obj +="<td><input id='filtr_email' type='text' name='filtr_email' value='"+Email+"' size='5'/></td>";

	obj +="</tr></table>";
	obj +="<br/><center><input type='image' src='images/search_button_filtr.gif' onclick='check_field("+form_id+", \"filtr_email\", \"filtr_last_name\", \"filtr_last_name\" ); return false;' name='button' /></center>";

	var ocomment = document.getElementById(div_id);

	ocomment.innerHTML=obj;
}

function check_field(form_id, id_filtr_email, id_filtr_last_name, id_filtr_first_name)
{
	var error=0;

 	var id_form=document.getElementById(form_id);

	var obj_filtr_first_name=document.getElementById(id_filtr_first_name);
	var obj_filtr_last_name=document.getElementById(id_filtr_last_name);
	var obj_filtr_email=document.getElementById(id_filtr_email);

	if(obj_filtr_first_name.value=='' && obj_filtr_last_name.value=='' && obj_filtr_email.value=='') {
		error++;
	}

	if(error==0)
	{
 		id_form.form.submit();
 	}
 	else
 	{
 		return false;
 	}
}

function showUserProfileDate(web, value)
{
	changeWindow(web+'.php?id=select&option=date&select='+value);
}

function checked_delete_data(id, value, url, option, another_par)
{
	var newUrl=url+'?'+option+'=d_'+id;

	if(another_par && another_par!='empty')
		newUrl+=another_par;

	var oelem = '';
	oelem=document.createElement("script");
	oelem.src=newUrl;
	oelem.type="text/javascript";
	var headID = document.getElementsByTagName("head")[0];
	headID.appendChild(oelem);
}


//function change atribyte class
//@param id_link this is a id of atribute which we want to change
//@param class_name this is a name of a new link's class
function change_class(id_link, class_name)
{
	var obj = document.getElementById(id_link);
	obj.className = class_name;
}

//function selected lessons option
//@param id_select this is a id of selected option
//@param value this is a value of selected option
//@param url this is a given url
//@param form_name is a name of form in which we selected option
//@param page_name is a option on which page we searched the data (student or teacher)
//@param search_opt is a otpion of searching
function selected_lesson_option(id_select, value, url, from_name, page_name, empty_session, search_opt)
{
    var id=document.getElementById(id_select);

    checked_selected_data(id_select, value, url, from_name, page_name, search_opt);

}

// this function change a value of selected select
//@param id_select this is a id of current selected option
//@param select_value this is a value of selected option
//@param form_name is a name of form in which we selected option
//@param values is array from db
//@param selected_guid_option is array from selected form option
//@param selected_main_data is array of id from selected option
function changeSelectValue(id_select, select_value, form_name, values, selected_guid_option, selected_main_data)
{
    var obj=values;
    var oselect = document.getElementById(id_select);
	var len=oselect.options.length;
	var zm=0;

	if(obj.length>1)
	{
		oselect.disabled=false;

	    //delete all select options
	    for(var p=(len-1); p >= 0; p--)
	    {
	    	oselect.remove(p);
	    }

		for(var k=0; k<obj.length; k++, zm++)
		{
			var selected_main_opt=false;
			var selected_opt_in_main=false;
			var selected_opt=false;

			if(k==0)
			{
				oselect.options[k] = new Option(obj[k][0], obj[k][0]);
				oselect.options[k].className = 'select_search_default';
			}
			else
			{
				for(var m=0;m<selected_guid_option.length;m++)
				{
					var is_set=false;
					//alert('k:'+k+' m: '+m+'selected_main_data '+selected_main_data[m]+' select_opt_header0 '+select_opt_header[0]+' select_opt_header1 '+select_opt_header[1]);
					if(obj[k][0])
					{
						if(obj[k][0]==selected_guid_option[m])
								selected_main_opt=true;

						if(obj[k][2]==selected_guid_option[m])
								selected_opt_in_main=true;
					}
					else
					{
						if(obj[k][2]==selected_guid_option[m])
								selected_opt=true;
					}
				}

				if(obj[k][0])
				{
					if(obj[k][0]!=obj[k-1][0])
					{
						//alert(' ifzm '+obj[k][1]+' mainop_'+obj[k][0]);
						oselect.options[zm] = new Option(obj[k][1], 'mainop_'+obj[k][0]);
						oselect.options[zm].className = 'select_search_main';

						if(selected_main_opt==true)
							oselect.selectedIndex=zm;
						//alert(' ifzm '+obj[k][3]+' opt_'+obj[k][2]);
						oselect.options[++zm] = new Option(obj[k][3], 'opt_'+obj[k][2]);
						oselect.options[zm].className = 'select_search';

						if(selected_opt_in_main==true)
							oselect.selectedIndex=zm;

					}
					else
					{
						//alert('ifelse zm '+obj[k][3]+' plus opt_'+obj[k][2]);
						oselect.options[zm] = new Option(obj[k][3], 'opt_'+obj[k][2]);
						oselect.options[zm].className = 'select_search';

						if(selected_opt_in_main==true)
							oselect.selectedIndex=zm;
					}
				}
				else
				{
					//alert('else zm '+obj[k][3]+' opt_'+obj[k][2]);
					oselect.options[zm] = new Option(obj[k][3], 'opt_'+obj[k][2]);
					oselect.options[zm].className = 'select_search_main';

					if(selected_opt==true)
						oselect.selectedIndex=zm;
				}
			}
		}
    }
    else
    {
    	var is_selected_option=false;
    	if(selected_main_data.length>1)
    	{
    		for(var k=0; k<selected_main_data.length; k++, zm++)
			{
				if(selected_main_data[k]==id_select)
					is_selected_option=true;
			}

			if(is_selected_option==false)
				oselect.disabled=true;
    	}
    	else
    	{
    		oselect.disabled=true;
    	}

    }
}

// this function creates a new js object, the needed value is drawn from php file
//appendChild() method adds a node after the last child node of the specified element
//@param id_select this is a id of selected option
//@param value this is a value of selected option
//@param url this is a given url
//@param form_name is a name of form in which we selected option
//@param page_name is a option on which page we searched the data (student or teacher)
//@param search_opt is a otpion of searching
function checked_selected_data(id_select, value, url, from_name, page_name, search_opt) {
	var oelem = '';
	var elemetByName;
    oelem=document.createElement("script");
    oelem.src=url+'?id='+id_select+'&value='+value+'&form='+from_name+'&page='+page_name+'&search_opt='+search_opt;
    oelem.type="text/javascript";
    elemetByName =document.getElementsByTagName("head")[0];
  	elemetByName.appendChild(oelem);
}

// this function show and hide searching form
//@param id_div this is a id of div where is a select option
//@param value this is a value of selected option
//@param url this is a given url
//@param form_name is a name of form in which we selected option
//@param page_name is a option on which page we searched the data (student or teacher)
//@param search_opt is a otpion of searching
//@param id_p this is id of option advance
function show_hide_advanced_search_form(id_div, value, url, from_name, page_name, search_opt, id_p)
{
	var obj = document.getElementById(id_div);
	obj.style.visibility = 'hidden';
    checked_selected_data(id_div, value, url, from_name, page_name, search_opt);
}


// this function show advance form (advance select option)
//@param id_div this is a id of div where will be a new select option
//@param url this is a given url
//@param page is a option on which page we searched the data (student or teacher)
//@param empty_session this is a flag of session
//@param search a otpion of searching
//@session_opt_search_adv this is a option on which choosen a search option (is a session value)
function show_advanced_form(id_div, form_name, results_db_adv, url, page, empty_session, search, session_opt_search_adv)
{
	var obj ="";
	var id_sel=new Array();

	for(var i=0; i<results_db_adv.length; i++)
	{
		if(results_db_adv[i][0])
		{
			obj +="<p id='form'>"+results_db_adv[i][1]+"</p>";
			obj +="<input type='hidden' name='select_key[]' value='"+results_db_adv[i][0]+"' />";
			obj +="<input type='hidden' name='select_default[]' value='"+results_db_adv[i][2]+"' />";
			
			obj +="<select id='"+results_db_adv[i][0]+"' name='select"+results_db_adv[i][0]+"' onchange='selected_lesson_option(\""+results_db_adv[i][0]+"\", this.value, \""+url+"\", \""+form_name+"\", \""+page+"\", \"true\", \""+search+"\");' class='select_background'>";
				if(results_db_adv[i][3])
				{
					obj +="<option value='All' class='select_search_default'>"+results_db_adv[i][2]+"</option>";

					for(var j=0; j<results_db_adv[i][3].length;j++)
					{
						if(results_db_adv[i][3][j])
						{
							if(results_db_adv[i][3][j][0])
							{
								if(results_db_adv[i][3][j-1][1]!=results_db_adv[i][3][j][1])
								{
									obj +="<option value='mainop_"+results_db_adv[i][3][j][0]+"' class='select_search_main'>"+results_db_adv[i][3][j][1]+"</option>";
								}
								obj +="<option value='opt_"+results_db_adv[i][3][j][2]+"' class='select_search'>"+results_db_adv[i][3][j][3]+"</option>";
							}
							else
							{
								if(results_db_adv[i][3][j][3])
									obj +="<option value='opt_"+results_db_adv[i][3][j][2]+"' class='select_search_main'>"+results_db_adv[i][3][j][3]+"</option>";
								else
									id_sel[i]=results_db_adv[i][0];
							}
						}
					}
				}
			obj +="</select>";
		}
	}

    var ocomment = document.getElementById(id_div);
    ocomment.innerHTML=obj;
    ocomment.style.visibility = 'visible';

    for(var j=0; j<results_db_adv.length;j++)
    {
    	if(id_sel[j])
		{
			var oselect = document.getElementById(id_sel[j]);
			oselect.disabled=true;
		}
    }

    var obj_adv = document.getElementById('advance');
	obj_adv.style.visibility = 'hidden';

	if(session_opt_search_adv==true)
		var obj_normal="<p id='link_adv_hide' class='link' onclick='show_hide_advanced_search_form(\"sel_"+form_name+"\", \"value\", \"searchAdvanced.php\", \""+form_name+"\", \""+page+"\", \"normal\", \"advanced\");' onmouseout='change_class(this.id, \"link\");' onmouseover='change_class(this.id, \"link_active\");'>Hide advanced</p>";
	else
		var obj_normal="<p id='link_adv' class='link' onclick='show_hide_advanced_search_form(\"sel_"+form_name+"\", \"value\", \"searchAdvanced.php\", \""+form_name+"\", \""+page+"\", \"advanced\", \"advanced\");' onmouseout='change_class(this.id, \"link\");' onmouseover='change_class(this.id, \"link_active\");'>Advanced</p>";
	obj_adv.innerHTML=obj_normal;
    obj_adv.style.visibility = 'visible';
}

//function display a description of word (word in glossary)
//@param object is a object of this current word on which we want to display a description
//@param type is a flag (1,0) to show or hide a description
//@e is a event
function dymek(object,type, e){
    e = (!e) ? window.event : e;

	if(typeof( e.pageX ) == 'number')
	{
		var posX=e.pageX;
		var posY=e.pageY;

		//var no = Math.floor(posX/100);
		posX -= naviPosX();
	}
	else if( typeof( e.clientX ) == 'number')
	{
		var posX=e.clientX;
		var posY=e.clientY;

		//var no = Math.floor(posX/100);
		posX -= naviPosX();

		var OldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
						( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
     					( navigator.vendor == 'KDE' );

	    if( !OldBrowser ) {
	      if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	        //IE 4, 5 & 6 (in non-standards compliant mode)
	        posX += document.body.scrollLeft;
	        posY += document.body.scrollTop;
	      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	        //IE 6 (in standards compliant mode)
	        posX += document.documentElement.scrollLeft;
	        posY += document.documentElement.scrollTop;
	      }
	    }
	}
    object.parentNode.lastChild.style.title='';
    object.parentNode.lastChild.style.position='absolute';
    object.parentNode.lastChild.style.left=posX+'px';
    object.parentNode.lastChild.style.top=15+posY+'px';
    object.parentNode.lastChild.style.display=type?'block':'none';

}

function naviPosX() {
  var winWidth = 1259;
  var myWidth = 0;
  var navi = 170;
  var newNavi=0;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }

  if(winWidth<myWidth) {
  	newNavi = Math.round((myWidth*navi)/winWidth + 4) + navi;
  }
  else if(winWidth>myWidth) {
  	newNavi = navi - Math.round((myWidth*navi)/winWidth + 4);
  }
  else {
  	newNavi = navi;
  }
  return newNavi;
}

//function draw description of current word
//@param lsn is a Lsn_GUID a current lesson
//@param div_id is a id of div in which we want to show a description
//@param description_public is a description of current word
function drawGlossary(lsn, div_id, description_public )
{
	var obj ="<table><tr><td class='td2'><p id='tab_opt'>"+description_public+"</p></tr></td></table>";

	globalObject+=obj;
	var ocomment = document.getElementById(div_id);

	ocomment.innerHTML=globalObject;
}

//this function change worksheet page (png page)
//@param url is a url of file which read a img
//@param id_img is a id of worksheet page image
//@param page_no is a current number of page
//@param id_navi_block is a id of onclicked navigation arrow
//@param total_no_page is a total number of png page
function changePageWrk(url, id_img, page_no, id_navi_block, total_no_pages, wrk_guid) {
	var id_p='id_p_blad';
	var div_preloader= 'preloader';
	
	//show_div_preloader(div_preloader, id_p, 'loading...');
	
	var total_pages=total_no_pages;
	total_pages--;
	var oelem = '';
	var page_no_tmp_pr=page_no;
	var page_no_tmp_nt=page_no;
	oelem=document.getElementById(id_img);
	var url ='readImage.php?wrk_guid='+wrk_guid+'&pno='+page_no;
	oelem.src=url;
	
	var obj_navi_block=document.getElementById(id_navi_block);

	if(id_navi_block=='next' || id_navi_block=='next_s') {
		page_no_tmp_nt++;
		obj_navi_block.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_nt, id_navi_block, total_no_pages, wrk_guid); };

		if(id_navi_block=='next') {
			var obj_navi_block2=document.getElementById('next_s');
			obj_navi_block2.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_nt, 'next_s', total_no_pages, wrk_guid); };
		} else {
			var obj_navi_block2=document.getElementById('next');
			obj_navi_block2.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_nt, 'next', total_no_pages, wrk_guid); };
		}

		page_no_tmp_pr--;
		var obj_navi_block_previous=document.getElementById('previous');
		obj_navi_block_previous.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_pr, 'previous', total_no_pages, wrk_guid); };
		var obj_navi_block_previous2=document.getElementById('previous_s');
		obj_navi_block_previous2.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_pr, 'previous_s', total_no_pages, wrk_guid); };


		if(page_no!=0) {
			obj_navi_block_previous.className = 'cl_visible';
			obj_navi_block_previous2.className = 'cl_visible';
		} else {
			obj_navi_block_previous.className = 'cl_hidden';
			obj_navi_block_previous2.className = 'cl_hidden';
		}

		if(page_no!=total_pages) {
			obj_navi_block.className = 'cl_visible';
			obj_navi_block2.className = 'cl_visible';
		} else {
			obj_navi_block.className = 'cl_hidden';
			obj_navi_block2.className = 'cl_hidden';
		}
	}

	if(id_navi_block=='previous' || id_navi_block=='previous_s') {
		page_no_tmp_pr--;
		obj_navi_block.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_pr, id_navi_block, total_no_pages, wrk_guid); };

		if(id_navi_block=='previous') {
			var obj_navi_block2=document.getElementById('previous_s');
			obj_navi_block2.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_pr, 'previous_s', total_no_pages, wrk_guid); };
		} else {
			var obj_navi_block2=document.getElementById('previous');
			obj_navi_block2.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_pr, 'previous_s', total_no_pages, wrk_guid); };
		}


		if(page_no!=0) {
			obj_navi_block.className = 'cl_visible';
			obj_navi_block2.className = 'cl_visible';
		} else {
			obj_navi_block.className = 'cl_hidden';
			obj_navi_block2.className = 'cl_hidden';
		}

		page_no_tmp_nt++;
		var obj_navi_block_next=document.getElementById('next');
		obj_navi_block_next.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_nt, 'next', total_no_pages, wrk_guid); };
		var obj_navi_block_next2=document.getElementById('next_s');
		obj_navi_block_next2.onclick = function(){ changePageWrk(url, id_img, page_no_tmp_nt, 'next_s', total_no_pages, wrk_guid); };


		if(page_no!=total_pages) {
			obj_navi_block_next.className = 'cl_visible';
			obj_navi_block_next2.className = 'cl_visible';
		} else {
			obj_navi_block_next.className = 'cl_hidden';
			obj_navi_block_next2.className = 'cl_hidden';
		}
	}
	//alert('tutaj');
	//hide_div_preloader(div_preloader);
}

/*
function drawAcceptComment(div_id, div_id_parent, comment, up_code_public)
{
	removeDiv(div_id, div_id_parent);
	var obj ="<div id='comment'><h4 class='h4'>"+comment+"</h4></div>";

	var ocomment = document.getElementById(div_id_parent);
	ocomment.innerHTML=obj;

	change_up_code_public(up_code_public);
}

function change_up_code_public(up_code_public)
{
	removeDiv('up_code_public', 'lesson_inner');
	var obj ="<div><h4>"+up_code_public+"</h4></div>";
	var ocomment = document.getElementById('lesson_inner');
	ocomment.innerHTML=obj;
}
*/

function removeObj(div_id, div_id_parent)
{
	//alert('div_id: '+div_id+' div_id_parent: '+div_id_parent);
 	obj_div_id=document.getElementById(div_id);
 	obj_div_id_parent=document.getElementById(div_id_parent);
 	obj_div_id_parent.removeChild(obj_div_id);
}

function addObj(id, obj) {
	var oelement = document.getElementById(id);
	oelement.innerHTML=obj;
}

function change_total_cost(id, cost_id, costvalue_id, input_id, price)
{
	var o_id = document.getElementById(id);
	var o_cost = document.getElementById(cost_id);
	var o_input_id = document.getElementById(input_id);
	o_input_id.value = o_id.value;

	removeObj(costvalue_id, cost_id);

	var total_amount = o_id.value*price;
	var obj ="<span id="+costvalue_id+">"+total_amount+"</h4></div>";
	o_cost.innerHTML=obj;
}

function changeFormAction(id_form, obj_value, new_action_value)
{
	var o_id_form = document.getElementById(id_form);

	o_id_form.action = new_action_value;
}

function changeLesson(param)
{
	var url=parent.location+'&usp_changed='+param;

	changeWindow(url);
}

function drawErrorComment(div_id, results_description, class_name)
{
	var obj ="<h4 id='res_comment' class='"+class_name+"'>"+results_description+"</h4>";
	var ocomment = document.getElementById(div_id);
	ocomment.innerHTML=obj;
}

function removeElement(div_id, div_id_parent) {
 	obj_div_id=document.getElementById(div_id);
 	obj_div_id_parent=document.getElementById(div_id_parent);
 	obj_div_id_parent.style.height = '0';
 	obj_div_id_parent.style.visibility = 'hidden';
 	obj_div_id_parent.removeChild(obj_div_id);
}

//this function creates a new js object, the needed value is drawn from php file
//url is a url of php
//another_param_to_url is an another param to added to url
//switchdiv bool value
//hideDiv bool value
function jsConnect2(url, div_id, div_id_parent, param, another_param_to_url, switchdiv, hideDiv) {
	var oelem = '';
	var elemetByName;
	var newUrl=getUrl2(url, div_id, param, another_param_to_url);
	
	oelem=document.createElement('script')
	oelem.setAttribute("type","text/javascript");
	oelem.setAttribute("src", newUrl);
	document.getElementById(div_id).appendChild(oelem);
	
 	if(switchdiv) {
 		//showremoveElement(div_id, div_id_action);
 	}
 	if(hideDiv) {
 		removeElement(div_id, div_id_parent);
 	}
}

//this function returns a new created a url
function getUrl2(url, div_id, param, another_param_to_url)
{
	var newUrl=url+'?'+param+'&div='+div_id;

	if(another_param_to_url!='empty') {
		newUrl+=another_param_to_url;
	}
	return newUrl;
}

function htmlspecialchars(p_string) {
	//p_string = p_string.replace(/&/g, '&amp;');
	//p_string = p_string.replace(/</g, '&lt;');
	//p_string = p_string.replace(/>/g, '&gt;');
	p_string = p_string.replace(/"/g, '&quot;');
	p_string = p_string.replace(/'/g, '&#039;');
	return p_string;
}

function change_gap(id_parent, value, option, value_tmp) {
	var element = '';
	var idp = htmlspecialchars (id_parent);
	var vv = htmlspecialchars (value);
	
	if(option=='add') {
		element = "<span onclick='change_gap(\""+idp+"\", \""+vv+"\", \"del\", \""+value_tmp+"\");' class='p_pointer'>"+vv+"</span>";
	} else {
		element = "<span onclick='change_gap(\""+idp+"\", \""+vv+"\", \"add\", \""+value_tmp+"\");' class='p_pointer'>"+value_tmp+"</span>";
	}
	
	addObj(id_parent, element);		
}

function change_gap_answer(id_answer, gaps_array, option, id_img) {
	var element = '';
	var idp = '';
	var vv = '';
	var opction_tmp ='';
	var opt_action= 'del';
	var img_obj = '';
	
	if(option == 'show') {	
		opction_tmp = 'hide';
		var img_obj = document.getElementById(id_img);
		//img_obj.src='images/active_c_play.png';
		activePlayButton(id_img);
		if(img_obj != null) {
			img_obj.name='active';
			img_obj.className = 'padding_right p_pointer';
		}
	} else { 
		opction_tmp = 'show'; opt_action='add';
		var img_obj = document.getElementById(id_img);
		//img_obj.src='images/c_play.png';
		deactivePlayButton(id_img);
		if(img_obj != null) {
			img_obj.name='deactive';
			img_obj.className = 'padding_right p_text';
		}
	}
	
	for(i=0; i<gaps_array.length; i++) {
		idp = htmlspecialchars (gaps_array[i][0]);
		if(option == 'show') {
			vv = htmlspecialchars (gaps_array[i][1]);
		} else {
			vv = htmlspecialchars (gaps_array[i][2]);
		}
		vv2 = htmlspecialchars (gaps_array[i][1]);
		element = "<span onclick='change_gap(\""+idp+"\", \""+vv2+"\", \""+opt_action+"\", \""+gaps_array[i][2]+"\");' class='p_pointer'>"+vv+"</span>";

		addObj(gaps_array[i][0], element);
	}
		
	var obj_current_id_answer = document.getElementById(id_answer);
	obj_current_id_answer.onclick = function(){ change_gap_answer(id_answer, gaps_array, opction_tmp, id_img); };
}

function show_hide_option(current_id, action_div_id, action_div_name, option) {
	
	if(option == 'show') {
		setCssStyle(action_div_id, false, false, false, false, false, false, 'inline' ,false, false, 'display');
		
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'hide'); };
	} else if(option == 'hide') {
		setCssStyle(action_div_id, false, false, false, false, false, false, 'none' , false, false, 'display_none'); 
		
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'show'); };
	} else if(option == 'showscript') {
		change_display_by_name(action_div_name, 'inline');
		
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'hidescript'); };
	} else if(option == 'hidescript') {
		change_display_by_name(action_div_name, 'none');
		
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'showscript'); };
	} else if(option == 'showall') {
		change_display_by_name(action_div_name, 'inline');
		
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'hideall'); };
		
	} else if(option == 'hideall') {
		change_display_by_name(action_div_name, 'none');
		
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'showall'); };
	} else if(option == 'showall_glossary') {
		//change_display_by_name(action_div_name, 'inline');
		change_glossary_image('minus.gif', 'gls_image', 'showall_glossary');
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'hideall_glossary'); };
		
	} else if(option == 'hideall_glossary') {
		//change_display_by_name(action_div_name, 'none');
		change_glossary_image('plus.gif', 'gls_image', 'hideall_glossary');
		var obj_current_id = document.getElementById(current_id);
		obj_current_id.onclick = function(){ show_hide_option(current_id, action_div_id, action_div_name, 'showall_glossary'); };
	}
}

function change_display_by_name(div_name, display_opt) {
	var elem_obj=document.getElementsByName(div_name);

	for(var i=0;i<elem_obj.length;i++) {
		elem_obj[i].style.display = display_opt;
	}
}

function playSound(surl, id) {
	var img_id = 'img_'+id;
	var img_name = document.getElementById(img_id).name;
	if(img_name=='active') {
		var elem = '<img id="'+img_id+'" name="'+img_name+'" alt="play" src="images/active_c_stop.png" onclick="stopSound(\''+surl+'\', \''+id+'\')" class="p_pointer padding_right" />';
		elem += '<embed src="'+surl+'" hidden=true autostart=true loop=false>';
		
		var ocomment = document.getElementById(id);
		ocomment.innerHTML=elem;
	}
}
function stopSound(surl, id) {
	var img_id = 'img_'+id;
	var img_name = document.getElementById(img_id).name;
	
	if(img_name=='active') {
		var elem = '<img id="'+img_id+'" name="'+img_name+'" alt="stop" src="images/active_c_play.png" onclick="playSound(\''+surl+'\', \''+id+'\')" class="p_pointer padding_right" />';
		elem += '<embed src="'+surl+'" hidden=true autostart=false loop=false>';
		
		var ocomment = document.getElementById(id);
		ocomment.innerHTML=elem;
	}
}

function activePlayButton(id) {
	var flashMovie=getFlashMovieObject(id);
	if(flashMovie != undefined && flashMovie.activeCallBack != undefined) {
		flashMovie.activeCallBack();
	}
}


function deactivePlayButton(id) {
	var flashMovie=getFlashMovieObject(id);
	if(flashMovie != undefined && flashMovie.deactiveCallBack != undefined) {
		flashMovie.deactiveCallBack();
	}
}

function stopPlayButton(id) {
	var flashMovie=getFlashMovieObject(id);
	if(flashMovie != undefined && flashMovie.stopCallBack != undefined) {
		//alert('stopPlayButton2');
		flashMovie.stopCallBack();
	}
}

function playOrStop(id) {
	if(playButtonID == null) {
		playButtonID = id;
	} else if(playButtonID == id) {
		//nothing 
	}
	else {
		stopPlayButton(playButtonID);
		playButtonID = id;
	}
}

function getFlashMovieObject(movieName)
{
	  if (window.document[movieName]) 
	  {
		  return window.document[movieName];
	  }
	  if (navigator.appName.indexOf("Microsoft Internet")==-1)
	  {
		  if (document.embeds && document.embeds[movieName])
			  return document.embeds[movieName]; 
	  }
	  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	  {
		  return document.getElementById(movieName);
	  }
}

function showTextGlossary(div_id, div_id_action) {

	var oelem = '';
	var elemetByName;
	
    if(switchdiv[div_id]==false || switchdiv[div_id]=='' || !switchdiv[div_id]) {
		switchdiv[div_id]= true;
        showDiv(div_id, div_id_action);

    } else {
    	switchdiv[div_id]= false;
		hideDiv(div_id, div_id_action);
    }
	
}

function change_glossary_image(image_file, image_name, action) {
	var elem_obj=document.getElementsByName(image_name);
	var id='';
	
	for(var i=0;i<elem_obj.length;i++) {
		var tmp_id = elem_obj[i].id;
		id=tmp_id.slice(3,tmp_id.length);
		
		if(action == 'hideall_glossary') {
			switchdiv[tmp_id]= false;
			hideDiv('glossary_'+id, tmp_id);
		} else {
			switchdiv[tmp_id]= true;
			showDiv('glossary_'+id, tmp_id);
		}
	}

}

/**
 * this function sort searched lessons by option (e.g. ShortName, LessonTitle, Created) and show in the page in tag div
 */
function lesson_sort_by(current_obj, div_parent, div_to_replace, page, mode, goBack, url_page) {
	
	var oelem=document.createElement("script");
    oelem.src='lessonsSortBy.php?sort_id='+current_obj.id+'&sort_value='+current_obj.value+'&page='+page+'&div_parent='+div_parent+'&div_to_replace='+div_to_replace+'&mode='+mode+'&goBack='+goBack+'&url_page='+url_page;
    oelem.type="text/javascript";
        
    var elemetByName =document.getElementById(div_to_replace);
	elemetByName.appendChild(oelem);
	globalObject='';	
}

function show_html_lessons_inner(sort_id, div_to_replace, div_parent, obj_html, page, mode, goBack) {
	var div_navi_block_parent= 'navi_block_parent';
	var div_navi_block= 'navi_block';
	var img_arrow_id = 'img_order';
	var img_arrow_id_parent = 'img_order_parent';
	
	if(document.getElementById(img_arrow_id)) {
		if(mode == 'SORT_ASC') {			
			removeElement(img_arrow_id, img_arrow_id_parent);			
			var elem = '<img id="'+img_arrow_id+'" alt="images" title="ASC" name="order" src="images/up_arrow.png" onclick="lesson_sort_by_order(\''+sort_id+'\', \''+div_to_replace+'\', \''+div_parent+'\', \''+page+'\', \'SORT_DESC\', \''+goBack+'\');" class="p_pointer padding_top_small2" />';
			var ocomment = document.getElementById(img_arrow_id_parent);
			ocomment.innerHTML=elem;
		} else {			
			removeElement(img_arrow_id, img_arrow_id_parent);
			var elem = '<img id="'+img_arrow_id+'" alt="images" title="DESC" name="order" src="images/down_arrow.png" onclick="lesson_sort_by_order(\''+sort_id+'\', \''+div_to_replace+'\', \''+div_parent+'\', \''+page+'\', \'SORT_ASC\', \''+goBack+'\');" class="p_pointer padding_top_small2" />';
			var ocomment = document.getElementById(img_arrow_id_parent);
			ocomment.innerHTML=elem;
		}
	}
	
	removeElement(div_to_replace, div_parent);
	if(document.getElementById(div_navi_block)) {
		removeElement(div_navi_block, div_navi_block_parent);
	}
	
	addObj(div_parent, obj_html);
}


function lesson_sort_by_order(select_sort_id, div_to_replace, div_parent, page, mode, goBack) {
	var obj_sort = document.getElementById(select_sort_id);
	var oelem=document.createElement("script");
    oelem.src='lessonsSortBy.php?sort_id='+select_sort_id+'&sort_value='+obj_sort.value+'&page='+page+'&div_parent='+div_parent+'&div_to_replace='+div_to_replace+'&mode='+mode+'&goBack='+goBack;
    oelem.type="text/javascript";
    
    var elemetByName =document.getElementById(div_to_replace);
	elemetByName.appendChild(oelem);
	globalObject='';	
}


function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;

}

function changeSrcElement(obj, new_src) {
	obj.src=new_src;
	return true;
}


function fb_init() {
   FB.init({
	     appId  : '205606872815256',
     status : true, // check login status
     cookie : true, // enable cookies to allow the server to access the session
     xfbml  : true  // parse XFBML
   });
}

function manageStar(obj, option, img_name, star_no) {
	var star_id = 'star_';
	for(var i=1;i<=star_no;i++) {
		var elemetById = document.getElementById(star_id+i);
		changeSrcElement(elemetById, img_name);
	}
	
}

//this function changes a window url
//@param url is a url which we want to load
function changeUrl(url)
{
	try {
		window.top.location.href=url;
 	} catch(e) {
		//nothing here
	}
}

function showAddingRateComponent(id, lsn_guid, prf_guid, user_rate, lrt_guid) {
	var param = 'lsn='+lsn_guid+'&prf='+prf_guid+'&lrt='+lrt_guid+'&rate';		
	
	var elem = '<div id="star_js"></div><div id="star_component"><ul class="star_component2"> ';
	elem +=	'<li><img id="star_1" src="'; if(user_rate < 1) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" onmouseover="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', 1);" onmouseout="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', \''+user_rate+'\');" class="p_pointer" onclick="loadobjs(\'addLessonRate.php\', \''+id+'\', \''+param+'=1\', \''+false+'\');" /></li>';
	elem +=	'<li><img id="star_2" src="'; if(user_rate < 2) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" onmouseover="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', 2);" onmouseout="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', \''+user_rate+'\');" class="p_pointer" onclick="loadobjs(\'addLessonRate.php\', \''+id+'\', \''+param+'=2\', \''+false+'\');" /></li>';
	elem +=	'<li><img id="star_3" src="'; if(user_rate < 3) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" onmouseover="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', 3);" onmouseout="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', \''+user_rate+'\');" class="p_pointer" onclick="loadobjs(\'addLessonRate.php\', \''+id+'\', \''+param+'=3\', \''+false+'\');" /></li>';
	elem +=	'<li><img id="star_4" src="'; if(user_rate < 4) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" onmouseover="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', 4);" onmouseout="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', \''+user_rate+'\');" class="p_pointer" onclick="loadobjs(\'addLessonRate.php\', \''+id+'\', \''+param+'=4\', \''+false+'\');" /></li>';
	elem +=	'<li><img id="star_5" src="'; if(user_rate < 5) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" onmouseover="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', 5);" onmouseout="manageStar(this, \'clear\', \'images/star_empty.png\', 5); manageStar(this, \'mark\', \'images/star_marked.png\', \''+user_rate+'\');" class="p_pointer" onclick="loadobjs(\'addLessonRate.php\', \''+id+'\', \''+param+'=5\', \''+false+'\');" /></li>';
	elem +=	'</ul></div>';
		
	var ocomment = document.getElementById(id);
	ocomment.innerHTML=elem;
}

function showTxt(text, class_name, id_name, div_id) {
	var elem ='<div id="'+id_name+'" class="'+class_name+'">'+text+'</div>';

	var ocomment = document.getElementById(div_id);
	ocomment.innerHTML=elem;
}

function showLessonRateComponent(div_id, rate_txt_header, rate_txt_footer, AverageRate) {
	var elem ='<div>'+rate_txt_header+'</div>';
		elem +='<div id="lesson_rate_show_component" class="padding_small">';
		elem +='<div class="float_left no_summary"><div id="average_rate">'+AverageRate+'</div></div>';
		elem +='<div class="float_left padding_left">';
		elem +='<ul class="star_component2">';
		elem +=	'<li><img id="star0_1" src="'; if(AverageRate < 1) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" /></li>';
		elem +=	'<li><img id="star0_2" src="'; if(AverageRate < 2) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" /></li>';
		elem +=	'<li><img id="star0_3" src="'; if(AverageRate < 3) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" /></li>';
		elem +=	'<li><img id="star0_4" src="'; if(AverageRate < 4) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" /></li>';
		elem +=	'<li><img id="star0_5" src="'; if(AverageRate < 5) { elem +='images/star_empty.png'; }else{ elem +='images/star_marked.png';} elem +='" /></li>';
		elem +='</ul></div>';
		elem +='<div class="clear"></div></div>';
		elem +='<div class="padding_top_small2">';
		elem +='<div id="no_of_votes">'+rate_txt_footer+'</div></div>';
		
		var ocomment = document.getElementById(div_id);
		ocomment.innerHTML=elem;
}

function loadobjs(url, div_id, param, another_param_to_url){
	
	var newUrl=getUrl2(url, div_id, param, another_param_to_url);
		
	fileref=document.createElement('script')
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", newUrl);
	
	if (fileref!=""){
		document.getElementsByTagName("head").item(0).appendChild(fileref);
	}
}

function changeSubscriptionPrice(cur_obj, url, sub_no, prices, currency_prefix, option) {
	//alert('cur_obj: '+cur_obj.value+' sub_no: '+sub_no);
	var element_pkg='';
	var elemet_price = '';
	var price=0;
	var new_url = url+'?k='+sub_no;
	var elemet_valid = document.getElementById('valid_for_'+sub_no);
	
	for(var i=1;i<=prices.lenght;i++) {
		alert(prices.i.i);
	}
	
	if(option=='bulk') {
		elemet_price = document.getElementById('bulk_price_'+sub_no);
		element_pkg = document.getElementById('package_opt_'+sub_no);
		
		price = prices[elemet_valid.value][element_pkg.value];
		new_url += '&p='+element_pkg.value+'&v='+elemet_valid.value;
	} else {
		elemet_price = document.getElementById('price_'+sub_no);
		price = prices[elemet_valid.value];
		new_url +='&v='+elemet_valid.value;
	}
	
	//alert('elemet_valid: '+elemet_valid.value+' elemet_price: '+elemet_price);
	
	var elem = price+' '+currency_prefix;
	elemet_price.innerHTML=elem;
	
	var link_more = document.getElementById('link_more_'+sub_no);
	link_more.href = new_url;
}

function play_audio_pb(phre) {	
	var player = '<object type="application/x-shockwave-flash" data="audio/player.swf" id="audioplayer1" height="16" width="190">';
	player += '<param name="movie" value="/audio/player.swf">';
	player += '<param name="FlashVars" value="playerID=1&amp;autostart=yes&amp;soundFile=audioFile.php?phre=`'+phre+'`">';
	player += '<param name="quality" value="high">';
	player += '<param name="menu" value="false">';
	player += '<param name="wmode" value="transparent">';
	player += '</object>';

	var elemet_obj = document.getElementById('player_'+phre);
	elemet_obj.innerHTML=player;	
}

function showTBVideo(current_id, parent_id, param, width, height) {
	var video ='<div><iframe width="'+width+'" height="'+height+'" src="http://www.youtube.com/embed/'+param+'" frameborder="0" allowfullscreen></iframe><div>';
	
	var elemet_obj = document.getElementById(parent_id);
	elemet_obj.innerHTML=video;
}

function print_order_confirm(url, title) {
	windowHeight=800;
	windowWidth=600;
    scrWidth = 640;
    scrHeight = 480;

    if (window.screen) {
        scrWidth = top.screen.width;
        scrHeight = top.screen.height
    }

    posX = Math.round((scrWidth - windowWidth)/2);
    posY = Math.round((scrHeight - windowHeight)/2);

    s = new Date();
    win_name = s.getMinutes() + '_' + s.getSeconds();

    window.open(url, win_name, "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+windowWidth+",height="+windowHeight+",left="+posX+",top="+posY);

}

function setAudioObject(id_option_value_img, img_name, option_value, file_url, play_or_stop, lsn_guid) {
	var res = '<object id="'+id_option_value_img+'" name="'+img_name+'" class="img_play padding_right" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" height="18" width="16" align="top">';
		res += '<param name="movie" value="audio/Lingua_player.swf" />';
		res +=	'<param name="quality" value="high" />';
		res +=	'<param name="bgcolor" value="#869ca7" />';
		res +=	'<param name="allowScriptAccess" value="sameDomain" />';
		res +=	'<param name="play" value="true" />';
		res +=	'<param name="wmode" value="transparent" />';
		res +=	'<param name="flashVars" value="url='+file_url+'&filename='+option_value+'&lsn='+lsn_guid+'&initialize='+img_name+'&autoplay='+play_or_stop+'" />';
		res +=	'<embed class="img_play" name="'+id_option_value_img+'" src="audio/Lingua_player.swf" quality="high" height="18" width="16" align="justify" ';
		res +=		'swliveconnect="true"';
		res +=		'play="'+play_or_stop+'" ';
		res +=		'loop="false" ';
		res +=		'quality="high" ';
		res +=		'allowScriptAccess="sameDomain" ';
		res +=		'wmode="transparent" ';
		res +=		'flashVars="url='+file_url+'&filename='+option_value+'&lsn='+lsn_guid+'&initialize='+img_name+'&autoplay='+play_or_stop+'" ';
		res +=		'type="application/x-shockwave-flash" ';
		res +=		'pluginspage="http://www.adobe.com/go/getflashplayer"> ';
		res +=	'</embed> ';
		res +='</object>';
	
	var elemet_obj = document.getElementById('img_'+id_option_value_img);
		elemet_obj.innerHTML=res;
		
	if(play_or_stop) {
		//playButtonID = id_option_value_img;
		playOrStop(id_option_value_img);
	}
}

