function show_comment_form() {
	 $("div#comment_form").animate({
	   height: 'toggle', opacity: 'toggle'
	 }, "slow");
}

function check_comment() {
	if(document.Comment.post_content.value == "") {
		mesaj="Comment is required!\n";
		alert(mesaj);
	}	
	else {
		document.Comment.submit();
	}
}



// JavaScript Document
var xPos;
var yPos;

//offsety si x
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showToolTip(title,msg,evt){
    if (evt) {
        var url = evt.target;
    }
    else {
        evt = window.event;
        var url = evt.srcElement;
    }
    xPos = evt.clientX;
    yPos = evt.clientY+ietruebody().scrollTop;
   
   var toolTip = document.getElementById("toolTip");
   toolTip.innerHTML = "<div style=\"font-size:11px;\"><b>"+title+"</b><br/>"+msg+"</div>";
   toolTip.style.top = parseInt(yPos)+50 + "px";
   toolTip.style.left = parseInt(xPos)+2 + "px";
   toolTip.style.visibility = "visible";
   
}

function hideToolTip(){
   var toolTip = document.getElementById("toolTip");
   toolTip.style.visibility = "hidden";
}


function showMenu(id) {
	document.getElementById(id).style.display = 'block';
	}

function hideMenu(id) {
	document.getElementById(id).style.display = 'none';
	}
