	function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
	/**********************************************************************
		IN:
			NUM - the number to format
			decimalNum - the number of decimal places to format the number to
			bolLeadingZero - true / false - display a leading zero for
											numbers between -1 and 1
			bolParens - true / false - use parenthesis around negative numbers
			bolCommas - put commas as number separators.
	 
		RETVAL:
			The formatted number!
			
		EXAMPLE:
			FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,
	             UseParensForNegativeNumbers, GroupDigits)
	 **********************************************************************/
	{ 
		
	        if (isNaN(parseInt(num))) return "NaN";
	
		var tmpNum = num;
		var iSign = num < 0 ? -1 : 1;		// Get sign of number
		
		// Adjust number so only the specified number of numbers after
		// the decimal point are shown.
		tmpNum *= Math.pow(10,decimalNum);
		tmpNum = Math.round(Math.abs(tmpNum))
		tmpNum /= Math.pow(10,decimalNum);
		tmpNum *= iSign;					// Readjust for sign
		
		
		// Create a string object to do our formatting on
		var tmpNumStr = new String(tmpNum);
	
		// See if we need to strip out the leading zero or not.
		if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
			if (num > 0)
				tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
			else
				tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
			
		// See if we need to put in the commas
		if (bolCommas && (num >= 1000 || num <= -1000)) {
			var iStart = tmpNumStr.indexOf(".");
			if (iStart < 0)
				iStart = tmpNumStr.length;
	
			iStart -= 3;
			while (iStart >= 1) {
				tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
				iStart -= 3;
			}		
		}
	
		// See if we need to use parenthesis
		if (bolParens && num < 0)
			tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";
	
		return tmpNumStr;		// Return our formatted string!
	}

	
	
	function checkDate(dateStr){
		//Declaration
		var dateValue = new String(dateStr);
		var dateObj = new Date();
		var dateStr = new String();
		var monthStr = new String();
		var yearStr = new String();
		var dateInt = 0;
		var monthInt = 0;

		
		arr_date = 	dateValue.split('.');		
		dateStr = arr_date[0];		
		monthStr = arr_date[1];
		yearStr = arr_date[2];
		
		
		currDate = dateObj.getDate();
		currMonth = dateObj.getMonth() + 1;
		currYear = dateObj.getFullYear();
		
		//Add single chars zero 
		//Example: 1 -> 01
		if (currDate < 10) currDate = '0' + currDate;
		if (currMonth < 10) currMonth = '0' + currMonth;
		
		var today =  currDate + '.' +  currMonth + '.' + currYear;
		
		dateInt = dateStr;
		monthInt = monthStr;
		
		
		//Check Year
		if (yearStr == null){
			alert('���������� ������ �� ������ (��.��.����)!');
			return today;
		}
		
		
		//Check Date
		if (dateInt > 31) {
			alert('��������� ����!');
			return today;
		}
		
		//Check Month
		if (monthInt > 12) {
			alert('��������� ����!');
			return today;
		}
		
	
		
		//Check DateString Length
		if (dateValue.length != 10){
			alert('���������� ������ �� ������ (��.��.����)!');
			return today;
		}
	
		return dateValue;
		
	
	
	}
	
		function checkEmail(email_address, file) {
			if (file == ""){
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
					return (true)
				} else {
					alert("Invalid E-mail Address! Please re-enter.");
					return (false)
				}
			}
		}

		function checkUserForm(email_address, username, name) {
			if (username == ""){
				alert("Invalid username! Please re-enter.");
				return (false)
			}

			if (name == ""){
				alert("Invalid name! Please re-enter.");
				return (false)
			}

			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
				//return (true)
			} else {
				alert("Invalid E-mail Address! Please re-enter.");
				return (false)
			}
		}
	
		function changeLanguage() {
			document.form_lang.submit();
		}

		function relative_message() {
			if (f.member_relative_id.value > 0)
				if (confirm("������ �� �� ������� ������� � ������� �� ��������� �����?")) {
					f.member_image_url.disabled=true;
					f.relative.value='yes';
					submitForm();
					f.submit();
				} else f.relative.value='no';
		}
		
		var i = 1;
		var i1 = 1;
		var k = new Array();
                k[1] = 1;
		
		function br_onclick() {
			if (i<30) {
				j=i;
				i++;
				//alert (i);
				//eval("document.f.elements.userfile"+j).insertAdjacentHTML("AfterEnd","<br id=\"brid"+i+"\"><input type=\"file\" name=\"userfile"+i+"\" size=\"40\" class=\"inputtext\">");
				if (document.body&&document.body.insertAdjacentHTML) {
					//alert ("have to work");
					eval("document.f.elements.userfile"+j).insertAdjacentHTML("AfterEnd","<br id=\"brid"+i+"\"><input type=\"file\" name=\"userfile"+i+"\" size=\"40\" class=\"inputtext\">");
				} else {
					//alert ("haven't work");
				     if(document.createElement
				        && document.documentElement
				        && (window.opera||navigator.userAgent.indexOf('MSIE 5.0')==-1)) {
				         var file=document.createElement("input");
				         file.setAttribute('id','userfile'+i);
				         file.setAttribute('name','userfile'+i);
				         file.setAttribute('type','file');
				         file.setAttribute('class','inputtext');
				         file.setAttribute('size','40');
				         //file.style.position='absolute';
				         //file.style.width=ifr.style.height=ifr.borderWidth='0px';
				         txt = document.getElementById('userfile1');
				         //prn=document.getElementById("exmpl");
				         prn = txt.parentNode;
				         prn.appendChild(file);
				         //prn.insertAfter(txt, file); 
				         //document.getElementById('f').insertBefore(btn, file);
				         //iframe=document.getElementById('f').insertBefore(btn, file);
				         //iframe=document.getElementById('f').appendChild('<br>');
				         
					}
				}
				document.f.elements.urlcount.value=i;
				cf.innerHTML=document.f.elements.urlcount.value=i;

				//document.f.elements.urlcount.value=i;
				//alert (document.f.elements.urlcount.value);
			}
		}
		
		function bl_onclick() {
			if (i>1) {
				j=i;
				i--;
				cf.innerHTML=i;
				document.f.elements.urlcount.value=i;
			if (document.body&&document.body.insertAdjacentHTML) {
					eval("document.f.elements.userfile"+j+".outerHTML=\"\"");
					//alert (i);
					eval("brid"+j+".outerHTML=\"\"");
			} else {
				//alert(document.getElementById('userfile' + j));
				elem = document.getElementById('userfile' + j);
				prn = elem.parentNode;
				prn.removeChild(elem);
			}
			
			}
		}


	function phase_br_onclick(elname, num) {
			if (k[num]<30) {
				l=k[num];
				k[num]++;
				//alert (i);
				//eval("document.f.elements.userfile"+j).insertAdjacentHTML("AfterEnd","<br id=\"brid"+i+"\"><input type=\"file\" name=\"userfile"+i+"\" size=\"40\" class=\"inputtext\">");
				if (document.body&&document.body.insertAdjacentHTML) {
					//alert ("have to work");
					eval("document.f.elements." + elname + l).insertAdjacentHTML("AfterEnd","<br id=\"brid"+k[num]+"\"><input type=\"file\" name=\"" + elname + "[" + k[num] + "]\" size=\"40\" class=\"inputtext\">");
				} else {
					//alert ("haven't work");
				     if(document.createElement
				        && document.documentElement
				        && (window.opera||navigator.userAgent.indexOf('MSIE 5.0')==-1)) {
				         var file=document.createElement("input");
				         file.setAttribute('id','' + elname + "[" + num + "][" + k[num] + "]");
				         file.setAttribute('name','' + elname +"[" + num + "][" + k[num] + "]");
				         file.setAttribute('type','file');
				         file.setAttribute('class','inputtext');
				         file.setAttribute('size','40');
				         //file.style.position='absolute';
				         //file.style.width=ifr.style.height=ifr.borderWidth='0px';
				         txt = document.getElementById(elname + "[" + num + "][" + l + "]");
				         //prn=document.getElementById("exmpl");
				         prn = txt.parentNode;
				         prn.appendChild(file);
				         //prn.insertAfter(txt, file);
				         //document.getElementById('f').insertBefore(btn, file);
				         //iframe=document.getElementById('f').insertBefore(btn, file);
				         //iframe=document.getElementById('f').appendChild('<br>');

					}
				}
                                //document.f.elements.phaseurlcount[num].value=k;
                                document.getElementById('phaseurlcount[' + num + ']').value = k[num];
                                //cf.innerHTML=document.getElementById(elementId)
				//document.f.elements.urlcount.value=i;
				pcf.innerHTML=document.getElementById('phaseurlcount[' + num + ']').value=k[num];

				//document.f.elements.urlcount.value=i;
				//alert (document.f.elements.urlcount.value);
			}
		}

		function phase_bl_onclick(elname, num) {
			if (k[num]>1) {
				l=k[num];
				k[num]--;
				pcf.innerHTML=k[num];
				document.getElementById('phaseurlcount[' + num + ']').value=k[num];
			if (document.body&&document.body.insertAdjacentHTML) {
					eval("document.f.elements." + elname +"[" + num + "]" + "[" + l +"].outerHTML=\"\"");
					//alert (i);
					eval(elname + "brid"+l+".outerHTML=\"\"");
			} else {
				//alert(document.getElementById('userfile' + j));
				elem = document.getElementById('pdf1[' + num + '][' + l + ']');
				prn = elem.parentNode;
				prn.removeChild(elem);
			}

			}
		}




		function img_br_onclick() {
			if (i1<30) {
				j=i1;
				i1++;
				if (document.body&&document.body.insertAdjacentHTML) {
					eval("document.f.elements.imgfile"+j).insertAdjacentHTML("AfterEnd","<br id=\"brid"+i1+"\"><input type=\"file\" name=\"imgfile"+i1+"\" size=\"40\" class=\"inputtext\">");
				} else {
				     if(document.createElement
				        && document.documentElement
				        && (window.opera||navigator.userAgent.indexOf('MSIE 5.0')==-1)) {
				         var file=document.createElement("input");
				         file.setAttribute('id','imgfile'+i1);
				         file.setAttribute('name','imgfile'+i1);
				         file.setAttribute('type','file');
				         file.setAttribute('class','inputtext');
				         file.setAttribute('size','40');
				         //file.style.position='absolute';
				         //file.style.width=ifr.style.height=ifr.borderWidth='0px';
				         txt = document.getElementById('imgfile1');
				         //prn=document.getElementById("exmpl");
				         prn = txt.parentNode;
				         prn.appendChild(file);
				         //prn.insertAfter(txt, file); 
				         //document.getElementById('f').insertBefore(btn, file);
				         //iframe=document.getElementById('f').insertBefore(btn, file);
				         //iframe=document.getElementById('f').appendChild('<br>');
				         
					}					
				}
				document.f.elements.imgcount.value=i1;
				cf2.innerHTML=document.f.elements.imgcount.value;
				//alert (i);
			}
		}
		function img_bl_onclick() {
			if (i1>1) {
				j=i1;
				i1--;
				cf2.innerHTML=i1;
				document.f.elements.imgcount.value=i1;
			if (document.body&&document.body.insertAdjacentHTML) {
				eval("document.f.elements.imgfile"+j+".outerHTML=\"\"");
				//alert (i);
				eval("brid"+j+".outerHTML=\"\"");
			} else {
				//alert(document.getElementById('imgfile' + j) + j);
				elem = document.getElementById('imgfile' + j);
				prn = elem.parentNode;
				prn.removeChild(elem);
			}
			
		}
		}



                function addPhaseEvent() {
                    var ni = document.getElementById('phaseDiv');
                    var numi = document.getElementById('phaseCalculation');
                    var num = (document.getElementById('phaseCalculation').value -1) + 2;
                    numi.value = num;
                    var divIdName = "phase" + num + "Div";
                    var newdiv = document.createElement('div');
                    newdiv.setAttribute('id', divIdName);
                    var htmlText = "";

                    htmlText = "<fieldset><legend>Phase " + num + "</legend><table>";
                    htmlText = htmlText + "<tr>\n <td class=\"td_silver\"></td>\n <td class=\"td_silver\"><br><br></td>\n</tr>\n";
                    htmlText = htmlText + "<tr>\n<td class=\"td_silver\">Name</td>\n<td class=\"td_silver\"><input type=\"text\" name=\"phase_title[" + num + "]\" size=\"45\" maxlength=\"255\" class=\"inputtext\">\n</td>\n</tr>\n";
                    htmlText = htmlText + "<tr>\n<td class=\"td_silver\">Phase short description</td>\n<td class=\"td_silver\">\n";
                    htmlText = htmlText + "<textarea name=\"phase_short_description[" + num + "]\" style=\"width:99%;height:75px\" onkeypress=\"smsLettersLeft(this,'PhaseMsgLen[" + num + "]')\" onchange=\"smsLettersLeft(this,'PhaseMsgLen[" + num + "]')\" onkeyup=\"smsLettersLeft(this,'PhaseMsgLen[" + num + "]')\" onkeydown=\"smsLettersLeft(this,'PhaseMsgLen[" + num + "]')\" onblur=\"smsLettersLeft(this, 'PhaseMsgLen[" + num + "]')\" onfocus=\"smsLettersLeft(this, 'PhaseMsgLen[" + num + "]')\" ></textarea><br>";
                    htmlText = htmlText + "<input name=\"PhaseMsgLen[" + num + "]\" type=\"text\" id=\"PhaseMsgLen[" + num + "]\" value=500> Characters left</td>\n</tr>\n";
                    htmlText = htmlText + "<tr>\n<td class=\"td\" valign=\"top\" width=\"150\">Phase description </td>\n<td class=\"td\" valign=\"top\">\n";

                    htmlText = htmlText + "<textarea name=\"phase_description[" + num + "]\" id=\"phase_description[" + num + "]\" class=\"ckeditor\"></textarea>";
                    htmlText = htmlText + "<script>CKEDITOR.replace( 'phase_description[" + num + "]');</script>\n</td>\n</tr>";

                    //pics div
                    htmlText = htmlText + "<tr><td colspan = \"2\"><div name=\"PhasepicsDiv[" + num +  "]\" id=\"PhasepicsDiv[" + num +  "]\"><fieldset id=\"fieldset[" + num + "]\"><legend>Pictures</legend><table><tr><td>\n<input type=\"hidden\" id=\"theValuePhase[" + num + "]\" name=\"theValuePhase[" + num + "]\" value=\"1\">\n Picture :</td><td colspan=\"2\"><input type=\"file\" class=\"inputtext\" id=\"phase_pics[" + num + "][1]\" name=\"phase_pics[" + num + "][1]\"></td><td>&nbsp</td></tr>";
                    htmlText = htmlText + "<tr><td>Description: </td><td><input type=\"text\" name=\"phase_pics_description[" + num + "][1]\" class=\"inputtext\"></td>";
                    htmlText = htmlText + "<td></td></tr></div>\n</td></tr></table></fieldset><a href=\"javascript:;\" onClick=\"javascript:addFilePhaseEvent('fieldset', 'phase_pics', " + num + ", 'file', 'theValuePhase', true, 'Picture');\">Add</a>\n";
                    htmlText = htmlText + "</td></tr>";

                    //end pics div
                    // video div

                    htmlText = htmlText + "<tr><td colspan = \"2\"><div name=\"PhasevideoDiv[" + num +  "]\" id=\"PhasevideoDiv[" + num +  "]\"><fieldset id=\"fieldsetVideo[" + num + "]\"><legend>Video</legend><table><tr><td>\n<input type=\"hidden\" id=\"theValueVideoPhase[" + num + "]\" name=\"theValueVideoPhase[" + num + "]\" value=\"1\">\n Video:</td><td colspan=\"2\"><textarea id=\"phase_videos[" + num + "][1]\" name=\"phase_videos[" + num + "][1]\"></textarea></td>";

                    htmlText = htmlText + "<td class=\"td\" align=\"right\"></div>\n</td></tr></table></fieldset><a href=\"javascript:;\" onClick=\"javascript:addFilePhaseEvent('fieldsetVideo', 'phase_videos', " + num + ", 'textarea', 'theValueVideoPhase', false, 'Video' );\">Add</a>\n";
                    htmlText = htmlText + "</td></tr>";

                    //end video div
                    // pdf div


                    htmlText = htmlText + "<tr><td colspan = \"2\"><div name=\"PhasepdfDiv[" + num +  "]\" id=\"PhasepdfDiv[" + num +  "]\"><fieldset id=\"fieldsetPdf[" + num + "]\"><legend>Pdf</legend><table><tr><td>\n<input type=\"hidden\" id=\"theValuePdfPhase[" + num + "]\" name=\"theValuePdfPhase[" + num + "]\" value=\"1\">\n pdf:</td><td colspan=\"2\"><input type=\"file\" class=\"inputtext\" id=\"phase_pdf[" + num + "][1]\" name=\"phase_pdf[" + num + "][1]\"></td>";

                    htmlText = htmlText + "<td class=\"td\" align=\"right\"></div>\n</td></tr></table></fieldset><a href=\"javascript:;\" onClick=\"javascript:addFilePhaseEvent('fieldsetPdf', 'phase_pdf', " + num + ", 'file', 'theValuePdfPhase', false, 'PDF');\">Add</a>\n";
 
                    //end pdf div
                    // powerpoint div


                    htmlText = htmlText + "<tr><td colspan = \"2\"><div name=\"PhaseppDiv[" + num +  "]\" id=\"PhaseppDiv[" + num +  "]\"><fieldset id=\"fieldsetPp[" + num + "]\"><legend>Power Point</legend><table><tr><td>\n<input type=\"hidden\" id=\"theValuePpPhase[" + num + "]\" name=\"theValuePp[" + num + "]\" value=\"1\">\n Power Point:</td><td colspan=\"2\"><input type=\"file\" class=\"inputtext\" id=\"phase_pp[" + num + "][1]\" name=\"phase_pp[" + num + "][1]\"></td>";

                    htmlText = htmlText + "<td class=\"td\" align=\"right\"></div>\n</td></tr></table></fieldset><a href=\"javascript:;\" onClick=\"javascript:addFilePhaseEvent('fieldsetPp', 'phase_pp', " + num + ", 'file', 'theValuePpPhase', false, 'Power Point');\">Add</a>\n";
 
                    //end powerpoint div
                    // amount div


                    htmlText = htmlText + "<tr><td colspan = \"2\"><div name=\"PhaseamountDiv[" + num +  "]\" id=\"PhaseamountDiv[" + num +  "]\"><fieldset id=\"fieldsetAmount[" + num + "]\"><legend>Amount: </legend><table><tr><td>\n<input type=\"hidden\" id=\"theValueAmountPhase[" + num + "]\" name=\"theValueAmountPhase[" + num + "]\" value=\"1\">\n Amount: <input type=\"text\" class=\"inputtext\" id=\"phase_amount[" + num + "]\" name=\"phase_amount[" + num + "]\"></td></tr>";


                    //end amount div
                    // contributor div

                    htmlText = htmlText + "<tr><td colspan = \"2\"><div name=\"PhaseContributorsDiv[" + num +  "]\" id=\"PhaseContributorsDiv[" + num +  "]\"><fieldset id=\"fieldsetContributor[" + num + "]\"><legend>Contributors</legend><table><tr><td>\n<input type=\"hidden\" id=\"theValueContributorPhase[" + num + "]\" name=\"theValueContributorPhase[" + num + "]\" value=\"1\">\n Contributor:</td><td colspan=\"2\"><input type=\"text\" class=\"inputtext\" id=\"phase_contributor[" + num + "][1]\" name=\"phase_contributor[" + num + "][1]\"></td></tr>";

                    //for (i in lang_array) {
			htmlText = htmlText + "<tr><td> Description:</td><td><input type=\"text\" name=\"phase_contributor[" + num + "][1]\" class=\"inputtext\"></td>";
                    //}

                    htmlText = htmlText + "<td class=\"td\" align=\"right\"></div>\n</td></tr></table></fieldset>";
                    htmlText = htmlText + "</td></tr></table></fieldset><a href=\"javascript:;\" onClick=\"javascript:addFilePhaseEvent('fieldsetContributor', 'phase_contributor', " + num + ", 'text', 'theValueContributorPhase', true, 'Contributor');\">Add</a>\n";

                    //end contributor div

                    newdiv.innerHTML = htmlText;
                    ni.appendChild(newdiv);
                }

		function addFilePhaseEvent(divname, element, cnum, type, valueName, description, names) {
			//alert (lang_array);
			var ni = document.getElementById(divname + "[" + cnum + "]");
			var numi = document.getElementById(valueName + '[' + cnum +']');
			//alert (numi);
                        if (document.getElementById(valueName + '[' + cnum +']') != null) {
                            var num = (document.getElementById(valueName + '[' + cnum +']').value -1)+ 2;
                        }else {
                            num = 1;
                        }
			numi.value = num;
			var divIdName = divname + "[" + cnum + "][" + num + "]";
			var newdiv = document.createElement('table');
			newdiv.setAttribute("id",divIdName + "_table");
                        var htmlText = "";
                        if (type == 'file') {
                            htmlText = "<tr><td>"+ names +"</td><td colspan=\"2\"><input type=\"file\" class=\"inputtext\" id=\"" + element + "["+cnum+"][" + num + "]\" name=\"" + element + "["+cnum+"][" + num + "]\" /></td></tr>";//" + names[i]: + "
                        }

                        if (type == 'textarea') {
                            htmlText = "<tr><td>"+ names +"</td><td colspan=\"2\"><textarea class=\"inputtext\" id=\"" + element + "["+cnum+"][" + num + "]\" name=\"" + element + "["+cnum+"][" + num + "]\"></textarea></td></tr>";//" + names[i]: + "
                        }

                        if (type == 'text') {
                            htmlText = "<tr><td>"+ names +"</td><td colspan=\"2\"><input type=\"text\" class=\"inputtext\" id=\"" + element + "["+cnum+"][" + num + "]\" name=\"" + element + "["+cnum+"][" + num + "]\" /></td></tr>";//" + names[i]: + "

                        }

                        if (description) {
                            if (description === true) {
                                description = 'Description';
                            }
                            htmlText = htmlText + "<tr><td>" + description + ":</td><td><input type=\"text\" name=\""+ element +"_description[" +cnum + "][" + num + "]\" class=\"inputtext\"></td></tr>";
                        }
                          
			//newdiv.innerHTML = "Description:" + htmlText + "&nbsp;&nbsp;&nbsp;image:<input type=file class=inputtext id=\"" + element + "["+cnum+"][" + num + "]\" name=\"" + element + "["+cnum+"][" + num + "]\"> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove item;</a><hr>";
                        htmlText = htmlText + "<tr><td colspan=\"3\" align=\"right\"><a href=\"javascript:;\" onclick=\"removePhaseEvent(\'" + divname + "[" + cnum + "]\', '" + divIdName + "_table')\">Remove item;</a></td></tr>";
                        newdiv.innerHTML = htmlText;
			ni.appendChild(newdiv);
                        //ni.appendChild(htmlText);
		}

		function removePhaseEvent(divName, element){
			var d = document.getElementById(divName);
			var olddiv = document.getElementById(element);
                        //var olddiv = element;
			d.removeChild(olddiv);
		}


		function addFileProjectEvent(container, theValue, field, name, description, named) {
			var ni = document.getElementById(container);
			var numi = document.getElementById(theValue);
			//alert (numi);
			var num = (document.getElementById(theValue).value -1)+ 2;
			numi.value = num;
			var divIdName = "table_" +name + "_" + num;
			var newdiv = document.createElement('table');
			newdiv.setAttribute("id",divIdName);
			var htmlText = "";//" + names[i]: + "

                        
			if (field == "file"){
                            htmlText = htmlText + "<tr><td>" + named + " " + num + ":</td><td><input type=\"file\" name=\"" + name +"[" + num + "]\" class=\"inputtext\" /></td>";
			}
			if (field == "text"){
                            htmlText = htmlText + "<tr><td> " + named + " " + num + ":</td><td><input type=\"text\" name=\"" + name +"[" + num + "]\" class=\"inputtext\" /></td>";
			}
			if (field == "textarea"){
                            htmlText = htmlText + "<tr><td>" + named + " " + num + ":</td><td><textarea name=\"" + name +"[" + num + "]\" class=\"inputtext\" rows=\"10\" cols=\"50\"></textarea></td>";
			}

                        if (description) {
                            htmlText = htmlText + "</tr>";
                        }


                        if (description) {
                            htmlText = htmlText + "<tr><td>Description:</td><td><input type=\"text\" name=\"" + name +"_description[" + num + "]\" class=\"inputtext\"></textarea></td>";
                        }

			newdiv.innerHTML = htmlText + "<td><a href=\"javascript:;\" onclick=\"removeProjectEvent('" + container + "', '"+divIdName+"')\">Remove item</a></td></tr>";
			ni.appendChild(newdiv);
		}

                function removeProjectEvent(container ,divNum){
			var d = document.getElementById(container);
			var olddiv = document.getElementById(divNum);
			d.removeChild(olddiv);
		}


		function addFileEvent(lang_array, names) {
			//alert (lang_array);
			var ni = document.getElementById('myDiv');
			var numi = document.getElementById('theValue');
			//alert (numi);
			var num = (document.getElementById("theValue").value -1)+ 2;
			numi.value = num;
			var divIdName = "my"+num+"Div";
			var newdiv = document.createElement('div');
			newdiv.setAttribute("id",divIdName);
			var htmlText = "";//" + names[i]: + " 
			var i;
			for (i in lang_array) {
				htmlText = htmlText + "<br>" + names[i] + ":<input type=text name=divl_"+num+"_" + lang_array[i] + " class=inputtext>";
			}
			newdiv.innerHTML = "Description:" + htmlText + "&nbsp;&nbsp;&nbsp;image:<input type=file class=inputtext id=divr_"+num+" name=divr_"+num+"> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove item;</a><hr>";
			ni.appendChild(newdiv);
		}




		function addEvent(lang_array, names) {
			//alert (lang_array);
			var ni = document.getElementById('myDiv');
			var numi = document.getElementById('theValue');
			//alert (numi);
			var num = (document.getElementById("theValue").value -1)+ 2;
			numi.value = num;
			var divIdName = "my"+num+"Div";
			var newdiv = document.createElement('div');
			newdiv.setAttribute("id",divIdName);
			var htmlText = "";//" + names[i]: + " 
			var i;
			for (i in lang_array) {
				htmlText = htmlText + "<br>" + names[i] + ":<input type=text name=divl_"+num+"_" + lang_array[i] + " class=inputtext>";
				htmlText = htmlText + "<input type=hidden id=h1sum_" + num + " value=0>";
			}
			newdiv.innerHTML = "item:" + htmlText + "&nbsp;&nbsp;&nbsp;sum:<input type=text class=inputtext id=divr_"+num+" name=divr_"+num+" onchange='calculate(this, \"\h1sum_" + num + "\")'> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove item;</a><hr>";
			ni.appendChild(newdiv);
		}

		function removeEvent(divNum){
			var d = document.getElementById('myDiv');
			var olddiv = document.getElementById(divNum);
			d.removeChild(olddiv);
		}
		
		function calculate(el, id) {
			if (digitvalidation(el, 1, 9, "Please enter a digit", "")) {
				var numi = document.getElementById('theValue');
				var msum = 0; 
				if (id != "") {
					msum = document.getElementById(id).value;
					//alert (msum);
					document.getElementById(id).value = el.value;
				}
				//alert(numi.value);
				var total=document.getElementById('total');	
				//alert (total.value); 
				//alert ("element valu=" + el.value);
				total.value=Number(total.value) - Number(msum) + Number(el.value);	
			}
			else el.value = "0";
			el.focus();
		}

		function digitvalidation(entered, min, max, alertbox, datatype){
			// Digit Validation by Henrik Petersen / NetKontoret
			// Explained at www.echoecho.com/jsforms.htm
			// Please do not remove this line and the two lines above.
			with (entered){
				checkvalue=parseFloat(value);
				if (datatype){
					smalldatatype=datatype.toLowerCase();
					if (smalldatatype.charAt(0)=="i") {
						checkvalue=parseInt(value); 
						if (value.indexOf(".")!=-1) {
							checkvalue=checkvalue+1
						}
					};
				}
				if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue){
					if (alertbox!="") {
						alert(alertbox);
					} return false;}
				else {return true;}
			}
		} 

