// JavaScript Document

function show_hide_themes()
{
	if (document.getElementById('themes').style.visibility == 'hidden')	
	{
		document.getElementById('themes').style.visibility = 'visible';
	}
	else
	{
		document.getElementById('themes').style.visibility = 'hidden';
	}
}

function send_mail(id, lang)
{
	if (lang == 'TR')
	{
		confirm_send = confirm('kontakt bilgileri bu eposta adresine gonderilecek : ' + document.getElementById('email').value + ' ');
	}
	else
	{
		confirm_send = confirm('The contact details will be sent to the following email address : ' + document.getElementById('email').value + ' ');
	}

	if (confirm_send == true)
	{
		write_ajax('send_mail.asp?id=' + id + '&to=' + document.getElementById('email').value + '&lang=' + lang, 'PSContactDetails');	
	}
}

//////////////////////////////////////////
function show_hide_mapcontents(obj)
{
	if (obj.className == 'mapcontents')
	{
		obj.className = 'mapcontents_small';
	}
	else
	{
		obj.className = 'mapcontents';
	}
}


//////////////////////////////////////////////////////
function switch_formatting(obj, ClassName1, ClassName2)
{
	//alert(ClassName1);
	if (obj.className == ClassName1)
	{
		obj.className = ClassName2;	
	}
	else
	{
		obj.className = ClassName1;	
	}
}

///////////////////////////////////////////////////////
function minimize_maximize(obj)
{
	if (obj.className == 'map_min')
	{
		obj.className = 'map_max';
	}
	else
	{
		obj.className = 'map_min';
	}
}

//////////////////////////////////////////////////////////
function recolorContactDetails(obj, allRecs)
{
	var indx = obj.id.split("_")[1];
	//alert (indx);
	for (i = 1; i<=allRecs; i++ )
	{
		if (i == indx)
		{
			//alert ('i == indx');
			document.getElementById('Title_' + i).className = 'selectedTD';
			document.getElementById('Position_' + i).className = 'selectedTD';
			
		}
		else
		{	
			//alert ('!i == indx');
			document.getElementById('Title_' + i).className = 'NOTselectedTD';
			document.getElementById('Position_' + i).className = 'NOTselectedTD';
		}
		
	}
	
}

////////////////////////////////////////////////
function countStr(stringToSearch, searchString)
{
	var _s = stringToSearch // haystack
	var _m = searchString; // needle
	var _c = 0;
	for (var i=0;i<_s.length;i++)
	{
		if (_m == _s.substr(i,_m.length))
		_c++;
		//alert(_c);
		return _c;
	}
}

///////////////////////////////////////////////////
function getElementsByClass(node,searchClass,tag) {
  var classElements = new Array();
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp(searchClass);
  for (i = 0, j = 0; i < elsLen; i++)
  {
    if ( pattern.test(els[i].className) )
	{
      classElements[j] = els[i];
      j++;
    }
  }
return classElements;
}

///////////////////////////////////////////

function write_contact_details(targetDiv, PersonPosition)
{
	var url = 'http://ps-blacksea-commission.ath.cx/bsc/directory_fpdata.asp?position=' + PersonPosition + '&what=PS'
	document.getElementById(targetDiv).innerHTML = "<iframe frameborder='0' src='" + url + "'></iframe>";	
}

////////////////////////////////////////////////////
function fontsizebuttons (obj)
{
	document.getElementById("fontsize10").className = 'buttonup';
	document.getElementById("fontsize12").className = 'buttonup';
	document.getElementById("fontsize14").className = 'buttonup';
	document.getElementById("fontsize16").className = 'buttonup';
	document.getElementById("fontsize18").className = 'buttonup';
	document.getElementById("fontsize20").className = 'buttonup';
	document.getElementById("fontsize22").className = 'buttonup';
	document.getElementById("fontsize24").className = 'buttonup';
	
	obj.className = 'buttondown';

}

////////////////////////////////////////////////////////////////
function change_fontsize(newfontsize, divId)
{
	//alert(newfontsize);
	document.getElementById(divId).style.fontSize = newfontsize + 'px';	
}

////////////////////////////////////////////////////////////////
function show_hide(id)
{
	//alert(id);
	if (document.getElementById(id).style.visibility == 'hidden')
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.position = '';
	}
	else
	{
		document.getElementById(id).style.visibility = 'hidden';
		document.getElementById(id).style.position = 'absolute';
	}
}


function highlightHTML(highlightText, htmlText)
{
		if (highlightText == '')
		{
			return 	htmlText; 
		}
		var highlightedText;
		var paragraphs = highlightText.split(",");
		var i;
		highlightedText = htmlText
		
		
		for (i = 0; i <= paragraphs.length - 1 ; i++ )
		{
			paragraphs[i] = paragraphs[i].replace(/^\s*|\s*$/g,'');
			var reg = new RegExp(paragraphs[i], "g");
			highlightedText = highlightedText.replace(reg, '<span class="highlight">' + paragraphs[i] + '</span>');
		}
		


return highlightedText;
		
}

function write_ajax(url, divname)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp.onreadystatechange=function(){
	
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById(divname).innerHTML=xmlHttp.responseText;		
	}
	
	
	};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



function highlightText_ajax(url, divname, highlight)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp.onreadystatechange=function(){
	
	if (xmlHttp.readyState==4)
	{ 
		//alert (highlight);
		//alert ('ajax response is ' + xmlHttp.responseText);
		if (!( highlight == ''))
		{
			var resp = highlightHTML(highlight, xmlHttp.responseText).split('<span class="highlight">');
			var respFinal = '';
			for (i = 0; i<= resp.length - 2 ; i++)
			{
				respFinal = respFinal + resp[i] + '<span class="highlight"><a name="highlight_' + i + '"></a>';
			}/**/
			respFinal = respFinal + resp[resp.length - 1];
			document.getElementById(divname).innerHTML=respFinal;
			
			var totalCount = getElementsByClass(document.getElementById('bscdocument'),'highlight', 'span').length;
			document.getElementById('highlightlast').href = '#highlight_' + (resp.length - 2);
			document.getElementById('highlighttip').innerHTML = (totalCount) + ' total occurrences of ' + highlight;
			//this is application specific - scroll to the first highlighted text
			window.location = '#highlight_0'; 
			
			
		}
		else
		{
			document.getElementById(divname).innerHTML=xmlHttp.responseText;
			document.getElementById('highlighttip').innerHTML = ' <strong>Tip:</strong> to highlight several words separate them by comma';
		}
		
	}
	
	
	};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function reset_search_function()
{
	if ((document.getElementById("srch").value == "Search ..."))
	{
		document.getElementById("srch").value = "";
	}
}