function hideMenuSelectat(id) {
	document.getElementById(id).style.display = 'none';
	}

		function ceva(id) {
			if(id == "id1") {
				document.getElementById('id1').style.display = "none";
				document.getElementById('id2').style.display = "block";
				document.getElementById('id2').style.backgroundPosition = "bottom";
				document.getElementById('id3').style.display = "block";
				document.getElementById('id3').style.backgroundPosition = "bottom";
				document.getElementById('id4').style.backgroundPosition = "bottom";
				document.getElementById('id4').style.display = "block";
				document.getElementById('id5').style.display = "block";
				
				document.getElementById('id1').style.zIndex = "1000";
				document.getElementById('id2').style.zIndex = "900";
				document.getElementById('id3').style.zIndex = "800";
				document.getElementById('id4').style.zIndex = "700";
				document.getElementById('id5').style.zIndex = "699";
			}
			else if(id == "id2") {
				document.getElementById('id1').style.display = "block";
				document.getElementById('id2').style.display = "none";
				document.getElementById('id3').style.display = "block";
				document.getElementById('id3').style.backgroundPosition = "bottom";
				document.getElementById('id4').style.display = "block";
				document.getElementById('id5').style.display = "block";
				
				document.getElementById('id1').style.zIndex = "900";
				document.getElementById('id2').style.zIndex = "1000";
				document.getElementById('id3').style.zIndex = "800";
				document.getElementById('id4').style.zIndex = "700";
				
			}
			else if(id == "id3") {
				document.getElementById('id1').style.display = "block";
				document.getElementById('id2').style.display = "block";
				document.getElementById('id2').style.backgroundPosition = "top";
				document.getElementById('id3').style.display = "none";
				document.getElementById('id4').style.display = "block";
				document.getElementById('id5').style.display = "block";
				
				document.getElementById('id1').style.zIndex = "800";
				document.getElementById('id2').style.zIndex = "900";
				document.getElementById('lol3').style.zIndex = "1000";
				document.getElementById('id4').style.zIndex = "700";
				document.getElementById('lol4').style.zIndex = "700";
				document.getElementById('lol5').style.zIndex = "699";
				document.getElementById('id5').style.zIndex = "699";
				document.getElementById('id4').style.backgroundPosition = "bottom";
			}
			else if(id == "id4") {
				document.getElementById('id1').style.display = "block";
				document.getElementById('id2').style.display = "block";
				document.getElementById('id3').style.display = "block";
				document.getElementById('id3').style.backgroundPosition = "top";
				document.getElementById('id4').style.display = "none";
				document.getElementById('id2').style.backgroundPosition = "top";
				document.getElementById('id5').style.display = "block";
				
				document.getElementById('id1').style.zIndex = "700";
				document.getElementById('id2').style.zIndex = "800";
				document.getElementById('id3').style.zIndex = "900";
				document.getElementById('lol4').style.zIndex = "1000";
				document.getElementById('id5').style.zIndex = "950";
			}
			
			else if(id == "id5") {
				document.getElementById('id1').style.display = "block";
				document.getElementById('id2').style.display = "block";
				document.getElementById('id3').style.display = "block";
				document.getElementById('id3').style.backgroundPosition = "top";
				document.getElementById('id4').style.display = "block";
				document.getElementById('id5').style.display = "none";
				document.getElementById('id2').style.backgroundPosition = "top";
				document.getElementById('id4').style.backgroundPosition = "top";
				
				document.getElementById('id1').style.zIndex = "700";
				document.getElementById('id2').style.zIndex = "800";
				document.getElementById('id3').style.zIndex = "900";
				document.getElementById('id4').style.zIndex = "1000";
				document.getElementById('lol5').style.zIndex = "1100";
			}
		}
	
	
	function next_month(luna,an,tip) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/calendar.php",
		   data: "luna="+luna+"&an="+an+"&tip="+tip+"",
		   success: function(transport){
			document.getElementById('generate_calendar').innerHTML = transport;
			//document.getElementById('generate_calendar').innerHTML = "Loading...";
			//window.location.reload();
		   }
		 });	
	}
	
	function next_year(luna,an,tip) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/calendar.php",
		   data: "luna="+luna+"&an="+an+"&tip="+tip+"",
		   success: function(transport){
			document.getElementById('generate_calendar').innerHTML = transport;
			//document.getElementById('generate_calendar').innerHTML = "Loading...";
			//window.location.reload();
		   }
		 });	
	}
	
	function switch_calendar(tip) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/calendar.php",
		   data: "tip="+tip+"",
		   success: function(transport){
			document.getElementById('generate_calendar').innerHTML = transport;
			//document.getElementById('generate_calendar').innerHTML = "Loading...";
			//window.location.reload();
			
		   }
		 });	
	}
	
	function switch_calendar1(tip) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/calendar1.php",
		   data: "tip="+tip+"",
		   success: function(transport){
			document.getElementById('countrydivcontainer').innerHTML = transport;
			//document.getElementById('generate_calendar').innerHTML = "Loading...";
			//window.location.reload();
			
		   }
		 });	
	}
	
	function switch_calendar2(tip) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/calendar_full.php",
		   data: "tip="+tip+"",
		   success: function(transport){
			document.getElementById('cal_full_div').innerHTML = transport;
			
		   }
		 });	
	}
	
	function news_afis(nr) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/news.php",
		   data: "news="+nr+"",
		   success: function(transport){
			document.getElementById('list1').innerHTML = transport;
			
		   }
		 });	
	}
	function news_afis2(pag_nr) {
			$.ajax({
		   type: "GET",
		   url: "functions/site/news2.php",
		   data: "pag_nr="+pag_nr+"",
		   success: function(transport){
			document.getElementById('list1').innerHTML = transport;
			
		   }
		 });	
	}		
	
	function pi_filestore(id,element) {
			$.ajax({
		   type: "POST",
		   url: "ajax/site/filestore.php",
		   data: "id="+id+"",
		   success: function(transport){
			document.getElementById(element).innerHTML = transport;
			
		   }
		 });	
	}		
	
				
				
		function login(){
		if(document.getElementById('login')==null)
parent.document.getElementById('login').innerHTML="<div id='sitemap'><a href='index.php'>Homepage</a> / Login</div><br><br><div style='padding:70px;text-align:left'><div id='error' style='height:15px; color:red;font-size:13;text-align:right;margin-bottom:-5px'>&nbsp;&nbsp;</div><form method='post' action='' onsubmit='check_login(); return false;'><fieldset style='border:1px dotted #999999;padding:15px;'><legend style='color:#999999;padding:2px;background-color:#FFFFFF;font-weight:bold;'>&nbsp;&nbsp;User login&nbsp;&nbsp;</legend><table border='0' cellspacing='5' cellpadding='5'><tr><td>User:</td><td><input type='text' size=15 class='textfield_login' name='user' id='user'></td></tr><tr><td> Password:</td><td> <input type='password' size=15 class='textfield_login' name='pass' id='pass'></td></tr><tr><td colspan=2><br> <input type='submit' size=7 class='submit_login' name='submit' value='NWE login'></td></tr></table></fieldset></form?<br> <a class='login' href='?act=new_user'>Create new NWE USER</a> / <a class='login'  href='?act=forgot'>Forgot password</a></div>";
else
document.getElementById('login').innerHTML="<div id='sitemap'><a href='index.php'>Homepage</a> / Login</div><br><br><div style='padding:70px;text-align:left'><div id='error' style='height:15px; color:red;font-size:13;text-align:right;margin-bottom:-5px'>&nbsp;&nbsp;</div><form method='post' action='' onsubmit='check_login(); return false;'><fieldset style='border:1px dotted #999999;padding:15px;'><legend style='color:#999999;padding:2px;background-color:#FFFFFF;font-weight:bold;'>&nbsp;&nbsp;User login&nbsp;&nbsp;</legend><table border='0' cellspacing='5' cellpadding='5'><tr><td>User:</td><td><input type='text' size=15 class='textfield_login' name='user' id='user'></td></tr><tr><td> Password:</td><td> <input type='password' size=15 class='textfield_login' name='pass' id='pass'></td></tr><tr><td colspan=2><br> <input type='submit' size=7 class='submit_login' name='submit' value='NWE login'></td></tr></table></fieldset></form?<br> <a class='login' href='?act=new_user'>Create new NWE USER</a> / <a class='login'  href='?act=forgot'>Forgot password</a></div>";
		}

		
		function check_login() {
			var user=document.getElementById('user').value;
			var pass=document.getElementById('pass').value;
			$.ajax({
		   type: "GET",
		   url: "ajax/site/check_login.php",
		   data: "user="+user+"&pass="+pass+"",
		   success: function(transport){
		   	if(transport==1){
		   		//window.location="index.php";
				//window.location = history.back();
				history.go(0);
		   	}
		   	else{
		   		document.getElementById('error').innerHTML = transport;	
		   	}
			
		   }
		 });	
	}		
	
		function check_user() {
			var user=document.getElementById('user').value;
			$.ajax({
		   type: "GET",
		   url: "ajax/site/check_user.php",
		   data: "user="+user+"",
		   success: function(transport){

		   		document.getElementById('check').innerHTML = transport;	

			
		   }
		 });	
	}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span> / '+x[i].getAttribute('maxlength')+" max length";
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'red';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}	

function change_step(id) {
	if(id == "step1") {
		document.getElementById("step1").style.display="block"
		document.getElementById("step2").style.display="none"
		document.getElementById("butonstep1").style.backgroundImage="url('images/site/steps_over_01.gif')"
		document.getElementById("butonstep2").style.backgroundImage="url('images/site/steps_02.gif')"
	}
	else if(id == "step2") {
		document.getElementById("step2").style.display="block"
		document.getElementById("step1").style.display="none"
		document.getElementById("butonstep2").style.backgroundImage="url('images/site/steps_over_02.gif')"
		document.getElementById("butonstep1").style.backgroundImage="url('images/site/steps_01.gif')"
	}
	
}

function check_submit_idea() {
			project_name = document.getElementById("project_name").value;
			general = FCKeditorAPI.GetInstance("general").GetXHTML(true);
			specifics_desc = FCKeditorAPI.GetInstance("specifics_desc").GetXHTML(true);
			expected_desc = FCKeditorAPI.GetInstance("expected_desc").GetXHTML(true);
			partners_involved = FCKeditorAPI.GetInstance("partners_involved").GetXHTML(true);
			further_partners = FCKeditorAPI.GetInstance("further_partners").GetXHTML(true);
			how_are_partners = FCKeditorAPI.GetInstance("how_are_partners").GetXHTML(true);
			what_is_innovative = FCKeditorAPI.GetInstance("what_is_innovative").GetXHTML(true);
			total_cost = document.getElementById("total_cost").value;
			total_erdf = document.getElementById("total_erdf").value;
			captcha = document.getElementById("captcha").value;
			region_id = document.getElementById("region_id").value;
			tel_no = document.getElementById("tel_no").value;
			email_address = document.getElementById("email_address").value;
			$.ajax({
			   type: "POST",
			   url: "ajax/site/check_submit_idea.php",
			   data: "project_name="+project_name+"&general="+general+"&specifics_desc="+specifics_desc+"&expected_desc="+expected_desc+"&total_cost="+total_cost+"&total_erdf="+total_erdf+"&partners_involved="+partners_involved+"&further_partners="+further_partners+"&how_are_partners="+how_are_partners+"&what_is_innovative="+what_is_innovative+"&captcha="+captcha+"&region_id="+region_id+"&tel_no="+tel_no+"&email_address="+email_address,
			   success: function(transport){
			   		if(transport=="1") {
				 		document.getElementById('error').innerHTML = '';	
						
				 		document.submitIdea.submit();
				 	}
				 	else {
				 		document.getElementById('error').innerHTML = transport;
						
				 	}
			   }
		 	});	
}


function set_limit(){
	document.form_l.submit();
	}
	
function tabs(id){
	if(id=="doc"){
		document.getElementById(id).style.display="block";
		document.getElementById("media").style.display="none";
		document.getElementById("filestore_search").style.display="none";
		document.getElementById("td_media").style.background = 'url(images/site/tabs-top_04.gif)';
		document.getElementById("td_doc").style.background = 'url(images/site/tabs-top_03.gif)'
	}
	else if(id=="media"){
		document.getElementById(id).style.display="block";
		document.getElementById("doc").style.display="none";
		document.getElementById("filestore_search").style.display="none";
		document.getElementById("td_doc").style.background = 'url(images/site/tabs-top_04.gif)'
		document.getElementById("td_media").style.background = 'url(images/site/tabs-top_03.gif)'
	}
}

function show_filestore_search() {
	document.getElementById("doc").style.display="none";
	document.getElementById("media").style.display="none";
	document.getElementById("filestore_search").style.display="block";
	document.getElementById("td_media").style.background = 'url(images/site/tabs-top_04.gif)';
	document.getElementById("td_doc").style.background = 'url(images/site/tabs-top_04.gif)'
}

function filestore_search() {
	record_id = document.getElementById("record_id").value;
	keyword = document.getElementById("keyword").value;
	$.ajax({
		type: "GET",
		url: "ajax/site/filestore_search.php",
		data: "record_id="+record_id+"&keyword="+keyword+"",
		success: function(transport){
			document.getElementById('filestore_results').innerHTML = transport;	
	 	}
	});	
}

function project_details(id){
	if(id=="details"){
		document.getElementById(id).style.display="block";
		document.getElementById("filestore").style.display="none";
	}
	else if(id=="filestore"){
		document.getElementById(id).style.display="block";
		document.getElementById("details").style.display="none";
	}
}

function check_edit_prj() {
			project_name = document.submitEdit.project_name.value;
			project_website_url = document.submitEdit.project_website_url.value;
			total_cost = document.submitEdit.total_cost.value;
			erdf_grant = document.submitEdit.erdf_grant.value;
		
			$.ajax({
			   type: "GET",
			    url: "ajax/site/check_edit_prj.php?project_name="+project_name+"&project_website_url="+project_website_url+"&total_cost="+total_cost+"&erdf_grant="+erdf_grant,
			   success: function(transport){
			   		if(transport=="1") {
				 		document.getElementById('error').innerHTML = '';
				 		document.getElementById('go_to').value='1';		
				 		document.submitEdit.submit();
				 	}
				 	else {
				 		document.getElementById('error').innerHTML = transport;	
				 	}
			   }
		 	});			 	
}

function check_record() {
			record_status_id = document.submitRecord.record_status_id.value;
			expiry_date = document.submitRecord.expiry_date.value;
			record_note = document.submitRecord.record_note.value;
		
			$.ajax({
			   type: "GET",
			    url: "ajax/site/check_record.php?record_status_id="+record_status_id+"&expiry_date="+expiry_date+"&record_note="+record_note,
			   success: function(transport){
			   		if(transport=="1") {
				 		document.getElementById('error').innerHTML = '';
				 		document.getElementById('go_to').value='1';		
				 		document.submitRecord.submit();
				 	}
				 	else {
				 		document.getElementById('error').innerHTML = transport;	
				 	}
			   }
		 	});			 	
}

function check_file() {
			type = document.submitFile.type.value;
			note_description = document.submitFile.note_description.value;
			doc_description = document.submitFile.doc_description.value;
			media_description = document.submitFile.media_description.value;		
			$.ajax({
			   type: "GET",
			    url: "ajax/site/check_file.php?type="+type+"&note_description="+note_description+"&doc_description="+doc_description+"&media_description="+media_description,
			   success: function(transport){
			   		if(transport=="1") {
				 		document.getElementById('error').innerHTML = '';
				 		document.getElementById('go_to').value='1';		
				 		document.submitFile.submit();
				 	}
				 	else {
				 		document.getElementById('error').innerHTML = transport;	
				 	}
			   }
		 	});			 	
}

function check_note() {
	
			note_description = document.submitNote.note_description.value;
					
			$.ajax({
			   type: "GET",
			    url: "ajax/site/check_note.php?note_description="+note_description,
			   success: function(transport){
			   		if(transport=="1") {
				 		document.getElementById('error').innerHTML = '';
				 		document.getElementById('go_to').value='1';		
				 		document.submitNote.submit();
				 	}
				 	else {
				 		document.getElementById('error').innerHTML = transport;	
				 	}
			   }
		 	});			 	
}

function what_type(tip) {
	if(tip == "note") {
		document.getElementById('note').style.display = "block";
		document.getElementById('document').style.display = "none";
		document.getElementById('media').style.display = "none";
	}
	else if(tip == "document") {
		document.getElementById('note').style.display = "none";
		document.getElementById('document').style.display = "block";
		document.getElementById('media').style.display = "none";
	}
	else if(tip == "media") {
		document.getElementById('note').style.display = "none";
		document.getElementById('document').style.display = "none";
		document.getElementById('media').style.display = "block";
	}
	else {}
}


function filestore_pagination(table_view,nr_table) {
	
	for(var i=0;i<nr_table;i++){
		
		var id="table_pag"+i;
		document.getElementById(id).style.display = 'none';	
	}
	document.getElementById(table_view).style.display = 'block';

}

function findPos(obj) {
	var curleft = curtop = 0;
if (obj.offsetParent) {
do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
	return curtop;
}
}

function create(imagine,idi)
{
if(document.getElementById("im"))
	{destroy();}
   var myElement = document.createElement("img");
   myElement.setAttribute("src", imagine);
   myElement.setAttribute("id", "im");
   myElement.setAttribute("style", "position:absolute;left:60px;top:30px;border:1px solid black;z-index:900;");
   myElement.style.cssText="position:absolute;left:60px;top:30px;border:1px solid black;z-index:900;";
   //myElement.setAttribute("onmouseout","destroy();");
   document.body.appendChild(myElement);
   set_coords(idi);
}

function destroy()
{
y=document.getElementById("im");
document.body.removeChild(y);

}

function set_coords(id)
  {
  //x=event.clientX;
  //y=event.clientY;
var obj = document.getElementById(id).getBoundingClientRect();

var left = obj.left;
var top = obj.top;
var bottom = obj.bottom;
var right = obj.right;
ot=findPos(document.getElementById(id));
//  z=document.getElementById(id).offsetTop+43;
z=ot-140;
  //q=document.getElementById(id).offsetLeft+340;
q=right-5;
//z=top;
document.getElementById("im").style.left=q+"px";
document.getElementById("im").style.top=z+"px";
  }
